@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/build.d.ts
ADDED
|
@@ -0,0 +1,996 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@formspec/build` - Build tools for FormSpec
|
|
3
|
+
*
|
|
4
|
+
* This package provides generators to compile FormSpec forms into:
|
|
5
|
+
* - JSON Schema 2020-12 (for validation)
|
|
6
|
+
* - JSON Forms UI Schema (for rendering)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { buildFormSchemas } from "@formspec/build";
|
|
11
|
+
* import { formspec, field, group } from "@formspec/dsl";
|
|
12
|
+
*
|
|
13
|
+
* const form = formspec(
|
|
14
|
+
* group("Customer",
|
|
15
|
+
* field.text("name", { label: "Name", required: true }),
|
|
16
|
+
* field.text("email", { label: "Email" }),
|
|
17
|
+
* ),
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* const { jsonSchema, uiSchema } = buildFormSchemas(form);
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { BuiltinConstraintBroadeningRegistration } from '@formspec/core';
|
|
27
|
+
import type { ConstraintTagRegistration } from '@formspec/core';
|
|
28
|
+
import type { CustomAnnotationRegistration } from '@formspec/core';
|
|
29
|
+
import type { CustomConstraintRegistration } from '@formspec/core';
|
|
30
|
+
import type { CustomTypeRegistration } from '@formspec/core';
|
|
31
|
+
import type { ExtensionDefinition } from '@formspec/core';
|
|
32
|
+
import type { FormElement } from '@formspec/core';
|
|
33
|
+
import type { FormIR } from '@formspec/core';
|
|
34
|
+
import type { FormSpec } from '@formspec/core';
|
|
35
|
+
import type { JsonValue } from '@formspec/core';
|
|
36
|
+
import { z } from 'zod';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Builds both JSON Schema and UI Schema from a FormSpec.
|
|
40
|
+
*
|
|
41
|
+
* This is a convenience function that combines `generateJsonSchema`
|
|
42
|
+
* and `generateUiSchema`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const form = formspec(
|
|
47
|
+
* field.text("name", { required: true }),
|
|
48
|
+
* field.number("age", { min: 0 }),
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* const { jsonSchema, uiSchema } = buildFormSchemas(form);
|
|
52
|
+
*
|
|
53
|
+
* // Use with JSON Forms renderer
|
|
54
|
+
* <JsonForms
|
|
55
|
+
* schema={jsonSchema}
|
|
56
|
+
* uischema={uiSchema}
|
|
57
|
+
* data={formData}
|
|
58
|
+
* renderers={materialRenderers}
|
|
59
|
+
* />
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param form - The FormSpec to build schemas from
|
|
63
|
+
* @returns Object containing both jsonSchema and uiSchema
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildFormSchemas<E extends readonly FormElement[]>(form: FormSpec<E>, options?: BuildFormSchemasOptions): BuildResult;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Options for building schemas from a FormSpec.
|
|
69
|
+
*
|
|
70
|
+
* Currently identical to `GenerateJsonSchemaOptions`. Defined separately so the
|
|
71
|
+
* Chain DSL surface can grow independently in the future if needed.
|
|
72
|
+
*/
|
|
73
|
+
export declare type BuildFormSchemasOptions = GenerateJsonSchemaOptions;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Builds JSON Schema and UI Schema from a TSDoc-derived model with ChainDSL
|
|
77
|
+
* field overlays.
|
|
78
|
+
*
|
|
79
|
+
* Overlays are matched by field name. The static model wins for structure,
|
|
80
|
+
* ordering, and constraints; ChainDSL overlays may contribute dynamic runtime
|
|
81
|
+
* field metadata such as dynamic enum or dynamic schema keywords, and may fill
|
|
82
|
+
* in missing annotations.
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildMixedAuthoringSchemas(options: BuildMixedAuthoringSchemasOptions): MixedAuthoringSchemas;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Options for generating mixed-authoring schemas.
|
|
88
|
+
*
|
|
89
|
+
* The `typeName` can resolve to a class, interface, or object type alias, just
|
|
90
|
+
* like `generateSchemas()`.
|
|
91
|
+
*/
|
|
92
|
+
export declare interface BuildMixedAuthoringSchemasOptions extends GenerateJsonSchemaFromIROptions {
|
|
93
|
+
/** Path to the TypeScript source file. */
|
|
94
|
+
readonly filePath: string;
|
|
95
|
+
/** Name of the class, interface, or type alias to analyze. */
|
|
96
|
+
readonly typeName: string;
|
|
97
|
+
/** ChainDSL overlays to apply to the static model. Groups and conditionals are flattened by field name. */
|
|
98
|
+
readonly overlays: FormSpec<readonly FormElement[]>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Result of building form schemas.
|
|
103
|
+
*/
|
|
104
|
+
export declare interface BuildResult {
|
|
105
|
+
/** JSON Schema 2020-12 for validation */
|
|
106
|
+
readonly jsonSchema: JsonSchema2020;
|
|
107
|
+
/** JSON Forms UI Schema for rendering */
|
|
108
|
+
readonly uiSchema: UISchema;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A Categorization element (tab-based layout).
|
|
113
|
+
*/
|
|
114
|
+
export declare interface Categorization {
|
|
115
|
+
type: "Categorization";
|
|
116
|
+
elements: Category[];
|
|
117
|
+
label?: string | undefined;
|
|
118
|
+
rule?: Rule | undefined;
|
|
119
|
+
options?: Record<string, unknown> | undefined;
|
|
120
|
+
[k: string]: unknown;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export declare const categorizationSchema: z.ZodType<Categorization>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A Category element, used inside a Categorization layout.
|
|
127
|
+
*/
|
|
128
|
+
export declare interface Category {
|
|
129
|
+
type: "Category";
|
|
130
|
+
label: string;
|
|
131
|
+
elements: UISchemaElement[];
|
|
132
|
+
rule?: Rule | undefined;
|
|
133
|
+
options?: Record<string, unknown> | undefined;
|
|
134
|
+
[k: string]: unknown;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export declare const categorySchema: z.ZodType<Category>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Generated schemas for a class.
|
|
141
|
+
*/
|
|
142
|
+
export declare interface ClassSchemas {
|
|
143
|
+
/** JSON Schema 2020-12 for validation */
|
|
144
|
+
jsonSchema: JsonSchema2020;
|
|
145
|
+
/** JSON Forms UI Schema for rendering */
|
|
146
|
+
uiSchema: UISchema;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* A Control element that binds to a JSON Schema property.
|
|
151
|
+
*/
|
|
152
|
+
export declare type ControlElement = z.infer<typeof controlSchema>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Zod schema for a Control element.
|
|
156
|
+
*/
|
|
157
|
+
export declare const controlSchema: z.ZodObject<{
|
|
158
|
+
type: z.ZodLiteral<"Control">;
|
|
159
|
+
scope: z.ZodString;
|
|
160
|
+
label: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>>;
|
|
161
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
162
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
163
|
+
condition: z.ZodObject<{
|
|
164
|
+
scope: z.ZodString;
|
|
165
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
166
|
+
}, "strict", z.ZodTypeAny, {
|
|
167
|
+
schema: RuleConditionSchema;
|
|
168
|
+
scope: string;
|
|
169
|
+
}, {
|
|
170
|
+
schema: RuleConditionSchema;
|
|
171
|
+
scope: string;
|
|
172
|
+
}>;
|
|
173
|
+
}, "strict", z.ZodTypeAny, {
|
|
174
|
+
condition: {
|
|
175
|
+
schema: RuleConditionSchema;
|
|
176
|
+
scope: string;
|
|
177
|
+
};
|
|
178
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
179
|
+
}, {
|
|
180
|
+
condition: {
|
|
181
|
+
schema: RuleConditionSchema;
|
|
182
|
+
scope: string;
|
|
183
|
+
};
|
|
184
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
185
|
+
}>>;
|
|
186
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
187
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
188
|
+
type: z.ZodLiteral<"Control">;
|
|
189
|
+
scope: z.ZodString;
|
|
190
|
+
label: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>>;
|
|
191
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
192
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
193
|
+
condition: z.ZodObject<{
|
|
194
|
+
scope: z.ZodString;
|
|
195
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
196
|
+
}, "strict", z.ZodTypeAny, {
|
|
197
|
+
schema: RuleConditionSchema;
|
|
198
|
+
scope: string;
|
|
199
|
+
}, {
|
|
200
|
+
schema: RuleConditionSchema;
|
|
201
|
+
scope: string;
|
|
202
|
+
}>;
|
|
203
|
+
}, "strict", z.ZodTypeAny, {
|
|
204
|
+
condition: {
|
|
205
|
+
schema: RuleConditionSchema;
|
|
206
|
+
scope: string;
|
|
207
|
+
};
|
|
208
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
209
|
+
}, {
|
|
210
|
+
condition: {
|
|
211
|
+
schema: RuleConditionSchema;
|
|
212
|
+
scope: string;
|
|
213
|
+
};
|
|
214
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
215
|
+
}>>;
|
|
216
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
217
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
218
|
+
type: z.ZodLiteral<"Control">;
|
|
219
|
+
scope: z.ZodString;
|
|
220
|
+
label: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>>;
|
|
221
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
222
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
223
|
+
condition: z.ZodObject<{
|
|
224
|
+
scope: z.ZodString;
|
|
225
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
226
|
+
}, "strict", z.ZodTypeAny, {
|
|
227
|
+
schema: RuleConditionSchema;
|
|
228
|
+
scope: string;
|
|
229
|
+
}, {
|
|
230
|
+
schema: RuleConditionSchema;
|
|
231
|
+
scope: string;
|
|
232
|
+
}>;
|
|
233
|
+
}, "strict", z.ZodTypeAny, {
|
|
234
|
+
condition: {
|
|
235
|
+
schema: RuleConditionSchema;
|
|
236
|
+
scope: string;
|
|
237
|
+
};
|
|
238
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
239
|
+
}, {
|
|
240
|
+
condition: {
|
|
241
|
+
schema: RuleConditionSchema;
|
|
242
|
+
scope: string;
|
|
243
|
+
};
|
|
244
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
245
|
+
}>>;
|
|
246
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
247
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Creates an extension registry from a list of extension definitions.
|
|
251
|
+
*
|
|
252
|
+
* The registry indexes all types, constraints, and annotations by their
|
|
253
|
+
* fully-qualified IDs (`<extensionId>/<name>`) for O(1) lookup during
|
|
254
|
+
* generation and validation.
|
|
255
|
+
*
|
|
256
|
+
* @param extensions - The extension definitions to register.
|
|
257
|
+
* @returns An {@link ExtensionRegistry} instance.
|
|
258
|
+
* @throws If duplicate type/constraint/annotation IDs are detected across extensions.
|
|
259
|
+
*/
|
|
260
|
+
export declare function createExtensionRegistry(extensions: readonly ExtensionDefinition[]): ExtensionRegistry;
|
|
261
|
+
|
|
262
|
+
/** JSON Schema with FormSpec extension properties for arbitrary x-formspec-* keys. */
|
|
263
|
+
export declare type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* A registry of extensions that provides lookup by fully-qualified ID.
|
|
267
|
+
*
|
|
268
|
+
* Type IDs follow the format: `<extensionId>/<typeName>`
|
|
269
|
+
* Constraint IDs follow the format: `<extensionId>/<constraintName>`
|
|
270
|
+
* Annotation IDs follow the format: `<extensionId>/<annotationName>`
|
|
271
|
+
*/
|
|
272
|
+
export declare interface ExtensionRegistry {
|
|
273
|
+
/** The extensions registered in this registry (in registration order). */
|
|
274
|
+
readonly extensions: readonly ExtensionDefinition[];
|
|
275
|
+
/**
|
|
276
|
+
* Look up a custom type registration by its fully-qualified type ID.
|
|
277
|
+
*
|
|
278
|
+
* @param typeId - The fully-qualified type ID (e.g., "x-stripe/monetary/Decimal").
|
|
279
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
280
|
+
*/
|
|
281
|
+
findType(typeId: string): CustomTypeRegistration | undefined;
|
|
282
|
+
/**
|
|
283
|
+
* Look up a custom type registration by a TypeScript-facing type name.
|
|
284
|
+
*
|
|
285
|
+
* This is used during TSDoc/class analysis to resolve extension-defined
|
|
286
|
+
* custom types from source-level declarations.
|
|
287
|
+
*/
|
|
288
|
+
findTypeByName(typeName: string): {
|
|
289
|
+
readonly extensionId: string;
|
|
290
|
+
readonly registration: CustomTypeRegistration;
|
|
291
|
+
} | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* Look up a custom constraint registration by its fully-qualified constraint ID.
|
|
294
|
+
*
|
|
295
|
+
* @param constraintId - The fully-qualified constraint ID.
|
|
296
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
297
|
+
*/
|
|
298
|
+
findConstraint(constraintId: string): CustomConstraintRegistration | undefined;
|
|
299
|
+
/**
|
|
300
|
+
* Look up a TSDoc custom constraint-tag registration by tag name.
|
|
301
|
+
*/
|
|
302
|
+
findConstraintTag(tagName: string): {
|
|
303
|
+
readonly extensionId: string;
|
|
304
|
+
readonly registration: ConstraintTagRegistration;
|
|
305
|
+
} | undefined;
|
|
306
|
+
/**
|
|
307
|
+
* Look up built-in tag broadening for a given custom type ID.
|
|
308
|
+
*/
|
|
309
|
+
findBuiltinConstraintBroadening(typeId: string, tagName: string): {
|
|
310
|
+
readonly extensionId: string;
|
|
311
|
+
readonly registration: BuiltinConstraintBroadeningRegistration;
|
|
312
|
+
} | undefined;
|
|
313
|
+
/**
|
|
314
|
+
* Look up a custom annotation registration by its fully-qualified annotation ID.
|
|
315
|
+
*
|
|
316
|
+
* @param annotationId - The fully-qualified annotation ID.
|
|
317
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
318
|
+
*/
|
|
319
|
+
findAnnotation(annotationId: string): CustomAnnotationRegistration | undefined;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Extension properties for custom FormSpec constraint tags. */
|
|
323
|
+
export declare type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Options for generating schemas from a decorated class.
|
|
327
|
+
*/
|
|
328
|
+
export declare interface GenerateFromClassOptions extends GenerateJsonSchemaFromIROptions {
|
|
329
|
+
/** Path to the TypeScript source file */
|
|
330
|
+
filePath: string;
|
|
331
|
+
/** Class name to analyze */
|
|
332
|
+
className: string;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Result of generating schemas from a decorated class.
|
|
337
|
+
*/
|
|
338
|
+
export declare interface GenerateFromClassResult {
|
|
339
|
+
/** JSON Schema 2020-12 for validation */
|
|
340
|
+
jsonSchema: JsonSchema2020;
|
|
341
|
+
/** JSON Forms UI Schema for rendering */
|
|
342
|
+
uiSchema: UISchema;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Generates a JSON Schema 2020-12 from a FormSpec.
|
|
347
|
+
*
|
|
348
|
+
* All generation routes through the canonical IR. The chain DSL is first
|
|
349
|
+
* canonicalized to a FormIR, then the IR-based generator produces the schema.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* const form = formspec(
|
|
354
|
+
* field.text("name", { label: "Name", required: true }),
|
|
355
|
+
* field.number("age", { min: 0 }),
|
|
356
|
+
* );
|
|
357
|
+
*
|
|
358
|
+
* const schema = generateJsonSchema(form);
|
|
359
|
+
* // {
|
|
360
|
+
* // $schema: "https://json-schema.org/draft/2020-12/schema",
|
|
361
|
+
* // type: "object",
|
|
362
|
+
* // properties: {
|
|
363
|
+
* // name: { type: "string", title: "Name" },
|
|
364
|
+
* // age: { type: "number", minimum: 0 }
|
|
365
|
+
* // },
|
|
366
|
+
* // required: ["name"]
|
|
367
|
+
* // }
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @param form - The FormSpec to convert
|
|
371
|
+
* @returns A JSON Schema 2020-12 object
|
|
372
|
+
*/
|
|
373
|
+
export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E>, options?: GenerateJsonSchemaOptions): JsonSchema2020;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Generates a JSON Schema 2020-12 object from a canonical FormIR.
|
|
377
|
+
*
|
|
378
|
+
* Groups and conditionals are flattened — they influence UI layout but do not
|
|
379
|
+
* affect the data schema. All fields appear at the level they would occupy in
|
|
380
|
+
* the output data.
|
|
381
|
+
*
|
|
382
|
+
* Named types in the `typeRegistry` are emitted as `$defs` entries and
|
|
383
|
+
* referenced via `$ref` (per PP7 — high-fidelity output).
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```typescript
|
|
387
|
+
* import { canonicalizeDSL } from "./canonicalize/index.js";
|
|
388
|
+
* import { generateJsonSchemaFromIR } from "./json-schema/ir-generator.js";
|
|
389
|
+
* import { formspec, field } from "@formspec/dsl";
|
|
390
|
+
*
|
|
391
|
+
* const form = formspec(
|
|
392
|
+
* field.text("name", { label: "Name", required: true }),
|
|
393
|
+
* field.number("age", { min: 0 }),
|
|
394
|
+
* );
|
|
395
|
+
* const ir = canonicalizeDSL(form);
|
|
396
|
+
* const schema = generateJsonSchemaFromIR(ir);
|
|
397
|
+
* // {
|
|
398
|
+
* // $schema: "https://json-schema.org/draft/2020-12/schema",
|
|
399
|
+
* // type: "object",
|
|
400
|
+
* // properties: {
|
|
401
|
+
* // name: { type: "string", title: "Name" },
|
|
402
|
+
* // age: { type: "number", minimum: 0 }
|
|
403
|
+
* // },
|
|
404
|
+
* // required: ["name"]
|
|
405
|
+
* // }
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* Advanced API — most consumers should use `generateJsonSchema()` or
|
|
409
|
+
* `buildFormSchemas()`, which canonicalize form definitions automatically.
|
|
410
|
+
* Callers of this function are responsible for providing pre-canonicalized IR.
|
|
411
|
+
*
|
|
412
|
+
* @param ir - The canonical FormIR produced by a canonicalizer
|
|
413
|
+
* @returns A plain JSON-serializable JSON Schema 2020-12 object
|
|
414
|
+
*/
|
|
415
|
+
export declare function generateJsonSchemaFromIR(ir: FormIR, options?: GenerateJsonSchemaFromIROptions): JsonSchema2020;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Options for generating JSON Schema from a canonical FormIR.
|
|
419
|
+
*/
|
|
420
|
+
export declare interface GenerateJsonSchemaFromIROptions {
|
|
421
|
+
/**
|
|
422
|
+
* Registry used to resolve custom types, constraints, and annotations.
|
|
423
|
+
*
|
|
424
|
+
* JSON Schema generation throws when custom IR nodes are present without a
|
|
425
|
+
* matching registration in this registry.
|
|
426
|
+
*/
|
|
427
|
+
readonly extensionRegistry?: ExtensionRegistry | undefined;
|
|
428
|
+
/**
|
|
429
|
+
* Vendor prefix passed to extension `toJsonSchema` hooks.
|
|
430
|
+
* @defaultValue "x-formspec"
|
|
431
|
+
*/
|
|
432
|
+
readonly vendorPrefix?: string | undefined;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Options for generating JSON Schema from a Chain DSL form.
|
|
437
|
+
*
|
|
438
|
+
* These options are forwarded to the IR-based JSON Schema generator.
|
|
439
|
+
*/
|
|
440
|
+
export declare type GenerateJsonSchemaOptions = GenerateJsonSchemaFromIROptions;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Generates JSON Schema and UI Schema from a named TypeScript
|
|
444
|
+
* type — a decorated class, an interface with TSDoc tags, or a type alias.
|
|
445
|
+
*
|
|
446
|
+
* This is the recommended entry point. It automatically detects whether
|
|
447
|
+
* the name resolves to a class, interface, or type alias and uses the
|
|
448
|
+
* appropriate IR analysis pipeline.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```typescript
|
|
452
|
+
* const result = generateSchemas({
|
|
453
|
+
* filePath: "./src/config.ts",
|
|
454
|
+
* typeName: "DiscountConfig",
|
|
455
|
+
* });
|
|
456
|
+
* ```
|
|
457
|
+
*
|
|
458
|
+
* @param options - File path and type name
|
|
459
|
+
* @returns Generated JSON Schema and UI Schema
|
|
460
|
+
*/
|
|
461
|
+
export declare function generateSchemas(options: GenerateSchemasOptions): GenerateFromClassResult;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Generates JSON Schema and UI Schema from a decorated TypeScript class.
|
|
465
|
+
*
|
|
466
|
+
* This is a high-level entry point that handles the entire pipeline:
|
|
467
|
+
* creating a TypeScript program, finding the class, analyzing it to IR,
|
|
468
|
+
* and generating schemas — all in one call.
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```typescript
|
|
472
|
+
* const result = generateSchemasFromClass({
|
|
473
|
+
* filePath: "./src/forms.ts",
|
|
474
|
+
* className: "UserForm",
|
|
475
|
+
* });
|
|
476
|
+
* console.log(result.jsonSchema);
|
|
477
|
+
* ```
|
|
478
|
+
*
|
|
479
|
+
* @param options - File path, class name, and optional compiler options
|
|
480
|
+
* @returns Generated JSON Schema and UI Schema
|
|
481
|
+
*/
|
|
482
|
+
export declare function generateSchemasFromClass(options: GenerateFromClassOptions): GenerateFromClassResult;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Options for generating schemas from a named type (class, interface, or type alias).
|
|
486
|
+
*/
|
|
487
|
+
export declare interface GenerateSchemasOptions extends GenerateJsonSchemaFromIROptions {
|
|
488
|
+
/** Path to the TypeScript source file */
|
|
489
|
+
filePath: string;
|
|
490
|
+
/** Name of the exported class, interface, or type alias to analyze */
|
|
491
|
+
typeName: string;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Generates a JSON Forms UI Schema from a FormSpec.
|
|
496
|
+
*
|
|
497
|
+
* All generation routes through the canonical IR. The chain DSL is first
|
|
498
|
+
* canonicalized to a FormIR, then the IR-based generator produces the schema.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* const form = formspec(
|
|
503
|
+
* group("Customer",
|
|
504
|
+
* field.text("name", { label: "Name" }),
|
|
505
|
+
* ),
|
|
506
|
+
* when("status", "draft",
|
|
507
|
+
* field.text("notes", { label: "Notes" }),
|
|
508
|
+
* ),
|
|
509
|
+
* );
|
|
510
|
+
*
|
|
511
|
+
* const uiSchema = generateUiSchema(form);
|
|
512
|
+
* // {
|
|
513
|
+
* // type: "VerticalLayout",
|
|
514
|
+
* // elements: [
|
|
515
|
+
* // {
|
|
516
|
+
* // type: "Group",
|
|
517
|
+
* // label: "Customer",
|
|
518
|
+
* // elements: [
|
|
519
|
+
* // { type: "Control", scope: "#/properties/name", label: "Name" }
|
|
520
|
+
* // ]
|
|
521
|
+
* // },
|
|
522
|
+
* // {
|
|
523
|
+
* // type: "Control",
|
|
524
|
+
* // scope: "#/properties/notes",
|
|
525
|
+
* // label: "Notes",
|
|
526
|
+
* // rule: {
|
|
527
|
+
* // effect: "SHOW",
|
|
528
|
+
* // condition: { scope: "#/properties/status", schema: { const: "draft" } }
|
|
529
|
+
* // }
|
|
530
|
+
* // }
|
|
531
|
+
* // ]
|
|
532
|
+
* // }
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @param form - The FormSpec to convert
|
|
536
|
+
* @returns A JSON Forms UI Schema
|
|
537
|
+
*/
|
|
538
|
+
export declare function generateUiSchema<E extends readonly FormElement[]>(form: FormSpec<E>): UISchema;
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Reads a FormSpec extension property from a JSON Schema node.
|
|
542
|
+
*
|
|
543
|
+
* Accepts any schema object — `JSONSchema7`, `JsonSchema2020`, `ExtendedJSONSchema7`, etc.
|
|
544
|
+
*
|
|
545
|
+
* @param schema - Any JSON Schema node
|
|
546
|
+
* @param key - Extension key (must start with `x-formspec-`)
|
|
547
|
+
* @returns The extension value, or `undefined` if not present
|
|
548
|
+
*/
|
|
549
|
+
export declare function getSchemaExtension(schema: object, key: `x-formspec-${string}`): unknown;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* A group element with a label.
|
|
553
|
+
*/
|
|
554
|
+
export declare interface GroupLayout {
|
|
555
|
+
type: "Group";
|
|
556
|
+
label: string;
|
|
557
|
+
elements: UISchemaElement[];
|
|
558
|
+
rule?: Rule | undefined;
|
|
559
|
+
options?: Record<string, unknown> | undefined;
|
|
560
|
+
[k: string]: unknown;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export declare const groupLayoutSchema: z.ZodType<GroupLayout>;
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* A horizontal layout element.
|
|
567
|
+
*/
|
|
568
|
+
export declare interface HorizontalLayout {
|
|
569
|
+
type: "HorizontalLayout";
|
|
570
|
+
elements: UISchemaElement[];
|
|
571
|
+
rule?: Rule | undefined;
|
|
572
|
+
options?: Record<string, unknown> | undefined;
|
|
573
|
+
[k: string]: unknown;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export declare const horizontalLayoutSchema: z.ZodType<HorizontalLayout>;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* A JSON Schema 2020-12 document, sub-schema, or keyword collection.
|
|
580
|
+
*
|
|
581
|
+
* This interface covers the subset of JSON Schema 2020-12 that this generator
|
|
582
|
+
* emits, plus an index signature for custom `x-formspec-*` extension keywords.
|
|
583
|
+
*/
|
|
584
|
+
export declare interface JsonSchema2020 {
|
|
585
|
+
$schema?: string;
|
|
586
|
+
$ref?: string;
|
|
587
|
+
$defs?: Record<string, JsonSchema2020>;
|
|
588
|
+
type?: string;
|
|
589
|
+
properties?: Record<string, JsonSchema2020>;
|
|
590
|
+
required?: string[];
|
|
591
|
+
items?: JsonSchema2020;
|
|
592
|
+
additionalProperties?: boolean | JsonSchema2020;
|
|
593
|
+
enum?: readonly (string | number)[];
|
|
594
|
+
const?: JsonValue;
|
|
595
|
+
allOf?: readonly JsonSchema2020[];
|
|
596
|
+
oneOf?: readonly JsonSchema2020[];
|
|
597
|
+
anyOf?: readonly JsonSchema2020[];
|
|
598
|
+
minimum?: number;
|
|
599
|
+
maximum?: number;
|
|
600
|
+
exclusiveMinimum?: number;
|
|
601
|
+
exclusiveMaximum?: number;
|
|
602
|
+
multipleOf?: number;
|
|
603
|
+
minLength?: number;
|
|
604
|
+
maxLength?: number;
|
|
605
|
+
minItems?: number;
|
|
606
|
+
maxItems?: number;
|
|
607
|
+
pattern?: string;
|
|
608
|
+
uniqueItems?: boolean;
|
|
609
|
+
format?: string;
|
|
610
|
+
title?: string;
|
|
611
|
+
description?: string;
|
|
612
|
+
default?: unknown;
|
|
613
|
+
deprecated?: boolean;
|
|
614
|
+
[key: `x-${string}`]: unknown;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* A JSON Schema definition (legacy subset used by Zod validator and types.ts).
|
|
619
|
+
*/
|
|
620
|
+
export declare interface JSONSchema7 {
|
|
621
|
+
$schema?: string;
|
|
622
|
+
$id?: string;
|
|
623
|
+
$ref?: string;
|
|
624
|
+
title?: string;
|
|
625
|
+
description?: string;
|
|
626
|
+
deprecated?: boolean;
|
|
627
|
+
type?: JSONSchemaType | JSONSchemaType[];
|
|
628
|
+
minLength?: number;
|
|
629
|
+
maxLength?: number;
|
|
630
|
+
pattern?: string;
|
|
631
|
+
minimum?: number;
|
|
632
|
+
maximum?: number;
|
|
633
|
+
exclusiveMinimum?: number;
|
|
634
|
+
exclusiveMaximum?: number;
|
|
635
|
+
enum?: readonly (string | number | boolean | null)[];
|
|
636
|
+
const?: string | number | boolean | null;
|
|
637
|
+
properties?: Record<string, JSONSchema7>;
|
|
638
|
+
required?: string[];
|
|
639
|
+
additionalProperties?: boolean | JSONSchema7;
|
|
640
|
+
items?: JSONSchema7 | JSONSchema7[];
|
|
641
|
+
minItems?: number;
|
|
642
|
+
maxItems?: number;
|
|
643
|
+
allOf?: JSONSchema7[];
|
|
644
|
+
anyOf?: JSONSchema7[];
|
|
645
|
+
oneOf?: JSONSchema7[];
|
|
646
|
+
not?: JSONSchema7;
|
|
647
|
+
if?: JSONSchema7;
|
|
648
|
+
then?: JSONSchema7;
|
|
649
|
+
else?: JSONSchema7;
|
|
650
|
+
format?: string;
|
|
651
|
+
default?: unknown;
|
|
652
|
+
/**
|
|
653
|
+
* Data source key for dynamic enum fields.
|
|
654
|
+
* Indicates that options should be fetched from a registered resolver.
|
|
655
|
+
*/
|
|
656
|
+
"x-formspec-source"?: string;
|
|
657
|
+
/**
|
|
658
|
+
* Field names whose values are needed to fetch dynamic enum options.
|
|
659
|
+
* Used for dependent/cascading dropdowns.
|
|
660
|
+
*/
|
|
661
|
+
"x-formspec-params"?: readonly string[];
|
|
662
|
+
/**
|
|
663
|
+
* Schema source identifier for dynamic schema fields.
|
|
664
|
+
* Indicates that the schema should be loaded dynamically at runtime.
|
|
665
|
+
*/
|
|
666
|
+
"x-formspec-schemaSource"?: string;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export declare const jsonSchema7Schema: z.ZodType<JSONSchema7>;
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* JSON Schema type definitions.
|
|
673
|
+
*
|
|
674
|
+
* These types are a subset of JSON Schema sufficient for form generation.
|
|
675
|
+
*/
|
|
676
|
+
/**
|
|
677
|
+
* JSON Schema primitive types.
|
|
678
|
+
*/
|
|
679
|
+
export declare type JSONSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Zod schema for JSON Schema primitive type strings.
|
|
683
|
+
*/
|
|
684
|
+
export declare const jsonSchemaTypeSchema: z.ZodEnum<["string", "number", "integer", "boolean", "object", "array", "null"]>;
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* A Label element for displaying static text.
|
|
688
|
+
*/
|
|
689
|
+
export declare type LabelElement = z.infer<typeof labelElementSchema>;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Zod schema for a Label element.
|
|
693
|
+
*/
|
|
694
|
+
export declare const labelElementSchema: z.ZodObject<{
|
|
695
|
+
type: z.ZodLiteral<"Label">;
|
|
696
|
+
text: z.ZodString;
|
|
697
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
698
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
699
|
+
condition: z.ZodObject<{
|
|
700
|
+
scope: z.ZodString;
|
|
701
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
702
|
+
}, "strict", z.ZodTypeAny, {
|
|
703
|
+
schema: RuleConditionSchema;
|
|
704
|
+
scope: string;
|
|
705
|
+
}, {
|
|
706
|
+
schema: RuleConditionSchema;
|
|
707
|
+
scope: string;
|
|
708
|
+
}>;
|
|
709
|
+
}, "strict", z.ZodTypeAny, {
|
|
710
|
+
condition: {
|
|
711
|
+
schema: RuleConditionSchema;
|
|
712
|
+
scope: string;
|
|
713
|
+
};
|
|
714
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
715
|
+
}, {
|
|
716
|
+
condition: {
|
|
717
|
+
schema: RuleConditionSchema;
|
|
718
|
+
scope: string;
|
|
719
|
+
};
|
|
720
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
721
|
+
}>>;
|
|
722
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
723
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
724
|
+
type: z.ZodLiteral<"Label">;
|
|
725
|
+
text: z.ZodString;
|
|
726
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
727
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
728
|
+
condition: z.ZodObject<{
|
|
729
|
+
scope: z.ZodString;
|
|
730
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
731
|
+
}, "strict", z.ZodTypeAny, {
|
|
732
|
+
schema: RuleConditionSchema;
|
|
733
|
+
scope: string;
|
|
734
|
+
}, {
|
|
735
|
+
schema: RuleConditionSchema;
|
|
736
|
+
scope: string;
|
|
737
|
+
}>;
|
|
738
|
+
}, "strict", z.ZodTypeAny, {
|
|
739
|
+
condition: {
|
|
740
|
+
schema: RuleConditionSchema;
|
|
741
|
+
scope: string;
|
|
742
|
+
};
|
|
743
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
744
|
+
}, {
|
|
745
|
+
condition: {
|
|
746
|
+
schema: RuleConditionSchema;
|
|
747
|
+
scope: string;
|
|
748
|
+
};
|
|
749
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
750
|
+
}>>;
|
|
751
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
752
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
753
|
+
type: z.ZodLiteral<"Label">;
|
|
754
|
+
text: z.ZodString;
|
|
755
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
756
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
757
|
+
condition: z.ZodObject<{
|
|
758
|
+
scope: z.ZodString;
|
|
759
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
760
|
+
}, "strict", z.ZodTypeAny, {
|
|
761
|
+
schema: RuleConditionSchema;
|
|
762
|
+
scope: string;
|
|
763
|
+
}, {
|
|
764
|
+
schema: RuleConditionSchema;
|
|
765
|
+
scope: string;
|
|
766
|
+
}>;
|
|
767
|
+
}, "strict", z.ZodTypeAny, {
|
|
768
|
+
condition: {
|
|
769
|
+
schema: RuleConditionSchema;
|
|
770
|
+
scope: string;
|
|
771
|
+
};
|
|
772
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
773
|
+
}, {
|
|
774
|
+
condition: {
|
|
775
|
+
schema: RuleConditionSchema;
|
|
776
|
+
scope: string;
|
|
777
|
+
};
|
|
778
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
779
|
+
}>>;
|
|
780
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
781
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Result of generating schemas from a mixed-authoring composition.
|
|
785
|
+
*/
|
|
786
|
+
export declare interface MixedAuthoringSchemas {
|
|
787
|
+
/** JSON Schema 2020-12 for validation. */
|
|
788
|
+
readonly jsonSchema: JsonSchema2020;
|
|
789
|
+
/** JSON Forms UI Schema for rendering. */
|
|
790
|
+
readonly uiSchema: UISchema;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Rule for conditional element visibility/enablement.
|
|
795
|
+
*/
|
|
796
|
+
export declare type Rule = z.infer<typeof ruleSchema>;
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* JSON Schema subset used in rule conditions.
|
|
800
|
+
*/
|
|
801
|
+
export declare interface RuleConditionSchema {
|
|
802
|
+
const?: unknown;
|
|
803
|
+
enum?: readonly unknown[];
|
|
804
|
+
type?: string;
|
|
805
|
+
not?: RuleConditionSchema;
|
|
806
|
+
minimum?: number;
|
|
807
|
+
maximum?: number;
|
|
808
|
+
exclusiveMinimum?: number;
|
|
809
|
+
exclusiveMaximum?: number;
|
|
810
|
+
minLength?: number;
|
|
811
|
+
properties?: Record<string, RuleConditionSchema>;
|
|
812
|
+
required?: string[];
|
|
813
|
+
allOf?: RuleConditionSchema[];
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
export declare const ruleConditionSchema: z.ZodType<RuleConditionSchema>;
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Rule effect types for conditional visibility.
|
|
820
|
+
*/
|
|
821
|
+
export declare type RuleEffect = z.infer<typeof ruleEffectSchema>;
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Zod schema for rule effect values.
|
|
825
|
+
*/
|
|
826
|
+
export declare const ruleEffectSchema: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Zod schema for a UI Schema rule.
|
|
830
|
+
*/
|
|
831
|
+
export declare const ruleSchema: z.ZodObject<{
|
|
832
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
833
|
+
condition: z.ZodObject<{
|
|
834
|
+
scope: z.ZodString;
|
|
835
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
836
|
+
}, "strict", z.ZodTypeAny, {
|
|
837
|
+
schema: RuleConditionSchema;
|
|
838
|
+
scope: string;
|
|
839
|
+
}, {
|
|
840
|
+
schema: RuleConditionSchema;
|
|
841
|
+
scope: string;
|
|
842
|
+
}>;
|
|
843
|
+
}, "strict", z.ZodTypeAny, {
|
|
844
|
+
condition: {
|
|
845
|
+
schema: RuleConditionSchema;
|
|
846
|
+
scope: string;
|
|
847
|
+
};
|
|
848
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
849
|
+
}, {
|
|
850
|
+
condition: {
|
|
851
|
+
schema: RuleConditionSchema;
|
|
852
|
+
scope: string;
|
|
853
|
+
};
|
|
854
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
855
|
+
}>;
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Condition for a rule.
|
|
859
|
+
*/
|
|
860
|
+
export declare type SchemaBasedCondition = z.infer<typeof schemaBasedConditionSchema>;
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Zod schema for a schema-based rule condition.
|
|
864
|
+
*/
|
|
865
|
+
export declare const schemaBasedConditionSchema: z.ZodObject<{
|
|
866
|
+
scope: z.ZodString;
|
|
867
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
868
|
+
}, "strict", z.ZodTypeAny, {
|
|
869
|
+
schema: RuleConditionSchema;
|
|
870
|
+
scope: string;
|
|
871
|
+
}, {
|
|
872
|
+
schema: RuleConditionSchema;
|
|
873
|
+
scope: string;
|
|
874
|
+
}>;
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Sets a FormSpec extension property on a JSON Schema node.
|
|
878
|
+
*
|
|
879
|
+
* Use this to safely add `x-formspec-*` properties to any schema,
|
|
880
|
+
* including nested schemas typed as `JSONSchema7` (which don't carry
|
|
881
|
+
* the extension index signature).
|
|
882
|
+
*
|
|
883
|
+
* @param schema - Any JSON Schema node
|
|
884
|
+
* @param key - Extension key (must start with `x-formspec-`)
|
|
885
|
+
* @param value - Extension value
|
|
886
|
+
*/
|
|
887
|
+
export declare function setSchemaExtension(schema: object, key: `x-formspec-${string}`, value: unknown): void;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Root UI Schema (always a layout — not a Control, Category, or Label).
|
|
891
|
+
*/
|
|
892
|
+
export declare type UISchema = VerticalLayout | HorizontalLayout | GroupLayout | Categorization;
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Union of all UI Schema element types.
|
|
896
|
+
*/
|
|
897
|
+
export declare type UISchemaElement = ControlElement | VerticalLayout | HorizontalLayout | GroupLayout | Categorization | Category | LabelElement;
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Base interface for all UI Schema elements.
|
|
901
|
+
*
|
|
902
|
+
* This is a manually maintained interface representing the common shape
|
|
903
|
+
* shared by all element types. It is kept as an interface (rather than
|
|
904
|
+
* derived from Zod) because it is the base of a discriminated union, not
|
|
905
|
+
* a union member itself.
|
|
906
|
+
*/
|
|
907
|
+
export declare interface UISchemaElementBase {
|
|
908
|
+
type: UISchemaElementType;
|
|
909
|
+
rule?: Rule;
|
|
910
|
+
options?: Record<string, unknown>;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
export declare const uiSchemaElementSchema: z.ZodType<UISchemaElement>;
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* UI Schema element types.
|
|
917
|
+
*/
|
|
918
|
+
export declare type UISchemaElementType = z.infer<typeof uiSchemaElementTypeSchema>;
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Zod schema for UI Schema element type strings.
|
|
922
|
+
*/
|
|
923
|
+
export declare const uiSchemaElementTypeSchema: z.ZodEnum<["Control", "VerticalLayout", "HorizontalLayout", "Group", "Categorization", "Category", "Label"]>;
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Zod schema for the root UI Schema (layout types only).
|
|
927
|
+
*/
|
|
928
|
+
export declare const uiSchemaSchema: z.ZodType<UISchema>;
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* A vertical layout element.
|
|
932
|
+
*/
|
|
933
|
+
export declare interface VerticalLayout {
|
|
934
|
+
type: "VerticalLayout";
|
|
935
|
+
elements: UISchemaElement[];
|
|
936
|
+
rule?: Rule | undefined;
|
|
937
|
+
options?: Record<string, unknown> | undefined;
|
|
938
|
+
[k: string]: unknown;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
export declare const verticalLayoutSchema: z.ZodType<VerticalLayout>;
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Builds and writes both JSON Schema and UI Schema files to disk.
|
|
945
|
+
*
|
|
946
|
+
* This is a convenience function for build-time schema generation.
|
|
947
|
+
* It creates the output directory if it doesn't exist.
|
|
948
|
+
*
|
|
949
|
+
* @example
|
|
950
|
+
* ```typescript
|
|
951
|
+
* import { formspec, field } from "formspec";
|
|
952
|
+
* import { writeSchemas } from "@formspec/build";
|
|
953
|
+
*
|
|
954
|
+
* const ProductForm = formspec(
|
|
955
|
+
* field.text("name", { required: true }),
|
|
956
|
+
* field.enum("status", ["draft", "active"]),
|
|
957
|
+
* );
|
|
958
|
+
*
|
|
959
|
+
* // Write schemas to ./generated/product-schema.json and ./generated/product-uischema.json
|
|
960
|
+
* const { jsonSchemaPath, uiSchemaPath } = writeSchemas(ProductForm, {
|
|
961
|
+
* outDir: "./generated",
|
|
962
|
+
* name: "product",
|
|
963
|
+
* });
|
|
964
|
+
*
|
|
965
|
+
* console.log(`Generated: ${jsonSchemaPath}, ${uiSchemaPath}`);
|
|
966
|
+
* ```
|
|
967
|
+
*
|
|
968
|
+
* @param form - The FormSpec to build schemas from
|
|
969
|
+
* @param options - Output options (directory, file name, indentation)
|
|
970
|
+
* @returns Object containing paths to the generated files
|
|
971
|
+
*/
|
|
972
|
+
export declare function writeSchemas<E extends readonly FormElement[]>(form: FormSpec<E>, options: WriteSchemasOptions): WriteSchemasResult;
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Options for writing schemas to disk.
|
|
976
|
+
*/
|
|
977
|
+
export declare interface WriteSchemasOptions extends GenerateJsonSchemaFromIROptions {
|
|
978
|
+
/** Output directory for the schema files */
|
|
979
|
+
readonly outDir: string;
|
|
980
|
+
/** Base name for the output files (without extension). Defaults to "schema" */
|
|
981
|
+
readonly name?: string;
|
|
982
|
+
/** Number of spaces for JSON indentation. Defaults to 2 */
|
|
983
|
+
readonly indent?: number;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* Result of writing schemas to disk.
|
|
988
|
+
*/
|
|
989
|
+
export declare interface WriteSchemasResult {
|
|
990
|
+
/** Path to the generated JSON Schema file */
|
|
991
|
+
readonly jsonSchemaPath: string;
|
|
992
|
+
/** Path to the generated UI Schema file */
|
|
993
|
+
readonly uiSchemaPath: string;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
export { }
|