@coldsmirk/abacus-core 0.9.0 → 0.11.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 +12 -28
- package/dist/index.cjs +30 -301
- package/dist/index.d.cts +48 -156
- package/dist/index.d.ts +48 -156
- package/dist/index.js +28 -297
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InitInput } from "@gorules/zen-engine-wasm";
|
|
2
|
+
import { SchemaTree } from "@coldsmirk/caliper-core";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* How an expression editor interprets its document:
|
|
@@ -540,15 +541,53 @@ declare function emptyConditionGroup(): ConditionTreeGroup;
|
|
|
540
541
|
* the tree is compilable (see the module note for the drop semantics).
|
|
541
542
|
*/
|
|
542
543
|
declare function compileConditionTree(tree: ConditionTreeGroup): string;
|
|
544
|
+
/**
|
|
545
|
+
* Whether a rule's `right` is an array of scalars — the membership-operand shape.
|
|
546
|
+
* Deliberately stricter than `Array.isArray`: every element must itself be a
|
|
547
|
+
* {@link ConditionScalar}, because a `null` slipping through the type as JSON data
|
|
548
|
+
* would make `toZenLiteral` serialize a `null` literal outside the canonical
|
|
549
|
+
* grammar rather than throw. Also the narrowing predicate for the
|
|
550
|
+
* scalar-or-array {@link ConditionTreeValue} union, which a bare `Array.isArray`
|
|
551
|
+
* narrows poorly over `readonly` arrays.
|
|
552
|
+
*/
|
|
553
|
+
declare function isConditionScalarArray(value: ConditionTreeValue | undefined): value is readonly ConditionScalar[];
|
|
554
|
+
/**
|
|
555
|
+
* Parse `text` as a **canonical** ZEN number — exactly what the condition compiler
|
|
556
|
+
* emits: the `String(n)` rendering of a ZEN-representable value
|
|
557
|
+
* ({@link isZenRepresentableNumber}). Anything else — extra precision float64
|
|
558
|
+
* cannot hold (`9007199254740993` would silently round to `…992`), a magnitude
|
|
559
|
+
* that collapses to Infinity (`1e999`), redundant digits (`1.50`), or a value
|
|
560
|
+
* outside ZEN's decimal domain — returns `null`. For this lifter those are shapes
|
|
561
|
+
* {@link compileConditionTree} can never produce (lifting one would silently
|
|
562
|
+
* rewrite the expression instead of returning `null` as the module contract
|
|
563
|
+
* requires); for a value editor they are inputs whose numeric meaning would
|
|
564
|
+
* change if committed as a number.
|
|
565
|
+
*/
|
|
566
|
+
declare function parseCanonicalZenNumber(text: string): number | null;
|
|
543
567
|
/**
|
|
544
568
|
* Lift a ZEN expression to a condition tree, or `null` when it is not in the
|
|
545
569
|
* canonical form {@link compileConditionTree} produces (the consumer then keeps the
|
|
546
570
|
* raw expression). Groups nested deeper than 64 parenthesized levels are refused as
|
|
547
571
|
* non-canonical rather than risking parser-stack overflow on adversarial input, and
|
|
548
|
-
* number literals must be canonical (see
|
|
572
|
+
* number literals must be canonical (see {@link parseCanonicalZenNumber}). The returned root
|
|
549
573
|
* is always a group, and every node carries a fresh {@link ConditionTreeRule.id}.
|
|
550
574
|
*/
|
|
551
575
|
declare function liftConditionTree(expression: string): ConditionTreeGroup | null;
|
|
576
|
+
/**
|
|
577
|
+
* Shared subject-path guard for the condition compilers. A subject / left-hand
|
|
578
|
+
* path is emitted **verbatim** into ZEN source, so both {@link compileCondition}
|
|
579
|
+
* (which writes that source) and {@link liftConditionTree} (which reads it back)
|
|
580
|
+
* gate paths through this one predicate — a single definition of "what is a safe
|
|
581
|
+
* field path" that cannot drift between the writer and the reader, which matters
|
|
582
|
+
* because the guard is also the compiler's injection defense.
|
|
583
|
+
*/
|
|
584
|
+
/**
|
|
585
|
+
* Whether `word` is one of ZEN's reserved words — the keywords the grammar
|
|
586
|
+
* claims as operators (`and`, `or`, `not`, `in`) or literals (`true`, `false`,
|
|
587
|
+
* `null`). A reserved word can never start an identifier path, and editor
|
|
588
|
+
* tooling treats one as not reachable through plain dot access.
|
|
589
|
+
*/
|
|
590
|
+
declare function isZenReservedWord(word: string): boolean;
|
|
552
591
|
/**
|
|
553
592
|
* Return `tree` with every node carrying a stable UI id. The shared structural
|
|
554
593
|
* policy is checked before recursive normalization, so invalid external data fails
|
|
@@ -669,6 +708,13 @@ declare function getExpressionMessages(): ExpressionMessages;
|
|
|
669
708
|
* function; listeners run synchronously after the new catalog becomes active.
|
|
670
709
|
*/
|
|
671
710
|
declare function subscribeExpressionMessages(listener: ExpressionMessagesListener): () => void;
|
|
711
|
+
/**
|
|
712
|
+
* The expression scope a schema tree declares: each named field becomes a typed variable, so a
|
|
713
|
+
* host can hand the result straight to `<ExpressionInput variables={…}>` (or `analyzeTypes`)
|
|
714
|
+
* and complete against the declared shape. Blank draft rows are skipped, while blank property
|
|
715
|
+
* names preserved by `@coldsmirk/caliper-core`'s `parseSchemaTree` remain part of the scope.
|
|
716
|
+
*/
|
|
717
|
+
declare function schemaTreeToExpressionType(tree: SchemaTree): ExpressionType;
|
|
672
718
|
/**
|
|
673
719
|
* One `{{ expression }}` hole located in a template document. `from` / `to` are
|
|
674
720
|
* the character offsets of the inner expression itself — the text between the
|
|
@@ -735,158 +781,4 @@ declare function getTemplateDiagnosticsSync(source: string): ExpressionDiagnosti
|
|
|
735
781
|
* Async {@link getTemplateDiagnosticsSync}, loading the engine on first use.
|
|
736
782
|
*/
|
|
737
783
|
declare function getTemplateDiagnostics(source: string): Promise<ExpressionDiagnostic[]>;
|
|
738
|
-
|
|
739
|
-
* The field-tree model behind the visual JSON Schema builder: a lossless projection of the
|
|
740
|
-
* JSON Schema subset the tree can host (`type` / `properties` / `items`, plus `required`).
|
|
741
|
-
* The schema JSON stays the single source of truth: {@link parseSchemaTree} REFUSES anything
|
|
742
|
-
* outside the subset (never a lossy rewrite), so a hand-written `oneOf` or `format` keeps its
|
|
743
|
-
* document JSON-only instead of silently vanishing on the first visual edit.
|
|
744
|
-
*/
|
|
745
|
-
/**
|
|
746
|
-
* The one dialect the tree round-trips: a document may omit `$schema` or declare exactly this.
|
|
747
|
-
*/
|
|
748
|
-
declare const SCHEMA_DIALECT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
749
|
-
type SchemaTreeFieldType = "any" | "array" | "boolean" | "integer" | "number" | "object" | "string";
|
|
750
|
-
interface SchemaTreeField {
|
|
751
|
-
/**
|
|
752
|
-
* Stable row identity for React keys and targeted edits — a UI concern, never serialized.
|
|
753
|
-
*/
|
|
754
|
-
id: string;
|
|
755
|
-
/**
|
|
756
|
-
* The property name under its parent object; unused on an array-element node.
|
|
757
|
-
*/
|
|
758
|
-
name: string;
|
|
759
|
-
type: SchemaTreeFieldType;
|
|
760
|
-
/**
|
|
761
|
-
* Listed in the parent object's `required`; unused on an array-element node.
|
|
762
|
-
*/
|
|
763
|
-
required: boolean;
|
|
764
|
-
/**
|
|
765
|
-
* The schema's `description` annotation; blank means none (not serialized).
|
|
766
|
-
*/
|
|
767
|
-
description: string;
|
|
768
|
-
/**
|
|
769
|
-
* Sub-fields, meaningful when `type` is `object`.
|
|
770
|
-
*/
|
|
771
|
-
children: SchemaTreeField[];
|
|
772
|
-
/**
|
|
773
|
-
* The element node, meaningful when `type` is `array`; `null` means untyped elements.
|
|
774
|
-
*/
|
|
775
|
-
items: SchemaTreeField | null;
|
|
776
|
-
/**
|
|
777
|
-
* For an object or array node parsed from JSON, whether its source explicitly
|
|
778
|
-
* declared that type. `false` preserves a type-less applicator; omitted keeps the
|
|
779
|
-
* historical hand-built-tree default of emitting the type.
|
|
780
|
-
*/
|
|
781
|
-
explicitType?: boolean;
|
|
782
|
-
/**
|
|
783
|
-
* Whether a blank / whitespace-only name came from a real `properties` key and must be
|
|
784
|
-
* persisted. Omitted blank names are unfinished UI rows and do not serialize.
|
|
785
|
-
*/
|
|
786
|
-
preserveBlankName?: boolean;
|
|
787
|
-
}
|
|
788
|
-
interface SchemaTree {
|
|
789
|
-
fields: SchemaTreeField[];
|
|
790
|
-
/**
|
|
791
|
-
* Whether the source declared `$schema` (re-emitted verbatim on serialize).
|
|
792
|
-
*/
|
|
793
|
-
dialect: boolean;
|
|
794
|
-
/**
|
|
795
|
-
* The root schema's `description` annotation, preserved verbatim across the round trip
|
|
796
|
-
* (the field view offers no root-level editor); blank means none.
|
|
797
|
-
*/
|
|
798
|
-
description: string;
|
|
799
|
-
/**
|
|
800
|
-
* For a tree parsed from JSON, whether the root explicitly declared `type: "object"`.
|
|
801
|
-
* `false` preserves a type-less root; omitted keeps the historical hand-built-tree default
|
|
802
|
-
* of emitting the type.
|
|
803
|
-
*/
|
|
804
|
-
explicitType?: boolean;
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* Why a document cannot be projected onto the field tree — structured so a UI can localize
|
|
808
|
-
* the explanation. Every code names the offending part where one exists.
|
|
809
|
-
*/
|
|
810
|
-
type SchemaTreeIssue = {
|
|
811
|
-
code: "invalid-description";
|
|
812
|
-
} | {
|
|
813
|
-
code: "invalid-field-definition";
|
|
814
|
-
field: string;
|
|
815
|
-
} | {
|
|
816
|
-
code: "invalid-field-type";
|
|
817
|
-
field: string;
|
|
818
|
-
} | {
|
|
819
|
-
code: "invalid-json";
|
|
820
|
-
} | {
|
|
821
|
-
code: "invalid-properties";
|
|
822
|
-
} | {
|
|
823
|
-
code: "invalid-required";
|
|
824
|
-
} | {
|
|
825
|
-
code: "misplaced-keyword";
|
|
826
|
-
keyword: string;
|
|
827
|
-
holder: "array" | "object";
|
|
828
|
-
} | {
|
|
829
|
-
code: "root-not-object";
|
|
830
|
-
} | {
|
|
831
|
-
code: "unknown-required-field";
|
|
832
|
-
field: string;
|
|
833
|
-
} | {
|
|
834
|
-
code: "unsupported-dialect";
|
|
835
|
-
} | {
|
|
836
|
-
code: "unsupported-field-type";
|
|
837
|
-
field: string;
|
|
838
|
-
type: string;
|
|
839
|
-
} | {
|
|
840
|
-
code: "unsupported-keyword";
|
|
841
|
-
keyword: string;
|
|
842
|
-
};
|
|
843
|
-
type SchemaTreeParseResult = {
|
|
844
|
-
ok: true;
|
|
845
|
-
tree: SchemaTree;
|
|
846
|
-
} | {
|
|
847
|
-
ok: false;
|
|
848
|
-
issue: SchemaTreeIssue;
|
|
849
|
-
};
|
|
850
|
-
/**
|
|
851
|
-
* A fresh {@link SchemaTreeField}, defaulting to an optional unnamed string field. The id is a
|
|
852
|
-
* tagged counter, not a UUID: field identity is a UI concern with no persistence or
|
|
853
|
-
* cross-process meaning — exactly the guarantee a React key needs.
|
|
854
|
-
*/
|
|
855
|
-
declare function newSchemaTreeField(overrides?: Partial<Omit<SchemaTreeField, "id">>): SchemaTreeField;
|
|
856
|
-
/**
|
|
857
|
-
* The expression scope a schema tree declares: each named field becomes a typed variable, so a
|
|
858
|
-
* host can hand the result straight to `<ExpressionInput variables={…}>` (or `analyzeTypes`)
|
|
859
|
-
* and complete against the declared shape. Blank draft rows are skipped, while blank property
|
|
860
|
-
* names preserved by {@link parseSchemaTree} remain part of the scope.
|
|
861
|
-
*/
|
|
862
|
-
declare function schemaTreeToExpressionType(tree: SchemaTree): ExpressionType;
|
|
863
|
-
/**
|
|
864
|
-
* Infer a draft 2020-12 JSON Schema from a sample payload — the "generate from example" path of
|
|
865
|
-
* the visual schema builder. Deliberately emits only the subset {@link parseSchemaTree} hosts
|
|
866
|
-
* (`type` / `properties` / `items`): integers stay `number` (a sample's `5` rarely promises
|
|
867
|
-
* integers forever) and nothing is marked `required` (validation strictness is an authoring
|
|
868
|
-
* decision, not something a single sample can attest).
|
|
869
|
-
*/
|
|
870
|
-
interface JsonObject {
|
|
871
|
-
[key: string]: Json;
|
|
872
|
-
}
|
|
873
|
-
type Json = null | boolean | number | string | Json[] | JsonObject;
|
|
874
|
-
/**
|
|
875
|
-
* The schema a sample value attests: scalars map to their type, objects carry every observed
|
|
876
|
-
* property, arrays take the merged schema of their elements (an empty or mixed array leaves the
|
|
877
|
-
* items open). `null` says nothing about the real type, so it infers `{}` (any).
|
|
878
|
-
*/
|
|
879
|
-
declare function inferSchema(sample: Json): JsonObject;
|
|
880
|
-
/**
|
|
881
|
-
* Project a schema document onto the field tree, or refuse with a structured
|
|
882
|
-
* {@link SchemaTreeIssue} when it uses anything beyond the subset. A blank document parses as
|
|
883
|
-
* an empty tree.
|
|
884
|
-
*/
|
|
885
|
-
declare function parseSchemaTree(text: string): SchemaTreeParseResult;
|
|
886
|
-
/**
|
|
887
|
-
* The field tree back as pretty-printed schema JSON. A parsed type-less object root stays
|
|
888
|
-
* type-less; a hand-built tree still emits an object root by default. Clearing the contract
|
|
889
|
-
* entirely (an empty document) stays a source-mode action.
|
|
890
|
-
*/
|
|
891
|
-
declare function serializeSchemaTree(tree: SchemaTree): string;
|
|
892
|
-
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 ExpressionMessagesListener, type ExpressionMode, ExpressionNotReadyError, type ExpressionType, type ExpressionTypeSpan, type FieldConditionInput, type Json, type LoadEngineOptions, MAX_CONDITION_TREE_DEPTH, SCHEMA_DIALECT_2020_12, type SchemaTree, type SchemaTreeField, type SchemaTreeFieldType, type SchemaTreeIssue, type SchemaTreeParseResult, 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, inferSchema, isEngineReady, isZenRepresentableNumber, liftConditionTree, loadEngine, newConditionNodeId, newSchemaTreeField, parseSchemaTree, parseTemplateHoles, registerExpressionLocale, resetEngine, satisfiesType, satisfiesTypeSync, schemaTreeToExpressionType, selectBranch, selectBranchWith, serializeSchemaTree, subscribeExpressionMessages, templateHoleAt, toZenLiteral, zhCNMessages };
|
|
784
|
+
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 ExpressionMessagesListener, 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, isConditionScalarArray, isEngineReady, isZenRepresentableNumber, isZenReservedWord, liftConditionTree, loadEngine, newConditionNodeId, parseCanonicalZenNumber, parseTemplateHoles, registerExpressionLocale, resetEngine, satisfiesType, satisfiesTypeSync, schemaTreeToExpressionType, selectBranch, selectBranchWith, subscribeExpressionMessages, templateHoleAt, toZenLiteral, zhCNMessages };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InitInput } from "@gorules/zen-engine-wasm";
|
|
2
|
+
import { SchemaTree } from "@coldsmirk/caliper-core";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* How an expression editor interprets its document:
|
|
@@ -540,15 +541,53 @@ declare function emptyConditionGroup(): ConditionTreeGroup;
|
|
|
540
541
|
* the tree is compilable (see the module note for the drop semantics).
|
|
541
542
|
*/
|
|
542
543
|
declare function compileConditionTree(tree: ConditionTreeGroup): string;
|
|
544
|
+
/**
|
|
545
|
+
* Whether a rule's `right` is an array of scalars — the membership-operand shape.
|
|
546
|
+
* Deliberately stricter than `Array.isArray`: every element must itself be a
|
|
547
|
+
* {@link ConditionScalar}, because a `null` slipping through the type as JSON data
|
|
548
|
+
* would make `toZenLiteral` serialize a `null` literal outside the canonical
|
|
549
|
+
* grammar rather than throw. Also the narrowing predicate for the
|
|
550
|
+
* scalar-or-array {@link ConditionTreeValue} union, which a bare `Array.isArray`
|
|
551
|
+
* narrows poorly over `readonly` arrays.
|
|
552
|
+
*/
|
|
553
|
+
declare function isConditionScalarArray(value: ConditionTreeValue | undefined): value is readonly ConditionScalar[];
|
|
554
|
+
/**
|
|
555
|
+
* Parse `text` as a **canonical** ZEN number — exactly what the condition compiler
|
|
556
|
+
* emits: the `String(n)` rendering of a ZEN-representable value
|
|
557
|
+
* ({@link isZenRepresentableNumber}). Anything else — extra precision float64
|
|
558
|
+
* cannot hold (`9007199254740993` would silently round to `…992`), a magnitude
|
|
559
|
+
* that collapses to Infinity (`1e999`), redundant digits (`1.50`), or a value
|
|
560
|
+
* outside ZEN's decimal domain — returns `null`. For this lifter those are shapes
|
|
561
|
+
* {@link compileConditionTree} can never produce (lifting one would silently
|
|
562
|
+
* rewrite the expression instead of returning `null` as the module contract
|
|
563
|
+
* requires); for a value editor they are inputs whose numeric meaning would
|
|
564
|
+
* change if committed as a number.
|
|
565
|
+
*/
|
|
566
|
+
declare function parseCanonicalZenNumber(text: string): number | null;
|
|
543
567
|
/**
|
|
544
568
|
* Lift a ZEN expression to a condition tree, or `null` when it is not in the
|
|
545
569
|
* canonical form {@link compileConditionTree} produces (the consumer then keeps the
|
|
546
570
|
* raw expression). Groups nested deeper than 64 parenthesized levels are refused as
|
|
547
571
|
* non-canonical rather than risking parser-stack overflow on adversarial input, and
|
|
548
|
-
* number literals must be canonical (see
|
|
572
|
+
* number literals must be canonical (see {@link parseCanonicalZenNumber}). The returned root
|
|
549
573
|
* is always a group, and every node carries a fresh {@link ConditionTreeRule.id}.
|
|
550
574
|
*/
|
|
551
575
|
declare function liftConditionTree(expression: string): ConditionTreeGroup | null;
|
|
576
|
+
/**
|
|
577
|
+
* Shared subject-path guard for the condition compilers. A subject / left-hand
|
|
578
|
+
* path is emitted **verbatim** into ZEN source, so both {@link compileCondition}
|
|
579
|
+
* (which writes that source) and {@link liftConditionTree} (which reads it back)
|
|
580
|
+
* gate paths through this one predicate — a single definition of "what is a safe
|
|
581
|
+
* field path" that cannot drift between the writer and the reader, which matters
|
|
582
|
+
* because the guard is also the compiler's injection defense.
|
|
583
|
+
*/
|
|
584
|
+
/**
|
|
585
|
+
* Whether `word` is one of ZEN's reserved words — the keywords the grammar
|
|
586
|
+
* claims as operators (`and`, `or`, `not`, `in`) or literals (`true`, `false`,
|
|
587
|
+
* `null`). A reserved word can never start an identifier path, and editor
|
|
588
|
+
* tooling treats one as not reachable through plain dot access.
|
|
589
|
+
*/
|
|
590
|
+
declare function isZenReservedWord(word: string): boolean;
|
|
552
591
|
/**
|
|
553
592
|
* Return `tree` with every node carrying a stable UI id. The shared structural
|
|
554
593
|
* policy is checked before recursive normalization, so invalid external data fails
|
|
@@ -669,6 +708,13 @@ declare function getExpressionMessages(): ExpressionMessages;
|
|
|
669
708
|
* function; listeners run synchronously after the new catalog becomes active.
|
|
670
709
|
*/
|
|
671
710
|
declare function subscribeExpressionMessages(listener: ExpressionMessagesListener): () => void;
|
|
711
|
+
/**
|
|
712
|
+
* The expression scope a schema tree declares: each named field becomes a typed variable, so a
|
|
713
|
+
* host can hand the result straight to `<ExpressionInput variables={…}>` (or `analyzeTypes`)
|
|
714
|
+
* and complete against the declared shape. Blank draft rows are skipped, while blank property
|
|
715
|
+
* names preserved by `@coldsmirk/caliper-core`'s `parseSchemaTree` remain part of the scope.
|
|
716
|
+
*/
|
|
717
|
+
declare function schemaTreeToExpressionType(tree: SchemaTree): ExpressionType;
|
|
672
718
|
/**
|
|
673
719
|
* One `{{ expression }}` hole located in a template document. `from` / `to` are
|
|
674
720
|
* the character offsets of the inner expression itself — the text between the
|
|
@@ -735,158 +781,4 @@ declare function getTemplateDiagnosticsSync(source: string): ExpressionDiagnosti
|
|
|
735
781
|
* Async {@link getTemplateDiagnosticsSync}, loading the engine on first use.
|
|
736
782
|
*/
|
|
737
783
|
declare function getTemplateDiagnostics(source: string): Promise<ExpressionDiagnostic[]>;
|
|
738
|
-
|
|
739
|
-
* The field-tree model behind the visual JSON Schema builder: a lossless projection of the
|
|
740
|
-
* JSON Schema subset the tree can host (`type` / `properties` / `items`, plus `required`).
|
|
741
|
-
* The schema JSON stays the single source of truth: {@link parseSchemaTree} REFUSES anything
|
|
742
|
-
* outside the subset (never a lossy rewrite), so a hand-written `oneOf` or `format` keeps its
|
|
743
|
-
* document JSON-only instead of silently vanishing on the first visual edit.
|
|
744
|
-
*/
|
|
745
|
-
/**
|
|
746
|
-
* The one dialect the tree round-trips: a document may omit `$schema` or declare exactly this.
|
|
747
|
-
*/
|
|
748
|
-
declare const SCHEMA_DIALECT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
749
|
-
type SchemaTreeFieldType = "any" | "array" | "boolean" | "integer" | "number" | "object" | "string";
|
|
750
|
-
interface SchemaTreeField {
|
|
751
|
-
/**
|
|
752
|
-
* Stable row identity for React keys and targeted edits — a UI concern, never serialized.
|
|
753
|
-
*/
|
|
754
|
-
id: string;
|
|
755
|
-
/**
|
|
756
|
-
* The property name under its parent object; unused on an array-element node.
|
|
757
|
-
*/
|
|
758
|
-
name: string;
|
|
759
|
-
type: SchemaTreeFieldType;
|
|
760
|
-
/**
|
|
761
|
-
* Listed in the parent object's `required`; unused on an array-element node.
|
|
762
|
-
*/
|
|
763
|
-
required: boolean;
|
|
764
|
-
/**
|
|
765
|
-
* The schema's `description` annotation; blank means none (not serialized).
|
|
766
|
-
*/
|
|
767
|
-
description: string;
|
|
768
|
-
/**
|
|
769
|
-
* Sub-fields, meaningful when `type` is `object`.
|
|
770
|
-
*/
|
|
771
|
-
children: SchemaTreeField[];
|
|
772
|
-
/**
|
|
773
|
-
* The element node, meaningful when `type` is `array`; `null` means untyped elements.
|
|
774
|
-
*/
|
|
775
|
-
items: SchemaTreeField | null;
|
|
776
|
-
/**
|
|
777
|
-
* For an object or array node parsed from JSON, whether its source explicitly
|
|
778
|
-
* declared that type. `false` preserves a type-less applicator; omitted keeps the
|
|
779
|
-
* historical hand-built-tree default of emitting the type.
|
|
780
|
-
*/
|
|
781
|
-
explicitType?: boolean;
|
|
782
|
-
/**
|
|
783
|
-
* Whether a blank / whitespace-only name came from a real `properties` key and must be
|
|
784
|
-
* persisted. Omitted blank names are unfinished UI rows and do not serialize.
|
|
785
|
-
*/
|
|
786
|
-
preserveBlankName?: boolean;
|
|
787
|
-
}
|
|
788
|
-
interface SchemaTree {
|
|
789
|
-
fields: SchemaTreeField[];
|
|
790
|
-
/**
|
|
791
|
-
* Whether the source declared `$schema` (re-emitted verbatim on serialize).
|
|
792
|
-
*/
|
|
793
|
-
dialect: boolean;
|
|
794
|
-
/**
|
|
795
|
-
* The root schema's `description` annotation, preserved verbatim across the round trip
|
|
796
|
-
* (the field view offers no root-level editor); blank means none.
|
|
797
|
-
*/
|
|
798
|
-
description: string;
|
|
799
|
-
/**
|
|
800
|
-
* For a tree parsed from JSON, whether the root explicitly declared `type: "object"`.
|
|
801
|
-
* `false` preserves a type-less root; omitted keeps the historical hand-built-tree default
|
|
802
|
-
* of emitting the type.
|
|
803
|
-
*/
|
|
804
|
-
explicitType?: boolean;
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* Why a document cannot be projected onto the field tree — structured so a UI can localize
|
|
808
|
-
* the explanation. Every code names the offending part where one exists.
|
|
809
|
-
*/
|
|
810
|
-
type SchemaTreeIssue = {
|
|
811
|
-
code: "invalid-description";
|
|
812
|
-
} | {
|
|
813
|
-
code: "invalid-field-definition";
|
|
814
|
-
field: string;
|
|
815
|
-
} | {
|
|
816
|
-
code: "invalid-field-type";
|
|
817
|
-
field: string;
|
|
818
|
-
} | {
|
|
819
|
-
code: "invalid-json";
|
|
820
|
-
} | {
|
|
821
|
-
code: "invalid-properties";
|
|
822
|
-
} | {
|
|
823
|
-
code: "invalid-required";
|
|
824
|
-
} | {
|
|
825
|
-
code: "misplaced-keyword";
|
|
826
|
-
keyword: string;
|
|
827
|
-
holder: "array" | "object";
|
|
828
|
-
} | {
|
|
829
|
-
code: "root-not-object";
|
|
830
|
-
} | {
|
|
831
|
-
code: "unknown-required-field";
|
|
832
|
-
field: string;
|
|
833
|
-
} | {
|
|
834
|
-
code: "unsupported-dialect";
|
|
835
|
-
} | {
|
|
836
|
-
code: "unsupported-field-type";
|
|
837
|
-
field: string;
|
|
838
|
-
type: string;
|
|
839
|
-
} | {
|
|
840
|
-
code: "unsupported-keyword";
|
|
841
|
-
keyword: string;
|
|
842
|
-
};
|
|
843
|
-
type SchemaTreeParseResult = {
|
|
844
|
-
ok: true;
|
|
845
|
-
tree: SchemaTree;
|
|
846
|
-
} | {
|
|
847
|
-
ok: false;
|
|
848
|
-
issue: SchemaTreeIssue;
|
|
849
|
-
};
|
|
850
|
-
/**
|
|
851
|
-
* A fresh {@link SchemaTreeField}, defaulting to an optional unnamed string field. The id is a
|
|
852
|
-
* tagged counter, not a UUID: field identity is a UI concern with no persistence or
|
|
853
|
-
* cross-process meaning — exactly the guarantee a React key needs.
|
|
854
|
-
*/
|
|
855
|
-
declare function newSchemaTreeField(overrides?: Partial<Omit<SchemaTreeField, "id">>): SchemaTreeField;
|
|
856
|
-
/**
|
|
857
|
-
* The expression scope a schema tree declares: each named field becomes a typed variable, so a
|
|
858
|
-
* host can hand the result straight to `<ExpressionInput variables={…}>` (or `analyzeTypes`)
|
|
859
|
-
* and complete against the declared shape. Blank draft rows are skipped, while blank property
|
|
860
|
-
* names preserved by {@link parseSchemaTree} remain part of the scope.
|
|
861
|
-
*/
|
|
862
|
-
declare function schemaTreeToExpressionType(tree: SchemaTree): ExpressionType;
|
|
863
|
-
/**
|
|
864
|
-
* Infer a draft 2020-12 JSON Schema from a sample payload — the "generate from example" path of
|
|
865
|
-
* the visual schema builder. Deliberately emits only the subset {@link parseSchemaTree} hosts
|
|
866
|
-
* (`type` / `properties` / `items`): integers stay `number` (a sample's `5` rarely promises
|
|
867
|
-
* integers forever) and nothing is marked `required` (validation strictness is an authoring
|
|
868
|
-
* decision, not something a single sample can attest).
|
|
869
|
-
*/
|
|
870
|
-
interface JsonObject {
|
|
871
|
-
[key: string]: Json;
|
|
872
|
-
}
|
|
873
|
-
type Json = null | boolean | number | string | Json[] | JsonObject;
|
|
874
|
-
/**
|
|
875
|
-
* The schema a sample value attests: scalars map to their type, objects carry every observed
|
|
876
|
-
* property, arrays take the merged schema of their elements (an empty or mixed array leaves the
|
|
877
|
-
* items open). `null` says nothing about the real type, so it infers `{}` (any).
|
|
878
|
-
*/
|
|
879
|
-
declare function inferSchema(sample: Json): JsonObject;
|
|
880
|
-
/**
|
|
881
|
-
* Project a schema document onto the field tree, or refuse with a structured
|
|
882
|
-
* {@link SchemaTreeIssue} when it uses anything beyond the subset. A blank document parses as
|
|
883
|
-
* an empty tree.
|
|
884
|
-
*/
|
|
885
|
-
declare function parseSchemaTree(text: string): SchemaTreeParseResult;
|
|
886
|
-
/**
|
|
887
|
-
* The field tree back as pretty-printed schema JSON. A parsed type-less object root stays
|
|
888
|
-
* type-less; a hand-built tree still emits an object root by default. Clearing the contract
|
|
889
|
-
* entirely (an empty document) stays a source-mode action.
|
|
890
|
-
*/
|
|
891
|
-
declare function serializeSchemaTree(tree: SchemaTree): string;
|
|
892
|
-
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 ExpressionMessagesListener, type ExpressionMode, ExpressionNotReadyError, type ExpressionType, type ExpressionTypeSpan, type FieldConditionInput, type Json, type LoadEngineOptions, MAX_CONDITION_TREE_DEPTH, SCHEMA_DIALECT_2020_12, type SchemaTree, type SchemaTreeField, type SchemaTreeFieldType, type SchemaTreeIssue, type SchemaTreeParseResult, 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, inferSchema, isEngineReady, isZenRepresentableNumber, liftConditionTree, loadEngine, newConditionNodeId, newSchemaTreeField, parseSchemaTree, parseTemplateHoles, registerExpressionLocale, resetEngine, satisfiesType, satisfiesTypeSync, schemaTreeToExpressionType, selectBranch, selectBranchWith, serializeSchemaTree, subscribeExpressionMessages, templateHoleAt, toZenLiteral, zhCNMessages };
|
|
784
|
+
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 ExpressionMessagesListener, 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, isConditionScalarArray, isEngineReady, isZenRepresentableNumber, isZenReservedWord, liftConditionTree, loadEngine, newConditionNodeId, parseCanonicalZenNumber, parseTemplateHoles, registerExpressionLocale, resetEngine, satisfiesType, satisfiesTypeSync, schemaTreeToExpressionType, selectBranch, selectBranchWith, subscribeExpressionMessages, templateHoleAt, toZenLiteral, zhCNMessages };
|