74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { join, resolve } from 'node:path'
|
|
import {
|
|
AnatomicalSheetDocumentSchema,
|
|
ReportMigrationMapSchema,
|
|
type ReportMigrationMap,
|
|
type SnapshotSource,
|
|
} from '../../src'
|
|
|
|
/**
|
|
* The committed equine draft (`pnpm import:equine`) as the application
|
|
* bundles it: document, reference, SVG assets and their manifest hashes,
|
|
* plus the v2 → v3 migration map. Read from the seed, never copied.
|
|
*/
|
|
|
|
export const DRAFT_DIR = resolve(
|
|
fileURLToPath(import.meta.url),
|
|
'../../../../../supabase/seed/anatomical-sheets/equine/draft',
|
|
)
|
|
|
|
interface SeedRef {
|
|
sheet_id: string
|
|
version_id: string | null
|
|
document_sha256: string
|
|
schema_version: number
|
|
species_id: string
|
|
}
|
|
|
|
interface SeedAsset {
|
|
file: string
|
|
sha256: string
|
|
svg_asset_id: string
|
|
}
|
|
|
|
function json<T>(name: string): T {
|
|
return JSON.parse(readFileSync(join(DRAFT_DIR, name), 'utf8')) as T
|
|
}
|
|
|
|
export interface DraftSheet extends SnapshotSource {
|
|
assetHashes: Readonly<Record<string, string>>
|
|
migrationMap: ReportMigrationMap
|
|
}
|
|
|
|
export function loadDraftSheet(): DraftSheet {
|
|
const ref = json<SeedRef>('sheet-ref.json')
|
|
const manifest = json<SeedAsset[]>('assets.json')
|
|
const assets: Record<string, string> = {}
|
|
const assetHashes: Record<string, string> = {}
|
|
for (const asset of manifest) {
|
|
assets[asset.svg_asset_id] = readFileSync(
|
|
join(DRAFT_DIR, 'assets', asset.file),
|
|
'utf8',
|
|
)
|
|
assetHashes[asset.svg_asset_id] = asset.sha256
|
|
}
|
|
return {
|
|
status: 'draft',
|
|
ref: {
|
|
sheetId: ref.sheet_id,
|
|
versionId: ref.version_id,
|
|
documentSha256: ref.document_sha256,
|
|
},
|
|
speciesId: ref.species_id,
|
|
schemaVersion: ref.schema_version,
|
|
document: AnatomicalSheetDocumentSchema.parse(json('document.json')),
|
|
assets,
|
|
assetHashes,
|
|
migrationMap: ReportMigrationMapSchema.parse(
|
|
json('report-migration-map.json'),
|
|
),
|
|
}
|
|
}
|