LoadIdtypeno test imports ittype LoadId = Brand<string, "LoadId">;The identity of one load, as the consumer names it.
The ledger port of exchange (commons integrations 0006-integrations-exchange): a typed record of functions, each returning a Result, with which a consumer keeps the trail of a load without the library knowing where it is kept (a database, a file, memory). It appends stage events, checks the intake of a content by its hash, and records the outcome of a validation or an acknowledgement by code. A stage is an opaque branded text: the consumer's code list of stages lives with the consumer, not here. An event never carries a payload value: its fields are identifiers, a code, an instant and a digest, each made by a smart constructor that admits no free text.
LoadIdtypeno test imports ittype LoadId = Brand<string, "LoadId">;The identity of one load, as the consumer names it.
Stagetypeno test imports ittype Stage = Brand<string, "Stage">;A stage of the consumer's pipeline, an opaque code such as RECEIVED or VALIDATED.
OutcomeCodetypeno test imports ittype OutcomeCode = Brand<string, "OutcomeCode">;A code that says why, or what came of a check: lower-case words joined by dashes.
ItemKeytypeno test imports ittype ItemKey = Brand<string, "ItemKey">;The key that names the same item across loads (a message id, a control number): what two contents of one item share.
parseLoadIdconstconst parseLoadId: (t: string) => Result<LoadId, IdError>A load id: letters, digits and . _ : -, up to 128. Free text is refused, and the refusal does not repeat it.
parseStageconstconst parseStage: (t: string) => Result<Stage, IdError>A stage: upper-case words joined by underscores.
parseOutcomeCodeconstconst parseOutcomeCode: (t: string) => Result<OutcomeCode, IdError>An outcome or reason code.
parseItemKeyconstconst parseItemKey: (t: string) => Result<ItemKey, IdError>An item key.
LedgerEventtypeno test imports ittype LedgerEvent = { readonly loadId: LoadId; readonly stage: Stage; readonly reasonCode?: OutcomeCode; readonly at: Instant; readonly contentHash?: Sha256 };One event of a load: a stage reached, with a reason code and a digest where there are any. Never a payload value.
IntakeRequesttypeno test imports ittype IntakeRequest = { readonly loadId: LoadId; readonly itemKey: ItemKey; readonly contentHash: Sha256; readonly at: Instant };What a content is, on intake.
Intaketypeno test imports ittype Intake = { readonly kind: "first-seen" } | { readonly kind: "duplicate"; readonly of: LoadId } | { readonly kind: "conflict"; readonly with: LoadId };What the ledger says of a content on intake: never seen; the same content seen before (in the load named); or another content of the same item (in the load named).
OutcomeKindtypeno test imports ittype OutcomeKind = "validation" | "acknowledgement";Which check an outcome is of.
OutcomeRecordtypeno test imports ittype OutcomeRecord = { readonly loadId: LoadId; readonly kind: OutcomeKind; readonly code: OutcomeCode; readonly at: Instant };The outcome of a check, by code.
LedgerErrortypeno test imports ittype LedgerError = { readonly kind: "unavailable" } | { readonly kind: "unknown-load"; readonly loadId: LoadId };Why the ledger could not answer.
LedgerPorttypetype LedgerPort = {
readonly append: (event: LedgerEvent) => Promise<Result<void, LedgerError>>;
readonly intake: (r… (459 characters)type LedgerPort = {
readonly append: (event: LedgerEvent) => Promise<Result<void, LedgerError>>;
readonly intake: (request: IntakeRequest) => Promise<Result<Intake, LedgerError>>;
readonly outcome: (record: OutcomeRecord) => Promise<Result<void, LedgerError>>;
readonly events: (loadId: LoadId) => Promise<Result<readonly LedgerEvent[], LedgerError>>;
readonly outcomes: (loadId: LoadId) => Promise<Result<readonly OutcomeRecord[], LedgerError>>;
};The ledger port.
memoryLedgerfunctionfunction memoryLedger(): LedgerPortA ledger in memory.
LedgerFindingtypeno test imports ittype LedgerFinding = { readonly rule: string; readonly message: string };What a ledger conformance finds wrong.
conformLedgerfunctionfunction conformLedger(make: () => LedgerPort, ids: { readonly load: (n: number) => LoadId; readonly stage: (name: string) => Stage; readonly code: (name: string) => OutcomeCode; readonly key: (n: number) => ItemKey; readonly hash: (n: number) => Sha256; readonly at: Instant; }): Promise<readonly LedgerFinding[]>The conformance suite of a ledger: make gives a fresh, empty ledger each time. It finds a ledger that does not keep events in the order appended, that does not tell first-seen from duplicate from conflict, that accepts an outcome for a load it has no event of, or that does not keep outcomes. Any implementation (memory, a database) runs it.