trilean 1.13.11 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +1 -1
  2. package/dist/evaluator-operations.js +24 -4
  3. package/dist-cli/trilean.mjs +25 -5
  4. package/package.json +10 -20
  5. package/schemas/trilean.schema.json +1 -1
  6. package/dist/builtin-functions.cjs +0 -242
  7. package/dist/builtin-functions.d.cts +0 -13
  8. package/dist/complex-division.cjs +0 -47
  9. package/dist/complex-division.d.cts +0 -23
  10. package/dist/complex.cjs +0 -35
  11. package/dist/complex.d.cts +0 -23
  12. package/dist/computed-value.cjs +0 -80
  13. package/dist/computed-value.d.cts +0 -48
  14. package/dist/derived-aggregates.cjs +0 -73
  15. package/dist/derived-aggregates.d.cts +0 -9
  16. package/dist/derived-connectives.cjs +0 -39
  17. package/dist/derived-connectives.d.cts +0 -14
  18. package/dist/derived-patterns.cjs +0 -93
  19. package/dist/derived-patterns.d.cts +0 -4
  20. package/dist/derived-values.cjs +0 -23
  21. package/dist/derived-values.d.cts +0 -7
  22. package/dist/dist-ed78Tuwe.js +0 -1612
  23. package/dist/dist-ySX7cb5d.cjs +0 -1612
  24. package/dist/duration-order.cjs +0 -83
  25. package/dist/duration-order.d.cts +0 -21
  26. package/dist/evaluate-document.cjs +0 -92
  27. package/dist/evaluate-document.d.cts +0 -42
  28. package/dist/evaluation.cjs +0 -47
  29. package/dist/evaluation.d.cts +0 -29
  30. package/dist/evaluator-budget.cjs +0 -37
  31. package/dist/evaluator-budget.d.cts +0 -22
  32. package/dist/evaluator-collection.cjs +0 -33
  33. package/dist/evaluator-collection.d.cts +0 -21
  34. package/dist/evaluator-compiled.cjs +0 -310
  35. package/dist/evaluator-compiled.d.cts +0 -18
  36. package/dist/evaluator-effect.cjs +0 -57
  37. package/dist/evaluator-effect.d.cts +0 -40
  38. package/dist/evaluator-factory.cjs +0 -31
  39. package/dist/evaluator-factory.d.cts +0 -34
  40. package/dist/evaluator-literals.cjs +0 -42
  41. package/dist/evaluator-literals.d.cts +0 -8
  42. package/dist/evaluator-operations.cjs +0 -440
  43. package/dist/evaluator-operations.d.cts +0 -27
  44. package/dist/evaluator-test-helpers.cjs +0 -15030
  45. package/dist/evaluator-test-helpers.d.cts +0 -10
  46. package/dist/evaluator-test-helpers.d.ts +0 -10
  47. package/dist/evaluator-test-helpers.js +0 -14902
  48. package/dist/evaluator.cjs +0 -228
  49. package/dist/evaluator.d.cts +0 -12
  50. package/dist/functions.cjs +0 -4
  51. package/dist/functions.d.cts +0 -12
  52. package/dist/index.cjs +0 -97
  53. package/dist/index.d.cts +0 -18
  54. package/dist/input-resolvers.cjs +0 -109
  55. package/dist/input-resolvers.d.cts +0 -22
  56. package/dist/integer-power.cjs +0 -19
  57. package/dist/integer-power.d.cts +0 -11
  58. package/dist/json-value.cjs +0 -12
  59. package/dist/json-value.d.cts +0 -8
  60. package/dist/plain-record.cjs +0 -7
  61. package/dist/plain-record.d.cts +0 -2
  62. package/dist/resolvers.cjs +0 -0
  63. package/dist/resolvers.d.cts +0 -54
  64. package/dist/tree.cjs +0 -332
  65. package/dist/tree.d.cts +0 -446
