refactor(types): move hand-written domain types to types/domain/* (slice 2)

lib/types.ts (aliases + governance shapes + auth re-exports) split into
types/domain/{index,governance,reexports}.ts, making the generated/hand-written
seam explicit (generated = types/database.ts, hand-written = types/domain/*).
lib/types.ts is now a re-export shim so all 11 importers are untouched. Fixed
the stale 'not yet in types/database.ts' comment — those tables/enums are now
generated; de-duplicating the governance rows into Tables<>/Enums<> is a noted
follow-up. tsc 0, 635 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Moheeb Zara
2026-08-02 04:21:19 -07:00
co-authored by Claude Opus 4.8
parent 18d5e22ad4
commit 3f7e9d96fa
4 changed files with 245 additions and 224 deletions
+5 -224
View File
@@ -1,226 +1,7 @@
/**
* Project-wide TypeScript types.
*
* Source of truth for row and enum shapes is `types/database.ts`, which is
* generated from the live Supabase schema. This file re-exports those types
* with friendlier names and adds composite / convenience types that the
* application layer uses.
*
* To regenerate the underlying types after a schema change:
* supabase gen types typescript --project-id <ref> > types/database.ts
* Compatibility shim. The hand-written domain types moved to `types/domain/*`
* (kept separate from the generated `types/database.ts`). This re-export keeps
* the `@/lib/types` specifier working for existing importers; prefer importing
* from `@/types/domain` in new code.
*/
import type { Tables, Enums } from '@/types/database'
// ─── Table Row Types ───────────────────────────────────────────────────────────
export type Space = Tables<'spaces'>
export type SpaceMember = Tables<'space_members'>
export type Task = Tables<'tasks'>
export type Project = Tables<'projects'>
export type KnowledgeBase = Tables<'knowledge_base'>
export type Secret = Tables<'secrets'>
export type AreaLead = Tables<'area_leads'>
export type Contact = Tables<'contacts'>
export type Payment = Tables<'payments'>
export type CommsChannel = Tables<'comms_channels'>
export type CommsMessage = Tables<'comms_messages'>
export type Integration = Tables<'integrations'>
export type ActivityLog = Tables<'activity_log'>
// ─── Enum Types ────────────────────────────────────────────────────────────────
export type MemberTier = Enums<'member_tier'>
export type MemberRole = Enums<'member_role'>
export type MemberStatus = Enums<'member_status'>
export type TaskType = Enums<'task_type'>
export type TaskStatus = Enums<'task_status'>
export type TaskRecurrence = Enums<'recurrence_type'>
export type ProjectStatus = Enums<'project_status'>
export type KBVisibility = Enums<'kb_visibility'>
export type ContactType = Enums<'contact_type'>
export type PaymentPlatform = Enums<'payment_platform'>
export type PaymentLinkStatus = Enums<'payment_link_status'>
export type ChannelType = Enums<'channel_type'>
export type AreaLeadStatus = Enums<'area_lead_status'>
// ─── Convenience aliases ─────────────────────────────────────────────────────
/** Common projection of `space_members` used by sidebars / props. */
export type MemberSummary = Pick<
SpaceMember,
'id' | 'space_id' | 'user_id' | 'role' | 'display_name' | 'handle'
>
/** Standard return shape for server actions. */
export type ActionResult<T = void> =
| { error: string; data?: undefined; success?: undefined }
| { error?: undefined; data: T; success?: undefined }
| { error?: undefined; data?: undefined; success: true }
// ─── Governance kernel (Tier 1 — migration 016) ──────────────────────────────
// These tables are not yet in types/database.ts (regenerate via supabase CLI
// to surface them in the generated types). Until then, hand-typed here.
export type ProposalType =
| 'bylaw_change'
| 'board_action'
| 'membership_vote'
| 'advisory_poll'
| 'recall'
| 'budget'
export type ProposalStatus =
| 'draft'
| 'open'
| 'decided'
| 'withdrawn'
| 'expired'
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
}
// ─── Re-exports from permissions/auth-helpers for one-stop imports ───────────
export type { Role } from '@/lib/permissions'
export {
ROLES,
ADMIN_ROLES,
TREASURER_ROLES,
ALL_ROLES,
ACTIVE_STATUSES,
hasRole,
} from '@/lib/permissions'
export type {
Member,
Result,
MemberResult,
ServerSupabase,
} from '@/lib/auth-helpers'
export * from '@/types/domain'