@formspec/build 0.1.0-alpha.4 → 0.1.0-alpha.41

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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -93
  3. package/dist/analyzer/class-analyzer.d.ts +135 -0
  4. package/dist/analyzer/class-analyzer.d.ts.map +1 -0
  5. package/dist/analyzer/jsdoc-constraints.d.ts +53 -0
  6. package/dist/analyzer/jsdoc-constraints.d.ts.map +1 -0
  7. package/dist/analyzer/program.d.ts +94 -0
  8. package/dist/analyzer/program.d.ts.map +1 -0
  9. package/dist/analyzer/tsdoc-parser.d.ts +126 -0
  10. package/dist/analyzer/tsdoc-parser.d.ts.map +1 -0
  11. package/dist/browser.cjs +2113 -0
  12. package/dist/browser.cjs.map +1 -0
  13. package/dist/browser.d.ts +74 -0
  14. package/dist/browser.d.ts.map +1 -0
  15. package/dist/browser.js +2070 -0
  16. package/dist/browser.js.map +1 -0
  17. package/dist/build-alpha.d.ts +1501 -0
  18. package/dist/build-beta.d.ts +1501 -0
  19. package/dist/build-internal.d.ts +1501 -0
  20. package/dist/build.d.ts +1194 -43
  21. package/dist/canonicalize/chain-dsl-canonicalizer.d.ts +22 -0
  22. package/dist/canonicalize/chain-dsl-canonicalizer.d.ts.map +1 -0
  23. package/dist/canonicalize/index.d.ts +8 -0
  24. package/dist/canonicalize/index.d.ts.map +1 -0
  25. package/dist/canonicalize/tsdoc-canonicalizer.d.ts +38 -0
  26. package/dist/canonicalize/tsdoc-canonicalizer.d.ts.map +1 -0
  27. package/dist/cli.cjs +6715 -0
  28. package/dist/cli.cjs.map +1 -0
  29. package/dist/cli.js +6687 -103
  30. package/dist/cli.js.map +1 -1
  31. package/dist/extensions/index.d.ts +8 -0
  32. package/dist/extensions/index.d.ts.map +1 -0
  33. package/dist/extensions/registry.d.ts +83 -0
  34. package/dist/extensions/registry.d.ts.map +1 -0
  35. package/dist/generators/class-schema.d.ts +347 -0
  36. package/dist/generators/class-schema.d.ts.map +1 -0
  37. package/dist/generators/discovered-schema.d.ts +152 -0
  38. package/dist/generators/discovered-schema.d.ts.map +1 -0
  39. package/dist/generators/method-schema.d.ts +72 -0
  40. package/dist/generators/method-schema.d.ts.map +1 -0
  41. package/dist/generators/mixed-authoring.d.ts +52 -0
  42. package/dist/generators/mixed-authoring.d.ts.map +1 -0
  43. package/dist/index.cjs +6412 -0
  44. package/dist/index.cjs.map +1 -0
  45. package/dist/index.d.ts +50 -8
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +6387 -107
  48. package/dist/index.js.map +1 -1
  49. package/dist/internals.cjs +5573 -0
  50. package/dist/internals.cjs.map +1 -0
  51. package/dist/internals.d.ts +32 -0
  52. package/dist/internals.d.ts.map +1 -0
  53. package/dist/internals.js +5554 -0
  54. package/dist/internals.js.map +1 -0
  55. package/dist/json-schema/generator.d.ts +32 -6
  56. package/dist/json-schema/generator.d.ts.map +1 -1
  57. package/dist/json-schema/ir-generator.d.ts +149 -0
  58. package/dist/json-schema/ir-generator.d.ts.map +1 -0
  59. package/dist/json-schema/schema.d.ts +23 -0
  60. package/dist/json-schema/schema.d.ts.map +1 -0
  61. package/dist/json-schema/types.d.ts +76 -2
  62. package/dist/json-schema/types.d.ts.map +1 -1
  63. package/dist/metadata/collision-guards.d.ts +3 -0
  64. package/dist/metadata/collision-guards.d.ts.map +1 -0
  65. package/dist/metadata/index.d.ts +7 -0
  66. package/dist/metadata/index.d.ts.map +1 -0
  67. package/dist/metadata/policy.d.ts +12 -0
  68. package/dist/metadata/policy.d.ts.map +1 -0
  69. package/dist/metadata/resolve.d.ts +21 -0
  70. package/dist/metadata/resolve.d.ts.map +1 -0
  71. package/dist/static-build.d.ts +61 -0
  72. package/dist/static-build.d.ts.map +1 -0
  73. package/dist/ui-schema/generator.d.ts +18 -2
  74. package/dist/ui-schema/generator.d.ts.map +1 -1
  75. package/dist/ui-schema/ir-generator.d.ts +54 -0
  76. package/dist/ui-schema/ir-generator.d.ts.map +1 -0
  77. package/dist/ui-schema/schema.d.ts +429 -0
  78. package/dist/ui-schema/schema.d.ts.map +1 -0
  79. package/dist/ui-schema/types.d.ts +179 -35
  80. package/dist/ui-schema/types.d.ts.map +1 -1
  81. package/dist/validate/constraint-validator.d.ts +85 -0
  82. package/dist/validate/constraint-validator.d.ts.map +1 -0
  83. package/dist/validate/index.d.ts +9 -0
  84. package/dist/validate/index.d.ts.map +1 -0
  85. package/package.json +31 -11
  86. package/dist/__tests__/cli.test.d.ts +0 -2
  87. package/dist/__tests__/cli.test.d.ts.map +0 -1
  88. package/dist/__tests__/cli.test.js +0 -178
  89. package/dist/__tests__/cli.test.js.map +0 -1
  90. package/dist/__tests__/edge-cases.test.d.ts +0 -7
  91. package/dist/__tests__/edge-cases.test.d.ts.map +0 -1
  92. package/dist/__tests__/edge-cases.test.js +0 -217
  93. package/dist/__tests__/edge-cases.test.js.map +0 -1
  94. package/dist/__tests__/generator.test.d.ts +0 -2
  95. package/dist/__tests__/generator.test.d.ts.map +0 -1
  96. package/dist/__tests__/generator.test.js +0 -225
  97. package/dist/__tests__/generator.test.js.map +0 -1
  98. package/dist/__tests__/integration.test.d.ts +0 -8
  99. package/dist/__tests__/integration.test.d.ts.map +0 -1
  100. package/dist/__tests__/integration.test.js +0 -163
  101. package/dist/__tests__/integration.test.js.map +0 -1
  102. package/dist/__tests__/write-schemas.test.d.ts +0 -2
  103. package/dist/__tests__/write-schemas.test.d.ts.map +0 -1
  104. package/dist/__tests__/write-schemas.test.js +0 -196
  105. package/dist/__tests__/write-schemas.test.js.map +0 -1
  106. package/dist/json-schema/generator.js +0 -161
  107. package/dist/json-schema/generator.js.map +0 -1
  108. package/dist/json-schema/types.js +0 -7
  109. package/dist/json-schema/types.js.map +0 -1
  110. package/dist/ui-schema/generator.js +0 -150
  111. package/dist/ui-schema/generator.js.map +0 -1
  112. package/dist/ui-schema/types.js +0 -8
  113. package/dist/ui-schema/types.js.map +0 -1
