@formspec/build 0.1.0-alpha.4 → 0.1.0-alpha.40
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/LICENSE +21 -0
- package/README.md +238 -93
- package/dist/analyzer/class-analyzer.d.ts +135 -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 +94 -0
- package/dist/analyzer/program.d.ts.map +1 -0
- package/dist/analyzer/tsdoc-parser.d.ts +126 -0
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
- package/dist/browser.cjs +1904 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.ts +74 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1861 -0
- package/dist/browser.js.map +1 -0
- package/dist/build-alpha.d.ts +1491 -0
- package/dist/build-beta.d.ts +1491 -0
- package/dist/build-internal.d.ts +1491 -0
- package/dist/build.d.ts +1184 -43
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +22 -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 +38 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
- package/dist/cli.cjs +6579 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +6551 -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 +83 -0
- package/dist/extensions/registry.d.ts.map +1 -0
- package/dist/generators/class-schema.d.ts +342 -0
- package/dist/generators/class-schema.d.ts.map +1 -0
- package/dist/generators/discovered-schema.d.ts +152 -0
- package/dist/generators/discovered-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 +52 -0
- package/dist/generators/mixed-authoring.d.ts.map +1 -0
- package/dist/index.cjs +6293 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +50 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6268 -107
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +5480 -0
- package/dist/internals.cjs.map +1 -0
- package/dist/internals.d.ts +32 -0
- package/dist/internals.d.ts.map +1 -0
- package/dist/internals.js +5461 -0
- package/dist/internals.js.map +1 -0
- package/dist/json-schema/generator.d.ts +27 -6
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/json-schema/ir-generator.d.ts +144 -0
- package/dist/json-schema/ir-generator.d.ts.map +1 -0
- package/dist/json-schema/schema.d.ts +23 -0
- package/dist/json-schema/schema.d.ts.map +1 -0
- package/dist/json-schema/types.d.ts +76 -2
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/metadata/collision-guards.d.ts +3 -0
- package/dist/metadata/collision-guards.d.ts.map +1 -0
- package/dist/metadata/index.d.ts +7 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/policy.d.ts +11 -0
- package/dist/metadata/policy.d.ts.map +1 -0
- package/dist/metadata/resolve.d.ts +20 -0
- package/dist/metadata/resolve.d.ts.map +1 -0
- package/dist/static-build.d.ts +61 -0
- package/dist/static-build.d.ts.map +1 -0
- package/dist/ui-schema/generator.d.ts +18 -2
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/ir-generator.d.ts +54 -0
- package/dist/ui-schema/ir-generator.d.ts.map +1 -0
- package/dist/ui-schema/schema.d.ts +429 -0
- package/dist/ui-schema/schema.d.ts.map +1 -0
- package/dist/ui-schema/types.d.ts +179 -35
- package/dist/ui-schema/types.d.ts.map +1 -1
- package/dist/validate/constraint-validator.d.ts +85 -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 +31 -11
- package/dist/__tests__/cli.test.d.ts +0 -2
- package/dist/__tests__/cli.test.d.ts.map +0 -1
- package/dist/__tests__/cli.test.js +0 -178
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/__tests__/edge-cases.test.d.ts +0 -7
- package/dist/__tests__/edge-cases.test.d.ts.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.d.ts +0 -2
- package/dist/__tests__/generator.test.d.ts.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.d.ts +0 -8
- package/dist/__tests__/integration.test.d.ts.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.d.ts +0 -2
- package/dist/__tests__/write-schemas.test.d.ts.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
|
@@ -0,0 +1,1491 @@
|
|
|
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 { AnyField } from '@formspec/core';
|
|
27
|
+
import { ArrayField } from '@formspec/core';
|
|
28
|
+
import { BooleanField } from '@formspec/core';
|
|
29
|
+
import { BuiltinConstraintBroadeningRegistration } from '@formspec/core';
|
|
30
|
+
import { Conditional } from '@formspec/core';
|
|
31
|
+
import { ConstraintTagRegistration } from '@formspec/core';
|
|
32
|
+
import { CustomAnnotationRegistration } from '@formspec/core';
|
|
33
|
+
import { CustomConstraintRegistration } from '@formspec/core';
|
|
34
|
+
import { CustomTypeRegistration } from '@formspec/core';
|
|
35
|
+
import { DynamicEnumField } from '@formspec/core';
|
|
36
|
+
import { DynamicSchemaField } from '@formspec/core';
|
|
37
|
+
import { EnumOption } from '@formspec/core';
|
|
38
|
+
import { EnumOptionValue } from '@formspec/core';
|
|
39
|
+
import { ExtensionDefinition } from '@formspec/core';
|
|
40
|
+
import { FormElement } from '@formspec/core';
|
|
41
|
+
import { FormSpec } from '@formspec/core';
|
|
42
|
+
import { Group } from '@formspec/core';
|
|
43
|
+
import type { MetadataPolicyInput } from '@formspec/core';
|
|
44
|
+
import { NumberField } from '@formspec/core';
|
|
45
|
+
import { ObjectField } from '@formspec/core';
|
|
46
|
+
import type { ResolvedMetadata } from '@formspec/core';
|
|
47
|
+
import { StaticEnumField } from '@formspec/core';
|
|
48
|
+
import { TextField } from '@formspec/core';
|
|
49
|
+
import * as ts from 'typescript';
|
|
50
|
+
import { z } from 'zod';
|
|
51
|
+
|
|
52
|
+
export { AnyField }
|
|
53
|
+
|
|
54
|
+
export { ArrayField }
|
|
55
|
+
|
|
56
|
+
export { BooleanField }
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Builds both JSON Schema and UI Schema from a FormSpec.
|
|
60
|
+
*
|
|
61
|
+
* This is a convenience function that combines `generateJsonSchema`
|
|
62
|
+
* and `generateUiSchema`.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const form = formspec(
|
|
67
|
+
* field.text("name", { required: true }),
|
|
68
|
+
* field.number("age", { min: 0 }),
|
|
69
|
+
* );
|
|
70
|
+
*
|
|
71
|
+
* const { jsonSchema, uiSchema } = buildFormSchemas(form);
|
|
72
|
+
*
|
|
73
|
+
* // Use with JSON Forms renderer
|
|
74
|
+
* <JsonForms
|
|
75
|
+
* schema={jsonSchema}
|
|
76
|
+
* uischema={uiSchema}
|
|
77
|
+
* data={formData}
|
|
78
|
+
* renderers={materialRenderers}
|
|
79
|
+
* />
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param form - The FormSpec to build schemas from
|
|
83
|
+
* @returns Object containing both jsonSchema and uiSchema
|
|
84
|
+
*
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
export declare function buildFormSchemas<E extends readonly FormElement[]>(form: FormSpec<E>, options?: BuildFormSchemasOptions): BuildResult;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Options for building schemas from a FormSpec.
|
|
91
|
+
*
|
|
92
|
+
* Currently identical to `GenerateJsonSchemaOptions`. Defined separately so the
|
|
93
|
+
* Chain DSL surface can grow independently in the future if needed.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export declare interface BuildFormSchemasOptions extends GenerateJsonSchemaOptions, GenerateUiSchemaOptions {
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Builds JSON Schema and UI Schema from a TSDoc-derived model with ChainDSL
|
|
102
|
+
* field overlays.
|
|
103
|
+
*
|
|
104
|
+
* Overlays are matched by field name. The static model wins for structure,
|
|
105
|
+
* ordering, and constraints; ChainDSL overlays may contribute dynamic runtime
|
|
106
|
+
* field metadata such as dynamic enum or dynamic schema keywords, and may fill
|
|
107
|
+
* in missing annotations.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export declare function buildMixedAuthoringSchemas(options: BuildMixedAuthoringSchemasOptions): MixedAuthoringSchemas;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Options for generating mixed-authoring schemas.
|
|
115
|
+
*
|
|
116
|
+
* The `typeName` can resolve to a class, interface, or object type alias, just
|
|
117
|
+
* like `generateSchemas()`.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
export declare interface BuildMixedAuthoringSchemasOptions extends StaticSchemaGenerationOptions {
|
|
122
|
+
/** Path to the TypeScript source file. */
|
|
123
|
+
readonly filePath: string;
|
|
124
|
+
/** Name of the class, interface, or type alias to analyze. */
|
|
125
|
+
readonly typeName: string;
|
|
126
|
+
/** ChainDSL overlays to apply to the static model. Groups and conditionals are flattened by field name. */
|
|
127
|
+
readonly overlays: FormSpec<readonly FormElement[]>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Result of building form schemas.
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export declare interface BuildResult {
|
|
136
|
+
/** JSON Schema 2020-12 for validation */
|
|
137
|
+
readonly jsonSchema: JsonSchema2020;
|
|
138
|
+
/** JSON Forms UI Schema for rendering */
|
|
139
|
+
readonly uiSchema: UISchema;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { BuiltinConstraintBroadeningRegistration }
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* A Categorization element (tab-based layout).
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
export declare interface Categorization {
|
|
150
|
+
/** Discriminator identifying a categorization layout. */
|
|
151
|
+
readonly type: "Categorization";
|
|
152
|
+
/** Categories rendered as tabs or steps. */
|
|
153
|
+
readonly elements: Category[];
|
|
154
|
+
/** Optional label for the overall categorization container. */
|
|
155
|
+
readonly label?: string | undefined;
|
|
156
|
+
/** Optional rule controlling visibility or enablement. */
|
|
157
|
+
readonly rule?: Rule | undefined;
|
|
158
|
+
/** Renderer-specific categorization options. */
|
|
159
|
+
readonly options?: Record<string, unknown> | undefined;
|
|
160
|
+
/** Additional renderer-specific extension properties. */
|
|
161
|
+
readonly [k: string]: unknown;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A Category element, used inside a Categorization layout.
|
|
166
|
+
*
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
export declare interface Category {
|
|
170
|
+
/** Discriminator identifying a category inside a categorization layout. */
|
|
171
|
+
readonly type: "Category";
|
|
172
|
+
/** Category label shown in tabs or step navigation. */
|
|
173
|
+
readonly label: string;
|
|
174
|
+
/** Child elements rendered inside the category. */
|
|
175
|
+
readonly elements: UISchemaElement[];
|
|
176
|
+
/** Optional rule controlling visibility or enablement. */
|
|
177
|
+
readonly rule?: Rule | undefined;
|
|
178
|
+
/** Renderer-specific category options. */
|
|
179
|
+
readonly options?: Record<string, unknown> | undefined;
|
|
180
|
+
/** Additional renderer-specific extension properties. */
|
|
181
|
+
readonly [k: string]: unknown;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { Conditional }
|
|
185
|
+
|
|
186
|
+
export { ConstraintTagRegistration }
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A Control element that binds to a JSON Schema property.
|
|
190
|
+
*
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
export declare interface ControlElement {
|
|
194
|
+
/** Discriminator identifying a JSON Forms control element. */
|
|
195
|
+
readonly type: "Control";
|
|
196
|
+
/** JSON Pointer scope that this control binds to. */
|
|
197
|
+
readonly scope: string;
|
|
198
|
+
/** Optional label override, or `false` to suppress the label. */
|
|
199
|
+
readonly label?: string | false | undefined;
|
|
200
|
+
/** Optional rule controlling visibility or enablement. */
|
|
201
|
+
readonly rule?: Rule | undefined;
|
|
202
|
+
/** Renderer-specific control options. */
|
|
203
|
+
readonly options?: Record<string, unknown> | undefined;
|
|
204
|
+
/** Additional renderer-specific extension properties. */
|
|
205
|
+
readonly [k: string]: unknown;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Creates an extension registry from a list of extension definitions.
|
|
210
|
+
*
|
|
211
|
+
* The registry indexes all types, constraints, and annotations by their
|
|
212
|
+
* fully-qualified IDs (`<extensionId>/<name>`) for O(1) lookup during
|
|
213
|
+
* generation and validation.
|
|
214
|
+
*
|
|
215
|
+
* @param extensions - The extension definitions to register.
|
|
216
|
+
* @returns An {@link ExtensionRegistry} instance.
|
|
217
|
+
* @throws If duplicate type/constraint/annotation IDs are detected across extensions.
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
export declare function createExtensionRegistry(extensions: readonly ExtensionDefinition[]): ExtensionRegistry;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Creates a supported static build context for a source file.
|
|
225
|
+
*
|
|
226
|
+
* @param filePath - Entry TypeScript source file used for export resolution
|
|
227
|
+
* @returns Reusable build context containing the program, checker, and source file
|
|
228
|
+
*
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
export declare function createStaticBuildContext(filePath: string): StaticBuildContext;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Creates a supported static build context from an existing host-owned program.
|
|
235
|
+
*
|
|
236
|
+
* @param program - Existing TypeScript program supplied by the caller
|
|
237
|
+
* @param filePath - Entry TypeScript source file used for export resolution
|
|
238
|
+
* @returns Reusable build context containing the program, checker, and source file
|
|
239
|
+
*
|
|
240
|
+
* @public
|
|
241
|
+
*/
|
|
242
|
+
export declare function createStaticBuildContextFromProgram(program: ts.Program, filePath: string): StaticBuildContext;
|
|
243
|
+
|
|
244
|
+
export { CustomAnnotationRegistration }
|
|
245
|
+
|
|
246
|
+
export { CustomConstraintRegistration }
|
|
247
|
+
|
|
248
|
+
export { CustomTypeRegistration }
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Non-throwing schema generation result with structured diagnostics.
|
|
252
|
+
*
|
|
253
|
+
* @public
|
|
254
|
+
*/
|
|
255
|
+
export declare interface DetailedClassSchemasResult {
|
|
256
|
+
/** Whether schema generation completed without error-severity diagnostics. */
|
|
257
|
+
readonly ok: boolean;
|
|
258
|
+
/** Collected analysis and validation diagnostics for this target. */
|
|
259
|
+
readonly diagnostics: readonly ValidationDiagnostic[];
|
|
260
|
+
/** JSON Schema 2020-12 for validation, when generation succeeds. */
|
|
261
|
+
readonly jsonSchema?: JsonSchema2020 | undefined;
|
|
262
|
+
/** JSON Forms UI Schema for rendering, when generation succeeds. */
|
|
263
|
+
readonly uiSchema?: UISchema | undefined;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Result for a single target in a batch generation request.
|
|
268
|
+
*
|
|
269
|
+
* @public
|
|
270
|
+
*/
|
|
271
|
+
export declare interface DetailedSchemaGenerationTargetResult extends DetailedClassSchemasResult {
|
|
272
|
+
/** Path to the TypeScript source file. */
|
|
273
|
+
readonly filePath: string;
|
|
274
|
+
/** Name of the exported class, interface, or type alias that was analyzed. */
|
|
275
|
+
readonly typeName: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Generated schemas for a discovered declaration or signature type.
|
|
280
|
+
*
|
|
281
|
+
* `uiSchema` is `null` when the discovered type does not have an object-shaped
|
|
282
|
+
* root that can be represented as a JSON Forms layout.
|
|
283
|
+
*
|
|
284
|
+
* @public
|
|
285
|
+
*/
|
|
286
|
+
export declare interface DiscoveredTypeSchemas {
|
|
287
|
+
/** JSON Schema 2020-12 for the resolved type. */
|
|
288
|
+
readonly jsonSchema: JsonSchema2020;
|
|
289
|
+
/** UI Schema for object-shaped roots, or `null` when not applicable. */
|
|
290
|
+
readonly uiSchema: UISchema | null;
|
|
291
|
+
/**
|
|
292
|
+
* Resolved type-level metadata used during generation, when available.
|
|
293
|
+
*
|
|
294
|
+
* This preserves explicit and inferred naming metadata such as singular and
|
|
295
|
+
* plural API/display names for consumers that need the resolved values in
|
|
296
|
+
* addition to the emitted schema artifacts.
|
|
297
|
+
*/
|
|
298
|
+
readonly resolvedMetadata?: ResolvedMetadata | undefined;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Discriminator-specific schema generation options.
|
|
303
|
+
*
|
|
304
|
+
* @public
|
|
305
|
+
*/
|
|
306
|
+
export declare interface DiscriminatorResolutionOptions {
|
|
307
|
+
/**
|
|
308
|
+
* Optional prefix applied only to metadata-derived discriminator values.
|
|
309
|
+
*
|
|
310
|
+
* Literal discriminator identities taken directly from a bound type remain
|
|
311
|
+
* unchanged.
|
|
312
|
+
*/
|
|
313
|
+
readonly apiNamePrefix?: string | undefined;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export { DynamicEnumField }
|
|
317
|
+
|
|
318
|
+
export { DynamicSchemaField }
|
|
319
|
+
|
|
320
|
+
export { EnumOption }
|
|
321
|
+
|
|
322
|
+
export { EnumOptionValue }
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* JSON Schema with FormSpec extension properties for arbitrary `x-formspec-*` keys.
|
|
326
|
+
*
|
|
327
|
+
* @public
|
|
328
|
+
*/
|
|
329
|
+
export declare type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;
|
|
330
|
+
|
|
331
|
+
export { ExtensionDefinition }
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* A registry of extensions that provides lookup by fully-qualified ID.
|
|
335
|
+
*
|
|
336
|
+
* Type IDs follow the format: `<extensionId>/<typeName>`
|
|
337
|
+
* Constraint IDs follow the format: `<extensionId>/<constraintName>`
|
|
338
|
+
* Annotation IDs follow the format: `<extensionId>/<annotationName>`
|
|
339
|
+
*
|
|
340
|
+
* @public
|
|
341
|
+
*/
|
|
342
|
+
export declare interface ExtensionRegistry {
|
|
343
|
+
/** The extensions registered in this registry (in registration order). */
|
|
344
|
+
readonly extensions: readonly ExtensionDefinition[];
|
|
345
|
+
/**
|
|
346
|
+
* Look up a custom type registration by its fully-qualified type ID.
|
|
347
|
+
*
|
|
348
|
+
* @param typeId - The fully-qualified type ID (e.g., "x-stripe/monetary/Decimal").
|
|
349
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
350
|
+
*/
|
|
351
|
+
findType(typeId: string): CustomTypeRegistration | undefined;
|
|
352
|
+
/**
|
|
353
|
+
* Look up a custom type registration by a TypeScript-facing type name.
|
|
354
|
+
*
|
|
355
|
+
* This is used during TSDoc/class analysis to resolve extension-defined
|
|
356
|
+
* custom types from source-level declarations.
|
|
357
|
+
*/
|
|
358
|
+
findTypeByName(typeName: string): {
|
|
359
|
+
readonly extensionId: string;
|
|
360
|
+
readonly registration: CustomTypeRegistration;
|
|
361
|
+
} | undefined;
|
|
362
|
+
/**
|
|
363
|
+
* Look up a custom constraint registration by its fully-qualified constraint ID.
|
|
364
|
+
*
|
|
365
|
+
* @param constraintId - The fully-qualified constraint ID.
|
|
366
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
367
|
+
*/
|
|
368
|
+
findConstraint(constraintId: string): CustomConstraintRegistration | undefined;
|
|
369
|
+
/**
|
|
370
|
+
* Look up a TSDoc custom constraint-tag registration by tag name.
|
|
371
|
+
*/
|
|
372
|
+
findConstraintTag(tagName: string): {
|
|
373
|
+
readonly extensionId: string;
|
|
374
|
+
readonly registration: ConstraintTagRegistration;
|
|
375
|
+
} | undefined;
|
|
376
|
+
/**
|
|
377
|
+
* Look up built-in tag broadening for a given custom type ID.
|
|
378
|
+
*/
|
|
379
|
+
findBuiltinConstraintBroadening(typeId: string, tagName: string): {
|
|
380
|
+
readonly extensionId: string;
|
|
381
|
+
readonly registration: BuiltinConstraintBroadeningRegistration;
|
|
382
|
+
} | undefined;
|
|
383
|
+
/**
|
|
384
|
+
* Look up a custom annotation registration by its fully-qualified annotation ID.
|
|
385
|
+
*
|
|
386
|
+
* @param annotationId - The fully-qualified annotation ID.
|
|
387
|
+
* @returns The registration if found, otherwise `undefined`.
|
|
388
|
+
*/
|
|
389
|
+
findAnnotation(annotationId: string): CustomAnnotationRegistration | undefined;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export { FormElement }
|
|
393
|
+
|
|
394
|
+
export { FormSpec }
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Extension properties for custom FormSpec constraint tags.
|
|
398
|
+
*
|
|
399
|
+
* @public
|
|
400
|
+
*/
|
|
401
|
+
export declare type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Options for generating schemas from a decorated class.
|
|
405
|
+
*
|
|
406
|
+
* @public
|
|
407
|
+
*/
|
|
408
|
+
export declare interface GenerateFromClassOptions extends StaticSchemaGenerationOptions {
|
|
409
|
+
/** Path to the TypeScript source file */
|
|
410
|
+
filePath: string;
|
|
411
|
+
/** Class name to analyze */
|
|
412
|
+
className: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Result of generating schemas from a decorated class.
|
|
417
|
+
*
|
|
418
|
+
* @public
|
|
419
|
+
*/
|
|
420
|
+
export declare interface GenerateFromClassResult {
|
|
421
|
+
/** JSON Schema 2020-12 for validation */
|
|
422
|
+
jsonSchema: JsonSchema2020;
|
|
423
|
+
/** JSON Forms UI Schema for rendering */
|
|
424
|
+
uiSchema: UISchema;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Generates a JSON Schema 2020-12 from a FormSpec.
|
|
429
|
+
*
|
|
430
|
+
* All generation routes through the canonical IR. The chain DSL is first
|
|
431
|
+
* canonicalized to a FormIR, then the IR-based generator produces the schema.
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```typescript
|
|
435
|
+
* const form = formspec(
|
|
436
|
+
* field.text("name", { label: "Name", required: true }),
|
|
437
|
+
* field.number("age", { min: 0 }),
|
|
438
|
+
* );
|
|
439
|
+
*
|
|
440
|
+
* const schema = generateJsonSchema(form);
|
|
441
|
+
* // {
|
|
442
|
+
* // $schema: "https://json-schema.org/draft/2020-12/schema",
|
|
443
|
+
* // type: "object",
|
|
444
|
+
* // properties: {
|
|
445
|
+
* // name: { type: "string", title: "Name" },
|
|
446
|
+
* // age: { type: "number", minimum: 0 }
|
|
447
|
+
* // },
|
|
448
|
+
* // required: ["name"]
|
|
449
|
+
* // }
|
|
450
|
+
* ```
|
|
451
|
+
*
|
|
452
|
+
* @param form - The FormSpec to convert
|
|
453
|
+
* @returns A JSON Schema 2020-12 object
|
|
454
|
+
*
|
|
455
|
+
* @public
|
|
456
|
+
*/
|
|
457
|
+
export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E>, options?: GenerateJsonSchemaOptions): JsonSchema2020;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Options for generating JSON Schema from a Chain DSL form.
|
|
461
|
+
*
|
|
462
|
+
* @public
|
|
463
|
+
*/
|
|
464
|
+
export declare interface GenerateJsonSchemaOptions {
|
|
465
|
+
/**
|
|
466
|
+
* Vendor prefix for emitted extension keywords.
|
|
467
|
+
* @defaultValue "x-formspec"
|
|
468
|
+
*/
|
|
469
|
+
readonly vendorPrefix?: string | undefined;
|
|
470
|
+
/** Metadata resolution policy for chain DSL generation. */
|
|
471
|
+
readonly metadata?: MetadataPolicyInput | undefined;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Generates JSON Schema and UI Schema from a named TypeScript
|
|
476
|
+
* type — a decorated class, an interface with TSDoc tags, or a type alias.
|
|
477
|
+
*
|
|
478
|
+
* This is the recommended entry point. It automatically detects whether
|
|
479
|
+
* the name resolves to a class, interface, or type alias and uses the
|
|
480
|
+
* appropriate IR analysis pipeline.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* const result = generateSchemas({
|
|
485
|
+
* filePath: "./src/config.ts",
|
|
486
|
+
* typeName: "DiscountConfig",
|
|
487
|
+
* errorReporting: "throw",
|
|
488
|
+
* });
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
/**
|
|
492
|
+
* Generates JSON Schema and UI Schema from a named type and throws when
|
|
493
|
+
* generation reports error-severity diagnostics.
|
|
494
|
+
*
|
|
495
|
+
* @param options - File path, type name, and explicit throw-on-error reporting
|
|
496
|
+
* @returns Generated JSON Schema and UI Schema
|
|
497
|
+
*
|
|
498
|
+
* @public
|
|
499
|
+
*/
|
|
500
|
+
export declare function generateSchemas(options: GenerateSchemasOptions & {
|
|
501
|
+
readonly errorReporting: "throw";
|
|
502
|
+
}): GenerateFromClassResult;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Generates JSON Schema and UI Schema from a named type and returns structured
|
|
506
|
+
* diagnostics instead of throwing on validation or analysis failures.
|
|
507
|
+
*
|
|
508
|
+
* @param options - File path, type name, and explicit diagnostics reporting
|
|
509
|
+
* @returns Structured generation result with diagnostics
|
|
510
|
+
*
|
|
511
|
+
* @public
|
|
512
|
+
*/
|
|
513
|
+
export declare function generateSchemas(options: GenerateSchemasOptions & {
|
|
514
|
+
readonly errorReporting: "diagnostics";
|
|
515
|
+
}): DetailedClassSchemasResult;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Generates JSON Schema and UI Schema from a named type.
|
|
519
|
+
*
|
|
520
|
+
* @deprecated Pass `errorReporting` explicitly. Omitting it defaults to `"throw"` only for backward compatibility.
|
|
521
|
+
* @param options - File path and type name
|
|
522
|
+
* @returns Generated JSON Schema and UI Schema
|
|
523
|
+
*
|
|
524
|
+
* @public
|
|
525
|
+
*/
|
|
526
|
+
export declare function generateSchemas(options: StaticSchemaGenerationOptions & {
|
|
527
|
+
readonly filePath: string;
|
|
528
|
+
readonly typeName: string;
|
|
529
|
+
}): GenerateFromClassResult;
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Generates schemas for many targets and returns per-target diagnostics instead
|
|
533
|
+
* of failing on the first problem.
|
|
534
|
+
*
|
|
535
|
+
* @public
|
|
536
|
+
*/
|
|
537
|
+
export declare function generateSchemasBatch(options: GenerateSchemasBatchOptions): readonly DetailedSchemaGenerationTargetResult[];
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Generates schemas for many targets from an existing TypeScript program and
|
|
541
|
+
* returns per-target diagnostics instead of failing on the first problem.
|
|
542
|
+
*
|
|
543
|
+
* @public
|
|
544
|
+
*/
|
|
545
|
+
export declare function generateSchemasBatchFromProgram(options: GenerateSchemasBatchFromProgramOptions): readonly DetailedSchemaGenerationTargetResult[];
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Batch options for non-throwing schema generation using an existing program.
|
|
549
|
+
*
|
|
550
|
+
* @public
|
|
551
|
+
*/
|
|
552
|
+
export declare interface GenerateSchemasBatchFromProgramOptions extends StaticSchemaGenerationOptions {
|
|
553
|
+
/** Existing TypeScript program supplied by the caller. */
|
|
554
|
+
readonly program: ts.Program;
|
|
555
|
+
/** Targets to analyze and generate. */
|
|
556
|
+
readonly targets: readonly SchemaGenerationTarget[];
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Batch options for non-throwing schema generation.
|
|
561
|
+
*
|
|
562
|
+
* @public
|
|
563
|
+
*/
|
|
564
|
+
export declare interface GenerateSchemasBatchOptions extends StaticSchemaGenerationOptions {
|
|
565
|
+
/** Targets to analyze and generate. */
|
|
566
|
+
readonly targets: readonly SchemaGenerationTarget[];
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Generates JSON Schema and UI Schema from a named type and returns structured
|
|
571
|
+
* diagnostics instead of throwing on validation or analysis failures.
|
|
572
|
+
* @deprecated Use `generateSchemas({ ...options, errorReporting: "diagnostics" })` instead.
|
|
573
|
+
*
|
|
574
|
+
* @public
|
|
575
|
+
*/
|
|
576
|
+
export declare function generateSchemasDetailed(options: StaticSchemaGenerationOptions & {
|
|
577
|
+
readonly filePath: string;
|
|
578
|
+
readonly typeName: string;
|
|
579
|
+
}): DetailedClassSchemasResult;
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Generates JSON Schema and UI Schema from a decorated TypeScript class.
|
|
583
|
+
*
|
|
584
|
+
* This is a high-level entry point that handles the entire pipeline:
|
|
585
|
+
* creating a TypeScript program, finding the class, analyzing it to IR,
|
|
586
|
+
* and generating schemas — all in one call.
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```typescript
|
|
590
|
+
* const result = generateSchemasFromClass({
|
|
591
|
+
* filePath: "./src/forms.ts",
|
|
592
|
+
* className: "UserForm",
|
|
593
|
+
* });
|
|
594
|
+
* console.log(result.jsonSchema);
|
|
595
|
+
* ```
|
|
596
|
+
*
|
|
597
|
+
* @param options - File path, class name, and optional compiler options
|
|
598
|
+
* @returns Generated JSON Schema and UI Schema
|
|
599
|
+
*
|
|
600
|
+
* @public
|
|
601
|
+
*/
|
|
602
|
+
export declare function generateSchemasFromClass(options: GenerateFromClassOptions): GenerateFromClassResult;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Generates schemas from a resolved declaration using the supported public
|
|
606
|
+
* static-build workflow.
|
|
607
|
+
*
|
|
608
|
+
* Named declarations reuse the same analyzer semantics as FormSpec's existing
|
|
609
|
+
* top-level generation APIs. Non-object type aliases fall back to the generic
|
|
610
|
+
* resolved-type entry point.
|
|
611
|
+
*
|
|
612
|
+
* @public
|
|
613
|
+
*/
|
|
614
|
+
export declare function generateSchemasFromDeclaration(options: GenerateSchemasFromDeclarationOptions): DiscoveredTypeSchemas;
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Options for generating schemas from a resolved declaration.
|
|
618
|
+
*
|
|
619
|
+
* @public
|
|
620
|
+
*/
|
|
621
|
+
export declare interface GenerateSchemasFromDeclarationOptions extends StaticSchemaGenerationOptions {
|
|
622
|
+
/** Supported build context used for checker access and related analysis. */
|
|
623
|
+
readonly context: StaticBuildContext;
|
|
624
|
+
/** Declaration to turn into schemas. */
|
|
625
|
+
readonly declaration: SchemaSourceDeclaration;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Generates schemas for a method or function parameter type.
|
|
630
|
+
*
|
|
631
|
+
* @public
|
|
632
|
+
*/
|
|
633
|
+
export declare function generateSchemasFromParameter(options: GenerateSchemasFromParameterOptions): DiscoveredTypeSchemas;
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Options for generating schemas from a method or function parameter type.
|
|
637
|
+
*
|
|
638
|
+
* @public
|
|
639
|
+
*/
|
|
640
|
+
export declare interface GenerateSchemasFromParameterOptions extends StaticSchemaGenerationOptions {
|
|
641
|
+
/** Supported build context used for checker access and related analysis. */
|
|
642
|
+
readonly context: StaticBuildContext;
|
|
643
|
+
/** Parameter declaration whose type should be converted into schemas. */
|
|
644
|
+
readonly parameter: ts.ParameterDeclaration;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Generates JSON Schema and UI Schema from a named type within an existing
|
|
649
|
+
* TypeScript program supplied by the caller.
|
|
650
|
+
*
|
|
651
|
+
* This low-level entry point lets downstream tooling reuse a host-owned
|
|
652
|
+
* `Program` for both FormSpec extraction and other TypeScript analysis.
|
|
653
|
+
*/
|
|
654
|
+
/**
|
|
655
|
+
* Generates JSON Schema and UI Schema from a named type within an existing
|
|
656
|
+
* TypeScript program and throws when generation reports error-severity diagnostics.
|
|
657
|
+
*
|
|
658
|
+
* @param options - Host program, file path, type name, and explicit throw-on-error reporting
|
|
659
|
+
* @returns Generated JSON Schema and UI Schema
|
|
660
|
+
*
|
|
661
|
+
* @public
|
|
662
|
+
*/
|
|
663
|
+
export declare function generateSchemasFromProgram(options: GenerateSchemasFromProgramOptions & {
|
|
664
|
+
readonly errorReporting: "throw";
|
|
665
|
+
}): GenerateFromClassResult;
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Generates JSON Schema and UI Schema from a named type within an existing
|
|
669
|
+
* TypeScript program and returns structured diagnostics instead of throwing on
|
|
670
|
+
* validation or analysis failures.
|
|
671
|
+
*
|
|
672
|
+
* @param options - Host program, file path, type name, and explicit diagnostics reporting
|
|
673
|
+
* @returns Structured generation result with diagnostics
|
|
674
|
+
*
|
|
675
|
+
* @public
|
|
676
|
+
*/
|
|
677
|
+
export declare function generateSchemasFromProgram(options: GenerateSchemasFromProgramOptions & {
|
|
678
|
+
readonly errorReporting: "diagnostics";
|
|
679
|
+
}): DetailedClassSchemasResult;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Generates JSON Schema and UI Schema from a named type within an existing
|
|
683
|
+
* TypeScript program.
|
|
684
|
+
*
|
|
685
|
+
* @deprecated Pass `errorReporting` explicitly. Omitting it defaults to `"throw"` only for backward compatibility.
|
|
686
|
+
* @param options - Host program, file path, and type name
|
|
687
|
+
* @returns Generated JSON Schema and UI Schema
|
|
688
|
+
*
|
|
689
|
+
* @public
|
|
690
|
+
*/
|
|
691
|
+
export declare function generateSchemasFromProgram(options: StaticSchemaGenerationOptions & {
|
|
692
|
+
readonly program: ts.Program;
|
|
693
|
+
readonly filePath: string;
|
|
694
|
+
readonly typeName: string;
|
|
695
|
+
}): GenerateFromClassResult;
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Generates JSON Schema and UI Schema from a named type within an existing
|
|
699
|
+
* TypeScript program and returns structured diagnostics instead of throwing on
|
|
700
|
+
* validation or analysis failures.
|
|
701
|
+
* @deprecated Use `generateSchemasFromProgram({ ...options, errorReporting: "diagnostics" })` instead.
|
|
702
|
+
*
|
|
703
|
+
* @public
|
|
704
|
+
*/
|
|
705
|
+
export declare function generateSchemasFromProgramDetailed(options: StaticSchemaGenerationOptions & {
|
|
706
|
+
readonly program: ts.Program;
|
|
707
|
+
readonly filePath: string;
|
|
708
|
+
readonly typeName: string;
|
|
709
|
+
}): DetailedClassSchemasResult;
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Options for generating schemas from a named type inside an existing TypeScript program.
|
|
713
|
+
*
|
|
714
|
+
* @public
|
|
715
|
+
*/
|
|
716
|
+
export declare interface GenerateSchemasFromProgramOptions extends StaticSchemaGenerationOptions {
|
|
717
|
+
/** Existing TypeScript program supplied by the caller. */
|
|
718
|
+
readonly program: ts.Program;
|
|
719
|
+
/** Path to the TypeScript source file */
|
|
720
|
+
readonly filePath: string;
|
|
721
|
+
/** Name of the exported class, interface, or type alias to analyze */
|
|
722
|
+
readonly typeName: string;
|
|
723
|
+
/**
|
|
724
|
+
* Controls whether error-severity diagnostics throw or are returned in the result.
|
|
725
|
+
*/
|
|
726
|
+
readonly errorReporting: "throw" | "diagnostics";
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Generates schemas for a method or function return type.
|
|
731
|
+
*
|
|
732
|
+
* Awaited `Promise<T>`-style return types are unwrapped before generation.
|
|
733
|
+
*
|
|
734
|
+
* @public
|
|
735
|
+
*/
|
|
736
|
+
export declare function generateSchemasFromReturnType(options: GenerateSchemasFromReturnTypeOptions): DiscoveredTypeSchemas;
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Options for generating schemas from a method or function return type.
|
|
740
|
+
*
|
|
741
|
+
* @public
|
|
742
|
+
*/
|
|
743
|
+
export declare interface GenerateSchemasFromReturnTypeOptions extends StaticSchemaGenerationOptions {
|
|
744
|
+
/** Supported build context used for checker access and related analysis. */
|
|
745
|
+
readonly context: StaticBuildContext;
|
|
746
|
+
/** Signature declaration whose return type should be converted into schemas. */
|
|
747
|
+
readonly declaration: ts.SignatureDeclaration;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Generates schemas from a resolved TypeScript type.
|
|
752
|
+
*
|
|
753
|
+
* This is the advanced public entry point for build tooling that already uses
|
|
754
|
+
* the TypeScript compiler API to discover types before handing them to
|
|
755
|
+
* FormSpec.
|
|
756
|
+
*
|
|
757
|
+
* @public
|
|
758
|
+
*/
|
|
759
|
+
export declare function generateSchemasFromType(options: GenerateSchemasFromTypeOptions): DiscoveredTypeSchemas;
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Options for generating schemas from a resolved TypeScript type.
|
|
763
|
+
*
|
|
764
|
+
* @public
|
|
765
|
+
*/
|
|
766
|
+
export declare interface GenerateSchemasFromTypeOptions extends StaticSchemaGenerationOptions {
|
|
767
|
+
/** Supported build context used for checker access and related analysis. */
|
|
768
|
+
readonly context: StaticBuildContext;
|
|
769
|
+
/** TypeScript type to turn into schemas. */
|
|
770
|
+
readonly type: ts.Type;
|
|
771
|
+
/**
|
|
772
|
+
* Optional source node associated with the type.
|
|
773
|
+
*
|
|
774
|
+
* When provided, FormSpec uses it as the source location for provenance and
|
|
775
|
+
* inline-type analysis.
|
|
776
|
+
*/
|
|
777
|
+
readonly sourceNode?: ts.Node | undefined;
|
|
778
|
+
/** Optional logical name used for anonymous roots. */
|
|
779
|
+
readonly name?: string | undefined;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Options for generating schemas from a named type (class, interface, or type alias).
|
|
784
|
+
*
|
|
785
|
+
* @public
|
|
786
|
+
*/
|
|
787
|
+
export declare interface GenerateSchemasOptions extends StaticSchemaGenerationOptions {
|
|
788
|
+
/** Path to the TypeScript source file */
|
|
789
|
+
readonly filePath: string;
|
|
790
|
+
/** Name of the exported class, interface, or type alias to analyze */
|
|
791
|
+
readonly typeName: string;
|
|
792
|
+
/**
|
|
793
|
+
* Controls whether error-severity diagnostics throw or are returned in the result.
|
|
794
|
+
*/
|
|
795
|
+
readonly errorReporting: "throw" | "diagnostics";
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Generates a JSON Forms UI Schema from a FormSpec.
|
|
800
|
+
*
|
|
801
|
+
* All generation routes through the canonical IR. The chain DSL is first
|
|
802
|
+
* canonicalized to a FormIR, then the IR-based generator produces the schema.
|
|
803
|
+
*
|
|
804
|
+
* @example
|
|
805
|
+
* ```typescript
|
|
806
|
+
* const form = formspec(
|
|
807
|
+
* group("Customer",
|
|
808
|
+
* field.text("name", { label: "Name" }),
|
|
809
|
+
* ),
|
|
810
|
+
* when("status", "draft",
|
|
811
|
+
* field.text("notes", { label: "Notes" }),
|
|
812
|
+
* ),
|
|
813
|
+
* );
|
|
814
|
+
*
|
|
815
|
+
* const uiSchema = generateUiSchema(form);
|
|
816
|
+
* // {
|
|
817
|
+
* // type: "VerticalLayout",
|
|
818
|
+
* // elements: [
|
|
819
|
+
* // {
|
|
820
|
+
* // type: "Group",
|
|
821
|
+
* // label: "Customer",
|
|
822
|
+
* // elements: [
|
|
823
|
+
* // { type: "Control", scope: "#/properties/name", label: "Name" }
|
|
824
|
+
* // ]
|
|
825
|
+
* // },
|
|
826
|
+
* // {
|
|
827
|
+
* // type: "Control",
|
|
828
|
+
* // scope: "#/properties/notes",
|
|
829
|
+
* // label: "Notes",
|
|
830
|
+
* // rule: {
|
|
831
|
+
* // effect: "SHOW",
|
|
832
|
+
* // condition: { scope: "#/properties/status", schema: { const: "draft" } }
|
|
833
|
+
* // }
|
|
834
|
+
* // }
|
|
835
|
+
* // ]
|
|
836
|
+
* // }
|
|
837
|
+
* ```
|
|
838
|
+
*
|
|
839
|
+
* @param form - The FormSpec to convert
|
|
840
|
+
* @returns A JSON Forms UI Schema
|
|
841
|
+
*
|
|
842
|
+
* @public
|
|
843
|
+
*/
|
|
844
|
+
export declare function generateUiSchema<E extends readonly FormElement[]>(form: FormSpec<E>, options?: GenerateUiSchemaOptions): UISchema;
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Options for generating a UI Schema from a Chain DSL form.
|
|
848
|
+
*
|
|
849
|
+
* @public
|
|
850
|
+
*/
|
|
851
|
+
export declare interface GenerateUiSchemaOptions {
|
|
852
|
+
/** Metadata resolution policy for chain DSL UI generation. */
|
|
853
|
+
readonly metadata?: MetadataPolicyInput | undefined;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
export { Group }
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* A group element with a label.
|
|
860
|
+
*
|
|
861
|
+
* @public
|
|
862
|
+
*/
|
|
863
|
+
export declare interface GroupLayout {
|
|
864
|
+
/** Discriminator identifying a labeled group container. */
|
|
865
|
+
readonly type: "Group";
|
|
866
|
+
/** Group label shown by compatible renderers. */
|
|
867
|
+
readonly label: string;
|
|
868
|
+
/** Child elements rendered inside the group. */
|
|
869
|
+
readonly elements: UISchemaElement[];
|
|
870
|
+
/** Optional rule controlling visibility or enablement. */
|
|
871
|
+
readonly rule?: Rule | undefined;
|
|
872
|
+
/** Renderer-specific group options. */
|
|
873
|
+
readonly options?: Record<string, unknown> | undefined;
|
|
874
|
+
/** Additional renderer-specific extension properties. */
|
|
875
|
+
readonly [k: string]: unknown;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* A horizontal layout element.
|
|
880
|
+
*
|
|
881
|
+
* @public
|
|
882
|
+
*/
|
|
883
|
+
export declare interface HorizontalLayout {
|
|
884
|
+
/** Discriminator identifying a horizontal layout container. */
|
|
885
|
+
readonly type: "HorizontalLayout";
|
|
886
|
+
/** Child elements rendered side by side. */
|
|
887
|
+
readonly elements: UISchemaElement[];
|
|
888
|
+
/** Optional rule controlling visibility or enablement. */
|
|
889
|
+
readonly rule?: Rule | undefined;
|
|
890
|
+
/** Renderer-specific layout options. */
|
|
891
|
+
readonly options?: Record<string, unknown> | undefined;
|
|
892
|
+
/** Additional renderer-specific extension properties. */
|
|
893
|
+
readonly [k: string]: unknown;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* A JSON Schema 2020-12 document, sub-schema, or keyword collection.
|
|
898
|
+
*
|
|
899
|
+
* This interface covers the subset of JSON Schema 2020-12 that this generator
|
|
900
|
+
* emits, plus an index signature for custom `x-formspec-*` extension keywords.
|
|
901
|
+
*
|
|
902
|
+
* @public
|
|
903
|
+
*/
|
|
904
|
+
export declare interface JsonSchema2020 {
|
|
905
|
+
/** Declared JSON Schema dialect URI for the document root. */
|
|
906
|
+
$schema?: string;
|
|
907
|
+
/** Reference to another schema location. */
|
|
908
|
+
$ref?: string;
|
|
909
|
+
/** Named reusable schema definitions keyed by definition name. */
|
|
910
|
+
$defs?: Record<string, JsonSchema2020>;
|
|
911
|
+
/** JSON Schema type keyword for the current node. */
|
|
912
|
+
type?: string;
|
|
913
|
+
/** Object properties keyed by property name. */
|
|
914
|
+
properties?: Record<string, JsonSchema2020>;
|
|
915
|
+
/** Property names that must be present on object values. */
|
|
916
|
+
required?: string[];
|
|
917
|
+
/** Item schema applied to array elements. */
|
|
918
|
+
items?: JsonSchema2020;
|
|
919
|
+
/** Whether, or how, additional object properties are allowed. */
|
|
920
|
+
additionalProperties?: boolean | JsonSchema2020;
|
|
921
|
+
/** Closed set of allowed scalar values. */
|
|
922
|
+
enum?: readonly (string | number)[];
|
|
923
|
+
/** Literal value the instance must equal. */
|
|
924
|
+
const?: unknown;
|
|
925
|
+
/** Schemas that must all validate successfully. */
|
|
926
|
+
allOf?: readonly JsonSchema2020[];
|
|
927
|
+
/** Schemas of which exactly one should validate successfully. */
|
|
928
|
+
oneOf?: readonly JsonSchema2020[];
|
|
929
|
+
/** Schemas of which at least one may validate successfully. */
|
|
930
|
+
anyOf?: readonly JsonSchema2020[];
|
|
931
|
+
/** Inclusive numeric lower bound. */
|
|
932
|
+
minimum?: number;
|
|
933
|
+
/** Inclusive numeric upper bound. */
|
|
934
|
+
maximum?: number;
|
|
935
|
+
/** Exclusive numeric lower bound. */
|
|
936
|
+
exclusiveMinimum?: number;
|
|
937
|
+
/** Exclusive numeric upper bound. */
|
|
938
|
+
exclusiveMaximum?: number;
|
|
939
|
+
/** Required numeric step interval. */
|
|
940
|
+
multipleOf?: number;
|
|
941
|
+
/** Inclusive minimum string length. */
|
|
942
|
+
minLength?: number;
|
|
943
|
+
/** Inclusive maximum string length. */
|
|
944
|
+
maxLength?: number;
|
|
945
|
+
/** Inclusive minimum array length. */
|
|
946
|
+
minItems?: number;
|
|
947
|
+
/** Inclusive maximum array length. */
|
|
948
|
+
maxItems?: number;
|
|
949
|
+
/** Regular expression pattern applied to string values. */
|
|
950
|
+
pattern?: string;
|
|
951
|
+
/** Whether array elements must be unique. */
|
|
952
|
+
uniqueItems?: boolean;
|
|
953
|
+
/** Format hint for downstream validators and tooling. */
|
|
954
|
+
format?: string;
|
|
955
|
+
/** Human-readable title for the schema node. */
|
|
956
|
+
title?: string;
|
|
957
|
+
/** Human-readable description for the schema node. */
|
|
958
|
+
description?: string;
|
|
959
|
+
/** Default value suggested for the schema node. */
|
|
960
|
+
default?: unknown;
|
|
961
|
+
/** Whether the schema node is deprecated. */
|
|
962
|
+
deprecated?: boolean;
|
|
963
|
+
/** Additional vendor-prefixed extension keywords. */
|
|
964
|
+
[key: `x-${string}`]: unknown;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* A JSON Schema definition (legacy subset used by Zod validator and types.ts).
|
|
969
|
+
*
|
|
970
|
+
* @public
|
|
971
|
+
*/
|
|
972
|
+
export declare interface JSONSchema7 {
|
|
973
|
+
/** Declared JSON Schema dialect URI for the document root. */
|
|
974
|
+
$schema?: string;
|
|
975
|
+
/** Stable identifier for the schema document or sub-schema. */
|
|
976
|
+
$id?: string;
|
|
977
|
+
/** Reference to another schema location. */
|
|
978
|
+
$ref?: string;
|
|
979
|
+
/** Human-readable title for the schema node. */
|
|
980
|
+
title?: string;
|
|
981
|
+
/** Human-readable description for the schema node. */
|
|
982
|
+
description?: string;
|
|
983
|
+
/** Whether the schema node is deprecated. */
|
|
984
|
+
deprecated?: boolean;
|
|
985
|
+
/** JSON Schema type keyword for the current node. */
|
|
986
|
+
type?: JSONSchemaType | JSONSchemaType[];
|
|
987
|
+
/** Inclusive minimum string length. */
|
|
988
|
+
minLength?: number;
|
|
989
|
+
/** Inclusive maximum string length. */
|
|
990
|
+
maxLength?: number;
|
|
991
|
+
/** Regular expression pattern applied to string values. */
|
|
992
|
+
pattern?: string;
|
|
993
|
+
/** Inclusive numeric lower bound. */
|
|
994
|
+
minimum?: number;
|
|
995
|
+
/** Inclusive numeric upper bound. */
|
|
996
|
+
maximum?: number;
|
|
997
|
+
/** Exclusive numeric lower bound. */
|
|
998
|
+
exclusiveMinimum?: number;
|
|
999
|
+
/** Exclusive numeric upper bound. */
|
|
1000
|
+
exclusiveMaximum?: number;
|
|
1001
|
+
/** Closed set of allowed scalar values. */
|
|
1002
|
+
enum?: readonly (string | number | boolean | null)[];
|
|
1003
|
+
/** Literal value the instance must equal. */
|
|
1004
|
+
const?: string | number | boolean | null;
|
|
1005
|
+
/** Object properties keyed by property name. */
|
|
1006
|
+
properties?: Record<string, JSONSchema7>;
|
|
1007
|
+
/** Property names that must be present on object values. */
|
|
1008
|
+
required?: string[];
|
|
1009
|
+
/** Whether, or how, additional object properties are allowed. */
|
|
1010
|
+
additionalProperties?: boolean | JSONSchema7;
|
|
1011
|
+
/** Item schema or tuple schemas applied to array elements. */
|
|
1012
|
+
items?: JSONSchema7 | JSONSchema7[];
|
|
1013
|
+
/** Inclusive minimum array length. */
|
|
1014
|
+
minItems?: number;
|
|
1015
|
+
/** Inclusive maximum array length. */
|
|
1016
|
+
maxItems?: number;
|
|
1017
|
+
/** Schemas that must all validate successfully. */
|
|
1018
|
+
allOf?: JSONSchema7[];
|
|
1019
|
+
/** Schemas of which at least one may validate successfully. */
|
|
1020
|
+
anyOf?: JSONSchema7[];
|
|
1021
|
+
/** Schemas of which exactly one should validate successfully. */
|
|
1022
|
+
oneOf?: JSONSchema7[];
|
|
1023
|
+
/** Schema that must not validate successfully. */
|
|
1024
|
+
not?: JSONSchema7;
|
|
1025
|
+
/** Conditional branch predicate schema. */
|
|
1026
|
+
if?: JSONSchema7;
|
|
1027
|
+
/** Schema applied when the `if` branch matches. */
|
|
1028
|
+
then?: JSONSchema7;
|
|
1029
|
+
/** Schema applied when the `if` branch does not match. */
|
|
1030
|
+
else?: JSONSchema7;
|
|
1031
|
+
/** Format hint for downstream validators and tooling. */
|
|
1032
|
+
format?: string;
|
|
1033
|
+
/** Default value suggested for the schema node. */
|
|
1034
|
+
default?: unknown;
|
|
1035
|
+
/**
|
|
1036
|
+
* Data source key for dynamic enum fields.
|
|
1037
|
+
* Indicates that options should be fetched from a registered resolver.
|
|
1038
|
+
*/
|
|
1039
|
+
"x-formspec-source"?: string;
|
|
1040
|
+
/**
|
|
1041
|
+
* Field names whose values are needed to fetch dynamic enum options.
|
|
1042
|
+
* Used for dependent/cascading dropdowns.
|
|
1043
|
+
*/
|
|
1044
|
+
"x-formspec-params"?: readonly string[];
|
|
1045
|
+
/**
|
|
1046
|
+
* Schema source identifier for dynamic schema fields.
|
|
1047
|
+
* Indicates that the schema should be loaded dynamically at runtime.
|
|
1048
|
+
*/
|
|
1049
|
+
"x-formspec-schemaSource"?: string;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Zod schema for the legacy JSON Schema 7 subset used by `@formspec/build`.
|
|
1054
|
+
*
|
|
1055
|
+
* @public
|
|
1056
|
+
*/
|
|
1057
|
+
export declare const jsonSchema7Schema: z.ZodType<JSONSchema7>;
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* JSON Schema type definitions.
|
|
1061
|
+
*
|
|
1062
|
+
* These types are a subset of JSON Schema sufficient for form generation.
|
|
1063
|
+
*/
|
|
1064
|
+
/**
|
|
1065
|
+
* JSON Schema primitive types.
|
|
1066
|
+
*
|
|
1067
|
+
* @public
|
|
1068
|
+
*/
|
|
1069
|
+
export declare type JSONSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* A Label element for displaying static text.
|
|
1073
|
+
*
|
|
1074
|
+
* @public
|
|
1075
|
+
*/
|
|
1076
|
+
export declare interface LabelElement {
|
|
1077
|
+
/** Discriminator identifying a static text label element. */
|
|
1078
|
+
readonly type: "Label";
|
|
1079
|
+
/** Static text content rendered by the label element. */
|
|
1080
|
+
readonly text: string;
|
|
1081
|
+
/** Optional rule controlling visibility or enablement. */
|
|
1082
|
+
readonly rule?: Rule | undefined;
|
|
1083
|
+
/** Renderer-specific label options. */
|
|
1084
|
+
readonly options?: Record<string, unknown> | undefined;
|
|
1085
|
+
/** Additional renderer-specific extension properties. */
|
|
1086
|
+
readonly [k: string]: unknown;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* Supported declaration kinds for standalone metadata resolution.
|
|
1091
|
+
*
|
|
1092
|
+
* This helper is intentionally limited to named type declarations,
|
|
1093
|
+
* methods/functions, and object-like properties. It does not currently expose
|
|
1094
|
+
* parameter or variable metadata resolution on the public build surface.
|
|
1095
|
+
*
|
|
1096
|
+
* @public
|
|
1097
|
+
*/
|
|
1098
|
+
export declare type MetadataSourceDeclaration = SchemaSourceDeclaration | ts.MethodDeclaration | ts.FunctionDeclaration | ts.PropertyDeclaration | ts.PropertySignature;
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* Result of generating schemas from a mixed-authoring composition.
|
|
1102
|
+
*
|
|
1103
|
+
* @public
|
|
1104
|
+
*/
|
|
1105
|
+
export declare interface MixedAuthoringSchemas {
|
|
1106
|
+
/** JSON Schema 2020-12 for validation. */
|
|
1107
|
+
readonly jsonSchema: JsonSchema2020;
|
|
1108
|
+
/** JSON Forms UI Schema for rendering. */
|
|
1109
|
+
readonly uiSchema: UISchema;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
export { NumberField }
|
|
1113
|
+
|
|
1114
|
+
export { ObjectField }
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* Resolves metadata from a declaration using FormSpec's configured metadata
|
|
1118
|
+
* policy for the matching declaration kind.
|
|
1119
|
+
*
|
|
1120
|
+
* @public
|
|
1121
|
+
*/
|
|
1122
|
+
export declare function resolveDeclarationMetadata(options: ResolveDeclarationMetadataOptions): ResolvedMetadata | undefined;
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Options for resolving metadata from a declaration against the active
|
|
1126
|
+
* metadata policy.
|
|
1127
|
+
*
|
|
1128
|
+
* @public
|
|
1129
|
+
*/
|
|
1130
|
+
export declare interface ResolveDeclarationMetadataOptions extends StaticSchemaGenerationOptions {
|
|
1131
|
+
/** Supported build context used for checker access and related analysis. */
|
|
1132
|
+
readonly context: StaticBuildContext;
|
|
1133
|
+
/** Declaration whose metadata should be resolved. */
|
|
1134
|
+
readonly declaration: MetadataSourceDeclaration;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Resolves an export from the context source file, following aliases and re-exports.
|
|
1139
|
+
*
|
|
1140
|
+
* @param context - Static build context created for the entry source file
|
|
1141
|
+
* @param exportName - Export name to resolve. Defaults to `"default"`.
|
|
1142
|
+
* @returns Resolved symbol for the export, or `null` when it cannot be found
|
|
1143
|
+
*
|
|
1144
|
+
* @public
|
|
1145
|
+
*/
|
|
1146
|
+
export declare function resolveModuleExport(context: StaticBuildContext, exportName?: string): ts.Symbol | null;
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* Resolves the declaration behind an export from the context source file,
|
|
1150
|
+
* following aliases and re-exports. This helper is intentionally limited to
|
|
1151
|
+
* declaration kinds accepted by declaration-driven schema generation.
|
|
1152
|
+
*
|
|
1153
|
+
* @param context - Static build context created for the entry source file
|
|
1154
|
+
* @param exportName - Export name to resolve. Defaults to `"default"`.
|
|
1155
|
+
* @returns Resolved class, interface, or type-alias declaration for the export,
|
|
1156
|
+
* or `null` when the export does not resolve to one of those schema-source kinds
|
|
1157
|
+
*
|
|
1158
|
+
* @public
|
|
1159
|
+
*/
|
|
1160
|
+
export declare function resolveModuleExportDeclaration(context: StaticBuildContext, exportName?: string): ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration | null;
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Rule for conditional element visibility/enablement.
|
|
1164
|
+
*
|
|
1165
|
+
* @public
|
|
1166
|
+
*/
|
|
1167
|
+
export declare interface Rule {
|
|
1168
|
+
/** UI effect to apply when the rule condition matches. */
|
|
1169
|
+
readonly effect: RuleEffect;
|
|
1170
|
+
/** Predicate that controls when the UI effect applies. */
|
|
1171
|
+
readonly condition: SchemaBasedCondition;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* JSON Schema subset used in rule conditions.
|
|
1176
|
+
*
|
|
1177
|
+
* @public
|
|
1178
|
+
*/
|
|
1179
|
+
export declare interface RuleConditionSchema {
|
|
1180
|
+
/** Literal value the condition schema must equal. */
|
|
1181
|
+
const?: unknown;
|
|
1182
|
+
/** Allowed values for the condition schema. */
|
|
1183
|
+
enum?: readonly unknown[];
|
|
1184
|
+
/** JSON Schema type required by the condition schema. */
|
|
1185
|
+
type?: string;
|
|
1186
|
+
/** Negated branch of the condition schema. */
|
|
1187
|
+
not?: RuleConditionSchema;
|
|
1188
|
+
/** Inclusive numeric lower bound in the condition schema. */
|
|
1189
|
+
minimum?: number;
|
|
1190
|
+
/** Inclusive numeric upper bound in the condition schema. */
|
|
1191
|
+
maximum?: number;
|
|
1192
|
+
/** Exclusive numeric lower bound in the condition schema. */
|
|
1193
|
+
exclusiveMinimum?: number;
|
|
1194
|
+
/** Exclusive numeric upper bound in the condition schema. */
|
|
1195
|
+
exclusiveMaximum?: number;
|
|
1196
|
+
/** Inclusive minimum string length in the condition schema. */
|
|
1197
|
+
minLength?: number;
|
|
1198
|
+
/** Nested property conditions keyed by property name. */
|
|
1199
|
+
properties?: Record<string, RuleConditionSchema>;
|
|
1200
|
+
/** Property names that must be present for the condition to match. */
|
|
1201
|
+
required?: string[];
|
|
1202
|
+
/** Schemas that must all match for the condition to succeed. */
|
|
1203
|
+
allOf?: RuleConditionSchema[];
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* JSON Forms UI Schema type definitions.
|
|
1208
|
+
*
|
|
1209
|
+
* These are the consumer-facing TypeScript shapes. Runtime validation remains
|
|
1210
|
+
* defined separately in `./schema.ts`.
|
|
1211
|
+
*
|
|
1212
|
+
* See: https://jsonforms.io/docs/uischema/
|
|
1213
|
+
*/
|
|
1214
|
+
/**
|
|
1215
|
+
* Rule effect types for conditional visibility.
|
|
1216
|
+
*
|
|
1217
|
+
* @public
|
|
1218
|
+
*/
|
|
1219
|
+
export declare type RuleEffect = "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Condition for a rule.
|
|
1223
|
+
*
|
|
1224
|
+
* @public
|
|
1225
|
+
*/
|
|
1226
|
+
export declare interface SchemaBasedCondition {
|
|
1227
|
+
/** JSON Pointer scope the rule evaluates against. */
|
|
1228
|
+
readonly scope: string;
|
|
1229
|
+
/** JSON Schema fragment evaluated at the scoped location. */
|
|
1230
|
+
readonly schema: RuleConditionSchema;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* A batch target for non-throwing schema generation.
|
|
1235
|
+
*
|
|
1236
|
+
* @public
|
|
1237
|
+
*/
|
|
1238
|
+
export declare interface SchemaGenerationTarget {
|
|
1239
|
+
/** Path to the TypeScript source file. */
|
|
1240
|
+
readonly filePath: string;
|
|
1241
|
+
/** Name of the exported class, interface, or type alias to analyze. */
|
|
1242
|
+
readonly typeName: string;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Supported declaration kinds for declaration-driven schema generation.
|
|
1247
|
+
*
|
|
1248
|
+
* @public
|
|
1249
|
+
*/
|
|
1250
|
+
export declare type SchemaSourceDeclaration = ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration;
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
* Supported compiler context for static build-time analysis workflows.
|
|
1254
|
+
*
|
|
1255
|
+
* This context gives consumers access to the TypeScript program, checker, and
|
|
1256
|
+
* source file used to discover declarations before invoking FormSpec schema
|
|
1257
|
+
* generation helpers.
|
|
1258
|
+
*
|
|
1259
|
+
* @public
|
|
1260
|
+
*/
|
|
1261
|
+
export declare interface StaticBuildContext {
|
|
1262
|
+
/** Host-owned or FormSpec-created TypeScript program. */
|
|
1263
|
+
readonly program: ts.Program;
|
|
1264
|
+
/** TypeScript checker for symbol and type analysis. */
|
|
1265
|
+
readonly checker: ts.TypeChecker;
|
|
1266
|
+
/** Source file used as the entry module for export resolution. */
|
|
1267
|
+
readonly sourceFile: ts.SourceFile;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
export { StaticEnumField }
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* Shared options for schema generation flows that support custom extensions.
|
|
1274
|
+
*
|
|
1275
|
+
* @public
|
|
1276
|
+
*/
|
|
1277
|
+
export declare interface StaticSchemaGenerationOptions {
|
|
1278
|
+
/**
|
|
1279
|
+
* Registry used to resolve custom types, constraints, and annotations.
|
|
1280
|
+
*/
|
|
1281
|
+
readonly extensionRegistry?: ExtensionRegistry | undefined;
|
|
1282
|
+
/**
|
|
1283
|
+
* Vendor prefix for emitted extension keywords.
|
|
1284
|
+
* @defaultValue "x-formspec"
|
|
1285
|
+
*/
|
|
1286
|
+
readonly vendorPrefix?: string | undefined;
|
|
1287
|
+
/** Metadata resolution policy for static schema generation. */
|
|
1288
|
+
readonly metadata?: MetadataPolicyInput | undefined;
|
|
1289
|
+
/** Discriminator-specific schema generation behavior. */
|
|
1290
|
+
readonly discriminator?: DiscriminatorResolutionOptions | undefined;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
export { TextField }
|
|
1294
|
+
|
|
1295
|
+
/**
|
|
1296
|
+
* Root UI Schema (always a layout — not a Control, Category, or Label).
|
|
1297
|
+
*
|
|
1298
|
+
* @public
|
|
1299
|
+
*/
|
|
1300
|
+
export declare type UISchema = VerticalLayout | HorizontalLayout | GroupLayout | Categorization;
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* Union of all UI Schema element types.
|
|
1304
|
+
*
|
|
1305
|
+
* @public
|
|
1306
|
+
*/
|
|
1307
|
+
export declare type UISchemaElement = ControlElement | VerticalLayout | HorizontalLayout | GroupLayout | Categorization | Category | LabelElement;
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* Base interface for all UI Schema elements.
|
|
1311
|
+
*
|
|
1312
|
+
* This is a manually maintained interface representing the common shape
|
|
1313
|
+
* shared by all element types. It is kept as an interface (rather than
|
|
1314
|
+
* derived from Zod) because it is the base of a discriminated union, not
|
|
1315
|
+
* a union member itself.
|
|
1316
|
+
*
|
|
1317
|
+
* @public
|
|
1318
|
+
*/
|
|
1319
|
+
export declare interface UISchemaElementBase {
|
|
1320
|
+
/** Discriminator for the concrete JSON Forms element type. */
|
|
1321
|
+
type: UISchemaElementType;
|
|
1322
|
+
/** Optional rule controlling visibility or enablement. */
|
|
1323
|
+
rule?: Rule;
|
|
1324
|
+
/** Renderer-specific options shared by UI schema elements. */
|
|
1325
|
+
options?: Record<string, unknown>;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* UI Schema element types.
|
|
1330
|
+
*
|
|
1331
|
+
* @public
|
|
1332
|
+
*/
|
|
1333
|
+
export declare type UISchemaElementType = "Control" | "VerticalLayout" | "HorizontalLayout" | "Group" | "Categorization" | "Category" | "Label";
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* Zod schema for the root UI Schema (layout types only).
|
|
1337
|
+
*
|
|
1338
|
+
* @public
|
|
1339
|
+
*/
|
|
1340
|
+
export declare const uiSchemaSchema: z.ZodType<UISchema>;
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* Options for validating canonical FormIR.
|
|
1344
|
+
*
|
|
1345
|
+
* @public
|
|
1346
|
+
*/
|
|
1347
|
+
export declare interface ValidateIROptions {
|
|
1348
|
+
/** Vendor prefix used when resolving extension-backed keywords. */
|
|
1349
|
+
readonly vendorPrefix?: string;
|
|
1350
|
+
/** Extension registry used to resolve custom constraints and types. */
|
|
1351
|
+
readonly extensionRegistry?: ExtensionRegistry;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
/**
|
|
1355
|
+
* A machine-readable validation diagnostic returned by static schema analysis.
|
|
1356
|
+
*
|
|
1357
|
+
* @public
|
|
1358
|
+
*/
|
|
1359
|
+
export declare interface ValidationDiagnostic {
|
|
1360
|
+
/** Stable machine-readable diagnostic code. */
|
|
1361
|
+
readonly code: string;
|
|
1362
|
+
/** Human-readable explanation of the validation problem. */
|
|
1363
|
+
readonly message: string;
|
|
1364
|
+
/** Severity of the reported validation problem. */
|
|
1365
|
+
readonly severity: ValidationDiagnosticSeverity;
|
|
1366
|
+
/** Primary source location associated with the diagnostic. */
|
|
1367
|
+
readonly primaryLocation: ValidationDiagnosticLocation;
|
|
1368
|
+
/** Related source locations that add context to the diagnostic. */
|
|
1369
|
+
readonly relatedLocations: readonly ValidationDiagnosticLocation[];
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
/**
|
|
1373
|
+
* Public source-location shape attached to validation diagnostics.
|
|
1374
|
+
*
|
|
1375
|
+
* This mirrors the provenance information surfaced by the shared analysis
|
|
1376
|
+
* layer without exposing `@formspec/core/internals` through the public API.
|
|
1377
|
+
*
|
|
1378
|
+
* @public
|
|
1379
|
+
*/
|
|
1380
|
+
export declare interface ValidationDiagnosticLocation {
|
|
1381
|
+
/** Authoring surface that produced the diagnostic location. */
|
|
1382
|
+
readonly surface: "tsdoc" | "chain-dsl" | "extension" | "inferred";
|
|
1383
|
+
/** Absolute path to the source file. */
|
|
1384
|
+
readonly file: string;
|
|
1385
|
+
/** 1-based line number in the source file. */
|
|
1386
|
+
readonly line: number;
|
|
1387
|
+
/** 0-based column number in the source file. */
|
|
1388
|
+
readonly column: number;
|
|
1389
|
+
/** Optional span length in characters. */
|
|
1390
|
+
readonly length?: number;
|
|
1391
|
+
/** Optional tag or construct associated with the location. */
|
|
1392
|
+
readonly tagName?: string;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
/**
|
|
1396
|
+
* Supported severity levels returned by static build validation.
|
|
1397
|
+
*
|
|
1398
|
+
* @public
|
|
1399
|
+
*/
|
|
1400
|
+
export declare type ValidationDiagnosticSeverity = "error" | "warning";
|
|
1401
|
+
|
|
1402
|
+
/**
|
|
1403
|
+
* Result of validating canonical FormIR before schema emission.
|
|
1404
|
+
*
|
|
1405
|
+
* @public
|
|
1406
|
+
*/
|
|
1407
|
+
export declare interface ValidationResult {
|
|
1408
|
+
/** Diagnostics produced during validation. */
|
|
1409
|
+
readonly diagnostics: readonly ValidationDiagnostic[];
|
|
1410
|
+
/** Whether any error-severity diagnostics were produced. */
|
|
1411
|
+
readonly valid: boolean;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
/**
|
|
1415
|
+
* A vertical layout element.
|
|
1416
|
+
*
|
|
1417
|
+
* @public
|
|
1418
|
+
*/
|
|
1419
|
+
export declare interface VerticalLayout {
|
|
1420
|
+
/** Discriminator identifying a vertical layout container. */
|
|
1421
|
+
readonly type: "VerticalLayout";
|
|
1422
|
+
/** Child elements rendered in vertical order. */
|
|
1423
|
+
readonly elements: UISchemaElement[];
|
|
1424
|
+
/** Optional rule controlling visibility or enablement. */
|
|
1425
|
+
readonly rule?: Rule | undefined;
|
|
1426
|
+
/** Renderer-specific layout options. */
|
|
1427
|
+
readonly options?: Record<string, unknown> | undefined;
|
|
1428
|
+
/** Additional renderer-specific extension properties. */
|
|
1429
|
+
readonly [k: string]: unknown;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
/**
|
|
1433
|
+
* Builds and writes both JSON Schema and UI Schema files to disk.
|
|
1434
|
+
*
|
|
1435
|
+
* This is a convenience function for build-time schema generation.
|
|
1436
|
+
* It creates the output directory if it doesn't exist.
|
|
1437
|
+
*
|
|
1438
|
+
* @example
|
|
1439
|
+
* ```typescript
|
|
1440
|
+
* import { formspec, field } from "formspec";
|
|
1441
|
+
* import { writeSchemas } from "@formspec/build";
|
|
1442
|
+
*
|
|
1443
|
+
* const ProductForm = formspec(
|
|
1444
|
+
* field.text("name", { required: true }),
|
|
1445
|
+
* field.enum("status", ["draft", "active"]),
|
|
1446
|
+
* );
|
|
1447
|
+
*
|
|
1448
|
+
* // Write schemas to ./generated/product-schema.json and ./generated/product-uischema.json
|
|
1449
|
+
* const { jsonSchemaPath, uiSchemaPath } = writeSchemas(ProductForm, {
|
|
1450
|
+
* outDir: "./generated",
|
|
1451
|
+
* name: "product",
|
|
1452
|
+
* });
|
|
1453
|
+
*
|
|
1454
|
+
* console.log(`Generated: ${jsonSchemaPath}, ${uiSchemaPath}`);
|
|
1455
|
+
* ```
|
|
1456
|
+
*
|
|
1457
|
+
* @param form - The FormSpec to build schemas from
|
|
1458
|
+
* @param options - Output options (directory, file name, indentation)
|
|
1459
|
+
* @returns Object containing paths to the generated files
|
|
1460
|
+
*
|
|
1461
|
+
* @public
|
|
1462
|
+
*/
|
|
1463
|
+
export declare function writeSchemas<E extends readonly FormElement[]>(form: FormSpec<E>, options: WriteSchemasOptions): WriteSchemasResult;
|
|
1464
|
+
|
|
1465
|
+
/**
|
|
1466
|
+
* Options for writing schemas to disk.
|
|
1467
|
+
*
|
|
1468
|
+
* @public
|
|
1469
|
+
*/
|
|
1470
|
+
export declare interface WriteSchemasOptions extends GenerateJsonSchemaOptions {
|
|
1471
|
+
/** Output directory for the schema files */
|
|
1472
|
+
readonly outDir: string;
|
|
1473
|
+
/** Base name for the output files (without extension). Defaults to "schema" */
|
|
1474
|
+
readonly name?: string;
|
|
1475
|
+
/** Number of spaces for JSON indentation. Defaults to 2 */
|
|
1476
|
+
readonly indent?: number;
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
/**
|
|
1480
|
+
* Result of writing schemas to disk.
|
|
1481
|
+
*
|
|
1482
|
+
* @public
|
|
1483
|
+
*/
|
|
1484
|
+
export declare interface WriteSchemasResult {
|
|
1485
|
+
/** Path to the generated JSON Schema file */
|
|
1486
|
+
readonly jsonSchemaPath: string;
|
|
1487
|
+
/** Path to the generated UI Schema file */
|
|
1488
|
+
readonly uiSchemaPath: string;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
export { }
|