trilean 1.6.2 → 1.7.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.
- package/README.md +13 -0
- package/dist/complex.d.cts +5 -6
- package/dist/complex.d.ts +5 -6
- package/dist/derived-aggregates.d.cts +5 -6
- package/dist/derived-aggregates.d.ts +5 -6
- package/dist/derived-connectives.d.cts +10 -11
- package/dist/derived-connectives.d.ts +10 -11
- package/dist/derived-patterns.d.cts +4 -5
- package/dist/derived-patterns.d.ts +4 -5
- package/dist/derived-values.d.cts +2 -3
- package/dist/derived-values.d.ts +2 -3
- package/dist/evaluation.d.cts +7 -8
- package/dist/evaluation.d.ts +7 -8
- package/dist/evaluator-budget.d.cts +6 -7
- package/dist/evaluator-budget.d.ts +6 -7
- package/dist/evaluator-collection.cjs +5 -4
- package/dist/evaluator-collection.d.cts +7 -7
- package/dist/evaluator-collection.d.ts +7 -7
- package/dist/evaluator-collection.js +5 -4
- package/dist/evaluator-effect.cjs +54 -0
- package/dist/evaluator-effect.d.cts +37 -0
- package/dist/evaluator-effect.d.ts +37 -0
- package/dist/evaluator-effect.js +50 -0
- package/dist/evaluator-factory.cjs +13 -2
- package/dist/evaluator-factory.d.cts +17 -6
- package/dist/evaluator-factory.d.ts +17 -6
- package/dist/evaluator-factory.js +13 -3
- package/dist/evaluator-indeterminacy-helpers.d.cts +26 -27
- package/dist/evaluator-indeterminacy-helpers.d.ts +26 -27
- package/dist/evaluator-operations.d.cts +10 -11
- package/dist/evaluator-operations.d.ts +10 -11
- package/dist/evaluator-test-helpers.d.cts +6 -7
- package/dist/evaluator-test-helpers.d.ts +6 -7
- package/dist/evaluator.cjs +43 -40
- package/dist/evaluator.d.cts +5 -5
- package/dist/evaluator.d.ts +5 -5
- package/dist/evaluator.js +43 -40
- package/dist/functions.d.cts +3 -4
- package/dist/functions.d.ts +3 -4
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/resolvers.d.cts +22 -6
- package/dist/resolvers.d.ts +22 -6
- package/dist/tree.d.cts +77 -78
- package/dist/tree.d.ts +77 -78
- package/package.json +3 -3
- package/schemas/trilean.schema.json +1 -1
package/dist/evaluator.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_complex = require("./complex.cjs");
|
|
3
3
|
const require_evaluation = require("./evaluation.cjs");
|
|
4
4
|
require("./evaluator-budget.cjs");
|
|
5
|
+
const require_evaluator_effect = require("./evaluator-effect.cjs");
|
|
5
6
|
const require_evaluator_collection = require("./evaluator-collection.cjs");
|
|
6
7
|
const require_evaluator_operations = require("./evaluator-operations.cjs");
|
|
7
8
|
const require_tree = require("./tree.cjs");
|
|
@@ -9,42 +10,42 @@ const require_tree = require("./tree.cjs");
|
|
|
9
10
|
/**
|
|
10
11
|
* `evaluatePredicateInternal` and `evaluateValueInternal` below are co-located in this one file, rather than split across `predicate-evaluator.ts`/`value-evaluator.ts`, because they are mutually recursive: a predicate leaf (`compare`, `textCompare`, `memberOf`, `exists`) holds `ExpressionNode` operands, and an expression node (`conditional`'s `when`, a fold's `filter`) holds `PredicateNode` operands. Splitting them across modules would make each half import the other, and whichever module finished loading second would see the other's export as `undefined` at its own module-evaluation time -- a genuine circular-import TDZ hazard, not merely a style preference. `resolveParticipatingItems` (in `evaluator-collection.ts`) would share that same hazard if it imported `evaluatePredicateInternal` directly, since it calls back into it to evaluate each candidate's filter -- so it instead takes the evaluator as an injected `EvaluatePredicate` parameter (see that type's own doc comment), which is what lets it live in its own file with no circular dependency on this one. The pure, non-recursive value-combination logic (`combineAnd`/`compareValues`/`applyArithmetic` and their siblings) carries no such constraint either and lives in `evaluator-operations.ts`; the resource-limit infrastructure (`EvaluationBudget` and its constants), likewise self-contained, lives in `evaluator-budget.ts`.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
function* evaluatePredicateInternal(node, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth) {
|
|
13
14
|
const budgetExceeded = budget.checkNode(nestingDepth);
|
|
14
15
|
if (budgetExceeded !== void 0) return budgetExceeded;
|
|
15
16
|
switch (node.kind) {
|
|
16
17
|
case "not": {
|
|
17
|
-
const operand =
|
|
18
|
+
const operand = yield* evaluatePredicateInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
18
19
|
if (operand.status === "indeterminate") return operand;
|
|
19
20
|
return require_evaluation.definite(!operand.value);
|
|
20
21
|
}
|
|
21
22
|
case "and": {
|
|
22
|
-
const [left, right] =
|
|
23
|
+
const [left, right] = yield* require_evaluator_effect.all([evaluatePredicateInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluatePredicateInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
23
24
|
return require_evaluator_operations.combineAnd(left, right);
|
|
24
25
|
}
|
|
25
26
|
case "or": {
|
|
26
|
-
const [left, right] =
|
|
27
|
+
const [left, right] = yield* require_evaluator_effect.all([evaluatePredicateInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluatePredicateInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
27
28
|
return require_evaluator_operations.combineOr(left, right);
|
|
28
29
|
}
|
|
29
|
-
case "allOf": return (
|
|
30
|
-
case "anyOf": return (
|
|
30
|
+
case "allOf": return (yield* require_evaluator_effect.all(node.operands.map((operand) => evaluatePredicateInternal(operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)))).reduce(require_evaluator_operations.combineAnd, require_evaluation.definite(true));
|
|
31
|
+
case "anyOf": return (yield* require_evaluator_effect.all(node.operands.map((operand) => evaluatePredicateInternal(operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)))).reduce(require_evaluator_operations.combineOr, require_evaluation.definite(false));
|
|
31
32
|
case "compare": {
|
|
32
|
-
const [left, right] =
|
|
33
|
+
const [left, right] = yield* require_evaluator_effect.all([evaluateValueInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluateValueInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
33
34
|
if (left.status === "indeterminate") return left;
|
|
34
35
|
if (right.status === "indeterminate") return right;
|
|
35
36
|
return require_evaluator_operations.compareValues(node.op, left.value, right.value);
|
|
36
37
|
}
|
|
37
38
|
case "textCompare": {
|
|
38
|
-
const [left, right] =
|
|
39
|
+
const [left, right] = yield* require_evaluator_effect.all([evaluateValueInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluateValueInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
39
40
|
if (left.status === "indeterminate") return left;
|
|
40
41
|
if (right.status === "indeterminate") return right;
|
|
41
42
|
return require_evaluator_operations.compareText(node.op, left.value, right.value);
|
|
42
43
|
}
|
|
43
44
|
case "memberOf": {
|
|
44
|
-
const operandResult =
|
|
45
|
+
const operandResult = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
45
46
|
if (operandResult.status === "indeterminate") return operandResult;
|
|
46
|
-
const candidateOutcomes =
|
|
47
|
-
const candidateResult =
|
|
47
|
+
const candidateOutcomes = yield* require_evaluator_effect.all(node.candidates.map(function* (candidate) {
|
|
48
|
+
const candidateResult = yield* evaluateValueInternal(candidate, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
48
49
|
if (candidateResult.status === "indeterminate") return candidateResult;
|
|
49
50
|
return require_evaluator_operations.computeMembershipMatch(operandResult.value, candidateResult.value);
|
|
50
51
|
}));
|
|
@@ -57,17 +58,17 @@ async function evaluatePredicateInternal(node, context, resolvers, accumulator,
|
|
|
57
58
|
return require_evaluation.definite(node.op === "notIn");
|
|
58
59
|
}
|
|
59
60
|
case "exists": {
|
|
60
|
-
const operandResult =
|
|
61
|
+
const operandResult = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
61
62
|
if (operandResult.status === "indeterminate" && operandResult.reason.code === "not-found") return require_evaluation.definite(false);
|
|
62
63
|
return require_evaluation.definite(true);
|
|
63
64
|
}
|
|
64
65
|
case "some":
|
|
65
66
|
case "every": {
|
|
66
|
-
const participating =
|
|
67
|
-
const votes = (
|
|
67
|
+
const participating = yield* require_evaluator_collection.resolveParticipatingItems(evaluatePredicateInternal, node.collection, node.filter, context, resolvers, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
68
|
+
const votes = (yield* require_evaluator_effect.all(participating.map(function* ({ item, filterOutcome }) {
|
|
68
69
|
if (filterOutcome === "exclude") return void 0;
|
|
69
70
|
if (filterOutcome !== "include") return filterOutcome;
|
|
70
|
-
return evaluatePredicateInternal(node.item, item, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
71
|
+
return yield* evaluatePredicateInternal(node.item, item, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
71
72
|
}))).filter((vote) => vote !== void 0);
|
|
72
73
|
const combine = node.kind === "some" ? require_evaluator_operations.combineOr : require_evaluator_operations.combineAnd;
|
|
73
74
|
const identity = node.kind === "some" ? require_evaluation.definite(false) : require_evaluation.definite(true);
|
|
@@ -78,21 +79,21 @@ async function evaluatePredicateInternal(node, context, resolvers, accumulator,
|
|
|
78
79
|
const keyString = JSON.stringify(node.key);
|
|
79
80
|
if (visitedTreeKeys.has(keyString)) return require_evaluation.indeterminate("domain-error", "circular treeReference detected");
|
|
80
81
|
if (treeReferenceDepth >= 100) return require_evaluation.indeterminate("domain-error", `treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
81
|
-
const resolution =
|
|
82
|
+
const resolution = yield* require_evaluator_effect.wait(resolvers.resolveTree(node.key, context));
|
|
82
83
|
if (!resolution.found) return require_evaluation.indeterminate("not-found", "treeReference key did not resolve to a tree");
|
|
83
84
|
const parsed = require_tree.PredicateNodeSchema.safeParse(resolution.node);
|
|
84
85
|
if (!parsed.success) return require_evaluation.indeterminate("wrong-type", "the referenced tree is not a valid PredicateNode");
|
|
85
|
-
return evaluatePredicateInternal(parsed.data, context, resolvers, accumulator, functions, /* @__PURE__ */ new Set([...visitedTreeKeys, keyString]), treeReferenceDepth + 1, budget, nestingDepth + 1);
|
|
86
|
+
return yield* evaluatePredicateInternal(parsed.data, context, resolvers, accumulator, functions, /* @__PURE__ */ new Set([...visitedTreeKeys, keyString]), treeReferenceDepth + 1, budget, nestingDepth + 1);
|
|
86
87
|
}
|
|
87
88
|
default: throw new Error("unreachable predicate node kind");
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
+
function* evaluateValueInternal(node, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth) {
|
|
91
92
|
const budgetExceeded = budget.checkNode(nestingDepth);
|
|
92
93
|
if (budgetExceeded !== void 0) return budgetExceeded;
|
|
93
94
|
switch (node.kind) {
|
|
94
95
|
case "reference": {
|
|
95
|
-
const resolution =
|
|
96
|
+
const resolution = yield* require_evaluator_effect.wait(resolvers.resolveValue(node.key, context));
|
|
96
97
|
if (!resolution.found) return require_evaluation.indeterminate("not-found", `no value found for reference key ${JSON.stringify(node.key)}`);
|
|
97
98
|
const unitError = require_evaluator_operations.checkReferenceUnit(node.unit, resolution.value);
|
|
98
99
|
if (unitError !== void 0) return unitError;
|
|
@@ -102,7 +103,7 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
102
103
|
if (accumulator === void 0) return require_evaluation.indeterminate("wrong-type", "accumulator used outside a reduce fold's combine expression");
|
|
103
104
|
return require_evaluation.definite(accumulator);
|
|
104
105
|
case "call": {
|
|
105
|
-
const argResults =
|
|
106
|
+
const argResults = yield* require_evaluator_effect.all(node.args.map((arg) => evaluateValueInternal(arg, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)));
|
|
106
107
|
const args = [];
|
|
107
108
|
for (const result of argResults) {
|
|
108
109
|
if (result.status === "indeterminate") return result;
|
|
@@ -141,40 +142,42 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
141
142
|
});
|
|
142
143
|
return require_evaluation.definite(require_complex.complexFromPolar(node.magnitude, node.phase, node.unit));
|
|
143
144
|
case "arithmetic": {
|
|
144
|
-
const [left, right] =
|
|
145
|
+
const [left, right] = yield* require_evaluator_effect.all([evaluateValueInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluateValueInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
145
146
|
if (left.status === "indeterminate") return left;
|
|
146
147
|
if (right.status === "indeterminate") return right;
|
|
147
148
|
return require_evaluator_operations.applyArithmetic(node.op, left.value, right.value);
|
|
148
149
|
}
|
|
149
150
|
case "negate": {
|
|
150
|
-
const operand =
|
|
151
|
+
const operand = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
151
152
|
if (operand.status === "indeterminate") return operand;
|
|
152
153
|
return require_evaluator_operations.applyNegate(operand.value);
|
|
153
154
|
}
|
|
154
155
|
case "lookup": {
|
|
155
|
-
const keyResults =
|
|
156
|
+
const keyResults = yield* require_evaluator_effect.all(node.keys.map((key) => evaluateValueInternal(key, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)));
|
|
156
157
|
const keyValues = [];
|
|
157
158
|
for (const result of keyResults) {
|
|
158
159
|
if (result.status === "indeterminate") return result;
|
|
159
160
|
keyValues.push(result.value);
|
|
160
161
|
}
|
|
161
|
-
const resolution =
|
|
162
|
+
const resolution = yield* require_evaluator_effect.wait(resolvers.resolveLookup(node.table, keyValues, context));
|
|
162
163
|
if (!resolution.found) return require_evaluation.indeterminate("not-found", `no match found in lookup table ${JSON.stringify(node.table)}`);
|
|
163
164
|
return require_evaluation.definite(resolution.value);
|
|
164
165
|
}
|
|
165
166
|
case "conditional": {
|
|
166
167
|
if ((node.hitPolicy ?? "first") === "first") {
|
|
167
168
|
for (const { when, then } of node.cases) {
|
|
168
|
-
const whenResult =
|
|
169
|
+
const whenResult = yield* evaluatePredicateInternal(when, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
169
170
|
if (whenResult.status === "indeterminate") return whenResult;
|
|
170
|
-
if (whenResult.value) return evaluateValueInternal(then, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
171
|
+
if (whenResult.value) return yield* evaluateValueInternal(then, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
171
172
|
}
|
|
172
|
-
return evaluateValueInternal(node.fallback, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
173
|
+
return yield* evaluateValueInternal(node.fallback, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
173
174
|
}
|
|
174
|
-
const evaluatedCases =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
const evaluatedCases = yield* require_evaluator_effect.all(node.cases.map(function* ({ when, then }) {
|
|
176
|
+
return {
|
|
177
|
+
then,
|
|
178
|
+
whenResult: yield* evaluatePredicateInternal(when, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)
|
|
179
|
+
};
|
|
180
|
+
}));
|
|
178
181
|
const matches = evaluatedCases.filter(({ whenResult }) => whenResult.status === "definite" && whenResult.value);
|
|
179
182
|
if (matches.length >= 2) return require_evaluation.indeterminate("domain-error", "more than one case matched under the 'unique' hit policy");
|
|
180
183
|
const reason = require_evaluation.firstIndeterminate(...evaluatedCases.map(({ whenResult }) => whenResult));
|
|
@@ -183,11 +186,11 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
183
186
|
reason
|
|
184
187
|
};
|
|
185
188
|
const [match] = matches;
|
|
186
|
-
if (match === void 0) return evaluateValueInternal(node.fallback, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
187
|
-
return evaluateValueInternal(match.then, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
189
|
+
if (match === void 0) return yield* evaluateValueInternal(node.fallback, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
190
|
+
return yield* evaluateValueInternal(match.then, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
188
191
|
}
|
|
189
192
|
case "fold": {
|
|
190
|
-
const participating =
|
|
193
|
+
const participating = yield* require_evaluator_collection.resolveParticipatingItems(evaluatePredicateInternal, node.collection, node.filter, context, resolvers, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
191
194
|
const filterIndeterminateReason = require_evaluator_collection.firstFilterIndeterminate(participating);
|
|
192
195
|
if (filterIndeterminateReason !== void 0) return {
|
|
193
196
|
status: "indeterminate",
|
|
@@ -195,11 +198,11 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
195
198
|
};
|
|
196
199
|
const includedItems = participating.filter(({ filterOutcome }) => filterOutcome === "include").map(({ item }) => item);
|
|
197
200
|
if (node.combiner.mode === "reduce") {
|
|
198
|
-
const initialResult =
|
|
201
|
+
const initialResult = yield* evaluateValueInternal(node.combiner.initial, context, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
199
202
|
if (initialResult.status === "indeterminate") return initialResult;
|
|
200
203
|
let runningAccumulator = initialResult.value;
|
|
201
204
|
for (const item of includedItems) {
|
|
202
|
-
const stepResult =
|
|
205
|
+
const stepResult = yield* evaluateValueInternal(node.combiner.combine, item, resolvers, runningAccumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
203
206
|
if (stepResult.status === "indeterminate") return stepResult;
|
|
204
207
|
runningAccumulator = stepResult.value;
|
|
205
208
|
}
|
|
@@ -209,7 +212,7 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
209
212
|
const dominatesOp = node.combiner.mode === "max" ? "gt" : "lt";
|
|
210
213
|
let runningExtremum;
|
|
211
214
|
for (const item of includedItems) {
|
|
212
|
-
const itemResult =
|
|
215
|
+
const itemResult = yield* evaluateValueInternal(node.combiner.item, item, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
213
216
|
if (itemResult.status === "indeterminate") return itemResult;
|
|
214
217
|
if (runningExtremum === void 0) {
|
|
215
218
|
runningExtremum = itemResult.value;
|
|
@@ -224,7 +227,7 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
224
227
|
}
|
|
225
228
|
case "delegate": {
|
|
226
229
|
if (resolvers.resolveDelegate === void 0) return require_evaluation.indeterminate("wrong-type", `no delegate handler registered for external system '${node.system}'`);
|
|
227
|
-
const resolution =
|
|
230
|
+
const resolution = yield* require_evaluator_effect.wait(resolvers.resolveDelegate(node.system, node.payload, context));
|
|
228
231
|
if (!resolution.found) return require_evaluation.indeterminate("not-found", `delegate handler for external system '${node.system}' reported no value`);
|
|
229
232
|
return require_evaluation.definite(resolution.value);
|
|
230
233
|
}
|
|
@@ -233,11 +236,11 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
233
236
|
const keyString = JSON.stringify(node.key);
|
|
234
237
|
if (visitedTreeKeys.has(keyString)) return require_evaluation.indeterminate("domain-error", "circular treeReference detected");
|
|
235
238
|
if (treeReferenceDepth >= 100) return require_evaluation.indeterminate("domain-error", `treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
236
|
-
const resolution =
|
|
239
|
+
const resolution = yield* require_evaluator_effect.wait(resolvers.resolveTree(node.key, context));
|
|
237
240
|
if (!resolution.found) return require_evaluation.indeterminate("not-found", "treeReference key did not resolve to a tree");
|
|
238
241
|
const parsed = require_tree.ExpressionNodeSchema.safeParse(resolution.node);
|
|
239
242
|
if (!parsed.success) return require_evaluation.indeterminate("wrong-type", "the referenced tree is not a valid ExpressionNode");
|
|
240
|
-
return evaluateValueInternal(parsed.data, context, resolvers, accumulator, functions, /* @__PURE__ */ new Set([...visitedTreeKeys, keyString]), treeReferenceDepth + 1, budget, nestingDepth + 1);
|
|
243
|
+
return yield* evaluateValueInternal(parsed.data, context, resolvers, accumulator, functions, /* @__PURE__ */ new Set([...visitedTreeKeys, keyString]), treeReferenceDepth + 1, budget, nestingDepth + 1);
|
|
241
244
|
}
|
|
242
245
|
default: throw new Error("unreachable expression node kind");
|
|
243
246
|
}
|
package/dist/evaluator.d.cts
CHANGED
|
@@ -3,12 +3,12 @@ import { ExpressionNode, PredicateNode } from "./tree.cjs";
|
|
|
3
3
|
import { Evaluation } from "./evaluation.cjs";
|
|
4
4
|
import { EvaluationBudget } from "./evaluator-budget.cjs";
|
|
5
5
|
import { FunctionRegistry } from "./functions.cjs";
|
|
6
|
-
import {
|
|
6
|
+
import { Task } from "./evaluator-effect.cjs";
|
|
7
|
+
import { EvaluationContext, EvaluatorResolvers } from "./resolvers.cjs";
|
|
7
8
|
//#region src/evaluator.d.ts
|
|
8
9
|
/**
|
|
9
10
|
* `evaluatePredicateInternal` and `evaluateValueInternal` below are co-located in this one file, rather than split across `predicate-evaluator.ts`/`value-evaluator.ts`, because they are mutually recursive: a predicate leaf (`compare`, `textCompare`, `memberOf`, `exists`) holds `ExpressionNode` operands, and an expression node (`conditional`'s `when`, a fold's `filter`) holds `PredicateNode` operands. Splitting them across modules would make each half import the other, and whichever module finished loading second would see the other's export as `undefined` at its own module-evaluation time -- a genuine circular-import TDZ hazard, not merely a style preference. `resolveParticipatingItems` (in `evaluator-collection.ts`) would share that same hazard if it imported `evaluatePredicateInternal` directly, since it calls back into it to evaluate each candidate's filter -- so it instead takes the evaluator as an injected `EvaluatePredicate` parameter (see that type's own doc comment), which is what lets it live in its own file with no circular dependency on this one. The pure, non-recursive value-combination logic (`combineAnd`/`compareValues`/`applyArithmetic` and their siblings) carries no such constraint either and lives in `evaluator-operations.ts`; the resource-limit infrastructure (`EvaluationBudget` and its constants), likewise self-contained, lives in `evaluator-budget.ts`.
|
|
10
11
|
*/
|
|
11
|
-
declare function evaluatePredicateInternal(node: PredicateNode, context: EvaluationContext, resolvers: Readonly<
|
|
12
|
-
declare function evaluateValueInternal(node: ExpressionNode, context: EvaluationContext, resolvers: Readonly<
|
|
13
|
-
//#endregion
|
|
14
|
-
export { evaluatePredicateInternal, evaluateValueInternal };
|
|
12
|
+
export declare function evaluatePredicateInternal(node: PredicateNode, context: EvaluationContext, resolvers: Readonly<EvaluatorResolvers>, accumulator: ComputedValue | undefined, functions: Readonly<FunctionRegistry>, visitedTreeKeys: ReadonlySet<string>, treeReferenceDepth: number, budget: Readonly<EvaluationBudget>, nestingDepth: number): Task<Evaluation<boolean>>;
|
|
13
|
+
export declare function evaluateValueInternal(node: ExpressionNode, context: EvaluationContext, resolvers: Readonly<EvaluatorResolvers>, accumulator: ComputedValue | undefined, functions: Readonly<FunctionRegistry>, visitedTreeKeys: ReadonlySet<string>, treeReferenceDepth: number, budget: Readonly<EvaluationBudget>, nestingDepth: number): Task<Evaluation<ComputedValue>>;
|
|
14
|
+
//#endregion
|
package/dist/evaluator.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { ExpressionNode, PredicateNode } from "./tree.js";
|
|
|
3
3
|
import { Evaluation } from "./evaluation.js";
|
|
4
4
|
import { EvaluationBudget } from "./evaluator-budget.js";
|
|
5
5
|
import { FunctionRegistry } from "./functions.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Task } from "./evaluator-effect.js";
|
|
7
|
+
import { EvaluationContext, EvaluatorResolvers } from "./resolvers.js";
|
|
7
8
|
//#region src/evaluator.d.ts
|
|
8
9
|
/**
|
|
9
10
|
* `evaluatePredicateInternal` and `evaluateValueInternal` below are co-located in this one file, rather than split across `predicate-evaluator.ts`/`value-evaluator.ts`, because they are mutually recursive: a predicate leaf (`compare`, `textCompare`, `memberOf`, `exists`) holds `ExpressionNode` operands, and an expression node (`conditional`'s `when`, a fold's `filter`) holds `PredicateNode` operands. Splitting them across modules would make each half import the other, and whichever module finished loading second would see the other's export as `undefined` at its own module-evaluation time -- a genuine circular-import TDZ hazard, not merely a style preference. `resolveParticipatingItems` (in `evaluator-collection.ts`) would share that same hazard if it imported `evaluatePredicateInternal` directly, since it calls back into it to evaluate each candidate's filter -- so it instead takes the evaluator as an injected `EvaluatePredicate` parameter (see that type's own doc comment), which is what lets it live in its own file with no circular dependency on this one. The pure, non-recursive value-combination logic (`combineAnd`/`compareValues`/`applyArithmetic` and their siblings) carries no such constraint either and lives in `evaluator-operations.ts`; the resource-limit infrastructure (`EvaluationBudget` and its constants), likewise self-contained, lives in `evaluator-budget.ts`.
|
|
10
11
|
*/
|
|
11
|
-
declare function evaluatePredicateInternal(node: PredicateNode, context: EvaluationContext, resolvers: Readonly<
|
|
12
|
-
declare function evaluateValueInternal(node: ExpressionNode, context: EvaluationContext, resolvers: Readonly<
|
|
13
|
-
//#endregion
|
|
14
|
-
export { evaluatePredicateInternal, evaluateValueInternal };
|
|
12
|
+
export declare function evaluatePredicateInternal(node: PredicateNode, context: EvaluationContext, resolvers: Readonly<EvaluatorResolvers>, accumulator: ComputedValue | undefined, functions: Readonly<FunctionRegistry>, visitedTreeKeys: ReadonlySet<string>, treeReferenceDepth: number, budget: Readonly<EvaluationBudget>, nestingDepth: number): Task<Evaluation<boolean>>;
|
|
13
|
+
export declare function evaluateValueInternal(node: ExpressionNode, context: EvaluationContext, resolvers: Readonly<EvaluatorResolvers>, accumulator: ComputedValue | undefined, functions: Readonly<FunctionRegistry>, visitedTreeKeys: ReadonlySet<string>, treeReferenceDepth: number, budget: Readonly<EvaluationBudget>, nestingDepth: number): Task<Evaluation<ComputedValue>>;
|
|
14
|
+
//#endregion
|
package/dist/evaluator.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { complexFromPolar } from "./complex.js";
|
|
2
2
|
import { definite, firstIndeterminate, indeterminate } from "./evaluation.js";
|
|
3
3
|
import "./evaluator-budget.js";
|
|
4
|
+
import { all, wait } from "./evaluator-effect.js";
|
|
4
5
|
import { firstFilterIndeterminate, resolveParticipatingItems } from "./evaluator-collection.js";
|
|
5
6
|
import { applyArithmetic, applyNegate, checkReferenceUnit, combineAnd, combineOr, compareText, compareValues, computeMembershipMatch, invokeRegisteredFunction } from "./evaluator-operations.js";
|
|
6
7
|
import { ExpressionNodeSchema, PredicateNodeSchema } from "./tree.js";
|
|
@@ -8,42 +9,42 @@ import { ExpressionNodeSchema, PredicateNodeSchema } from "./tree.js";
|
|
|
8
9
|
/**
|
|
9
10
|
* `evaluatePredicateInternal` and `evaluateValueInternal` below are co-located in this one file, rather than split across `predicate-evaluator.ts`/`value-evaluator.ts`, because they are mutually recursive: a predicate leaf (`compare`, `textCompare`, `memberOf`, `exists`) holds `ExpressionNode` operands, and an expression node (`conditional`'s `when`, a fold's `filter`) holds `PredicateNode` operands. Splitting them across modules would make each half import the other, and whichever module finished loading second would see the other's export as `undefined` at its own module-evaluation time -- a genuine circular-import TDZ hazard, not merely a style preference. `resolveParticipatingItems` (in `evaluator-collection.ts`) would share that same hazard if it imported `evaluatePredicateInternal` directly, since it calls back into it to evaluate each candidate's filter -- so it instead takes the evaluator as an injected `EvaluatePredicate` parameter (see that type's own doc comment), which is what lets it live in its own file with no circular dependency on this one. The pure, non-recursive value-combination logic (`combineAnd`/`compareValues`/`applyArithmetic` and their siblings) carries no such constraint either and lives in `evaluator-operations.ts`; the resource-limit infrastructure (`EvaluationBudget` and its constants), likewise self-contained, lives in `evaluator-budget.ts`.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
function* evaluatePredicateInternal(node, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth) {
|
|
12
13
|
const budgetExceeded = budget.checkNode(nestingDepth);
|
|
13
14
|
if (budgetExceeded !== void 0) return budgetExceeded;
|
|
14
15
|
switch (node.kind) {
|
|
15
16
|
case "not": {
|
|
16
|
-
const operand =
|
|
17
|
+
const operand = yield* evaluatePredicateInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
17
18
|
if (operand.status === "indeterminate") return operand;
|
|
18
19
|
return definite(!operand.value);
|
|
19
20
|
}
|
|
20
21
|
case "and": {
|
|
21
|
-
const [left, right] =
|
|
22
|
+
const [left, right] = yield* all([evaluatePredicateInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluatePredicateInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
22
23
|
return combineAnd(left, right);
|
|
23
24
|
}
|
|
24
25
|
case "or": {
|
|
25
|
-
const [left, right] =
|
|
26
|
+
const [left, right] = yield* all([evaluatePredicateInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluatePredicateInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
26
27
|
return combineOr(left, right);
|
|
27
28
|
}
|
|
28
|
-
case "allOf": return (
|
|
29
|
-
case "anyOf": return (
|
|
29
|
+
case "allOf": return (yield* all(node.operands.map((operand) => evaluatePredicateInternal(operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)))).reduce(combineAnd, definite(true));
|
|
30
|
+
case "anyOf": return (yield* all(node.operands.map((operand) => evaluatePredicateInternal(operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)))).reduce(combineOr, definite(false));
|
|
30
31
|
case "compare": {
|
|
31
|
-
const [left, right] =
|
|
32
|
+
const [left, right] = yield* all([evaluateValueInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluateValueInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
32
33
|
if (left.status === "indeterminate") return left;
|
|
33
34
|
if (right.status === "indeterminate") return right;
|
|
34
35
|
return compareValues(node.op, left.value, right.value);
|
|
35
36
|
}
|
|
36
37
|
case "textCompare": {
|
|
37
|
-
const [left, right] =
|
|
38
|
+
const [left, right] = yield* all([evaluateValueInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluateValueInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
38
39
|
if (left.status === "indeterminate") return left;
|
|
39
40
|
if (right.status === "indeterminate") return right;
|
|
40
41
|
return compareText(node.op, left.value, right.value);
|
|
41
42
|
}
|
|
42
43
|
case "memberOf": {
|
|
43
|
-
const operandResult =
|
|
44
|
+
const operandResult = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
44
45
|
if (operandResult.status === "indeterminate") return operandResult;
|
|
45
|
-
const candidateOutcomes =
|
|
46
|
-
const candidateResult =
|
|
46
|
+
const candidateOutcomes = yield* all(node.candidates.map(function* (candidate) {
|
|
47
|
+
const candidateResult = yield* evaluateValueInternal(candidate, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
47
48
|
if (candidateResult.status === "indeterminate") return candidateResult;
|
|
48
49
|
return computeMembershipMatch(operandResult.value, candidateResult.value);
|
|
49
50
|
}));
|
|
@@ -56,17 +57,17 @@ async function evaluatePredicateInternal(node, context, resolvers, accumulator,
|
|
|
56
57
|
return definite(node.op === "notIn");
|
|
57
58
|
}
|
|
58
59
|
case "exists": {
|
|
59
|
-
const operandResult =
|
|
60
|
+
const operandResult = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
60
61
|
if (operandResult.status === "indeterminate" && operandResult.reason.code === "not-found") return definite(false);
|
|
61
62
|
return definite(true);
|
|
62
63
|
}
|
|
63
64
|
case "some":
|
|
64
65
|
case "every": {
|
|
65
|
-
const participating =
|
|
66
|
-
const votes = (
|
|
66
|
+
const participating = yield* resolveParticipatingItems(evaluatePredicateInternal, node.collection, node.filter, context, resolvers, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
67
|
+
const votes = (yield* all(participating.map(function* ({ item, filterOutcome }) {
|
|
67
68
|
if (filterOutcome === "exclude") return void 0;
|
|
68
69
|
if (filterOutcome !== "include") return filterOutcome;
|
|
69
|
-
return evaluatePredicateInternal(node.item, item, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
70
|
+
return yield* evaluatePredicateInternal(node.item, item, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
70
71
|
}))).filter((vote) => vote !== void 0);
|
|
71
72
|
const combine = node.kind === "some" ? combineOr : combineAnd;
|
|
72
73
|
const identity = node.kind === "some" ? definite(false) : definite(true);
|
|
@@ -77,21 +78,21 @@ async function evaluatePredicateInternal(node, context, resolvers, accumulator,
|
|
|
77
78
|
const keyString = JSON.stringify(node.key);
|
|
78
79
|
if (visitedTreeKeys.has(keyString)) return indeterminate("domain-error", "circular treeReference detected");
|
|
79
80
|
if (treeReferenceDepth >= 100) return indeterminate("domain-error", `treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
80
|
-
const resolution =
|
|
81
|
+
const resolution = yield* wait(resolvers.resolveTree(node.key, context));
|
|
81
82
|
if (!resolution.found) return indeterminate("not-found", "treeReference key did not resolve to a tree");
|
|
82
83
|
const parsed = PredicateNodeSchema.safeParse(resolution.node);
|
|
83
84
|
if (!parsed.success) return indeterminate("wrong-type", "the referenced tree is not a valid PredicateNode");
|
|
84
|
-
return evaluatePredicateInternal(parsed.data, context, resolvers, accumulator, functions, /* @__PURE__ */ new Set([...visitedTreeKeys, keyString]), treeReferenceDepth + 1, budget, nestingDepth + 1);
|
|
85
|
+
return yield* evaluatePredicateInternal(parsed.data, context, resolvers, accumulator, functions, /* @__PURE__ */ new Set([...visitedTreeKeys, keyString]), treeReferenceDepth + 1, budget, nestingDepth + 1);
|
|
85
86
|
}
|
|
86
87
|
default: throw new Error("unreachable predicate node kind");
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
+
function* evaluateValueInternal(node, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth) {
|
|
90
91
|
const budgetExceeded = budget.checkNode(nestingDepth);
|
|
91
92
|
if (budgetExceeded !== void 0) return budgetExceeded;
|
|
92
93
|
switch (node.kind) {
|
|
93
94
|
case "reference": {
|
|
94
|
-
const resolution =
|
|
95
|
+
const resolution = yield* wait(resolvers.resolveValue(node.key, context));
|
|
95
96
|
if (!resolution.found) return indeterminate("not-found", `no value found for reference key ${JSON.stringify(node.key)}`);
|
|
96
97
|
const unitError = checkReferenceUnit(node.unit, resolution.value);
|
|
97
98
|
if (unitError !== void 0) return unitError;
|
|
@@ -101,7 +102,7 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
101
102
|
if (accumulator === void 0) return indeterminate("wrong-type", "accumulator used outside a reduce fold's combine expression");
|
|
102
103
|
return definite(accumulator);
|
|
103
104
|
case "call": {
|
|
104
|
-
const argResults =
|
|
105
|
+
const argResults = yield* all(node.args.map((arg) => evaluateValueInternal(arg, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)));
|
|
105
106
|
const args = [];
|
|
106
107
|
for (const result of argResults) {
|
|
107
108
|
if (result.status === "indeterminate") return result;
|
|
@@ -140,40 +141,42 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
140
141
|
});
|
|
141
142
|
return definite(complexFromPolar(node.magnitude, node.phase, node.unit));
|
|
142
143
|
case "arithmetic": {
|
|
143
|
-
const [left, right] =
|
|
144
|
+
const [left, right] = yield* all([evaluateValueInternal(node.left, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1), evaluateValueInternal(node.right, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)]);
|
|
144
145
|
if (left.status === "indeterminate") return left;
|
|
145
146
|
if (right.status === "indeterminate") return right;
|
|
146
147
|
return applyArithmetic(node.op, left.value, right.value);
|
|
147
148
|
}
|
|
148
149
|
case "negate": {
|
|
149
|
-
const operand =
|
|
150
|
+
const operand = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
150
151
|
if (operand.status === "indeterminate") return operand;
|
|
151
152
|
return applyNegate(operand.value);
|
|
152
153
|
}
|
|
153
154
|
case "lookup": {
|
|
154
|
-
const keyResults =
|
|
155
|
+
const keyResults = yield* all(node.keys.map((key) => evaluateValueInternal(key, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)));
|
|
155
156
|
const keyValues = [];
|
|
156
157
|
for (const result of keyResults) {
|
|
157
158
|
if (result.status === "indeterminate") return result;
|
|
158
159
|
keyValues.push(result.value);
|
|
159
160
|
}
|
|
160
|
-
const resolution =
|
|
161
|
+
const resolution = yield* wait(resolvers.resolveLookup(node.table, keyValues, context));
|
|
161
162
|
if (!resolution.found) return indeterminate("not-found", `no match found in lookup table ${JSON.stringify(node.table)}`);
|
|
162
163
|
return definite(resolution.value);
|
|
163
164
|
}
|
|
164
165
|
case "conditional": {
|
|
165
166
|
if ((node.hitPolicy ?? "first") === "first") {
|
|
166
167
|
for (const { when, then } of node.cases) {
|
|
167
|
-
const whenResult =
|
|
168
|
+
const whenResult = yield* evaluatePredicateInternal(when, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
168
169
|
if (whenResult.status === "indeterminate") return whenResult;
|
|
169
|
-
if (whenResult.value) return evaluateValueInternal(then, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
170
|
+
if (whenResult.value) return yield* evaluateValueInternal(then, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
170
171
|
}
|
|
171
|
-
return evaluateValueInternal(node.fallback, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
172
|
+
return yield* evaluateValueInternal(node.fallback, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
172
173
|
}
|
|
173
|
-
const evaluatedCases =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
const evaluatedCases = yield* all(node.cases.map(function* ({ when, then }) {
|
|
175
|
+
return {
|
|
176
|
+
then,
|
|
177
|
+
whenResult: yield* evaluatePredicateInternal(when, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1)
|
|
178
|
+
};
|
|
179
|
+
}));
|
|
177
180
|
const matches = evaluatedCases.filter(({ whenResult }) => whenResult.status === "definite" && whenResult.value);
|
|
178
181
|
if (matches.length >= 2) return indeterminate("domain-error", "more than one case matched under the 'unique' hit policy");
|
|
179
182
|
const reason = firstIndeterminate(...evaluatedCases.map(({ whenResult }) => whenResult));
|
|
@@ -182,11 +185,11 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
182
185
|
reason
|
|
183
186
|
};
|
|
184
187
|
const [match] = matches;
|
|
185
|
-
if (match === void 0) return evaluateValueInternal(node.fallback, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
186
|
-
return evaluateValueInternal(match.then, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
188
|
+
if (match === void 0) return yield* evaluateValueInternal(node.fallback, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
189
|
+
return yield* evaluateValueInternal(match.then, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
187
190
|
}
|
|
188
191
|
case "fold": {
|
|
189
|
-
const participating =
|
|
192
|
+
const participating = yield* resolveParticipatingItems(evaluatePredicateInternal, node.collection, node.filter, context, resolvers, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
190
193
|
const filterIndeterminateReason = firstFilterIndeterminate(participating);
|
|
191
194
|
if (filterIndeterminateReason !== void 0) return {
|
|
192
195
|
status: "indeterminate",
|
|
@@ -194,11 +197,11 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
194
197
|
};
|
|
195
198
|
const includedItems = participating.filter(({ filterOutcome }) => filterOutcome === "include").map(({ item }) => item);
|
|
196
199
|
if (node.combiner.mode === "reduce") {
|
|
197
|
-
const initialResult =
|
|
200
|
+
const initialResult = yield* evaluateValueInternal(node.combiner.initial, context, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
198
201
|
if (initialResult.status === "indeterminate") return initialResult;
|
|
199
202
|
let runningAccumulator = initialResult.value;
|
|
200
203
|
for (const item of includedItems) {
|
|
201
|
-
const stepResult =
|
|
204
|
+
const stepResult = yield* evaluateValueInternal(node.combiner.combine, item, resolvers, runningAccumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
202
205
|
if (stepResult.status === "indeterminate") return stepResult;
|
|
203
206
|
runningAccumulator = stepResult.value;
|
|
204
207
|
}
|
|
@@ -208,7 +211,7 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
208
211
|
const dominatesOp = node.combiner.mode === "max" ? "gt" : "lt";
|
|
209
212
|
let runningExtremum;
|
|
210
213
|
for (const item of includedItems) {
|
|
211
|
-
const itemResult =
|
|
214
|
+
const itemResult = yield* evaluateValueInternal(node.combiner.item, item, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
212
215
|
if (itemResult.status === "indeterminate") return itemResult;
|
|
213
216
|
if (runningExtremum === void 0) {
|
|
214
217
|
runningExtremum = itemResult.value;
|
|
@@ -223,7 +226,7 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
223
226
|
}
|
|
224
227
|
case "delegate": {
|
|
225
228
|
if (resolvers.resolveDelegate === void 0) return indeterminate("wrong-type", `no delegate handler registered for external system '${node.system}'`);
|
|
226
|
-
const resolution =
|
|
229
|
+
const resolution = yield* wait(resolvers.resolveDelegate(node.system, node.payload, context));
|
|
227
230
|
if (!resolution.found) return indeterminate("not-found", `delegate handler for external system '${node.system}' reported no value`);
|
|
228
231
|
return definite(resolution.value);
|
|
229
232
|
}
|
|
@@ -232,11 +235,11 @@ async function evaluateValueInternal(node, context, resolvers, accumulator, func
|
|
|
232
235
|
const keyString = JSON.stringify(node.key);
|
|
233
236
|
if (visitedTreeKeys.has(keyString)) return indeterminate("domain-error", "circular treeReference detected");
|
|
234
237
|
if (treeReferenceDepth >= 100) return indeterminate("domain-error", `treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
235
|
-
const resolution =
|
|
238
|
+
const resolution = yield* wait(resolvers.resolveTree(node.key, context));
|
|
236
239
|
if (!resolution.found) return indeterminate("not-found", "treeReference key did not resolve to a tree");
|
|
237
240
|
const parsed = ExpressionNodeSchema.safeParse(resolution.node);
|
|
238
241
|
if (!parsed.success) return indeterminate("wrong-type", "the referenced tree is not a valid ExpressionNode");
|
|
239
|
-
return evaluateValueInternal(parsed.data, context, resolvers, accumulator, functions, /* @__PURE__ */ new Set([...visitedTreeKeys, keyString]), treeReferenceDepth + 1, budget, nestingDepth + 1);
|
|
242
|
+
return yield* evaluateValueInternal(parsed.data, context, resolvers, accumulator, functions, /* @__PURE__ */ new Set([...visitedTreeKeys, keyString]), treeReferenceDepth + 1, budget, nestingDepth + 1);
|
|
240
243
|
}
|
|
241
244
|
default: throw new Error("unreachable expression node kind");
|
|
242
245
|
}
|
package/dist/functions.d.cts
CHANGED
|
@@ -3,9 +3,8 @@ import { t as ComputedValue } from "./computed-value-CbRF0Izc.cjs";
|
|
|
3
3
|
/**
|
|
4
4
|
* Named functions available to a `call` expression node, supplied once at evaluator construction time (see `createEvaluator` in evaluator-factory.ts) rather than per evaluation call. A function reports a domain violation (e.g. `squareRoot` given a negative number) by returning a `domainError` rather than throwing -- this keeps `call` inside the same three-outcome model as every other node kind.
|
|
5
5
|
*/
|
|
6
|
-
type FunctionRegistry = Record<string, (args: readonly ComputedValue[]) => ComputedValue | {
|
|
6
|
+
export type FunctionRegistry = Record<string, (args: readonly ComputedValue[]) => ComputedValue | {
|
|
7
7
|
domainError: string;
|
|
8
8
|
}>;
|
|
9
|
-
declare const emptyFunctionRegistry: FunctionRegistry;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { FunctionRegistry, emptyFunctionRegistry };
|
|
9
|
+
export declare const emptyFunctionRegistry: FunctionRegistry;
|
|
10
|
+
//#endregion
|
package/dist/functions.d.ts
CHANGED
|
@@ -3,9 +3,8 @@ import { t as ComputedValue } from "./computed-value-CbRF0Izc.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Named functions available to a `call` expression node, supplied once at evaluator construction time (see `createEvaluator` in evaluator-factory.ts) rather than per evaluation call. A function reports a domain violation (e.g. `squareRoot` given a negative number) by returning a `domainError` rather than throwing -- this keeps `call` inside the same three-outcome model as every other node kind.
|
|
5
5
|
*/
|
|
6
|
-
type FunctionRegistry = Record<string, (args: readonly ComputedValue[]) => ComputedValue | {
|
|
6
|
+
export type FunctionRegistry = Record<string, (args: readonly ComputedValue[]) => ComputedValue | {
|
|
7
7
|
domainError: string;
|
|
8
8
|
}>;
|
|
9
|
-
declare const emptyFunctionRegistry: FunctionRegistry;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { FunctionRegistry, emptyFunctionRegistry };
|
|
9
|
+
export declare const emptyFunctionRegistry: FunctionRegistry;
|
|
10
|
+
//#endregion
|
package/dist/index.cjs
CHANGED
|
@@ -64,6 +64,7 @@ exports.complexMagnitude = require_complex.complexMagnitude;
|
|
|
64
64
|
exports.complexPhase = require_complex.complexPhase;
|
|
65
65
|
exports.count = require_derived_aggregates.count;
|
|
66
66
|
exports.createEvaluator = require_evaluator_factory.createEvaluator;
|
|
67
|
+
exports.createSyncEvaluator = require_evaluator_factory.createSyncEvaluator;
|
|
67
68
|
exports.definite = require_evaluation.definite;
|
|
68
69
|
exports.emptyFunctionRegistry = require_functions.emptyFunctionRegistry;
|
|
69
70
|
exports.evaluatePredicate = require_evaluator_factory.evaluatePredicate;
|
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,6 @@ import { hierarchicalGlobPattern, prefixPattern, wildcardPattern } from "./deriv
|
|
|
8
8
|
import { coalesce } from "./derived-values.cjs";
|
|
9
9
|
import { Evaluation, IndeterminateReason, IndeterminateReasonSchema, definite, firstIndeterminate, indeterminate } from "./evaluation.cjs";
|
|
10
10
|
import { FunctionRegistry, emptyFunctionRegistry } from "./functions.cjs";
|
|
11
|
-
import { EvaluationContext, Resolution, Resolvers, TreeResolution } from "./resolvers.cjs";
|
|
12
|
-
import { createEvaluator, evaluatePredicate, evaluateValue } from "./evaluator-factory.cjs";
|
|
13
|
-
export { type AccumulatorNode, AccumulatorNodeSchema, type AllOfNode, AllOfNodeSchema, type AndNode, AndNodeSchema, type AnyOfNode, AnyOfNodeSchema, type ArithmeticNode, ArithmeticNodeSchema, type ArithmeticOperator, ArithmeticOperatorSchema, type BooleanLiteralNode, BooleanLiteralNodeSchema, type CallNode, CallNodeSchema, type CompareNode, CompareNodeSchema, type ComparisonOperator, ComparisonOperatorSchema, type ComplexLiteralNode, ComplexLiteralNodeSchema, type ComplexPolarLiteralNode, ComplexPolarLiteralNodeSchema, type ComplexRectangularLiteralNode, ComplexRectangularLiteralNodeSchema, type ComputedValue, ComputedValueSchema, type ConditionalCase, ConditionalCaseSchema, type ConditionalNode, ConditionalNodeSchema, type DelegateNode, DelegateNodeSchema, type DurationLiteralNode, DurationLiteralNodeSchema, type DurationUnit, DurationUnitSchema, type Evaluation, type EvaluationContext, type EveryNode, EveryNodeSchema, type ExistsNode, ExistsNodeSchema, type ExpressionNode, ExpressionNodeSchema, type FoldCombiner, FoldCombinerSchema, type FoldNode, FoldNodeSchema, type FunctionRegistry, type HitPolicy, HitPolicySchema, type IndeterminateReason, IndeterminateReasonSchema, type InstantLiteralNode, InstantLiteralNodeSchema, type JsonValue, JsonValueSchema, type LookupNode, LookupNodeSchema, type MemberOfNode, MemberOfNodeSchema, type MembershipOperator, MembershipOperatorSchema, type NegateNode, NegateNodeSchema, type NotNode, NotNodeSchema, type NumberLiteralNode, NumberLiteralNodeSchema, type OrNode, OrNodeSchema, type PredicateNode, PredicateNodeSchema, type ReferenceNode, ReferenceNodeSchema, type Resolution, type Resolvers, type SomeNode, SomeNodeSchema, type TextCompareNode, TextCompareNodeSchema, type TextComparisonOperator, TextComparisonOperatorSchema, type TextLiteralNode, TextLiteralNodeSchema, type TreeReferenceNode, TreeReferenceNodeSchema, type TreeResolution, type Unit, UnitSchema, and, average, coalesce, combineUnitsForDivide, combineUnitsForMultiply, complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase, count, createEvaluator, definite, emptyFunctionRegistry, evaluatePredicate, evaluateValue, firstIndeterminate, hierarchicalGlobPattern, iff, implies, indeterminate, nand, none, nor, not, or, prefixPattern, presenceOf, sum, unitsEqual, wildcardPattern, xor };
|
|
11
|
+
import { EvaluationContext, Resolution, Resolvers, SyncResolvers, TreeResolution } from "./resolvers.cjs";
|
|
12
|
+
import { EvaluatorOptions, createEvaluator, createSyncEvaluator, evaluatePredicate, evaluateValue } from "./evaluator-factory.cjs";
|
|
13
|
+
export { type AccumulatorNode, AccumulatorNodeSchema, type AllOfNode, AllOfNodeSchema, type AndNode, AndNodeSchema, type AnyOfNode, AnyOfNodeSchema, type ArithmeticNode, ArithmeticNodeSchema, type ArithmeticOperator, ArithmeticOperatorSchema, type BooleanLiteralNode, BooleanLiteralNodeSchema, type CallNode, CallNodeSchema, type CompareNode, CompareNodeSchema, type ComparisonOperator, ComparisonOperatorSchema, type ComplexLiteralNode, ComplexLiteralNodeSchema, type ComplexPolarLiteralNode, ComplexPolarLiteralNodeSchema, type ComplexRectangularLiteralNode, ComplexRectangularLiteralNodeSchema, type ComputedValue, ComputedValueSchema, type ConditionalCase, ConditionalCaseSchema, type ConditionalNode, ConditionalNodeSchema, type DelegateNode, DelegateNodeSchema, type DurationLiteralNode, DurationLiteralNodeSchema, type DurationUnit, DurationUnitSchema, type Evaluation, type EvaluationContext, type EvaluatorOptions, type EveryNode, EveryNodeSchema, type ExistsNode, ExistsNodeSchema, type ExpressionNode, ExpressionNodeSchema, type FoldCombiner, FoldCombinerSchema, type FoldNode, FoldNodeSchema, type FunctionRegistry, type HitPolicy, HitPolicySchema, type IndeterminateReason, IndeterminateReasonSchema, type InstantLiteralNode, InstantLiteralNodeSchema, type JsonValue, JsonValueSchema, type LookupNode, LookupNodeSchema, type MemberOfNode, MemberOfNodeSchema, type MembershipOperator, MembershipOperatorSchema, type NegateNode, NegateNodeSchema, type NotNode, NotNodeSchema, type NumberLiteralNode, NumberLiteralNodeSchema, type OrNode, OrNodeSchema, type PredicateNode, PredicateNodeSchema, type ReferenceNode, ReferenceNodeSchema, type Resolution, type Resolvers, type SomeNode, SomeNodeSchema, type SyncResolvers, type TextCompareNode, TextCompareNodeSchema, type TextComparisonOperator, TextComparisonOperatorSchema, type TextLiteralNode, TextLiteralNodeSchema, type TreeReferenceNode, TreeReferenceNodeSchema, type TreeResolution, type Unit, UnitSchema, and, average, coalesce, combineUnitsForDivide, combineUnitsForMultiply, complexFromPolar, complexLiteralFromPolar, complexMagnitude, complexPhase, count, createEvaluator, createSyncEvaluator, definite, emptyFunctionRegistry, evaluatePredicate, evaluateValue, firstIndeterminate, hierarchicalGlobPattern, iff, implies, indeterminate, nand, none, nor, not, or, prefixPattern, presenceOf, sum, unitsEqual, wildcardPattern, xor };
|