@formspec/build 0.1.0-alpha.2 → 0.1.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -0
- package/dist/__tests__/alias-chain-propagation.test.d.ts +9 -0
- package/dist/__tests__/alias-chain-propagation.test.d.ts.map +1 -0
- package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts +2 -0
- package/dist/__tests__/chain-dsl-canonicalizer.test.d.ts.map +1 -0
- package/dist/__tests__/class-schema.test.d.ts +2 -0
- package/dist/__tests__/class-schema.test.d.ts.map +1 -0
- package/dist/__tests__/constraint-validator.test.d.ts +2 -0
- package/dist/__tests__/constraint-validator.test.d.ts.map +1 -0
- package/dist/__tests__/date-extension.integration.test.d.ts +2 -0
- package/dist/__tests__/date-extension.integration.test.d.ts.map +1 -0
- package/dist/__tests__/extension-api.test.d.ts +2 -0
- package/dist/__tests__/extension-api.test.d.ts.map +1 -0
- package/dist/__tests__/extension-runtime.integration.test.d.ts +2 -0
- package/dist/__tests__/extension-runtime.integration.test.d.ts.map +1 -0
- package/dist/__tests__/fixtures/alias-chains.d.ts +37 -0
- package/dist/__tests__/fixtures/alias-chains.d.ts.map +1 -0
- package/dist/__tests__/fixtures/class-schema-regressions.d.ts +86 -0
- package/dist/__tests__/fixtures/class-schema-regressions.d.ts.map +1 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts +132 -0
- package/dist/__tests__/fixtures/edge-cases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts +31 -0
- package/dist/__tests__/fixtures/example-a-builtins.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-date-extension.d.ts +12 -0
- package/dist/__tests__/fixtures/example-date-extension.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-interface-types.d.ts +107 -0
- package/dist/__tests__/fixtures/example-interface-types.d.ts.map +1 -0
- package/dist/__tests__/fixtures/example-numeric-extension.d.ts +20 -0
- package/dist/__tests__/fixtures/example-numeric-extension.d.ts.map +1 -0
- package/dist/__tests__/fixtures/extension-forms.d.ts +7 -0
- package/dist/__tests__/fixtures/extension-forms.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts +31 -0
- package/dist/__tests__/fixtures/mixed-authoring-shipping-address.d.ts.map +1 -0
- package/dist/__tests__/fixtures/named-primitive-aliases.d.ts +15 -0
- package/dist/__tests__/fixtures/named-primitive-aliases.d.ts.map +1 -0
- package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts +14 -0
- package/dist/__tests__/fixtures/nested-array-path-constraints.d.ts.map +1 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts +65 -0
- package/dist/__tests__/fixtures/sample-forms.d.ts.map +1 -0
- package/dist/__tests__/generate-schemas.test.d.ts +2 -0
- package/dist/__tests__/generate-schemas.test.d.ts.map +1 -0
- package/dist/__tests__/guards.test.d.ts +2 -0
- package/dist/__tests__/guards.test.d.ts.map +1 -0
- package/dist/__tests__/ir-analyzer.test.d.ts +11 -0
- package/dist/__tests__/ir-analyzer.test.d.ts.map +1 -0
- package/dist/__tests__/ir-jsdoc-constraints.test.d.ts +12 -0
- package/dist/__tests__/ir-jsdoc-constraints.test.d.ts.map +1 -0
- package/dist/__tests__/ir-json-schema-generator.test.d.ts +11 -0
- package/dist/__tests__/ir-json-schema-generator.test.d.ts.map +1 -0
- package/dist/__tests__/ir-ui-schema-generator.test.d.ts +2 -0
- package/dist/__tests__/ir-ui-schema-generator.test.d.ts.map +1 -0
- package/dist/__tests__/mixed-authoring.test.d.ts +2 -0
- package/dist/__tests__/mixed-authoring.test.d.ts.map +1 -0
- package/dist/__tests__/numeric-extension.integration.test.d.ts +2 -0
- package/dist/__tests__/numeric-extension.integration.test.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/address/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/address/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/address/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/plan-status/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts +6 -0
- package/dist/__tests__/parity/fixtures/plan-status/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts +17 -0
- package/dist/__tests__/parity/fixtures/plan-status/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts +13 -0
- package/dist/__tests__/parity/fixtures/product-config/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/product-config/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts +28 -0
- package/dist/__tests__/parity/fixtures/product-config/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/usd-cents/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts +6 -0
- package/dist/__tests__/parity/fixtures/usd-cents/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/usd-cents/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts +12 -0
- package/dist/__tests__/parity/fixtures/user-registration/chain-dsl.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts +9 -0
- package/dist/__tests__/parity/fixtures/user-registration/expected-ir.d.ts.map +1 -0
- package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts +19 -0
- package/dist/__tests__/parity/fixtures/user-registration/tsdoc.d.ts.map +1 -0
- package/dist/__tests__/parity/parity.test.d.ts +18 -0
- package/dist/__tests__/parity/parity.test.d.ts.map +1 -0
- package/dist/__tests__/parity/utils.d.ts +152 -0
- package/dist/__tests__/parity/utils.d.ts.map +1 -0
- package/dist/__tests__/path-target-parser.test.d.ts +9 -0
- package/dist/__tests__/path-target-parser.test.d.ts.map +1 -0
- package/dist/analyzer/class-analyzer.d.ts +100 -0
- package/dist/analyzer/class-analyzer.d.ts.map +1 -0
- package/dist/analyzer/jsdoc-constraints.d.ts +53 -0
- package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
- package/dist/analyzer/program.d.ts +68 -0
- package/dist/analyzer/program.d.ts.map +1 -0
- package/dist/analyzer/tsdoc-parser.d.ts +123 -0
- package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
- package/dist/browser.cjs +1294 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.ts +73 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1245 -0
- package/dist/browser.js.map +1 -0
- package/dist/build.d.ts +1144 -0
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +18 -0
- package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -0
- package/dist/canonicalize/index.d.ts +8 -0
- package/dist/canonicalize/index.d.ts.map +1 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts +34 -0
- package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
- package/dist/cli.cjs +3859 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +3823 -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 +111 -0
- package/dist/generators/class-schema.d.ts.map +1 -0
- package/dist/generators/method-schema.d.ts +65 -0
- package/dist/generators/method-schema.d.ts.map +1 -0
- package/dist/generators/mixed-authoring.d.ts +51 -0
- package/dist/generators/mixed-authoring.d.ts.map +1 -0
- package/dist/index.cjs +3624 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +45 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3584 -106
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +3368 -0
- package/dist/internals.cjs.map +1 -0
- package/dist/internals.d.ts +30 -0
- package/dist/internals.d.ts.map +1 -0
- package/dist/internals.js +3342 -0
- package/dist/internals.js.map +1 -0
- package/dist/json-schema/generator.d.ts +20 -5
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/json-schema/ir-generator.d.ts +114 -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 +45 -2
- package/dist/json-schema/types.d.ts.map +1 -1
- package/dist/ui-schema/generator.d.ts +7 -0
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/ir-generator.d.ts +53 -0
- package/dist/ui-schema/ir-generator.d.ts.map +1 -0
- package/dist/ui-schema/schema.d.ts +434 -0
- package/dist/ui-schema/schema.d.ts.map +1 -0
- package/dist/ui-schema/types.d.ts +10 -73
- package/dist/ui-schema/types.d.ts.map +1 -1
- package/dist/validate/constraint-validator.d.ts +23 -0
- package/dist/validate/constraint-validator.d.ts.map +1 -0
- package/dist/validate/index.d.ts +9 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/package.json +27 -7
- package/dist/__tests__/cli.test.js +0 -178
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/__tests__/edge-cases.test.js +0 -217
- package/dist/__tests__/edge-cases.test.js.map +0 -1
- package/dist/__tests__/generator.test.js +0 -225
- package/dist/__tests__/generator.test.js.map +0 -1
- package/dist/__tests__/integration.test.js +0 -163
- package/dist/__tests__/integration.test.js.map +0 -1
- package/dist/__tests__/write-schemas.test.js +0 -196
- package/dist/__tests__/write-schemas.test.js.map +0 -1
- package/dist/json-schema/generator.js +0 -161
- package/dist/json-schema/generator.js.map +0 -1
- package/dist/json-schema/types.js +0 -7
- package/dist/json-schema/types.js.map +0 -1
- package/dist/ui-schema/generator.js +0 -150
- package/dist/ui-schema/generator.js.map +0 -1
- package/dist/ui-schema/types.js +0 -8
- package/dist/ui-schema/types.js.map +0 -1
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JSON Schema generator for FormSpec forms.
|
|
3
|
+
*
|
|
4
|
+
* Routes through the canonical IR pipeline: Chain DSL → FormIR → JSON Schema 2020-12.
|
|
3
5
|
*/
|
|
4
6
|
import type { FormElement, FormSpec } from "@formspec/core";
|
|
5
|
-
import type
|
|
7
|
+
import { type GenerateJsonSchemaFromIROptions, type JsonSchema2020 } from "./ir-generator.js";
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
9
|
+
* Options for generating JSON Schema from a Chain DSL form.
|
|
10
|
+
*
|
|
11
|
+
* These options are forwarded to the IR-based JSON Schema generator.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export type GenerateJsonSchemaOptions = GenerateJsonSchemaFromIROptions;
|
|
16
|
+
/**
|
|
17
|
+
* Generates a JSON Schema 2020-12 from a FormSpec.
|
|
18
|
+
*
|
|
19
|
+
* All generation routes through the canonical IR. The chain DSL is first
|
|
20
|
+
* canonicalized to a FormIR, then the IR-based generator produces the schema.
|
|
8
21
|
*
|
|
9
22
|
* @example
|
|
10
23
|
* ```typescript
|
|
@@ -15,7 +28,7 @@ import type { JSONSchema7 } from "./types.js";
|
|
|
15
28
|
*
|
|
16
29
|
* const schema = generateJsonSchema(form);
|
|
17
30
|
* // {
|
|
18
|
-
* // $schema: "https://json-schema.org/draft-
|
|
31
|
+
* // $schema: "https://json-schema.org/draft/2020-12/schema",
|
|
19
32
|
* // type: "object",
|
|
20
33
|
* // properties: {
|
|
21
34
|
* // name: { type: "string", title: "Name" },
|
|
@@ -26,7 +39,9 @@ import type { JSONSchema7 } from "./types.js";
|
|
|
26
39
|
* ```
|
|
27
40
|
*
|
|
28
41
|
* @param form - The FormSpec to convert
|
|
29
|
-
* @returns A JSON Schema object
|
|
42
|
+
* @returns A JSON Schema 2020-12 object
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
30
45
|
*/
|
|
31
|
-
export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E
|
|
46
|
+
export declare function generateJsonSchema<E extends readonly FormElement[]>(form: FormSpec<E>, options?: GenerateJsonSchemaOptions): JsonSchema2020;
|
|
32
47
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/json-schema/generator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/json-schema/generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAEL,KAAK,+BAA+B,EACpC,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,+BAA+B,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,WAAW,EAAE,EACjE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,OAAO,CAAC,EAAE,yBAAyB,GAClC,cAAc,CAGhB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema 2020-12 generator that consumes the canonical FormIR.
|
|
3
|
+
*
|
|
4
|
+
* This generator is a pure function of the IR. It never consults the TypeScript
|
|
5
|
+
* AST or surface syntax directly — only the IR (per the JSON Schema vocabulary spec §1.2).
|
|
6
|
+
*
|
|
7
|
+
* @see https://json-schema.org/draft/2020-12/schema
|
|
8
|
+
* @see https://json-schema.org/draft/2020-12/schema
|
|
9
|
+
*/
|
|
10
|
+
import type { FormIR, JsonValue } from "@formspec/core";
|
|
11
|
+
import type { ExtensionRegistry } from "../extensions/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* A JSON Schema 2020-12 document, sub-schema, or keyword collection.
|
|
14
|
+
*
|
|
15
|
+
* This interface covers the subset of JSON Schema 2020-12 that this generator
|
|
16
|
+
* emits, plus an index signature for custom `x-formspec-*` extension keywords.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface JsonSchema2020 {
|
|
21
|
+
$schema?: string;
|
|
22
|
+
$ref?: string;
|
|
23
|
+
$defs?: Record<string, JsonSchema2020>;
|
|
24
|
+
type?: string;
|
|
25
|
+
properties?: Record<string, JsonSchema2020>;
|
|
26
|
+
required?: string[];
|
|
27
|
+
items?: JsonSchema2020;
|
|
28
|
+
additionalProperties?: boolean | JsonSchema2020;
|
|
29
|
+
enum?: readonly (string | number)[];
|
|
30
|
+
const?: JsonValue;
|
|
31
|
+
allOf?: readonly JsonSchema2020[];
|
|
32
|
+
oneOf?: readonly JsonSchema2020[];
|
|
33
|
+
anyOf?: readonly JsonSchema2020[];
|
|
34
|
+
minimum?: number;
|
|
35
|
+
maximum?: number;
|
|
36
|
+
exclusiveMinimum?: number;
|
|
37
|
+
exclusiveMaximum?: number;
|
|
38
|
+
multipleOf?: number;
|
|
39
|
+
minLength?: number;
|
|
40
|
+
maxLength?: number;
|
|
41
|
+
minItems?: number;
|
|
42
|
+
maxItems?: number;
|
|
43
|
+
pattern?: string;
|
|
44
|
+
uniqueItems?: boolean;
|
|
45
|
+
format?: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
default?: unknown;
|
|
49
|
+
deprecated?: boolean;
|
|
50
|
+
[key: `x-${string}`]: unknown;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for generating JSON Schema from a canonical FormIR.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export interface GenerateJsonSchemaFromIROptions {
|
|
58
|
+
/**
|
|
59
|
+
* Registry used to resolve custom types, constraints, and annotations.
|
|
60
|
+
*
|
|
61
|
+
* JSON Schema generation throws when custom IR nodes are present without a
|
|
62
|
+
* matching registration in this registry.
|
|
63
|
+
*/
|
|
64
|
+
readonly extensionRegistry?: ExtensionRegistry | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Vendor prefix passed to extension `toJsonSchema` hooks.
|
|
67
|
+
* @defaultValue "x-formspec"
|
|
68
|
+
*/
|
|
69
|
+
readonly vendorPrefix?: string | undefined;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generates a JSON Schema 2020-12 object from a canonical FormIR.
|
|
73
|
+
*
|
|
74
|
+
* Groups and conditionals are flattened — they influence UI layout but do not
|
|
75
|
+
* affect the data schema. All fields appear at the level they would occupy in
|
|
76
|
+
* the output data.
|
|
77
|
+
*
|
|
78
|
+
* Named types in the `typeRegistry` are emitted as `$defs` entries and
|
|
79
|
+
* referenced via `$ref` (per PP7 — high-fidelity output).
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* import { canonicalizeDSL } from "./canonicalize/index.js";
|
|
84
|
+
* import { generateJsonSchemaFromIR } from "./json-schema/ir-generator.js";
|
|
85
|
+
* import { formspec, field } from "@formspec/dsl";
|
|
86
|
+
*
|
|
87
|
+
* const form = formspec(
|
|
88
|
+
* field.text("name", { label: "Name", required: true }),
|
|
89
|
+
* field.number("age", { min: 0 }),
|
|
90
|
+
* );
|
|
91
|
+
* const ir = canonicalizeDSL(form);
|
|
92
|
+
* const schema = generateJsonSchemaFromIR(ir);
|
|
93
|
+
* // {
|
|
94
|
+
* // $schema: "https://json-schema.org/draft/2020-12/schema",
|
|
95
|
+
* // type: "object",
|
|
96
|
+
* // properties: {
|
|
97
|
+
* // name: { type: "string", title: "Name" },
|
|
98
|
+
* // age: { type: "number", minimum: 0 }
|
|
99
|
+
* // },
|
|
100
|
+
* // required: ["name"]
|
|
101
|
+
* // }
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* Advanced API — most consumers should use `generateJsonSchema()` or
|
|
105
|
+
* `buildFormSchemas()`, which canonicalize form definitions automatically.
|
|
106
|
+
* Callers of this function are responsible for providing pre-canonicalized IR.
|
|
107
|
+
*
|
|
108
|
+
* @param ir - The canonical FormIR produced by a canonicalizer
|
|
109
|
+
* @returns A plain JSON-serializable JSON Schema 2020-12 object
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
export declare function generateJsonSchemaFromIR(ir: FormIR, options?: GenerateJsonSchemaFromIROptions): JsonSchema2020;
|
|
114
|
+
//# sourceMappingURL=ir-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-generator.d.ts","sourceRoot":"","sources":["../../src/json-schema/ir-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,MAAM,EAgBN,SAAS,EACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAMhE;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAA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AAG,SAAS,CAAC;CAC5C;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,+BAA+B,GACxC,cAAc,CAwChB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for JSON Schema output validation.
|
|
3
|
+
*
|
|
4
|
+
* These schemas cover the subset of JSON Schema that FormSpec generates,
|
|
5
|
+
* plus the FormSpec-specific `x-formspec-*` extension properties.
|
|
6
|
+
*
|
|
7
|
+
* @see https://json-schema.org/draft/2020-12/schema
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import type { JSONSchema7 } from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Zod schema for JSON Schema primitive type strings.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare const jsonSchemaTypeSchema: z.ZodEnum<["string", "number", "integer", "boolean", "object", "array", "null"]>;
|
|
17
|
+
/**
|
|
18
|
+
* Zod schema for the legacy JSON Schema 7 subset used by `@formspec/build`.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare const jsonSchema7Schema: z.ZodType<JSONSchema7>;
|
|
23
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/json-schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAM9C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,kFAQ/B,CAAC;AAaH;;;;GAIG;AAGH,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAoEpD,CAAC"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSON Schema
|
|
2
|
+
* JSON Schema type definitions.
|
|
3
3
|
*
|
|
4
4
|
* These types are a subset of JSON Schema sufficient for form generation.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* JSON Schema primitive types.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
8
10
|
*/
|
|
9
11
|
export type JSONSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
10
12
|
/**
|
|
11
|
-
* A JSON Schema definition (
|
|
13
|
+
* A JSON Schema definition (legacy subset used by Zod validator and types.ts).
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
12
16
|
*/
|
|
13
17
|
export interface JSONSchema7 {
|
|
14
18
|
$schema?: string;
|
|
@@ -16,6 +20,7 @@ export interface JSONSchema7 {
|
|
|
16
20
|
$ref?: string;
|
|
17
21
|
title?: string;
|
|
18
22
|
description?: string;
|
|
23
|
+
deprecated?: boolean;
|
|
19
24
|
type?: JSONSchemaType | JSONSchemaType[];
|
|
20
25
|
minLength?: number;
|
|
21
26
|
maxLength?: number;
|
|
@@ -57,4 +62,42 @@ export interface JSONSchema7 {
|
|
|
57
62
|
*/
|
|
58
63
|
"x-formspec-schemaSource"?: string;
|
|
59
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Extension properties for custom FormSpec constraint tags.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* JSON Schema with FormSpec extension properties for arbitrary `x-formspec-*` keys.
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;
|
|
77
|
+
/**
|
|
78
|
+
* Sets a FormSpec extension property on a JSON Schema node.
|
|
79
|
+
*
|
|
80
|
+
* Use this to safely add `x-formspec-*` properties to any schema,
|
|
81
|
+
* including nested schemas typed as `JSONSchema7` (which don't carry
|
|
82
|
+
* the extension index signature).
|
|
83
|
+
*
|
|
84
|
+
* @param schema - Any JSON Schema node
|
|
85
|
+
* @param key - Extension key (must start with `x-formspec-`)
|
|
86
|
+
* @param value - Extension value
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export declare function setSchemaExtension(schema: object, key: `x-formspec-${string}`, value: unknown): void;
|
|
91
|
+
/**
|
|
92
|
+
* Reads a FormSpec extension property from a JSON Schema node.
|
|
93
|
+
*
|
|
94
|
+
* Accepts any schema object — `JSONSchema7`, `JsonSchema2020`, `ExtendedJSONSchema7`, etc.
|
|
95
|
+
*
|
|
96
|
+
* @param schema - Any JSON Schema node
|
|
97
|
+
* @param key - Extension key (must start with `x-formspec-`)
|
|
98
|
+
* @returns The extension value, or `undefined` if not present
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export declare function getSchemaExtension(schema: object, key: `x-formspec-${string}`): unknown;
|
|
60
103
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/json-schema/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/json-schema/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEX;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,C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AAC;IAMlB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAExC;;;OAGG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,cAAc,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,cAAc,MAAM,EAAE,EAC3B,KAAK,EAAE,OAAO,GACb,IAAI,CAEN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,MAAM,EAAE,GAAG,OAAO,CAEvF"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JSON Forms UI Schema generator for FormSpec forms.
|
|
3
|
+
*
|
|
4
|
+
* Routes through the canonical IR pipeline: Chain DSL → FormIR → UI Schema.
|
|
3
5
|
*/
|
|
4
6
|
import type { FormElement, FormSpec } from "@formspec/core";
|
|
5
7
|
import type { UISchema } from "./types.js";
|
|
6
8
|
/**
|
|
7
9
|
* Generates a JSON Forms UI Schema from a FormSpec.
|
|
8
10
|
*
|
|
11
|
+
* All generation routes through the canonical IR. The chain DSL is first
|
|
12
|
+
* canonicalized to a FormIR, then the IR-based generator produces the schema.
|
|
13
|
+
*
|
|
9
14
|
* @example
|
|
10
15
|
* ```typescript
|
|
11
16
|
* const form = formspec(
|
|
@@ -43,6 +48,8 @@ import type { UISchema } from "./types.js";
|
|
|
43
48
|
*
|
|
44
49
|
* @param form - The FormSpec to convert
|
|
45
50
|
* @returns A JSON Forms UI Schema
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
46
53
|
*/
|
|
47
54
|
export declare function generateUiSchema<E extends readonly FormElement[]>(form: FormSpec<E>): UISchema;
|
|
48
55
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/ui-schema/generator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/ui-schema/generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,SAAS,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAG9F"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Forms UI Schema generator that operates on the canonical FormIR.
|
|
3
|
+
*
|
|
4
|
+
* This generator consumes the IR produced by the Canonicalize phase and
|
|
5
|
+
* produces a JSON Forms UI Schema. All downstream UI Schema generation
|
|
6
|
+
* should use this module for UI Schema generation.
|
|
7
|
+
*/
|
|
8
|
+
import type { FormIR } from "@formspec/core";
|
|
9
|
+
import type { UISchema } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Generates a JSON Forms UI Schema from a canonical `FormIR`.
|
|
12
|
+
*
|
|
13
|
+
* Mapping rules:
|
|
14
|
+
* - `FieldNode` → `ControlElement` with `scope: "#/properties/<name>"`
|
|
15
|
+
* - `displayName` annotation → `label` on the `ControlElement`
|
|
16
|
+
* - `GroupLayoutNode` → `GroupLayout` with recursively converted `elements`
|
|
17
|
+
* - `ConditionalLayoutNode` → children flattened with a `SHOW` rule
|
|
18
|
+
* - Nested conditionals → combined `allOf` rule
|
|
19
|
+
* - Root wrapper is always `{ type: "VerticalLayout", elements: [...] }`
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const ir = canonicalizeDSL(
|
|
24
|
+
* formspec(
|
|
25
|
+
* group("Customer", field.text("name", { label: "Name" })),
|
|
26
|
+
* when(is("status", "draft"), field.text("notes", { label: "Notes" })),
|
|
27
|
+
* )
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* const uiSchema = generateUiSchemaFromIR(ir);
|
|
31
|
+
* // {
|
|
32
|
+
* // type: "VerticalLayout",
|
|
33
|
+
* // elements: [
|
|
34
|
+
* // {
|
|
35
|
+
* // type: "Group",
|
|
36
|
+
* // label: "Customer",
|
|
37
|
+
* // elements: [{ type: "Control", scope: "#/properties/name", label: "Name" }]
|
|
38
|
+
* // },
|
|
39
|
+
* // {
|
|
40
|
+
* // type: "Control",
|
|
41
|
+
* // scope: "#/properties/notes",
|
|
42
|
+
* // label: "Notes",
|
|
43
|
+
* // rule: { effect: "SHOW", condition: { scope: "#/properties/status", schema: { const: "draft" } } }
|
|
44
|
+
* // }
|
|
45
|
+
* // ]
|
|
46
|
+
* // }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param ir - The canonical FormIR produced by the Canonicalize phase
|
|
50
|
+
* @returns A validated JSON Forms UI Schema
|
|
51
|
+
*/
|
|
52
|
+
export declare function generateUiSchemaFromIR(ir: FormIR): UISchema;
|
|
53
|
+
//# sourceMappingURL=ir-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-generator.d.ts","sourceRoot":"","sources":["../../src/ui-schema/ir-generator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAA6C,MAAM,gBAAgB,CAAC;AACxF,OAAO,KAAK,EACV,QAAQ,EAMT,MAAM,YAAY,CAAC;AAuLpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAO3D"}
|