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
and | Conjunction (f && g) of two boolean predicate Fns, merging their parameters, preconditions, and obligations. |
compose | Sequential composition (g ∘ f). |
constant | Constant Fn ignoring paramSchemas and always returning value. |
contramap | Adapt 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… |
guard | Wrap 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… |
guardOf | Recognise a contract guard by its shape, including one built by hand. |
identity | Identity Fn for a single parameter { value: S }. |
ifElse | Conditional branching combinator: evaluates onTrue when cond is true, onFalse when cond is false, and null when cond is null. Each branch's preconditions… |
implies | Logical implication (f => g, i.e. !f || g) of two boolean predicate Fns. |
iterate | Static n-fold composition of a single-parameter endomorphism f (f(f(...f(x)))). Statically unrolled so it remains terminating, SQL-lowerable, and Z3-verifiable. |
make | Define a callable MetaKit function from named parameter Schemas and a body expression. |
map | Transform f's output expression while preserving params, whereClauses, and intermediate obligations. |
not | Negate a boolean predicate Fn. |
or | Disjunction (f || g) of two boolean predicate Fns, merging their parameters, preconditions, and obligations. |
params | Start a signature-first function specification from named parameter Schemas. |
partial | Partial 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_NODES | Default AST node occurrence budget for Fn.iterate unrolling. |
GuardSubject | The value a guarded call checks: a parameter, a composed function's obligation, or the result. |
ProjectedFrom | The kind of node a projection could not reach into. |
Unstated | Why a call could not be built: a guard check it cannot state, or an argument it cannot substitute. |
Classes
FnContractError | Error returned by fn.runChecked when a contract boundary fails at runtime. |
UnstatedGuard | A 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
EnsuresEnv | Environment available inside Fn.ensures: { params, result }. |
EnsuresPaths | Path accessors passed to Fn.ensures. |
Fn | A callable, inspectable, verifiable MetaKit function. |
FnObligation | Scoped intermediate contract obligation preserved across Fn composition (compose, map, not, and, or, ifElse, partial, contramap). |
FnSpec | Signature-first specification built with Fn.params(...) before attaching .body(...). |
Guard | A single contract guard recognised by its node shape. |
Types
ArgInputs | Argument inputs accepted when calling a Fn symbolically inside an expression. |
DeferredArgs | Expressions for every parameter. Pass Expr.lit(null) for an absent optional parameter. |
MergedArgEnv | Merged environment of all symbolic argument expressions passed to a Fn call. |
ParamPaths | Path accessors passed to body and where builders. |
ParamSchemas | A record mapping parameter names to Effect Schemas. |
ParamValues | Runtime value record for parameter schemas P. |
ReturnCarrier | Underlying carrier type accepted when a body or argument feeds a declared Schema type R: |