trilean 1.6.0 → 1.6.1

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.
Files changed (50) hide show
  1. package/dist/complex.d.cts +1 -1
  2. package/dist/complex.d.ts +1 -1
  3. package/dist/computed-value-CbRF0Izc.d.cts +51 -0
  4. package/dist/computed-value-CbRF0Izc.d.ts +51 -0
  5. package/dist/computed-value.cjs +1 -1
  6. package/dist/computed-value.d.cts +1 -50
  7. package/dist/computed-value.d.ts +1 -50
  8. package/dist/computed-value.js +1 -1
  9. package/dist/evaluator-budget.cjs +24 -0
  10. package/dist/evaluator-budget.d.cts +21 -0
  11. package/dist/evaluator-budget.d.ts +21 -0
  12. package/dist/evaluator-budget.js +20 -0
  13. package/dist/evaluator-collection.cjs +33 -0
  14. package/dist/evaluator-collection.d.cts +23 -0
  15. package/dist/evaluator-collection.d.ts +23 -0
  16. package/dist/evaluator-collection.js +31 -0
  17. package/dist/evaluator-factory.cjs +19 -0
  18. package/dist/evaluator-factory.d.cts +22 -0
  19. package/dist/evaluator-factory.d.ts +22 -0
  20. package/dist/evaluator-factory.js +16 -0
  21. package/dist/evaluator-indeterminacy-helpers.cjs +180 -0
  22. package/dist/evaluator-indeterminacy-helpers.d.cts +57 -0
  23. package/dist/evaluator-indeterminacy-helpers.d.ts +57 -0
  24. package/dist/evaluator-indeterminacy-helpers.js +158 -0
  25. package/dist/evaluator-operations.cjs +385 -0
  26. package/dist/evaluator-operations.d.cts +27 -0
  27. package/dist/evaluator-operations.d.ts +27 -0
  28. package/dist/evaluator-operations.js +376 -0
  29. package/dist/evaluator-test-helpers.cjs +40 -0
  30. package/dist/evaluator-test-helpers.d.cts +13 -0
  31. package/dist/evaluator-test-helpers.d.ts +13 -0
  32. package/dist/evaluator-test-helpers.js +35 -0
  33. package/dist/evaluator.cjs +25 -442
  34. package/dist/evaluator.d.cts +6 -14
  35. package/dist/evaluator.d.ts +6 -14
  36. package/dist/evaluator.js +12 -428
  37. package/dist/functions.d.cts +2 -2
  38. package/dist/functions.d.ts +2 -2
  39. package/dist/index.cjs +5 -5
  40. package/dist/index.d.cts +2 -2
  41. package/dist/index.d.ts +2 -2
  42. package/dist/index.js +2 -2
  43. package/dist/magic-string.es-BWtG0AyA.js +1017 -0
  44. package/dist/magic-string.es-BvKy4sJx.cjs +1017 -0
  45. package/dist/resolvers.d.cts +1 -1
  46. package/dist/resolvers.d.ts +1 -1
  47. package/dist/test.DNmyFkvJ-Dasq3mQO.cjs +13578 -0
  48. package/dist/test.DNmyFkvJ-SCEEf0VK.js +13573 -0
  49. package/package.json +2 -2
  50. package/schemas/trilean.schema.json +1 -1
@@ -1,4 +1,4 @@
1
- import { ComputedValue, Unit } from "./computed-value.cjs";
1
+ import { a as Unit, t as ComputedValue } from "./computed-value-CbRF0Izc.cjs";
2
2
  import { ComplexLiteralNode } from "./tree.cjs";
3
3
  //#region src/complex.d.ts
