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:
Moheeb Zara
2026-08-04 22:21:29 -07:00
parent 4f4e3096ca
commit b2b463491a
13 changed files with 2055 additions and 465 deletions
+3 -3
View File
@@ -80,7 +80,8 @@ export async function markAttendance(input: unknown) {
export async function completeSession(input: unknown) {
const gate = await requirePermission('classes.instruct')
if (!gate.ok) return { error: gate.error }
const { supabase, member } = gate
const { member } = gate
const supabase = await createClient()
const v = parseInput(sessionIdSchema, input)
if (!v.ok) return { error: v.error }
@@ -105,8 +106,7 @@ export async function completeSession(input: unknown) {
.eq('space_id', member.space_id)
if (upErr) return { error: upErr.message }
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
const cls = (session as unknown as { classes?: { title: string; grants_certification_id: string | null } | null }).classes
const cls = session.classes
let issued = 0
let certSkipped = false
if (cls?.grants_certification_id) {
+2 -21
View File
@@ -212,27 +212,8 @@ export async function listUpcomingSessions() {
.order('starts_at', { ascending: true })
if (error) return { error: error.message }
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
const rows = ((sessions ?? []) as unknown as Array<{
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 rows = (sessions ?? []).filter(
(s) => s.classes?.is_active !== false,
)
const ids = rows.map((s: { id: string }) => s.id)
+1 -4
View File
@@ -43,10 +43,7 @@ export async function signUpForClass(input: unknown) {
.eq('space_id', member.space_id)
.maybeSingle()
if (!session) return { error: 'Session not found' }
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
const cls = (session as unknown as {
classes?: { title: string | null; capacity: number | null; is_active: boolean; required_form_id: string | null } | null
}).classes
const cls = session.classes
if (cls && cls.is_active === false) return { error: 'This class is no longer available.' }
const { data: isMgr } = await supabase.rpc('user_has_permission', {
+1 -2
View File
@@ -225,8 +225,7 @@ export async function listDoorCards(input: unknown) {
return {
data: (cards ?? []).map(c => {
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
const sm = c.space_members as unknown as { display_name: string | null } | { display_name: string | null }[] | null
const sm = c.space_members
const name = Array.isArray(sm) ? sm[0]?.display_name : sm?.display_name
return {
cardId: c.id as string,
+3 -2
View File
@@ -450,14 +450,15 @@ export async function cancelReservation(input: unknown) {
export async function listEquipmentReservations(input: unknown) {
const gate = await requireEquipmentManager()
if (!gate.ok) return { error: gate.error }
const { supabase, member } = gate
const { member } = gate
const supabase = await createClient()
const v = parseInput(listEquipmentReservationsSchema, input)
if (!v.ok) return { error: v.error }
const { data, error } = await supabase
.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('equipment_id', v.data.equipmentId)
.order('starts_at', { ascending: true })
+1 -2
View File
@@ -257,8 +257,7 @@ export async function listMemberBilling() {
if (error) return { error: error.message }
return {
data: (data ?? []).map(r => {
// TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata)
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 sm = r.space_members
const mem = Array.isArray(sm) ? sm[0] : sm
return {
memberId: r.member_id as string,
+1 -1
View File
@@ -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
// your member name in the note") to help the treasurer reconcile later.
export const duesPaymentMethodSchema = z.object({
platform: z.enum(DUES_LINK_PLATFORMS as unknown as [string, ...string[]]),
platform: z.enum(DUES_LINK_PLATFORMS),
url: z
.string()
.trim()