testRecordsFitTheLexicon
tcmts.records.test.testRecordsFitTheLexicon · #paoc5sp7 · term
import { RELEASE_COLLECTION, releaseLexicon } from "#codebase/tcmts/records";
import type { ReleaseRecord } from "#codebase/tcmts/records";
export const testRecordsFitTheLexicon = () => {
const r: ReleaseRecord = {
$type: RELEASE_COLLECTION,
package: "geo",
version: "1.2.0",
namespace: "x",
entry: "y",
hashFormat: 2,
notes: "",
sources: ["https://alice.dev"],
createdAt: new Date(0).toISOString(),
};
const props = releaseLexicon.defs.main.record.properties;
const keys = Object.keys(r).filter((k) => k !== "$type");
if (JSON.stringify(keys.toSorted()) !== JSON.stringify(Object.keys(props).toSorted()))
throw new Error(`the record has ${keys}, the lexicon ${Object.keys(props)}`);
for (const k of releaseLexicon.defs.main.record.required)
if (!(k in r)) throw new Error(`no ${k}`);
const types = { string: "string", integer: "number", array: "object" } as const;
for (const [k, p] of Object.entries(props))
if (typeof r[k as keyof ReleaseRecord] !== types[p.type])
throw new Error(`${k} isn't ${p.type}`);
if (releaseLexicon.id !== RELEASE_COLLECTION) throw new Error(releaseLexicon.id);
}
uses