refactor(types): regenerate database types from canonical schema; drop TODO(types) join casts
Regenerate types/database.ts from a local Supabase built from the canonical scripts/schema.sql. The running dev DB was stale (missing the 'stripe' payment_platform value, members_with_permission, spaces.host_requires_card, payments.link_status, dues_payment_methods.space_id), so it was rebuilt from schema.sql first. With real relationship metadata the 11 `as unknown as … // TODO(types)` join casts are no longer needed: - me portal, session-attendance, member-certifications, equipment-reservations: narrow the action result with `'data' in res` instead of a blanket cast. - stripe / door embeds read the now-typed relation directly. - completeSession + listEquipmentReservations route the embedded-select query through the fully-typed createClient() rather than the wide ServerSupabase gate client (the pattern documented in auth-helpers.ts); equipment disambiguates its two space_members FKs with an explicit !fkey hint. Collapse the hand-maintained governance rows/enums in types/domain/governance.ts into Tables<>/Enums<> aliases. Tighten duesPaymentMethodSchema.platform to the DUES_LINK_PLATFORMS literal union (the old `as unknown as [string,...]` erased it), which the now-correct payment_platform enum requires. The hand-added class_signup_tx / class_cancel_tx RPC entries are now generated natively. typecheck 0 · lint 0 errors · 645 tests · build ok
This commit is contained in:
@@ -98,12 +98,10 @@ export default async function MePage() {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
const signupRes = await getMyClassSignups()
|
const signupRes = await getMyClassSignups()
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
const classSignups: ClassSignup[] = 'data' in signupRes ? (signupRes.data ?? []) : []
|
||||||
const classSignups: ClassSignup[] = 'data' in signupRes ? (signupRes.data as unknown as ClassSignup[]) : []
|
|
||||||
|
|
||||||
const reservationRes = await getMyReservations()
|
const reservationRes = await getMyReservations()
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
const reservations: Reservation[] = 'data' in reservationRes ? (reservationRes.data ?? []) : []
|
||||||
const reservations: Reservation[] = 'data' in reservationRes ? (reservationRes.data as unknown as Reservation[]) : []
|
|
||||||
|
|
||||||
const cardsRes = await getMyCards()
|
const cardsRes = await getMyCards()
|
||||||
const myCards: MyCard[] = 'data' in cardsRes ? (cardsRes.data as MyCard[]) : []
|
const myCards: MyCard[] = 'data' in cardsRes ? (cardsRes.data as MyCard[]) : []
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ export function MemberCertificationsDialog({
|
|||||||
if ('error' in g && g.error) {
|
if ('error' in g && g.error) {
|
||||||
toast.error(g.error)
|
toast.error(g.error)
|
||||||
} else {
|
} else {
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
setGrants(('data' in g ? g.data : []) ?? [])
|
||||||
setGrants(((g as unknown as { data: Grant[] }).data) ?? [])
|
|
||||||
}
|
}
|
||||||
if (!('error' in t) || !t.error) {
|
if (!('error' in t) || !t.error) {
|
||||||
setTypes(((t as { data: CertType[] }).data ?? []).filter(c => c.is_active))
|
setTypes(((t as { data: CertType[] }).data ?? []).filter(c => c.is_active))
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ export function SessionAttendance({
|
|||||||
toast.error(res.error)
|
toast.error(res.error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
setRows(('data' in res ? res.data : []) ?? [])
|
||||||
setRows(((res as unknown as { data: Signup[] }).data) ?? [])
|
|
||||||
}, [sessionId])
|
}, [sessionId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ export function EquipmentReservations({ equipmentId }: { equipmentId: string })
|
|||||||
toast.error(res.error)
|
toast.error(res.error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
setRows(('data' in res ? res.data : []) ?? [])
|
||||||
setRows(((res as unknown as { data: Reservation[] }).data) ?? [])
|
|
||||||
}, [equipmentId])
|
}, [equipmentId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ export async function markAttendance(input: unknown) {
|
|||||||
export async function completeSession(input: unknown) {
|
export async function completeSession(input: unknown) {
|
||||||
const gate = await requirePermission('classes.instruct')
|
const gate = await requirePermission('classes.instruct')
|
||||||
if (!gate.ok) return { error: gate.error }
|
if (!gate.ok) return { error: gate.error }
|
||||||
const { supabase, member } = gate
|
const { member } = gate
|
||||||
|
const supabase = await createClient()
|
||||||
|
|
||||||
const v = parseInput(sessionIdSchema, input)
|
const v = parseInput(sessionIdSchema, input)
|
||||||
if (!v.ok) return { error: v.error }
|
if (!v.ok) return { error: v.error }
|
||||||
@@ -105,8 +106,7 @@ export async function completeSession(input: unknown) {
|
|||||||
.eq('space_id', member.space_id)
|
.eq('space_id', member.space_id)
|
||||||
if (upErr) return { error: upErr.message }
|
if (upErr) return { error: upErr.message }
|
||||||
|
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
const cls = session.classes
|
||||||
const cls = (session as unknown as { classes?: { title: string; grants_certification_id: string | null } | null }).classes
|
|
||||||
let issued = 0
|
let issued = 0
|
||||||
let certSkipped = false
|
let certSkipped = false
|
||||||
if (cls?.grants_certification_id) {
|
if (cls?.grants_certification_id) {
|
||||||
|
|||||||
@@ -212,27 +212,8 @@ export async function listUpcomingSessions() {
|
|||||||
.order('starts_at', { ascending: true })
|
.order('starts_at', { ascending: true })
|
||||||
if (error) return { error: error.message }
|
if (error) return { error: error.message }
|
||||||
|
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
const rows = (sessions ?? []).filter(
|
||||||
const rows = ((sessions ?? []) as unknown as Array<{
|
(s) => s.classes?.is_active !== false,
|
||||||
id: string
|
|
||||||
class_id: string
|
|
||||||
starts_at: string
|
|
||||||
ends_at: string | null
|
|
||||||
location: string | null
|
|
||||||
capacity: number | null
|
|
||||||
status: string
|
|
||||||
notes: string | null
|
|
||||||
classes: {
|
|
||||||
title: string
|
|
||||||
description: string | null
|
|
||||||
payment_link: string | null
|
|
||||||
capacity: number | null
|
|
||||||
is_active: boolean
|
|
||||||
grants_certification_id: string | null
|
|
||||||
required_form_id: string | null
|
|
||||||
} | null
|
|
||||||
}>).filter(
|
|
||||||
(s: { classes?: { is_active?: boolean } | null }) => s.classes?.is_active !== false,
|
|
||||||
)
|
)
|
||||||
const ids = rows.map((s: { id: string }) => s.id)
|
const ids = rows.map((s: { id: string }) => s.id)
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,7 @@ export async function signUpForClass(input: unknown) {
|
|||||||
.eq('space_id', member.space_id)
|
.eq('space_id', member.space_id)
|
||||||
.maybeSingle()
|
.maybeSingle()
|
||||||
if (!session) return { error: 'Session not found' }
|
if (!session) return { error: 'Session not found' }
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
const cls = session.classes
|
||||||
const cls = (session as unknown as {
|
|
||||||
classes?: { title: string | null; capacity: number | null; is_active: boolean; required_form_id: string | null } | null
|
|
||||||
}).classes
|
|
||||||
if (cls && cls.is_active === false) return { error: 'This class is no longer available.' }
|
if (cls && cls.is_active === false) return { error: 'This class is no longer available.' }
|
||||||
|
|
||||||
const { data: isMgr } = await supabase.rpc('user_has_permission', {
|
const { data: isMgr } = await supabase.rpc('user_has_permission', {
|
||||||
|
|||||||
@@ -225,8 +225,7 @@ export async function listDoorCards(input: unknown) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
data: (cards ?? []).map(c => {
|
data: (cards ?? []).map(c => {
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
const sm = c.space_members
|
||||||
const sm = c.space_members as unknown as { display_name: string | null } | { display_name: string | null }[] | null
|
|
||||||
const name = Array.isArray(sm) ? sm[0]?.display_name : sm?.display_name
|
const name = Array.isArray(sm) ? sm[0]?.display_name : sm?.display_name
|
||||||
return {
|
return {
|
||||||
cardId: c.id as string,
|
cardId: c.id as string,
|
||||||
|
|||||||
@@ -450,14 +450,15 @@ export async function cancelReservation(input: unknown) {
|
|||||||
export async function listEquipmentReservations(input: unknown) {
|
export async function listEquipmentReservations(input: unknown) {
|
||||||
const gate = await requireEquipmentManager()
|
const gate = await requireEquipmentManager()
|
||||||
if (!gate.ok) return { error: gate.error }
|
if (!gate.ok) return { error: gate.error }
|
||||||
const { supabase, member } = gate
|
const { member } = gate
|
||||||
|
const supabase = await createClient()
|
||||||
|
|
||||||
const v = parseInput(listEquipmentReservationsSchema, input)
|
const v = parseInput(listEquipmentReservationsSchema, input)
|
||||||
if (!v.ok) return { error: v.error }
|
if (!v.ok) return { error: v.error }
|
||||||
|
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from('equipment_reservations')
|
.from('equipment_reservations')
|
||||||
.select('id, member_id, starts_at, ends_at, status, notes, space_members(display_name, email)')
|
.select('id, member_id, starts_at, ends_at, status, notes, space_members!equipment_reservations_member_id_fkey(display_name, email)')
|
||||||
.eq('space_id', member.space_id)
|
.eq('space_id', member.space_id)
|
||||||
.eq('equipment_id', v.data.equipmentId)
|
.eq('equipment_id', v.data.equipmentId)
|
||||||
.order('starts_at', { ascending: true })
|
.order('starts_at', { ascending: true })
|
||||||
|
|||||||
@@ -257,8 +257,7 @@ export async function listMemberBilling() {
|
|||||||
if (error) return { error: error.message }
|
if (error) return { error: error.message }
|
||||||
return {
|
return {
|
||||||
data: (data ?? []).map(r => {
|
data: (data ?? []).map(r => {
|
||||||
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
|
const sm = r.space_members
|
||||||
const sm = r.space_members as unknown as { display_name: string | null; email: string | null; tier: string | null } | { display_name: string | null; email: string | null; tier: string | null }[] | null
|
|
||||||
const mem = Array.isArray(sm) ? sm[0] : sm
|
const mem = Array.isArray(sm) ? sm[0] : sm
|
||||||
return {
|
return {
|
||||||
memberId: r.member_id as string,
|
memberId: r.member_id as string,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { DUES_LINK_PLATFORMS, isSafeDuesUrl } from '../dues-payments-logic'
|
|||||||
// member-clickable anchor. instructions is an optional memo hint (e.g. "put
|
// member-clickable anchor. instructions is an optional memo hint (e.g. "put
|
||||||
// your member name in the note") to help the treasurer reconcile later.
|
// your member name in the note") to help the treasurer reconcile later.
|
||||||
export const duesPaymentMethodSchema = z.object({
|
export const duesPaymentMethodSchema = z.object({
|
||||||
platform: z.enum(DUES_LINK_PLATFORMS as unknown as [string, ...string[]]),
|
platform: z.enum(DUES_LINK_PLATFORMS),
|
||||||
url: z
|
url: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
|
|||||||
+2013
-264
File diff suppressed because it is too large
Load Diff
+25
-156
@@ -1,161 +1,30 @@
|
|||||||
/**
|
/**
|
||||||
* Hand-written governance-kernel domain types (proposals, votes, incidents,
|
* Governance-kernel domain types (proposals, votes, incidents, policies,
|
||||||
* policies, areas) and their enums.
|
* areas) and their enums.
|
||||||
*
|
*
|
||||||
* NOTE: the underlying tables and enums now ALSO exist in the generated
|
* These are thin aliases over the generated database types (`types/database.ts`,
|
||||||
* `types/database.ts` (proposals, proposal_votes, incidents, incident_updates,
|
* regenerated from the canonical schema). Keep them as `Tables<>` / `Enums<>`
|
||||||
* policies, space_areas; proposal_type, incident_status, etc.). These shapes
|
* aliases — do NOT hand-maintain the row shapes here; regenerate the database
|
||||||
* were hand-authored before that regeneration and are kept verbatim here to
|
* types instead.
|
||||||
* avoid a behavior change. Follow-up: after verifying field parity, replace the
|
|
||||||
* row types with `Tables<'proposals'>` etc. and the enums with
|
|
||||||
* `Enums<'proposal_type'>` etc., and delete the duplication.
|
|
||||||
*/
|
*/
|
||||||
|
import type { Tables, Enums } from '@/types/database'
|
||||||
|
|
||||||
export type ProposalType =
|
// Enums
|
||||||
| 'bylaw_change'
|
export type ProposalType = Enums<'proposal_type'>
|
||||||
| 'board_action'
|
export type ProposalStatus = Enums<'proposal_status'>
|
||||||
| 'membership_vote'
|
export type ThresholdRule = Enums<'threshold_rule'>
|
||||||
| 'advisory_poll'
|
export type VotePosition = Enums<'vote_position'>
|
||||||
| 'recall'
|
export type IncidentStatus = Enums<'incident_status'>
|
||||||
| 'budget'
|
export type IncidentSeverity = Enums<'incident_severity'>
|
||||||
|
export type IncidentUpdateVisibility = Enums<'incident_update_visibility'>
|
||||||
|
export type PolicyStatus = Enums<'policy_status'>
|
||||||
|
export type FinancialVisibility = Enums<'financial_visibility'>
|
||||||
|
export type DirectoryVisibility = Enums<'directory_visibility'>
|
||||||
|
|
||||||
export type ProposalStatus =
|
// Rows
|
||||||
| 'draft'
|
export type SpaceArea = Tables<'space_areas'>
|
||||||
| 'open'
|
export type Proposal = Tables<'proposals'>
|
||||||
| 'decided'
|
export type ProposalVote = Tables<'proposal_votes'>
|
||||||
| 'withdrawn'
|
export type Incident = Tables<'incidents'>
|
||||||
| 'expired'
|
export type IncidentUpdateRow = Tables<'incident_updates'>
|
||||||
|
export type Policy = Tables<'policies'>
|
||||||
export type ThresholdRule =
|
|
||||||
| 'simple_majority'
|
|
||||||
| 'two_thirds'
|
|
||||||
| 'three_fourths'
|
|
||||||
| 'unanimous'
|
|
||||||
|
|
||||||
export type VotePosition = 'yes' | 'no' | 'abstain' | 'recused'
|
|
||||||
|
|
||||||
export type IncidentStatus =
|
|
||||||
| 'received'
|
|
||||||
| 'under_review'
|
|
||||||
| 'decided'
|
|
||||||
| 'appealed'
|
|
||||||
| 'closed'
|
|
||||||
|
|
||||||
export type IncidentSeverity = 'low' | 'medium' | 'high' | 'critical'
|
|
||||||
|
|
||||||
export type IncidentUpdateVisibility =
|
|
||||||
| 'reporter_only'
|
|
||||||
| 'all_parties'
|
|
||||||
| 'board_only'
|
|
||||||
|
|
||||||
export type PolicyStatus = 'draft' | 'active' | 'deprecated' | 'superseded'
|
|
||||||
|
|
||||||
export type SpaceArea = {
|
|
||||||
id: string
|
|
||||||
space_id: string
|
|
||||||
code: string
|
|
||||||
name: string
|
|
||||||
icon: string | null
|
|
||||||
sort_order: number
|
|
||||||
is_archived: boolean
|
|
||||||
created_at: string
|
|
||||||
updated_at: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FinancialVisibility = 'treasurer_only' | 'board_visible' | 'all_members_visible'
|
|
||||||
|
|
||||||
export type DirectoryVisibility =
|
|
||||||
| 'board_only'
|
|
||||||
| 'member_count_visible'
|
|
||||||
| 'members_visible'
|
|
||||||
| 'public_members_visible'
|
|
||||||
|
|
||||||
export type Proposal = {
|
|
||||||
id: string
|
|
||||||
space_id: string
|
|
||||||
proposer_id: string | null
|
|
||||||
proposer_name: string | null
|
|
||||||
title: string
|
|
||||||
body: string
|
|
||||||
proposal_type: ProposalType
|
|
||||||
status: ProposalStatus
|
|
||||||
quorum_required: number
|
|
||||||
quorum_percent: number
|
|
||||||
quorum_floor: number
|
|
||||||
threshold: ThresholdRule
|
|
||||||
voting_opens_at: string | null
|
|
||||||
voting_closes_at: string | null
|
|
||||||
policy_ref_id: string | null
|
|
||||||
parent_incident_id: string | null
|
|
||||||
outcome_yes: number
|
|
||||||
outcome_no: number
|
|
||||||
outcome_abstain: number
|
|
||||||
outcome_recused: number
|
|
||||||
total_voters: number
|
|
||||||
quorum_met: boolean | null
|
|
||||||
passed: boolean | null
|
|
||||||
created_at: string
|
|
||||||
updated_at: string
|
|
||||||
decided_at: string | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ProposalVote = {
|
|
||||||
id: string
|
|
||||||
proposal_id: string
|
|
||||||
member_id: string
|
|
||||||
position: VotePosition
|
|
||||||
recusal_reason: string | null
|
|
||||||
comment: string | null
|
|
||||||
voted_at: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Incident = {
|
|
||||||
id: string
|
|
||||||
space_id: string
|
|
||||||
reporter_id: string | null
|
|
||||||
reporter_token: string | null
|
|
||||||
is_anonymous: boolean
|
|
||||||
subjects: string[]
|
|
||||||
category: string
|
|
||||||
severity: IncidentSeverity
|
|
||||||
title: string
|
|
||||||
body: string
|
|
||||||
status: IncidentStatus
|
|
||||||
disposition: string | null
|
|
||||||
decision_maker_ids: string[]
|
|
||||||
appeal_proposal_id: string | null
|
|
||||||
sla_response_by: string | null
|
|
||||||
created_at: string
|
|
||||||
updated_at: string
|
|
||||||
acknowledged_at: string | null
|
|
||||||
decided_at: string | null
|
|
||||||
closed_at: string | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type IncidentUpdateRow = {
|
|
||||||
id: string
|
|
||||||
incident_id: string
|
|
||||||
author_id: string | null
|
|
||||||
author_name: string | null
|
|
||||||
body: string
|
|
||||||
visibility: IncidentUpdateVisibility
|
|
||||||
created_at: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Policy = {
|
|
||||||
id: string
|
|
||||||
space_id: string
|
|
||||||
slug: string
|
|
||||||
section_ref: string | null
|
|
||||||
parent_policy_id: string | null
|
|
||||||
title: string
|
|
||||||
body_formal: string
|
|
||||||
body_plain: string | null
|
|
||||||
version: number
|
|
||||||
prior_version_id: string | null
|
|
||||||
status: PolicyStatus
|
|
||||||
effective_at: string | null
|
|
||||||
adopted_by_proposal_id: string | null
|
|
||||||
created_at: string
|
|
||||||
updated_at: string
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user