Metakit / API

@doeixd/metakit/artifact

Portable semantic artifacts (@doeixd/metakit/artifact).

Encodes and decodes the portable subset of MetaKit Expr nodes as versioned Effect Schema values: paths, JSON-safe literals, bound Rows variables, core/foreign calls by stable (id, version), conditionals, and matches.

Never serializes JavaScript closures (Opaque), raw SchemaAST internals, or interpreter functions, and never fabricates Expr<Env, A> without validating wire shape, size/depth limits, operator registry & allowlist, path scope, arity, and result kind against the caller's Schemas.

Bundles write an expression or a transition for a reader outside JavaScript, in one profile (docs/bundles.md).

Namespaces

DEFAULT_LIMITSDefault resource bounds for portable artifacts.
HashThe one place MetaKit hashes a definition: the canonical JSON rules, the domain tags and SHA-256. The rules are written out in docs/semantics.md ("Content…

Functions

canonicalizeNodeDeterministic canonical form of a PortableNode: literal object keys sorted, while strictly preserving evaluation order, If/Match branch order, and operator…
canonicalJsonThe canonical JSON of a PortableArtifactV1 (Hash.canonical of its canonical form). Fails with Unhashable for a hand-built artifact holding a leaf JSON…
decodeBundleRead a bundle written by encodeExprBundle or encodeTransitionBundle, applying every check its encoder applies: the size bound counted the same way, the…
decodeExprDecode and validate a wire artifact into a typed Expr<EnvOf<Shape>, R['Type']> over a multi-slice environment { slice: Schema }.
decodeForSchemaDecode and validate a wire artifact into a typed Expr<S['Type'], R['Type']> over a single Schema.
encodeExprEncode an Expr into a versioned PortableArtifactV1. Rejects Opaque nodes, non-portable literals (NaN, Infinity, -0, functions, symbols, class instances),…
encodeExprBundleWrite expr as a bundle of profile (Language.safeIntK3), its paths read against env, the Schema of each slice ({ row: Account }).
encodeTransitionBundleWrite transition as a bundle of profile, its paths read against { state, input, supplied } built from its Schemas. A write is stated with its target's kind…
evidenceKeyCompute an EvidenceKey (ev:sha256:<hex>, domain metakit/evidence@1) for caching reader/verifier results. Returns Option.none() if any required foreign op…
fingerprintCompute the deterministic ArtifactFingerprint (sha256:<hex>, domain metakit/expr@3) of an Expr or an already-encoded PortableArtifactV1: its canonical…
fnHashesA function's executable and contract hashes. The executable hash (metakit/fn@1) covers what decides a call: its parameters' names and interfaces (by name),…
machineHashesA machine's executable and contract hashes. The executable hash (metakit/machine@1) is each message tag with its transition's executable hash, sorted by…
operationFingerprintThe definition hash (sha256:<hex>, domain metakit/operation@1) of a derived operation: what decides a call's outcome. That is its parameters' names and…
operationHashesA derived operation's executable and contract hashes. The executable hash is operationFingerprint's (metakit/operation@1), which every call of it holds. The…
registryBuild an OperationRegistry from Operations and/or Languages. Identical or signature-compatible duplicate registrations are idempotent; conflicting…
schemaFingerprintHash schema's interface (domain metakit/schema@1): the value EvidenceKeyInput.schemaFingerprint takes for a target's Schema.
schemaInterfaceThe interface of schema's decoded side, as a canonical value: two Schemas that differ only in documentation, names or field order have equal interfaces.…
transitionHashesA transition's executable and contract hashes. The executable hash (metakit/transition@4) covers its guard, writes and emits, and the interface of each path…

Values

BundleNodeOne entry of a bundle's node table. A child is the index of an earlier entry. A Path holds the interface of the Schema it was built with (schemaInterface),…
CODEC_VERSIONCurrent wire format version for portable expression artifacts.
emptyRegistryRegistry with no foreign operations (core operators only).
PortableArtifactV1
PortableBundleV1A bundle of either kind, as decodeBundle reads it.
PortableExprBundleV1An expression's bundle: node is its root in nodes.
PortableLiteral
PortableNodeSchema
PortableOpRef
PortableSlotOne path a bundle reads: the host supplies one value of it per call.
PortableTransitionBundleV1A transition's bundle: each expression a step evaluates is a root in nodes. ensures is left out, as the executable hash leaves it out: no step evaluates it,…
WriteRequirementWhat the state before a step must hold, read from one slot, for a write to go; where one fails the step refuses as Unwritable (docs/semantics.md, §6 step…

Classes

ArtifactDecodeErrorA wire artifact failed version, schema, scope, arity, or result-type validation.
ArtifactLimitErrorAn artifact exceeded a configured resource limit.
BundleRefusedErrorA definition is outside the profile, a path it reads cannot be a slot, a write cannot be stated, or (decode only) the fingerprint is not the one its content…
DuplicateOperationErrorTwo incompatible operations were registered under the same id@version.
EvidenceStoreA key-value store of evidence. Prove.machine and Prove.fn read it where it is provided and prove as before where it is not; @doeixd/metakit/sql/stored needs…
UnknownOperationErrorAn artifact referenced an unknown, unregistered, or disallowed operator.
UnsupportedNodeErrorA node or literal value lies outside the portable subset: an Opaque node, a literal such as NaN or a function ('Lit'), or a bound read outside its fold…

Interfaces

AllowlistPolicyPolicy controlling which operators an externally received artifact may invoke.
ArtifactLimitsBounds enforced during both encoding and decoding to guard against hostile inputs.
DecodeBaseOptions
DecodeEnvOptions
DecodeSchemaOptions
DefinitionHashesA definition's two hashes (docs/semantics.md, "Executable and contract hashes").
EncodeOptions
EvidenceKeyInputInputs that decide whether cached execution/verification evidence may be reused.
FnDefinitionA function as its hashes read it: what Fn.params(...)…body(...) builds.
MachineDefinitionA machine as its hashes read it: its state Schema, its start and its arms by message tag.
OperationRegistryImmutable registry resolving (id, version) to declared AnyOperations.
TransitionDefinitionA transition as its contract hash reads it: its terms and the Schemas a proof of it assumes.

Types

ArtifactError
ArtifactFingerprintContent fingerprint of a canonical portable expression artifact (sha256:<hex>).
BundleError
EncodeError
EvidenceKeyCache key for reader/verification evidence (ev:sha256:<hex>). Distinct from a definition's hash: includes reader identity/version, backend profile, schema…
OperationFingerprintContent hash of a derived operation's definition (sha256:<hex>, domain metakit/operation@1).
PortableNode
PortableRowsOver
RegistrySourceSource accepted by Artifact.registry: a single Operation or a Language.
SchemaFingerprintHash of a Schema's interface (sha256:<hex>, domain metakit/schema@1).
SchemaInterfaceThe canonical interface of a Schema, as schemaInterface writes it.