4
4
  /**
package/dist/complex.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ComputedValue, Unit } from "./computed-value.js";
1
+ import { a as Unit, t as ComputedValue } from "./computed-value-CbRF0Izc.js";
2
2
  import { ComplexLiteralNode } from "./tree.js";
3
3
  //#region src/complex.d.ts
4
4
  /**
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ //#region src/computed-value.d.ts
3
+ /** Dimension symbol -\> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
4
+ declare const UnitSchema: z.ZodRecord<z.ZodString, z.ZodNumber>;
5
+ type Unit = z.infer<typeof UnitSchema>;
6
+ declare const DurationUnitSchema: z.ZodEnum<{
7
+ ms: "ms";
8
+ s: "s";
9
+ min: "min";
10
+ h: "h";
11
+ d: "d";
12
+ }>;
13
+ type DurationUnit = z.infer<typeof DurationUnitSchema>;
14
+ declare const ComputedValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
15
+ kind: z.ZodLiteral<"number">;
16
+ value: z.ZodNumber;
17
+ unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
18
+ }, z.core.$strip>, z.ZodObject<{
19
+ kind: z.ZodLiteral<"text">;
20
+ value: z.ZodString;
21
+ }, z.core.$strip>, z.ZodObject<{
22
+ kind: z.ZodLiteral<"boolean">;
23
+ value: z.ZodBoolean;
24
+ }, z.core.$strip>, z.ZodObject<{
25
+ kind: z.ZodLiteral<"instant">;
26
+ value: z.ZodString;
27
+ }, z.core.$strip>, z.ZodObject<{
28
+ kind: z.ZodLiteral<"duration">;
29
+ value: z.ZodNumber;
30
+ unit: z.ZodEnum<{
31
+ ms: "ms";
32
+ s: "s";
33
+ min: "min";
34
+ h: "h";
35
+ d: "d";
36
+ }>;
37
+ }, z.core.$strip>, z.ZodObject<{
38
+ kind: z.ZodLiteral<"complex">;
39
+ re: z.ZodNumber;
40
+ im: z.ZodNumber;
41
+ unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
42
+ }, z.core.$strip>], "kind">;
43
+ type ComputedValue = z.infer<typeof ComputedValueSchema>;
44
+ /** An operand with no `unit` is dimensionless (an empty map) for comparison purposes. */
45
+ declare function unitsEqual(a: Unit | undefined, b: Unit | undefined): boolean;
46
+ /** Multiplying two unit-tagged numbers adds exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
47
+ declare function combineUnitsForMultiply(a: Unit | undefined, b: Unit | undefined): Unit;
48
+ /** Dividing two unit-tagged numbers subtracts exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
49
+ declare function combineUnitsForDivide(a: Unit | undefined, b: Unit | undefined): Unit;
50
+ //#endregion
51
+ export { Unit as a, combineUnitsForMultiply as c, DurationUnitSchema as i, unitsEqual as l, ComputedValueSchema as n, UnitSchema as o, DurationUnit as r, combineUnitsForDivide as s, ComputedValue as t };
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ //#region src/computed-value.d.ts
3
+ /** Dimension symbol -\> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
4
+ declare const UnitSchema: z.ZodRecord<z.ZodString, z.ZodNumber>;
5
+ type Unit = z.infer<typeof UnitSchema>;
6
+ declare const DurationUnitSchema: z.ZodEnum<{
7
+ ms: "ms";
8
+ s: "s";
9
+ min: "min";
10
+ h: "h";
11
+ d: "d";
12
+ }>;
13
+ type DurationUnit = z.infer<typeof DurationUnitSchema>;
14
+ declare const ComputedValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
15
+ kind: z.ZodLiteral<"number">;
16
+ value: z.ZodNumber;
17
+ unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
18
+ }, z.core.$strip>, z.ZodObject<{
19
+ kind: z.ZodLiteral<"text">;
20
+ value: z.ZodString;
21
+ }, z.core.$strip>, z.ZodObject<{
22
+ kind: z.ZodLiteral<"boolean">;
23
+ value: z.ZodBoolean;
24
+ }, z.core.$strip>, z.ZodObject<{
25
+ kind: z.ZodLiteral<"instant">;
26
+ value: z.ZodString;
27
+ }, z.core.$strip>, z.ZodObject<{
28
+ kind: z.ZodLiteral<"duration">;
29
+ value: z.ZodNumber;
30
+ unit: z.ZodEnum<{
31
+ ms: "ms";
32
+ s: "s";
33
+ min: "min";
34
+ h: "h";
35
+ d: "d";
36
+ }>;
37
+ }, z.core.$strip>, z.ZodObject<{
38
+ kind: z.ZodLiteral<"complex">;
39
+ re: z.ZodNumber;
40
+ im: z.ZodNumber;
41
+ unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
42
+ }, z.core.$strip>], "kind">;
43
+ type ComputedValue = z.infer<typeof ComputedValueSchema>;
44
+ /** An operand with no `unit` is dimensionless (an empty map) for comparison purposes. */
45
+ declare function unitsEqual(a: Unit | undefined, b: Unit | undefined): boolean;
46
+ /** Multiplying two unit-tagged numbers adds exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
47
+ declare function combineUnitsForMultiply(a: Unit | undefined, b: Unit | undefined): Unit;
48
+ /** Dividing two unit-tagged numbers subtracts exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
49
+ declare function combineUnitsForDivide(a: Unit | undefined, b: Unit | undefined): Unit;
50
+ //#endregion
51
+ export { Unit as a, combineUnitsForMultiply as c, DurationUnitSchema as i, unitsEqual as l, ComputedValueSchema as n, UnitSchema as o, DurationUnit as r, combineUnitsForDivide as s, ComputedValue as t };
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let zod = require("zod");
3
3
  //#region src/computed-value.ts
4
- /** Dimension symbol -> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
4
+ /** Dimension symbol -\> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
5
5
  const UnitSchema = zod.z.record(zod.z.string(), zod.z.number());
6
6
  const DurationUnitSchema = zod.z.enum([
7
7
  "ms",
@@ -1,51 +1,2 @@
1
- import { z } from "zod";
2
- //#region src/computed-value.d.ts
3
- /** Dimension symbol -> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
4
- declare const UnitSchema: z.ZodRecord<z.ZodString, z.ZodNumber>;
5
- type Unit = z.infer<typeof UnitSchema>;
6
- declare const DurationUnitSchema: z.ZodEnum<{
7
- ms: "ms";
8
- s: "s";
9
- min: "min";
10
- h: "h";
11
- d: "d";
12
- }>;
13
- type DurationUnit = z.infer<typeof DurationUnitSchema>;
14
- declare const ComputedValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
15
- kind: z.ZodLiteral<"number">;
16
- value: z.ZodNumber;
17
- unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
18
- }, z.core.$strip>, z.ZodObject<{
19
- kind: z.ZodLiteral<"text">;
20
- value: z.ZodString;
21
- }, z.core.$strip>, z.ZodObject<{
22
- kind: z.ZodLiteral<"boolean">;
23
- value: z.ZodBoolean;
24
- }, z.core.$strip>, z.ZodObject<{
25
- kind: z.ZodLiteral<"instant">;
26
- value: z.ZodString;
27
- }, z.core.$strip>, z.ZodObject<{
28
- kind: z.ZodLiteral<"duration">;
29
- value: z.ZodNumber;
30
- unit: z.ZodEnum<{
31
- ms: "ms";
32
- s: "s";
33
- min: "min";
34
- h: "h";
35
- d: "d";
36
- }>;
37
- }, z.core.$strip>, z.ZodObject<{
38
- kind: z.ZodLiteral<"complex">;
39
- re: z.ZodNumber;
40
- im: z.ZodNumber;
41
- unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
42
- }, z.core.$strip>], "kind">;
43
- type ComputedValue = z.infer<typeof ComputedValueSchema>;
44
- /** An operand with no `unit` is dimensionless (an empty map) for comparison purposes. */
45
- declare function unitsEqual(a: Unit | undefined, b: Unit | undefined): boolean;
46
- /** Multiplying two unit-tagged numbers adds exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
47
- declare function combineUnitsForMultiply(a: Unit | undefined, b: Unit | undefined): Unit;
48
- /** Dividing two unit-tagged numbers subtracts exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
49
- declare function combineUnitsForDivide(a: Unit | undefined, b: Unit | undefined): Unit;
50
- //#endregion
1
+ import { a as Unit, c as combineUnitsForMultiply, i as DurationUnitSchema, l as unitsEqual, n as ComputedValueSchema, o as UnitSchema, r as DurationUnit, s as combineUnitsForDivide, t as ComputedValue } from "./computed-value-CbRF0Izc.cjs";
51
2
  export { ComputedValue, ComputedValueSchema, DurationUnit, DurationUnitSchema, Unit, UnitSchema, combineUnitsForDivide, combineUnitsForMultiply, unitsEqual };
@@ -1,51 +1,2 @@
1
- import { z } from "zod";
2
- //#region src/computed-value.d.ts
3
- /** Dimension symbol -> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
4
- declare const UnitSchema: z.ZodRecord<z.ZodString, z.ZodNumber>;
5
- type Unit = z.infer<typeof UnitSchema>;
6
- declare const DurationUnitSchema: z.ZodEnum<{
7
- ms: "ms";
8
- s: "s";
9
- min: "min";
10
- h: "h";
11
- d: "d";
12
- }>;
13
- type DurationUnit = z.infer<typeof DurationUnitSchema>;
14
- declare const ComputedValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
15
- kind: z.ZodLiteral<"number">;
16
- value: z.ZodNumber;
17
- unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
18
- }, z.core.$strip>, z.ZodObject<{
19
- kind: z.ZodLiteral<"text">;
20
- value: z.ZodString;
21
- }, z.core.$strip>, z.ZodObject<{
22
- kind: z.ZodLiteral<"boolean">;
23
- value: z.ZodBoolean;
24
- }, z.core.$strip>, z.ZodObject<{
25
- kind: z.ZodLiteral<"instant">;
26
- value: z.ZodString;
27
- }, z.core.$strip>, z.ZodObject<{
28
- kind: z.ZodLiteral<"duration">;
29
- value: z.ZodNumber;
30
- unit: z.ZodEnum<{
31
- ms: "ms";
32
- s: "s";
33
- min: "min";
34
- h: "h";
35
- d: "d";
36
- }>;
37
- }, z.core.$strip>, z.ZodObject<{
38
- kind: z.ZodLiteral<"complex">;
39
- re: z.ZodNumber;
40
- im: z.ZodNumber;
41
- unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
42
- }, z.core.$strip>], "kind">;
43
- type ComputedValue = z.infer<typeof ComputedValueSchema>;
44
- /** An operand with no `unit` is dimensionless (an empty map) for comparison purposes. */
45
- declare function unitsEqual(a: Unit | undefined, b: Unit | undefined): boolean;
46
- /** Multiplying two unit-tagged numbers adds exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
47
- declare function combineUnitsForMultiply(a: Unit | undefined, b: Unit | undefined): Unit;
48
- /** Dividing two unit-tagged numbers subtracts exponents per dimension. An operand with no `unit` is treated as dimensionless (an empty map). */
49
- declare function combineUnitsForDivide(a: Unit | undefined, b: Unit | undefined): Unit;
50
- //#endregion
1
+ import { a as Unit, c as combineUnitsForMultiply, i as DurationUnitSchema, l as unitsEqual, n as ComputedValueSchema, o as UnitSchema, r as DurationUnit, s as combineUnitsForDivide, t as ComputedValue } from "./computed-value-CbRF0Izc.js";
51
2
  export { ComputedValue, ComputedValueSchema, DurationUnit, DurationUnitSchema, Unit, UnitSchema, combineUnitsForDivide, combineUnitsForMultiply, unitsEqual };
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  //#region src/computed-value.ts
3
- /** Dimension symbol -> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
3
+ /** Dimension symbol -\> exponent, e.g. `{ m: 1, s: -1 }` for metres per second. A bare symbol like `"kg"` is shorthand for `{ kg: 1 }`. */
4
4
  const UnitSchema = z.record(z.string(), z.number());
