Files
faunosteo/packages/supabase/src/anatomical-sheets.ts
T

32 lines
955 B
TypeScript

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
}