@kanonak-protocol/expression 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `@kanonak-protocol/expression` — the Kanonak expression RUNTIME.
3
+ *
4
+ * A small, deterministic tree-walker that folds a `kanonak.org/transformations`
5
+ * (`tx`) + `kanonak.org/math` expression tree to a single number. Generated SDKs
6
+ * reference it so a typed expression can be *run*, not just *represented*.
7
+ *
8
+ * Three layers, exactly as the six-language proof established:
9
+ *
10
+ * 1. DISPATCH — derived from the ontology. An operator's arity falls out of its
11
+ * `tx` superclass: UnaryNumericOp -> unary `value`; BinaryArithmetic /
12
+ * BinaryComparison -> binary; BooleanLogic -> n-ary `operands`; plus the two
13
+ * structural shapes the hierarchy can't imply (`Not`'s `operand`, `Clip`'s
14
+ * ternary). The OPERATOR_ARITY table below is that derivation, frozen.
15
+ *
16
+ * 2. PRIMITIVES — the one authored, determinism-bearing artifact. PRIMITIVES
17
+ * maps each operator URI to its fold. Determinism traps live here and are
18
+ * matched in every language port (Round half-away-from-zero, floored Modulo,
19
+ * Sign(0)=0, comparisons as 1/0).
20
+ *
21
+ * 3. THE FOLD — `evaluate`, a fixed shape: operators recurse + apply a
22
+ * primitive; literals return their numeric value; EVERYTHING ELSE (a typed
23
+ * VarRef, a domain `Step`/`Time`/`Smooth`, any future leaf) is handed to the
24
+ * caller's `resolve(node, ctx, evaluate)`. The runtime is a pure operator
25
+ * engine; binding and domain-leaf semantics are the caller's business. It
26
+ * never privileges `tx.VarRef` — that is just one leaf a domain may resolve.
27
+ *
28
+ * Value domain: uniform numeric. Booleans and comparison results are `1`/`0`, so
29
+ * every language stays on one numeric path. `EXPRESSION_RUNTIME_VERSION` freezes
30
+ * the determinism contract; a change to any primitive, value rule, or dispatch
31
+ * requires a NEW version, never an edit in place.
32
+ */
33
+ /** The frozen expression-runtime version (determinism contract). Not hashed. */
34
+ export declare const EXPRESSION_RUNTIME_VERSION = "1";
35
+ /** A node in the expression tree. `type` is the operator/literal/leaf canonical
36
+ * URI (versionless: `publisher/package/name`); operand keys are the frozen `tx`
37
+ * operand property local names. Unknown fields are ignored by the kernel and are
38
+ * available to `resolve` for domain leaves. */
39
+ export interface ExprNode {
40
+ type: string;
41
+ [operandOrValue: string]: unknown;
42
+ }
43
+ /** Resolve any node the kernel does not recognise as an operator or literal — a
44
+ * binding (`tx.VarRef`, a domain's typed `refersTo` VarRef) or a domain leaf
45
+ * (`Step`, `Time`, `Smooth`…) — to a number. `ctx` is opaque caller state (the
46
+ * binding env, a sim clock, integration state). `evaluate` is handed back so a
47
+ * domain leaf containing sub-expressions can recurse into the kernel. */
48
+ export type Resolve<C> = (node: ExprNode, ctx: C, evaluate: (n: ExprNode, ctx: C) => number) => number;
49
+ export declare class ExpressionError extends Error {
50
+ }
51
+ /**
52
+ * Evaluate an expression tree to a number. Operators fold via the frozen
53
+ * dispatch + primitive tables; literals yield their numeric value; any other
54
+ * node is delegated to `resolve`.
55
+ */
56
+ export declare function evaluate<C = unknown>(node: ExprNode, ctx: C, resolve: Resolve<C>): number;
57
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,gFAAgF;AAChF,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAK9C;;;+CAG+C;AAC/C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC;CACnC;AAED;;;;yEAIyE;AACzE,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,MAAM,KAAK,MAAM,CAAC;AAEvG,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAgH7C;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CA8CzF"}
package/dist/index.js ADDED
@@ -0,0 +1,189 @@
1
+ /**
2
+ * `@kanonak-protocol/expression` — the Kanonak expression RUNTIME.
3
+ *
4
+ * A small, deterministic tree-walker that folds a `kanonak.org/transformations`
5
+ * (`tx`) + `kanonak.org/math` expression tree to a single number. Generated SDKs
6
+ * reference it so a typed expression can be *run*, not just *represented*.
7
+ *
8
+ * Three layers, exactly as the six-language proof established:
9
+ *
10
+ * 1. DISPATCH — derived from the ontology. An operator's arity falls out of its
11
+ * `tx` superclass: UnaryNumericOp -> unary `value`; BinaryArithmetic /
12
+ * BinaryComparison -> binary; BooleanLogic -> n-ary `operands`; plus the two
13
+ * structural shapes the hierarchy can't imply (`Not`'s `operand`, `Clip`'s
14
+ * ternary). The OPERATOR_ARITY table below is that derivation, frozen.
15
+ *
16
+ * 2. PRIMITIVES — the one authored, determinism-bearing artifact. PRIMITIVES
17
+ * maps each operator URI to its fold. Determinism traps live here and are
18
+ * matched in every language port (Round half-away-from-zero, floored Modulo,
19
+ * Sign(0)=0, comparisons as 1/0).
20
+ *
21
+ * 3. THE FOLD — `evaluate`, a fixed shape: operators recurse + apply a
22
+ * primitive; literals return their numeric value; EVERYTHING ELSE (a typed
23
+ * VarRef, a domain `Step`/`Time`/`Smooth`, any future leaf) is handed to the
24
+ * caller's `resolve(node, ctx, evaluate)`. The runtime is a pure operator
25
+ * engine; binding and domain-leaf semantics are the caller's business. It
26
+ * never privileges `tx.VarRef` — that is just one leaf a domain may resolve.
27
+ *
28
+ * Value domain: uniform numeric. Booleans and comparison results are `1`/`0`, so
29
+ * every language stays on one numeric path. `EXPRESSION_RUNTIME_VERSION` freezes
30
+ * the determinism contract; a change to any primitive, value rule, or dispatch
31
+ * requires a NEW version, never an edit in place.
32
+ */
33
+ /** The frozen expression-runtime version (determinism contract). Not hashed. */
34
+ export const EXPRESSION_RUNTIME_VERSION = '1';
35
+ const TX = 'kanonak.org/transformations';
36
+ const MATH = 'kanonak.org/math';
37
+ export class ExpressionError extends Error {
38
+ }
39
+ const UN = (operand) => ({ kind: 'unary', operand });
40
+ const BIN = (left, right) => ({ kind: 'binary', left, right });
41
+ // UnaryNumericOp + Not -> `value` / `operand`; BinaryArithmetic -> arithLeft/Right;
42
+ // BinaryComparison -> compareLeft/Right; BooleanLogic -> operands list; Clip ternary.
43
+ const ARITH = BIN('arithLeft', 'arithRight');
44
+ const COMPARE = BIN('compareLeft', 'compareRight');
45
+ const VALUE = UN('value');
46
+ const OPERATOR_ARITY = {
47
+ [`${TX}/Add`]: ARITH,
48
+ [`${TX}/Subtract`]: ARITH,
49
+ [`${TX}/Multiply`]: ARITH,
50
+ [`${TX}/Divide`]: ARITH,
51
+ [`${MATH}/Power`]: ARITH,
52
+ [`${MATH}/Modulo`]: ARITH,
53
+ [`${MATH}/Minimum`]: ARITH,
54
+ [`${MATH}/Maximum`]: ARITH,
55
+ [`${TX}/Abs`]: VALUE,
56
+ [`${TX}/Negate`]: VALUE,
57
+ [`${MATH}/Exp`]: VALUE,
58
+ [`${MATH}/Ln`]: VALUE,
59
+ [`${MATH}/Log10`]: VALUE,
60
+ [`${MATH}/Sqrt`]: VALUE,
61
+ [`${MATH}/Floor`]: VALUE,
62
+ [`${MATH}/Ceil`]: VALUE,
63
+ [`${MATH}/Round`]: VALUE,
64
+ [`${MATH}/Sign`]: VALUE,
65
+ [`${TX}/Equals`]: COMPARE,
66
+ [`${TX}/GreaterThan`]: COMPARE,
67
+ [`${TX}/LessThan`]: COMPARE,
68
+ [`${TX}/GreaterThanOrEqual`]: COMPARE,
69
+ [`${TX}/LessThanOrEqual`]: COMPARE,
70
+ [`${TX}/And`]: { kind: 'nary', operands: 'operands' },
71
+ [`${TX}/Or`]: { kind: 'nary', operands: 'operands' },
72
+ // `Not` is a direct Expression subclass with boolean (not numeric-unary)
73
+ // semantics — handled explicitly in `evaluate`, not via the numeric tables.
74
+ [`${MATH}/Clip`]: { kind: 'ternary', a: 'clipValue', b: 'clipLower', c: 'clipUpper' },
75
+ };
76
+ /** Floored modulo (the host `%` truncates toward zero): Modulo(-7,3) = 2. */
77
+ function flooredMod(a, b) {
78
+ if (b === 0)
79
+ throw new ExpressionError('Modulo by zero');
80
+ return a - b * Math.floor(a / b);
81
+ }
82
+ /** Round half away from zero: Round(-2.5) = -3, Round(2.5) = 3. */
83
+ function roundHalfAway(a) {
84
+ return a < 0 ? -Math.round(-a) : Math.round(a);
85
+ }
86
+ const truthy = (n) => n !== 0;
87
+ const bool = (b) => (b ? 1 : 0);
88
+ function requireDomain(ok, msg) {
89
+ if (!ok)
90
+ throw new ExpressionError(msg);
91
+ }
92
+ /** Unary/binary/ternary primitives, keyed by operator URI. The authored,
93
+ * determinism-bearing table — matched per language. */
94
+ const UNARY = {
95
+ [`${TX}/Abs`]: (x) => Math.abs(x),
96
+ [`${TX}/Negate`]: (x) => -x,
97
+ [`${MATH}/Exp`]: (x) => Math.exp(x),
98
+ [`${MATH}/Ln`]: (x) => (requireDomain(x > 0, 'Ln of a non-positive number'), Math.log(x)),
99
+ [`${MATH}/Log10`]: (x) => (requireDomain(x > 0, 'Log10 of a non-positive number'), Math.log10(x)),
100
+ [`${MATH}/Sqrt`]: (x) => (requireDomain(x >= 0, 'Sqrt of a negative number'), Math.sqrt(x)),
101
+ [`${MATH}/Floor`]: (x) => Math.floor(x),
102
+ [`${MATH}/Ceil`]: (x) => Math.ceil(x),
103
+ [`${MATH}/Round`]: roundHalfAway,
104
+ [`${MATH}/Sign`]: (x) => Math.sign(x),
105
+ };
106
+ const BINARY = {
107
+ [`${TX}/Add`]: (a, b) => a + b,
108
+ [`${TX}/Subtract`]: (a, b) => a - b,
109
+ [`${TX}/Multiply`]: (a, b) => a * b,
110
+ [`${TX}/Divide`]: (a, b) => (requireDomain(b !== 0, 'Divide by zero'), a / b),
111
+ [`${MATH}/Power`]: (a, b) => Math.pow(a, b),
112
+ [`${MATH}/Modulo`]: flooredMod,
113
+ [`${MATH}/Minimum`]: (a, b) => Math.min(a, b),
114
+ [`${MATH}/Maximum`]: (a, b) => Math.max(a, b),
115
+ [`${TX}/Equals`]: (a, b) => bool(a === b),
116
+ [`${TX}/GreaterThan`]: (a, b) => bool(a > b),
117
+ [`${TX}/LessThan`]: (a, b) => bool(a < b),
118
+ [`${TX}/GreaterThanOrEqual`]: (a, b) => bool(a >= b),
119
+ [`${TX}/LessThanOrEqual`]: (a, b) => bool(a <= b),
120
+ };
121
+ /** Numeric value of a literal node, or `undefined` if it is not a literal. */
122
+ function literalValue(node) {
123
+ switch (node.type) {
124
+ case `${TX}/IntegerLiteral`: return Number(node.integerLiteral);
125
+ case `${TX}/DecimalLiteral`: return Number(node.decimalLiteral);
126
+ case `${TX}/BooleanLiteral`: return bool(node.booleanLiteral === true || node.booleanLiteral === 'true');
127
+ default: return undefined;
128
+ }
129
+ }
130
+ /**
131
+ * Evaluate an expression tree to a number. Operators fold via the frozen
132
+ * dispatch + primitive tables; literals yield their numeric value; any other
133
+ * node is delegated to `resolve`.
134
+ */
135
+ export function evaluate(node, ctx, resolve) {
136
+ const recurse = (n, c) => evaluate(n, c, resolve);
137
+ const arity = OPERATOR_ARITY[node.type];
138
+ if (arity) {
139
+ switch (arity.kind) {
140
+ case 'unary': {
141
+ const x = recurse(operand(node, arity.operand), ctx);
142
+ return UNARY[node.type](x);
143
+ }
144
+ case 'binary': {
145
+ const a = recurse(operand(node, arity.left), ctx);
146
+ const b = recurse(operand(node, arity.right), ctx);
147
+ return BINARY[node.type](a, b);
148
+ }
149
+ case 'nary': {
150
+ const items = node[arity.operands];
151
+ if (!Array.isArray(items))
152
+ throw new ExpressionError(`${node.type} expects an '${arity.operands}' list`);
153
+ const isAnd = node.type === `${TX}/And`;
154
+ // Short-circuit; empty And is vacuously true, empty Or vacuously false.
155
+ for (const item of items) {
156
+ const v = truthy(recurse(item, ctx));
157
+ if (isAnd && !v)
158
+ return 0;
159
+ if (!isAnd && v)
160
+ return 1;
161
+ }
162
+ return bool(isAnd);
163
+ }
164
+ case 'ternary': {
165
+ // Only Clip today: clamp clipValue into [clipLower, clipUpper].
166
+ const v = recurse(operand(node, arity.a), ctx);
167
+ const lo = recurse(operand(node, arity.b), ctx);
168
+ const hi = recurse(operand(node, arity.c), ctx);
169
+ return Math.min(Math.max(v, lo), hi);
170
+ }
171
+ }
172
+ }
173
+ if (node.type === `${TX}/Not`) {
174
+ return bool(!truthy(recurse(operand(node, 'operand'), ctx)));
175
+ }
176
+ const lit = literalValue(node);
177
+ if (lit !== undefined)
178
+ return lit;
179
+ // Not an operator or literal — a binding or domain leaf. The caller owns it.
180
+ return resolve(node, ctx, recurse);
181
+ }
182
+ function operand(node, key) {
183
+ const v = node[key];
184
+ if (v === null || v === undefined || typeof v !== 'object') {
185
+ throw new ExpressionError(`${node.type} is missing operand '${key}'`);
186
+ }
187
+ return v;
188
+ }
189
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,gFAAgF;AAChF,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAE9C,MAAM,EAAE,GAAG,6BAA6B,CAAC;AACzC,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAkBhC,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAS7C,MAAM,EAAE,GAAG,CAAC,OAAe,EAAS,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AACpE,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,KAAa,EAA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,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,eAAe,CAAC,GAAG,IAAI,CAAC,IAAI,wBAAwB,GAAG,GAAG,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,CAAa,CAAC;AACvB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@kanonak-protocol/expression",
3
+ "version": "0.1.0",
4
+ "description": "The Kanonak expression runtime (expressionRuntimeVersion \"1\") — a deterministic tree-walker that folds a kanonak.org/transformations + kanonak.org/math expression to a number, verified against the shared parity vectors. The behavior every generated SDK evaluates through.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://kanonak.org",
7
+ "author": "Kanonak Maintainers (https://github.com/kanonak-protocol/runtime)",
8
+ "bugs": {
9
+ "url": "https://github.com/kanonak-protocol/runtime/issues"
10
+ },
11
+ "type": "module",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "keywords": [
27
+ "kanonak",
28
+ "expression",
29
+ "evaluate",
30
+ "transformations",
31
+ "deterministic",
32
+ "sdk"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/kanonak-protocol/runtime"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.build.json",
40
+ "typecheck": "tsc --noEmit",
41
+ "conformance": "tsx src/conformance.ts"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^22.10.0",
45
+ "tsx": "^4.19.0",
46
+ "typescript": "^5.7.2"
47
+ }
48
+ }