@formspec/build 0.1.0-alpha.2 → 0.1.0-alpha.20
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 +120 -0
- package/dist/__tests__/alias-chain-propagation.test.d.ts +9 -0
- package/dist/__tests__/alias-chain-propagation.test.d.ts.map +1 -0
- package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts +2 -0
- package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts.map +1 -0
- package/dist/__tests__/class-schema.test.d.ts +2 -0
- package/dist/__tests__/class-schema.test.d.ts.map +1 -0
- package/dist/__tests__/constraint-validator.test.d.ts +2 -0
- package/dist/__tests__/constraint-validator.test.d.ts.map +1 -0
- package/dist/__tests__/date-extension.integration.test.d.ts +2 -0
- package/dist/__tests__/date-extension.integration.test.d.ts.map +1 -0
- package/dist/__tests__/extension-api.test.d.ts +2 -0
- package/dist/__tests__/extension-api.test.d.ts.map +1 -0
- package/dist/__tests__/extension-runtime.integration.test.d.ts +2 -0
- package/dist/__tests__/extension-runtime.integration.test.d.ts.map +1 -0
- package/dist/__tests__/fixtures/alias-chains.d.ts +37 -0
- package/dist/__tests__/fixtures/alias-chains.d.ts.map +1 -0
- package/dist/__tests__/fixtures/class-schema-regressions.d.ts +87 -0
- package/dist/__tests__/fixtures/class-schema-regressions.d.ts.map +1 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts +132 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts +30 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-date-extension.d.ts +12 -0
- package/dist/__tests__/fixtures/example-date-extension.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-interface-types.d.ts +102 -0
- package/dist/__tests__/fixtures/example-interface-types.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-numeric-extension.d.ts +20 -0
- package/dist/__tests__/fixtures/example-numeric-extension.d.ts.map +1 -0
- package/dist/__tests__/fixtures/extension-forms.d.ts +7 -0
- package/dist/__tests__/fixtures/extension-forms.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts +31 -0
- package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts.map +1 -0
- package/dist/__tests__/fixtures/named-primitive-aliases.d.ts +15 -0
- package/dist/__tests__/fixtures/named-primitive-aliases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts +14 -0
- package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts.map +1 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts +65 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts.map +1 -0
- package/dist/__tests__/generate-schemas.test.d.ts +2 -0
- package/dist/__tests__/generate-schemas.test.d.ts.map +1 -0
- package/dist/__tests__/guards.test.d.ts +2 -0
- package/dist/__tests__/guards.test.d.ts.map +1 -0
- package/dist/__tests__/ir-analyzer.test.d.ts +11 -0
- package/dist/__tests__/ir-analyzer.test.d.ts.map +1 -0
- package/dist/__tests__/ir-jsdoc-constraints.test.d.ts +12 -0
- package/dist/__tests__/ir-jsdoc-constraints.test.d.ts.map +1 -0
- package/dist/__tests__/ir-json-schema-generator.test.d.ts +11 -0
- package/dist/__tests__/ir-json-schema-generator.test.d.ts.map +1 -0
- package/dist/__tests__/ir-ui-schema-generator.test.d.ts +2 -0
- package/dist/__tests__/ir-ui-schema-generator.test.d.ts.map +1 -0
- package/dist/__tests__/mixed-authoring.test.d.ts +2 -0
- package/dist/__tests__/mixed-authoring.test.d.ts.map +1 -0
- package/dist/__tests__/numeric-extension.integration.test.d.ts +2 -0
- package/dist/__tests__/numeric-extension.integration.test.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts +6 -0
- package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts +17 -0
- package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts +13 -0
- package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts +28 -0
- package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts +6 -0
- package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts +12 -0
- package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/parity.test.d.ts +18 -0
- package/dist/__tests__/parity/parity.test.d.ts.map +1 -0
- package/dist/__tests__/parity/utils.d.ts +151 -0
- package/dist/__tests__/parity/utils.d.ts.map +1 -0
- package/dist/__tests__/path-target-parser.test.d.ts +9 -0
- package/dist/__tests__/path-target-parser.test.d.ts.map +1 -0
- package/dist/analyzer/class-analyzer.d.ts +100 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -0
- package/dist/analyzer/jsdoc-constraints.d.ts +53 -0
- package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
- package/dist/analyzer/program.d.ts +68 -0
- package/dist/analyzer/program.d.ts.map +1 -0
- package/dist/analyzer/tsdoc-parser.d.ts +122 -0
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
- package/dist/browser.cjs +1291 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.ts +73 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1242 -0
- package/dist/browser.js.map +1 -0
- package/dist/build.d.ts +996 -0
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +18 -0
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -0
- package/dist/canonicalize/index.d.ts +8 -0
- package/dist/canonicalize/index.d.ts.map +1 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts +34 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
- package/dist/cli.cjs +3862 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +3826 -103
- package/dist/cli.js.map +1 -1
- package/dist/extensions/index.d.ts +8 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/registry.d.ts +79 -0
- package/dist/extensions/registry.d.ts.map +1 -0
- package/dist/generators/class-schema.d.ts +99 -0
- package/dist/generators/class-schema.d.ts.map +1 -0
- package/dist/generators/method-schema.d.ts +65 -0
- package/dist/generators/method-schema.d.ts.map +1 -0
- package/dist/generators/mixed-authoring.d.ts +45 -0
- package/dist/generators/mixed-authoring.d.ts.map +1 -0
- package/dist/index.cjs +3627 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +33 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3587 -106
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +3371 -0
- package/dist/internals.cjs.map +1 -0
- package/dist/internals.d.ts +30 -0
- package/dist/internals.d.ts.map +1 -0
- package/dist/internals.js +3345 -0
- package/dist/internals.js.map +1 -0
- package/dist/json-schema/generator.d.ts +16 -5
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/json-schema/ir-generator.d.ts +108 -0
- package/dist/json-schema/ir-generator.d.ts.map +1 -0
- package/dist/json-schema/schema.d.ts +16 -0
- package/dist/json-schema/schema.d.ts.map +1 -0
- package/dist/json-schema/types.d.ts +29 -2
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/ui-schema/generator.d.ts +5 -0
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/ir-generator.d.ts +53 -0
- package/dist/ui-schema/ir-generator.d.ts.map +1 -0
- package/dist/ui-schema/schema.d.ts +357 -0
- package/dist/ui-schema/schema.d.ts.map +1 -0
- package/dist/ui-schema/types.d.ts +8 -73
- package/dist/ui-schema/types.d.ts.map +1 -1
- package/dist/validate/constraint-validator.d.ts +23 -0
- package/dist/validate/constraint-validator.d.ts.map +1 -0
- package/dist/validate/index.d.ts +9 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/package.json +27 -7
- package/dist/__tests__/cli.test.js +0 -178
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/__tests__/edge-cases.test.js +0 -217
- package/dist/__tests__/edge-cases.test.js.map +0 -1
- package/dist/__tests__/generator.test.js +0 -225
- package/dist/__tests__/generator.test.js.map +0 -1
- package/dist/__tests__/integration.test.js +0 -163
- package/dist/__tests__/integration.test.js.map +0 -1
- package/dist/__tests__/write-schemas.test.js +0 -196
- package/dist/__tests__/write-schemas.test.js.map +0 -1
- package/dist/json-schema/generator.js +0 -161
- package/dist/json-schema/generator.js.map +0 -1
- package/dist/json-schema/types.js +0 -7
- package/dist/json-schema/types.js.map +0 -1
- package/dist/ui-schema/generator.js +0 -150
- package/dist/ui-schema/generator.js.map +0 -1
- package/dist/ui-schema/types.js +0 -8
- package/dist/ui-schema/types.js.map +0 -1
package/dist/browser.js
ADDED
|
@@ -0,0 +1,1242 @@
|
|
|
1
|
+
// src/canonicalize/chain-dsl-canonicalizer.ts
|
|
2
|
+
import { IR_VERSION } from "@formspec/core";
|
|
3
|
+
var CHAIN_DSL_PROVENANCE = {
|
|
4
|
+
surface: "chain-dsl",
|
|
5
|
+
file: "",
|
|
6
|
+
line: 0,
|
|
7
|
+
column: 0
|
|
8
|
+
};
|
|
9
|
+
function isGroup(el) {
|
|
10
|
+
return el._type === "group";
|
|
11
|
+
}
|
|
12
|
+
function isConditional(el) {
|
|
13
|
+
return el._type === "conditional";
|
|
14
|
+
}
|
|
15
|
+
function isField(el) {
|
|
16
|
+
return el._type === "field";
|
|
17
|
+
}
|
|
18
|
+
function canonicalizeChainDSL(form) {
|
|
19
|
+
return {
|
|
20
|
+
kind: "form-ir",
|
|
21
|
+
irVersion: IR_VERSION,
|
|
22
|
+
elements: canonicalizeElements(form.elements),
|
|
23
|
+
rootAnnotations: [],
|
|
24
|
+
typeRegistry: {},
|
|
25
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function canonicalizeElements(elements) {
|
|
29
|
+
return elements.map(canonicalizeElement);
|
|
30
|
+
}
|
|
31
|
+
function canonicalizeElement(element) {
|
|
32
|
+
if (isField(element)) {
|
|
33
|
+
return canonicalizeField(element);
|
|
34
|
+
}
|
|
35
|
+
if (isGroup(element)) {
|
|
36
|
+
return canonicalizeGroup(element);
|
|
37
|
+
}
|
|
38
|
+
if (isConditional(element)) {
|
|
39
|
+
return canonicalizeConditional(element);
|
|
40
|
+
}
|
|
41
|
+
const _exhaustive = element;
|
|
42
|
+
throw new Error(`Unknown element type: ${JSON.stringify(_exhaustive)}`);
|
|
43
|
+
}
|
|
44
|
+
function canonicalizeField(field) {
|
|
45
|
+
switch (field._field) {
|
|
46
|
+
case "text":
|
|
47
|
+
return canonicalizeTextField(field);
|
|
48
|
+
case "number":
|
|
49
|
+
return canonicalizeNumberField(field);
|
|
50
|
+
case "boolean":
|
|
51
|
+
return canonicalizeBooleanField(field);
|
|
52
|
+
case "enum":
|
|
53
|
+
return canonicalizeStaticEnumField(field);
|
|
54
|
+
case "dynamic_enum":
|
|
55
|
+
return canonicalizeDynamicEnumField(field);
|
|
56
|
+
case "dynamic_schema":
|
|
57
|
+
return canonicalizeDynamicSchemaField(field);
|
|
58
|
+
case "array":
|
|
59
|
+
return canonicalizeArrayField(field);
|
|
60
|
+
case "object":
|
|
61
|
+
return canonicalizeObjectField(field);
|
|
62
|
+
default: {
|
|
63
|
+
const _exhaustive = field;
|
|
64
|
+
throw new Error(`Unknown field type: ${JSON.stringify(_exhaustive)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function canonicalizeTextField(field) {
|
|
69
|
+
const type = { kind: "primitive", primitiveKind: "string" };
|
|
70
|
+
const constraints = [];
|
|
71
|
+
if (field.minLength !== void 0) {
|
|
72
|
+
const c = {
|
|
73
|
+
kind: "constraint",
|
|
74
|
+
constraintKind: "minLength",
|
|
75
|
+
value: field.minLength,
|
|
76
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
77
|
+
};
|
|
78
|
+
constraints.push(c);
|
|
79
|
+
}
|
|
80
|
+
if (field.maxLength !== void 0) {
|
|
81
|
+
const c = {
|
|
82
|
+
kind: "constraint",
|
|
83
|
+
constraintKind: "maxLength",
|
|
84
|
+
value: field.maxLength,
|
|
85
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
86
|
+
};
|
|
87
|
+
constraints.push(c);
|
|
88
|
+
}
|
|
89
|
+
if (field.pattern !== void 0) {
|
|
90
|
+
const c = {
|
|
91
|
+
kind: "constraint",
|
|
92
|
+
constraintKind: "pattern",
|
|
93
|
+
pattern: field.pattern,
|
|
94
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
95
|
+
};
|
|
96
|
+
constraints.push(c);
|
|
97
|
+
}
|
|
98
|
+
return buildFieldNode(
|
|
99
|
+
field.name,
|
|
100
|
+
type,
|
|
101
|
+
field.required,
|
|
102
|
+
buildAnnotations(field.label, field.placeholder),
|
|
103
|
+
constraints
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
function canonicalizeNumberField(field) {
|
|
107
|
+
const type = { kind: "primitive", primitiveKind: "number" };
|
|
108
|
+
const constraints = [];
|
|
109
|
+
if (field.min !== void 0) {
|
|
110
|
+
const c = {
|
|
111
|
+
kind: "constraint",
|
|
112
|
+
constraintKind: "minimum",
|
|
113
|
+
value: field.min,
|
|
114
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
115
|
+
};
|
|
116
|
+
constraints.push(c);
|
|
117
|
+
}
|
|
118
|
+
if (field.max !== void 0) {
|
|
119
|
+
const c = {
|
|
120
|
+
kind: "constraint",
|
|
121
|
+
constraintKind: "maximum",
|
|
122
|
+
value: field.max,
|
|
123
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
124
|
+
};
|
|
125
|
+
constraints.push(c);
|
|
126
|
+
}
|
|
127
|
+
if (field.multipleOf !== void 0) {
|
|
128
|
+
const c = {
|
|
129
|
+
kind: "constraint",
|
|
130
|
+
constraintKind: "multipleOf",
|
|
131
|
+
value: field.multipleOf,
|
|
132
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
133
|
+
};
|
|
134
|
+
constraints.push(c);
|
|
135
|
+
}
|
|
136
|
+
return buildFieldNode(
|
|
137
|
+
field.name,
|
|
138
|
+
type,
|
|
139
|
+
field.required,
|
|
140
|
+
buildAnnotations(field.label),
|
|
141
|
+
constraints
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
function canonicalizeBooleanField(field) {
|
|
145
|
+
const type = { kind: "primitive", primitiveKind: "boolean" };
|
|
146
|
+
return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
|
|
147
|
+
}
|
|
148
|
+
function canonicalizeStaticEnumField(field) {
|
|
149
|
+
const members = field.options.map((opt) => {
|
|
150
|
+
if (typeof opt === "string") {
|
|
151
|
+
return { value: opt };
|
|
152
|
+
}
|
|
153
|
+
return { value: opt.id, displayName: opt.label };
|
|
154
|
+
});
|
|
155
|
+
const type = { kind: "enum", members };
|
|
156
|
+
return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
|
|
157
|
+
}
|
|
158
|
+
function canonicalizeDynamicEnumField(field) {
|
|
159
|
+
const type = {
|
|
160
|
+
kind: "dynamic",
|
|
161
|
+
dynamicKind: "enum",
|
|
162
|
+
sourceKey: field.source,
|
|
163
|
+
parameterFields: field.params ? [...field.params] : []
|
|
164
|
+
};
|
|
165
|
+
return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
|
|
166
|
+
}
|
|
167
|
+
function canonicalizeDynamicSchemaField(field) {
|
|
168
|
+
const type = {
|
|
169
|
+
kind: "dynamic",
|
|
170
|
+
dynamicKind: "schema",
|
|
171
|
+
sourceKey: field.schemaSource,
|
|
172
|
+
parameterFields: []
|
|
173
|
+
};
|
|
174
|
+
return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
|
|
175
|
+
}
|
|
176
|
+
function canonicalizeArrayField(field) {
|
|
177
|
+
const itemProperties = buildObjectProperties(field.items);
|
|
178
|
+
const itemsType = {
|
|
179
|
+
kind: "object",
|
|
180
|
+
properties: itemProperties,
|
|
181
|
+
additionalProperties: true
|
|
182
|
+
};
|
|
183
|
+
const type = { kind: "array", items: itemsType };
|
|
184
|
+
const constraints = [];
|
|
185
|
+
if (field.minItems !== void 0) {
|
|
186
|
+
const c = {
|
|
187
|
+
kind: "constraint",
|
|
188
|
+
constraintKind: "minItems",
|
|
189
|
+
value: field.minItems,
|
|
190
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
191
|
+
};
|
|
192
|
+
constraints.push(c);
|
|
193
|
+
}
|
|
194
|
+
if (field.maxItems !== void 0) {
|
|
195
|
+
const c = {
|
|
196
|
+
kind: "constraint",
|
|
197
|
+
constraintKind: "maxItems",
|
|
198
|
+
value: field.maxItems,
|
|
199
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
200
|
+
};
|
|
201
|
+
constraints.push(c);
|
|
202
|
+
}
|
|
203
|
+
return buildFieldNode(
|
|
204
|
+
field.name,
|
|
205
|
+
type,
|
|
206
|
+
field.required,
|
|
207
|
+
buildAnnotations(field.label),
|
|
208
|
+
constraints
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
function canonicalizeObjectField(field) {
|
|
212
|
+
const properties = buildObjectProperties(field.properties);
|
|
213
|
+
const type = {
|
|
214
|
+
kind: "object",
|
|
215
|
+
properties,
|
|
216
|
+
additionalProperties: true
|
|
217
|
+
};
|
|
218
|
+
return buildFieldNode(field.name, type, field.required, buildAnnotations(field.label));
|
|
219
|
+
}
|
|
220
|
+
function canonicalizeGroup(g) {
|
|
221
|
+
return {
|
|
222
|
+
kind: "group",
|
|
223
|
+
label: g.label,
|
|
224
|
+
elements: canonicalizeElements(g.elements),
|
|
225
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function canonicalizeConditional(c) {
|
|
229
|
+
return {
|
|
230
|
+
kind: "conditional",
|
|
231
|
+
fieldName: c.field,
|
|
232
|
+
// Conditional values from the chain DSL are JSON-serializable primitives
|
|
233
|
+
// (strings, numbers, booleans) produced by the `is()` predicate helper.
|
|
234
|
+
value: assertJsonValue(c.value),
|
|
235
|
+
elements: canonicalizeElements(c.elements),
|
|
236
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function assertJsonValue(v) {
|
|
240
|
+
if (v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
241
|
+
return v;
|
|
242
|
+
}
|
|
243
|
+
if (Array.isArray(v)) {
|
|
244
|
+
return v.map(assertJsonValue);
|
|
245
|
+
}
|
|
246
|
+
if (typeof v === "object") {
|
|
247
|
+
const result = {};
|
|
248
|
+
for (const [key, val] of Object.entries(v)) {
|
|
249
|
+
result[key] = assertJsonValue(val);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
throw new TypeError(`Conditional value is not a valid JsonValue: ${typeof v}`);
|
|
254
|
+
}
|
|
255
|
+
function buildFieldNode(name, type, required, annotations, constraints = []) {
|
|
256
|
+
return {
|
|
257
|
+
kind: "field",
|
|
258
|
+
name,
|
|
259
|
+
type,
|
|
260
|
+
required: required === true,
|
|
261
|
+
constraints,
|
|
262
|
+
annotations,
|
|
263
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function buildAnnotations(label, placeholder) {
|
|
267
|
+
const annotations = [];
|
|
268
|
+
if (label !== void 0) {
|
|
269
|
+
const a = {
|
|
270
|
+
kind: "annotation",
|
|
271
|
+
annotationKind: "displayName",
|
|
272
|
+
value: label,
|
|
273
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
274
|
+
};
|
|
275
|
+
annotations.push(a);
|
|
276
|
+
}
|
|
277
|
+
if (placeholder !== void 0) {
|
|
278
|
+
const a = {
|
|
279
|
+
kind: "annotation",
|
|
280
|
+
annotationKind: "placeholder",
|
|
281
|
+
value: placeholder,
|
|
282
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
283
|
+
};
|
|
284
|
+
annotations.push(a);
|
|
285
|
+
}
|
|
286
|
+
return annotations;
|
|
287
|
+
}
|
|
288
|
+
function buildObjectProperties(elements, insideConditional = false) {
|
|
289
|
+
const properties = [];
|
|
290
|
+
for (const el of elements) {
|
|
291
|
+
if (isField(el)) {
|
|
292
|
+
const fieldNode = canonicalizeField(el);
|
|
293
|
+
properties.push({
|
|
294
|
+
name: fieldNode.name,
|
|
295
|
+
type: fieldNode.type,
|
|
296
|
+
// Fields inside a conditional branch are always optional in the
|
|
297
|
+
// data schema, regardless of their `required` flag — the condition
|
|
298
|
+
// may not be met, so the field may be absent.
|
|
299
|
+
optional: insideConditional || !fieldNode.required,
|
|
300
|
+
constraints: fieldNode.constraints,
|
|
301
|
+
annotations: fieldNode.annotations,
|
|
302
|
+
provenance: CHAIN_DSL_PROVENANCE
|
|
303
|
+
});
|
|
304
|
+
} else if (isGroup(el)) {
|
|
305
|
+
properties.push(...buildObjectProperties(el.elements, insideConditional));
|
|
306
|
+
} else if (isConditional(el)) {
|
|
307
|
+
properties.push(...buildObjectProperties(el.elements, true));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return properties;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/canonicalize/tsdoc-canonicalizer.ts
|
|
314
|
+
import { IR_VERSION as IR_VERSION2 } from "@formspec/core";
|
|
315
|
+
|
|
316
|
+
// src/json-schema/ir-generator.ts
|
|
317
|
+
function makeContext(options) {
|
|
318
|
+
const vendorPrefix = options?.vendorPrefix ?? "x-formspec";
|
|
319
|
+
if (!vendorPrefix.startsWith("x-")) {
|
|
320
|
+
throw new Error(
|
|
321
|
+
`Invalid vendorPrefix "${vendorPrefix}". Extension JSON Schema keywords must start with "x-".`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
defs: {},
|
|
326
|
+
extensionRegistry: options?.extensionRegistry,
|
|
327
|
+
vendorPrefix
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
function generateJsonSchemaFromIR(ir, options) {
|
|
331
|
+
const ctx = makeContext(options);
|
|
332
|
+
for (const [name, typeDef] of Object.entries(ir.typeRegistry)) {
|
|
333
|
+
ctx.defs[name] = generateTypeNode(typeDef.type, ctx);
|
|
334
|
+
if (typeDef.constraints && typeDef.constraints.length > 0) {
|
|
335
|
+
applyConstraints(ctx.defs[name], typeDef.constraints, ctx);
|
|
336
|
+
}
|
|
337
|
+
if (typeDef.annotations && typeDef.annotations.length > 0) {
|
|
338
|
+
applyAnnotations(ctx.defs[name], typeDef.annotations, ctx);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const properties = {};
|
|
342
|
+
const required = [];
|
|
343
|
+
collectFields(ir.elements, properties, required, ctx);
|
|
344
|
+
const uniqueRequired = [...new Set(required)];
|
|
345
|
+
const result = {
|
|
346
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
347
|
+
type: "object",
|
|
348
|
+
properties,
|
|
349
|
+
...uniqueRequired.length > 0 && { required: uniqueRequired }
|
|
350
|
+
};
|
|
351
|
+
if (ir.annotations && ir.annotations.length > 0) {
|
|
352
|
+
applyAnnotations(result, ir.annotations, ctx);
|
|
353
|
+
}
|
|
354
|
+
if (Object.keys(ctx.defs).length > 0) {
|
|
355
|
+
result.$defs = ctx.defs;
|
|
356
|
+
}
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
function collectFields(elements, properties, required, ctx) {
|
|
360
|
+
for (const element of elements) {
|
|
361
|
+
switch (element.kind) {
|
|
362
|
+
case "field":
|
|
363
|
+
properties[element.name] = generateFieldSchema(element, ctx);
|
|
364
|
+
if (element.required) {
|
|
365
|
+
required.push(element.name);
|
|
366
|
+
}
|
|
367
|
+
break;
|
|
368
|
+
case "group":
|
|
369
|
+
collectFields(element.elements, properties, required, ctx);
|
|
370
|
+
break;
|
|
371
|
+
case "conditional":
|
|
372
|
+
collectFields(element.elements, properties, required, ctx);
|
|
373
|
+
break;
|
|
374
|
+
default: {
|
|
375
|
+
const _exhaustive = element;
|
|
376
|
+
void _exhaustive;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function generateFieldSchema(field, ctx) {
|
|
382
|
+
const schema = generateTypeNode(field.type, ctx);
|
|
383
|
+
const itemStringSchema = schema.type === "array" && schema.items?.type === "string" ? schema.items : void 0;
|
|
384
|
+
const directConstraints = [];
|
|
385
|
+
const itemConstraints = [];
|
|
386
|
+
const pathConstraints = [];
|
|
387
|
+
for (const c of field.constraints) {
|
|
388
|
+
if (c.path) {
|
|
389
|
+
pathConstraints.push(c);
|
|
390
|
+
} else if (itemStringSchema !== void 0 && isStringItemConstraint(c)) {
|
|
391
|
+
itemConstraints.push(c);
|
|
392
|
+
} else {
|
|
393
|
+
directConstraints.push(c);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
applyConstraints(schema, directConstraints, ctx);
|
|
397
|
+
if (itemStringSchema !== void 0) {
|
|
398
|
+
applyConstraints(itemStringSchema, itemConstraints, ctx);
|
|
399
|
+
}
|
|
400
|
+
const rootAnnotations = [];
|
|
401
|
+
const itemAnnotations = [];
|
|
402
|
+
for (const annotation of field.annotations) {
|
|
403
|
+
if (itemStringSchema !== void 0 && annotation.annotationKind === "format") {
|
|
404
|
+
itemAnnotations.push(annotation);
|
|
405
|
+
} else {
|
|
406
|
+
rootAnnotations.push(annotation);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
applyAnnotations(schema, rootAnnotations, ctx);
|
|
410
|
+
if (itemStringSchema !== void 0) {
|
|
411
|
+
applyAnnotations(itemStringSchema, itemAnnotations, ctx);
|
|
412
|
+
}
|
|
413
|
+
if (pathConstraints.length === 0) {
|
|
414
|
+
return schema;
|
|
415
|
+
}
|
|
416
|
+
return applyPathTargetedConstraints(schema, pathConstraints, ctx);
|
|
417
|
+
}
|
|
418
|
+
function isStringItemConstraint(constraint) {
|
|
419
|
+
switch (constraint.constraintKind) {
|
|
420
|
+
case "minLength":
|
|
421
|
+
case "maxLength":
|
|
422
|
+
case "pattern":
|
|
423
|
+
return true;
|
|
424
|
+
default:
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function applyPathTargetedConstraints(schema, pathConstraints, ctx) {
|
|
429
|
+
if (schema.type === "array" && schema.items) {
|
|
430
|
+
schema.items = applyPathTargetedConstraints(schema.items, pathConstraints, ctx);
|
|
431
|
+
return schema;
|
|
432
|
+
}
|
|
433
|
+
const byTarget = /* @__PURE__ */ new Map();
|
|
434
|
+
for (const c of pathConstraints) {
|
|
435
|
+
const target = c.path?.segments[0];
|
|
436
|
+
if (!target) continue;
|
|
437
|
+
const group = byTarget.get(target) ?? [];
|
|
438
|
+
group.push(c);
|
|
439
|
+
byTarget.set(target, group);
|
|
440
|
+
}
|
|
441
|
+
const propertyOverrides = {};
|
|
442
|
+
for (const [target, constraints] of byTarget) {
|
|
443
|
+
const subSchema = {};
|
|
444
|
+
applyConstraints(subSchema, constraints, ctx);
|
|
445
|
+
propertyOverrides[target] = subSchema;
|
|
446
|
+
}
|
|
447
|
+
if (schema.$ref) {
|
|
448
|
+
const { $ref, ...rest } = schema;
|
|
449
|
+
const refPart = { $ref };
|
|
450
|
+
const overridePart = {
|
|
451
|
+
properties: propertyOverrides,
|
|
452
|
+
...rest
|
|
453
|
+
};
|
|
454
|
+
return { allOf: [refPart, overridePart] };
|
|
455
|
+
}
|
|
456
|
+
if (schema.type === "object" && schema.properties) {
|
|
457
|
+
const missingOverrides = {};
|
|
458
|
+
for (const [target, overrideSchema] of Object.entries(propertyOverrides)) {
|
|
459
|
+
if (schema.properties[target]) {
|
|
460
|
+
Object.assign(schema.properties[target], overrideSchema);
|
|
461
|
+
} else {
|
|
462
|
+
missingOverrides[target] = overrideSchema;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (Object.keys(missingOverrides).length === 0) {
|
|
466
|
+
return schema;
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
allOf: [schema, { properties: missingOverrides }]
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
if (schema.allOf) {
|
|
473
|
+
schema.allOf = [...schema.allOf, { properties: propertyOverrides }];
|
|
474
|
+
return schema;
|
|
475
|
+
}
|
|
476
|
+
return schema;
|
|
477
|
+
}
|
|
478
|
+
function generateTypeNode(type, ctx) {
|
|
479
|
+
switch (type.kind) {
|
|
480
|
+
case "primitive":
|
|
481
|
+
return generatePrimitiveType(type);
|
|
482
|
+
case "enum":
|
|
483
|
+
return generateEnumType(type);
|
|
484
|
+
case "array":
|
|
485
|
+
return generateArrayType(type, ctx);
|
|
486
|
+
case "object":
|
|
487
|
+
return generateObjectType(type, ctx);
|
|
488
|
+
case "record":
|
|
489
|
+
return generateRecordType(type, ctx);
|
|
490
|
+
case "union":
|
|
491
|
+
return generateUnionType(type, ctx);
|
|
492
|
+
case "reference":
|
|
493
|
+
return generateReferenceType(type);
|
|
494
|
+
case "dynamic":
|
|
495
|
+
return generateDynamicType(type);
|
|
496
|
+
case "custom":
|
|
497
|
+
return generateCustomType(type, ctx);
|
|
498
|
+
default: {
|
|
499
|
+
const _exhaustive = type;
|
|
500
|
+
return _exhaustive;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function generatePrimitiveType(type) {
|
|
505
|
+
return {
|
|
506
|
+
type: type.primitiveKind === "integer" || type.primitiveKind === "bigint" ? "integer" : type.primitiveKind
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
function generateEnumType(type) {
|
|
510
|
+
const hasDisplayNames = type.members.some((m) => m.displayName !== void 0);
|
|
511
|
+
if (hasDisplayNames) {
|
|
512
|
+
return {
|
|
513
|
+
oneOf: type.members.map((m) => {
|
|
514
|
+
const entry = { const: m.value };
|
|
515
|
+
if (m.displayName !== void 0) {
|
|
516
|
+
entry.title = m.displayName;
|
|
517
|
+
}
|
|
518
|
+
return entry;
|
|
519
|
+
})
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
return { enum: type.members.map((m) => m.value) };
|
|
523
|
+
}
|
|
524
|
+
function generateArrayType(type, ctx) {
|
|
525
|
+
return {
|
|
526
|
+
type: "array",
|
|
527
|
+
items: generateTypeNode(type.items, ctx)
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function generateObjectType(type, ctx) {
|
|
531
|
+
const properties = {};
|
|
532
|
+
const required = [];
|
|
533
|
+
for (const prop of type.properties) {
|
|
534
|
+
properties[prop.name] = generatePropertySchema(prop, ctx);
|
|
535
|
+
if (!prop.optional) {
|
|
536
|
+
required.push(prop.name);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
const schema = { type: "object", properties };
|
|
540
|
+
if (required.length > 0) {
|
|
541
|
+
schema.required = required;
|
|
542
|
+
}
|
|
543
|
+
if (!type.additionalProperties) {
|
|
544
|
+
schema.additionalProperties = false;
|
|
545
|
+
}
|
|
546
|
+
return schema;
|
|
547
|
+
}
|
|
548
|
+
function generateRecordType(type, ctx) {
|
|
549
|
+
return {
|
|
550
|
+
type: "object",
|
|
551
|
+
additionalProperties: generateTypeNode(type.valueType, ctx)
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function generatePropertySchema(prop, ctx) {
|
|
555
|
+
const schema = generateTypeNode(prop.type, ctx);
|
|
556
|
+
applyConstraints(schema, prop.constraints, ctx);
|
|
557
|
+
applyAnnotations(schema, prop.annotations, ctx);
|
|
558
|
+
return schema;
|
|
559
|
+
}
|
|
560
|
+
function generateUnionType(type, ctx) {
|
|
561
|
+
if (isBooleanUnion(type)) {
|
|
562
|
+
return { type: "boolean" };
|
|
563
|
+
}
|
|
564
|
+
if (isNullableUnion(type)) {
|
|
565
|
+
return {
|
|
566
|
+
oneOf: type.members.map((m) => generateTypeNode(m, ctx))
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
anyOf: type.members.map((m) => generateTypeNode(m, ctx))
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
function isBooleanUnion(type) {
|
|
574
|
+
if (type.members.length !== 2) return false;
|
|
575
|
+
const kinds = type.members.map((m) => m.kind);
|
|
576
|
+
return kinds.every((k) => k === "primitive") && type.members.every((m) => m.kind === "primitive" && m.primitiveKind === "boolean");
|
|
577
|
+
}
|
|
578
|
+
function isNullableUnion(type) {
|
|
579
|
+
if (type.members.length !== 2) return false;
|
|
580
|
+
const nullCount = type.members.filter(
|
|
581
|
+
(m) => m.kind === "primitive" && m.primitiveKind === "null"
|
|
582
|
+
).length;
|
|
583
|
+
return nullCount === 1;
|
|
584
|
+
}
|
|
585
|
+
function generateReferenceType(type) {
|
|
586
|
+
return { $ref: `#/$defs/${type.name}` };
|
|
587
|
+
}
|
|
588
|
+
function generateDynamicType(type) {
|
|
589
|
+
if (type.dynamicKind === "enum") {
|
|
590
|
+
const schema = {
|
|
591
|
+
type: "string",
|
|
592
|
+
"x-formspec-source": type.sourceKey
|
|
593
|
+
};
|
|
594
|
+
if (type.parameterFields.length > 0) {
|
|
595
|
+
schema["x-formspec-params"] = [...type.parameterFields];
|
|
596
|
+
}
|
|
597
|
+
return schema;
|
|
598
|
+
}
|
|
599
|
+
return {
|
|
600
|
+
type: "object",
|
|
601
|
+
additionalProperties: true,
|
|
602
|
+
"x-formspec-schemaSource": type.sourceKey
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function applyConstraints(schema, constraints, ctx) {
|
|
606
|
+
for (const constraint of constraints) {
|
|
607
|
+
switch (constraint.constraintKind) {
|
|
608
|
+
case "minimum":
|
|
609
|
+
schema.minimum = constraint.value;
|
|
610
|
+
break;
|
|
611
|
+
case "maximum":
|
|
612
|
+
schema.maximum = constraint.value;
|
|
613
|
+
break;
|
|
614
|
+
case "exclusiveMinimum":
|
|
615
|
+
schema.exclusiveMinimum = constraint.value;
|
|
616
|
+
break;
|
|
617
|
+
case "exclusiveMaximum":
|
|
618
|
+
schema.exclusiveMaximum = constraint.value;
|
|
619
|
+
break;
|
|
620
|
+
case "multipleOf": {
|
|
621
|
+
const { value } = constraint;
|
|
622
|
+
if (value === 1 && schema.type === "number") {
|
|
623
|
+
schema.type = "integer";
|
|
624
|
+
} else {
|
|
625
|
+
schema.multipleOf = value;
|
|
626
|
+
}
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
case "minLength":
|
|
630
|
+
schema.minLength = constraint.value;
|
|
631
|
+
break;
|
|
632
|
+
case "maxLength":
|
|
633
|
+
schema.maxLength = constraint.value;
|
|
634
|
+
break;
|
|
635
|
+
case "minItems":
|
|
636
|
+
schema.minItems = constraint.value;
|
|
637
|
+
break;
|
|
638
|
+
case "maxItems":
|
|
639
|
+
schema.maxItems = constraint.value;
|
|
640
|
+
break;
|
|
641
|
+
case "pattern":
|
|
642
|
+
schema.pattern = constraint.pattern;
|
|
643
|
+
break;
|
|
644
|
+
case "uniqueItems":
|
|
645
|
+
schema.uniqueItems = constraint.value;
|
|
646
|
+
break;
|
|
647
|
+
case "const":
|
|
648
|
+
schema.const = constraint.value;
|
|
649
|
+
break;
|
|
650
|
+
case "allowedMembers":
|
|
651
|
+
break;
|
|
652
|
+
case "custom":
|
|
653
|
+
applyCustomConstraint(schema, constraint, ctx);
|
|
654
|
+
break;
|
|
655
|
+
default: {
|
|
656
|
+
const _exhaustive = constraint;
|
|
657
|
+
void _exhaustive;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function applyAnnotations(schema, annotations, ctx) {
|
|
663
|
+
for (const annotation of annotations) {
|
|
664
|
+
switch (annotation.annotationKind) {
|
|
665
|
+
case "displayName":
|
|
666
|
+
schema.title = annotation.value;
|
|
667
|
+
break;
|
|
668
|
+
case "description":
|
|
669
|
+
schema.description = annotation.value;
|
|
670
|
+
break;
|
|
671
|
+
case "defaultValue":
|
|
672
|
+
schema.default = annotation.value;
|
|
673
|
+
break;
|
|
674
|
+
case "format":
|
|
675
|
+
schema.format = annotation.value;
|
|
676
|
+
break;
|
|
677
|
+
case "deprecated":
|
|
678
|
+
schema.deprecated = true;
|
|
679
|
+
if (annotation.message !== void 0 && annotation.message !== "") {
|
|
680
|
+
schema[`${ctx.vendorPrefix}-deprecation-description`] = annotation.message;
|
|
681
|
+
}
|
|
682
|
+
break;
|
|
683
|
+
case "placeholder":
|
|
684
|
+
break;
|
|
685
|
+
case "formatHint":
|
|
686
|
+
break;
|
|
687
|
+
case "custom":
|
|
688
|
+
applyCustomAnnotation(schema, annotation, ctx);
|
|
689
|
+
break;
|
|
690
|
+
default: {
|
|
691
|
+
const _exhaustive = annotation;
|
|
692
|
+
void _exhaustive;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function generateCustomType(type, ctx) {
|
|
698
|
+
const registration = ctx.extensionRegistry?.findType(type.typeId);
|
|
699
|
+
if (registration === void 0) {
|
|
700
|
+
throw new Error(
|
|
701
|
+
`Cannot generate JSON Schema for custom type "${type.typeId}" without a matching extension registration`
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
return registration.toJsonSchema(type.payload, ctx.vendorPrefix);
|
|
705
|
+
}
|
|
706
|
+
function applyCustomConstraint(schema, constraint, ctx) {
|
|
707
|
+
const registration = ctx.extensionRegistry?.findConstraint(constraint.constraintId);
|
|
708
|
+
if (registration === void 0) {
|
|
709
|
+
throw new Error(
|
|
710
|
+
`Cannot generate JSON Schema for custom constraint "${constraint.constraintId}" without a matching extension registration`
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
assignVendorPrefixedExtensionKeywords(
|
|
714
|
+
schema,
|
|
715
|
+
registration.toJsonSchema(constraint.payload, ctx.vendorPrefix),
|
|
716
|
+
ctx.vendorPrefix,
|
|
717
|
+
`custom constraint "${constraint.constraintId}"`
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
function applyCustomAnnotation(schema, annotation, ctx) {
|
|
721
|
+
const registration = ctx.extensionRegistry?.findAnnotation(annotation.annotationId);
|
|
722
|
+
if (registration === void 0) {
|
|
723
|
+
throw new Error(
|
|
724
|
+
`Cannot generate JSON Schema for custom annotation "${annotation.annotationId}" without a matching extension registration`
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
if (registration.toJsonSchema === void 0) {
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
assignVendorPrefixedExtensionKeywords(
|
|
731
|
+
schema,
|
|
732
|
+
registration.toJsonSchema(annotation.value, ctx.vendorPrefix),
|
|
733
|
+
ctx.vendorPrefix,
|
|
734
|
+
`custom annotation "${annotation.annotationId}"`
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
function assignVendorPrefixedExtensionKeywords(schema, extensionSchema, vendorPrefix, source) {
|
|
738
|
+
for (const [key, value] of Object.entries(extensionSchema)) {
|
|
739
|
+
if (!key.startsWith(`${vendorPrefix}-`)) {
|
|
740
|
+
throw new Error(
|
|
741
|
+
`Cannot apply ${source}: extension hooks may only emit "${vendorPrefix}-*" JSON Schema keywords`
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
schema[key] = value;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// src/json-schema/generator.ts
|
|
749
|
+
function generateJsonSchema(form, options) {
|
|
750
|
+
const ir = canonicalizeChainDSL(form);
|
|
751
|
+
return generateJsonSchemaFromIR(ir, options);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// src/ui-schema/schema.ts
|
|
755
|
+
import { z } from "zod";
|
|
756
|
+
var jsonPointerSchema = z.string();
|
|
757
|
+
var ruleEffectSchema = z.enum(["SHOW", "HIDE", "ENABLE", "DISABLE"]);
|
|
758
|
+
var uiSchemaElementTypeSchema = z.enum([
|
|
759
|
+
"Control",
|
|
760
|
+
"VerticalLayout",
|
|
761
|
+
"HorizontalLayout",
|
|
762
|
+
"Group",
|
|
763
|
+
"Categorization",
|
|
764
|
+
"Category",
|
|
765
|
+
"Label"
|
|
766
|
+
]);
|
|
767
|
+
var ruleConditionSchema = z.lazy(
|
|
768
|
+
() => z.object({
|
|
769
|
+
const: z.unknown().optional(),
|
|
770
|
+
enum: z.array(z.unknown()).readonly().optional(),
|
|
771
|
+
type: z.string().optional(),
|
|
772
|
+
not: ruleConditionSchema.optional(),
|
|
773
|
+
minimum: z.number().optional(),
|
|
774
|
+
maximum: z.number().optional(),
|
|
775
|
+
exclusiveMinimum: z.number().optional(),
|
|
776
|
+
exclusiveMaximum: z.number().optional(),
|
|
777
|
+
minLength: z.number().optional(),
|
|
778
|
+
properties: z.record(z.string(), ruleConditionSchema).optional(),
|
|
779
|
+
required: z.array(z.string()).optional(),
|
|
780
|
+
allOf: z.array(ruleConditionSchema).optional()
|
|
781
|
+
}).strict()
|
|
782
|
+
);
|
|
783
|
+
var schemaBasedConditionSchema = z.object({
|
|
784
|
+
scope: jsonPointerSchema,
|
|
785
|
+
schema: ruleConditionSchema
|
|
786
|
+
}).strict();
|
|
787
|
+
var ruleSchema = z.object({
|
|
788
|
+
effect: ruleEffectSchema,
|
|
789
|
+
condition: schemaBasedConditionSchema
|
|
790
|
+
}).strict();
|
|
791
|
+
var uiSchemaElementSchema = z.lazy(
|
|
792
|
+
() => z.union([
|
|
793
|
+
controlSchema,
|
|
794
|
+
verticalLayoutSchema,
|
|
795
|
+
horizontalLayoutSchema,
|
|
796
|
+
groupLayoutSchema,
|
|
797
|
+
categorizationSchema,
|
|
798
|
+
categorySchema,
|
|
799
|
+
labelElementSchema
|
|
800
|
+
])
|
|
801
|
+
);
|
|
802
|
+
var controlSchema = z.object({
|
|
803
|
+
type: z.literal("Control"),
|
|
804
|
+
scope: jsonPointerSchema,
|
|
805
|
+
label: z.union([z.string(), z.literal(false)]).optional(),
|
|
806
|
+
rule: ruleSchema.optional(),
|
|
807
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
808
|
+
}).passthrough();
|
|
809
|
+
var verticalLayoutSchema = z.lazy(
|
|
810
|
+
() => z.object({
|
|
811
|
+
type: z.literal("VerticalLayout"),
|
|
812
|
+
elements: z.array(uiSchemaElementSchema),
|
|
813
|
+
rule: ruleSchema.optional(),
|
|
814
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
815
|
+
}).passthrough()
|
|
816
|
+
);
|
|
817
|
+
var horizontalLayoutSchema = z.lazy(
|
|
818
|
+
() => z.object({
|
|
819
|
+
type: z.literal("HorizontalLayout"),
|
|
820
|
+
elements: z.array(uiSchemaElementSchema),
|
|
821
|
+
rule: ruleSchema.optional(),
|
|
822
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
823
|
+
}).passthrough()
|
|
824
|
+
);
|
|
825
|
+
var groupLayoutSchema = z.lazy(
|
|
826
|
+
() => z.object({
|
|
827
|
+
type: z.literal("Group"),
|
|
828
|
+
label: z.string(),
|
|
829
|
+
elements: z.array(uiSchemaElementSchema),
|
|
830
|
+
rule: ruleSchema.optional(),
|
|
831
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
832
|
+
}).passthrough()
|
|
833
|
+
);
|
|
834
|
+
var categorySchema = z.lazy(
|
|
835
|
+
() => z.object({
|
|
836
|
+
type: z.literal("Category"),
|
|
837
|
+
label: z.string(),
|
|
838
|
+
elements: z.array(uiSchemaElementSchema),
|
|
839
|
+
rule: ruleSchema.optional(),
|
|
840
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
841
|
+
}).passthrough()
|
|
842
|
+
);
|
|
843
|
+
var categorizationSchema = z.lazy(
|
|
844
|
+
() => z.object({
|
|
845
|
+
type: z.literal("Categorization"),
|
|
846
|
+
elements: z.array(categorySchema),
|
|
847
|
+
label: z.string().optional(),
|
|
848
|
+
rule: ruleSchema.optional(),
|
|
849
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
850
|
+
}).passthrough()
|
|
851
|
+
);
|
|
852
|
+
var labelElementSchema = z.object({
|
|
853
|
+
type: z.literal("Label"),
|
|
854
|
+
text: z.string(),
|
|
855
|
+
rule: ruleSchema.optional(),
|
|
856
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
857
|
+
}).passthrough();
|
|
858
|
+
var uiSchema = z.lazy(
|
|
859
|
+
() => z.union([verticalLayoutSchema, horizontalLayoutSchema, groupLayoutSchema, categorizationSchema])
|
|
860
|
+
);
|
|
861
|
+
|
|
862
|
+
// src/ui-schema/ir-generator.ts
|
|
863
|
+
import { z as z2 } from "zod";
|
|
864
|
+
function parseOrThrow(schema, value, label) {
|
|
865
|
+
try {
|
|
866
|
+
return schema.parse(value);
|
|
867
|
+
} catch (error) {
|
|
868
|
+
if (error instanceof z2.ZodError) {
|
|
869
|
+
throw new Error(
|
|
870
|
+
`Generated ${label} failed validation:
|
|
871
|
+
${error.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n")}`
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
throw error;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
function fieldToScope(fieldName) {
|
|
878
|
+
return `#/properties/${fieldName}`;
|
|
879
|
+
}
|
|
880
|
+
function createShowRule(fieldName, value) {
|
|
881
|
+
return {
|
|
882
|
+
effect: "SHOW",
|
|
883
|
+
condition: {
|
|
884
|
+
scope: fieldToScope(fieldName),
|
|
885
|
+
schema: { const: value }
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
function flattenConditionSchema(scope, schema) {
|
|
890
|
+
if (schema.allOf === void 0) {
|
|
891
|
+
if (scope === "#") {
|
|
892
|
+
return [schema];
|
|
893
|
+
}
|
|
894
|
+
const fieldName = scope.replace("#/properties/", "");
|
|
895
|
+
return [
|
|
896
|
+
{
|
|
897
|
+
properties: {
|
|
898
|
+
[fieldName]: schema
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
];
|
|
902
|
+
}
|
|
903
|
+
return schema.allOf.flatMap((member) => flattenConditionSchema(scope, member));
|
|
904
|
+
}
|
|
905
|
+
function combineRules(parentRule, childRule) {
|
|
906
|
+
return {
|
|
907
|
+
effect: "SHOW",
|
|
908
|
+
condition: {
|
|
909
|
+
scope: "#",
|
|
910
|
+
schema: {
|
|
911
|
+
allOf: [
|
|
912
|
+
...flattenConditionSchema(parentRule.condition.scope, parentRule.condition.schema),
|
|
913
|
+
...flattenConditionSchema(childRule.condition.scope, childRule.condition.schema)
|
|
914
|
+
]
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
function fieldNodeToControl(field, parentRule) {
|
|
920
|
+
const displayNameAnnotation = field.annotations.find((a) => a.annotationKind === "displayName");
|
|
921
|
+
const placeholderAnnotation = field.annotations.find((a) => a.annotationKind === "placeholder");
|
|
922
|
+
const control = {
|
|
923
|
+
type: "Control",
|
|
924
|
+
scope: fieldToScope(field.name),
|
|
925
|
+
...displayNameAnnotation !== void 0 && { label: displayNameAnnotation.value },
|
|
926
|
+
...placeholderAnnotation !== void 0 && {
|
|
927
|
+
options: { placeholder: placeholderAnnotation.value }
|
|
928
|
+
},
|
|
929
|
+
...parentRule !== void 0 && { rule: parentRule }
|
|
930
|
+
};
|
|
931
|
+
return control;
|
|
932
|
+
}
|
|
933
|
+
function groupNodeToLayout(group, parentRule) {
|
|
934
|
+
return {
|
|
935
|
+
type: "Group",
|
|
936
|
+
label: group.label,
|
|
937
|
+
elements: irElementsToUiSchema(group.elements, parentRule),
|
|
938
|
+
...parentRule !== void 0 && { rule: parentRule }
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
function irElementsToUiSchema(elements, parentRule) {
|
|
942
|
+
const result = [];
|
|
943
|
+
for (const element of elements) {
|
|
944
|
+
switch (element.kind) {
|
|
945
|
+
case "field": {
|
|
946
|
+
result.push(fieldNodeToControl(element, parentRule));
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
case "group": {
|
|
950
|
+
result.push(groupNodeToLayout(element, parentRule));
|
|
951
|
+
break;
|
|
952
|
+
}
|
|
953
|
+
case "conditional": {
|
|
954
|
+
const newRule = createShowRule(element.fieldName, element.value);
|
|
955
|
+
const combinedRule = parentRule !== void 0 ? combineRules(parentRule, newRule) : newRule;
|
|
956
|
+
const childElements = irElementsToUiSchema(element.elements, combinedRule);
|
|
957
|
+
result.push(...childElements);
|
|
958
|
+
break;
|
|
959
|
+
}
|
|
960
|
+
default: {
|
|
961
|
+
const _exhaustive = element;
|
|
962
|
+
void _exhaustive;
|
|
963
|
+
throw new Error("Unhandled IR element kind");
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return result;
|
|
968
|
+
}
|
|
969
|
+
function generateUiSchemaFromIR(ir) {
|
|
970
|
+
const result = {
|
|
971
|
+
type: "VerticalLayout",
|
|
972
|
+
elements: irElementsToUiSchema(ir.elements)
|
|
973
|
+
};
|
|
974
|
+
return parseOrThrow(uiSchema, result, "UI Schema");
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
// src/ui-schema/generator.ts
|
|
978
|
+
function generateUiSchema(form) {
|
|
979
|
+
const ir = canonicalizeChainDSL(form);
|
|
980
|
+
return generateUiSchemaFromIR(ir);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// src/json-schema/types.ts
|
|
984
|
+
function setSchemaExtension(schema, key, value) {
|
|
985
|
+
schema[key] = value;
|
|
986
|
+
}
|
|
987
|
+
function getSchemaExtension(schema, key) {
|
|
988
|
+
return schema[key];
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// src/extensions/registry.ts
|
|
992
|
+
function createExtensionRegistry(extensions) {
|
|
993
|
+
const typeMap = /* @__PURE__ */ new Map();
|
|
994
|
+
const typeNameMap = /* @__PURE__ */ new Map();
|
|
995
|
+
const constraintMap = /* @__PURE__ */ new Map();
|
|
996
|
+
const constraintTagMap = /* @__PURE__ */ new Map();
|
|
997
|
+
const builtinBroadeningMap = /* @__PURE__ */ new Map();
|
|
998
|
+
const annotationMap = /* @__PURE__ */ new Map();
|
|
999
|
+
for (const ext of extensions) {
|
|
1000
|
+
if (ext.types !== void 0) {
|
|
1001
|
+
for (const type of ext.types) {
|
|
1002
|
+
const qualifiedId = `${ext.extensionId}/${type.typeName}`;
|
|
1003
|
+
if (typeMap.has(qualifiedId)) {
|
|
1004
|
+
throw new Error(`Duplicate custom type ID: "${qualifiedId}"`);
|
|
1005
|
+
}
|
|
1006
|
+
typeMap.set(qualifiedId, type);
|
|
1007
|
+
for (const sourceTypeName of type.tsTypeNames ?? [type.typeName]) {
|
|
1008
|
+
if (typeNameMap.has(sourceTypeName)) {
|
|
1009
|
+
throw new Error(`Duplicate custom type source name: "${sourceTypeName}"`);
|
|
1010
|
+
}
|
|
1011
|
+
typeNameMap.set(sourceTypeName, {
|
|
1012
|
+
extensionId: ext.extensionId,
|
|
1013
|
+
registration: type
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
if (type.builtinConstraintBroadenings !== void 0) {
|
|
1017
|
+
for (const broadening of type.builtinConstraintBroadenings) {
|
|
1018
|
+
const key = `${qualifiedId}:${broadening.tagName}`;
|
|
1019
|
+
if (builtinBroadeningMap.has(key)) {
|
|
1020
|
+
throw new Error(`Duplicate built-in constraint broadening: "${key}"`);
|
|
1021
|
+
}
|
|
1022
|
+
builtinBroadeningMap.set(key, {
|
|
1023
|
+
extensionId: ext.extensionId,
|
|
1024
|
+
registration: broadening
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (ext.constraints !== void 0) {
|
|
1031
|
+
for (const constraint of ext.constraints) {
|
|
1032
|
+
const qualifiedId = `${ext.extensionId}/${constraint.constraintName}`;
|
|
1033
|
+
if (constraintMap.has(qualifiedId)) {
|
|
1034
|
+
throw new Error(`Duplicate custom constraint ID: "${qualifiedId}"`);
|
|
1035
|
+
}
|
|
1036
|
+
constraintMap.set(qualifiedId, constraint);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
if (ext.constraintTags !== void 0) {
|
|
1040
|
+
for (const tag of ext.constraintTags) {
|
|
1041
|
+
if (constraintTagMap.has(tag.tagName)) {
|
|
1042
|
+
throw new Error(`Duplicate custom constraint tag: "@${tag.tagName}"`);
|
|
1043
|
+
}
|
|
1044
|
+
constraintTagMap.set(tag.tagName, {
|
|
1045
|
+
extensionId: ext.extensionId,
|
|
1046
|
+
registration: tag
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
if (ext.annotations !== void 0) {
|
|
1051
|
+
for (const annotation of ext.annotations) {
|
|
1052
|
+
const qualifiedId = `${ext.extensionId}/${annotation.annotationName}`;
|
|
1053
|
+
if (annotationMap.has(qualifiedId)) {
|
|
1054
|
+
throw new Error(`Duplicate custom annotation ID: "${qualifiedId}"`);
|
|
1055
|
+
}
|
|
1056
|
+
annotationMap.set(qualifiedId, annotation);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return {
|
|
1061
|
+
extensions,
|
|
1062
|
+
findType: (typeId) => typeMap.get(typeId),
|
|
1063
|
+
findTypeByName: (typeName) => typeNameMap.get(typeName),
|
|
1064
|
+
findConstraint: (constraintId) => constraintMap.get(constraintId),
|
|
1065
|
+
findConstraintTag: (tagName) => constraintTagMap.get(tagName),
|
|
1066
|
+
findBuiltinConstraintBroadening: (typeId, tagName) => builtinBroadeningMap.get(`${typeId}:${tagName}`),
|
|
1067
|
+
findAnnotation: (annotationId) => annotationMap.get(annotationId)
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// src/json-schema/schema.ts
|
|
1072
|
+
import { z as z3 } from "zod";
|
|
1073
|
+
var jsonSchemaTypeSchema = z3.enum([
|
|
1074
|
+
"string",
|
|
1075
|
+
"number",
|
|
1076
|
+
"integer",
|
|
1077
|
+
"boolean",
|
|
1078
|
+
"object",
|
|
1079
|
+
"array",
|
|
1080
|
+
"null"
|
|
1081
|
+
]);
|
|
1082
|
+
var jsonSchema7Schema = z3.lazy(
|
|
1083
|
+
() => z3.object({
|
|
1084
|
+
$schema: z3.string().optional(),
|
|
1085
|
+
$id: z3.string().optional(),
|
|
1086
|
+
$ref: z3.string().optional(),
|
|
1087
|
+
// Metadata
|
|
1088
|
+
title: z3.string().optional(),
|
|
1089
|
+
description: z3.string().optional(),
|
|
1090
|
+
deprecated: z3.boolean().optional(),
|
|
1091
|
+
// Type
|
|
1092
|
+
type: z3.union([jsonSchemaTypeSchema, z3.array(jsonSchemaTypeSchema)]).optional(),
|
|
1093
|
+
// String validation
|
|
1094
|
+
minLength: z3.number().optional(),
|
|
1095
|
+
maxLength: z3.number().optional(),
|
|
1096
|
+
pattern: z3.string().optional(),
|
|
1097
|
+
// Number validation
|
|
1098
|
+
minimum: z3.number().optional(),
|
|
1099
|
+
maximum: z3.number().optional(),
|
|
1100
|
+
exclusiveMinimum: z3.number().optional(),
|
|
1101
|
+
exclusiveMaximum: z3.number().optional(),
|
|
1102
|
+
// Enum
|
|
1103
|
+
enum: z3.array(z3.union([z3.string(), z3.number(), z3.boolean(), z3.null()])).readonly().optional(),
|
|
1104
|
+
const: z3.union([z3.string(), z3.number(), z3.boolean(), z3.null()]).optional(),
|
|
1105
|
+
// Object
|
|
1106
|
+
properties: z3.record(z3.string(), jsonSchema7Schema).optional(),
|
|
1107
|
+
required: z3.array(z3.string()).optional(),
|
|
1108
|
+
additionalProperties: z3.union([z3.boolean(), jsonSchema7Schema]).optional(),
|
|
1109
|
+
// Array
|
|
1110
|
+
items: z3.union([jsonSchema7Schema, z3.array(jsonSchema7Schema)]).optional(),
|
|
1111
|
+
minItems: z3.number().optional(),
|
|
1112
|
+
maxItems: z3.number().optional(),
|
|
1113
|
+
// Composition
|
|
1114
|
+
allOf: z3.array(jsonSchema7Schema).optional(),
|
|
1115
|
+
anyOf: z3.array(jsonSchema7Schema).optional(),
|
|
1116
|
+
oneOf: z3.array(jsonSchema7Schema).optional(),
|
|
1117
|
+
not: jsonSchema7Schema.optional(),
|
|
1118
|
+
// Conditional
|
|
1119
|
+
if: jsonSchema7Schema.optional(),
|
|
1120
|
+
then: jsonSchema7Schema.optional(),
|
|
1121
|
+
else: jsonSchema7Schema.optional(),
|
|
1122
|
+
// Format
|
|
1123
|
+
format: z3.string().optional(),
|
|
1124
|
+
// Default
|
|
1125
|
+
default: z3.unknown().optional(),
|
|
1126
|
+
// FormSpec extensions
|
|
1127
|
+
"x-formspec-source": z3.string().optional(),
|
|
1128
|
+
"x-formspec-params": z3.array(z3.string()).readonly().optional(),
|
|
1129
|
+
"x-formspec-schemaSource": z3.string().optional()
|
|
1130
|
+
}).passthrough()
|
|
1131
|
+
);
|
|
1132
|
+
|
|
1133
|
+
// src/validate/constraint-validator.ts
|
|
1134
|
+
import {
|
|
1135
|
+
analyzeConstraintTargets
|
|
1136
|
+
} from "@formspec/analysis";
|
|
1137
|
+
function validateFieldNode(ctx, field) {
|
|
1138
|
+
const analysis = analyzeConstraintTargets(
|
|
1139
|
+
field.name,
|
|
1140
|
+
field.type,
|
|
1141
|
+
field.constraints,
|
|
1142
|
+
ctx.typeRegistry,
|
|
1143
|
+
ctx.extensionRegistry === void 0 ? void 0 : {
|
|
1144
|
+
extensionRegistry: ctx.extensionRegistry
|
|
1145
|
+
}
|
|
1146
|
+
);
|
|
1147
|
+
ctx.diagnostics.push(...analysis.diagnostics);
|
|
1148
|
+
if (field.type.kind === "object") {
|
|
1149
|
+
for (const property of field.type.properties) {
|
|
1150
|
+
validateObjectProperty(ctx, field.name, property);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
function validateObjectProperty(ctx, parentName, property) {
|
|
1155
|
+
const qualifiedName = `${parentName}.${property.name}`;
|
|
1156
|
+
const analysis = analyzeConstraintTargets(
|
|
1157
|
+
qualifiedName,
|
|
1158
|
+
property.type,
|
|
1159
|
+
property.constraints,
|
|
1160
|
+
ctx.typeRegistry,
|
|
1161
|
+
ctx.extensionRegistry === void 0 ? void 0 : {
|
|
1162
|
+
extensionRegistry: ctx.extensionRegistry
|
|
1163
|
+
}
|
|
1164
|
+
);
|
|
1165
|
+
ctx.diagnostics.push(...analysis.diagnostics);
|
|
1166
|
+
if (property.type.kind === "object") {
|
|
1167
|
+
for (const nestedProperty of property.type.properties) {
|
|
1168
|
+
validateObjectProperty(ctx, qualifiedName, nestedProperty);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function validateElement(ctx, element) {
|
|
1173
|
+
switch (element.kind) {
|
|
1174
|
+
case "field":
|
|
1175
|
+
validateFieldNode(ctx, element);
|
|
1176
|
+
break;
|
|
1177
|
+
case "group":
|
|
1178
|
+
for (const child of element.elements) {
|
|
1179
|
+
validateElement(ctx, child);
|
|
1180
|
+
}
|
|
1181
|
+
break;
|
|
1182
|
+
case "conditional":
|
|
1183
|
+
for (const child of element.elements) {
|
|
1184
|
+
validateElement(ctx, child);
|
|
1185
|
+
}
|
|
1186
|
+
break;
|
|
1187
|
+
default: {
|
|
1188
|
+
const exhaustive = element;
|
|
1189
|
+
throw new Error(`Unhandled element kind: ${String(exhaustive)}`);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
function validateIR(ir, options) {
|
|
1194
|
+
const ctx = {
|
|
1195
|
+
diagnostics: [],
|
|
1196
|
+
extensionRegistry: options?.extensionRegistry,
|
|
1197
|
+
typeRegistry: ir.typeRegistry
|
|
1198
|
+
};
|
|
1199
|
+
for (const element of ir.elements) {
|
|
1200
|
+
validateElement(ctx, element);
|
|
1201
|
+
}
|
|
1202
|
+
return {
|
|
1203
|
+
diagnostics: ctx.diagnostics,
|
|
1204
|
+
valid: ctx.diagnostics.every((diagnostic) => diagnostic.severity !== "error")
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// src/browser.ts
|
|
1209
|
+
function buildFormSchemas(form, options) {
|
|
1210
|
+
return {
|
|
1211
|
+
jsonSchema: generateJsonSchema(form, options),
|
|
1212
|
+
uiSchema: generateUiSchema(form)
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
export {
|
|
1216
|
+
buildFormSchemas,
|
|
1217
|
+
canonicalizeChainDSL,
|
|
1218
|
+
categorizationSchema,
|
|
1219
|
+
categorySchema,
|
|
1220
|
+
controlSchema,
|
|
1221
|
+
createExtensionRegistry,
|
|
1222
|
+
generateJsonSchema,
|
|
1223
|
+
generateJsonSchemaFromIR,
|
|
1224
|
+
generateUiSchema,
|
|
1225
|
+
getSchemaExtension,
|
|
1226
|
+
groupLayoutSchema,
|
|
1227
|
+
horizontalLayoutSchema,
|
|
1228
|
+
jsonSchema7Schema,
|
|
1229
|
+
jsonSchemaTypeSchema,
|
|
1230
|
+
labelElementSchema,
|
|
1231
|
+
ruleConditionSchema,
|
|
1232
|
+
ruleEffectSchema,
|
|
1233
|
+
ruleSchema,
|
|
1234
|
+
schemaBasedConditionSchema,
|
|
1235
|
+
setSchemaExtension,
|
|
1236
|
+
uiSchemaElementSchema,
|
|
1237
|
+
uiSchemaElementTypeSchema,
|
|
1238
|
+
uiSchema as uiSchemaSchema,
|
|
1239
|
+
validateIR,
|
|
1240
|
+
verticalLayoutSchema
|
|
1241
|
+
};
|
|
1242
|
+
//# sourceMappingURL=browser.js.map
|