trilean 1.0.13 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -26
- package/dist/complex.cjs +34 -0
- package/dist/complex.d.cts +23 -0
- package/dist/complex.d.ts +23 -0
- package/dist/complex.js +30 -0
- package/dist/computed-value.cjs +10 -0
- package/dist/computed-value.d.cts +8 -0
- package/dist/computed-value.d.ts +8 -0
- package/dist/computed-value.js +10 -0
- package/dist/derived-values.cjs +24 -0
- package/dist/derived-values.d.cts +10 -0
- package/dist/derived-values.d.ts +10 -0
- package/dist/derived-values.js +23 -0
- package/dist/evaluator.cjs +187 -36
- package/dist/evaluator.js +187 -36
- package/dist/index.cjs +14 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/resolvers.d.cts +11 -2
- package/dist/resolvers.d.ts +11 -2
- package/dist/tree.cjs +45 -3
- package/dist/tree.d.cts +78 -3
- package/dist/tree.d.ts +78 -3
- package/dist/tree.js +40 -4
- package/package.json +1 -1
- package/schemas/trilean.schema.json +1 -1
package/dist/tree.cjs
CHANGED
|
@@ -26,6 +26,7 @@ const ArithmeticOperatorSchema = zod.z.enum([
|
|
|
26
26
|
"power",
|
|
27
27
|
"modulo"
|
|
28
28
|
]);
|
|
29
|
+
const HitPolicySchema = zod.z.enum(["first", "unique"]);
|
|
29
30
|
const NotNodeSchema = zod.z.object({
|
|
30
31
|
kind: zod.z.literal("not"),
|
|
31
32
|
get operand() {
|
|
@@ -118,6 +119,11 @@ const EveryNodeSchema = zod.z.object({
|
|
|
118
119
|
return PredicateNodeSchema.optional();
|
|
119
120
|
}
|
|
120
121
|
});
|
|
122
|
+
/** 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. */
|
|
123
|
+
const TreeReferenceNodeSchema = zod.z.object({
|
|
124
|
+
kind: zod.z.literal("treeReference"),
|
|
125
|
+
key: require_json_value.JsonValueSchema
|
|
126
|
+
});
|
|
121
127
|
const PredicateNodeSchema = zod.z.discriminatedUnion("kind", [
|
|
122
128
|
NotNodeSchema,
|
|
123
129
|
AndNodeSchema,
|
|
@@ -129,7 +135,8 @@ const PredicateNodeSchema = zod.z.discriminatedUnion("kind", [
|
|
|
129
135
|
MemberOfNodeSchema,
|
|
130
136
|
ExistsNodeSchema,
|
|
131
137
|
SomeNodeSchema,
|
|
132
|
-
EveryNodeSchema
|
|
138
|
+
EveryNodeSchema,
|
|
139
|
+
TreeReferenceNodeSchema
|
|
133
140
|
]);
|
|
134
141
|
const NumberLiteralNodeSchema = zod.z.object({
|
|
135
142
|
kind: zod.z.literal("numberLiteral"),
|
|
@@ -140,6 +147,10 @@ const TextLiteralNodeSchema = zod.z.object({
|
|
|
140
147
|
kind: zod.z.literal("textLiteral"),
|
|
141
148
|
value: zod.z.string()
|
|
142
149
|
});
|
|
150
|
+
const BooleanLiteralNodeSchema = zod.z.object({
|
|
151
|
+
kind: zod.z.literal("booleanLiteral"),
|
|
152
|
+
value: zod.z.boolean()
|
|
153
|
+
});
|
|
143
154
|
const InstantLiteralNodeSchema = zod.z.object({
|
|
144
155
|
kind: zod.z.literal("instantLiteral"),
|
|
145
156
|
/** ISO-8601 timestamp. */
|
|
@@ -150,6 +161,25 @@ const DurationLiteralNodeSchema = zod.z.object({
|
|
|
150
161
|
value: zod.z.number(),
|
|
151
162
|
unit: require_computed_value.DurationUnitSchema
|
|
152
163
|
});
|
|
164
|
+
/**
|
|
165
|
+
* 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.
|
|
166
|
+
*
|
|
167
|
+
* The evaluator normalises whichever form was authored into the single rectangular `ComputedValue` immediately on evaluation (see the `complexLiteral` case in evaluator.ts), so nothing downstream of that -- arithmetic, `compare`, `memberOf`, `negate` -- ever sees a polar value; they keep consuming the one canonical `complex` shape unchanged.
|
|
168
|
+
*/
|
|
169
|
+
const ComplexRectangularLiteralNodeSchema = zod.z.strictObject({
|
|
170
|
+
kind: zod.z.literal("complexLiteral"),
|
|
171
|
+
re: zod.z.number(),
|
|
172
|
+
im: zod.z.number(),
|
|
173
|
+
unit: require_computed_value.UnitSchema.optional()
|
|
174
|
+
});
|
|
175
|
+
const ComplexPolarLiteralNodeSchema = zod.z.strictObject({
|
|
176
|
+
kind: zod.z.literal("complexLiteral"),
|
|
177
|
+
magnitude: zod.z.number(),
|
|
178
|
+
phase: zod.z.number(),
|
|
179
|
+
unit: require_computed_value.UnitSchema.optional()
|
|
180
|
+
});
|
|
181
|
+
/** 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. */
|
|
182
|
+
const ComplexLiteralNodeSchema = zod.z.union([ComplexRectangularLiteralNodeSchema, ComplexPolarLiteralNodeSchema]);
|
|
153
183
|
const ReferenceNodeSchema = zod.z.object({
|
|
154
184
|
kind: zod.z.literal("reference"),
|
|
155
185
|
key: require_json_value.JsonValueSchema,
|
|
@@ -195,6 +225,8 @@ const ConditionalCaseSchema = zod.z.object({
|
|
|
195
225
|
});
|
|
196
226
|
const ConditionalNodeSchema = zod.z.object({
|
|
197
227
|
kind: zod.z.literal("conditional"),
|
|
228
|
+
/** 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. */
|
|
229
|
+
hitPolicy: HitPolicySchema.optional(),
|
|
198
230
|
get cases() {
|
|
199
231
|
return zod.z.array(ConditionalCaseSchema);
|
|
200
232
|
},
|
|
@@ -239,9 +271,11 @@ const DelegateNodeSchema = zod.z.object({
|
|
|
239
271
|
system: zod.z.string(),
|
|
240
272
|
payload: require_json_value.JsonValueSchema
|
|
241
273
|
});
|
|
242
|
-
|
|
274
|
+
/** 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`. */
|
|
275
|
+
const CoreExpressionNodeSchema = zod.z.discriminatedUnion("kind", [
|
|
243
276
|
NumberLiteralNodeSchema,
|
|
244
277
|
TextLiteralNodeSchema,
|
|
278
|
+
BooleanLiteralNodeSchema,
|
|
245
279
|
InstantLiteralNodeSchema,
|
|
246
280
|
DurationLiteralNodeSchema,
|
|
247
281
|
ReferenceNodeSchema,
|
|
@@ -252,8 +286,10 @@ const ExpressionNodeSchema = zod.z.discriminatedUnion("kind", [
|
|
|
252
286
|
ConditionalNodeSchema,
|
|
253
287
|
FoldNodeSchema,
|
|
254
288
|
AccumulatorNodeSchema,
|
|
255
|
-
DelegateNodeSchema
|
|
289
|
+
DelegateNodeSchema,
|
|
290
|
+
TreeReferenceNodeSchema
|
|
256
291
|
]);
|
|
292
|
+
const ExpressionNodeSchema = zod.z.union([CoreExpressionNodeSchema, ComplexLiteralNodeSchema]);
|
|
257
293
|
//#endregion
|
|
258
294
|
exports.AccumulatorNodeSchema = AccumulatorNodeSchema;
|
|
259
295
|
exports.AllOfNodeSchema = AllOfNodeSchema;
|
|
@@ -261,9 +297,13 @@ exports.AndNodeSchema = AndNodeSchema;
|
|
|
261
297
|
exports.AnyOfNodeSchema = AnyOfNodeSchema;
|
|
262
298
|
exports.ArithmeticNodeSchema = ArithmeticNodeSchema;
|
|
263
299
|
exports.ArithmeticOperatorSchema = ArithmeticOperatorSchema;
|
|
300
|
+
exports.BooleanLiteralNodeSchema = BooleanLiteralNodeSchema;
|
|
264
301
|
exports.CallNodeSchema = CallNodeSchema;
|
|
265
302
|
exports.CompareNodeSchema = CompareNodeSchema;
|
|
266
303
|
exports.ComparisonOperatorSchema = ComparisonOperatorSchema;
|
|
304
|
+
exports.ComplexLiteralNodeSchema = ComplexLiteralNodeSchema;
|
|
305
|
+
exports.ComplexPolarLiteralNodeSchema = ComplexPolarLiteralNodeSchema;
|
|
306
|
+
exports.ComplexRectangularLiteralNodeSchema = ComplexRectangularLiteralNodeSchema;
|
|
267
307
|
exports.ConditionalCaseSchema = ConditionalCaseSchema;
|
|
268
308
|
exports.ConditionalNodeSchema = ConditionalNodeSchema;
|
|
269
309
|
exports.DelegateNodeSchema = DelegateNodeSchema;
|
|
@@ -273,6 +313,7 @@ exports.ExistsNodeSchema = ExistsNodeSchema;
|
|
|
273
313
|
exports.ExpressionNodeSchema = ExpressionNodeSchema;
|
|
274
314
|
exports.FoldCombinerSchema = FoldCombinerSchema;
|
|
275
315
|
exports.FoldNodeSchema = FoldNodeSchema;
|
|
316
|
+
exports.HitPolicySchema = HitPolicySchema;
|
|
276
317
|
exports.InstantLiteralNodeSchema = InstantLiteralNodeSchema;
|
|
277
318
|
exports.LookupNodeSchema = LookupNodeSchema;
|
|
278
319
|
exports.MemberOfNodeSchema = MemberOfNodeSchema;
|
|
@@ -287,3 +328,4 @@ exports.SomeNodeSchema = SomeNodeSchema;
|
|
|
287
328
|
exports.TextCompareNodeSchema = TextCompareNodeSchema;
|
|
288
329
|
exports.TextComparisonOperatorSchema = TextComparisonOperatorSchema;
|
|
289
330
|
exports.TextLiteralNodeSchema = TextLiteralNodeSchema;
|
|
331
|
+
exports.TreeReferenceNodeSchema = TreeReferenceNodeSchema;
|
package/dist/tree.d.cts
CHANGED
|
@@ -31,6 +31,11 @@ declare const ArithmeticOperatorSchema: z.ZodEnum<{
|
|
|
31
31
|
modulo: "modulo";
|
|
32
32
|
}>;
|
|
33
33
|
type ArithmeticOperator = z.infer<typeof ArithmeticOperatorSchema>;
|
|
34
|
+
declare const HitPolicySchema: z.ZodEnum<{
|
|
35
|
+
first: "first";
|
|
36
|
+
unique: "unique";
|
|
37
|
+
}>;
|
|
38
|
+
type HitPolicy = z.infer<typeof HitPolicySchema>;
|
|
34
39
|
declare const NotNodeSchema: z.ZodObject<{
|
|
35
40
|
kind: z.ZodLiteral<"not">;
|
|
36
41
|
operand: typeof PredicateNodeSchema;
|
|
@@ -113,6 +118,12 @@ declare const EveryNodeSchema: z.ZodObject<{
|
|
|
113
118
|
filter: z.ZodOptional<typeof PredicateNodeSchema>;
|
|
114
119
|
}, z.core.$strip>;
|
|
115
120
|
type EveryNode = z.infer<typeof EveryNodeSchema>;
|
|
121
|
+
/** 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. */
|
|
122
|
+
declare const TreeReferenceNodeSchema: z.ZodObject<{
|
|
123
|
+
kind: z.ZodLiteral<"treeReference">;
|
|
124
|
+
key: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
type TreeReferenceNode = z.infer<typeof TreeReferenceNodeSchema>;
|
|
116
127
|
declare const PredicateNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
117
128
|
kind: z.ZodLiteral<"not">;
|
|
118
129
|
operand: typeof PredicateNodeSchema;
|
|
@@ -173,6 +184,9 @@ declare const PredicateNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
173
184
|
collection: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
174
185
|
item: typeof PredicateNodeSchema;
|
|
175
186
|
filter: z.ZodOptional<typeof PredicateNodeSchema>;
|
|
187
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
188
|
+
kind: z.ZodLiteral<"treeReference">;
|
|
189
|
+
key: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
176
190
|
}, z.core.$strip>], "kind">;
|
|
177
191
|
type PredicateNode = z.infer<typeof PredicateNodeSchema>;
|
|
178
192
|
declare const NumberLiteralNodeSchema: z.ZodObject<{
|
|
@@ -186,6 +200,11 @@ declare const TextLiteralNodeSchema: z.ZodObject<{
|
|
|
186
200
|
value: z.ZodString;
|
|
187
201
|
}, z.core.$strip>;
|
|
188
202
|
type TextLiteralNode = z.infer<typeof TextLiteralNodeSchema>;
|
|
203
|
+
declare const BooleanLiteralNodeSchema: z.ZodObject<{
|
|
204
|
+
kind: z.ZodLiteral<"booleanLiteral">;
|
|
205
|
+
value: z.ZodBoolean;
|
|
206
|
+
}, z.core.$strip>;
|
|
207
|
+
type BooleanLiteralNode = z.infer<typeof BooleanLiteralNodeSchema>;
|
|
189
208
|
declare const InstantLiteralNodeSchema: z.ZodObject<{
|
|
190
209
|
kind: z.ZodLiteral<"instantLiteral">;
|
|
191
210
|
value: z.ZodString;
|
|
@@ -203,6 +222,38 @@ declare const DurationLiteralNodeSchema: z.ZodObject<{
|
|
|
203
222
|
}>;
|
|
204
223
|
}, z.core.$strip>;
|
|
205
224
|
type DurationLiteralNode = z.infer<typeof DurationLiteralNodeSchema>;
|
|
225
|
+
/**
|
|
226
|
+
* 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.
|
|
227
|
+
*
|
|
228
|
+
* The evaluator normalises whichever form was authored into the single rectangular `ComputedValue` immediately on evaluation (see the `complexLiteral` case in evaluator.ts), so nothing downstream of that -- arithmetic, `compare`, `memberOf`, `negate` -- ever sees a polar value; they keep consuming the one canonical `complex` shape unchanged.
|
|
229
|
+
*/
|
|
230
|
+
declare const ComplexRectangularLiteralNodeSchema: z.ZodObject<{
|
|
231
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
232
|
+
re: z.ZodNumber;
|
|
233
|
+
im: z.ZodNumber;
|
|
234
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
235
|
+
}, z.core.$strict>;
|
|
236
|
+
type ComplexRectangularLiteralNode = z.infer<typeof ComplexRectangularLiteralNodeSchema>;
|
|
237
|
+
declare const ComplexPolarLiteralNodeSchema: z.ZodObject<{
|
|
238
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
239
|
+
magnitude: z.ZodNumber;
|
|
240
|
+
phase: z.ZodNumber;
|
|
241
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
242
|
+
}, z.core.$strict>;
|
|
243
|
+
type ComplexPolarLiteralNode = z.infer<typeof ComplexPolarLiteralNodeSchema>;
|
|
244
|
+
/** 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. */
|
|
245
|
+
declare const ComplexLiteralNodeSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
246
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
247
|
+
re: z.ZodNumber;
|
|
248
|
+
im: z.ZodNumber;
|
|
249
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
250
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
251
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
252
|
+
magnitude: z.ZodNumber;
|
|
253
|
+
phase: z.ZodNumber;
|
|
254
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
255
|
+
}, z.core.$strict>]>;
|
|
256
|
+
type ComplexLiteralNode = z.infer<typeof ComplexLiteralNodeSchema>;
|
|
206
257
|
declare const ReferenceNodeSchema: z.ZodObject<{
|
|
207
258
|
kind: z.ZodLiteral<"reference">;
|
|
208
259
|
key: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
@@ -247,6 +298,10 @@ declare const ConditionalCaseSchema: z.ZodObject<{
|
|
|
247
298
|
type ConditionalCase = z.infer<typeof ConditionalCaseSchema>;
|
|
248
299
|
declare const ConditionalNodeSchema: z.ZodObject<{
|
|
249
300
|
kind: z.ZodLiteral<"conditional">;
|
|
301
|
+
hitPolicy: z.ZodOptional<z.ZodEnum<{
|
|
302
|
+
first: "first";
|
|
303
|
+
unique: "unique";
|
|
304
|
+
}>>;
|
|
250
305
|
cases: z.ZodArray<typeof ConditionalCaseSchema>;
|
|
251
306
|
fallback: typeof ExpressionNodeSchema;
|
|
252
307
|
}, z.core.$strip>;
|
|
@@ -290,13 +345,16 @@ declare const DelegateNodeSchema: z.ZodObject<{
|
|
|
290
345
|
payload: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
291
346
|
}, z.core.$strip>;
|
|
292
347
|
type DelegateNode = z.infer<typeof DelegateNodeSchema>;
|
|
293
|
-
declare const ExpressionNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
348
|
+
declare const ExpressionNodeSchema: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
294
349
|
kind: z.ZodLiteral<"numberLiteral">;
|
|
295
350
|
value: z.ZodNumber;
|
|
296
351
|
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
297
352
|
}, z.core.$strip>, z.ZodObject<{
|
|
298
353
|
kind: z.ZodLiteral<"textLiteral">;
|
|
299
354
|
value: z.ZodString;
|
|
355
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
356
|
+
kind: z.ZodLiteral<"booleanLiteral">;
|
|
357
|
+
value: z.ZodBoolean;
|
|
300
358
|
}, z.core.$strip>, z.ZodObject<{
|
|
301
359
|
kind: z.ZodLiteral<"instantLiteral">;
|
|
302
360
|
value: z.ZodString;
|
|
@@ -339,6 +397,10 @@ declare const ExpressionNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
339
397
|
keys: z.ZodArray<typeof ExpressionNodeSchema>;
|
|
340
398
|
}, z.core.$strip>, z.ZodObject<{
|
|
341
399
|
kind: z.ZodLiteral<"conditional">;
|
|
400
|
+
hitPolicy: z.ZodOptional<z.ZodEnum<{
|
|
401
|
+
first: "first";
|
|
402
|
+
unique: "unique";
|
|
403
|
+
}>>;
|
|
342
404
|
cases: z.ZodArray<typeof ConditionalCaseSchema>;
|
|
343
405
|
fallback: typeof ExpressionNodeSchema;
|
|
344
406
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -362,7 +424,20 @@ declare const ExpressionNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
362
424
|
kind: z.ZodLiteral<"delegate">;
|
|
363
425
|
system: z.ZodString;
|
|
364
426
|
payload: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
365
|
-
}, z.core.$strip
|
|
427
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
428
|
+
kind: z.ZodLiteral<"treeReference">;
|
|
429
|
+
key: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
430
|
+
}, z.core.$strip>], "kind">, z.ZodUnion<readonly [z.ZodObject<{
|
|
431
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
432
|
+
re: z.ZodNumber;
|
|
433
|
+
im: z.ZodNumber;
|
|
434
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
435
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
436
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
437
|
+
magnitude: z.ZodNumber;
|
|
438
|
+
phase: z.ZodNumber;
|
|
439
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
440
|
+
}, z.core.$strict>]>]>;
|
|
366
441
|
type ExpressionNode = z.infer<typeof ExpressionNodeSchema>;
|
|
367
442
|
//#endregion
|
|
368
|
-
export { AccumulatorNode, AccumulatorNodeSchema, AllOfNode, AllOfNodeSchema, AndNode, AndNodeSchema, AnyOfNode, AnyOfNodeSchema, ArithmeticNode, ArithmeticNodeSchema, ArithmeticOperator, ArithmeticOperatorSchema, CallNode, CallNodeSchema, CompareNode, CompareNodeSchema, ComparisonOperator, ComparisonOperatorSchema, ConditionalCase, ConditionalCaseSchema, ConditionalNode, ConditionalNodeSchema, DelegateNode, DelegateNodeSchema, DurationLiteralNode, DurationLiteralNodeSchema, EveryNode, EveryNodeSchema, ExistsNode, ExistsNodeSchema, ExpressionNode, ExpressionNodeSchema, FoldCombiner, FoldCombinerSchema, FoldNode, FoldNodeSchema, InstantLiteralNode, InstantLiteralNodeSchema, LookupNode, LookupNodeSchema, MemberOfNode, MemberOfNodeSchema, MembershipOperator, MembershipOperatorSchema, NegateNode, NegateNodeSchema, NotNode, NotNodeSchema, NumberLiteralNode, NumberLiteralNodeSchema, OrNode, OrNodeSchema, PredicateNode, PredicateNodeSchema, ReferenceNode, ReferenceNodeSchema, SomeNode, SomeNodeSchema, TextCompareNode, TextCompareNodeSchema, TextComparisonOperator, TextComparisonOperatorSchema, TextLiteralNode, TextLiteralNodeSchema };
|
|
443
|
+
export { AccumulatorNode, AccumulatorNodeSchema, AllOfNode, AllOfNodeSchema, AndNode, AndNodeSchema, AnyOfNode, AnyOfNodeSchema, ArithmeticNode, ArithmeticNodeSchema, ArithmeticOperator, ArithmeticOperatorSchema, BooleanLiteralNode, BooleanLiteralNodeSchema, CallNode, CallNodeSchema, CompareNode, CompareNodeSchema, ComparisonOperator, ComparisonOperatorSchema, ComplexLiteralNode, ComplexLiteralNodeSchema, ComplexPolarLiteralNode, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNode, ComplexRectangularLiteralNodeSchema, ConditionalCase, ConditionalCaseSchema, ConditionalNode, ConditionalNodeSchema, DelegateNode, DelegateNodeSchema, DurationLiteralNode, DurationLiteralNodeSchema, EveryNode, EveryNodeSchema, ExistsNode, ExistsNodeSchema, ExpressionNode, ExpressionNodeSchema, FoldCombiner, FoldCombinerSchema, FoldNode, FoldNodeSchema, HitPolicy, HitPolicySchema, InstantLiteralNode, InstantLiteralNodeSchema, LookupNode, LookupNodeSchema, MemberOfNode, MemberOfNodeSchema, MembershipOperator, MembershipOperatorSchema, NegateNode, NegateNodeSchema, NotNode, NotNodeSchema, NumberLiteralNode, NumberLiteralNodeSchema, OrNode, OrNodeSchema, PredicateNode, PredicateNodeSchema, ReferenceNode, ReferenceNodeSchema, SomeNode, SomeNodeSchema, TextCompareNode, TextCompareNodeSchema, TextComparisonOperator, TextComparisonOperatorSchema, TextLiteralNode, TextLiteralNodeSchema, TreeReferenceNode, TreeReferenceNodeSchema };
|
package/dist/tree.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ declare const ArithmeticOperatorSchema: z.ZodEnum<{
|
|
|
31
31
|
modulo: "modulo";
|
|
32
32
|
}>;
|
|
33
33
|
type ArithmeticOperator = z.infer<typeof ArithmeticOperatorSchema>;
|
|
34
|
+
declare const HitPolicySchema: z.ZodEnum<{
|
|
35
|
+
first: "first";
|
|
36
|
+
unique: "unique";
|
|
37
|
+
}>;
|
|
38
|
+
type HitPolicy = z.infer<typeof HitPolicySchema>;
|
|
34
39
|
declare const NotNodeSchema: z.ZodObject<{
|
|
35
40
|
kind: z.ZodLiteral<"not">;
|
|
36
41
|
operand: typeof PredicateNodeSchema;
|
|
@@ -113,6 +118,12 @@ declare const EveryNodeSchema: z.ZodObject<{
|
|
|
113
118
|
filter: z.ZodOptional<typeof PredicateNodeSchema>;
|
|
114
119
|
}, z.core.$strip>;
|
|
115
120
|
type EveryNode = z.infer<typeof EveryNodeSchema>;
|
|
121
|
+
/** 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. */
|
|
122
|
+
declare const TreeReferenceNodeSchema: z.ZodObject<{
|
|
123
|
+
kind: z.ZodLiteral<"treeReference">;
|
|
124
|
+
key: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
type TreeReferenceNode = z.infer<typeof TreeReferenceNodeSchema>;
|
|
116
127
|
declare const PredicateNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
117
128
|
kind: z.ZodLiteral<"not">;
|
|
118
129
|
operand: typeof PredicateNodeSchema;
|
|
@@ -173,6 +184,9 @@ declare const PredicateNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
173
184
|
collection: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
174
185
|
item: typeof PredicateNodeSchema;
|
|
175
186
|
filter: z.ZodOptional<typeof PredicateNodeSchema>;
|
|
187
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
188
|
+
kind: z.ZodLiteral<"treeReference">;
|
|
189
|
+
key: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
176
190
|
}, z.core.$strip>], "kind">;
|
|
177
191
|
type PredicateNode = z.infer<typeof PredicateNodeSchema>;
|
|
178
192
|
declare const NumberLiteralNodeSchema: z.ZodObject<{
|
|
@@ -186,6 +200,11 @@ declare const TextLiteralNodeSchema: z.ZodObject<{
|
|
|
186
200
|
value: z.ZodString;
|
|
187
201
|
}, z.core.$strip>;
|
|
188
202
|
type TextLiteralNode = z.infer<typeof TextLiteralNodeSchema>;
|
|
203
|
+
declare const BooleanLiteralNodeSchema: z.ZodObject<{
|
|
204
|
+
kind: z.ZodLiteral<"booleanLiteral">;
|
|
205
|
+
value: z.ZodBoolean;
|
|
206
|
+
}, z.core.$strip>;
|
|
207
|
+
type BooleanLiteralNode = z.infer<typeof BooleanLiteralNodeSchema>;
|
|
189
208
|
declare const InstantLiteralNodeSchema: z.ZodObject<{
|
|
190
209
|
kind: z.ZodLiteral<"instantLiteral">;
|
|
191
210
|
value: z.ZodString;
|
|
@@ -203,6 +222,38 @@ declare const DurationLiteralNodeSchema: z.ZodObject<{
|
|
|
203
222
|
}>;
|
|
204
223
|
}, z.core.$strip>;
|
|
205
224
|
type DurationLiteralNode = z.infer<typeof DurationLiteralNodeSchema>;
|
|
225
|
+
/**
|
|
226
|
+
* 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.
|
|
227
|
+
*
|
|
228
|
+
* The evaluator normalises whichever form was authored into the single rectangular `ComputedValue` immediately on evaluation (see the `complexLiteral` case in evaluator.ts), so nothing downstream of that -- arithmetic, `compare`, `memberOf`, `negate` -- ever sees a polar value; they keep consuming the one canonical `complex` shape unchanged.
|
|
229
|
+
*/
|
|
230
|
+
declare const ComplexRectangularLiteralNodeSchema: z.ZodObject<{
|
|
231
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
232
|
+
re: z.ZodNumber;
|
|
233
|
+
im: z.ZodNumber;
|
|
234
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
235
|
+
}, z.core.$strict>;
|
|
236
|
+
type ComplexRectangularLiteralNode = z.infer<typeof ComplexRectangularLiteralNodeSchema>;
|
|
237
|
+
declare const ComplexPolarLiteralNodeSchema: z.ZodObject<{
|
|
238
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
239
|
+
magnitude: z.ZodNumber;
|
|
240
|
+
phase: z.ZodNumber;
|
|
241
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
242
|
+
}, z.core.$strict>;
|
|
243
|
+
type ComplexPolarLiteralNode = z.infer<typeof ComplexPolarLiteralNodeSchema>;
|
|
244
|
+
/** 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. */
|
|
245
|
+
declare const ComplexLiteralNodeSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
246
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
247
|
+
re: z.ZodNumber;
|
|
248
|
+
im: z.ZodNumber;
|
|
249
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
250
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
251
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
252
|
+
magnitude: z.ZodNumber;
|
|
253
|
+
phase: z.ZodNumber;
|
|
254
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
255
|
+
}, z.core.$strict>]>;
|
|
256
|
+
type ComplexLiteralNode = z.infer<typeof ComplexLiteralNodeSchema>;
|
|
206
257
|
declare const ReferenceNodeSchema: z.ZodObject<{
|
|
207
258
|
kind: z.ZodLiteral<"reference">;
|
|
208
259
|
key: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
@@ -247,6 +298,10 @@ declare const ConditionalCaseSchema: z.ZodObject<{
|
|
|
247
298
|
type ConditionalCase = z.infer<typeof ConditionalCaseSchema>;
|
|
248
299
|
declare const ConditionalNodeSchema: z.ZodObject<{
|
|
249
300
|
kind: z.ZodLiteral<"conditional">;
|
|
301
|
+
hitPolicy: z.ZodOptional<z.ZodEnum<{
|
|
302
|
+
first: "first";
|
|
303
|
+
unique: "unique";
|
|
304
|
+
}>>;
|
|
250
305
|
cases: z.ZodArray<typeof ConditionalCaseSchema>;
|
|
251
306
|
fallback: typeof ExpressionNodeSchema;
|
|
252
307
|
}, z.core.$strip>;
|
|
@@ -290,13 +345,16 @@ declare const DelegateNodeSchema: z.ZodObject<{
|
|
|
290
345
|
payload: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
291
346
|
}, z.core.$strip>;
|
|
292
347
|
type DelegateNode = z.infer<typeof DelegateNodeSchema>;
|
|
293
|
-
declare const ExpressionNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
348
|
+
declare const ExpressionNodeSchema: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
294
349
|
kind: z.ZodLiteral<"numberLiteral">;
|
|
295
350
|
value: z.ZodNumber;
|
|
296
351
|
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
297
352
|
}, z.core.$strip>, z.ZodObject<{
|
|
298
353
|
kind: z.ZodLiteral<"textLiteral">;
|
|
299
354
|
value: z.ZodString;
|
|
355
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
356
|
+
kind: z.ZodLiteral<"booleanLiteral">;
|
|
357
|
+
value: z.ZodBoolean;
|
|
300
358
|
}, z.core.$strip>, z.ZodObject<{
|
|
301
359
|
kind: z.ZodLiteral<"instantLiteral">;
|
|
302
360
|
value: z.ZodString;
|
|
@@ -339,6 +397,10 @@ declare const ExpressionNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
339
397
|
keys: z.ZodArray<typeof ExpressionNodeSchema>;
|
|
340
398
|
}, z.core.$strip>, z.ZodObject<{
|
|
341
399
|
kind: z.ZodLiteral<"conditional">;
|
|
400
|
+
hitPolicy: z.ZodOptional<z.ZodEnum<{
|
|
401
|
+
first: "first";
|
|
402
|
+
unique: "unique";
|
|
403
|
+
}>>;
|
|
342
404
|
cases: z.ZodArray<typeof ConditionalCaseSchema>;
|
|
343
405
|
fallback: typeof ExpressionNodeSchema;
|
|
344
406
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -362,7 +424,20 @@ declare const ExpressionNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
362
424
|
kind: z.ZodLiteral<"delegate">;
|
|
363
425
|
system: z.ZodString;
|
|
364
426
|
payload: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
365
|
-
}, z.core.$strip
|
|
427
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
428
|
+
kind: z.ZodLiteral<"treeReference">;
|
|
429
|
+
key: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
|
|
430
|
+
}, z.core.$strip>], "kind">, z.ZodUnion<readonly [z.ZodObject<{
|
|
431
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
432
|
+
re: z.ZodNumber;
|
|
433
|
+
im: z.ZodNumber;
|
|
434
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
435
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
436
|
+
kind: z.ZodLiteral<"complexLiteral">;
|
|
437
|
+
magnitude: z.ZodNumber;
|
|
438
|
+
phase: z.ZodNumber;
|
|
439
|
+
unit: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
440
|
+
}, z.core.$strict>]>]>;
|
|
366
441
|
type ExpressionNode = z.infer<typeof ExpressionNodeSchema>;
|
|
367
442
|
//#endregion
|
|
368
|
-
export { AccumulatorNode, AccumulatorNodeSchema, AllOfNode, AllOfNodeSchema, AndNode, AndNodeSchema, AnyOfNode, AnyOfNodeSchema, ArithmeticNode, ArithmeticNodeSchema, ArithmeticOperator, ArithmeticOperatorSchema, CallNode, CallNodeSchema, CompareNode, CompareNodeSchema, ComparisonOperator, ComparisonOperatorSchema, ConditionalCase, ConditionalCaseSchema, ConditionalNode, ConditionalNodeSchema, DelegateNode, DelegateNodeSchema, DurationLiteralNode, DurationLiteralNodeSchema, EveryNode, EveryNodeSchema, ExistsNode, ExistsNodeSchema, ExpressionNode, ExpressionNodeSchema, FoldCombiner, FoldCombinerSchema, FoldNode, FoldNodeSchema, InstantLiteralNode, InstantLiteralNodeSchema, LookupNode, LookupNodeSchema, MemberOfNode, MemberOfNodeSchema, MembershipOperator, MembershipOperatorSchema, NegateNode, NegateNodeSchema, NotNode, NotNodeSchema, NumberLiteralNode, NumberLiteralNodeSchema, OrNode, OrNodeSchema, PredicateNode, PredicateNodeSchema, ReferenceNode, ReferenceNodeSchema, SomeNode, SomeNodeSchema, TextCompareNode, TextCompareNodeSchema, TextComparisonOperator, TextComparisonOperatorSchema, TextLiteralNode, TextLiteralNodeSchema };
|
|
443
|
+
export { AccumulatorNode, AccumulatorNodeSchema, AllOfNode, AllOfNodeSchema, AndNode, AndNodeSchema, AnyOfNode, AnyOfNodeSchema, ArithmeticNode, ArithmeticNodeSchema, ArithmeticOperator, ArithmeticOperatorSchema, BooleanLiteralNode, BooleanLiteralNodeSchema, CallNode, CallNodeSchema, CompareNode, CompareNodeSchema, ComparisonOperator, ComparisonOperatorSchema, ComplexLiteralNode, ComplexLiteralNodeSchema, ComplexPolarLiteralNode, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNode, ComplexRectangularLiteralNodeSchema, ConditionalCase, ConditionalCaseSchema, ConditionalNode, ConditionalNodeSchema, DelegateNode, DelegateNodeSchema, DurationLiteralNode, DurationLiteralNodeSchema, EveryNode, EveryNodeSchema, ExistsNode, ExistsNodeSchema, ExpressionNode, ExpressionNodeSchema, FoldCombiner, FoldCombinerSchema, FoldNode, FoldNodeSchema, HitPolicy, HitPolicySchema, InstantLiteralNode, InstantLiteralNodeSchema, LookupNode, LookupNodeSchema, MemberOfNode, MemberOfNodeSchema, MembershipOperator, MembershipOperatorSchema, NegateNode, NegateNodeSchema, NotNode, NotNodeSchema, NumberLiteralNode, NumberLiteralNodeSchema, OrNode, OrNodeSchema, PredicateNode, PredicateNodeSchema, ReferenceNode, ReferenceNodeSchema, SomeNode, SomeNodeSchema, TextCompareNode, TextCompareNodeSchema, TextComparisonOperator, TextComparisonOperatorSchema, TextLiteralNode, TextLiteralNodeSchema, TreeReferenceNode, TreeReferenceNodeSchema };
|
package/dist/tree.js
CHANGED
|
@@ -25,6 +25,7 @@ const ArithmeticOperatorSchema = z.enum([
|
|
|
25
25
|
"power",
|
|
26
26
|
"modulo"
|
|
27
27
|
]);
|
|
28
|
+
const HitPolicySchema = z.enum(["first", "unique"]);
|
|
28
29
|
const NotNodeSchema = z.object({
|
|
29
30
|
kind: z.literal("not"),
|
|
30
31
|
get operand() {
|
|
@@ -117,6 +118,11 @@ const EveryNodeSchema = z.object({
|
|
|
117
118
|
return PredicateNodeSchema.optional();
|
|
118
119
|
}
|
|
119
120
|
});
|
|
121
|
+
/** 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. */
|
|
122
|
+
const TreeReferenceNodeSchema = z.object({
|
|
123
|
+
kind: z.literal("treeReference"),
|
|
124
|
+
key: JsonValueSchema
|
|
125
|
+
});
|
|
120
126
|
const PredicateNodeSchema = z.discriminatedUnion("kind", [
|
|
121
127
|
NotNodeSchema,
|
|
122
128
|
AndNodeSchema,
|
|
@@ -128,7 +134,8 @@ const PredicateNodeSchema = z.discriminatedUnion("kind", [
|
|
|
128
134
|
MemberOfNodeSchema,
|
|
129
135
|
ExistsNodeSchema,
|
|
130
136
|
SomeNodeSchema,
|
|
131
|
-
EveryNodeSchema
|
|
137
|
+
EveryNodeSchema,
|
|
138
|
+
TreeReferenceNodeSchema
|
|
132
139
|
]);
|
|
133
140
|
const NumberLiteralNodeSchema = z.object({
|
|
134
141
|
kind: z.literal("numberLiteral"),
|
|
@@ -139,6 +146,10 @@ const TextLiteralNodeSchema = z.object({
|
|
|
139
146
|
kind: z.literal("textLiteral"),
|
|
140
147
|
value: z.string()
|
|
141
148
|
});
|
|
149
|
+
const BooleanLiteralNodeSchema = z.object({
|
|
150
|
+
kind: z.literal("booleanLiteral"),
|
|
151
|
+
value: z.boolean()
|
|
152
|
+
});
|
|
142
153
|
const InstantLiteralNodeSchema = z.object({
|
|
143
154
|
kind: z.literal("instantLiteral"),
|
|
144
155
|
/** ISO-8601 timestamp. */
|
|
@@ -149,6 +160,25 @@ const DurationLiteralNodeSchema = z.object({
|
|
|
149
160
|
value: z.number(),
|
|
150
161
|
unit: DurationUnitSchema
|
|
151
162
|
});
|
|
163
|
+
/**
|
|
164
|
+
* 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.
|
|
165
|
+
*
|
|
166
|
+
* The evaluator normalises whichever form was authored into the single rectangular `ComputedValue` immediately on evaluation (see the `complexLiteral` case in evaluator.ts), so nothing downstream of that -- arithmetic, `compare`, `memberOf`, `negate` -- ever sees a polar value; they keep consuming the one canonical `complex` shape unchanged.
|
|
167
|
+
*/
|
|
168
|
+
const ComplexRectangularLiteralNodeSchema = z.strictObject({
|
|
169
|
+
kind: z.literal("complexLiteral"),
|
|
170
|
+
re: z.number(),
|
|
171
|
+
im: z.number(),
|
|
172
|
+
unit: UnitSchema.optional()
|
|
173
|
+
});
|
|
174
|
+
const ComplexPolarLiteralNodeSchema = z.strictObject({
|
|
175
|
+
kind: z.literal("complexLiteral"),
|
|
176
|
+
magnitude: z.number(),
|
|
177
|
+
phase: z.number(),
|
|
178
|
+
unit: UnitSchema.optional()
|
|
179
|
+
});
|
|
180
|
+
/** 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. */
|
|
181
|
+
const ComplexLiteralNodeSchema = z.union([ComplexRectangularLiteralNodeSchema, ComplexPolarLiteralNodeSchema]);
|
|
152
182
|
const ReferenceNodeSchema = z.object({
|
|
153
183
|
kind: z.literal("reference"),
|
|
154
184
|
key: JsonValueSchema,
|
|
@@ -194,6 +224,8 @@ const ConditionalCaseSchema = z.object({
|
|
|
194
224
|
});
|
|
195
225
|
const ConditionalNodeSchema = z.object({
|
|
196
226
|
kind: z.literal("conditional"),
|
|
227
|
+
/** 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. */
|
|
228
|
+
hitPolicy: HitPolicySchema.optional(),
|
|
197
229
|
get cases() {
|
|
198
230
|
return z.array(ConditionalCaseSchema);
|
|
199
231
|
},
|
|
@@ -238,9 +270,11 @@ const DelegateNodeSchema = z.object({
|
|
|
238
270
|
system: z.string(),
|
|
239
271
|
payload: JsonValueSchema
|
|
240
272
|
});
|
|
241
|
-
|
|
273
|
+
/** 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`. */
|
|
274
|
+
const CoreExpressionNodeSchema = z.discriminatedUnion("kind", [
|
|
242
275
|
NumberLiteralNodeSchema,
|
|
243
276
|
TextLiteralNodeSchema,
|
|
277
|
+
BooleanLiteralNodeSchema,
|
|
244
278
|
InstantLiteralNodeSchema,
|
|
245
279
|
DurationLiteralNodeSchema,
|
|
246
280
|
ReferenceNodeSchema,
|
|
@@ -251,7 +285,9 @@ const ExpressionNodeSchema = z.discriminatedUnion("kind", [
|
|
|
251
285
|
ConditionalNodeSchema,
|
|
252
286
|
FoldNodeSchema,
|
|
253
287
|
AccumulatorNodeSchema,
|
|
254
|
-
DelegateNodeSchema
|
|
288
|
+
DelegateNodeSchema,
|
|
289
|
+
TreeReferenceNodeSchema
|
|
255
290
|
]);
|
|
291
|
+
const ExpressionNodeSchema = z.union([CoreExpressionNodeSchema, ComplexLiteralNodeSchema]);
|
|
256
292
|
//#endregion
|
|
257
|
-
export { AccumulatorNodeSchema, AllOfNodeSchema, AndNodeSchema, AnyOfNodeSchema, ArithmeticNodeSchema, ArithmeticOperatorSchema, CallNodeSchema, CompareNodeSchema, ComparisonOperatorSchema, ConditionalCaseSchema, ConditionalNodeSchema, DelegateNodeSchema, DurationLiteralNodeSchema, EveryNodeSchema, ExistsNodeSchema, ExpressionNodeSchema, FoldCombinerSchema, FoldNodeSchema, InstantLiteralNodeSchema, LookupNodeSchema, MemberOfNodeSchema, MembershipOperatorSchema, NegateNodeSchema, NotNodeSchema, NumberLiteralNodeSchema, OrNodeSchema, PredicateNodeSchema, ReferenceNodeSchema, SomeNodeSchema, TextCompareNodeSchema, TextComparisonOperatorSchema, TextLiteralNodeSchema };
|
|
293
|
+
export { AccumulatorNodeSchema, AllOfNodeSchema, AndNodeSchema, AnyOfNodeSchema, ArithmeticNodeSchema, ArithmeticOperatorSchema, BooleanLiteralNodeSchema, CallNodeSchema, CompareNodeSchema, ComparisonOperatorSchema, ComplexLiteralNodeSchema, ComplexPolarLiteralNodeSchema, ComplexRectangularLiteralNodeSchema, ConditionalCaseSchema, ConditionalNodeSchema, DelegateNodeSchema, DurationLiteralNodeSchema, EveryNodeSchema, ExistsNodeSchema, ExpressionNodeSchema, FoldCombinerSchema, FoldNodeSchema, HitPolicySchema, InstantLiteralNodeSchema, LookupNodeSchema, MemberOfNodeSchema, MembershipOperatorSchema, NegateNodeSchema, NotNodeSchema, NumberLiteralNodeSchema, OrNodeSchema, PredicateNodeSchema, ReferenceNodeSchema, SomeNodeSchema, TextCompareNodeSchema, TextComparisonOperatorSchema, TextLiteralNodeSchema, TreeReferenceNodeSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trilean",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"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.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$defs":{"ExpressionNode":{"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":"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"},"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"}]},"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"],"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"}]},"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.0
|
|
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"],"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.2.0/schemas/trilean.schema.json","$schema":"https://json-schema.org/draft/2020-12/schema","oneOf":[{"$ref":"#/$defs/PredicateNode"},{"$ref":"#/$defs/ExpressionNode"}]}
|