@formspec/build 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +138 -0
- package/dist/__tests__/analyzer-edge-cases.test.d.ts +13 -0
- package/dist/__tests__/analyzer-edge-cases.test.d.ts.map +1 -0
- package/dist/__tests__/analyzer.test.d.ts +5 -0
- package/dist/__tests__/analyzer.test.d.ts.map +1 -0
- package/dist/__tests__/codegen.test.d.ts +5 -0
- package/dist/__tests__/codegen.test.d.ts.map +1 -0
- package/dist/__tests__/decorator-pipeline.test.d.ts +11 -0
- package/dist/__tests__/decorator-pipeline.test.d.ts.map +1 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts +110 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts +12 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-b-decorators.d.ts +5 -0
- package/dist/__tests__/fixtures/example-b-decorators.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-b-extended.d.ts +5 -0
- package/dist/__tests__/fixtures/example-b-extended.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-c-custom.d.ts +5 -0
- package/dist/__tests__/fixtures/example-c-custom.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-c-decorators.d.ts +5 -0
- package/dist/__tests__/fixtures/example-c-decorators.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-d-mixed-decorators.d.ts +6 -0
- package/dist/__tests__/fixtures/example-d-mixed-decorators.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-e-decorators.d.ts +11 -0
- package/dist/__tests__/fixtures/example-e-decorators.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-e-no-namespace.d.ts +5 -0
- package/dist/__tests__/fixtures/example-e-no-namespace.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-jsdoc-constraints.d.ts +16 -0
- package/dist/__tests__/fixtures/example-jsdoc-constraints.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-nested-class.d.ts +45 -0
- package/dist/__tests__/fixtures/example-nested-class.d.ts.map +1 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts +55 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts.map +1 -0
- package/dist/__tests__/interface-types.test.d.ts +11 -0
- package/dist/__tests__/interface-types.test.d.ts.map +1 -0
- package/dist/__tests__/jsdoc-constraints.test.d.ts +10 -0
- package/dist/__tests__/jsdoc-constraints.test.d.ts.map +1 -0
- package/dist/analyzer/class-analyzer.d.ts +139 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -0
- package/dist/analyzer/decorator-extractor.d.ts +78 -0
- package/dist/analyzer/decorator-extractor.d.ts.map +1 -0
- package/dist/analyzer/jsdoc-constraints.d.ts +47 -0
- package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
- package/dist/analyzer/program.d.ts +53 -0
- package/dist/analyzer/program.d.ts.map +1 -0
- package/dist/analyzer/type-converter.d.ts +75 -0
- package/dist/analyzer/type-converter.d.ts.map +1 -0
- package/dist/browser.cjs +549 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.ts +56 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +501 -0
- package/dist/browser.js.map +1 -0
- package/dist/build.d.ts +890 -0
- package/dist/cli.cjs +2267 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +2204 -103
- package/dist/cli.js.map +1 -1
- package/dist/codegen/index.d.ts +75 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/generators/class-schema.d.ts +114 -0
- package/dist/generators/class-schema.d.ts.map +1 -0
- package/dist/generators/method-schema.d.ts +67 -0
- package/dist/generators/method-schema.d.ts.map +1 -0
- package/dist/index.cjs +2093 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2024 -104
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +1345 -0
- package/dist/internals.cjs.map +1 -0
- package/dist/internals.d.ts +21 -0
- package/dist/internals.d.ts.map +1 -0
- package/dist/internals.js +1298 -0
- package/dist/internals.js.map +1 -0
- package/dist/json-schema/generator.d.ts.map +1 -1
- 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 +28 -0
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/ui-schema/generator.d.ts +15 -0
- package/dist/ui-schema/generator.d.ts.map +1 -1
- 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/package.json +25 -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 -209
- package/dist/__tests__/edge-cases.test.js.map +0 -1
- package/dist/__tests__/generator.test.js +0 -208
- 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 -146
- 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,890 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@formspec/build` - Build tools for FormSpec
|
|
3
|
+
*
|
|
4
|
+
* This package provides generators to compile FormSpec forms into:
|
|
5
|
+
* - JSON Schema (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 { FormElement } from '@formspec/core';
|
|
27
|
+
import type { FormSpec } from '@formspec/core';
|
|
28
|
+
import { z } from 'zod';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Builds both JSON Schema and UI Schema from a FormSpec.
|
|
32
|
+
*
|
|
33
|
+
* This is a convenience function that combines `generateJsonSchema`
|
|
34
|
+
* and `generateUiSchema`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const form = formspec(
|
|
39
|
+
* field.text("name", { required: true }),
|
|
40
|
+
* field.number("age", { min: 0 }),
|
|
41
|
+
* );
|
|
42
|
+
*
|
|
43
|
+
* const { jsonSchema, uiSchema } = buildFormSchemas(form);
|
|
44
|
+
*
|
|
45
|
+
* // Use with JSON Forms renderer
|
|
46
|
+
* <JsonForms
|
|
47
|
+
* schema={jsonSchema}
|
|
48
|
+
* uischema={uiSchema}
|
|
49
|
+
* data={formData}
|
|
50
|
+
* renderers={materialRenderers}
|
|
51
|
+
* />
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param form - The FormSpec to build schemas from
|
|
55
|
+
* @returns Object containing both jsonSchema and uiSchema
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildFormSchemas<E extends readonly FormElement[]>(form: FormSpec<E>): BuildResult;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Result of building form schemas.
|
|
61
|
+
*/
|
|
62
|
+
export declare interface BuildResult {
|
|
63
|
+
/** JSON Schema for validation */
|
|
64
|
+
readonly jsonSchema: JSONSchema7;
|
|
65
|
+
/** JSON Forms UI Schema for rendering */
|
|
66
|
+
readonly uiSchema: UISchema;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A Categorization element (tab-based layout).
|
|
71
|
+
*/
|
|
72
|
+
export declare interface Categorization {
|
|
73
|
+
type: "Categorization";
|
|
74
|
+
elements: Category[];
|
|
75
|
+
label?: string | undefined;
|
|
76
|
+
rule?: Rule | undefined;
|
|
77
|
+
options?: Record<string, unknown> | undefined;
|
|
78
|
+
[k: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export declare const categorizationSchema: z.ZodType<Categorization>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A Category element, used inside a Categorization layout.
|
|
85
|
+
*/
|
|
86
|
+
export declare interface Category {
|
|
87
|
+
type: "Category";
|
|
88
|
+
label: string;
|
|
89
|
+
elements: UISchemaElement[];
|
|
90
|
+
rule?: Rule | undefined;
|
|
91
|
+
options?: Record<string, unknown> | undefined;
|
|
92
|
+
[k: string]: unknown;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export declare const categorySchema: z.ZodType<Category>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Generated schemas for a class.
|
|
99
|
+
*/
|
|
100
|
+
export declare interface ClassSchemas {
|
|
101
|
+
/** JSON Schema for validation */
|
|
102
|
+
jsonSchema: ExtendedJSONSchema7;
|
|
103
|
+
/** JSON Forms UI Schema for rendering */
|
|
104
|
+
uiSchema: UISchema;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Options for code generation.
|
|
109
|
+
*/
|
|
110
|
+
export declare interface CodegenOptions {
|
|
111
|
+
/** Source files to analyze (glob patterns supported) */
|
|
112
|
+
files: string[];
|
|
113
|
+
/** Output file path */
|
|
114
|
+
output: string;
|
|
115
|
+
/** Base directory for relative imports */
|
|
116
|
+
baseDir?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A Control element that binds to a JSON Schema property.
|
|
121
|
+
*/
|
|
122
|
+
export declare type ControlElement = z.infer<typeof controlSchema>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Zod schema for a Control element.
|
|
126
|
+
*/
|
|
127
|
+
export declare const controlSchema: z.ZodObject<{
|
|
128
|
+
type: z.ZodLiteral<"Control">;
|
|
129
|
+
scope: z.ZodString;
|
|
130
|
+
label: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>>;
|
|
131
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
132
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
133
|
+
condition: z.ZodObject<{
|
|
134
|
+
scope: z.ZodString;
|
|
135
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
136
|
+
}, "strict", z.ZodTypeAny, {
|
|
137
|
+
schema: RuleConditionSchema;
|
|
138
|
+
scope: string;
|
|
139
|
+
}, {
|
|
140
|
+
schema: RuleConditionSchema;
|
|
141
|
+
scope: string;
|
|
142
|
+
}>;
|
|
143
|
+
}, "strict", z.ZodTypeAny, {
|
|
144
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
145
|
+
condition: {
|
|
146
|
+
schema: RuleConditionSchema;
|
|
147
|
+
scope: string;
|
|
148
|
+
};
|
|
149
|
+
}, {
|
|
150
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
151
|
+
condition: {
|
|
152
|
+
schema: RuleConditionSchema;
|
|
153
|
+
scope: string;
|
|
154
|
+
};
|
|
155
|
+
}>>;
|
|
156
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
157
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
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
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
175
|
+
condition: {
|
|
176
|
+
schema: RuleConditionSchema;
|
|
177
|
+
scope: string;
|
|
178
|
+
};
|
|
179
|
+
}, {
|
|
180
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
181
|
+
condition: {
|
|
182
|
+
schema: RuleConditionSchema;
|
|
183
|
+
scope: string;
|
|
184
|
+
};
|
|
185
|
+
}>>;
|
|
186
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
187
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
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
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
205
|
+
condition: {
|
|
206
|
+
schema: RuleConditionSchema;
|
|
207
|
+
scope: string;
|
|
208
|
+
};
|
|
209
|
+
}, {
|
|
210
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
211
|
+
condition: {
|
|
212
|
+
schema: RuleConditionSchema;
|
|
213
|
+
scope: string;
|
|
214
|
+
};
|
|
215
|
+
}>>;
|
|
216
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
217
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Information about a decorated class found during codegen analysis.
|
|
221
|
+
*
|
|
222
|
+
* Used to track which classes need type metadata patches and where
|
|
223
|
+
* they are located in the source tree.
|
|
224
|
+
*/
|
|
225
|
+
export declare interface DecoratedClassInfo {
|
|
226
|
+
/** Class name as it appears in the source file */
|
|
227
|
+
name: string;
|
|
228
|
+
/** Import path to the source file (relative to output, without extension) */
|
|
229
|
+
sourcePath: string;
|
|
230
|
+
/** Type metadata for all decorated properties in the class */
|
|
231
|
+
typeMetadata: Record<string, TypeMetadata>;
|
|
232
|
+
/** Whether the class is exported from its source file */
|
|
233
|
+
isExported: boolean;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** JSON Schema with FormSpec extension properties for arbitrary x-formspec-* keys. */
|
|
237
|
+
export declare type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Finds all decorated classes in the given source files.
|
|
241
|
+
*/
|
|
242
|
+
export declare function findDecoratedClasses(files: string[], baseDir: string): DecoratedClassInfo[];
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* FormSpec field definition (simplified for output).
|
|
246
|
+
*/
|
|
247
|
+
export declare interface FormSpecField {
|
|
248
|
+
_field: string;
|
|
249
|
+
id: string;
|
|
250
|
+
label?: string;
|
|
251
|
+
placeholder?: string;
|
|
252
|
+
description?: string;
|
|
253
|
+
required?: boolean;
|
|
254
|
+
min?: number;
|
|
255
|
+
max?: number;
|
|
256
|
+
step?: number;
|
|
257
|
+
minLength?: number;
|
|
258
|
+
maxLength?: number;
|
|
259
|
+
minItems?: number;
|
|
260
|
+
maxItems?: number;
|
|
261
|
+
pattern?: string;
|
|
262
|
+
options?: (string | {
|
|
263
|
+
id: string;
|
|
264
|
+
label: string;
|
|
265
|
+
})[];
|
|
266
|
+
showWhen?: object;
|
|
267
|
+
group?: string;
|
|
268
|
+
fields?: FormSpecField[];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Extension properties for custom FormSpec decorators. */
|
|
272
|
+
export declare type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Generates the codegen output file content.
|
|
276
|
+
*/
|
|
277
|
+
export declare function generateCodegenOutput(classes: DecoratedClassInfo[], outputPath: string, baseDir: string): string;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Options for generating schemas from a decorated class.
|
|
281
|
+
*/
|
|
282
|
+
export declare interface GenerateFromClassOptions {
|
|
283
|
+
/** Path to the TypeScript source file */
|
|
284
|
+
filePath: string;
|
|
285
|
+
/** Class name to analyze */
|
|
286
|
+
className: string;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Result of generating schemas from a decorated class.
|
|
291
|
+
*/
|
|
292
|
+
export declare interface GenerateFromClassResult {
|
|
293
|
+
/** JSON Schema for validation */
|
|
294
|
+
jsonSchema: ExtendedJSONSchema7;
|
|
295
|
+
/** JSON Forms UI Schema for rendering */
|
|
296
|
+
uiSchema: UISchema;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Generates a JSON Schema from a FormSpec.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* const form = formspec(
|
|
305
|
+
* field.text("name", { label: "Name", required: true }),
|
|
306
|
+
* field.number("age", { min: 0 }),
|
|
307
|
+
* );
|
|
308
|
+
*
|
|
309
|
+
* const schema = generateJsonSchema(form);
|
|
310
|
+
* // {
|
|
311
|
+
* // $schema: "https://json-schema.org/draft-07/schema#",
|
|
312
|
+
* // type: "object",
|
|
313
|
+
* // properties: {
|
|
314
|
+
* // name: { type: "string", title: "Name" },
|
|
315
|
+
* // age: { type: "number", minimum: 0 }
|
|
316
|
+
* // },
|
|
317
|
+
* // required: ["name"]
|
|
318
|
+
* // }
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @param form - The FormSpec to convert
|
|
322
|
+
* @returns A JSON Schema object
|
|
323
|
+
*/
|
|
324
|
+
export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E>): JSONSchema7;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Generates JSON Schema and FormSpec/UI Schema from a named TypeScript
|
|
328
|
+
* type — a decorated class, an interface with TSDoc tags, or a type alias.
|
|
329
|
+
*
|
|
330
|
+
* This is the recommended entry point. It automatically detects whether
|
|
331
|
+
* the name resolves to a class, interface, or type alias and uses the
|
|
332
|
+
* appropriate analysis pipeline:
|
|
333
|
+
*
|
|
334
|
+
* - **Classes**: extracts decorators and JSDoc constraints
|
|
335
|
+
* - **Interfaces**: extracts TSDoc tags (`@Field_displayName`, `@Minimum`, etc.)
|
|
336
|
+
* - **Type aliases**: object literal bodies analyzed like interfaces
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* // Works with both classes and interfaces — caller doesn't need to know
|
|
341
|
+
* const result = generateSchemas({
|
|
342
|
+
* filePath: "./src/config.ts",
|
|
343
|
+
* typeName: "DiscountConfig",
|
|
344
|
+
* });
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* @param options - File path and type name
|
|
348
|
+
* @returns Generated JSON Schema and FormSpec/UI Schema
|
|
349
|
+
*/
|
|
350
|
+
export declare function generateSchemas(options: GenerateSchemasOptions): GenerateFromClassResult;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Generates JSON Schema and FormSpec/UI Schema from a decorated TypeScript class.
|
|
354
|
+
*
|
|
355
|
+
* This is a high-level entry point that handles the entire pipeline:
|
|
356
|
+
* creating a TypeScript program, finding the class, analyzing it,
|
|
357
|
+
* and generating schemas — all in one call.
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* const result = generateSchemasFromClass({
|
|
362
|
+
* filePath: "./src/forms.ts",
|
|
363
|
+
* className: "UserForm",
|
|
364
|
+
* });
|
|
365
|
+
* console.log(result.jsonSchema);
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @param options - File path, class name, and optional compiler options
|
|
369
|
+
* @returns Generated JSON Schema and FormSpec/UI Schema
|
|
370
|
+
*/
|
|
371
|
+
export declare function generateSchemasFromClass(options: GenerateFromClassOptions): GenerateFromClassResult;
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Options for generating schemas from a named type (class, interface, or type alias).
|
|
375
|
+
*/
|
|
376
|
+
export declare interface GenerateSchemasOptions {
|
|
377
|
+
/** Path to the TypeScript source file */
|
|
378
|
+
filePath: string;
|
|
379
|
+
/** Name of the exported class, interface, or type alias to analyze */
|
|
380
|
+
typeName: string;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Generates a JSON Forms UI Schema from a FormSpec.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```typescript
|
|
388
|
+
* const form = formspec(
|
|
389
|
+
* group("Customer",
|
|
390
|
+
* field.text("name", { label: "Name" }),
|
|
391
|
+
* ),
|
|
392
|
+
* when("status", "draft",
|
|
393
|
+
* field.text("notes", { label: "Notes" }),
|
|
394
|
+
* ),
|
|
395
|
+
* );
|
|
396
|
+
*
|
|
397
|
+
* const uiSchema = generateUiSchema(form);
|
|
398
|
+
* // {
|
|
399
|
+
* // type: "VerticalLayout",
|
|
400
|
+
* // elements: [
|
|
401
|
+
* // {
|
|
402
|
+
* // type: "Group",
|
|
403
|
+
* // label: "Customer",
|
|
404
|
+
* // elements: [
|
|
405
|
+
* // { type: "Control", scope: "#/properties/name", label: "Name" }
|
|
406
|
+
* // ]
|
|
407
|
+
* // },
|
|
408
|
+
* // {
|
|
409
|
+
* // type: "Control",
|
|
410
|
+
* // scope: "#/properties/notes",
|
|
411
|
+
* // label: "Notes",
|
|
412
|
+
* // rule: {
|
|
413
|
+
* // effect: "SHOW",
|
|
414
|
+
* // condition: { scope: "#/properties/status", schema: { const: "draft" } }
|
|
415
|
+
* // }
|
|
416
|
+
* // }
|
|
417
|
+
* // ]
|
|
418
|
+
* // }
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* @param form - The FormSpec to convert
|
|
422
|
+
* @returns A JSON Forms UI Schema
|
|
423
|
+
*/
|
|
424
|
+
export declare function generateUiSchema<E extends readonly FormElement[]>(form: FormSpec<E>): UISchema;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Converts FormSpecField[] (from decorator/interface/type analysis) to a JSON Forms UISchema.
|
|
428
|
+
*
|
|
429
|
+
* Mapping:
|
|
430
|
+
* - Each field → `{ type: "Control", scope: "#/properties/{id}", label? }`
|
|
431
|
+
* - `showWhen: { field, value }` → rule with SHOW effect
|
|
432
|
+
* - `group` property → Groups fields by group name, preserving insertion order
|
|
433
|
+
* - `fields` (nested object) → single Control pointing to the object property
|
|
434
|
+
* - Root wrapper → `{ type: "VerticalLayout", elements }`
|
|
435
|
+
*
|
|
436
|
+
* @param fields - The FormSpecField array to convert
|
|
437
|
+
* @returns A JSON Forms UISchema
|
|
438
|
+
*/
|
|
439
|
+
export declare function generateUiSchemaFromFields(fields: FormSpecField[]): UISchema;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Reads a FormSpec extension property from a JSON Schema node.
|
|
443
|
+
*
|
|
444
|
+
* Use this to safely read `x-formspec-*` properties from any schema,
|
|
445
|
+
* including nested schemas typed as `JSONSchema7`.
|
|
446
|
+
*
|
|
447
|
+
* @param schema - Any JSON Schema node
|
|
448
|
+
* @param key - Extension key (must start with `x-formspec-`)
|
|
449
|
+
* @returns The extension value, or `undefined` if not present
|
|
450
|
+
*/
|
|
451
|
+
export declare function getSchemaExtension(schema: JSONSchema7, key: `x-formspec-${string}`): unknown;
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* A group element with a label.
|
|
455
|
+
*/
|
|
456
|
+
export declare interface GroupLayout {
|
|
457
|
+
type: "Group";
|
|
458
|
+
label: string;
|
|
459
|
+
elements: UISchemaElement[];
|
|
460
|
+
rule?: Rule | undefined;
|
|
461
|
+
options?: Record<string, unknown> | undefined;
|
|
462
|
+
[k: string]: unknown;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export declare const groupLayoutSchema: z.ZodType<GroupLayout>;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* A horizontal layout element.
|
|
469
|
+
*/
|
|
470
|
+
export declare interface HorizontalLayout {
|
|
471
|
+
type: "HorizontalLayout";
|
|
472
|
+
elements: UISchemaElement[];
|
|
473
|
+
rule?: Rule | undefined;
|
|
474
|
+
options?: Record<string, unknown> | undefined;
|
|
475
|
+
[k: string]: unknown;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export declare const horizontalLayoutSchema: z.ZodType<HorizontalLayout>;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* A JSON Schema definition (draft-07 subset).
|
|
482
|
+
*/
|
|
483
|
+
export declare interface JSONSchema7 {
|
|
484
|
+
$schema?: string;
|
|
485
|
+
$id?: string;
|
|
486
|
+
$ref?: string;
|
|
487
|
+
title?: string;
|
|
488
|
+
description?: string;
|
|
489
|
+
deprecated?: boolean;
|
|
490
|
+
type?: JSONSchemaType | JSONSchemaType[];
|
|
491
|
+
minLength?: number;
|
|
492
|
+
maxLength?: number;
|
|
493
|
+
pattern?: string;
|
|
494
|
+
minimum?: number;
|
|
495
|
+
maximum?: number;
|
|
496
|
+
exclusiveMinimum?: number;
|
|
497
|
+
exclusiveMaximum?: number;
|
|
498
|
+
enum?: readonly (string | number | boolean | null)[];
|
|
499
|
+
const?: string | number | boolean | null;
|
|
500
|
+
properties?: Record<string, JSONSchema7>;
|
|
501
|
+
required?: string[];
|
|
502
|
+
additionalProperties?: boolean | JSONSchema7;
|
|
503
|
+
items?: JSONSchema7 | JSONSchema7[];
|
|
504
|
+
minItems?: number;
|
|
505
|
+
maxItems?: number;
|
|
506
|
+
allOf?: JSONSchema7[];
|
|
507
|
+
anyOf?: JSONSchema7[];
|
|
508
|
+
oneOf?: JSONSchema7[];
|
|
509
|
+
not?: JSONSchema7;
|
|
510
|
+
if?: JSONSchema7;
|
|
511
|
+
then?: JSONSchema7;
|
|
512
|
+
else?: JSONSchema7;
|
|
513
|
+
format?: string;
|
|
514
|
+
default?: unknown;
|
|
515
|
+
/**
|
|
516
|
+
* Data source key for dynamic enum fields.
|
|
517
|
+
* Indicates that options should be fetched from a registered resolver.
|
|
518
|
+
*/
|
|
519
|
+
"x-formspec-source"?: string;
|
|
520
|
+
/**
|
|
521
|
+
* Field names whose values are needed to fetch dynamic enum options.
|
|
522
|
+
* Used for dependent/cascading dropdowns.
|
|
523
|
+
*/
|
|
524
|
+
"x-formspec-params"?: readonly string[];
|
|
525
|
+
/**
|
|
526
|
+
* Schema source identifier for dynamic schema fields.
|
|
527
|
+
* Indicates that the schema should be loaded dynamically at runtime.
|
|
528
|
+
*/
|
|
529
|
+
"x-formspec-schemaSource"?: string;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export declare const jsonSchema7Schema: z.ZodType<JSONSchema7>;
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* JSON Schema Draft-07 type definitions.
|
|
536
|
+
*
|
|
537
|
+
* These types are a subset of JSON Schema sufficient for form generation.
|
|
538
|
+
*/
|
|
539
|
+
/**
|
|
540
|
+
* JSON Schema primitive types.
|
|
541
|
+
*/
|
|
542
|
+
export declare type JSONSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Zod schema for JSON Schema primitive type strings.
|
|
546
|
+
*/
|
|
547
|
+
export declare const jsonSchemaTypeSchema: z.ZodEnum<["string", "number", "integer", "boolean", "object", "array", "null"]>;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* A Label element for displaying static text.
|
|
551
|
+
*/
|
|
552
|
+
export declare type LabelElement = z.infer<typeof labelElementSchema>;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Zod schema for a Label element.
|
|
556
|
+
*/
|
|
557
|
+
export declare const labelElementSchema: z.ZodObject<{
|
|
558
|
+
type: z.ZodLiteral<"Label">;
|
|
559
|
+
text: z.ZodString;
|
|
560
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
561
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
562
|
+
condition: z.ZodObject<{
|
|
563
|
+
scope: z.ZodString;
|
|
564
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
565
|
+
}, "strict", z.ZodTypeAny, {
|
|
566
|
+
schema: RuleConditionSchema;
|
|
567
|
+
scope: string;
|
|
568
|
+
}, {
|
|
569
|
+
schema: RuleConditionSchema;
|
|
570
|
+
scope: string;
|
|
571
|
+
}>;
|
|
572
|
+
}, "strict", z.ZodTypeAny, {
|
|
573
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
574
|
+
condition: {
|
|
575
|
+
schema: RuleConditionSchema;
|
|
576
|
+
scope: string;
|
|
577
|
+
};
|
|
578
|
+
}, {
|
|
579
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
580
|
+
condition: {
|
|
581
|
+
schema: RuleConditionSchema;
|
|
582
|
+
scope: string;
|
|
583
|
+
};
|
|
584
|
+
}>>;
|
|
585
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
586
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
587
|
+
type: z.ZodLiteral<"Label">;
|
|
588
|
+
text: z.ZodString;
|
|
589
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
590
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
591
|
+
condition: z.ZodObject<{
|
|
592
|
+
scope: z.ZodString;
|
|
593
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
594
|
+
}, "strict", z.ZodTypeAny, {
|
|
595
|
+
schema: RuleConditionSchema;
|
|
596
|
+
scope: string;
|
|
597
|
+
}, {
|
|
598
|
+
schema: RuleConditionSchema;
|
|
599
|
+
scope: string;
|
|
600
|
+
}>;
|
|
601
|
+
}, "strict", z.ZodTypeAny, {
|
|
602
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
603
|
+
condition: {
|
|
604
|
+
schema: RuleConditionSchema;
|
|
605
|
+
scope: string;
|
|
606
|
+
};
|
|
607
|
+
}, {
|
|
608
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
609
|
+
condition: {
|
|
610
|
+
schema: RuleConditionSchema;
|
|
611
|
+
scope: string;
|
|
612
|
+
};
|
|
613
|
+
}>>;
|
|
614
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
615
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
616
|
+
type: z.ZodLiteral<"Label">;
|
|
617
|
+
text: z.ZodString;
|
|
618
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
619
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
620
|
+
condition: z.ZodObject<{
|
|
621
|
+
scope: z.ZodString;
|
|
622
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
623
|
+
}, "strict", z.ZodTypeAny, {
|
|
624
|
+
schema: RuleConditionSchema;
|
|
625
|
+
scope: string;
|
|
626
|
+
}, {
|
|
627
|
+
schema: RuleConditionSchema;
|
|
628
|
+
scope: string;
|
|
629
|
+
}>;
|
|
630
|
+
}, "strict", z.ZodTypeAny, {
|
|
631
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
632
|
+
condition: {
|
|
633
|
+
schema: RuleConditionSchema;
|
|
634
|
+
scope: string;
|
|
635
|
+
};
|
|
636
|
+
}, {
|
|
637
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
638
|
+
condition: {
|
|
639
|
+
schema: RuleConditionSchema;
|
|
640
|
+
scope: string;
|
|
641
|
+
};
|
|
642
|
+
}>>;
|
|
643
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
644
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Rule for conditional element visibility/enablement.
|
|
648
|
+
*/
|
|
649
|
+
export declare type Rule = z.infer<typeof ruleSchema>;
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* JSON Schema subset used in rule conditions.
|
|
653
|
+
*/
|
|
654
|
+
export declare interface RuleConditionSchema {
|
|
655
|
+
const?: unknown;
|
|
656
|
+
enum?: readonly unknown[];
|
|
657
|
+
type?: string;
|
|
658
|
+
not?: RuleConditionSchema;
|
|
659
|
+
minimum?: number;
|
|
660
|
+
maximum?: number;
|
|
661
|
+
exclusiveMinimum?: number;
|
|
662
|
+
exclusiveMaximum?: number;
|
|
663
|
+
minLength?: number;
|
|
664
|
+
properties?: Record<string, RuleConditionSchema>;
|
|
665
|
+
required?: string[];
|
|
666
|
+
allOf?: RuleConditionSchema[];
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export declare const ruleConditionSchema: z.ZodType<RuleConditionSchema>;
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Rule effect types for conditional visibility.
|
|
673
|
+
*/
|
|
674
|
+
export declare type RuleEffect = z.infer<typeof ruleEffectSchema>;
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Zod schema for rule effect values.
|
|
678
|
+
*/
|
|
679
|
+
export declare const ruleEffectSchema: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Zod schema for a UI Schema rule.
|
|
683
|
+
*/
|
|
684
|
+
export declare const ruleSchema: z.ZodObject<{
|
|
685
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
686
|
+
condition: z.ZodObject<{
|
|
687
|
+
scope: z.ZodString;
|
|
688
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
689
|
+
}, "strict", z.ZodTypeAny, {
|
|
690
|
+
schema: RuleConditionSchema;
|
|
691
|
+
scope: string;
|
|
692
|
+
}, {
|
|
693
|
+
schema: RuleConditionSchema;
|
|
694
|
+
scope: string;
|
|
695
|
+
}>;
|
|
696
|
+
}, "strict", z.ZodTypeAny, {
|
|
697
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
698
|
+
condition: {
|
|
699
|
+
schema: RuleConditionSchema;
|
|
700
|
+
scope: string;
|
|
701
|
+
};
|
|
702
|
+
}, {
|
|
703
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
704
|
+
condition: {
|
|
705
|
+
schema: RuleConditionSchema;
|
|
706
|
+
scope: string;
|
|
707
|
+
};
|
|
708
|
+
}>;
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Runs the code generation.
|
|
712
|
+
*/
|
|
713
|
+
export declare function runCodegen(options: CodegenOptions): void;
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Condition for a rule.
|
|
717
|
+
*/
|
|
718
|
+
export declare type SchemaBasedCondition = z.infer<typeof schemaBasedConditionSchema>;
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Zod schema for a schema-based rule condition.
|
|
722
|
+
*/
|
|
723
|
+
export declare const schemaBasedConditionSchema: z.ZodObject<{
|
|
724
|
+
scope: z.ZodString;
|
|
725
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
726
|
+
}, "strict", z.ZodTypeAny, {
|
|
727
|
+
schema: RuleConditionSchema;
|
|
728
|
+
scope: string;
|
|
729
|
+
}, {
|
|
730
|
+
schema: RuleConditionSchema;
|
|
731
|
+
scope: string;
|
|
732
|
+
}>;
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Sets a FormSpec extension property on a JSON Schema node.
|
|
736
|
+
*
|
|
737
|
+
* Use this to safely add `x-formspec-*` properties to any schema,
|
|
738
|
+
* including nested schemas typed as `JSONSchema7` (which don't carry
|
|
739
|
+
* the extension index signature).
|
|
740
|
+
*
|
|
741
|
+
* @param schema - Any JSON Schema node
|
|
742
|
+
* @param key - Extension key (must start with `x-formspec-`)
|
|
743
|
+
* @param value - Extension value
|
|
744
|
+
*/
|
|
745
|
+
export declare function setSchemaExtension(schema: JSONSchema7, key: `x-formspec-${string}`, value: unknown): void;
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Code generation for FormSpec type metadata.
|
|
749
|
+
*
|
|
750
|
+
* Generates a TypeScript file that patches decorated classes with
|
|
751
|
+
* their extracted type metadata, enabling runtime schema generation
|
|
752
|
+
* as an alternative to a TypeScript transformer.
|
|
753
|
+
*
|
|
754
|
+
* Usage:
|
|
755
|
+
* formspec codegen ./src/forms.ts -o ./src/__formspec_types__.ts
|
|
756
|
+
*
|
|
757
|
+
* Then in your code:
|
|
758
|
+
* import './__formspec_types__'; // Patches all decorated classes
|
|
759
|
+
* import { UserFormSchema, getUserFormFormSpec } from './__formspec_types__';
|
|
760
|
+
* const spec = getUserFormFormSpec();
|
|
761
|
+
*/
|
|
762
|
+
/**
|
|
763
|
+
* Type metadata format used by `@formspec/decorators`.
|
|
764
|
+
*
|
|
765
|
+
* Represents the runtime type information for a field that TypeScript
|
|
766
|
+
* normally erases at compile time.
|
|
767
|
+
*/
|
|
768
|
+
export declare interface TypeMetadata {
|
|
769
|
+
/** Base type: "string", "number", "boolean", "enum", "array", "object", "unknown" */
|
|
770
|
+
type: string;
|
|
771
|
+
/** For enum types, the possible literal values */
|
|
772
|
+
values?: unknown[];
|
|
773
|
+
/** For array types, metadata about the array element type */
|
|
774
|
+
itemType?: TypeMetadata;
|
|
775
|
+
/** For object types, metadata about each property */
|
|
776
|
+
properties?: Record<string, TypeMetadata>;
|
|
777
|
+
/** Whether the field accepts null */
|
|
778
|
+
nullable?: boolean;
|
|
779
|
+
/** Whether the field is optional (T | undefined or ?: modifier) */
|
|
780
|
+
optional?: boolean;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Root UI Schema (always a layout — not a Control, Category, or Label).
|
|
785
|
+
*/
|
|
786
|
+
export declare type UISchema = VerticalLayout | HorizontalLayout | GroupLayout | Categorization;
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Union of all UI Schema element types.
|
|
790
|
+
*/
|
|
791
|
+
export declare type UISchemaElement = ControlElement | VerticalLayout | HorizontalLayout | GroupLayout | Categorization | Category | LabelElement;
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Base interface for all UI Schema elements.
|
|
795
|
+
*
|
|
796
|
+
* This is a manually maintained interface representing the common shape
|
|
797
|
+
* shared by all element types. It is kept as an interface (rather than
|
|
798
|
+
* derived from Zod) because it is the base of a discriminated union, not
|
|
799
|
+
* a union member itself.
|
|
800
|
+
*/
|
|
801
|
+
export declare interface UISchemaElementBase {
|
|
802
|
+
type: UISchemaElementType;
|
|
803
|
+
rule?: Rule;
|
|
804
|
+
options?: Record<string, unknown>;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
export declare const uiSchemaElementSchema: z.ZodType<UISchemaElement>;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* UI Schema element types.
|
|
811
|
+
*/
|
|
812
|
+
export declare type UISchemaElementType = z.infer<typeof uiSchemaElementTypeSchema>;
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Zod schema for UI Schema element type strings.
|
|
816
|
+
*/
|
|
817
|
+
export declare const uiSchemaElementTypeSchema: z.ZodEnum<["Control", "VerticalLayout", "HorizontalLayout", "Group", "Categorization", "Category", "Label"]>;
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Zod schema for the root UI Schema (layout types only).
|
|
821
|
+
*/
|
|
822
|
+
export declare const uiSchemaSchema: z.ZodType<UISchema>;
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* A vertical layout element.
|
|
826
|
+
*/
|
|
827
|
+
export declare interface VerticalLayout {
|
|
828
|
+
type: "VerticalLayout";
|
|
829
|
+
elements: UISchemaElement[];
|
|
830
|
+
rule?: Rule | undefined;
|
|
831
|
+
options?: Record<string, unknown> | undefined;
|
|
832
|
+
[k: string]: unknown;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
export declare const verticalLayoutSchema: z.ZodType<VerticalLayout>;
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Builds and writes both JSON Schema and UI Schema files to disk.
|
|
839
|
+
*
|
|
840
|
+
* This is a convenience function for build-time schema generation.
|
|
841
|
+
* It creates the output directory if it doesn't exist.
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```typescript
|
|
845
|
+
* import { formspec, field } from "formspec";
|
|
846
|
+
* import { writeSchemas } from "@formspec/build";
|
|
847
|
+
*
|
|
848
|
+
* const ProductForm = formspec(
|
|
849
|
+
* field.text("name", { required: true }),
|
|
850
|
+
* field.enum("status", ["draft", "active"]),
|
|
851
|
+
* );
|
|
852
|
+
*
|
|
853
|
+
* // Write schemas to ./generated/product-schema.json and ./generated/product-uischema.json
|
|
854
|
+
* const { jsonSchemaPath, uiSchemaPath } = writeSchemas(ProductForm, {
|
|
855
|
+
* outDir: "./generated",
|
|
856
|
+
* name: "product",
|
|
857
|
+
* });
|
|
858
|
+
*
|
|
859
|
+
* console.log(`Generated: ${jsonSchemaPath}, ${uiSchemaPath}`);
|
|
860
|
+
* ```
|
|
861
|
+
*
|
|
862
|
+
* @param form - The FormSpec to build schemas from
|
|
863
|
+
* @param options - Output options (directory, file name, indentation)
|
|
864
|
+
* @returns Object containing paths to the generated files
|
|
865
|
+
*/
|
|
866
|
+
export declare function writeSchemas<E extends readonly FormElement[]>(form: FormSpec<E>, options: WriteSchemasOptions): WriteSchemasResult;
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Options for writing schemas to disk.
|
|
870
|
+
*/
|
|
871
|
+
export declare interface WriteSchemasOptions {
|
|
872
|
+
/** Output directory for the schema files */
|
|
873
|
+
readonly outDir: string;
|
|
874
|
+
/** Base name for the output files (without extension). Defaults to "schema" */
|
|
875
|
+
readonly name?: string;
|
|
876
|
+
/** Number of spaces for JSON indentation. Defaults to 2 */
|
|
877
|
+
readonly indent?: number;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Result of writing schemas to disk.
|
|
882
|
+
*/
|
|
883
|
+
export declare interface WriteSchemasResult {
|
|
884
|
+
/** Path to the generated JSON Schema file */
|
|
885
|
+
readonly jsonSchemaPath: string;
|
|
886
|
+
/** Path to the generated UI Schema file */
|
|
887
|
+
readonly uiSchemaPath: string;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
export { }
|