5
5
  const DurationUnitSchema = z.enum([
6
6
  "ms",
@@ -0,0 +1,24 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_evaluation = require("./evaluation.cjs");
3
+ //#region src/evaluator-budget.ts
4
+ /** A defense-in-depth guard against a long acyclic `treeReference` chain exhausting the call stack -- distinct from, and layered on top of, the cycle detector in evaluator.ts (`visitedTreeKeys`), which catches an actual repeat immediately and more precisely. */
5
+ const MAX_TREE_REFERENCE_DEPTH = 100;
6
+ /** 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. */
7
+ const DEFAULT_MAX_EVALUATION_NODES = 1e4;
8
+ /** Default cap on ordinary recursive-descent nesting depth -- see `createEvaluator`'s `maxNestingDepth` option, threaded through to `createEvaluationBudget` below. Set comfortably below the depth at which this evaluator's own recursive descent has been observed to exhaust the host call stack (a chain of plain `not` nodes wrapped around a single leaf, evaluated directly against this file under Node.js, failed consistently somewhere in the low thousands of nesting levels, with some run-to-run variance from whatever else already occupied the stack), while remaining far deeper than any legitimate hand-authored tree is ever likely to nest. Kept well clear of that measured failure point because the exact threshold varies by host runtime (a Cloudflare Workers isolate's own stack is smaller than Node's) and by how much of the stack the rest of the call chain has already used. */
9
+ const DEFAULT_MAX_NESTING_DEPTH = 500;
10
+ /** 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. */
11
+ function createEvaluationBudget(maxNodes, maxNestingDepth) {
12
+ /** Total predicate/expression nodes visited so far across the whole call -- shared by every branch of an `and`/`or`/`allOf`/`anyOf`/fold/quantifier through the closure below, so it accumulates across the whole traversal rather than resetting per branch. */
13
+ let nodesVisited = 0;
14
+ return { checkNode(nestingDepth) {
15
+ nodesVisited += 1;
16
+ if (nodesVisited > maxNodes) return require_evaluation.indeterminate("domain-error", `evaluation exceeded the maximum of ${maxNodes.toString()} nodes visited in a single call (resource exhausted)`);
17
+ if (nestingDepth >= maxNestingDepth) return require_evaluation.indeterminate("domain-error", `evaluation nesting depth exceeds the maximum of ${maxNestingDepth.toString()} (resource exhausted)`);
18
+ } };
19
+ }
20
+ //#endregion
21
+ exports.DEFAULT_MAX_EVALUATION_NODES = DEFAULT_MAX_EVALUATION_NODES;
22
+ exports.DEFAULT_MAX_NESTING_DEPTH = DEFAULT_MAX_NESTING_DEPTH;
23
+ exports.MAX_TREE_REFERENCE_DEPTH = MAX_TREE_REFERENCE_DEPTH;
24
+ exports.createEvaluationBudget = createEvaluationBudget;
@@ -0,0 +1,21 @@
1
+ import { Evaluation } from "./evaluation.cjs";
2
+ //#region src/evaluator-budget.d.ts
3
+ /** A defense-in-depth guard against a long acyclic `treeReference` chain exhausting the call stack -- distinct from, and layered on top of, the cycle detector in evaluator.ts (`visitedTreeKeys`), which catches an actual repeat immediately and more precisely. */
4
+ declare const MAX_TREE_REFERENCE_DEPTH = 100;
5
+ /** 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. */
6
+ declare const DEFAULT_MAX_EVALUATION_NODES = 10000;
7
+ /** Default cap on ordinary recursive-descent nesting depth -- see `createEvaluator`'s `maxNestingDepth` option, threaded through to `createEvaluationBudget` below. Set comfortably below the depth at which this evaluator's own recursive descent has been observed to exhaust the host call stack (a chain of plain `not` nodes wrapped around a single leaf, evaluated directly against this file under Node.js, failed consistently somewhere in the low thousands of nesting levels, with some run-to-run variance from whatever else already occupied the stack), while remaining far deeper than any legitimate hand-authored tree is ever likely to nest. Kept well clear of that measured failure point because the exact threshold varies by host runtime (a Cloudflare Workers isolate's own stack is smaller than Node's) and by how much of the stack the rest of the call chain has already used. */
8
+ declare const DEFAULT_MAX_NESTING_DEPTH = 500;
9
+ /**
10
+ * A single `evaluatePredicate`/`evaluateValue` call's resource limits, independent of and layered underneath `MAX_TREE_REFERENCE_DEPTH`'s own cross-tree chain guard above: that guard only advances at an actual `treeReference` resolution and says nothing about a plain, self-contained tree built from ordinary `and`/`or`/`fold`/`conditional`/quantifier nesting, with no `treeReference` node anywhere in it. This closes that gap for a consumer evaluating a tree it did not author and cannot fully trust before evaluation (e.g. a tree embedded in a signed but otherwise attacker-controlled payload).
11
+ *
12
+ * Exposed as a single `checkNode` method rather than a raw mutable counter, following the same all-callback shape `Resolvers` and `FunctionRegistry` use in evaluator.ts: every recursive call site threads this object through as `Readonly<EvaluationBudget>`, and that wrapper genuinely prevents tampering because the running node count lives in `createEvaluationBudget`'s own closure, never as an assignable property on the object itself.
13
+ */
14
+ interface EvaluationBudget {
15
+ /** Charges one node visit and checks both caps, returning the `Evaluation` to return immediately if either is now exceeded, or `undefined` if evaluation of this node may proceed. Called as the very first action inside `evaluatePredicateInternal`/`evaluateValueInternal`, before any of that node's own work or further recursion, so an exceeded budget is discovered before it can be spent on additional descent. */
16
+ checkNode: (nestingDepth: number) => Evaluation<never> | undefined;
17
+ }
18
+ /** 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. */
19
+ declare function createEvaluationBudget(maxNodes: number, maxNestingDepth: number): EvaluationBudget;
20
+ //#endregion
21
+ export { DEFAULT_MAX_EVALUATION_NODES, DEFAULT_MAX_NESTING_DEPTH, EvaluationBudget, MAX_TREE_REFERENCE_DEPTH, createEvaluationBudget };
@@ -0,0 +1,21 @@
1
+ import { Evaluation } from "./evaluation.js";
2
+ //#region src/evaluator-budget.d.ts
3
+ /** A defense-in-depth guard against a long acyclic `treeReference` chain exhausting the call stack -- distinct from, and layered on top of, the cycle detector in evaluator.ts (`visitedTreeKeys`), which catches an actual repeat immediately and more precisely. */
4
+ declare const MAX_TREE_REFERENCE_DEPTH = 100;
5
+ /** 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. */
6
+ declare const DEFAULT_MAX_EVALUATION_NODES = 10000;
7
+ /** Default cap on ordinary recursive-descent nesting depth -- see `createEvaluator`'s `maxNestingDepth` option, threaded through to `createEvaluationBudget` below. Set comfortably below the depth at which this evaluator's own recursive descent has been observed to exhaust the host call stack (a chain of plain `not` nodes wrapped around a single leaf, evaluated directly against this file under Node.js, failed consistently somewhere in the low thousands of nesting levels, with some run-to-run variance from whatever else already occupied the stack), while remaining far deeper than any legitimate hand-authored tree is ever likely to nest. Kept well clear of that measured failure point because the exact threshold varies by host runtime (a Cloudflare Workers isolate's own stack is smaller than Node's) and by how much of the stack the rest of the call chain has already used. */
8
+ declare const DEFAULT_MAX_NESTING_DEPTH = 500;
9
+ /**
10
+ * A single `evaluatePredicate`/`evaluateValue` call's resource limits, independent of and layered underneath `MAX_TREE_REFERENCE_DEPTH`'s own cross-tree chain guard above: that guard only advances at an actual `treeReference` resolution and says nothing about a plain, self-contained tree built from ordinary `and`/`or`/`fold`/`conditional`/quantifier nesting, with no `treeReference` node anywhere in it. This closes that gap for a consumer evaluating a tree it did not author and cannot fully trust before evaluation (e.g. a tree embedded in a signed but otherwise attacker-controlled payload).
11
+ *
12
+ * Exposed as a single `checkNode` method rather than a raw mutable counter, following the same all-callback shape `Resolvers` and `FunctionRegistry` use in evaluator.ts: every recursive call site threads this object through as `Readonly<EvaluationBudget>`, and that wrapper genuinely prevents tampering because the running node count lives in `createEvaluationBudget`'s own closure, never as an assignable property on the object itself.
13
+ */
14
+ interface EvaluationBudget {
15
+ /** Charges one node visit and checks both caps, returning the `Evaluation` to return immediately if either is now exceeded, or `undefined` if evaluation of this node may proceed. Called as the very first action inside `evaluatePredicateInternal`/`evaluateValueInternal`, before any of that node's own work or further recursion, so an exceeded budget is discovered before it can be spent on additional descent. */
16
+ checkNode: (nestingDepth: number) => Evaluation<never> | undefined;
17
+ }
18
+ /** 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. */
19
+ declare function createEvaluationBudget(maxNodes: number, maxNestingDepth: number): EvaluationBudget;
20
+ //#endregion
21
+ export { DEFAULT_MAX_EVALUATION_NODES, DEFAULT_MAX_NESTING_DEPTH, EvaluationBudget, MAX_TREE_REFERENCE_DEPTH, createEvaluationBudget };
@@ -0,0 +1,20 @@
1
+ import { indeterminate } from "./evaluation.js";
2
+ //#region src/evaluator-budget.ts
3
+ /** A defense-in-depth guard against a long acyclic `treeReference` chain exhausting the call stack -- distinct from, and layered on top of, the cycle detector in evaluator.ts (`visitedTreeKeys`), which catches an actual repeat immediately and more precisely. */
4
+ const MAX_TREE_REFERENCE_DEPTH = 100;
5
+ /** 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. */
6
+ const DEFAULT_MAX_EVALUATION_NODES = 1e4;
7
+ /** Default cap on ordinary recursive-descent nesting depth -- see `createEvaluator`'s `maxNestingDepth` option, threaded through to `createEvaluationBudget` below. Set comfortably below the depth at which this evaluator's own recursive descent has been observed to exhaust the host call stack (a chain of plain `not` nodes wrapped around a single leaf, evaluated directly against this file under Node.js, failed consistently somewhere in the low thousands of nesting levels, with some run-to-run variance from whatever else already occupied the stack), while remaining far deeper than any legitimate hand-authored tree is ever likely to nest. Kept well clear of that measured failure point because the exact threshold varies by host runtime (a Cloudflare Workers isolate's own stack is smaller than Node's) and by how much of the stack the rest of the call chain has already used. */
8
+ const DEFAULT_MAX_NESTING_DEPTH = 500;
9
+ /** 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. */
10
+ function createEvaluationBudget(maxNodes, maxNestingDepth) {
11
+ /** Total predicate/expression nodes visited so far across the whole call -- shared by every branch of an `and`/`or`/`allOf`/`anyOf`/fold/quantifier through the closure below, so it accumulates across the whole traversal rather than resetting per branch. */
12
+ let nodesVisited = 0;
13
+ return { checkNode(nestingDepth) {
14
+ nodesVisited += 1;
15
+ if (nodesVisited > maxNodes) return indeterminate("domain-error", `evaluation exceeded the maximum of ${maxNodes.toString()} nodes visited in a single call (resource exhausted)`);
16
+ if (nestingDepth >= maxNestingDepth) return indeterminate("domain-error", `evaluation nesting depth exceeds the maximum of ${maxNestingDepth.toString()} (resource exhausted)`);
17
+ } };
18
+ }
19
+ //#endregion
20
+ export { DEFAULT_MAX_EVALUATION_NODES, DEFAULT_MAX_NESTING_DEPTH, MAX_TREE_REFERENCE_DEPTH, createEvaluationBudget };
@@ -0,0 +1,33 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/evaluator-collection.ts
3
+ /**
4
+ * Collection resolution shared by the quantifiers (`some`/`every`) and by `fold` in evaluator.ts: resolves the opaque `collection` reference to its concrete candidate list via `resolvers.resolveCollection`, then evaluates each candidate's optional `filter` (via the injected `evaluatePredicate`, see `EvaluatePredicate`'s own doc comment) with that candidate as its own evaluation context and the accumulator reset to `undefined` -- see the README's "Evaluation context" and "Pre-filtering which items participate" sections. Deliberately stops short of deciding how an indeterminate filter combines with the rest of the surrounding node: `some`/`every` fold a filter-indeterminate item in as its own vote via the surrounding OR/AND absorption, while `fold` has no absorbing value at all and goes indeterminate outright on the same condition -- the two callers need genuinely different combination logic over these same per-item outcomes, so this helper only produces the outcomes and leaves combining them to the caller.
5
+ */
6
+ async function resolveParticipatingItems(evaluatePredicate, collection, filter, context, resolvers, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth) {
7
+ const candidates = await resolvers.resolveCollection(collection, context);
8
+ return Promise.all(candidates.map(async (item) => {
9
+ if (filter === void 0) return {
10
+ item,
11
+ filterOutcome: "include"
12
+ };
13
+ const filterResult = await evaluatePredicate(filter, item, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
14
+ if (filterResult.status === "indeterminate") return {
15
+ item,
16
+ filterOutcome: filterResult
17
+ };
18
+ return {
19
+ item,
20
+ filterOutcome: filterResult.value ? "include" : "exclude"
21
+ };
22
+ }));
23
+ }
24
+ /** The first participating item (in declared collection order) whose `filter` evaluation was itself indeterminate, or `undefined` if every participating item's filter resolved definitely -- a filter-excluded item's own `"exclude"` outcome never counts here. Used only by `fold`, which -- unlike `some`/`every`'s OR/AND absorption -- has no absorbing value at all: any participating item's indeterminate filter makes the whole fold indeterminate outright, with no other item's outcome able to override it. */
25
+ function firstFilterIndeterminate(participating) {
26
+ for (const { filterOutcome } of participating) {
27
+ if (filterOutcome === "include" || filterOutcome === "exclude") continue;
28
+ if (filterOutcome.status === "indeterminate") return filterOutcome.reason;
29
+ }
30
+ }
31
+ //#endregion
32
+ exports.firstFilterIndeterminate = firstFilterIndeterminate;
33
+ exports.resolveParticipatingItems = resolveParticipatingItems;
@@ -0,0 +1,23 @@
1
+ import { t as ComputedValue } from "./computed-value-CbRF0Izc.cjs";
2
+ import { t as JsonValue } from "./json-value-B1Hjjjri.cjs";
3
+ import { PredicateNode } from "./tree.cjs";
4
+ import { Evaluation, IndeterminateReason } from "./evaluation.cjs";
5
+ import { EvaluationBudget } from "./evaluator-budget.cjs";
6
+ import { FunctionRegistry } from "./functions.cjs";
7
+ import { EvaluationContext, Resolvers } from "./resolvers.cjs";
8
+ //#region src/evaluator-collection.d.ts
9
+ /** `resolveParticipatingItems`'s own view of `evaluatePredicateInternal` -- the exact signature that function has in evaluator.ts, injected here rather than imported directly so this module has no dependency back on evaluator.ts. Evaluating a `filter` genuinely does need the full recursive predicate evaluator (a filter can itself be arbitrarily nested), but taking it as a parameter rather than an import means this collection-resolution logic and evaluator.ts's mutually-recursive `evaluatePredicateInternal`/`evaluateValueInternal` pair never import each other, so there is no circular-import hazard between the two files. */
10
+ type EvaluatePredicate = (node: PredicateNode, context: EvaluationContext, resolvers: Readonly<Resolvers>, accumulator: ComputedValue | undefined, functions: Readonly<FunctionRegistry>, visitedTreeKeys: ReadonlySet<string>, treeReferenceDepth: number, budget: Readonly<EvaluationBudget>, nestingDepth: number) => Promise<Evaluation<boolean>>;
11
+ /** A collection candidate paired with its own pre-filter outcome: `"include"`/`"exclude"` when `filter` resolved definitely, or the filter's own indeterminate `Evaluation` when it did not (there is no third, definite-but-neither branch -- see `resolveParticipatingItems` below). */
12
+ interface ResolvedCollectionItem {
13
+ readonly item: unknown;
14
+ readonly filterOutcome: "include" | "exclude" | Evaluation<never>;
15
+ }
16
+ /**
17
+ * Collection resolution shared by the quantifiers (`some`/`every`) and by `fold` in evaluator.ts: resolves the opaque `collection` reference to its concrete candidate list via `resolvers.resolveCollection`, then evaluates each candidate's optional `filter` (via the injected `evaluatePredicate`, see `EvaluatePredicate`'s own doc comment) with that candidate as its own evaluation context and the accumulator reset to `undefined` -- see the README's "Evaluation context" and "Pre-filtering which items participate" sections. Deliberately stops short of deciding how an indeterminate filter combines with the rest of the surrounding node: `some`/`every` fold a filter-indeterminate item in as its own vote via the surrounding OR/AND absorption, while `fold` has no absorbing value at all and goes indeterminate outright on the same condition -- the two callers need genuinely different combination logic over these same per-item outcomes, so this helper only produces the outcomes and leaves combining them to the caller.
18
+ */
19
+ declare function resolveParticipatingItems(evaluatePredicate: EvaluatePredicate, collection: JsonValue, filter: PredicateNode | undefined, context: EvaluationContext, resolvers: Readonly<Resolvers>, functions: Readonly<FunctionRegistry>, visitedTreeKeys: ReadonlySet<string>, treeReferenceDepth: number, budget: Readonly<EvaluationBudget>, nestingDepth: number): Promise<ResolvedCollectionItem[]>;
20
+ /** The first participating item (in declared collection order) whose `filter` evaluation was itself indeterminate, or `undefined` if every participating item's filter resolved definitely -- a filter-excluded item's own `"exclude"` outcome never counts here. Used only by `fold`, which -- unlike `some`/`every`'s OR/AND absorption -- has no absorbing value at all: any participating item's indeterminate filter makes the whole fold indeterminate outright, with no other item's outcome able to override it. */
21
+ declare function firstFilterIndeterminate(participating: readonly ResolvedCollectionItem[]): IndeterminateReason | undefined;
22
+ //#endregion
23
+ export { EvaluatePredicate, ResolvedCollectionItem, firstFilterIndeterminate, resolveParticipatingItems };
@@ -0,0 +1,23 @@
1
+ import { t as ComputedValue } from "./computed-value-CbRF0Izc.js";
2
+ import { t as JsonValue } from "./json-value-B1Hjjjri.js";
3
+ import { PredicateNode } from "./tree.js";
4
+ import { Evaluation, IndeterminateReason } from "./evaluation.js";
5
+ import { EvaluationBudget } from "./evaluator-budget.js";
6
+ import { FunctionRegistry } from "./functions.js";
7
+ import { EvaluationContext, Resolvers } from "./resolvers.js";
8
+ //#region src/evaluator-collection.d.ts
9
+ /** `resolveParticipatingItems`'s own view of `evaluatePredicateInternal` -- the exact signature that function has in evaluator.ts, injected here rather than imported directly so this module has no dependency back on evaluator.ts. Evaluating a `filter` genuinely does need the full recursive predicate evaluator (a filter can itself be arbitrarily nested), but taking it as a parameter rather than an import means this collection-resolution logic and evaluator.ts's mutually-recursive `evaluatePredicateInternal`/`evaluateValueInternal` pair never import each other, so there is no circular-import hazard between the two files. */
10
+ type EvaluatePredicate = (node: PredicateNode, context: EvaluationContext, resolvers: Readonly<Resolvers>, accumulator: ComputedValue | undefined, functions: Readonly<FunctionRegistry>, visitedTreeKeys: ReadonlySet<string>, treeReferenceDepth: number, budget: Readonly<EvaluationBudget>, nestingDepth: number) => Promise<Evaluation<boolean>>;
11
+ /** A collection candidate paired with its own pre-filter outcome: `"include"`/`"exclude"` when `filter` resolved definitely, or the filter's own indeterminate `Evaluation` when it did not (there is no third, definite-but-neither branch -- see `resolveParticipatingItems` below). */
12
+ interface ResolvedCollectionItem {
13
+ readonly item: unknown;
14
+ readonly filterOutcome: "include" | "exclude" | Evaluation<never>;
15
+ }
16
+ /**
17
+ * Collection resolution shared by the quantifiers (`some`/`every`) and by `fold` in evaluator.ts: resolves the opaque `collection` reference to its concrete candidate list via `resolvers.resolveCollection`, then evaluates each candidate's optional `filter` (via the injected `evaluatePredicate`, see `EvaluatePredicate`'s own doc comment) with that candidate as its own evaluation context and the accumulator reset to `undefined` -- see the README's "Evaluation context" and "Pre-filtering which items participate" sections. Deliberately stops short of deciding how an indeterminate filter combines with the rest of the surrounding node: `some`/`every` fold a filter-indeterminate item in as its own vote via the surrounding OR/AND absorption, while `fold` has no absorbing value at all and goes indeterminate outright on the same condition -- the two callers need genuinely different combination logic over these same per-item outcomes, so this helper only produces the outcomes and leaves combining them to the caller.
18
+ */
19
+ declare function resolveParticipatingItems(evaluatePredicate: EvaluatePredicate, collection: JsonValue, filter: PredicateNode | undefined, context: EvaluationContext, resolvers: Readonly<Resolvers>, functions: Readonly<FunctionRegistry>, visitedTreeKeys: ReadonlySet<string>, treeReferenceDepth: number, budget: Readonly<EvaluationBudget>, nestingDepth: number): Promise<ResolvedCollectionItem[]>;
20
+ /** The first participating item (in declared collection order) whose `filter` evaluation was itself indeterminate, or `undefined` if every participating item's filter resolved definitely -- a filter-excluded item's own `"exclude"` outcome never counts here. Used only by `fold`, which -- unlike `some`/`every`'s OR/AND absorption -- has no absorbing value at all: any participating item's indeterminate filter makes the whole fold indeterminate outright, with no other item's outcome able to override it. */
21
+ declare function firstFilterIndeterminate(participating: readonly ResolvedCollectionItem[]): IndeterminateReason | undefined;
22
+ //#endregion
23
+ export { EvaluatePredicate, ResolvedCollectionItem, firstFilterIndeterminate, resolveParticipatingItems };
@@ -0,0 +1,31 @@
1
+ //#region src/evaluator-collection.ts
2
+ /**
3
+ * Collection resolution shared by the quantifiers (`some`/`every`) and by `fold` in evaluator.ts: resolves the opaque `collection` reference to its concrete candidate list via `resolvers.resolveCollection`, then evaluates each candidate's optional `filter` (via the injected `evaluatePredicate`, see `EvaluatePredicate`'s own doc comment) with that candidate as its own evaluation context and the accumulator reset to `undefined` -- see the README's "Evaluation context" and "Pre-filtering which items participate" sections. Deliberately stops short of deciding how an indeterminate filter combines with the rest of the surrounding node: `some`/`every` fold a filter-indeterminate item in as its own vote via the surrounding OR/AND absorption, while `fold` has no absorbing value at all and goes indeterminate outright on the same condition -- the two callers need genuinely different combination logic over these same per-item outcomes, so this helper only produces the outcomes and leaves combining them to the caller.
4
+ */
5
+ async function resolveParticipatingItems(evaluatePredicate, collection, filter, context, resolvers, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth) {
6
+ const candidates = await resolvers.resolveCollection(collection, context);
7
+ return Promise.all(candidates.map(async (item) => {
8
+ if (filter === void 0) return {
9
+ item,
10
+ filterOutcome: "include"
11
+ };
12
+ const filterResult = await evaluatePredicate(filter, item, resolvers, void 0, functions, visitedTreeKeys, treeReferenceDepth, budget, nestingDepth + 1);
13
+ if (filterResult.status === "indeterminate") return {
14
+ item,
15
+ filterOutcome: filterResult
16
+ };
17
+ return {
18
+ item,
19
+ filterOutcome: filterResult.value ? "include" : "exclude"
20
+ };
21
+ }));
22
+ }
23
+ /** The first participating item (in declared collection order) whose `filter` evaluation was itself indeterminate, or `undefined` if every participating item's filter resolved definitely -- a filter-excluded item's own `"exclude"` outcome never counts here. Used only by `fold`, which -- unlike `some`/`every`'s OR/AND absorption -- has no absorbing value at all: any participating item's indeterminate filter makes the whole fold indeterminate outright, with no other item's outcome able to override it. */
24
+ function firstFilterIndeterminate(participating) {
25
+ for (const { filterOutcome } of participating) {
26
+ if (filterOutcome === "include" || filterOutcome === "exclude") continue;
27
+ if (filterOutcome.status === "indeterminate") return filterOutcome.reason;
28
+ }
29
+ }
30
+ //#endregion
31
+ export { firstFilterIndeterminate, resolveParticipatingItems };
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_evaluator_budget = require("./evaluator-budget.cjs");
3
+ const require_evaluator = require("./evaluator.cjs");
4
+ const require_functions = require("./functions.cjs");
5
+ //#region src/evaluator-factory.ts
6
+ /**
7
+ * Builds a bound `{ evaluatePredicate, evaluateValue }` pair over a caller-supplied function registry for `call` nodes -- the registry is bound once, at construction time, unlike `resolvers`, which are supplied fresh to every call. `maxNodes` and `maxNestingDepth` configure that same pair's own `EvaluationBudget` (see its doc comment in evaluator-budget.ts), created fresh for every top-level `evaluatePredicate`/`evaluateValue` invocation so budgets never leak between unrelated calls. The bare module-level `evaluatePredicate`/`evaluateValue` exports below are `createEvaluator({})`'s output, so both caps default to `DEFAULT_MAX_EVALUATION_NODES`/`DEFAULT_MAX_NESTING_DEPTH` for every caller that does not explicitly configure them.
8
+ */
9
+ function createEvaluator({ functions = require_functions.emptyFunctionRegistry, maxNodes = require_evaluator_budget.DEFAULT_MAX_EVALUATION_NODES, maxNestingDepth = 500 }) {
10
+ return {
11
+ evaluatePredicate: async (node, context, resolvers) => require_evaluator.evaluatePredicateInternal(node, context, resolvers, void 0, functions, /* @__PURE__ */ new Set(), 0, require_evaluator_budget.createEvaluationBudget(maxNodes, maxNestingDepth), 0),
12
+ evaluateValue: async (node, context, resolvers) => require_evaluator.evaluateValueInternal(node, context, resolvers, void 0, functions, /* @__PURE__ */ new Set(), 0, require_evaluator_budget.createEvaluationBudget(maxNodes, maxNestingDepth), 0)
13
+ };
14
+ }
15
+ const { evaluatePredicate, evaluateValue } = createEvaluator({});
16
+ //#endregion
17
+ exports.createEvaluator = createEvaluator;
18
+ exports.evaluatePredicate = evaluatePredicate;
19
+ exports.evaluateValue = evaluateValue;
@@ -0,0 +1,22 @@
1
+ import { t as ComputedValue } from "./computed-value-CbRF0Izc.cjs";
2
+ import { ExpressionNode, PredicateNode } from "./tree.cjs";
3
+ import { Evaluation } from "./evaluation.cjs";
4
+ import { FunctionRegistry } from "./functions.cjs";
5
+ import { EvaluationContext, Resolvers } from "./resolvers.cjs";
6
+ //#region src/evaluator-factory.d.ts
7
+ /**
8
+ * Builds a bound `{ evaluatePredicate, evaluateValue }` pair over a caller-supplied function registry for `call` nodes -- the registry is bound once, at construction time, unlike `resolvers`, which are supplied fresh to every call. `maxNodes` and `maxNestingDepth` configure that same pair's own `EvaluationBudget` (see its doc comment in evaluator-budget.ts), created fresh for every top-level `evaluatePredicate`/`evaluateValue` invocation so budgets never leak between unrelated calls. The bare module-level `evaluatePredicate`/`evaluateValue` exports below are `createEvaluator({})`'s output, so both caps default to `DEFAULT_MAX_EVALUATION_NODES`/`DEFAULT_MAX_NESTING_DEPTH` for every caller that does not explicitly configure them.
9
+ */
10
+ declare function createEvaluator({ functions, maxNodes, maxNestingDepth }: {
11
+ functions?: FunctionRegistry;
12
+ /** Caps the total number of predicate/expression nodes a single `evaluatePredicate`/`evaluateValue` call may visit -- see `createEvaluationBudget`. Defaults to `DEFAULT_MAX_EVALUATION_NODES`. */
13
+ maxNodes?: number;
14
+ /** Caps ordinary recursive-descent nesting depth, independent of `MAX_TREE_REFERENCE_DEPTH`'s own `treeReference` chain-depth cap -- see `createEvaluationBudget`. Defaults to `DEFAULT_MAX_NESTING_DEPTH`. */
15
+ maxNestingDepth?: number;
16
+ }): {
17
+ evaluatePredicate: (node: PredicateNode, context: EvaluationContext, resolvers: Readonly<Resolvers>) => Promise<Evaluation<boolean>>;
18
+ evaluateValue: (node: ExpressionNode, context: EvaluationContext, resolvers: Readonly<Resolvers>) => Promise<Evaluation<ComputedValue>>;
19
+ };
20
+ declare const evaluatePredicate: (node: PredicateNode, context: EvaluationContext, resolvers: Readonly<Resolvers>) => Promise<Evaluation<boolean>>, evaluateValue: (node: ExpressionNode, context: EvaluationContext, resolvers: Readonly<Resolvers>) => Promise<Evaluation<ComputedValue>>;
21
+ //#endregion
22
+ export { createEvaluator, evaluatePredicate, evaluateValue };
@@ -0,0 +1,22 @@
1
+ import { t as ComputedValue } from "./computed-value-CbRF0Izc.js";
2
+ import { ExpressionNode, PredicateNode } from "./tree.js";
3
+ import { Evaluation } from "./evaluation.js";
4
+ import { FunctionRegistry } from "./functions.js";
5
+ import { EvaluationContext, Resolvers } from "./resolvers.js";
6
+ //#region src/evaluator-factory.d.ts
7
+ /**
8
+ * Builds a bound `{ evaluatePredicate, evaluateValue }` pair over a caller-supplied function registry for `call` nodes -- the registry is bound once, at construction time, unlike `resolvers`, which are supplied fresh to every call. `maxNodes` and `maxNestingDepth` configure that same pair's own `EvaluationBudget` (see its doc comment in evaluator-budget.ts), created fresh for every top-level `evaluatePredicate`/`evaluateValue` invocation so budgets never leak between unrelated calls. The bare module-level `evaluatePredicate`/`evaluateValue` exports below are `createEvaluator({})`'s output, so both caps default to `DEFAULT_MAX_EVALUATION_NODES`/`DEFAULT_MAX_NESTING_DEPTH` for every caller that does not explicitly configure them.
9
+ */
10
+ declare function createEvaluator({ functions, maxNodes, maxNestingDepth }: {
11
+ functions?: FunctionRegistry;
12
+ /** Caps the total number of predicate/expression nodes a single `evaluatePredicate`/`evaluateValue` call may visit -- see `createEvaluationBudget`. Defaults to `DEFAULT_MAX_EVALUATION_NODES`. */
13
+ maxNodes?: number;
14
+ /** Caps ordinary recursive-descent nesting depth, independent of `MAX_TREE_REFERENCE_DEPTH`'s own `treeReference` chain-depth cap -- see `createEvaluationBudget`. Defaults to `DEFAULT_MAX_NESTING_DEPTH`. */
15
+ maxNestingDepth?: number;
16
+ }): {
17
+ evaluatePredicate: (node: PredicateNode, context: EvaluationContext, resolvers: Readonly<Resolvers>) => Promise<Evaluation<boolean>>;
18
+ evaluateValue: (node: ExpressionNode, context: EvaluationContext, resolvers: Readonly<Resolvers>) => Promise<Evaluation<ComputedValue>>;
19
+ };
20
+ declare const evaluatePredicate: (node: PredicateNode, context: EvaluationContext, resolvers: Readonly<Resolvers>) => Promise<Evaluation<boolean>>, evaluateValue: (node: ExpressionNode, context: EvaluationContext, resolvers: Readonly<Resolvers>) => Promise<Evaluation<ComputedValue>>;
21
+ //#endregion
22
+ export { createEvaluator, evaluatePredicate, evaluateValue };
@@ -0,0 +1,16 @@
1
+ import { DEFAULT_MAX_EVALUATION_NODES, createEvaluationBudget } from "./evaluator-budget.js";
2
+ import { evaluatePredicateInternal, evaluateValueInternal } from "./evaluator.js";
3
+ import { emptyFunctionRegistry } from "./functions.js";
4
+ //#region src/evaluator-factory.ts
5
+ /**
6
+ * Builds a bound `{ evaluatePredicate, evaluateValue }` pair over a caller-supplied function registry for `call` nodes -- the registry is bound once, at construction time, unlike `resolvers`, which are supplied fresh to every call. `maxNodes` and `maxNestingDepth` configure that same pair's own `EvaluationBudget` (see its doc comment in evaluator-budget.ts), created fresh for every top-level `evaluatePredicate`/`evaluateValue` invocation so budgets never leak between unrelated calls. The bare module-level `evaluatePredicate`/`evaluateValue` exports below are `createEvaluator({})`'s output, so both caps default to `DEFAULT_MAX_EVALUATION_NODES`/`DEFAULT_MAX_NESTING_DEPTH` for every caller that does not explicitly configure them.
7
+ */
8
+ function createEvaluator({ functions = emptyFunctionRegistry, maxNodes = DEFAULT_MAX_EVALUATION_NODES, maxNestingDepth = 500 }) {
9
+ return {
10
+ evaluatePredicate: async (node, context, resolvers) => evaluatePredicateInternal(node, context, resolvers, void 0, functions, /* @__PURE__ */ new Set(), 0, createEvaluationBudget(maxNodes, maxNestingDepth), 0),
11
+ evaluateValue: async (node, context, resolvers) => evaluateValueInternal(node, context, resolvers, void 0, functions, /* @__PURE__ */ new Set(), 0, createEvaluationBudget(maxNodes, maxNestingDepth), 0)
12
+ };
13
+ }
14
+ const { evaluatePredicate, evaluateValue } = createEvaluator({});
15
+ //#endregion
16
+ export { createEvaluator, evaluatePredicate, evaluateValue };