governance.instantconstno test imports itconst instant: Decoder<string>An ISO 8601 instant with a zone.
The document envelope (0004-grc-documents): everything GRC persists or exchanges is { kind, schema, id, createdAt, provenance, ...body }. defineKind makes the decoder of a kind from the decoders of its body, a registry of kinds holds them by kind, and readDocument reads text or a value through it, knowing exactly the schema each kind has in this release: a document of another schema is an error value that names both, never read by a second reader.
import { createKinds, defineKind, readDocument } from "./document.ts";
import { string } from "@intellectual-frontiers/core";
const note = defineKind("grc.note", "1", { text: string });
const kinds = createKinds();
kinds.register(note);
readDocument(kinds, "{}"); // an error value: the kind is missinggovernance.instantconstno test imports itconst instant: Decoder<string>An ISO 8601 instant with a zone.
governance.provenanceDecoderconstno test imports itconst provenanceDecoder: Decoder<ObjectOf<{ producer: Decoder<ObjectOf<{ name: Decoder<string>; version: Decoder<string>; }, Record<never, never>>>; inputs: Decoder<readonly string[]>; }, { actor: Decoder<string>; }>>Provenance: the producer, what it was made from (ids or digests), and optionally who or what acted.
governance.Provenancetypeno test imports ittype Provenance = Decoded<typeof provenanceDecoder>;Provenance.
governance.Documenttypeno test imports ittype Document = {
readonly kind: string;
readonly schema: string;
readonly id: string;
readonly createdAt: string;
readonly provenance: Provenance;
};What every document has.
governance.DocumentKindtypeno test imports ittype DocumentKind<T extends Document = Document> = {
readonly id: string;
readonly kind: string;
readonly schema: string;
readonly decode: Decoder<T>;
};A kind of document: its decoder, with the one schema it knows. Its id is its kind, the stable id in the registry of kinds.
governance.defineKindfunctionno test imports itfunction defineKind<R extends Fields, O extends Fields = Record<never, never>>(kind: string, schema: string, required: R… (447 characters)function defineKind<R extends Fields, O extends Fields = Record<never, never>>(kind: string, schema: string, required: R, optional?: O | undefined, validate?: ((value: Document & { readonly [K in keyof R]: Decoded<R[K]>; } & { readonly [K in keyof O]?: Decoded<O[K]> | undefined; }) => string | undefined) | undefined): DocumentKind<Document & { readonly [K in keyof R]: Decoded<R[K]>; } & { readonly [K in keyof O]?: Decoded<O[K]> | undefined; }>The kind kind at schema, with a body of these required and optional fields, and optionally a check of the whole that says what is wrong.
governance.Kindstypeno test imports ittype Kinds = Registry<DocumentKind>;A registry of kinds of documents.
governance.createKindsfunctionno test imports itfunction createKinds(): KindsA registry of kinds, empty.
governance.ReadProblemtypeno test imports ittype ReadProblem =
| { readonly kind: "json"; readonly message: string }
| { readonly kind: "no-kind"; readonly found: string }
| { readonly kind: "unknown-kind"; readonly found: string }
| { readonly kind: "schema"; readonly documentKind: string; readonly found: string; readonly expected: string }
| { readonly kind: "decode"; readonly error: DecodeError };Why a document was not read.
governance.readDocumentfunctionno test imports itfunction readDocument(kinds: Kinds, input: unknown): Result<Document, ReadProblem>The document in input (a value, or its JSON text), through the registry; or why it cannot be read.
governance.describeReadProblemfunctionno test imports itfunction describeReadProblem(p: ReadProblem): stringOne sentence for a problem.
governance.PRODUCERconstno test imports itconst PRODUCER: { readonly name: "@intellectual-frontiers/grc"; readonly version: "0.2.0"; }The producer every document of this library names.
governance.provenanceOffunctionno test imports itfunction provenanceOf(inputs?: readonly string[], actor?: string | undefined): ObjectOf<{ producer: Decoder<ObjectOf<{ name: Decoder<string>; version: Decoder<string>; }, Record<never, never>>>; inputs: Decoder<readonly string[]>; }, { actor: Decoder<string>; }>Provenance for a document made here from the documents or digests inputs.
instantconstno test imports itconst instant: Decoder<string>An ISO 8601 instant with a zone.
provenanceDecoderconstno test imports itconst provenanceDecoder: Decoder<ObjectOf<{ producer: Decoder<ObjectOf<{ name: Decoder<string>; version: Decoder<string>; }, Record<never, never>>>; inputs: Decoder<readonly string[]>; }, { actor: Decoder<string>; }>>Provenance: the producer, what it was made from (ids or digests), and optionally who or what acted.
Provenancetypeno test imports ittype Provenance = Decoded<typeof provenanceDecoder>;Provenance.
Documenttypeno test imports ittype Document = {
readonly kind: string;
readonly schema: string;
readonly id: string;
readonly createdAt: string;
readonly provenance: Provenance;
};What every document has.
DocumentKindtypeno test imports ittype DocumentKind<T extends Document = Document> = {
readonly id: string;
readonly kind: string;
readonly schema: string;
readonly decode: Decoder<T>;
};A kind of document: its decoder, with the one schema it knows. Its id is its kind, the stable id in the registry of kinds.
defineKindfunctionfunction defineKind<R extends Fields, O extends Fields = Record<never, never>>(kind: string, schema: string, required: R… (447 characters)function defineKind<R extends Fields, O extends Fields = Record<never, never>>(kind: string, schema: string, required: R, optional?: O | undefined, validate?: ((value: Document & { readonly [K in keyof R]: Decoded<R[K]>; } & { readonly [K in keyof O]?: Decoded<O[K]> | undefined; }) => string | undefined) | undefined): DocumentKind<Document & { readonly [K in keyof R]: Decoded<R[K]>; } & { readonly [K in keyof O]?: Decoded<O[K]> | undefined; }>The kind kind at schema, with a body of these required and optional fields, and optionally a check of the whole that says what is wrong.
Kindstypeno test imports ittype Kinds = Registry<DocumentKind>;A registry of kinds of documents.
createKindsfunctionfunction createKinds(): KindsA registry of kinds, empty.
ReadProblemtypeno test imports ittype ReadProblem =
| { readonly kind: "json"; readonly message: string }
| { readonly kind: "no-kind"; readonly found: string }
| { readonly kind: "unknown-kind"; readonly found: string }
| { readonly kind: "schema"; readonly documentKind: string; readonly found: string; readonly expected: string }
| { readonly kind: "decode"; readonly error: DecodeError };Why a document was not read.
readDocumentfunctionfunction readDocument(kinds: Kinds, input: unknown): Result<Document, ReadProblem>The document in input (a value, or its JSON text), through the registry; or why it cannot be read.
describeReadProblemfunctionfunction describeReadProblem(p: ReadProblem): stringOne sentence for a problem.
PRODUCERconstno test imports itconst PRODUCER: { readonly name: "@intellectual-frontiers/grc"; readonly version: "0.2.0"; }The producer every document of this library names.
provenanceOffunctionno test imports itfunction provenanceOf(inputs?: readonly string[], actor?: string | undefined): ObjectOf<{ producer: Decoder<ObjectOf<{ name: Decoder<string>; version: Decoder<string>; }, Record<never, never>>>; inputs: Decoder<readonly string[]>; }, { actor: Decoder<string>; }>Provenance for a document made here from the documents or digests inputs.