feat(supabase): regenerated types, row aliases, publishSheetVersion gate, schema test

This commit is contained in:
bchanot committed 2026-10-08 23:42:44 +02:00
1 parent f4ceaf68f9
commit 8cac8b1a68
6 files changed
+510 -8

No files matched your search

@@ -0,0 +1,31 @@
import {
AnatomicalSheetDocumentSchema,
assertPublishable,
} from '@faunosteo/domain'
import type { FaunosteoClient } from './client'
/**
* Publication gate on the client side: the full Zod shape and every
* integrity rule run before the RPC, so the editor gets the complete issue
* list. The database re-checks the referential rules on its own
* (private.sheet_document_issues); this call never replaces that guard.
*/
export async function publishSheetVersion(
client: FaunosteoClient,
versionId: string,
): Promise<string> {
const draft = await client
.from('anatomical_sheet_versions')
.select('content')
.eq('id', versionId)
.single()
if (draft.error) throw draft.error
assertPublishable(AnatomicalSheetDocumentSchema.parse(draft.data.content))
const published = await client.rpc('publish_sheet_version', {
version_id: versionId,
})
if (published.error) throw published.error
return published.data
}
+306
View File
@@ -9,6 +9,230 @@ export type Json =
export type Database = {
public: {
Tables: {
anatomical_sheet_assets: {
Row: {
byte_size: number
content_type: string
created_at: string
created_by: string | null
file_name: string
id: string
sha256: string
sheet_id: string
}
ComputedFields: never
Insert: {
byte_size: number
content_type?: string
created_at?: string
created_by?: string | null
file_name: string
id?: string
sha256: string
sheet_id: string
}
Update: {
byte_size?: number
content_type?: string
created_at?: string
created_by?: string | null
file_name?: string
id?: string
sha256?: string
sheet_id?: string
}
Relationships: [
{
foreignKeyName: 'anatomical_sheet_assets_created_by_fkey'
columns: ['created_by']
isOneToOne: false
referencedRelation: 'profiles'
referencedColumns: ['id']
},
{
foreignKeyName: 'anatomical_sheet_assets_sheet_id_fkey'
columns: ['sheet_id']
isOneToOne: false
referencedRelation: 'anatomical_sheets'
referencedColumns: ['id']
},
]
}
anatomical_sheet_versions: {
Row: {
change_note: string
content: NonNullable<Json>
created_at: string
created_by: string | null
deprecated_at: string | null
deprecated_by: string | null
document_schema_version: number
id: string
published_at: string | null
published_by: string | null
sheet_id: string
status: Database['public']['Enums']['sheet_version_status']
updated_at: string
version_number: number
}
ComputedFields: never
Insert: {
change_note?: string
content: NonNullable<Json>
created_at?: string
created_by?: string | null
deprecated_at?: string | null
deprecated_by?: string | null
document_schema_version: number
id?: string
published_at?: string | null
published_by?: string | null
sheet_id: string
status?: Database['public']['Enums']['sheet_version_status']
updated_at?: string
version_number: number
}
Update: {
change_note?: string
content?: NonNullable<Json>
created_at?: string
created_by?: string | null
deprecated_at?: string | null
deprecated_by?: string | null
document_schema_version?: number
id?: string
published_at?: string | null
published_by?: string | null
sheet_id?: string
status?: Database['public']['Enums']['sheet_version_status']
updated_at?: string
version_number?: number
}
Relationships: [
{
foreignKeyName: 'anatomical_sheet_versions_created_by_fkey'
columns: ['created_by']
isOneToOne: false
referencedRelation: 'profiles'
referencedColumns: ['id']
},
{
foreignKeyName: 'anatomical_sheet_versions_deprecated_by_fkey'
columns: ['deprecated_by']
isOneToOne: false
referencedRelation: 'profiles'
referencedColumns: ['id']
},
{
foreignKeyName: 'anatomical_sheet_versions_published_by_fkey'
columns: ['published_by']
isOneToOne: false
referencedRelation: 'profiles'
referencedColumns: ['id']
},
{
foreignKeyName: 'anatomical_sheet_versions_sheet_id_fkey'
columns: ['sheet_id']
isOneToOne: false
referencedRelation: 'anatomical_sheets'
referencedColumns: ['id']
},
]
}
anatomical_sheets: {
Row: {
archived_at: string | null
based_on_sheet_id: string | null
based_on_version_id: string | null
created_at: string
creator_user_id: string | null
current_version_id: string | null
deleted_at: string | null
description: string
id: string
is_official: boolean
name: string
slug: string
species_id: string
status: Database['public']['Enums']['sheet_status']
updated_at: string
visibility: Database['public']['Enums']['sheet_visibility']
}
ComputedFields: never
Insert: {
archived_at?: string | null
based_on_sheet_id?: string | null
based_on_version_id?: string | null
created_at?: string
creator_user_id?: string | null
current_version_id?: string | null
deleted_at?: string | null
description?: string
id?: string
is_official?: boolean
name: string
slug: string
species_id: string
status?: Database['public']['Enums']['sheet_status']
updated_at?: string
visibility?: Database['public']['Enums']['sheet_visibility']
}
Update: {
archived_at?: string | null
based_on_sheet_id?: string | null
based_on_version_id?: string | null
created_at?: string
creator_user_id?: string | null
current_version_id?: string | null
deleted_at?: string | null
description?: string
id?: string
is_official?: boolean
name?: string
slug?: string
species_id?: string
status?: Database['public']['Enums']['sheet_status']
updated_at?: string
visibility?: Database['public']['Enums']['sheet_visibility']
}
Relationships: [
{
foreignKeyName: 'anatomical_sheets_based_on_sheet_id_fkey'
columns: ['based_on_sheet_id']
isOneToOne: false
referencedRelation: 'anatomical_sheets'
referencedColumns: ['id']
},
{
foreignKeyName: 'anatomical_sheets_based_on_version_fkey'
columns: ['based_on_version_id']
isOneToOne: false
referencedRelation: 'anatomical_sheet_versions'
referencedColumns: ['id']
},
{
foreignKeyName: 'anatomical_sheets_creator_user_id_fkey'
columns: ['creator_user_id']
isOneToOne: false
referencedRelation: 'profiles'
referencedColumns: ['id']
},
{
foreignKeyName: 'anatomical_sheets_current_version_fkey'
columns: ['current_version_id']
isOneToOne: false
referencedRelation: 'anatomical_sheet_versions'
referencedColumns: ['id']
},
{
foreignKeyName: 'anatomical_sheets_species_id_fkey'
columns: ['species_id']
isOneToOne: false
referencedRelation: 'species'
referencedColumns: ['id']
},
]
}
profile_roles: {
Row: {
granted_at: string
@@ -108,11 +332,76 @@ export type Database = {
}
Relationships: []
}
species: {
Row: {
active: boolean
created_at: string
id: string
name_en: string
name_fr: string
sort_order: number
}
ComputedFields: never
Insert: {
active?: boolean
created_at?: string
id: string
name_en: string
name_fr: string
sort_order?: number
}
Update: {
active?: boolean
created_at?: string
id?: string
name_en?: string
name_fr?: string
sort_order?: number
}
Relationships: []
}
}
Views: {
[_ in never]: never
}
Functions: {
archive_anatomical_sheet: { Args: { sheet_id: string }; Returns: string }
create_anatomical_sheet: {
Args: {
description?: string
document: Json
name: string
official?: boolean
slug: string
species_id: string
visibility?: Database['public']['Enums']['sheet_visibility']
}
Returns: string
}
create_sheet_draft: {
Args: {
change_note?: string
from_version_id?: string
sheet_id: string
}
Returns: string
}
delete_anatomical_sheet: { Args: { sheet_id: string }; Returns: string }
delete_sheet_asset: { Args: { asset_id: string }; Returns: string }
delete_sheet_version: { Args: { version_id: string }; Returns: string }
deprecate_sheet_version: {
Args: { reason?: string; version_id: string }
Returns: string
}
fork_anatomical_sheet: {
Args: {
name: string
slug: string
source_version_id: string
visibility?: Database['public']['Enums']['sheet_visibility']
}
Returns: string
}
grant_platform_role: {
Args: {
role: Database['public']['Enums']['platform_role']
@@ -120,6 +409,17 @@ export type Database = {
}
Returns: string
}
publish_sheet_version: { Args: { version_id: string }; Returns: string }
register_sheet_asset: {
Args: {
byte_size: number
file_name: string
sha256: string
sheet_id: string
}
Returns: string
}
restore_anatomical_sheet: { Args: { sheet_id: string }; Returns: string }
revoke_platform_role: {
Args: {
reason?: string
@@ -131,6 +431,9 @@ export type Database = {
}
Enums: {
platform_role: 'owner' | 'admin' | 'moderator' | 'support'
sheet_status: 'active' | 'archived' | 'deleted'
sheet_version_status: 'draft' | 'published' | 'deprecated'
sheet_visibility: 'private' | 'public'
}
CompositeTypes: {
[_ in never]: never
@@ -259,6 +562,9 @@ export const Constants = {
public: {
Enums: {
platform_role: ['owner', 'admin', 'moderator', 'support'],
sheet_status: ['active', 'archived', 'deleted'],
sheet_version_status: ['draft', 'published', 'deprecated'],
sheet_visibility: ['private', 'public'],
},
},
} as const
+16
View File
@@ -21,3 +21,19 @@ export type Profile = Tables<'profiles'>
export type ProfileRole = Tables<'profile_roles'>
/** owner | admin | moderator | support. Not a professional status. */
export type PlatformRole = Enums<'platform_role'>
export { publishSheetVersion } from './anatomical-sheets'
/** Row of public.species. */
export type Species = Tables<'species'>
/** Row of public.anatomical_sheets. */
export type AnatomicalSheet = Tables<'anatomical_sheets'>
/** Row of public.anatomical_sheet_versions (content = canonical document). */
export type AnatomicalSheetVersion = Tables<'anatomical_sheet_versions'>
/** Row of public.anatomical_sheet_assets. */
export type AnatomicalSheetAsset = Tables<'anatomical_sheet_assets'>
/** private | public. */
export type SheetVisibility = Enums<'sheet_visibility'>
/** active | archived | deleted. */
export type SheetStatus = Enums<'sheet_status'>
/** draft | published | deprecated. */
export type SheetVersionStatus = Enums<'sheet_version_status'>