IF Commons GitHub

integrations/host/import

Import a slice of an outside vocabulary into a generated TypeScript module (commons 0019-mizan-integrations FR-005 to FR-009), from a manifest written in TypeScript.

bun commons/mizan/src/integrations/host/import.ts MANIFEST.ts write the module the manifest names bun commons/mizan/src/integrations/host/import.ts MANIFEST.ts --check exit 1, writing nothing, where the module is not what the import makes; for a URL source it compares the manifest to the module's header offline, and with --fetch fetches the source and compares fully

The manifest is a module that exports manifest: the pinned standard (issuer, version, license, whether it may be copied, the SHA-256 of the source), the source (a file relative to the manifest, or an https:// URL fetched once and held to the SHA-256 pin, 0019-mizan-integrations FR-014), its format (turtle, n-triples, json-ld, rdf-xml, oscal-catalog or json-schema), the namespace and the slice of local names to take, the out file and the rdfImport specifier of the module that gives namespace and vocabulary. The manifest is read once, here, into a typed record; a finding stops the run with exit 2 and one sentence each.

Source: commons/mizan/src/integrations/host/import.ts

1 of 11 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

integrations.decodeManifestfunctionno test imports it
function decodeManifest(x: unknown): Result<ImportManifest, string>

A manifest module's manifest export, checked once: every field there and of its type, or the sentence that says which is not.

integrations.ImportManifesttypeno test imports it
type ImportManifest = { readonly standard: StandardRecord; readonly source: string; readonly format: "turtle" | "n… (751 characters)
type ImportManifest = {
  readonly standard: StandardRecord;
  readonly source: string;
  readonly format: "turtle" | "n-triples" | "json-ld" | "rdf-xml" | "oscal-catalog" | "json-schema";
  /** The namespace of a vocabulary's terms: required for `turtle`, `n-triples`, `json-ld` and `rdf-xml`, none for an OSCAL catalog (whose slice names control identifiers) or a JSON Schema (whose slice names `$defs`). */
  readonly namespace?: { readonly prefix: string; readonly iri: string };
  readonly slice: readonly string[];
  readonly out: string;
  /** Where the PROV-O record is written, relative to the manifest: beside it, named after `out`, by default. */
  readonly provOut?: string;
  readonly rdfImport: string;
  readonly exportName?: string;
};

What a manifest says, read into a typed record.

integrations.isUrlfunctionno test imports it
function isUrl(source: string): boolean

Whether a source is a URL: https://, or http:// on the loopback address, which only a test serves (the SHA-256 pin holds either to the same bytes).

integrations.readModuleHeaderfunctionno test imports it
function readModuleHeader(moduleText: string): { readonly sha256: string; readonly terms: readonly string[]; } | undefined

What a generated module's header and vocabulary say, read back without the source: its pinned hash and the local names of its terms.

integrations.readSourcefunctionno test imports it
function readSource(source: string, dir: string): Promise<Result<string, string>>

The text of a source: a file relative to the manifest's folder, or the body of an https:// URL; a failure to read it is the sentence that says why.

decodeManifestfunctionno test imports it
function decodeManifest(x: unknown): Result<ImportManifest, string>

A manifest module's manifest export, checked once: every field there and of its type, or the sentence that says which is not.

ImportManifesttypeno test imports it
type ImportManifest = { readonly standard: StandardRecord; readonly source: string; readonly format: "turtle" | "n… (751 characters)
type ImportManifest = {
  readonly standard: StandardRecord;
  readonly source: string;
  readonly format: "turtle" | "n-triples" | "json-ld" | "rdf-xml" | "oscal-catalog" | "json-schema";
  /** The namespace of a vocabulary's terms: required for `turtle`, `n-triples`, `json-ld` and `rdf-xml`, none for an OSCAL catalog (whose slice names control identifiers) or a JSON Schema (whose slice names `$defs`). */
  readonly namespace?: { readonly prefix: string; readonly iri: string };
  readonly slice: readonly string[];
  readonly out: string;
  /** Where the PROV-O record is written, relative to the manifest: beside it, named after `out`, by default. */
  readonly provOut?: string;
  readonly rdfImport: string;
  readonly exportName?: string;
};

What a manifest says, read into a typed record.

isUrlfunctionno test imports it
function isUrl(source: string): boolean

Whether a source is a URL: https://, or http:// on the loopback address, which only a test serves (the SHA-256 pin holds either to the same bytes).

readModuleHeaderfunctionno test imports it
function readModuleHeader(moduleText: string): { readonly sha256: string; readonly terms: readonly string[]; } | undefined

What a generated module's header and vocabulary say, read back without the source: its pinned hash and the local names of its terms.

readSourcefunctionno test imports it
function readSource(source: string, dir: string): Promise<Result<string, string>>

The text of a source: a file relative to the manifest's folder, or the body of an https:// URL; a failure to read it is the sentence that says why.

mainfunction
function main(argv: readonly string[]): Promise<number>

The command line. Returns the exit status: 0, 1 where the module is stale (--check), 2 where the manifest or the import has findings.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.