Node.AnyOp
type · packages/metakit/src/nodeOps.ts:266
type AnyOp = Op | ForeignOpAn operator a Call may name: a core one, which carries its evaluator, or a foreign one.
Metakit / @doeixd/metakit
namespace · packages/metakit/src/node.ts:12
export * as Node from './node.js'The seven kinds of node every MetaKit expression is made of, and the closed
set of 50 primitive operators (CoreOpId).
Every reader's table (sqlOps, abstractOps, smtOps, opProperties) is
typed by CoreOpId, and coreOps (from @doeixd/metakit/build) holds the operator
descriptors under the same type, so adding a primitive fails to compile
until every reader implements it. Derived helpers (min, max, abs,
clamp, between, isNotNull, implies) are plain TypeScript functions
over If and the primitives and need no table entry.
Node.AnyOptype · packages/metakit/src/nodeOps.ts:266
type AnyOp = Op | ForeignOpAn operator a Call may name: a core one, which carries its evaluator, or a foreign one.
Node.applyfunction · packages/metakit/src/nodeOps.ts:346
function apply(op: Op, args: ReadonlyArray<unknown>): unknownop applied to argument values under its null rule; an absent value is null.
Node.applyingfunction · packages/metakit/src/nodeOps.ts:350
function applying(
op: AnyOp,
args: ReadonlyArray<unknown>,
run: (values: ReadonlyArray<unknown>) => unknown,
): unknownrun over argument values under op's null rule; an absent value is null.
Node.Binderinterface · packages/metakit/src/nodeTree.ts:17
interface Binder {
readonly slot: symbol
}The identity a fold or a list write gives the element it binds. A bound
Path names it, so no field name of the environment is reserved and
nothing is renamed when terms compose; a reader holds the element under
slot, which no path a Schema field spells can reach.
Node.binderfunction · packages/metakit/src/nodeTree.ts:22
function binder(): BinderA new binder, distinct from every other.
Node.Callinterface · packages/metakit/src/nodeTree.ts:36
interface Call {
readonly _tag: 'Call'
readonly op: AnyOp
readonly args: ReadonlyArray<Node>
}An operator applied to arguments.
Node.ClaimSidetype · packages/metakit/src/nodeOps.ts:182
type ClaimSide = 'left' | 'right' | 'both'Side an identity or absorbing element applies on.
Node.CoreOpIdtype · packages/metakit/src/nodeOps.ts:7
type CoreOpId =
| 'bool.and'
| 'bool.or'
| 'bool.not'
| 'eq.is'
| 'eq.in'
| 'eq.equals'
| 'eq.among'
| 'null.isNull'
| 'null.coalesce'
| 'str.lowerAscii'
| 'str.upperAscii'
| 'str.trim'
| 'str.concat'
| 'str.lt'
| 'str.lte'
| 'str.gt'
| 'str.gte'
| 'ord.lt'
| 'ord.lte'
| 'ord.gt'
| 'ord.gte'
| 'num.add'
| 'num.sub'
| 'num.mul'
| 'num.neg'
| 'num.mulScaled'
| 'num.div'
| 'num.rem'
| 'time.addDays'
| 'time.addMonths'
| 'time.daysBetween'
| 'time.startOfMonth'
| 'time.overlaps'
| 'str.len'
| 'str.startsWith'
| 'str.endsWith'
| 'str.contains'
| 'arr.count'
| 'arr.isEmpty'
| 'arr.has'
| 'arr.append'
| 'arr.include'
| 'arr.exclude'
| 'arr.move'
| 'arr.at'
| 'arr.with'
| 'set.union'
| 'set.intersect'
| 'set.difference'
| 'rec.make'The closed set of 50 primitive operators.
Node.elementfunction · packages/metakit/src/nodeTree.ts:227
function element(env: unknown, binder: Binder): unknownThe element binder holds in env, which a bound path reads; throws where
the environment holds none, as for a reference outside every fold that
binds it (a malformed term).
Node.escapedfunction · packages/metakit/src/nodeTree.ts:231
function escaped(): ErrorThe error of a bound read outside every fold or write that binds it.
Node.failedfunction · packages/metakit/src/nodeOps.ts:338
function failed(op: ForeignOp, error: unknown): RefusalThe refusal of a call whose implementation threw, with what it threw.
Node.Foldinterface · packages/metakit/src/nodeTree.ts:138
interface Fold {
readonly id: RowsFold
readonly evaluate: (
rows: Rows,
source: unknown,
env: unknown,
at: (node: Node, env: unknown) => unknown,
foreign?: ForeignImplementations,
) => unknown
readonly judge: <T>(
rows: Rows,
partialEnv: unknown,
reader: RowsReader<T>,
lookup: (segments: ReadonlyArray<string>) => Option.Option<unknown>,
foreign?: ForeignImplementations,
) => T
}The question a Rows node asks, as a Call holds its Op: its name, by
which every static reader's table is keyed, and the reference reading of
it, concrete evaluation and partial judgement. A page carries only the
folds it builds.
Node.foreignAllowlistfunction · packages/metakit/src/nodeOps.ts:293
function foreignAllowlist(
ops: ReadonlyArray<Pick<ForeignOp, 'id' | 'version'>>,
): ReadonlySet<string>The names of ops, as isForeignAllowed tests them.
Node.ForeignClaimsinterface · packages/metakit/src/nodeOps.ts:188
interface ForeignClaims {
readonly identity?: {
readonly value: unknown
readonly side: ClaimSide
}
readonly absorbing?: {
readonly value: unknown
readonly result: unknown
readonly side: ClaimSide
}
readonly idempotent?: true
readonly commutative?: true
readonly associative?:
| true
| {
readonly unlessRefused: true
}
readonly invertible?: {
readonly inverse: ForeignOp | 'self'
}
readonly monotone?: ReadonlyArray<MonotoneDirection>
readonly total?: true
}Algebraic claims carried on a ForeignOp descriptor.
Node.ForeignDefinitioninterface · packages/metakit/src/nodeOps.ts:243
interface ForeignDefinition {
readonly params: ReadonlyArray<readonly [name: string, schema: Schema.Top]>
readonly result: Schema.Top
readonly where: ReadonlyArray<Node>
readonly obligations: ReadonlyArray<{
readonly when: Option.Option<Node>
readonly expr: Node
readonly schema: Option.Option<Schema.Top>
readonly ensures: ReadonlyArray<Node>
}>
readonly body: Node
readonly ensures: ReadonlyArray<Node>
}A derived operation's function, carried on its descriptor so every call
reaches it. Its definition hash (Artifact.operationFingerprint) covers all
but the ensures parts, which its contract hash adds (Artifact.operationHashes).
Node.ForeignImplementationinterface · packages/metakit/src/nodeTree.ts:64
interface ForeignImplementation {
readonly run: (
args: ReadonlyArray<unknown>,
foreign?: ForeignImplementations,
) => unknown
}One implementation of a foreign operation.
Node.ForeignImplementationstype · packages/metakit/src/nodeTree.ts:76
type ForeignImplementations = Readonly<Record<string, ForeignImplementation>>The implementations a reader is given, by id@version (Node.foreignName),
so two versions of one operation each have theirs.
Node.foreignNamefunction · packages/metakit/src/nodeOps.ts:289
function foreignName(op: Pick<ForeignOp, 'id' | 'version'>): stringA foreign operation's name in every reader's table of implementations:
id@version, so two versions of one operation are two entries.
Node.ForeignOpinterface · packages/metakit/src/nodeOps.ts:216
interface ForeignOp {
readonly _tag: 'Foreign'
readonly id: string
readonly version: number
readonly returns: ValueKind
readonly nulls: 'strict' | 'own'
readonly args?: ReadonlyArray<Schema.Top>
readonly result?: Schema.Top
readonly checkArgs?: ReadonlyArray<ForeignSchemaCheck>
readonly checkResult?: ForeignSchemaCheck
readonly claims: ForeignClaims
readonly definition?: ForeignDefinition
}An operation an application defines, outside the closed set: carried by
its id and version, with no evaluator, since a page and a server may
hold different implementations of it or none. Each reader takes the
implementations from its caller, and refuses a call it holds none for.
Node.ForeignOperationinterface · packages/metakit/src/nodeOps.ts:301
interface ForeignOperation {
readonly descriptor: ForeignOp
}An operation as Operation.define returns it, named by the descriptor it
holds: what a table of [operation, value] pairs names each entry by.
Node.ForeignSchemaCheckinterface · packages/metakit/src/nodeOps.ts:205
interface ForeignSchemaCheck {
readonly is: (value: unknown) => boolean
readonly describe: string
}A precompiled Schema guard carried on a ForeignOp for runtime domain enforcement.
Node.foreignTablefunction · packages/metakit/src/nodeOps.ts:309
function foreignTable<V>(
pairs: ReadonlyArray<readonly [ForeignOperation, V]>,
table: string,
): ReadonlyMap<string, V>The entries of a list of [operation, value] pairs by id@version.
An operation listed twice throws, naming table.
Node.heldfunction · packages/metakit/src/nodeTree.ts:217
function held(env: unknown, binder: Binder): Option.Option<unknown>The element a reader holds in env for binder, where it holds one.
Node.holdsNulfunction · packages/metakit/src/nodeOps.ts:119
function holdsNul(values: ReadonlyArray<unknown>): booleanWhether one of values (or a nested array candidate) is text holding a NUL character.
Node.Ifinterface · packages/metakit/src/nodeTree.ts:43
interface If {
readonly _tag: 'If'
readonly cond: Node
readonly then: Node
readonly otherwise: Node
}A two-way choice on a boolean; a null condition gives null.
Node.illTypedfunction · packages/metakit/src/nodeOps.ts:97
function illTyped(at: string, expected: string, value: unknown): RefusalThe refusal of an operand that is not of the operator's type.
Node.isForeignfunction · packages/metakit/src/nodeOps.ts:269
function isForeign(op: AnyOp): op is ForeignOpWhether op is a foreign operation, which carries no evaluator.
Node.isForeignAllowedfunction · packages/metakit/src/nodeOps.ts:328
function isForeignAllowed(
name: string,
allowlist: ReadonlySet<string> | undefined,
): booleanWhether a foreign operation's id@version name is permitted by allowlist.
Matches exact id@version names; undefined permits every operation.
Node.isRefusalfunction · packages/metakit/src/nodeOps.ts:94
function isRefusal(value: unknown): value is RefusalNode.keyfunction · packages/metakit/src/nodeKey.ts:56
function key(node: Node): stringA string equal for two nodes exactly when they are the same term: the key by which partial evaluation removes duplicates and the checkers name terms. Two opaque nodes are one term only when they share their function.
A bound read is written as its distance, ^n, the folds between it and
the one that binds it, so two folds that differ only in their binder have
one key wherever they sit; a read whose binder is outside node is
^#id, a value of this process, as an opaque node's key is.
Node.keyWithinfunction · packages/metakit/src/nodeKey.ts:70
function keyWithin(node: Node, scope: ReadonlyArray<Binder>): stringnode's key as a part of a term whose folds around it bind scope, innermost last.
Node.Litinterface · packages/metakit/src/nodeTree.ts:6
interface Lit {
readonly _tag: 'Lit'
readonly value: unknown
}A constant.
Node.mapPathsfunction · packages/metakit/src/nodePaths.ts:99
function mapPaths(node: Node, path: (node: PathNode) => Node): NodeEvery read of the environment in node passed through path; a bound read is left as it is.
path is asked once per Path node object, and a subterm node shares is shared in the result.
Node.mapRowsfunction · packages/metakit/src/nodeTree.ts:186
function mapRows(
rows: Rows,
source: (node: Node) => Node,
body: (node: Node) => Node,
): Rowsrows with its source passed through source and each node of its body through body.
Node.Matchinterface · packages/metakit/src/nodeTree.ts:56
interface Match {
readonly _tag: 'Match'
readonly on: Node
readonly cases: ReadonlyArray<readonly [value: string, then: Node]>
readonly otherwise: Option.Option<Node>
}A choice on a value among literal cases. With no otherwise, the cases
cover every value the Schema of on allows and a null on gives null;
with one, it takes null and every value no case names. A subject holding
a NUL is refused (unportable).
Node.MonotoneDirectiontype · packages/metakit/src/nodeOps.ts:185
type MonotoneDirection = 'up' | 'down' | 'none'Monotonicity direction for one argument of a custom operation.
Node.Nodetype · packages/metakit/src/nodeTree.ts:177
type Node = Lit | PathNode | Call | If | Match | Opaque | RowsNode.Opinterface · packages/metakit/src/nodeOps.ts:159
interface Op<Id extends CoreOpId = CoreOpId> {
readonly _tag?: undefined
readonly id: Id
readonly returns: ValueKind | 'operand'
readonly nulls: 'strict' | 'own'
readonly refuses?: (value: unknown) => Refusal | undefined
readonly evaluate: (args: ReadonlyArray<unknown>) => unknown
}An operator's descriptor: its id and its in-memory evaluator. A Call
holds the descriptor itself, so a page that uses one operator ships only
that operator's evaluator. What it keeps is in opProperties.
Node.Opaqueinterface · packages/metakit/src/nodeTree.ts:83
interface Opaque {
readonly _tag: 'Opaque'
readonly name: string
readonly reads: Option.Option<ReadonlyArray<ReadonlyArray<string>>>
readonly run: (env: unknown, foreign: ForeignImplementations) => unknown
}Arbitrary code no reader can see into. It declares what it reads (none: everything), runs in evaluation with the caller's foreign implementations, and leaves every static reader undecided.
Node.OpIdtype · packages/metakit/src/nodeOps.ts:59
type OpId = CoreOpIdNode.PathNodeinterface · packages/metakit/src/nodeTree.ts:28
interface PathNode {
readonly _tag: 'Path'
readonly segments: ReadonlyArray<string>
readonly ast: Option.Option<SchemaAST.AST>
readonly bound?: Binder | undefined
}A read at segments, typed by the Schema it was built from: of the
environment, or, where bound is set, of the element that binder holds.
Node.prefixfunction · packages/metakit/src/nodePaths.ts:57
function prefix(node: Node, segments: ReadonlyArray<string>): NodePrefix every read of the environment (and Opaque read/env) inside node with segments.
A subterm node shares is shared in the result.
Node.Refusalclass · packages/metakit/src/nodeOps.ts:76
class Refusal extends Data.TaggedError('Refusal')<{
readonly reason:
| 'unsafe-integer'
| 'non-finite'
| 'ill-typed'
| 'unmatched'
| 'unportable'
| 'unsupported'
| 'failed'
readonly at: string
readonly detail: string
}> {}Evaluation declined to answer: an integer result left the safe range
(unsafe-integer), a number was NaN or infinite (non-finite), an operand
was not of the operator's type (ill-typed), a Match met a value none
of its cases names (unmatched), a text, equality or Match operation met
text holding a NUL character, which Postgres cannot store (unportable), a
foreign operation had no implementation (unsupported), or the one given
threw (failed). A refusal is not a value: it decides before null, and an
operator given a refused operand is refused, as a database refuses a
statement it cannot run before any operator answers. Only what needs an
operand conditionally passes one by: null.coalesce answers its first
operand where it has a value, If and Match evaluate only the
branch taken, and an any (every) fold is true (false) once one element
settles it, as SQL's EXISTS is. A predicate that is refused does not hold.
Node.refusedForEqualityfunction · packages/metakit/src/nodeOps.ts:140
function refusedForEquality(at: string, value: unknown): Refusal | undefinedThe refusal of an operand an equality refuses whatever the others hold: text holding a NUL, or NaN; candidates are looked into.
Node.relatedSegmentfunction · packages/metakit/src/nodeTree.ts:122
function relatedSegment(relation: string): stringThe segment under a row at which the rows pointing at it through relation are held.
Node.RESERVED_PREFIXESconst · packages/metakit/src/nodeOps.ts:272
const RESERVED_PREFIXES: readonly [
'bool.',
'eq.',
'null.',
'ord.',
'num.',
'time.',
'str.',
'arr.',
'set.',
'rows.',
]The prefixes of the core operators' ids, which a foreign operation may not take.
Node.Rowsinterface · packages/metakit/src/nodeTree.ts:164
interface Rows {
readonly _tag: 'Rows'
readonly fold: Fold
readonly over: RowsOver
readonly where: Option.Option<Node>
readonly value: Option.Option<Node>
readonly set: ReadonlyArray<readonly [field: string, value: Node]>
readonly op?: ForeignOp | undefined
readonly binder: Binder
}One question asked of each element of a list, or each related row: whether
any or every one passes where, how many do, the sum, least or greatest of
value over those that do, the first that does (find), the ones that do
(keep), or each that does changed by set (patch). where, value
and set read the element through paths bound to binder; an element
passes only where where is true.
Node.rowsBodyfunction · packages/metakit/src/nodeTree.ts:210
function rowsBody(rows: Rows): ReadonlyArray<Node>The nodes of a Rows body: its test, its value and what set writes.
Node.RowsFoldtype · packages/metakit/src/nodeTree.ts:91
type RowsFold =
| 'any'
| 'every'
| 'count'
| 'sum'
| 'min'
| 'max'
| 'reduce'
| 'find'
| 'keep'
| 'patch'The question a Rows node asks of each element.
Node.RowsOverconst · packages/metakit/src/nodeTree.ts:119
const RowsOver: Data.TaggedEnum.Constructor<
| { readonly _tag: 'List'; readonly list: Node }
| {
readonly _tag: 'Related'
readonly of: Node
readonly relation: string
readonly cardinality?: 'one' | 'optional' | 'many'
}
>What a Rows node asks its question of: the elements of a list the
environment holds (List), or the rows of another kind pointing at the row
of reads through relation (Related), held under that row at the
segment <relation> as { rows, whole }, where whole says whether these
are all of them.
Node.RowsReaderinterface · packages/metakit/src/nodeTree.ts:125
interface RowsReader<T> {
readonly judge: (node: Node, env: unknown) => T
readonly known: (judged: T) => Option.Option<unknown>
readonly value: (value: unknown) => T
readonly kept: (rows: Rows, source: T, outer: unknown) => T
}How a reader evaluates a body, shows a value, and keeps a Rows node it cannot decide.
Node.rowsSourcefunction · packages/metakit/src/nodeTree.ts:182
function rowsSource(over: RowsOver): NodeThe node a Rows node asks its question of: the list, or the row the related rows point at.
Node.substitutePathsfunction · packages/metakit/src/nodePaths.ts:103
function substitutePaths(
node: Node,
replace: (segments: ReadonlyArray<string>) => Option.Option<Node>,
): NodeSubstitute matching Path nodes using replace, asked once per Path node object; sharing is kept.
Node.textIdentityfunction · packages/metakit/src/nodeOps.ts:115
function textIdentity(value: unknown): unknownA value as every reader compares it: text as a database holds it
(wellFormed), so '\uD800' and '�' are one text to equality, a
Match, the checker and the solver alike; any other value as it is.
Node.unboundfunction · packages/metakit/src/nodeTree.ts:235
function unbound(node: Node): Option.Option<Binder>The binder of a read in node that no fold or write inside node holds: none where node is closed.
Node.unorderedfunction · packages/metakit/src/nodeOps.ts:133
function unordered(at: string): RefusalThe refusal of NaN by an operation that orders or compares numbers, as the databases part over it.
Node.unportablefunction · packages/metakit/src/nodeOps.ts:125
function unportable(at: string): RefusalThe refusal of text holding a NUL character, which every text, equality and Match operation gives.
Node.unsupportedfunction · packages/metakit/src/nodeOps.ts:334
function unsupported(op: ForeignOp, detail?: string): RefusalThe refusal of a call of an operation the reader holds no implementation of.
Node.ValueKindtype · packages/metakit/src/nodeOps.ts:152
type ValueKind = 'number' | 'boolean' | 'text'What an operator's result is, which decides the properties that may return an operand of it.
Node.wellFormedfunction · packages/metakit/src/nodeOps.ts:108
function wellFormed(text: string): stringtext as SQLite's and Postgres's drivers hold it: each lone surrogate as U+FFFD.