2026-10-15 02:19:38 -07:00
import { writeFile } from "node:fs/promises" ;
import { dirname , join , resolve } from "node:path" ;
import { fileURLToPath , pathToFileURL } from "node:url" ;
2026-10-20 18:09:28 +08:00
// Record built-in catalog profile digests into the compiled runtime. Run after
2026-10-15 02:19:38 -07:00
// `tsc` and before bundling, so the digests come from the same compiled
// contracts and pinned schema converter that the runtime serves.
const compiledRoot = resolve (
dirname ( fileURLToPath ( import . meta . url )),
"../dist" ,
);
2026-10-20 18:09:28 +08:00
const { createCatalogDigestProfiles } = await import (
2026-10-15 02:19:38 -07:00
pathToFileURL ( join ( compiledRoot , "catalogIdentity.js" )). href
);
2026-10-20 18:09:28 +08:00
// Retain only hashes, with every shared record frozen. Schemas remain owned by
// the compiled contracts and are converted once for all four identities.
const profiles = Object . entries ( createCatalogDigestProfiles ())
. map (
([ input , outputs ]) =>
` ${ JSON . stringify ( input ) } : Object.freeze({ ${ Object . entries ( outputs )
. map (
([ output , digests ]) =>
` ${ JSON . stringify ( output ) } : Object.freeze( ${ JSON . stringify ( digests ) } )` ,
)
. join ( "," ) } })` ,
)
. join ( "," );
2026-10-15 02:19:38 -07:00
await writeFile (
join ( compiledRoot , "recordedCatalogDigests.js" ),
2026-10-20 18:09:28 +08:00
`/** Recorded from compiled catalog profiles by scripts/record-catalog-digests.mjs; do not edit. */\nexport const RECORDED_CATALOG_DIGEST_PROFILES = Object.freeze({ ${ profiles } });\n` ,
2026-10-15 02:19:38 -07:00
"utf8" ,
);