@@ -1,196 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
- import * as fs from "node:fs";
3
- import * as path from "node:path";
4
- import * as os from "node:os";
5
- import { writeSchemas } from "../index.js";
6
- import { formspec, field, group } from "@formspec/dsl";
7
- describe("writeSchemas", () => {
8
- let tempDir;
9
- beforeEach(() => {
10
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "formspec-test-"));
11
- });
12
- afterEach(() => {
13
- // Clean up temp directory
14
- if (fs.existsSync(tempDir)) {
15
- fs.rmSync(tempDir, { recursive: true });
16
- }
17
- });
18
- // Positive tests
19
- describe("positive cases", () => {
20
- it("should write both schema files to specified directory", () => {
21
- const form = formspec(field.text("name", { required: true }), field.number("age"));
22
- const result = writeSchemas(form, {
23
- outDir: tempDir,
24
- name: "test",
25
- });
26
- expect(fs.existsSync(result.jsonSchemaPath)).toBe(true);
27
- expect(fs.existsSync(result.uiSchemaPath)).toBe(true);
28
- expect(result.jsonSchemaPath).toBe(path.join(tempDir, "test-schema.json"));
29
- expect(result.uiSchemaPath).toBe(path.join(tempDir, "test-uischema.json"));
30
- });
31
- it("should create output directory if it doesn't exist", () => {
32
- const form = formspec(field.text("name"));
33
- const nestedDir = path.join(tempDir, "nested", "deeply", "output");
34
- expect(fs.existsSync(nestedDir)).toBe(false);
35
- writeSchemas(form, {
36
- outDir: nestedDir,
37
- name: "test",
38
- });
39
- expect(fs.existsSync(nestedDir)).toBe(true);
40
- });
41
- it("should use 'schema' as default name when not provided", () => {
42
- const form = formspec(field.text("name"));
43
- const result = writeSchemas(form, {
44
- outDir: tempDir,
45
- });
46
- expect(result.jsonSchemaPath).toBe(path.join(tempDir, "schema-schema.json"));
47
- expect(result.uiSchemaPath).toBe(path.join(tempDir, "schema-uischema.json"));
48
- });
49
- it("should use custom indentation when provided", () => {
50
- const form = formspec(field.text("name"));
51
- writeSchemas(form, {
52
- outDir: tempDir,
53
- name: "test",
54
- indent: 4,
55
- });
56
- const content = fs.readFileSync(path.join(tempDir, "test-schema.json"), "utf-8");
57
- // With indent 4, we should see 4-space indentation
58
- expect(content).toContain(" "); // 4 spaces
59
- });
60
- it("should generate valid JSON files that can be parsed", () => {
61
- const form = formspec(field.text("name"), field.enum("status", ["draft", "active"]));
62
- const result = writeSchemas(form, {
63
- outDir: tempDir,
64
- name: "test",
65
- });
66
- const jsonSchema = JSON.parse(fs.readFileSync(result.jsonSchemaPath, "utf-8"));
67
- const uiSchema = JSON.parse(fs.readFileSync(result.uiSchemaPath, "utf-8"));
68
- expect(jsonSchema).toHaveProperty("type", "object");
69
- expect(jsonSchema).toHaveProperty("properties");
70
- expect(uiSchema).toHaveProperty("type");
71
- });
72
- it("should generate correct schema content matching buildFormSchemas output", () => {
73
- const form = formspec(group("Info", field.text("name", { label: "Name", required: true }), field.number("age", { label: "Age", min: 0 })));
74
- const result = writeSchemas(form, {
75
- outDir: tempDir,
76
- name: "test",
77
- });
78
- const jsonSchema = JSON.parse(fs.readFileSync(result.jsonSchemaPath, "utf-8"));
79
- expect(jsonSchema.properties).toHaveProperty("name");
80
- expect(jsonSchema.properties).toHaveProperty("age");
81
- expect(jsonSchema.required).toContain("name");
82
- expect(jsonSchema.properties.age).toHaveProperty("minimum", 0);
83
- });
84
- it("should handle forms with enum fields", () => {
85
- const form = formspec(field.enum("status", ["draft", "published", "archived"]));
86
- const result = writeSchemas(form, {
87
- outDir: tempDir,
88
- name: "test",
89
- });
90
- const jsonSchema = JSON.parse(fs.readFileSync(result.jsonSchemaPath, "utf-8"));
91
- expect(jsonSchema.properties.status).toHaveProperty("enum");
92
- expect(jsonSchema.properties.status.enum).toEqual(["draft", "published", "archived"]);
93
- });
94
- it("should handle forms with nested objects", () => {
95
- const form = formspec(field.object("address", field.text("street"), field.text("city")));
96
- const result = writeSchemas(form, {
97
- outDir: tempDir,
98
- name: "test",
99
- });
100
- const jsonSchema = JSON.parse(fs.readFileSync(result.jsonSchemaPath, "utf-8"));
101
- expect(jsonSchema.properties.address).toHaveProperty("type", "object");
102
- expect(jsonSchema.properties.address.properties).toHaveProperty("street");
103
- expect(jsonSchema.properties.address.properties).toHaveProperty("city");
104
- });
105
- it("should handle forms with arrays", () => {
106
- const form = formspec(field.array("items", field.text("name"), field.number("quantity")));
107
- const result = writeSchemas(form, {
108
- outDir: tempDir,
109
- name: "test",
110
- });
111
- const jsonSchema = JSON.parse(fs.readFileSync(result.jsonSchemaPath, "utf-8"));
112
- expect(jsonSchema.properties.items).toHaveProperty("type", "array");
113
- expect(jsonSchema.properties.items).toHaveProperty("items");
114
- });
115
- });
116
- // Negative tests
117
- describe("negative cases", () => {
118
- it("should overwrite existing files", () => {
119
- const form1 = formspec(field.text("original"));
120
- const form2 = formspec(field.text("updated"));
121
- // Write first version
122
- writeSchemas(form1, {
123
- outDir: tempDir,
124
- name: "test",
125
- });
126
- // Write second version
127
- const result = writeSchemas(form2, {
128
- outDir: tempDir,
129
- name: "test",
130
- });
131
- const jsonSchema = JSON.parse(fs.readFileSync(result.jsonSchemaPath, "utf-8"));
132
- expect(jsonSchema.properties).toHaveProperty("updated");
133
- expect(jsonSchema.properties).not.toHaveProperty("original");
134
- });
135
- it("should handle empty forms", () => {
136
- const form = formspec();
137
- const result = writeSchemas(form, {
138
- outDir: tempDir,
139
- name: "empty",
140
- });
141
- expect(fs.existsSync(result.jsonSchemaPath)).toBe(true);
142
- const jsonSchema = JSON.parse(fs.readFileSync(result.jsonSchemaPath, "utf-8"));
143
- expect(jsonSchema).toHaveProperty("type", "object");
144
- });
145
- it("should handle forms with special characters in field names", () => {
146
- const form = formspec(field.text("field-with-dashes"), field.text("field_with_underscores"));
147
- const result = writeSchemas(form, {
148
- outDir: tempDir,
149
- name: "test",
150
- });
151
- const jsonSchema = JSON.parse(fs.readFileSync(result.jsonSchemaPath, "utf-8"));
152
- expect(jsonSchema.properties).toHaveProperty("field-with-dashes");
153
- expect(jsonSchema.properties).toHaveProperty("field_with_underscores");
154
- });
155
- it("should handle output directory with trailing slash", () => {
156
- const form = formspec(field.text("name"));
157
- const result = writeSchemas(form, {
158
- outDir: tempDir + "/",
159
- name: "test",
160
- });
161
- expect(fs.existsSync(result.jsonSchemaPath)).toBe(true);
162
- });
163
- });
164
- // Edge cases
165
- describe("edge cases", () => {
166
- it("should handle name with dots", () => {
167
- const form = formspec(field.text("name"));
168
- const result = writeSchemas(form, {
169
- outDir: tempDir,
170
- name: "my.form.v1",
171
- });
172
- expect(result.jsonSchemaPath).toBe(path.join(tempDir, "my.form.v1-schema.json"));
173
- });
174
- it("should return absolute paths", () => {
175
- const form = formspec(field.text("name"));
176
- const result = writeSchemas(form, {
177
- outDir: tempDir,
178
- name: "test",
179
- });
180
- expect(path.isAbsolute(result.jsonSchemaPath)).toBe(true);
181
- expect(path.isAbsolute(result.uiSchemaPath)).toBe(true);
182
- });
183
- it("should handle zero indent (compact JSON)", () => {
184
- const form = formspec(field.text("name"));
185
- writeSchemas(form, {
186
- outDir: tempDir,
187
- name: "test",
188
- indent: 0,
189
- });
190
- const content = fs.readFileSync(path.join(tempDir, "test-schema.json"), "utf-8");
191
- // With indent 0, JSON should be on one line (no newlines except at end)
192
- expect(content.split("\n").length).toBeLessThanOrEqual(2);
193
- });
194
- });
195
- });
196
- //# sourceMappingURL=write-schemas.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"write-schemas.test.js","sourceRoot":"","sources":["../../src/__tests__/write-schemas.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEvD,Q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IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1D,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAClD,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAE1C,YAAY,CAAC,IAAI,EAAE;gBACjB,MAAM,EAAE,OAAO;gBACf,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE,CAAC;aACV,CAAC,CAAC;YAEH,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC,CAAC;YACjF,wEAAwE;YACxE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,161 +0,0 @@
1
- /**
2
- * JSON Schema generator for FormSpec forms.
3
- */
4
- /**
5
- * Generates JSON Schema for nested elements (used for array items and object properties).
6
- */
7
- function generateNestedSchema(elements) {
8
- const properties = {};
9
- const required = [];
10
- collectFields(elements, properties, required);
11
- return {
12
- type: "object",
13
- properties,
14
- ...(required.length > 0 && { required }),
15
- };
16
- }
17
- /**
18
- * Converts a single field to its JSON Schema representation.
19
- */
20
- function fieldToJsonSchema(field) {
21
- const base = {};
22
- if (field.label !== undefined) {
23
- base.title = field.label;
24
- }
25
- switch (field._field) {
26
- case "text":
27
- return { ...base, type: "string" };
28
- case "number":
29
- return {
30
- ...base,
31
- type: "number",
32
- ...(field.min !== undefined && { minimum: field.min }),
33
- ...(field.max !== undefined && { maximum: field.max }),
34
- };
35
- case "boolean":
36
- return { ...base, type: "boolean" };
37
- case "enum": {
38
- const opts = field.options;
39
- const isObjectOptions = opts.length > 0 &&
40
- opts.every((opt) => typeof opt === "object" && opt !== null && "id" in opt && "label" in opt);
41
- if (isObjectOptions) {
42
- // Object options with id/label: use oneOf with const/title
43
- return {
44
- ...base,
45
- type: "string",
46
- oneOf: opts.map((o) => ({
47
- const: o.id,
48
- title: o.label,
49
- })),
50
- };
51
- }
52
- return { ...base, type: "string", enum: opts };
53
- }
54
- case "dynamic_enum":
55
- // Dynamic enums are strings at the schema level
56
- // The actual options are resolved at runtime
57
- // x-formspec-source indicates the data source key
58
- // x-formspec-params indicates dependent field names for fetching options
59
- return {
60
- ...base,
61
- type: "string",
62
- "x-formspec-source": field.source,
63
- ...(field.params !== undefined &&
64
- field.params.length > 0 && { "x-formspec-params": field.params }),
65
- };
66
- case "dynamic_schema":
67
- // Dynamic schemas are objects with unknown properties
68
- // x-formspec-schemaSource indicates where to load the schema from
69
- return {
70
- ...base,
71
- type: "object",
72
- additionalProperties: true,
73
- "x-formspec-schemaSource": field.schemaSource,
74
- };
75
- case "array": {
76
- const arrayField = field;
77
- return {
78
- ...base,
79
- type: "array",
80
- items: generateNestedSchema(arrayField.items),
81
- ...(arrayField.minItems !== undefined && { minItems: arrayField.minItems }),
82
- ...(arrayField.maxItems !== undefined && { maxItems: arrayField.maxItems }),
83
- };
84
- }
85
- case "object": {
86
- const objectField = field;
87
- const nestedSchema = generateNestedSchema(objectField.properties);
88
- return {
89
- ...base,
90
- ...nestedSchema,
91
- };
92
- }
93
- default: {
94
- // Exhaustiveness check
95
- const _exhaustive = field;
96
- return _exhaustive;
97
- }
98
- }
99
- }
100
- /**
101
- * Visits all elements in a form tree, collecting fields and required fields.
102
- */
103
- function collectFields(elements, properties, required) {
104
- for (const element of elements) {
105
- switch (element._type) {
106
- case "field":
107
- properties[element.name] = fieldToJsonSchema(element);
108
- if (element.required === true) {
109
- required.push(element.name);
110
- }
111
- break;
112
- case "group":
113
- // Groups don't affect schema structure, just collect their children
114
- collectFields(element.elements, properties, required);
115
- break;
116
- case "conditional":
117
- // Conditional fields are still part of the schema
118
- // They're just hidden/shown in the UI
119
- collectFields(element
120
- .elements, properties, required);
121
- break;
122
- }
123
- }
124
- }
125
- /**
126
- * Generates a JSON Schema from a FormSpec.
127
- *
128
- * @example
129
- * ```typescript
130
- * const form = formspec(
131
- * field.text("name", { label: "Name", required: true }),
132
- * field.number("age", { min: 0 }),
133
- * );
134
- *
135
- * const schema = generateJsonSchema(form);
136
- * // {
137
- * // $schema: "https://json-schema.org/draft-07/schema#",
138
- * // type: "object",
139
- * // properties: {
140
- * // name: { type: "string", title: "Name" },
141
- * // age: { type: "number", minimum: 0 }
142
- * // },
143
- * // required: ["name"]
144
- * // }
145
- * ```
146
- *
147
- * @param form - The FormSpec to convert
148
- * @returns A JSON Schema object
149
- */
150
- export function generateJsonSchema(form) {
151
- const properties = {};
152
- const required = [];
153
- collectFields(form.elements, properties, required);
154
- return {
155
- $schema: "https://json-schema.org/draft-07/schema#",
156
- type: "object",
157
- properties,
158
- ...(required.length > 0 && { required }),
159
- };
160
- }
161
- //# sourceMappingURL=generator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/json-schema/generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH;;GAEG;AACH,SAAS,oBAAoB,CAAC,QAAgC;IAC5D,MAAM,UAAU,GAAgC,EAAE,CAAC;IACnD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,aAAa,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE9C,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU;QACV,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;KACzC,CAAC;AACJ,CAAC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AAE,QAAQ;QACd,UAAU;QACV,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;KACzC,CAAC;AACJ,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * JSON Schema Draft-07 type definitions.
3
- *
4
- * These types are a subset of JSON Schema sufficient for form generation.
5
- */
6
- export {};
7
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/json-schema/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -1,150 +0,0 @@
1
- /**
2
- * JSON Forms UI Schema generator for FormSpec forms.
3
- */
4
- /**
5
- * Converts a field name to a JSON Pointer scope.
6
- */
7
- function fieldToScope(fieldName) {
8
- return `#/properties/${fieldName}`;
9
- }
10
- /**
11
- * Creates a rule for conditional visibility.
12
- */
13
- function createShowRule(fieldName, value) {
14
- return {
15
- effect: "SHOW",
16
- condition: {
17
- scope: fieldToScope(fieldName),
18
- schema: { const: value },
19
- },
20
- };
21
- }
22
- /**
23
- * Combines two rules into one using allOf.
24
- *
25
- * When elements are nested inside multiple conditionals, all conditions
26
- * must be met for the element to be visible.
27
- */
28
- function combineRules(parentRule, childRule) {
29
- // Both rules should have the same effect (SHOW)
30
- // Combine conditions using allOf
31
- const parentCondition = parentRule.condition;
32
- const childCondition = childRule.condition;
33
- return {
34
- effect: "SHOW",
35
- condition: {
36
- scope: "#",
37
- schema: {
38
- allOf: [
39
- {
40
- properties: {
41
- [parentCondition.scope.replace("#/properties/", "")]: parentCondition.schema,
42
- },
43
- },
44
- {
45
- properties: {
46
- [childCondition.scope.replace("#/properties/", "")]: childCondition.schema,
47
- },
48
- },
49
- ],
50
- },
51
- },
52
- };
53
- }
54
- /**
55
- * Converts form elements to UI Schema elements.
56
- *
57
- * @param elements - The form elements to convert
58
- * @param parentRule - Optional rule inherited from parent conditional
59
- * @returns Array of UI Schema elements
60
- */
61
- function elementsToUiSchema(elements, parentRule) {
62
- const result = [];
63
- for (const element of elements) {
64
- switch (element._type) {
65
- case "field": {
66
- const control = {
67
- type: "Control",
68
- scope: fieldToScope(element.name),
69
- ...(element.label !== undefined && { label: element.label }),
70
- ...(parentRule !== undefined && { rule: parentRule }),
71
- };
72
- result.push(control);
73
- break;
74
- }
75
- case "group": {
76
- const groupElement = element;
77
- const group = {
78
- type: "Group",
79
- label: groupElement.label,
80
- elements: elementsToUiSchema(groupElement.elements, parentRule),
81
- ...(parentRule !== undefined && { rule: parentRule }),
82
- };
83
- result.push(group);
84
- break;
85
- }
86
- case "conditional": {
87
- const conditionalElement = element;
88
- // Create a rule for this conditional
89
- const newRule = createShowRule(conditionalElement.field, conditionalElement.value);
90
- // Combine with parent rule if present (for nested conditionals)
91
- const combinedRule = parentRule !== undefined
92
- ? combineRules(parentRule, newRule)
93
- : newRule;
94
- // Apply the combined rule to all children
95
- const childElements = elementsToUiSchema(conditionalElement.elements, combinedRule);
96
- result.push(...childElements);
97
- break;
98
- }
99
- }
100
- }
101
- return result;
102
- }
103
- /**
104
- * Generates a JSON Forms UI Schema from a FormSpec.
105
- *
106
- * @example
107
- * ```typescript
108
- * const form = formspec(
109
- * group("Customer",
110
- * field.text("name", { label: "Name" }),
111
- * ),
112
- * when("status", "draft",
113
- * field.text("notes", { label: "Notes" }),
114
- * ),
115
- * );
116
- *
117
- * const uiSchema = generateUiSchema(form);
118
- * // {
119
- * // type: "VerticalLayout",
120
- * // elements: [
121
- * // {
122
- * // type: "Group",
123
- * // label: "Customer",
124
- * // elements: [
125
- * // { type: "Control", scope: "#/properties/name", label: "Name" }
126
- * // ]
127
- * // },
128
- * // {
129
- * // type: "Control",
130
- * // scope: "#/properties/notes",
131
- * // label: "Notes",
132
- * // rule: {
133
- * // effect: "SHOW",
134
- * // condition: { scope: "#/properties/status", schema: { const: "draft" } }
135
- * // }
136
- * // }
137
- * // ]
138
- * // }
139
- * ```
140
- *
141
- * @param form - The FormSpec to convert
142
- * @returns A JSON Forms UI Schema
143
- */
144
- export function generateUiSchema(form) {
145
- return {
146
- type: "VerticalLayout",
147
- elements: elementsToUiSchema(form.elements),
148
- };
149
- }
150
- //# sourceMappingURL=generator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/ui-schema/generator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgBH;;GAEG;AACH,SAAS,YAAY,CAAC,SAAiB;IACrC,OAAO,gBAAgB,SAAS,EAAE,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,SAAiB,EAAE,KAAc;IACvD,OAAO;QACL,MAAM,EAAE,MAAM;QACd,SAAS,EAAE;YACT,KAAK,EAAE,YAAY,CAAC,SAAS,CAAC;YAC9B,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;SACzB;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,UAAgB,EAAE,SAAe;IACrD,gDAAgD;IAChD,iCAAiC;IACjC,MAAM,eAAe,GAAG,UAAU,CAAC,SAAS,CAAC;IAC7C,MAAM,cAAc,GAAG,SAAS,CAAC,SAAS,CAAC;IAE3C,OAAO;QACL,MAAM,EAAE,MAAM;QACd,SAAS,EAAE;YACT,KAAK,EAAE,GAAG;YACV,MAAM,EAAE;gBACN,KAAK,EAAE;oBACL;wBACE,UAAU,EAAE;4BACV,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM;yBAC7E;qBACF;oBACD;wBACE,UAAU,EAAE;4BACV,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,EAAE,cAAc,CAAC,MAAM;yBAC3E;qBACF;iBACF;aACF;SACF;KACF,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,QAAgC,EAChC,UAAiB;IAE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AO,CAAC;oBACnC,CAAC,CAAC,OAAO,CAAC;gBACZ,0CAA0C;gBAC1C,MAAM,aAAa,GAAG,kBAAkB,CACtC,kBAAkB,CAAC,QAAQ,EAC3B,YAAY,CACb,CAAC;gBACF,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;gBAC9B,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAiB;IAEjB,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC;KAC5C,CAAC;AACJ,CAAC"}
@@ -1,8 +0,0 @@
1
- /**
2
- * JSON Forms UI Schema type definitions.
3
- *
4
- * These types define the UI layout structure for JSON Forms.
5
- * See: https://jsonforms.io/docs/uischema/
6
- */
7
- export {};
8
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ui-schema/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}