trilean 1.13.9 → 1.13.11
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 +1 -1
- package/dist/evaluator-budget.cjs +16 -2
- package/dist/evaluator-budget.d.cts +5 -1
- package/dist/evaluator-budget.d.ts +5 -1
- package/dist/evaluator-budget.js +15 -3
- package/dist/evaluator-compiled.cjs +1 -1
- package/dist/evaluator-compiled.js +2 -2
- package/dist/evaluator-test-helpers.cjs +14995 -4
- package/dist/evaluator-test-helpers.js +14869 -1
- package/dist/evaluator.cjs +4 -4
- package/dist/evaluator.js +4 -4
- package/dist-cli/trilean.mjs +19 -7
- package/package.json +3 -2
- package/schemas/trilean.schema.json +1 -1
- package/dist/evaluator-indeterminacy-helpers.cjs +0 -179
- package/dist/evaluator-indeterminacy-helpers.d.cts +0 -55
- package/dist/evaluator-indeterminacy-helpers.d.ts +0 -55
- package/dist/evaluator-indeterminacy-helpers.js +0 -157
- package/dist/index.CZzC1gGg-CQphWYWn.cjs +0 -14998
- package/dist/index.CZzC1gGg-D3-vRdPe.js +0 -14870
package/dist/evaluator.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_evaluation = require("./evaluation.cjs");
|
|
3
|
-
require("./evaluator-budget.cjs");
|
|
3
|
+
const require_evaluator_budget = require("./evaluator-budget.cjs");
|
|
4
4
|
const require_evaluator_collection = require("./evaluator-collection.cjs");
|
|
5
5
|
const require_evaluator_operations = require("./evaluator-operations.cjs");
|
|
6
6
|
const require_evaluator_literals = require("./evaluator-literals.cjs");
|
|
@@ -60,7 +60,7 @@ function* evaluatePredicateInternal(node, context, resolvers, accumulator, funct
|
|
|
60
60
|
case "exists": {
|
|
61
61
|
const operandResult = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
62
62
|
if (operandResult.status === "indeterminate") {
|
|
63
|
-
if (operandResult.reason.code === "not-yet-known") return operandResult;
|
|
63
|
+
if (operandResult.reason.code === "not-yet-known" || require_evaluator_budget.isResourceExhaustion(operandResult.reason)) return operandResult;
|
|
64
64
|
if (operandResult.reason.code === "not-found") return require_evaluation.definite(false);
|
|
65
65
|
}
|
|
66
66
|
return require_evaluation.definite(true);
|
|
@@ -81,7 +81,7 @@ function* evaluatePredicateInternal(node, context, resolvers, accumulator, funct
|
|
|
81
81
|
if (resolvers.resolveTree === void 0) return require_evaluation.indeterminate("wrong-type", "no tree resolver registered for treeReference nodes");
|
|
82
82
|
const keyString = JSON.stringify(node.key);
|
|
83
83
|
if (visitedTreeKeys.has(keyString)) return require_evaluation.indeterminate("domain-error", "circular treeReference detected");
|
|
84
|
-
if (treeReferenceDepth >= 100) return
|
|
84
|
+
if (treeReferenceDepth >= 100) return require_evaluator_budget.resourceExhausted(`treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
85
85
|
const resolution = yield* require_evaluator_effect.wait(resolvers.resolveTree(node.key, context));
|
|
86
86
|
if (!resolution.found) return require_evaluator_operations.absenceEvaluation(resolution, "treeReference key did not resolve to a tree", "the tree for the treeReference key is not yet known");
|
|
87
87
|
const parsed = require_tree.PredicateNodeSchema.safeParse(resolution.node);
|
|
@@ -214,7 +214,7 @@ function* evaluateValueInternal(node, context, resolvers, accumulator, functions
|
|
|
214
214
|
if (resolvers.resolveTree === void 0) return require_evaluation.indeterminate("wrong-type", "no tree resolver registered for treeReference nodes");
|
|
215
215
|
const keyString = JSON.stringify(node.key);
|
|
216
216
|
if (visitedTreeKeys.has(keyString)) return require_evaluation.indeterminate("domain-error", "circular treeReference detected");
|
|
217
|
-
if (treeReferenceDepth >= 100) return
|
|
217
|
+
if (treeReferenceDepth >= 100) return require_evaluator_budget.resourceExhausted(`treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
218
218
|
const resolution = yield* require_evaluator_effect.wait(resolvers.resolveTree(node.key, context));
|
|
219
219
|
if (!resolution.found) return require_evaluator_operations.absenceEvaluation(resolution, "treeReference key did not resolve to a tree", "the tree for the treeReference key is not yet known");
|
|
220
220
|
const parsed = require_tree.ExpressionNodeSchema.safeParse(resolution.node);
|
package/dist/evaluator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { definite, firstIndeterminate, indeterminate } from "./evaluation.js";
|
|
2
|
-
import "./evaluator-budget.js";
|
|
2
|
+
import { isResourceExhaustion, resourceExhausted } from "./evaluator-budget.js";
|
|
3
3
|
import { firstFilterIndeterminate, resolveParticipatingItems } from "./evaluator-collection.js";
|
|
4
4
|
import { absenceEvaluation, applyArithmetic, applyNegate, checkReferenceUnit, combineAnd, combineOr, compareText, compareValues, computeMembershipMatch, invokeRegisteredFunction } from "./evaluator-operations.js";
|
|
5
5
|
import { literalValue } from "./evaluator-literals.js";
|
|
@@ -59,7 +59,7 @@ function* evaluatePredicateInternal(node, context, resolvers, accumulator, funct
|
|
|
59
59
|
case "exists": {
|
|
60
60
|
const operandResult = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
61
61
|
if (operandResult.status === "indeterminate") {
|
|
62
|
-
if (operandResult.reason.code === "not-yet-known") return operandResult;
|
|
62
|
+
if (operandResult.reason.code === "not-yet-known" || isResourceExhaustion(operandResult.reason)) return operandResult;
|
|
63
63
|
if (operandResult.reason.code === "not-found") return definite(false);
|
|
64
64
|
}
|
|
65
65
|
return definite(true);
|
|
@@ -80,7 +80,7 @@ function* evaluatePredicateInternal(node, context, resolvers, accumulator, funct
|
|
|
80
80
|
if (resolvers.resolveTree === void 0) return indeterminate("wrong-type", "no tree resolver registered for treeReference nodes");
|
|
81
81
|
const keyString = JSON.stringify(node.key);
|
|
82
82
|
if (visitedTreeKeys.has(keyString)) return indeterminate("domain-error", "circular treeReference detected");
|
|
83
|
-
if (treeReferenceDepth >= 100) return
|
|
83
|
+
if (treeReferenceDepth >= 100) return resourceExhausted(`treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
84
84
|
const resolution = yield* wait(resolvers.resolveTree(node.key, context));
|
|
85
85
|
if (!resolution.found) return absenceEvaluation(resolution, "treeReference key did not resolve to a tree", "the tree for the treeReference key is not yet known");
|
|
86
86
|
const parsed = PredicateNodeSchema.safeParse(resolution.node);
|
|
@@ -213,7 +213,7 @@ function* evaluateValueInternal(node, context, resolvers, accumulator, functions
|
|
|
213
213
|
if (resolvers.resolveTree === void 0) return indeterminate("wrong-type", "no tree resolver registered for treeReference nodes");
|
|
214
214
|
const keyString = JSON.stringify(node.key);
|
|
215
215
|
if (visitedTreeKeys.has(keyString)) return indeterminate("domain-error", "circular treeReference detected");
|
|
216
|
-
if (treeReferenceDepth >= 100) return
|
|
216
|
+
if (treeReferenceDepth >= 100) return resourceExhausted(`treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
217
217
|
const resolution = yield* wait(resolvers.resolveTree(node.key, context));
|
|
218
218
|
if (!resolution.found) return absenceEvaluation(resolution, "treeReference key did not resolve to a tree", "the tree for the treeReference key is not yet known");
|
|
219
219
|
const parsed = ExpressionNodeSchema.safeParse(resolution.node);
|
package/dist-cli/trilean.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { parseArgs } from "node:util";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { RegexParseError, compilePattern } from "trilean-regex";
|
|
6
6
|
// package.json
|
|
7
|
-
var version = "1.13.
|
|
7
|
+
var version = "1.13.11";
|
|
8
8
|
// src/computed-value.ts
|
|
9
9
|
/** Dimension symbol -\> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
|
|
10
10
|
const UnitSchema = z.record(z.string(), z.number());
|
|
@@ -118,6 +118,18 @@ function firstIndeterminate(...results) {
|
|
|
118
118
|
return first;
|
|
119
119
|
}
|
|
120
120
|
// src/evaluator-budget.ts
|
|
121
|
+
/** The reason objects that report an exhausted resource limit (node budget, nesting depth, treeReference chain depth). Every such reason has the code `domain-error`, so the code alone cannot tell a limit from any other domain error; membership here is what `exists` reads to let a limit propagate instead of counting as "the value resolved". Identity is preserved by every node that forwards an operand's reason, so a reason keeps its membership as it propagates. */
|
|
122
|
+
const exhaustedReasons = /* @__PURE__ */ new WeakSet();
|
|
123
|
+
/** The indeterminate result for an exhausted resource limit: code `domain-error` with the limit's own message, recorded so `isResourceExhaustion` recognises it. */
|
|
124
|
+
function resourceExhausted(message) {
|
|
125
|
+
const result = indeterminate("domain-error", message);
|
|
126
|
+
if (result.status === "indeterminate") exhaustedReasons.add(result.reason);
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
/** Whether `reason` reports an exhausted resource limit, as opposed to any other indeterminacy. */
|
|
130
|
+
function isResourceExhaustion(reason) {
|
|
131
|
+
return exhaustedReasons.has(reason);
|
|
132
|
+
}
|
|
121
133
|
/** Default cap on the total number of predicate/expression nodes a single `evaluatePredicate`/`evaluateValue` call may visit -- see `createEvaluator`'s `maxNodes` option, threaded through to `createEvaluationBudget` below. Chosen generously above any realistic hand-authored business-rule, eligibility, or formula tree (see README.md's own consumer use cases), while still bounding an untrusted, adversarially-authored tree's total evaluation cost to a fixed, small amount of work regardless of how it is shaped. */
|
|
122
134
|
const DEFAULT_MAX_EVALUATION_NODES = 1e4;
|
|
123
135
|
/** Constructs a fresh `EvaluationBudget` for one top-level `evaluatePredicate`/`evaluateValue` call -- see `createEvaluator`'s `maxNodes`/`maxNestingDepth` options, which supply `maxNodes`/`maxNestingDepth` here. A fresh closure per call is what keeps `nodesVisited` from leaking between unrelated evaluations. */
|
|
@@ -126,8 +138,8 @@ function createEvaluationBudget(maxNodes, maxNestingDepth) {
|
|
|
126
138
|
let nodesVisited = 0;
|
|
127
139
|
return { checkNode(nestingDepth) {
|
|
128
140
|
nodesVisited += 1;
|
|
129
|
-
if (nodesVisited > maxNodes) return
|
|
130
|
-
if (nestingDepth >= maxNestingDepth) return
|
|
141
|
+
if (nodesVisited > maxNodes) return resourceExhausted(`evaluation exceeded the maximum of ${maxNodes.toString()} nodes visited in a single call (resource exhausted)`);
|
|
142
|
+
if (nestingDepth >= maxNestingDepth) return resourceExhausted(`evaluation nesting depth exceeds the maximum of ${maxNestingDepth.toString()} (resource exhausted)`);
|
|
131
143
|
} };
|
|
132
144
|
}
|
|
133
145
|
// src/evaluator-effect.ts
|
|
@@ -1184,7 +1196,7 @@ function* evaluatePredicateInternal(node, context, resolvers, accumulator, funct
|
|
|
1184
1196
|
case "exists": {
|
|
1185
1197
|
const operandResult = yield* evaluateValueInternal(node.operand, context, resolvers, accumulator, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
|
|
1186
1198
|
if (operandResult.status === "indeterminate") {
|
|
1187
|
-
if (operandResult.reason.code === "not-yet-known") return operandResult;
|
|
1199
|
+
if (operandResult.reason.code === "not-yet-known" || isResourceExhaustion(operandResult.reason)) return operandResult;
|
|
1188
1200
|
if (operandResult.reason.code === "not-found") return definite(false);
|
|
1189
1201
|
}
|
|
1190
1202
|
return definite(true);
|
|
@@ -1204,7 +1216,7 @@ function* evaluatePredicateInternal(node, context, resolvers, accumulator, funct
|
|
|
1204
1216
|
if (resolvers.resolveTree === void 0) return indeterminate("wrong-type", "no tree resolver registered for treeReference nodes");
|
|
1205
1217
|
const keyString = JSON.stringify(node.key);
|
|
1206
1218
|
if (visitedTreeKeys.has(keyString)) return indeterminate("domain-error", "circular treeReference detected");
|
|
1207
|
-
if (treeReferenceDepth >= 100) return
|
|
1219
|
+
if (treeReferenceDepth >= 100) return resourceExhausted(`treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
1208
1220
|
const resolution = yield* wait(resolvers.resolveTree(node.key, context));
|
|
1209
1221
|
if (!resolution.found) return absenceEvaluation(resolution, "treeReference key did not resolve to a tree", "the tree for the treeReference key is not yet known");
|
|
1210
1222
|
const parsed = PredicateNodeSchema.safeParse(resolution.node);
|
|
@@ -1337,7 +1349,7 @@ function* evaluateValueInternal(node, context, resolvers, accumulator, functions
|
|
|
1337
1349
|
if (resolvers.resolveTree === void 0) return indeterminate("wrong-type", "no tree resolver registered for treeReference nodes");
|
|
1338
1350
|
const keyString = JSON.stringify(node.key);
|
|
1339
1351
|
if (visitedTreeKeys.has(keyString)) return indeterminate("domain-error", "circular treeReference detected");
|
|
1340
|
-
if (treeReferenceDepth >= 100) return
|
|
1352
|
+
if (treeReferenceDepth >= 100) return resourceExhausted(`treeReference chain exceeds the maximum depth of ${100 .toString()}`);
|
|
1341
1353
|
const resolution = yield* wait(resolvers.resolveTree(node.key, context));
|
|
1342
1354
|
if (!resolution.found) return absenceEvaluation(resolution, "treeReference key did not resolve to a tree", "the tree for the treeReference key is not yet known");
|
|
1343
1355
|
const parsed = ExpressionNodeSchema.safeParse(resolution.node);
|
|
@@ -1480,7 +1492,7 @@ var NodeCompiler = class {
|
|
|
1480
1492
|
return this.charged(depth, (context, resolvers, budget) => {
|
|
1481
1493
|
const result = operand(context, resolvers, budget);
|
|
1482
1494
|
if (result.status === "indeterminate") {
|
|
1483
|
-
if (result.reason.code === "not-yet-known") return result;
|
|
1495
|
+
if (result.reason.code === "not-yet-known" || isResourceExhaustion(result.reason)) return result;
|
|
1484
1496
|
if (result.reason.code === "not-found") return definite(false);
|
|
1485
1497
|
}
|
|
1486
1498
|
return definite(true);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trilean",
|
|
3
3
|
"description": "Three-valued predicate and expression evaluation trees, stored as JSON and evaluated against injected resolvers, for domain logic — business rules, eligibility checks, formulas, search filters, and more — that needs to be data instead of code.",
|
|
4
|
-
"version": "1.13.
|
|
4
|
+
"version": "1.13.11",
|
|
5
5
|
"bin": {
|
|
6
6
|
"trilean": "./dist-cli/trilean.mjs"
|
|
7
7
|
},
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "https://github.com/ExaDev/trilean/issues"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"trilean-regex": "1.0.
|
|
12
|
+
"trilean-regex": "1.0.23",
|
|
13
13
|
"zod": "^4.6.7"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"@exadev/eslint-config": "3.0.0",
|
|
19
19
|
"@types/node": "^26.6.5",
|
|
20
20
|
"@vitest/coverage-v8": "^5.0.4",
|
|
21
|
+
"ajv": "8.20.0",
|
|
21
22
|
"canonicalize": "^5.1.0",
|
|
22
23
|
"eslint": "^10.14.0",
|
|
23
24
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$defs":{"ExpressionNode":{"anyOf":[{"oneOf":[{"additionalProperties":false,"properties":{"kind":{"const":"numberLiteral","type":"string"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"},"value":{"type":"number"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"textLiteral","type":"string"},"value":{"type":"string"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"booleanLiteral","type":"string"},"value":{"type":"boolean"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"instantLiteral","type":"string"},"value":{"type":"string"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"durationLiteral","type":"string"},"unit":{"enum":["ms","s","min","h","d"],"type":"string"},"value":{"type":"number"}},"required":["kind","value","unit"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"reference","type":"string"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","key"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"arithmetic","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["add","subtract","multiply","divide","power","modulo"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"negate","type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"args":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"fn":{"type":"string"},"kind":{"const":"call","type":"string"}},"required":["kind","fn","args"],"type":"object"},{"additionalProperties":false,"properties":{"keys":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"kind":{"const":"lookup","type":"string"},"table":{"$ref":"#/$defs/schema0"}},"required":["kind","table","keys"],"type":"object"},{"additionalProperties":false,"properties":{"cases":{"items":{"additionalProperties":false,"properties":{"then":{"$ref":"#/$defs/ExpressionNode"},"when":{"$ref":"#/$defs/PredicateNode"}},"required":["when","then"],"type":"object"},"type":"array"},"fallback":{"$ref":"#/$defs/ExpressionNode"},"hitPolicy":{"enum":["first","unique"],"type":"string"},"kind":{"const":"conditional","type":"string"}},"required":["kind","cases","fallback"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"combiner":{"oneOf":[{"additionalProperties":false,"properties":{"item":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"max","type":"string"}},"required":["mode","item"],"type":"object"},{"additionalProperties":false,"properties":{"item":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"min","type":"string"}},"required":["mode","item"],"type":"object"},{"additionalProperties":false,"properties":{"combine":{"$ref":"#/$defs/ExpressionNode"},"initial":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"reduce","type":"string"}},"required":["mode","initial","combine"],"type":"object"}]},"filter":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"fold","type":"string"}},"required":["kind","collection","combiner"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"accumulator","type":"string"}},"required":["kind"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"delegate","type":"string"},"payload":{"$ref":"#/$defs/schema0"},"system":{"type":"string"}},"required":["kind","system","payload"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"treeReference","type":"string"}},"required":["kind","key"],"type":"object"}]},{"anyOf":[{"additionalProperties":false,"properties":{"im":{"type":"number"},"kind":{"const":"complexLiteral","type":"string"},"re":{"type":"number"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","re","im"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"complexLiteral","type":"string"},"magnitude":{"type":"number"},"phase":{"type":"number"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","magnitude","phase"],"type":"object"}]}]},"PredicateNode":{"oneOf":[{"additionalProperties":false,"properties":{"kind":{"const":"not","type":"string"},"operand":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"and","type":"string"},"left":{"$ref":"#/$defs/PredicateNode"},"right":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"or","type":"string"},"left":{"$ref":"#/$defs/PredicateNode"},"right":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"allOf","type":"string"},"operands":{"items":{"$ref":"#/$defs/PredicateNode"},"type":"array"}},"required":["kind","operands"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"anyOf","type":"string"},"operands":{"items":{"$ref":"#/$defs/PredicateNode"},"type":"array"}},"required":["kind","operands"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"compare","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["gt","gte","lt","lte","eq","neq"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"textCompare","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["equals","notEquals","matches","notMatches","portableMatches","portableNotMatches"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"candidates":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"kind":{"const":"memberOf","type":"string"},"op":{"enum":["in","notIn"],"type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","operand","candidates"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"exists","type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"filter":{"$ref":"#/$defs/PredicateNode"},"item":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"some","type":"string"}},"required":["kind","collection","item"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"filter":{"$ref":"#/$defs/PredicateNode"},"item":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"every","type":"string"}},"required":["kind","collection","item"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"treeReference","type":"string"}},"required":["kind","key"],"type":"object"}]},"schema0":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"items":{"$ref":"#/$defs/schema0"},"type":"array"},{"additionalProperties":{"$ref":"#/$defs/schema0"},"propertyNames":{"type":"string"},"type":"object"}]}},"$id":"https://cdn.jsdelivr.net/npm/trilean@1.13.
|
|
1
|
+
{"$defs":{"ExpressionNode":{"anyOf":[{"oneOf":[{"additionalProperties":false,"properties":{"kind":{"const":"numberLiteral","type":"string"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"},"value":{"type":"number"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"textLiteral","type":"string"},"value":{"type":"string"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"booleanLiteral","type":"string"},"value":{"type":"boolean"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"instantLiteral","type":"string"},"value":{"type":"string"}},"required":["kind","value"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"durationLiteral","type":"string"},"unit":{"enum":["ms","s","min","h","d"],"type":"string"},"value":{"type":"number"}},"required":["kind","value","unit"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"reference","type":"string"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","key"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"arithmetic","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["add","subtract","multiply","divide","power","modulo"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"negate","type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"args":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"fn":{"type":"string"},"kind":{"const":"call","type":"string"}},"required":["kind","fn","args"],"type":"object"},{"additionalProperties":false,"properties":{"keys":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"kind":{"const":"lookup","type":"string"},"table":{"$ref":"#/$defs/schema0"}},"required":["kind","table","keys"],"type":"object"},{"additionalProperties":false,"properties":{"cases":{"items":{"additionalProperties":false,"properties":{"then":{"$ref":"#/$defs/ExpressionNode"},"when":{"$ref":"#/$defs/PredicateNode"}},"required":["when","then"],"type":"object"},"type":"array"},"fallback":{"$ref":"#/$defs/ExpressionNode"},"hitPolicy":{"enum":["first","unique"],"type":"string"},"kind":{"const":"conditional","type":"string"}},"required":["kind","cases","fallback"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"combiner":{"oneOf":[{"additionalProperties":false,"properties":{"item":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"max","type":"string"}},"required":["mode","item"],"type":"object"},{"additionalProperties":false,"properties":{"item":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"min","type":"string"}},"required":["mode","item"],"type":"object"},{"additionalProperties":false,"properties":{"combine":{"$ref":"#/$defs/ExpressionNode"},"initial":{"$ref":"#/$defs/ExpressionNode"},"mode":{"const":"reduce","type":"string"}},"required":["mode","initial","combine"],"type":"object"}]},"filter":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"fold","type":"string"}},"required":["kind","collection","combiner"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"accumulator","type":"string"}},"required":["kind"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"delegate","type":"string"},"payload":{"$ref":"#/$defs/schema0"},"system":{"type":"string"}},"required":["kind","system","payload"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"treeReference","type":"string"}},"required":["kind","key"],"type":"object"}]},{"anyOf":[{"additionalProperties":false,"properties":{"im":{"type":"number"},"kind":{"const":"complexLiteral","type":"string"},"re":{"type":"number"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","re","im"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"complexLiteral","type":"string"},"magnitude":{"type":"number"},"phase":{"type":"number"},"unit":{"additionalProperties":{"type":"number"},"propertyNames":{"type":"string"},"type":"object"}},"required":["kind","magnitude","phase"],"type":"object"}]}]},"PredicateNode":{"oneOf":[{"additionalProperties":false,"properties":{"kind":{"const":"not","type":"string"},"operand":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"and","type":"string"},"left":{"$ref":"#/$defs/PredicateNode"},"right":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"or","type":"string"},"left":{"$ref":"#/$defs/PredicateNode"},"right":{"$ref":"#/$defs/PredicateNode"}},"required":["kind","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"allOf","type":"string"},"operands":{"items":{"$ref":"#/$defs/PredicateNode"},"type":"array"}},"required":["kind","operands"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"anyOf","type":"string"},"operands":{"items":{"$ref":"#/$defs/PredicateNode"},"type":"array"}},"required":["kind","operands"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"compare","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["gt","gte","lt","lte","eq","neq"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"textCompare","type":"string"},"left":{"$ref":"#/$defs/ExpressionNode"},"op":{"enum":["equals","notEquals","matches","notMatches","portableMatches","portableNotMatches"],"type":"string"},"right":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","left","right"],"type":"object"},{"additionalProperties":false,"properties":{"candidates":{"items":{"$ref":"#/$defs/ExpressionNode"},"type":"array"},"kind":{"const":"memberOf","type":"string"},"op":{"enum":["in","notIn"],"type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","op","operand","candidates"],"type":"object"},{"additionalProperties":false,"properties":{"kind":{"const":"exists","type":"string"},"operand":{"$ref":"#/$defs/ExpressionNode"}},"required":["kind","operand"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"filter":{"$ref":"#/$defs/PredicateNode"},"item":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"some","type":"string"}},"required":["kind","collection","item"],"type":"object"},{"additionalProperties":false,"properties":{"collection":{"$ref":"#/$defs/schema0"},"filter":{"$ref":"#/$defs/PredicateNode"},"item":{"$ref":"#/$defs/PredicateNode"},"kind":{"const":"every","type":"string"}},"required":["kind","collection","item"],"type":"object"},{"additionalProperties":false,"properties":{"key":{"$ref":"#/$defs/schema0"},"kind":{"const":"treeReference","type":"string"}},"required":["kind","key"],"type":"object"}]},"schema0":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"boolean"},{"type":"null"},{"items":{"$ref":"#/$defs/schema0"},"type":"array"},{"additionalProperties":{"$ref":"#/$defs/schema0"},"propertyNames":{"type":"string"},"type":"object"}]}},"$id":"https://cdn.jsdelivr.net/npm/trilean@1.13.11/schemas/trilean.schema.json","$schema":"https://json-schema.org/draft/2020-12/schema","oneOf":[{"$ref":"#/$defs/PredicateNode"},{"$ref":"#/$defs/ExpressionNode"}]}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_index_CZzC1gGg = require("./index.CZzC1gGg-CQphWYWn.cjs");
|
|
3
|
-
const require_evaluator_factory = require("./evaluator-factory.cjs");
|
|
4
|
-
// src/evaluator-indeterminacy-helpers.ts
|
|
5
|
-
/**
|
|
6
|
-
* Shared fixture machinery for the two split indeterminacy test files (evaluator.indeterminacy-table.unit.test.ts, evaluator.indeterminacy-cases.unit.test.ts): systematic, table-driven coverage of README.md's "Indeterminacy reference" section, one fixture per node-kind x reason-code combination that section documents, for every `PredicateNode`/`ExpressionNode` kind implemented. This complements, rather than replaces, the ad hoc behavioural tests already spread across the evaluator.*.test.ts files and truth-tables.unit.test.ts.
|
|
7
|
-
*/
|
|
8
|
-
function isPlainRecord(value) {
|
|
9
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
-
}
|
|
11
|
-
function isUnknownArray(value) {
|
|
12
|
-
return Array.isArray(value);
|
|
13
|
-
}
|
|
14
|
-
/** A single resolver pool shared by every fixture below, covering every named key/table/collection any fixture needs. Fixtures that need genuinely different resolver behaviour (the delegate/call rows) supply their own. */
|
|
15
|
-
const baseResolvers = {
|
|
16
|
-
resolveValue: async (key, context) => {
|
|
17
|
-
if (key === "present") return Promise.resolve({
|
|
18
|
-
found: true,
|
|
19
|
-
value: {
|
|
20
|
-
kind: "number",
|
|
21
|
-
value: 10,
|
|
22
|
-
unit: { m: 1 }
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
if (key === "presentText") return Promise.resolve({
|
|
26
|
-
found: true,
|
|
27
|
-
value: {
|
|
28
|
-
kind: "text",
|
|
29
|
-
value: "hello"
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
if (typeof key === "string" && isPlainRecord(context) && key in context) {
|
|
33
|
-
const value = context[key];
|
|
34
|
-
if (typeof value === "number") return Promise.resolve({
|
|
35
|
-
found: true,
|
|
36
|
-
value: {
|
|
37
|
-
kind: "number",
|
|
38
|
-
value
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
if (typeof value === "string") return Promise.resolve({
|
|
42
|
-
found: true,
|
|
43
|
-
value: {
|
|
44
|
-
kind: "text",
|
|
45
|
-
value
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return Promise.resolve({ found: false });
|
|
50
|
-
},
|
|
51
|
-
resolveLookup: async (table) => {
|
|
52
|
-
if (table === "table1") return Promise.resolve({
|
|
53
|
-
found: true,
|
|
54
|
-
value: {
|
|
55
|
-
kind: "number",
|
|
56
|
-
value: 100
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return Promise.resolve({ found: false });
|
|
60
|
-
},
|
|
61
|
-
resolveCollection: async (collection, context) => {
|
|
62
|
-
if (collection === "single-notfound") return Promise.resolve([{}]);
|
|
63
|
-
if (collection === "single-wrongtype") return Promise.resolve([{ value: "x" }]);
|
|
64
|
-
if (collection === "single-domainerror") return Promise.resolve([{}]);
|
|
65
|
-
if (collection === "empty") return Promise.resolve([]);
|
|
66
|
-
if (collection === "one-item") return Promise.resolve([{}]);
|
|
67
|
-
if (collection === "nested-outer") return Promise.resolve([{ values: [{ amount: 1 }, { amount: 2 }] }, { values: [{ amount: 10 }] }]);
|
|
68
|
-
if (collection === "values" && isPlainRecord(context)) {
|
|
69
|
-
const values = context.values;
|
|
70
|
-
return Promise.resolve(isUnknownArray(values) ? values : []);
|
|
71
|
-
}
|
|
72
|
-
return Promise.resolve([]);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const numberLiteral = (value) => ({
|
|
76
|
-
kind: "numberLiteral",
|
|
77
|
-
value
|
|
78
|
-
});
|
|
79
|
-
const missingRef = {
|
|
80
|
-
kind: "reference",
|
|
81
|
-
key: "missing"
|
|
82
|
-
};
|
|
83
|
-
const divideByZero = {
|
|
84
|
-
kind: "arithmetic",
|
|
85
|
-
op: "divide",
|
|
86
|
-
left: numberLiteral(1),
|
|
87
|
-
right: numberLiteral(0)
|
|
88
|
-
};
|
|
89
|
-
const wrongTypeArithmetic = {
|
|
90
|
-
kind: "arithmetic",
|
|
91
|
-
op: "add",
|
|
92
|
-
left: {
|
|
93
|
-
kind: "textLiteral",
|
|
94
|
-
value: "x"
|
|
95
|
-
},
|
|
96
|
-
right: numberLiteral(1)
|
|
97
|
-
};
|
|
98
|
-
const trueGuard = {
|
|
99
|
-
kind: "compare",
|
|
100
|
-
op: "eq",
|
|
101
|
-
left: numberLiteral(1),
|
|
102
|
-
right: numberLiteral(1)
|
|
103
|
-
};
|
|
104
|
-
const falseGuard = {
|
|
105
|
-
kind: "compare",
|
|
106
|
-
op: "eq",
|
|
107
|
-
left: numberLiteral(1),
|
|
108
|
-
right: numberLiteral(2)
|
|
109
|
-
};
|
|
110
|
-
const missingGuard = {
|
|
111
|
-
kind: "compare",
|
|
112
|
-
op: "eq",
|
|
113
|
-
left: missingRef,
|
|
114
|
-
right: numberLiteral(1)
|
|
115
|
-
};
|
|
116
|
-
/** Arbitrary non-`{-1,0,1,2}` magnitudes used below, named individually so each numeric literal only appears once (`@typescript-eslint/no-magic-numbers` only exempts -1/0/1/2 and object-literal property values, not values passed as plain call arguments). */
|
|
117
|
-
const memberOfProbeValue = 5;
|
|
118
|
-
const reduceInitialSeed = 5;
|
|
119
|
-
const laterConditionalCaseValue = 3;
|
|
120
|
-
const untouchedReduceInitial = 42;
|
|
121
|
-
const uniqueHitPolicyThirdCaseValue = 3;
|
|
122
|
-
const isDefinite = { status: "definite" };
|
|
123
|
-
const isNotFound = {
|
|
124
|
-
status: "indeterminate",
|
|
125
|
-
code: "not-found"
|
|
126
|
-
};
|
|
127
|
-
const isWrongType = {
|
|
128
|
-
status: "indeterminate",
|
|
129
|
-
code: "wrong-type"
|
|
130
|
-
};
|
|
131
|
-
const isDomainError = {
|
|
132
|
-
status: "indeterminate",
|
|
133
|
-
code: "domain-error"
|
|
134
|
-
};
|
|
135
|
-
function pred(description, node, expected, overrides = {}) {
|
|
136
|
-
const { context, resolvers = baseResolvers, functions } = overrides;
|
|
137
|
-
const { evaluatePredicate: evaluate } = functions ? require_evaluator_factory.createEvaluator({ functions }) : { evaluatePredicate: require_evaluator_factory.evaluatePredicate };
|
|
138
|
-
return {
|
|
139
|
-
description,
|
|
140
|
-
expected,
|
|
141
|
-
run: async () => evaluate(node, context, resolvers)
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function expr(description, node, expected, overrides = {}) {
|
|
145
|
-
const { context, resolvers = baseResolvers, functions } = overrides;
|
|
146
|
-
const { evaluateValue: evaluate } = functions ? require_evaluator_factory.createEvaluator({ functions }) : { evaluateValue: require_evaluator_factory.evaluateValue };
|
|
147
|
-
return {
|
|
148
|
-
description,
|
|
149
|
-
expected,
|
|
150
|
-
run: async () => evaluate(node, context, resolvers)
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
async function runFixture({ run, expected }) {
|
|
154
|
-
const result = await run();
|
|
155
|
-
require_index_CZzC1gGg.globalExpect(result.status).toBe(expected.status);
|
|
156
|
-
if (expected.status === "indeterminate" && result.status === "indeterminate") require_index_CZzC1gGg.globalExpect(result.reason.code).toBe(expected.code);
|
|
157
|
-
}
|
|
158
|
-
exports.baseResolvers = baseResolvers;
|
|
159
|
-
exports.divideByZero = divideByZero;
|
|
160
|
-
exports.expr = expr;
|
|
161
|
-
exports.falseGuard = falseGuard;
|
|
162
|
-
exports.isDefinite = isDefinite;
|
|
163
|
-
exports.isDomainError = isDomainError;
|
|
164
|
-
exports.isNotFound = isNotFound;
|
|
165
|
-
exports.isPlainRecord = isPlainRecord;
|
|
166
|
-
exports.isUnknownArray = isUnknownArray;
|
|
167
|
-
exports.isWrongType = isWrongType;
|
|
168
|
-
exports.laterConditionalCaseValue = laterConditionalCaseValue;
|
|
169
|
-
exports.memberOfProbeValue = memberOfProbeValue;
|
|
170
|
-
exports.missingGuard = missingGuard;
|
|
171
|
-
exports.missingRef = missingRef;
|
|
172
|
-
exports.numberLiteral = numberLiteral;
|
|
173
|
-
exports.pred = pred;
|
|
174
|
-
exports.reduceInitialSeed = reduceInitialSeed;
|
|
175
|
-
exports.runFixture = runFixture;
|
|
176
|
-
exports.trueGuard = trueGuard;
|
|
177
|
-
exports.uniqueHitPolicyThirdCaseValue = uniqueHitPolicyThirdCaseValue;
|
|
178
|
-
exports.untouchedReduceInitial = untouchedReduceInitial;
|
|
179
|
-
exports.wrongTypeArithmetic = wrongTypeArithmetic;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { IndeterminateReason } from "./evaluation.cjs";
|
|
2
|
-
import { FunctionRegistry } from "./functions.cjs";
|
|
3
|
-
import { EvaluationContext, Resolvers } from "./resolvers.cjs";
|
|
4
|
-
import { ExpressionNode, PredicateNode } from "./tree.cjs";
|
|
5
|
-
/**
|
|
6
|
-
* Shared fixture machinery for the two split indeterminacy test files (evaluator.indeterminacy-table.unit.test.ts, evaluator.indeterminacy-cases.unit.test.ts): systematic, table-driven coverage of README.md's "Indeterminacy reference" section, one fixture per node-kind x reason-code combination that section documents, for every `PredicateNode`/`ExpressionNode` kind implemented. This complements, rather than replaces, the ad hoc behavioural tests already spread across the evaluator.*.test.ts files and truth-tables.unit.test.ts.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
-
export declare function isUnknownArray(value: unknown): value is unknown[];
|
|
10
|
-
/** A single resolver pool shared by every fixture below, covering every named key/table/collection any fixture needs. Fixtures that need genuinely different resolver behaviour (the delegate/call rows) supply their own. */
|
|
11
|
-
export declare const baseResolvers: Resolvers;
|
|
12
|
-
export declare const numberLiteral: (value: number) => ExpressionNode;
|
|
13
|
-
export declare const missingRef: ExpressionNode;
|
|
14
|
-
export declare const divideByZero: ExpressionNode;
|
|
15
|
-
export declare const wrongTypeArithmetic: ExpressionNode;
|
|
16
|
-
export declare const trueGuard: PredicateNode;
|
|
17
|
-
export declare const falseGuard: PredicateNode;
|
|
18
|
-
export declare const missingGuard: PredicateNode;
|
|
19
|
-
/** Arbitrary non-`{-1,0,1,2}` magnitudes used below, named individually so each numeric literal only appears once (`@typescript-eslint/no-magic-numbers` only exempts -1/0/1/2 and object-literal property values, not values passed as plain call arguments). */
|
|
20
|
-
export declare const memberOfProbeValue = 5;
|
|
21
|
-
export declare const reduceInitialSeed = 5;
|
|
22
|
-
export declare const laterConditionalCaseValue = 3;
|
|
23
|
-
export declare const untouchedReduceInitial = 42;
|
|
24
|
-
export declare const uniqueHitPolicyThirdCaseValue = 3;
|
|
25
|
-
export type Expected = {
|
|
26
|
-
readonly status: "definite";
|
|
27
|
-
} | {
|
|
28
|
-
readonly status: "indeterminate";
|
|
29
|
-
readonly code: IndeterminateReason["code"];
|
|
30
|
-
};
|
|
31
|
-
export declare const isDefinite: Expected;
|
|
32
|
-
export declare const isNotFound: Expected;
|
|
33
|
-
export declare const isWrongType: Expected;
|
|
34
|
-
export declare const isDomainError: Expected;
|
|
35
|
-
/** The minimal shape `runFixture` needs from either `evaluatePredicate`'s or `evaluateValue`'s result -- both `Evaluation<boolean>` and `Evaluation<ComputedValue>` are structurally assignable here since only the indeterminate branch's `reason` is ever inspected, never the definite branch's `value`. Typing `Fixture.run`'s result as this proper discriminated union, rather than the looser `{ status: string }` it replaces, is what lets `runFixture` below narrow `result.reason` directly instead of needing a type assertion. */
|
|
36
|
-
type FixtureRunResult = {
|
|
37
|
-
readonly status: "definite";
|
|
38
|
-
} | {
|
|
39
|
-
readonly status: "indeterminate";
|
|
40
|
-
readonly reason: IndeterminateReason;
|
|
41
|
-
};
|
|
42
|
-
export interface Fixture {
|
|
43
|
-
readonly description: string;
|
|
44
|
-
readonly expected: Expected;
|
|
45
|
-
readonly run: () => Promise<FixtureRunResult>;
|
|
46
|
-
}
|
|
47
|
-
export interface FixtureOverrides {
|
|
48
|
-
readonly context?: EvaluationContext;
|
|
49
|
-
readonly resolvers?: Resolvers;
|
|
50
|
-
readonly functions?: FunctionRegistry;
|
|
51
|
-
}
|
|
52
|
-
export declare function pred(description: string, node: PredicateNode, expected: Expected, overrides?: FixtureOverrides): Fixture;
|
|
53
|
-
export declare function expr(description: string, node: ExpressionNode, expected: Expected, overrides?: FixtureOverrides): Fixture;
|
|
54
|
-
export declare function runFixture({ run, expected }: Fixture): Promise<void>;
|
|
55
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { IndeterminateReason } from "./evaluation.js";
|
|
2
|
-
import { FunctionRegistry } from "./functions.js";
|
|
3
|
-
import { EvaluationContext, Resolvers } from "./resolvers.js";
|
|
4
|
-
import { ExpressionNode, PredicateNode } from "./tree.js";
|
|
5
|
-
/**
|
|
6
|
-
* Shared fixture machinery for the two split indeterminacy test files (evaluator.indeterminacy-table.unit.test.ts, evaluator.indeterminacy-cases.unit.test.ts): systematic, table-driven coverage of README.md's "Indeterminacy reference" section, one fixture per node-kind x reason-code combination that section documents, for every `PredicateNode`/`ExpressionNode` kind implemented. This complements, rather than replaces, the ad hoc behavioural tests already spread across the evaluator.*.test.ts files and truth-tables.unit.test.ts.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
9
|
-
export declare function isUnknownArray(value: unknown): value is unknown[];
|
|
10
|
-
/** A single resolver pool shared by every fixture below, covering every named key/table/collection any fixture needs. Fixtures that need genuinely different resolver behaviour (the delegate/call rows) supply their own. */
|
|
11
|
-
export declare const baseResolvers: Resolvers;
|
|
12
|
-
export declare const numberLiteral: (value: number) => ExpressionNode;
|
|
13
|
-
export declare const missingRef: ExpressionNode;
|
|
14
|
-
export declare const divideByZero: ExpressionNode;
|
|
15
|
-
export declare const wrongTypeArithmetic: ExpressionNode;
|
|
16
|
-
export declare const trueGuard: PredicateNode;
|
|
17
|
-
export declare const falseGuard: PredicateNode;
|
|
18
|
-
export declare const missingGuard: PredicateNode;
|
|
19
|
-
/** Arbitrary non-`{-1,0,1,2}` magnitudes used below, named individually so each numeric literal only appears once (`@typescript-eslint/no-magic-numbers` only exempts -1/0/1/2 and object-literal property values, not values passed as plain call arguments). */
|
|
20
|
-
export declare const memberOfProbeValue = 5;
|
|
21
|
-
export declare const reduceInitialSeed = 5;
|
|
22
|
-
export declare const laterConditionalCaseValue = 3;
|
|
23
|
-
export declare const untouchedReduceInitial = 42;
|
|
24
|
-
export declare const uniqueHitPolicyThirdCaseValue = 3;
|
|
25
|
-
export type Expected = {
|
|
26
|
-
readonly status: "definite";
|
|
27
|
-
} | {
|
|
28
|
-
readonly status: "indeterminate";
|
|
29
|
-
readonly code: IndeterminateReason["code"];
|
|
30
|
-
};
|
|
31
|
-
export declare const isDefinite: Expected;
|
|
32
|
-
export declare const isNotFound: Expected;
|
|
33
|
-
export declare const isWrongType: Expected;
|
|
34
|
-
export declare const isDomainError: Expected;
|
|
35
|
-
/** The minimal shape `runFixture` needs from either `evaluatePredicate`'s or `evaluateValue`'s result -- both `Evaluation<boolean>` and `Evaluation<ComputedValue>` are structurally assignable here since only the indeterminate branch's `reason` is ever inspected, never the definite branch's `value`. Typing `Fixture.run`'s result as this proper discriminated union, rather than the looser `{ status: string }` it replaces, is what lets `runFixture` below narrow `result.reason` directly instead of needing a type assertion. */
|
|
36
|
-
type FixtureRunResult = {
|
|
37
|
-
readonly status: "definite";
|
|
38
|
-
} | {
|
|
39
|
-
readonly status: "indeterminate";
|
|
40
|
-
readonly reason: IndeterminateReason;
|
|
41
|
-
};
|
|
42
|
-
export interface Fixture {
|
|
43
|
-
readonly description: string;
|
|
44
|
-
readonly expected: Expected;
|
|
45
|
-
readonly run: () => Promise<FixtureRunResult>;
|
|
46
|
-
}
|
|
47
|
-
export interface FixtureOverrides {
|
|
48
|
-
readonly context?: EvaluationContext;
|
|
49
|
-
readonly resolvers?: Resolvers;
|
|
50
|
-
readonly functions?: FunctionRegistry;
|
|
51
|
-
}
|
|
52
|
-
export declare function pred(description: string, node: PredicateNode, expected: Expected, overrides?: FixtureOverrides): Fixture;
|
|
53
|
-
export declare function expr(description: string, node: ExpressionNode, expected: Expected, overrides?: FixtureOverrides): Fixture;
|
|
54
|
-
export declare function runFixture({ run, expected }: Fixture): Promise<void>;
|
|
55
|
-
export {};
|