@coldsmirk/abacus-core 0.4.0 → 0.5.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 +19 -10
- package/dist/index.cjs +1348 -2
- package/dist/index.d.cts +92 -40
- package/dist/index.d.ts +92 -40
- package/dist/index.js +1301 -2
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { InitInput } from "@gorules/zen-engine-wasm";
|
|
2
2
|
|
|
3
|
-
//#region src/engine/intellisense.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* How an expression editor interprets its document:
|
|
6
5
|
*
|
|
@@ -37,19 +36,22 @@ type ExpressionType = "Any" | "Null" | "Bool" | "String" | "Number" | "Date" | {
|
|
|
37
36
|
Object: Record<string, ExpressionType>;
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
40
|
-
* A single syntax / type diagnostic, positioned by
|
|
39
|
+
* A single syntax / type diagnostic, positioned by UTF-16 code-unit offset
|
|
40
|
+
* (the coordinate system of JS strings and CodeMirror documents).
|
|
41
41
|
*/
|
|
42
42
|
interface ExpressionDiagnostic {
|
|
43
43
|
/**
|
|
44
|
-
* Start offset in the source.
|
|
44
|
+
* Start offset in the source (UTF-16 code units).
|
|
45
45
|
*/
|
|
46
46
|
from: number;
|
|
47
47
|
/**
|
|
48
|
-
* End offset in the source.
|
|
48
|
+
* End offset in the source (UTF-16 code units).
|
|
49
49
|
*/
|
|
50
50
|
to: number;
|
|
51
51
|
/**
|
|
52
|
-
* Human-readable error message.
|
|
52
|
+
* Human-readable error message, verbatim from the engine. Any position it
|
|
53
|
+
* quotes in prose (e.g. `... at (8, 8)`) is the engine's own UTF-8 byte
|
|
54
|
+
* coordinate — `from` / `to` carry the converted offsets.
|
|
53
55
|
*/
|
|
54
56
|
message: string;
|
|
55
57
|
/**
|
|
@@ -132,8 +134,6 @@ declare function satisfiesType(actual: ExpressionType, expected: ExpressionType)
|
|
|
132
134
|
* engine has not loaded yet.
|
|
133
135
|
*/
|
|
134
136
|
declare function satisfiesTypeSync(actual: ExpressionType, expected: ExpressionType): boolean;
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region src/engine/errors.d.ts
|
|
137
137
|
/**
|
|
138
138
|
* Error raised when the ZEN engine fails to load or an expression cannot be
|
|
139
139
|
* evaluated. The original failure is preserved on {@link cause} and the
|
|
@@ -151,8 +151,6 @@ declare class ExpressionError extends Error {
|
|
|
151
151
|
declare class ExpressionNotReadyError extends ExpressionError {
|
|
152
152
|
constructor(message?: string);
|
|
153
153
|
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/engine/loader.d.ts
|
|
156
154
|
/**
|
|
157
155
|
* The data an expression reads from. Property paths in the expression (e.g.
|
|
158
156
|
* `customer.name`) resolve against this object.
|
|
@@ -255,13 +253,20 @@ declare function getEngineError(): ExpressionError | null;
|
|
|
255
253
|
declare function getEngineSync(): ExpressionEngine;
|
|
256
254
|
/**
|
|
257
255
|
* Reset the engine singleton — drops the loaded engine, the cached type context,
|
|
258
|
-
* the latched error, and the configured wasm input
|
|
259
|
-
*
|
|
260
|
-
*
|
|
256
|
+
* the latched error, and the configured wasm input, and orphans any in-flight
|
|
257
|
+
* load: its later settlement is discarded instead of clobbering the new state,
|
|
258
|
+
* and the next {@link loadEngine} waits for it to settle before initializing
|
|
259
|
+
* (the upstream wasm initializer tolerates no concurrent calls — see lastLoad).
|
|
260
|
+
* Mainly for tests, and the way to re-run {@link configureEngine} after a
|
|
261
|
+
* **failed** load (configure throws once the engine has started loading).
|
|
262
|
+
*
|
|
263
|
+
* A different `wasmInput` cannot take effect once the wasm module has
|
|
264
|
+
* initialized successfully: the ESM module cache keeps the instantiated module
|
|
265
|
+
* for the lifetime of the JS realm, and its initializer ignores a new input
|
|
266
|
+
* after success. Reset-and-reconfigure is therefore a retry primitive for load
|
|
267
|
+
* failures, not a live wasm-swap.
|
|
261
268
|
*/
|
|
262
269
|
declare function resetEngine(): void;
|
|
263
|
-
//#endregion
|
|
264
|
-
//#region src/condition/types.d.ts
|
|
265
270
|
/**
|
|
266
271
|
* Structural shapes for the visual condition model compiled to ZEN. They mirror
|
|
267
272
|
* the condition types used in the form and flow editors so a host can map those
|
|
@@ -356,18 +361,33 @@ type BranchSelection = {
|
|
|
356
361
|
matched: false;
|
|
357
362
|
branchId: string | null;
|
|
358
363
|
};
|
|
359
|
-
|
|
360
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Whether a finite number compiles into a ZEN literal that behaves identically
|
|
366
|
+
* to the same JS number supplied in an evaluation context. Two requirements
|
|
367
|
+
* fold into this: the literal must be inside ZEN's decimal domain (a 96-bit
|
|
368
|
+
* mantissa scaled by at most 10^-28 — an out-of-domain literal fails to PARSE
|
|
369
|
+
* and poisons the whole compiled expression), and the engine's own context
|
|
370
|
+
* conversion of the number must land on the exact same decimal — otherwise
|
|
371
|
+
* `field == value` compiled from a value silently evaluates false against a
|
|
372
|
+
* context holding that very value (the engine converts context f64s lossily;
|
|
373
|
+
* see internal/zen-decimal.ts). Used by {@link toZenLiteral}, by
|
|
374
|
+
* {@link liftConditionTree} — which must accept exactly the numbers the
|
|
375
|
+
* compiler can emit — and by UI layers deciding whether a user-entered number
|
|
376
|
+
* survives compilation.
|
|
377
|
+
*/
|
|
378
|
+
declare function isZenRepresentableNumber(value: number): boolean;
|
|
361
379
|
/**
|
|
362
380
|
* Serialize a JavaScript value into a ZEN literal. Nullish becomes `null`;
|
|
363
381
|
* numbers / booleans / bigints are emitted verbatim; strings are quoted via
|
|
364
382
|
* {@link encodeZenString}; arrays become `[a, b, ...]`.
|
|
365
383
|
*
|
|
366
384
|
* Throws {@link ExpressionError} for a value with no faithful ZEN
|
|
367
|
-
* representation — an object, symbol, or function,
|
|
368
|
-
* quote styles
|
|
369
|
-
*
|
|
370
|
-
*
|
|
385
|
+
* representation — an object, symbol, or function, a string containing both
|
|
386
|
+
* quote styles, a number failing {@link isZenRepresentableNumber} (outside
|
|
387
|
+
* ZEN's decimal domain, or held differently by the engine's context
|
|
388
|
+
* conversion), or a bigint outside the decimal domain. Callers that need a
|
|
389
|
+
* sentinel instead of a throw go through {@link compileCondition}, which
|
|
390
|
+
* degrades such a value to a non-compiling (null) condition.
|
|
371
391
|
*/
|
|
372
392
|
declare function toZenLiteral(value: unknown): string;
|
|
373
393
|
/**
|
|
@@ -405,10 +425,8 @@ declare function selectBranchWith(branches: readonly ConditionBranchInput[], con
|
|
|
405
425
|
* first use. See {@link selectBranchWith} for the selection semantics.
|
|
406
426
|
*/
|
|
407
427
|
declare function selectBranch(branches: readonly ConditionBranchInput[], context: ExpressionContext): Promise<BranchSelection>;
|
|
408
|
-
//#endregion
|
|
409
|
-
//#region src/condition/tree-types.d.ts
|
|
410
428
|
/**
|
|
411
|
-
* The visual condition **tree** model:
|
|
429
|
+
* The visual condition **tree** model: a bounded and/or tree of typed
|
|
412
430
|
* comparison rules that {@link compileConditionTree} serializes to a single ZEN
|
|
413
431
|
* boolean expression and {@link liftConditionTree} reconstructs from one. It is a
|
|
414
432
|
* distinct, self-contained shape from the compiler's flat {@link ConditionInput} —
|
|
@@ -417,6 +435,11 @@ declare function selectBranch(branches: readonly ConditionBranchInput[], context
|
|
|
417
435
|
* leaf: a {@link ConditionTreeRule} lowers to a field {@link ConditionInput} so the
|
|
418
436
|
* operator vocabulary, literal encoding, and injection guard have one owner.
|
|
419
437
|
*/
|
|
438
|
+
/**
|
|
439
|
+
* Maximum number of nested group edges below a condition tree's root group.
|
|
440
|
+
* The root is depth 0, so a group at depth 64 is valid and one at 65 is not.
|
|
441
|
+
*/
|
|
442
|
+
declare const MAX_CONDITION_TREE_DEPTH = 64;
|
|
420
443
|
/**
|
|
421
444
|
* A scalar operand: the value types ZEN compares against and that survive the
|
|
422
445
|
* compile/lift round-trip (strings, numbers, booleans). Objects and null are not
|
|
@@ -460,18 +483,40 @@ type ConditionTreeOperator = typeof CONDITION_TREE_OPERATORS[number];
|
|
|
460
483
|
*/
|
|
461
484
|
interface ConditionTreeRule {
|
|
462
485
|
kind: "rule";
|
|
486
|
+
/**
|
|
487
|
+
* Stable node identity for list rendering (React keys). Ignored by the
|
|
488
|
+
* compiler; {@link liftConditionTree} and the builder's creation paths assign
|
|
489
|
+
* one, and edits carry it through, so a node keeps its identity for as long
|
|
490
|
+
* as it exists. Optional so hand-built trees for headless compilation need
|
|
491
|
+
* not supply it.
|
|
492
|
+
*/
|
|
493
|
+
id?: string;
|
|
463
494
|
left: string;
|
|
464
495
|
operator: ConditionTreeOperator;
|
|
465
496
|
right?: ConditionTreeValue;
|
|
497
|
+
/**
|
|
498
|
+
* The element type intended for a membership (`in` / `not_in`) operand while
|
|
499
|
+
* `right` is an **empty** array — an empty array cannot say whether the tags
|
|
500
|
+
* to come are numbers, and a builder toggle has to live in the tree for the
|
|
501
|
+
* component to stay fully controlled (a same-value form reset must also reset
|
|
502
|
+
* this). Ignored by the compiler, never produced by
|
|
503
|
+
* {@link liftConditionTree}, and irrelevant once `right` has elements (their
|
|
504
|
+
* actual type wins).
|
|
505
|
+
*/
|
|
506
|
+
rightElementType?: "string" | "number";
|
|
466
507
|
}
|
|
467
508
|
/**
|
|
468
509
|
* A boolean group joining its `items` with `op`. Items are leaf rules or nested
|
|
469
|
-
* groups,
|
|
470
|
-
* condition is always a group, so callers can treat
|
|
471
|
-
* the tree's entry type.
|
|
510
|
+
* groups, up to {@link MAX_CONDITION_TREE_DEPTH} nested group edges below the root.
|
|
511
|
+
* The root of a lifted condition is always a group, so callers can treat
|
|
512
|
+
* {@link ConditionTreeGroup} as the tree's entry type.
|
|
472
513
|
*/
|
|
473
514
|
interface ConditionTreeGroup {
|
|
474
515
|
kind: "group";
|
|
516
|
+
/**
|
|
517
|
+
* Stable node identity for list rendering — see {@link ConditionTreeRule.id}.
|
|
518
|
+
*/
|
|
519
|
+
id?: string;
|
|
475
520
|
op: "and" | "or";
|
|
476
521
|
items: readonly ConditionTreeNode[];
|
|
477
522
|
}
|
|
@@ -479,25 +524,37 @@ interface ConditionTreeGroup {
|
|
|
479
524
|
* A node in the condition tree: a nested group or a leaf rule.
|
|
480
525
|
*/
|
|
481
526
|
type ConditionTreeNode = ConditionTreeGroup | ConditionTreeRule;
|
|
482
|
-
|
|
483
|
-
|
|
527
|
+
/**
|
|
528
|
+
* A fresh {@link ConditionTreeRule.id | node id}, unique within the process —
|
|
529
|
+
* exactly the guarantee a React key needs. A tagged counter, not a UUID: node
|
|
530
|
+
* identity is a UI concern with no persistence or cross-process meaning.
|
|
531
|
+
*/
|
|
532
|
+
declare function newConditionNodeId(): string;
|
|
533
|
+
/**
|
|
534
|
+
* A fresh empty and-group — the canonical "no condition yet" tree, e.g. a
|
|
535
|
+
* form's initial value for a condition-builder field. It compiles to `""`.
|
|
536
|
+
*/
|
|
537
|
+
declare function emptyConditionGroup(): ConditionTreeGroup;
|
|
484
538
|
/**
|
|
485
539
|
* Compile a condition tree to a canonical ZEN expression, or `""` when no rule in
|
|
486
540
|
* the tree is compilable (see the module note for the drop semantics).
|
|
487
541
|
*/
|
|
488
542
|
declare function compileConditionTree(tree: ConditionTreeGroup): string;
|
|
489
|
-
//#endregion
|
|
490
|
-
//#region src/condition/lift-tree.d.ts
|
|
491
543
|
/**
|
|
492
544
|
* Lift a ZEN expression to a condition tree, or `null` when it is not in the
|
|
493
545
|
* canonical form {@link compileConditionTree} produces (the consumer then keeps the
|
|
494
546
|
* raw expression). Groups nested deeper than 64 parenthesized levels are refused as
|
|
495
|
-
* non-canonical rather than risking parser-stack overflow on adversarial input
|
|
496
|
-
*
|
|
547
|
+
* non-canonical rather than risking parser-stack overflow on adversarial input, and
|
|
548
|
+
* number literals must be canonical (see `parseCanonicalNumber`). The returned root
|
|
549
|
+
* is always a group, and every node carries a fresh {@link ConditionTreeRule.id}.
|
|
497
550
|
*/
|
|
498
551
|
declare function liftConditionTree(expression: string): ConditionTreeGroup | null;
|
|
499
|
-
|
|
500
|
-
|
|
552
|
+
/**
|
|
553
|
+
* Return `tree` with every node carrying a stable UI id. The shared structural
|
|
554
|
+
* policy is checked before recursive normalization, so invalid external data fails
|
|
555
|
+
* with an {@link ExpressionError} instead of a native stack overflow.
|
|
556
|
+
*/
|
|
557
|
+
declare function ensureConditionNodeIds(tree: ConditionTreeGroup): ConditionTreeGroup;
|
|
501
558
|
/**
|
|
502
559
|
* Evaluate a standard ZEN expression, loading the engine on first use.
|
|
503
560
|
*
|
|
@@ -521,8 +578,6 @@ declare function evaluateSync<T = unknown>(expression: string, context?: Express
|
|
|
521
578
|
* {@link ExpressionNotReadyError} when the engine has not loaded yet.
|
|
522
579
|
*/
|
|
523
580
|
declare function evaluateUnarySync(expression: string, context?: ExpressionContext): boolean;
|
|
524
|
-
//#endregion
|
|
525
|
-
//#region src/engine/messages.d.ts
|
|
526
581
|
/**
|
|
527
582
|
* The locales the library ships with out of the box.
|
|
528
583
|
*/
|
|
@@ -608,8 +663,6 @@ declare function configureExpressionMessages({
|
|
|
608
663
|
* The active {@link ExpressionMessages} catalog (English by default).
|
|
609
664
|
*/
|
|
610
665
|
declare function getExpressionMessages(): ExpressionMessages;
|
|
611
|
-
//#endregion
|
|
612
|
-
//#region src/engine/template.d.ts
|
|
613
666
|
/**
|
|
614
667
|
* One `{{ expression }}` hole located in a template document. `from` / `to` are
|
|
615
668
|
* the character offsets of the inner expression itself — the text between the
|
|
@@ -676,5 +729,4 @@ declare function getTemplateDiagnosticsSync(source: string): ExpressionDiagnosti
|
|
|
676
729
|
* Async {@link getTemplateDiagnosticsSync}, loading the engine on first use.
|
|
677
730
|
*/
|
|
678
731
|
declare function getTemplateDiagnostics(source: string): Promise<ExpressionDiagnostic[]>;
|
|
679
|
-
|
|
680
|
-
export { type BranchSelection, type BuiltInExpressionLocale, CONDITION_OPERATORS, CONDITION_TREE_OPERATORS, type ConditionBranchInput, type ConditionGroupInput, type ConditionInput, type ConditionOperator, type ConditionOperatorArity, type ConditionScalar, type ConditionTreeGroup, type ConditionTreeNode, type ConditionTreeOperator, type ConditionTreeRule, type ConditionTreeValue, type ConfigureMessagesOptions, type ExpressionAnalysis, type ExpressionCompletion, type ExpressionConditionInput, type ExpressionContext, type ExpressionDiagnostic, type ExpressionEngine, ExpressionError, type ExpressionLocale, type ExpressionMessages, type ExpressionMode, ExpressionNotReadyError, type ExpressionType, type ExpressionTypeSpan, type FieldConditionInput, type LoadEngineOptions, type TemplateHole, analyzeTemplate, analyzeTemplateSync, analyzeTypes, analyzeTypesSync, compileBranch, compileCondition, compileConditionTree, compileGroup, conditionOperatorArity, configureEngine, configureExpressionMessages, enMessages, evaluate, evaluateSync, evaluateUnary, evaluateUnarySync, getCompletionItems, getCompletionItemsSync, getDiagnostics, getDiagnosticsSync, getEngineError, getEngineSync, getExpressionMessages, getTemplateDiagnostics, getTemplateDiagnosticsSync, isEngineReady, liftConditionTree, loadEngine, parseTemplateHoles, registerExpressionLocale, resetEngine, satisfiesType, satisfiesTypeSync, selectBranch, selectBranchWith, templateHoleAt, toZenLiteral, zhCNMessages };
|
|
732
|
+
export { type BranchSelection, type BuiltInExpressionLocale, CONDITION_OPERATORS, CONDITION_TREE_OPERATORS, type ConditionBranchInput, type ConditionGroupInput, type ConditionInput, type ConditionOperator, type ConditionOperatorArity, type ConditionScalar, type ConditionTreeGroup, type ConditionTreeNode, type ConditionTreeOperator, type ConditionTreeRule, type ConditionTreeValue, type ConfigureMessagesOptions, type ExpressionAnalysis, type ExpressionCompletion, type ExpressionConditionInput, type ExpressionContext, type ExpressionDiagnostic, type ExpressionEngine, ExpressionError, type ExpressionLocale, type ExpressionMessages, type ExpressionMode, ExpressionNotReadyError, type ExpressionType, type ExpressionTypeSpan, type FieldConditionInput, type LoadEngineOptions, MAX_CONDITION_TREE_DEPTH, type TemplateHole, analyzeTemplate, analyzeTemplateSync, analyzeTypes, analyzeTypesSync, compileBranch, compileCondition, compileConditionTree, compileGroup, conditionOperatorArity, configureEngine, configureExpressionMessages, emptyConditionGroup, enMessages, ensureConditionNodeIds, evaluate, evaluateSync, evaluateUnary, evaluateUnarySync, getCompletionItems, getCompletionItemsSync, getDiagnostics, getDiagnosticsSync, getEngineError, getEngineSync, getExpressionMessages, getTemplateDiagnostics, getTemplateDiagnosticsSync, isEngineReady, isZenRepresentableNumber, liftConditionTree, loadEngine, newConditionNodeId, parseTemplateHoles, registerExpressionLocale, resetEngine, satisfiesType, satisfiesTypeSync, selectBranch, selectBranchWith, templateHoleAt, toZenLiteral, zhCNMessages };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { InitInput } from "@gorules/zen-engine-wasm";
|
|
2
2
|
|
|
3
|
-
//#region src/engine/intellisense.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* How an expression editor interprets its document:
|
|
6
5
|
*
|
|
@@ -37,19 +36,22 @@ type ExpressionType = "Any" | "Null" | "Bool" | "String" | "Number" | "Date" | {
|
|
|
37
36
|
Object: Record<string, ExpressionType>;
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
40
|
-
* A single syntax / type diagnostic, positioned by
|
|
39
|
+
* A single syntax / type diagnostic, positioned by UTF-16 code-unit offset
|
|
40
|
+
* (the coordinate system of JS strings and CodeMirror documents).
|
|
41
41
|
*/
|
|
42
42
|
interface ExpressionDiagnostic {
|
|
43
43
|
/**
|
|
44
|
-
* Start offset in the source.
|
|
44
|
+
* Start offset in the source (UTF-16 code units).
|
|
45
45
|
*/
|
|
46
46
|
from: number;
|
|
47
47
|
/**
|
|
48
|
-
* End offset in the source.
|
|
48
|
+
* End offset in the source (UTF-16 code units).
|
|
49
49
|
*/
|
|
50
50
|
to: number;
|
|
51
51
|
/**
|
|
52
|
-
* Human-readable error message.
|
|
52
|
+
* Human-readable error message, verbatim from the engine. Any position it
|
|
53
|
+
* quotes in prose (e.g. `... at (8, 8)`) is the engine's own UTF-8 byte
|
|
54
|
+
* coordinate — `from` / `to` carry the converted offsets.
|
|
53
55
|
*/
|
|
54
56
|
message: string;
|
|
55
57
|
/**
|
|
@@ -132,8 +134,6 @@ declare function satisfiesType(actual: ExpressionType, expected: ExpressionType)
|
|
|
132
134
|
* engine has not loaded yet.
|
|
133
135
|
*/
|
|
134
136
|
declare function satisfiesTypeSync(actual: ExpressionType, expected: ExpressionType): boolean;
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region src/engine/errors.d.ts
|
|
137
137
|
/**
|
|
138
138
|
* Error raised when the ZEN engine fails to load or an expression cannot be
|
|
139
139
|
* evaluated. The original failure is preserved on {@link cause} and the
|
|
@@ -151,8 +151,6 @@ declare class ExpressionError extends Error {
|
|
|
151
151
|
declare class ExpressionNotReadyError extends ExpressionError {
|
|
152
152
|
constructor(message?: string);
|
|
153
153
|
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/engine/loader.d.ts
|
|
156
154
|
/**
|
|
157
155
|
* The data an expression reads from. Property paths in the expression (e.g.
|
|
158
156
|
* `customer.name`) resolve against this object.
|
|
@@ -255,13 +253,20 @@ declare function getEngineError(): ExpressionError | null;
|
|
|
255
253
|
declare function getEngineSync(): ExpressionEngine;
|
|
256
254
|
/**
|
|
257
255
|
* Reset the engine singleton — drops the loaded engine, the cached type context,
|
|
258
|
-
* the latched error, and the configured wasm input
|
|
259
|
-
*
|
|
260
|
-
*
|
|
256
|
+
* the latched error, and the configured wasm input, and orphans any in-flight
|
|
257
|
+
* load: its later settlement is discarded instead of clobbering the new state,
|
|
258
|
+
* and the next {@link loadEngine} waits for it to settle before initializing
|
|
259
|
+
* (the upstream wasm initializer tolerates no concurrent calls — see lastLoad).
|
|
260
|
+
* Mainly for tests, and the way to re-run {@link configureEngine} after a
|
|
261
|
+
* **failed** load (configure throws once the engine has started loading).
|
|
262
|
+
*
|
|
263
|
+
* A different `wasmInput` cannot take effect once the wasm module has
|
|
264
|
+
* initialized successfully: the ESM module cache keeps the instantiated module
|
|
265
|
+
* for the lifetime of the JS realm, and its initializer ignores a new input
|
|
266
|
+
* after success. Reset-and-reconfigure is therefore a retry primitive for load
|
|
267
|
+
* failures, not a live wasm-swap.
|
|
261
268
|
*/
|
|
262
269
|
declare function resetEngine(): void;
|
|
263
|
-
//#endregion
|
|
264
|
-
//#region src/condition/types.d.ts
|
|
265
270
|
/**
|
|
266
271
|
* Structural shapes for the visual condition model compiled to ZEN. They mirror
|
|
267
272
|
* the condition types used in the form and flow editors so a host can map those
|
|
@@ -356,18 +361,33 @@ type BranchSelection = {
|
|
|
356
361
|
matched: false;
|
|
357
362
|
branchId: string | null;
|
|
358
363
|
};
|
|
359
|
-
|
|
360
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Whether a finite number compiles into a ZEN literal that behaves identically
|
|
366
|
+
* to the same JS number supplied in an evaluation context. Two requirements
|
|
367
|
+
* fold into this: the literal must be inside ZEN's decimal domain (a 96-bit
|
|
368
|
+
* mantissa scaled by at most 10^-28 — an out-of-domain literal fails to PARSE
|
|
369
|
+
* and poisons the whole compiled expression), and the engine's own context
|
|
370
|
+
* conversion of the number must land on the exact same decimal — otherwise
|
|
371
|
+
* `field == value` compiled from a value silently evaluates false against a
|
|
372
|
+
* context holding that very value (the engine converts context f64s lossily;
|
|
373
|
+
* see internal/zen-decimal.ts). Used by {@link toZenLiteral}, by
|
|
374
|
+
* {@link liftConditionTree} — which must accept exactly the numbers the
|
|
375
|
+
* compiler can emit — and by UI layers deciding whether a user-entered number
|
|
376
|
+
* survives compilation.
|
|
377
|
+
*/
|
|
378
|
+
declare function isZenRepresentableNumber(value: number): boolean;
|
|
361
379
|
/**
|
|
362
380
|
* Serialize a JavaScript value into a ZEN literal. Nullish becomes `null`;
|
|
363
381
|
* numbers / booleans / bigints are emitted verbatim; strings are quoted via
|
|
364
382
|
* {@link encodeZenString}; arrays become `[a, b, ...]`.
|
|
365
383
|
*
|
|
366
384
|
* Throws {@link ExpressionError} for a value with no faithful ZEN
|
|
367
|
-
* representation — an object, symbol, or function,
|
|
368
|
-
* quote styles
|
|
369
|
-
*
|
|
370
|
-
*
|
|
385
|
+
* representation — an object, symbol, or function, a string containing both
|
|
386
|
+
* quote styles, a number failing {@link isZenRepresentableNumber} (outside
|
|
387
|
+
* ZEN's decimal domain, or held differently by the engine's context
|
|
388
|
+
* conversion), or a bigint outside the decimal domain. Callers that need a
|
|
389
|
+
* sentinel instead of a throw go through {@link compileCondition}, which
|
|
390
|
+
* degrades such a value to a non-compiling (null) condition.
|
|
371
391
|
*/
|
|
372
392
|
declare function toZenLiteral(value: unknown): string;
|
|
373
393
|
/**
|
|
@@ -405,10 +425,8 @@ declare function selectBranchWith(branches: readonly ConditionBranchInput[], con
|
|
|
405
425
|
* first use. See {@link selectBranchWith} for the selection semantics.
|
|
406
426
|
*/
|
|
407
427
|
declare function selectBranch(branches: readonly ConditionBranchInput[], context: ExpressionContext): Promise<BranchSelection>;
|
|
408
|
-
//#endregion
|
|
409
|
-
//#region src/condition/tree-types.d.ts
|
|
410
428
|
/**
|
|
411
|
-
* The visual condition **tree** model:
|
|
429
|
+
* The visual condition **tree** model: a bounded and/or tree of typed
|
|
412
430
|
* comparison rules that {@link compileConditionTree} serializes to a single ZEN
|
|
413
431
|
* boolean expression and {@link liftConditionTree} reconstructs from one. It is a
|
|
414
432
|
* distinct, self-contained shape from the compiler's flat {@link ConditionInput} —
|
|
@@ -417,6 +435,11 @@ declare function selectBranch(branches: readonly ConditionBranchInput[], context
|
|
|
417
435
|
* leaf: a {@link ConditionTreeRule} lowers to a field {@link ConditionInput} so the
|
|
418
436
|
* operator vocabulary, literal encoding, and injection guard have one owner.
|
|
419
437
|
*/
|
|
438
|
+
/**
|
|
439
|
+
* Maximum number of nested group edges below a condition tree's root group.
|
|
440
|
+
* The root is depth 0, so a group at depth 64 is valid and one at 65 is not.
|
|
441
|
+
*/
|
|
442
|
+
declare const MAX_CONDITION_TREE_DEPTH = 64;
|
|
420
443
|
/**
|
|
421
444
|
* A scalar operand: the value types ZEN compares against and that survive the
|
|
422
445
|
* compile/lift round-trip (strings, numbers, booleans). Objects and null are not
|
|
@@ -460,18 +483,40 @@ type ConditionTreeOperator = typeof CONDITION_TREE_OPERATORS[number];
|
|
|
460
483
|
*/
|
|
461
484
|
interface ConditionTreeRule {
|
|
462
485
|
kind: "rule";
|
|
486
|
+
/**
|
|
487
|
+
* Stable node identity for list rendering (React keys). Ignored by the
|
|
488
|
+
* compiler; {@link liftConditionTree} and the builder's creation paths assign
|
|
489
|
+
* one, and edits carry it through, so a node keeps its identity for as long
|
|
490
|
+
* as it exists. Optional so hand-built trees for headless compilation need
|
|
491
|
+
* not supply it.
|
|
492
|
+
*/
|
|
493
|
+
id?: string;
|
|
463
494
|
left: string;
|
|
464
495
|
operator: ConditionTreeOperator;
|
|
465
496
|
right?: ConditionTreeValue;
|
|
497
|
+
/**
|
|
498
|
+
* The element type intended for a membership (`in` / `not_in`) operand while
|
|
499
|
+
* `right` is an **empty** array — an empty array cannot say whether the tags
|
|
500
|
+
* to come are numbers, and a builder toggle has to live in the tree for the
|
|
501
|
+
* component to stay fully controlled (a same-value form reset must also reset
|
|
502
|
+
* this). Ignored by the compiler, never produced by
|
|
503
|
+
* {@link liftConditionTree}, and irrelevant once `right` has elements (their
|
|
504
|
+
* actual type wins).
|
|
505
|
+
*/
|
|
506
|
+
rightElementType?: "string" | "number";
|
|
466
507
|
}
|
|
467
508
|
/**
|
|
468
509
|
* A boolean group joining its `items` with `op`. Items are leaf rules or nested
|
|
469
|
-
* groups,
|
|
470
|
-
* condition is always a group, so callers can treat
|
|
471
|
-
* the tree's entry type.
|
|
510
|
+
* groups, up to {@link MAX_CONDITION_TREE_DEPTH} nested group edges below the root.
|
|
511
|
+
* The root of a lifted condition is always a group, so callers can treat
|
|
512
|
+
* {@link ConditionTreeGroup} as the tree's entry type.
|
|
472
513
|
*/
|
|
473
514
|
interface ConditionTreeGroup {
|
|
474
515
|
kind: "group";
|
|
516
|
+
/**
|
|
517
|
+
* Stable node identity for list rendering — see {@link ConditionTreeRule.id}.
|
|
518
|
+
*/
|
|
519
|
+
id?: string;
|
|
475
520
|
op: "and" | "or";
|
|
476
521
|
items: readonly ConditionTreeNode[];
|
|
477
522
|
}
|
|
@@ -479,25 +524,37 @@ interface ConditionTreeGroup {
|
|
|
479
524
|
* A node in the condition tree: a nested group or a leaf rule.
|
|
480
525
|
*/
|
|
481
526
|
type ConditionTreeNode = ConditionTreeGroup | ConditionTreeRule;
|
|
482
|
-
|
|
483
|
-
|
|
527
|
+
/**
|
|
528
|
+
* A fresh {@link ConditionTreeRule.id | node id}, unique within the process —
|
|
529
|
+
* exactly the guarantee a React key needs. A tagged counter, not a UUID: node
|
|
530
|
+
* identity is a UI concern with no persistence or cross-process meaning.
|
|
531
|
+
*/
|
|
532
|
+
declare function newConditionNodeId(): string;
|
|
533
|
+
/**
|
|
534
|
+
* A fresh empty and-group — the canonical "no condition yet" tree, e.g. a
|
|
535
|
+
* form's initial value for a condition-builder field. It compiles to `""`.
|
|
536
|
+
*/
|
|
537
|
+
declare function emptyConditionGroup(): ConditionTreeGroup;
|
|
484
538
|
/**
|
|
485
539
|
* Compile a condition tree to a canonical ZEN expression, or `""` when no rule in
|
|
486
540
|
* the tree is compilable (see the module note for the drop semantics).
|
|
487
541
|
*/
|
|
488
542
|
declare function compileConditionTree(tree: ConditionTreeGroup): string;
|
|
489
|
-
//#endregion
|
|
490
|
-
//#region src/condition/lift-tree.d.ts
|
|
491
543
|
/**
|
|
492
544
|
* Lift a ZEN expression to a condition tree, or `null` when it is not in the
|
|
493
545
|
* canonical form {@link compileConditionTree} produces (the consumer then keeps the
|
|
494
546
|
* raw expression). Groups nested deeper than 64 parenthesized levels are refused as
|
|
495
|
-
* non-canonical rather than risking parser-stack overflow on adversarial input
|
|
496
|
-
*
|
|
547
|
+
* non-canonical rather than risking parser-stack overflow on adversarial input, and
|
|
548
|
+
* number literals must be canonical (see `parseCanonicalNumber`). The returned root
|
|
549
|
+
* is always a group, and every node carries a fresh {@link ConditionTreeRule.id}.
|
|
497
550
|
*/
|
|
498
551
|
declare function liftConditionTree(expression: string): ConditionTreeGroup | null;
|
|
499
|
-
|
|
500
|
-
|
|
552
|
+
/**
|
|
553
|
+
* Return `tree` with every node carrying a stable UI id. The shared structural
|
|
554
|
+
* policy is checked before recursive normalization, so invalid external data fails
|
|
555
|
+
* with an {@link ExpressionError} instead of a native stack overflow.
|
|
556
|
+
*/
|
|
557
|
+
declare function ensureConditionNodeIds(tree: ConditionTreeGroup): ConditionTreeGroup;
|
|
501
558
|
/**
|
|
502
559
|
* Evaluate a standard ZEN expression, loading the engine on first use.
|
|
503
560
|
*
|
|
@@ -521,8 +578,6 @@ declare function evaluateSync<T = unknown>(expression: string, context?: Express
|
|
|
521
578
|
* {@link ExpressionNotReadyError} when the engine has not loaded yet.
|
|
522
579
|
*/
|
|
523
580
|
declare function evaluateUnarySync(expression: string, context?: ExpressionContext): boolean;
|
|
524
|
-
//#endregion
|
|
525
|
-
//#region src/engine/messages.d.ts
|
|
526
581
|
/**
|
|
527
582
|
* The locales the library ships with out of the box.
|
|
528
583
|
*/
|
|
@@ -608,8 +663,6 @@ declare function configureExpressionMessages({
|
|
|
608
663
|
* The active {@link ExpressionMessages} catalog (English by default).
|
|
609
664
|
*/
|
|
610
665
|
declare function getExpressionMessages(): ExpressionMessages;
|
|
611
|
-
//#endregion
|
|
612
|
-
//#region src/engine/template.d.ts
|
|
613
666
|
/**
|
|
614
667
|
* One `{{ expression }}` hole located in a template document. `from` / `to` are
|
|
615
668
|
* the character offsets of the inner expression itself — the text between the
|
|
@@ -676,5 +729,4 @@ declare function getTemplateDiagnosticsSync(source: string): ExpressionDiagnosti
|
|
|
676
729
|
* Async {@link getTemplateDiagnosticsSync}, loading the engine on first use.
|
|
677
730
|
*/
|
|
678
731
|
declare function getTemplateDiagnostics(source: string): Promise<ExpressionDiagnostic[]>;
|
|
679
|
-
|
|
680
|
-
export { type BranchSelection, type BuiltInExpressionLocale, CONDITION_OPERATORS, CONDITION_TREE_OPERATORS, type ConditionBranchInput, type ConditionGroupInput, type ConditionInput, type ConditionOperator, type ConditionOperatorArity, type ConditionScalar, type ConditionTreeGroup, type ConditionTreeNode, type ConditionTreeOperator, type ConditionTreeRule, type ConditionTreeValue, type ConfigureMessagesOptions, type ExpressionAnalysis, type ExpressionCompletion, type ExpressionConditionInput, type ExpressionContext, type ExpressionDiagnostic, type ExpressionEngine, ExpressionError, type ExpressionLocale, type ExpressionMessages, type ExpressionMode, ExpressionNotReadyError, type ExpressionType, type ExpressionTypeSpan, type FieldConditionInput, type LoadEngineOptions, type TemplateHole, analyzeTemplate, analyzeTemplateSync, analyzeTypes, analyzeTypesSync, compileBranch, compileCondition, compileConditionTree, compileGroup, conditionOperatorArity, configureEngine, configureExpressionMessages, enMessages, evaluate, evaluateSync, evaluateUnary, evaluateUnarySync, getCompletionItems, getCompletionItemsSync, getDiagnostics, getDiagnosticsSync, getEngineError, getEngineSync, getExpressionMessages, getTemplateDiagnostics, getTemplateDiagnosticsSync, isEngineReady, liftConditionTree, loadEngine, parseTemplateHoles, registerExpressionLocale, resetEngine, satisfiesType, satisfiesTypeSync, selectBranch, selectBranchWith, templateHoleAt, toZenLiteral, zhCNMessages };
|
|
732
|
+
export { type BranchSelection, type BuiltInExpressionLocale, CONDITION_OPERATORS, CONDITION_TREE_OPERATORS, type ConditionBranchInput, type ConditionGroupInput, type ConditionInput, type ConditionOperator, type ConditionOperatorArity, type ConditionScalar, type ConditionTreeGroup, type ConditionTreeNode, type ConditionTreeOperator, type ConditionTreeRule, type ConditionTreeValue, type ConfigureMessagesOptions, type ExpressionAnalysis, type ExpressionCompletion, type ExpressionConditionInput, type ExpressionContext, type ExpressionDiagnostic, type ExpressionEngine, ExpressionError, type ExpressionLocale, type ExpressionMessages, type ExpressionMode, ExpressionNotReadyError, type ExpressionType, type ExpressionTypeSpan, type FieldConditionInput, type LoadEngineOptions, MAX_CONDITION_TREE_DEPTH, type TemplateHole, analyzeTemplate, analyzeTemplateSync, analyzeTypes, analyzeTypesSync, compileBranch, compileCondition, compileConditionTree, compileGroup, conditionOperatorArity, configureEngine, configureExpressionMessages, emptyConditionGroup, enMessages, ensureConditionNodeIds, evaluate, evaluateSync, evaluateUnary, evaluateUnarySync, getCompletionItems, getCompletionItemsSync, getDiagnostics, getDiagnosticsSync, getEngineError, getEngineSync, getExpressionMessages, getTemplateDiagnostics, getTemplateDiagnosticsSync, isEngineReady, isZenRepresentableNumber, liftConditionTree, loadEngine, newConditionNodeId, parseTemplateHoles, registerExpressionLocale, resetEngine, satisfiesType, satisfiesTypeSync, selectBranch, selectBranchWith, templateHoleAt, toZenLiteral, zhCNMessages };
|