FLEET_SCHEMAconstconst FLEET_SCHEMA: 1The schema the manifest of a store says it is kept at, and the one this code reads and writes.
The documents of a fleet store (commons estate 0005-estate-fleet-documents): what is kept of an estate in a store, one typed document each, with the schema that reads it and the layout that names it written as code. An asset is a document of its own and is read back through defineAsset, so a stored asset that breaks a rule of the estate is a finding and never a value. An observation is one document that is written once; a declaration and the risks accepted of an asset are one document each, changed only by a write that expects the revision it read; a reference to evidence holds the digest, never the bytes, which stay in the evidence stores of grc; and a manifest says what the store is and at which schema it is kept.
import { assetCodec, ASSETS } from "./documents.ts";
ASSETS; // "assets"
assetCodec.mediaType; // "application/json"FLEET_SCHEMAconstconst FLEET_SCHEMA: 1The schema the manifest of a store says it is kept at, and the one this code reads and writes.
FLEET_LAYOUTconstconst FLEET_LAYOUT: 1The layout of the folders: the paths below, as this code names them.
ASSETSconstno test imports itconst ASSETS: PrefixWhere the assets are: assets/<first character>/<id>.json.
OBSERVATIONSconstno test imports itconst OBSERVATIONS: PrefixWhere the observations are: observations/<asset>/<instant>.json.
DECLARATIONSconstno test imports itconst DECLARATIONS: PrefixWhere the declarations are: declarations/<first character>/<asset>.json.
ACCEPTANCESconstno test imports itconst ACCEPTANCES: PrefixWhere the accepted risks are: acceptances/<first character>/<asset>.json.
EVIDENCEconstno test imports itconst EVIDENCE: PrefixWhere the references to evidence are: evidence/<asset>/<digest>.json.
ROOT_FOLDERconstno test imports itconst ROOT_FOLDER: PrefixThe folder of the manifest, which is the root.
jsonValueconstno test imports itconst jsonValue: Decoder<Json>A decoder of a JSON value, no deeper than 32 levels.
instantTextconstno test imports itconst instantText: Decoder<string>A decoder of an instant: a UTC instant in the form YYYY-MM-DDTHH:MM:SS[.fff]Z that the calendar has.
instantOffunctionfunction instantOf(ms: number): stringThe instant of a time in milliseconds, in the one form the documents use.
observationKeyfunctionfunction observationKey(at: string): Result<DocId, string>The compact form of an instant that names an observation: the same characters with the hyphens and colons left out, so that the names sort as the instants do.
inputOffunctionfunction inputOf(asset: Asset): AssetInputThe input an asset is made from: the owners of the capabilities it offers.
assetCodecconstconst assetCodec: Codec<Asset>The codec of an asset document.
StoredResulttypeno test imports ittype StoredResult = { readonly id: string; readonly status: "pass" | "fail" | "warn" | "unknown"; readonly controls: readonly string[] };What a policy found, as a document keeps it.
StoredObservationtypeno test imports ittype StoredObservation = {
readonly asset: string;
readonly at: string;
readonly source: string;
readonly state: Readonly<Record<string, Json>>;
readonly results: readonly StoredResult[];
};An observation as it is kept: of which asset, when, attributed to which source, the keyed records seen and the results of the policies.
observationCodecconstconst observationCodec: Codec<StoredObservation>The codec of an observation document.
StoredDeclarationtypeno test imports ittype StoredDeclaration = { readonly asset: string; readonly declared: Readonly<Record<string, Json>>; readonly by: string; readonly at: string };What is declared of an asset, who declared it and when.
declarationCodecconstconst declarationCodec: Codec<StoredDeclaration>The codec of a declaration document.
StoredRisktypeno test imports ittype StoredRisk = { readonly policy: string; readonly reason: string; readonly by: string; readonly until: string };One risk a person accepted of an asset.
StoredAcceptancestypeno test imports ittype StoredAcceptances = { readonly asset: string; readonly risks: readonly StoredRisk[] };The risks accepted of an asset, by policy.
acceptancesCodecconstconst acceptancesCodec: Codec<StoredAcceptances>The codec of an accepted-risks document.
StoredEvidencetypeno test imports ittype StoredEvidence = {
readonly subject: string;
readonly digest: string;
readonly store: string;
readonly type: string;
readonly observedAt: string;
readonly mediaType?: string;
readonly size?: number;
readonly producer?: string;
};A reference to evidence kept in an evidence store: the digest of its bytes, the store, what it is about and what kind it is. The bytes are never here.
evidenceCodecconstconst evidenceCodec: Codec<StoredEvidence>The codec of an evidence-reference document.
Manifesttypeno test imports ittype Manifest = { readonly store: string; readonly schema: number; readonly layout: number; readonly created: string };What a store says it is: which fleet, at which schema and layout it is kept, and when it was made.
manifestCodecconstconst manifestCodec: Codec<Manifest>The codec of the manifest. It is read at any schema, so that a newer store is refused with a reason and not as an unreadable file.
MANIFEST_KEYconstno test imports itconst MANIFEST_KEY: DocIdThe key of the manifest, fleet.json at the root.
shardedByIdconstconst shardedById: Layout<DocId>The layout of the assets, declarations and accepted risks: one file for each asset below a folder of the first character of its identity, so that an identity of any length has a place.
flatByIdconstconst flatById: Layout<DocId>The layout of the manifest and of the observations of one asset: one file for each key directly below the folder.
docIdOffunctionno test imports itfunction docIdOf(asset: string): Result<DocId, string>The identity of a document of an asset: the asset's identity, which is a document name.