@@ -1,54 +0,0 @@
1
- import { ComputedValue } from "./computed-value.cjs";
2
- import { JsonValue } from "./json-value.cjs";
3
- /**
4
- * An opaque, purely in-process value supplied by the caller, never itself part of the serialised tree and never required to be JSON-serialisable. Descending into a `fold` or a quantifier replaces the context for the sub-node's evaluation with the single resolved item.
5
- */
6
- export type EvaluationContext = unknown;
7
- /**
8
- * A resolver's report that it has no value to give. `{ found: false }` says the value is known to be absent, and evaluates to an indeterminate `not-found`, which `exists` reads as a definite `false`. `{ found: false, notYetKnown: true }` says the value has not been supplied yet and may exist later, and evaluates to an indeterminate `not-yet-known`, which `exists` leaves indeterminate. Use it when evaluating a partial assignment, so that a definite result on the partial input is also the result on every completion of it. `notYetKnown: false` is the same as leaving it out.
9
- */
10
- export interface Absence {
11
- found: false;
12
- notYetKnown?: boolean;
13
- }
14
- export type Resolution = {
15
- found: true;
16
- value: ComputedValue;
17
- } | Absence;
18
- /** The `resolveTree` counterpart to `Resolution`: `found: true` carries the referenced tree as opaque JSON, re-validated by the evaluator (see the `treeReference` node kind) rather than trusted as already-shaped `PredicateNode`/`ExpressionNode`. Absence, known or not yet known, is reported exactly as it is for `Resolution`. */
19
- export type TreeResolution = {
20
- found: true;
21
- node: JsonValue;
22
- } | Absence;
23
- /**
24
- * Three core, required points of extension, plus two further independent optional ones (`resolveDelegate`, `resolveTree`), each supplied separately by the embedding consumer, each treated as pure data to hand over -- never as resolver logic living inside the schema itself. Plain TypeScript interfaces, not Zod schemas: resolvers are never serialised, only ever supplied in-process at evaluation time.
25
- */
26
- export interface Resolvers {
27
- /** Resolver 1 -- a single opaque key to a single value (`reference`). */
28
- resolveValue: (key: JsonValue, context: EvaluationContext) => Promise<Resolution>;
29
- /** Resolver 2 -- an opaque table identifier plus computed keys to a single value (`lookup`). */
30
- resolveLookup: (table: JsonValue, keys: readonly ComputedValue[], context: EvaluationContext) => Promise<Resolution>;
31
- /** Resolver 3 -- an opaque collection reference to a concrete list of items (`fold`/`some`/`every`). Always returns the full candidate list; narrowing which items participate is handled uniformly, after resolution, by each node's own `filter`. */
32
- resolveCollection: (collection: JsonValue, context: EvaluationContext) => Promise<unknown[]>;
33
- /** Optional, separate from the three core contracts -- see the `delegate` node kind. */
34
- resolveDelegate?: (system: string, payload: JsonValue, context: EvaluationContext) => Promise<Resolution>;
35
- /** Optional, separate from the three core contracts -- see the `treeReference` node kind. Absence is `wrong-type`, the same deliberate-absence treatment as an unregistered `resolveDelegate`, not a masked bug -- and keeps this an additive, non-breaking interface change for every existing consumer. */
36
- resolveTree?: (key: JsonValue, context: EvaluationContext) => Promise<TreeResolution>;
37
- }
38
- /**
39
- * The resolvers of a synchronous evaluator (`createSyncEvaluator`): the same points of extension as `Resolvers`, each returning its result directly instead of a promise. A resolver of a synchronous evaluator that returns a promise anyway makes the evaluation throw, since it cannot be awaited.
40
- */
41
- export interface SyncResolvers {
42
- /** Synchronous counterpart of `Resolvers.resolveValue`. */
43
- resolveValue: (key: JsonValue, context: EvaluationContext) => Resolution;
44
- /** Synchronous counterpart of `Resolvers.resolveLookup`. */
45
- resolveLookup: (table: JsonValue, keys: readonly ComputedValue[], context: EvaluationContext) => Resolution;
46
- /** Synchronous counterpart of `Resolvers.resolveCollection`. */
47
- resolveCollection: (collection: JsonValue, context: EvaluationContext) => unknown[];
48
- /** Synchronous counterpart of `Resolvers.resolveDelegate`. */
49
- resolveDelegate?: (system: string, payload: JsonValue, context: EvaluationContext) => Resolution;
50
- /** Synchronous counterpart of `Resolvers.resolveTree`. */
51
- resolveTree?: (key: JsonValue, context: EvaluationContext) => TreeResolution;
52
- }
53
- /** What the shared node rules accept: either flavour of resolvers, since they only ever hand each result to `wait`. */
54
- export type EvaluatorResolvers = Resolvers | SyncResolvers;
package/dist/tree.cjs DELETED
@@ -1,332 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_computed_value = require("./computed-value.cjs");
3
- const require_json_value = require("./json-value.cjs");
4
- let zod = require("zod");
5
- // src/tree.ts
6
- const ComparisonOperatorSchema = zod.z.enum([
7
- "gt",
8
- "gte",
9
- "lt",
10
- "lte",
11
- "eq",
12
- "neq"
13
- ]);
14
- const TextComparisonOperatorSchema = zod.z.enum([
15
- "equals",
16
- "notEquals",
17
- "matches",
18
- "notMatches",
19
- "portableMatches",
20
- "portableNotMatches"
21
- ]);
22
- const MembershipOperatorSchema = zod.z.enum(["in", "notIn"]);
23
- const ArithmeticOperatorSchema = zod.z.enum([
24
- "add",
25
- "subtract",
26
- "multiply",
27
- "divide",
28
- "power",
29
- "modulo"
30
- ]);
31
- const HitPolicySchema = zod.z.enum(["first", "unique"]);
32
- const NotNodeSchema = zod.z.object({
33
- kind: zod.z.literal("not"),
34
- get operand() {
35
- return PredicateNodeSchema;
36
- }
37
- });
38
- const AndNodeSchema = zod.z.object({
39
- kind: zod.z.literal("and"),
40
- get left() {
41
- return PredicateNodeSchema;
42
- },
43
- get right() {
44
- return PredicateNodeSchema;
45
- }
46
- });
47
- const OrNodeSchema = zod.z.object({
48
- kind: zod.z.literal("or"),
49
- get left() {
50
- return PredicateNodeSchema;
51
- },
52
- get right() {
53
- return PredicateNodeSchema;
54
- }
55
- });
56
- const AllOfNodeSchema = zod.z.object({
57
- kind: zod.z.literal("allOf"),
58
- get operands() {
59
- return zod.z.array(PredicateNodeSchema);
60
- }
61
- });
62
- const AnyOfNodeSchema = zod.z.object({
63
- kind: zod.z.literal("anyOf"),
64
- get operands() {
65
- return zod.z.array(PredicateNodeSchema);
66
- }
67
- });
68
- const CompareNodeSchema = zod.z.object({
69
- kind: zod.z.literal("compare"),
70
- op: ComparisonOperatorSchema,
71
- get left() {
72
- return ExpressionNodeSchema;
73
- },
74
- get right() {
75
- return ExpressionNodeSchema;
76
- }
77
- });
78
- const TextCompareNodeSchema = zod.z.object({
79
- kind: zod.z.literal("textCompare"),
80
- op: TextComparisonOperatorSchema,
81
- get left() {
82
- return ExpressionNodeSchema;
83
- },
84
- get right() {
85
- return ExpressionNodeSchema;
86
- }
87
- });
88
- const MemberOfNodeSchema = zod.z.object({
89
- kind: zod.z.literal("memberOf"),
90
- op: MembershipOperatorSchema,
91
- get operand() {
92
- return ExpressionNodeSchema;
93
- },
94
- get candidates() {
95
- return zod.z.array(ExpressionNodeSchema);
96
- }
97
- });
98
- const ExistsNodeSchema = zod.z.object({
99
- kind: zod.z.literal("exists"),
100
- get operand() {
101
- return ExpressionNodeSchema;
102
- }
103
- });
104
- const SomeNodeSchema = zod.z.object({
105
- kind: zod.z.literal("some"),
106
- collection: require_json_value.JsonValueSchema,
107
- get item() {
108
- return PredicateNodeSchema;
109
- },
110
- get filter() {
111
- return PredicateNodeSchema.optional();
112
- }
113
- });
114
- const EveryNodeSchema = zod.z.object({
115
- kind: zod.z.literal("every"),
116
- collection: require_json_value.JsonValueSchema,
117
- get item() {
118
- return PredicateNodeSchema;
119
- },
120
- get filter() {
121
- return PredicateNodeSchema.optional();
122
- }
123
- });
124
- /** Shared by both trees -- the only node kind valid in both PredicateNodeSchema's and ExpressionNodeSchema's own discriminated unions, appended as the last member of each below. Declared once, here, ahead of the predicate union that needs it first; the expression union further down references this exact same schema object again rather than declaring its own copy. See the `treeReference` section of README.md. */
125
- const TreeReferenceNodeSchema = zod.z.object({
126
- kind: zod.z.literal("treeReference"),
127
- key: require_json_value.JsonValueSchema
128
- });
129
- const PredicateNodeSchema = zod.z.discriminatedUnion("kind", [
130
- NotNodeSchema,
131
- AndNodeSchema,
132
- OrNodeSchema,
133
- AllOfNodeSchema,
134
- AnyOfNodeSchema,
135
- CompareNodeSchema,
136
- TextCompareNodeSchema,
137
- MemberOfNodeSchema,
138
- ExistsNodeSchema,
139
- SomeNodeSchema,
140
- EveryNodeSchema,
141
- TreeReferenceNodeSchema
142
- ]);
143
- const NumberLiteralNodeSchema = zod.z.object({
144
- kind: zod.z.literal("numberLiteral"),
145
- value: zod.z.number(),
146
- unit: require_computed_value.UnitSchema.optional()
147
- });
148
- const TextLiteralNodeSchema = zod.z.object({
149
- kind: zod.z.literal("textLiteral"),
150
- value: zod.z.string()
151
- });
152
- const BooleanLiteralNodeSchema = zod.z.object({
153
- kind: zod.z.literal("booleanLiteral"),
154
- value: zod.z.boolean()
155
- });
156
- const InstantLiteralNodeSchema = zod.z.object({
157
- kind: zod.z.literal("instantLiteral"),
158
- /** ISO-8601 timestamp. */
159
- value: zod.z.string()
160
- });
161
- const DurationLiteralNodeSchema = zod.z.object({
162
- kind: zod.z.literal("durationLiteral"),
163
- value: zod.z.number(),
164
- unit: require_computed_value.DurationUnitSchema
165
- });
166
- /**
167
- * The wire-format literal accepts either of the two authoring forms real-world complex data arrives in, discriminated structurally rather than by a `form` tag: rectangular (`re`/`im`), matching the `complex` computed-value kind's own single canonical representation exactly (see the "Complex values" section of README.md), or polar (`magnitude`/`phase`, in radians), for the domains that reason that way natively and would otherwise have to hand-compute the conversion before ever constructing the tree. `strictObject` on both members is what makes the two forms mutually exclusive on the wire -- a plain `object` would silently strip an unrecognised field rather than reject a payload that mixes both.
168
- *
169
- * The evaluator normalises whichever form was authored into the single rectangular `ComputedValue` immediately on evaluation (see `literalValue` in evaluator-literals.ts), so nothing downstream of that -- arithmetic, `compare`, `memberOf`, `negate` -- ever sees a polar value; they keep consuming the one canonical `complex` shape unchanged.
170
- */
171
- const ComplexRectangularLiteralNodeSchema = zod.z.strictObject({
172
- kind: zod.z.literal("complexLiteral"),
173
- re: zod.z.number(),
174
- im: zod.z.number(),
175
- unit: require_computed_value.UnitSchema.optional()
176
- });
177
- const ComplexPolarLiteralNodeSchema = zod.z.strictObject({
178
- kind: zod.z.literal("complexLiteral"),
179
- magnitude: zod.z.number(),
180
- phase: zod.z.number(),
181
- unit: require_computed_value.UnitSchema.optional()
182
- });
183
- /** Both literal forms share the one literal `kind: "complexLiteral"` value, which is exactly why this is a plain `z.union` rather than a `z.discriminatedUnion` -- `z.discriminatedUnion` requires a unique discriminant literal per member and throws ("Duplicate discriminator value") the moment two members share one. `ExpressionNodeSchema` below folds this plain union in alongside its own discriminated union of every other kind, rather than trying to host it as a normal member. */
184
- const ComplexLiteralNodeSchema = zod.z.union([ComplexRectangularLiteralNodeSchema, ComplexPolarLiteralNodeSchema]);
185
- const ReferenceNodeSchema = zod.z.object({
186
- kind: zod.z.literal("reference"),
187
- key: require_json_value.JsonValueSchema,
188
- unit: require_computed_value.UnitSchema.optional()
189
- });
190
- const ArithmeticNodeSchema = zod.z.object({
191
- kind: zod.z.literal("arithmetic"),
192
- op: ArithmeticOperatorSchema,
193
- get left() {
194
- return ExpressionNodeSchema;
195
- },
196
- get right() {
197
- return ExpressionNodeSchema;
198
- }
199
- });
200
- const NegateNodeSchema = zod.z.object({
201
- kind: zod.z.literal("negate"),
202
- get operand() {
203
- return ExpressionNodeSchema;
204
- }
205
- });
206
- const CallNodeSchema = zod.z.object({
207
- kind: zod.z.literal("call"),
208
- fn: zod.z.string(),
209
- get args() {
210
- return zod.z.array(ExpressionNodeSchema);
211
- }
212
- });
213
- const LookupNodeSchema = zod.z.object({
214
- kind: zod.z.literal("lookup"),
215
- table: require_json_value.JsonValueSchema,
216
- get keys() {
217
- return zod.z.array(ExpressionNodeSchema);
218
- }
219
- });
220
- const ConditionalCaseSchema = zod.z.object({
221
- get when() {
222
- return PredicateNodeSchema;
223
- },
224
- get then() {
225
- return ExpressionNodeSchema;
226
- }
227
- });
228
- const ConditionalNodeSchema = zod.z.object({
229
- kind: zod.z.literal("conditional"),
230
- /** Absent means `"first"` -- the exact, unchanged behaviour of every tree serialised before this field existed. A deliberate, meaningful default, not a masked-bug fallback; see the `conditional` section of README.md for `"unique"`'s own absorption rules. */
231
- hitPolicy: HitPolicySchema.optional(),
232
- get cases() {
233
- return zod.z.array(ConditionalCaseSchema);
234
- },
235
- get fallback() {
236
- return ExpressionNodeSchema;
237
- }
238
- });
239
- const FoldCombinerSchema = zod.z.discriminatedUnion("mode", [
240
- zod.z.object({
241
- mode: zod.z.literal("max"),
242
- get item() {
243
- return ExpressionNodeSchema;
244
- }
245
- }),
246
- zod.z.object({
247
- mode: zod.z.literal("min"),
248
- get item() {
249
- return ExpressionNodeSchema;
250
- }
251
- }),
252
- zod.z.object({
253
- mode: zod.z.literal("reduce"),
254
- get initial() {
255
- return ExpressionNodeSchema;
256
- },
257
- get combine() {
258
- return ExpressionNodeSchema;
259
- }
260
- })
261
- ]);
262
- const FoldNodeSchema = zod.z.object({
263
- kind: zod.z.literal("fold"),
264
- collection: require_json_value.JsonValueSchema,
265
- get filter() {
266
- return PredicateNodeSchema.optional();
267
- },
268
- combiner: FoldCombinerSchema
269
- });
270
- const AccumulatorNodeSchema = zod.z.object({ kind: zod.z.literal("accumulator") });
271
- const DelegateNodeSchema = zod.z.object({
272
- kind: zod.z.literal("delegate"),
273
- system: zod.z.string(),
274
- payload: require_json_value.JsonValueSchema
275
- });
276
- /** Every expression node kind except `complexLiteral`, which cannot be a member of this same discriminated union alongside its own two forms (see `ComplexLiteralNodeSchema` above) -- folded back in below via a plain `z.union` rather than `z.discriminatedUnion`. */
277
- const CoreExpressionNodeSchema = zod.z.discriminatedUnion("kind", [
278
- NumberLiteralNodeSchema,
279
- TextLiteralNodeSchema,
280
- BooleanLiteralNodeSchema,
281
- InstantLiteralNodeSchema,
282
- DurationLiteralNodeSchema,
283
- ReferenceNodeSchema,
284
- ArithmeticNodeSchema,
285
- NegateNodeSchema,
286
- CallNodeSchema,
287
- LookupNodeSchema,
288
- ConditionalNodeSchema,
289
- FoldNodeSchema,
290
- AccumulatorNodeSchema,
291
- DelegateNodeSchema,
292
- TreeReferenceNodeSchema
293
- ]);
294
- const ExpressionNodeSchema = zod.z.union([CoreExpressionNodeSchema, ComplexLiteralNodeSchema]);
295
- exports.AccumulatorNodeSchema = AccumulatorNodeSchema;
296
- exports.AllOfNodeSchema = AllOfNodeSchema;
297
- exports.AndNodeSchema = AndNodeSchema;
298
- exports.AnyOfNodeSchema = AnyOfNodeSchema;
299
- exports.ArithmeticNodeSchema = ArithmeticNodeSchema;
300
- exports.ArithmeticOperatorSchema = ArithmeticOperatorSchema;
301
- exports.BooleanLiteralNodeSchema = BooleanLiteralNodeSchema;
302
- exports.CallNodeSchema = CallNodeSchema;
303
- exports.CompareNodeSchema = CompareNodeSchema;
304
- exports.ComparisonOperatorSchema = ComparisonOperatorSchema;
305
- exports.ComplexLiteralNodeSchema = ComplexLiteralNodeSchema;
306
- exports.ComplexPolarLiteralNodeSchema = ComplexPolarLiteralNodeSchema;
307
- exports.ComplexRectangularLiteralNodeSchema = ComplexRectangularLiteralNodeSchema;
308
- exports.ConditionalCaseSchema = ConditionalCaseSchema;
309
- exports.ConditionalNodeSchema = ConditionalNodeSchema;
310
- exports.DelegateNodeSchema = DelegateNodeSchema;
311
- exports.DurationLiteralNodeSchema = DurationLiteralNodeSchema;
312
- exports.EveryNodeSchema = EveryNodeSchema;
313
- exports.ExistsNodeSchema = ExistsNodeSchema;
314
- exports.ExpressionNodeSchema = ExpressionNodeSchema;
315
- exports.FoldCombinerSchema = FoldCombinerSchema;
316
- exports.FoldNodeSchema = FoldNodeSchema;
317
- exports.HitPolicySchema = HitPolicySchema;
318
- exports.InstantLiteralNodeSchema = InstantLiteralNodeSchema;
319
- exports.LookupNodeSchema = LookupNodeSchema;
320
- exports.MemberOfNodeSchema = MemberOfNodeSchema;
321
- exports.MembershipOperatorSchema = MembershipOperatorSchema;
322
- exports.NegateNodeSchema = NegateNodeSchema;
323
- exports.NotNodeSchema = NotNodeSchema;
324
- exports.NumberLiteralNodeSchema = NumberLiteralNodeSchema;
325
- exports.OrNodeSchema = OrNodeSchema;
326
- exports.PredicateNodeSchema = PredicateNodeSchema;
327
- exports.ReferenceNodeSchema = ReferenceNodeSchema;
328
- exports.SomeNodeSchema = SomeNodeSchema;
329
- exports.TextCompareNodeSchema = TextCompareNodeSchema;
330
- exports.TextComparisonOperatorSchema = TextComparisonOperatorSchema;
331
- exports.TextLiteralNodeSchema = TextLiteralNodeSchema;
332
- exports.TreeReferenceNodeSchema = TreeReferenceNodeSchema;