testEveryLexiconIsALexicon

tcmts.dev.lexicons.test.testEveryLexiconIsALexicon · #wxcdxra7 · term

import { authorityOf, checkedLexicon } from "#codebase/tcmts/dev/lexicons";
import { ATTESTATION_KINDS, lexicons, RELEASE_COLLECTION, STAR_COLLECTION } from "#codebase/tcmts/records";

export const testEveryLexiconIsALexicon = () => {
  for (const doc of lexicons) checkedLexicon(doc);
  const ids = lexicons.map((d) => String(d.id)).toSorted();
  const collections = [
    RELEASE_COLLECTION,
    STAR_COLLECTION,
    ...Object.values(ATTESTATION_KINDS),
  ].toSorted();
  if (JSON.stringify(ids) !== JSON.stringify(collections))
    throw new Error(`the lexicons are ${ids}, the collections ${collections}`);
  if (new Set(lexicons.map((d) => authorityOf(String(d.id)))).size !== 1)
    throw new Error("tcm's lexicons are all published under tcm.codes");
  if (authorityOf(RELEASE_COLLECTION) !== "tcm.codes")
    throw new Error(authorityOf(RELEASE_COLLECTION));
  let refused = false;
  try {
    checkedLexicon({
      lexicon: 1,
      id: "codes.tcm.x",
      defs: {
        main: {
          type: "record",
          key: "tid",
          record: { type: "object", properties: { a: { type: "object", properties: {} } } },
        },
      },
    });
  } catch {
    refused = true;
  }
  if (!refused)
    throw new Error("an object inside a record's properties isn't Lexicon, and wasn't refused");
}

uses