Metakit / API

@doeixd/metakit/fn

@doeixd/metakit/fn: pure, Schema-typed, callable MetaKit functions with Design-by-Contract preconditions (where), return Schemas (returns), and postconditions (ensures).

Calling a Fn inside an expression substitutes its argument ASTs directly into body (zero new CoreOpIds), so SQL, Drizzle, Tier 2 residualize, Tier 3 Zone, and Tier 4 Z3 all see straight through it. Prove.fn verifies where => returns && ensures once in Z3.

Functions

andConjunction (f && g) of two boolean predicate Fns, merging their parameters, preconditions, and obligations.
composeSequential composition (g ∘ f).
constantConstant Fn ignoring paramSchemas and always returning value.
contramapAdapt f to a new parameter schema newParams by mapping inputs through mapArgs. Strict, as a call is: a mapped argument that refuses makes the call refuse…
guardWrap body in nested fallback-free Match guards for each condition in order. A condition evaluating to false or null refuses unmatched with contract in its…
guardOfRecognise a contract guard by its shape, including one built by hand.
identityIdentity Fn for a single parameter { value: S }.
ifElseConditional branching combinator: evaluates onTrue when cond is true, onFalse when cond is false, and null when cond is null. Each branch's preconditions…
impliesLogical implication (f => g, i.e. !f || g) of two boolean predicate Fns.
iterateStatic n-fold composition of a single-parameter endomorphism f (f(f(...f(x)))). Statically unrolled so it remains terminating, SQL-lowerable, and Z3-verifiable.
makeDefine a callable MetaKit function from named parameter Schemas and a body expression.
mapTransform f's output expression while preserving params, whereClauses, and intermediate obligations.
notNegate a boolean predicate Fn.
orDisjunction (f || g) of two boolean predicate Fns, merging their parameters, preconditions, and obligations.
paramsStart a signature-first function specification from named parameter Schemas.
partialPartial application: fix a subset of f's parameters to concrete literals, returning a specialized Fn over the remaining parameters with body, whereClauses,…

Values

DEFAULT_MAX_EXPANSION_NODESDefault AST node occurrence budget for Fn.iterate unrolling.
GuardSubjectThe value a guarded call checks: a parameter, a composed function's obligation, or the result.
ProjectedFromThe kind of node a projection could not reach into.
UnstatedWhy a call could not be built: a guard check it cannot state, or an argument it cannot substitute.

Classes

FnContractErrorError returned by fn.runChecked when a contract boundary fails at runtime.
UnstatedGuardA call a function cannot build: a check it cannot state as a guard, or an argument it cannot substitute. Match on reason for the cause.

Interfaces

EnsuresEnvEnvironment available inside Fn.ensures: { params, result }.
EnsuresPathsPath accessors passed to Fn.ensures.
FnA callable, inspectable, verifiable MetaKit function.
FnObligationScoped intermediate contract obligation preserved across Fn composition (compose, map, not, and, or, ifElse, partial, contramap).
FnSpecSignature-first specification built with Fn.params(...) before attaching .body(...).
GuardA single contract guard recognised by its node shape.

Types

ArgInputsArgument inputs accepted when calling a Fn symbolically inside an expression.
DeferredArgsExpressions for every parameter. Pass Expr.lit(null) for an absent optional parameter.
MergedArgEnvMerged environment of all symbolic argument expressions passed to a Fn call.
ParamPathsPath accessors passed to body and where builders.
ParamSchemasA record mapping parameter names to Effect Schemas.
ParamValuesRuntime value record for parameter schemas P.
ReturnCarrierUnderlying carrier type accepted when a body or argument feeds a declared Schema type R: