@formspec/dsl 0.1.0-alpha.2 → 0.1.0-alpha.23

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/dist/index.js CHANGED
@@ -1,39 +1,412 @@
1
- /**
2
- * `@formspec/dsl` - DSL functions for defining FormSpec forms
3
- *
4
- * This package provides the builder functions for creating form specifications:
5
- * - `field.*` - Field builders (text, number, boolean, enum, dynamicEnum)
6
- * - `group()` - Visual grouping
7
- * - `when()` + `is()` - Conditional visibility
8
- * - `formspec()` - Top-level form definition
9
- *
10
- * @example
11
- * ```typescript
12
- * import { formspec, field, group, when, is } from "@formspec/dsl";
13
- *
14
- * const InvoiceForm = formspec(
15
- * group("Customer",
16
- * field.text("customerName", { label: "Customer Name" }),
17
- * field.dynamicEnum("country", "fetch_countries", { label: "Country" }),
18
- * ),
19
- * group("Invoice Details",
20
- * field.number("amount", { label: "Amount", min: 0 }),
21
- * field.enum("status", ["draft", "sent", "paid"] as const),
22
- * when(is("status", "draft"),
23
- * field.text("internalNotes", { label: "Internal Notes" }),
24
- * ),
25
- * ),
26
- * );
27
- * ```
28
- *
29
- * @packageDocumentation
30
- */
31
- // Field builders
32
- export { field } from "./field.js";
33
- // Predicate builders
34
- export { is } from "./predicate.js";
35
- // Structure builders
36
- export { group, when, formspec, formspecWithValidation } from "./structure.js";
37
- // Validation
38
- export { validateForm, logValidationIssues } from "./validation.js";
1
+ // src/field.ts
2
+ var field = {
3
+ /**
4
+ * Creates a text input field.
5
+ *
6
+ * @param name - The field name (used as the schema key)
7
+ * @param config - Optional configuration for label, placeholder, etc.
8
+ * @returns A TextField descriptor
9
+ */
10
+ text: (name, config) => ({
11
+ _type: "field",
12
+ _field: "text",
13
+ name,
14
+ ...config
15
+ }),
16
+ /**
17
+ * Creates a numeric input field.
18
+ *
19
+ * @param name - The field name (used as the schema key)
20
+ * @param config - Optional configuration for label, min, max, etc.
21
+ * @returns A NumberField descriptor
22
+ */
23
+ number: (name, config) => ({
24
+ _type: "field",
25
+ _field: "number",
26
+ name,
27
+ ...config
28
+ }),
29
+ /**
30
+ * Creates a boolean checkbox field.
31
+ *
32
+ * @param name - The field name (used as the schema key)
33
+ * @param config - Optional configuration for label, etc.
34
+ * @returns A BooleanField descriptor
35
+ */
36
+ boolean: (name, config) => ({
37
+ _type: "field",
38
+ _field: "boolean",
39
+ name,
40
+ ...config
41
+ }),
42
+ /**
43
+ * Creates a field with static enum options (known at compile time).
44
+ *
45
+ * Literal types are automatically inferred - no `as const` needed:
46
+ * ```typescript
47
+ * field.enum("status", ["draft", "sent", "paid"])
48
+ * // Schema type: "draft" | "sent" | "paid"
49
+ * ```
50
+ *
51
+ * Options can be strings or objects with `id` and `label`:
52
+ * ```typescript
53
+ * field.enum("priority", [
54
+ * { id: "low", label: "Low Priority" },
55
+ * { id: "high", label: "High Priority" },
56
+ * ])
57
+ * ```
58
+ *
59
+ * **Note:** All options must be of the same type (all strings OR all objects).
60
+ * Mixing strings and objects will throw a runtime error.
61
+ *
62
+ * @param name - The field name (used as the schema key)
63
+ * @param options - Array of allowed string values or objects with `id` and `label` properties
64
+ * @param config - Optional configuration for label, etc.
65
+ * @returns A StaticEnumField descriptor
66
+ * @throws Error if options array contains mixed types (strings and objects)
67
+ */
68
+ enum: (name, options, config) => {
69
+ if (options.length > 0) {
70
+ const first = options[0];
71
+ const firstIsObject = typeof first === "object" && first !== null;
72
+ for (const opt of options) {
73
+ const optIsObject = typeof opt === "object" && opt !== null;
74
+ if (optIsObject !== firstIsObject) {
75
+ throw new Error(
76
+ `field.enum("${name}"): options must be all strings or all objects with {id, label}, not mixed. Received mixed types in options array.`
77
+ );
78
+ }
79
+ }
80
+ if (firstIsObject) {
81
+ for (const opt of options) {
82
+ const obj = opt;
83
+ if (typeof obj.id !== "string" || typeof obj.label !== "string") {
84
+ throw new Error(
85
+ `field.enum("${name}"): object options must have string "id" and "label" properties. Received: ${JSON.stringify(opt)}`
86
+ );
87
+ }
88
+ }
89
+ }
90
+ }
91
+ return {
92
+ _type: "field",
93
+ _field: "enum",
94
+ name,
95
+ options,
96
+ ...config
97
+ };
98
+ },
99
+ /**
100
+ * Creates a field with dynamic enum options (fetched from a data source at runtime).
101
+ *
102
+ * The data source must be registered in DataSourceRegistry via module augmentation:
103
+ * ```typescript
104
+ * declare module "@formspec/core" {
105
+ * interface DataSourceRegistry {
106
+ * countries: { id: string; code: string; name: string };
107
+ * }
108
+ * }
109
+ *
110
+ * field.dynamicEnum("country", "countries", { label: "Country" })
111
+ * ```
112
+ *
113
+ * @param name - The field name (used as the schema key)
114
+ * @param source - The data source key (must be in DataSourceRegistry)
115
+ * @param config - Optional configuration for label, params, etc.
116
+ * @returns A DynamicEnumField descriptor
117
+ */
118
+ dynamicEnum: (name, source, config) => ({
119
+ _type: "field",
120
+ _field: "dynamic_enum",
121
+ name,
122
+ source,
123
+ ...config
124
+ }),
125
+ /**
126
+ * Creates a field that loads its schema dynamically (e.g., from an extension).
127
+ *
128
+ * @param name - The field name (used as the schema key)
129
+ * @param schemaSource - Identifier for the schema source
130
+ * @param config - Optional configuration for label, etc.
131
+ * @returns A DynamicSchemaField descriptor
132
+ */
133
+ dynamicSchema: (name, schemaSource, config) => ({
134
+ _type: "field",
135
+ _field: "dynamic_schema",
136
+ name,
137
+ schemaSource,
138
+ ...config
139
+ }),
140
+ /**
141
+ * Creates an array field containing repeating items.
142
+ *
143
+ * Use this for lists of values (e.g., multiple addresses, line items).
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * field.array("addresses",
148
+ * field.text("street", { label: "Street" }),
149
+ * field.text("city", { label: "City" }),
150
+ * field.text("zip", { label: "ZIP Code" }),
151
+ * )
152
+ * ```
153
+ *
154
+ * @param name - The field name (used as the schema key)
155
+ * @param items - The form elements that define each array item
156
+ * @returns An ArrayField descriptor
157
+ */
158
+ array: (name, ...items) => ({
159
+ _type: "field",
160
+ _field: "array",
161
+ name,
162
+ items
163
+ }),
164
+ /**
165
+ * Creates an array field with additional configuration options.
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * field.arrayWithConfig("lineItems", {
170
+ * label: "Line Items",
171
+ * minItems: 1,
172
+ * maxItems: 10,
173
+ * },
174
+ * field.text("description"),
175
+ * field.number("quantity"),
176
+ * )
177
+ * ```
178
+ *
179
+ * @param name - The field name (used as the schema key)
180
+ * @param config - Configuration for label, minItems, maxItems, etc.
181
+ * @param items - The form elements that define each array item
182
+ * @returns An ArrayField descriptor
183
+ */
184
+ arrayWithConfig: (name, config, ...items) => ({
185
+ _type: "field",
186
+ _field: "array",
187
+ name,
188
+ items,
189
+ ...config
190
+ }),
191
+ /**
192
+ * Creates an object field containing nested properties.
193
+ *
194
+ * Use this for grouping related fields under a single key in the schema.
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * field.object("address",
199
+ * field.text("street", { label: "Street" }),
200
+ * field.text("city", { label: "City" }),
201
+ * field.text("zip", { label: "ZIP Code" }),
202
+ * )
203
+ * ```
204
+ *
205
+ * @param name - The field name (used as the schema key)
206
+ * @param properties - The form elements that define the object's properties
207
+ * @returns An ObjectField descriptor
208
+ */
209
+ object: (name, ...properties) => ({
210
+ _type: "field",
211
+ _field: "object",
212
+ name,
213
+ properties
214
+ }),
215
+ /**
216
+ * Creates an object field with additional configuration options.
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * field.objectWithConfig("billingAddress", { label: "Billing Address", required: true },
221
+ * field.text("street"),
222
+ * field.text("city"),
223
+ * )
224
+ * ```
225
+ *
226
+ * @param name - The field name (used as the schema key)
227
+ * @param config - Configuration for label, required, etc.
228
+ * @param properties - The form elements that define the object's properties
229
+ * @returns An ObjectField descriptor
230
+ */
231
+ objectWithConfig: (name, config, ...properties) => ({
232
+ _type: "field",
233
+ _field: "object",
234
+ name,
235
+ properties,
236
+ ...config
237
+ })
238
+ };
239
+
240
+ // src/predicate.ts
241
+ function is(field2, value) {
242
+ return {
243
+ _predicate: "equals",
244
+ field: field2,
245
+ value
246
+ };
247
+ }
248
+
249
+ // src/validation.ts
250
+ function collectFieldNames(elements, path = "") {
251
+ const fieldNames = /* @__PURE__ */ new Map();
252
+ function visit(elements2, currentPath) {
253
+ for (const element of elements2) {
254
+ switch (element._type) {
255
+ case "field": {
256
+ const field2 = element;
257
+ const fieldPath = currentPath ? `${currentPath}.${field2.name}` : field2.name;
258
+ const existing = fieldNames.get(field2.name);
259
+ if (existing !== void 0) {
260
+ existing.count++;
261
+ existing.paths.push(fieldPath);
262
+ } else {
263
+ fieldNames.set(field2.name, { count: 1, paths: [fieldPath] });
264
+ }
265
+ if (field2._field === "array") {
266
+ const arrayField = field2;
267
+ visit(arrayField.items, `${fieldPath}[]`);
268
+ } else if (field2._field === "object") {
269
+ const objectField = field2;
270
+ visit(objectField.properties, fieldPath);
271
+ }
272
+ break;
273
+ }
274
+ case "group": {
275
+ const group2 = element;
276
+ const groupPath = currentPath ? `${currentPath}.[${group2.label}]` : `[${group2.label}]`;
277
+ visit(group2.elements, groupPath);
278
+ break;
279
+ }
280
+ case "conditional": {
281
+ const conditional = element;
282
+ const conditionalPath = currentPath ? `${currentPath}.when(${conditional.field})` : `when(${conditional.field})`;
283
+ visit(conditional.elements, conditionalPath);
284
+ break;
285
+ }
286
+ }
287
+ }
288
+ }
289
+ visit(elements, path);
290
+ return fieldNames;
291
+ }
292
+ function collectConditionalReferences(elements, path = "") {
293
+ const references = [];
294
+ function visit(elements2, currentPath) {
295
+ for (const element of elements2) {
296
+ switch (element._type) {
297
+ case "field": {
298
+ const field2 = element;
299
+ const fieldPath = currentPath ? `${currentPath}.${field2.name}` : field2.name;
300
+ if (field2._field === "array") {
301
+ const arrayField = field2;
302
+ visit(arrayField.items, `${fieldPath}[]`);
303
+ } else if (field2._field === "object") {
304
+ const objectField = field2;
305
+ visit(objectField.properties, fieldPath);
306
+ }
307
+ break;
308
+ }
309
+ case "group": {
310
+ const group2 = element;
311
+ const groupPath = currentPath ? `${currentPath}.[${group2.label}]` : `[${group2.label}]`;
312
+ visit(group2.elements, groupPath);
313
+ break;
314
+ }
315
+ case "conditional": {
316
+ const conditional = element;
317
+ const conditionalPath = currentPath ? `${currentPath}.when(${conditional.field})` : `when(${conditional.field})`;
318
+ references.push({
319
+ fieldName: conditional.field,
320
+ path: conditionalPath
321
+ });
322
+ visit(conditional.elements, conditionalPath);
323
+ break;
324
+ }
325
+ }
326
+ }
327
+ }
328
+ visit(elements, path);
329
+ return references;
330
+ }
331
+ function validateForm(elements) {
332
+ const issues = [];
333
+ const fieldNames = collectFieldNames(elements);
334
+ for (const [name, info] of fieldNames) {
335
+ if (info.count > 1 && info.paths[0] !== void 0) {
336
+ issues.push({
337
+ severity: "error",
338
+ message: `Duplicate field name "${name}" found ${String(info.count)} times at: ${info.paths.join(", ")}`,
339
+ path: info.paths[0]
340
+ });
341
+ }
342
+ }
343
+ const references = collectConditionalReferences(elements);
344
+ for (const ref of references) {
345
+ if (!fieldNames.has(ref.fieldName)) {
346
+ issues.push({
347
+ severity: "error",
348
+ message: `Conditional references non-existent field "${ref.fieldName}"`,
349
+ path: ref.path
350
+ });
351
+ }
352
+ }
353
+ return {
354
+ valid: issues.every((issue) => issue.severity !== "error"),
355
+ issues
356
+ };
357
+ }
358
+ function logValidationIssues(result, formName) {
359
+ if (result.issues.length === 0) {
360
+ return;
361
+ }
362
+ const prefix = formName ? `FormSpec "${formName}"` : "FormSpec";
363
+ for (const issue of result.issues) {
364
+ const location = issue.path ? ` at ${issue.path}` : "";
365
+ const message = `${prefix}: ${issue.message}${location}`;
366
+ if (issue.severity === "error") {
367
+ console.error(message);
368
+ } else {
369
+ console.warn(message);
370
+ }
371
+ }
372
+ }
373
+
374
+ // src/structure.ts
375
+ function group(label, ...elements) {
376
+ return { _type: "group", label, elements };
377
+ }
378
+ function when(predicate, ...elements) {
379
+ return {
380
+ _type: "conditional",
381
+ field: predicate.field,
382
+ value: predicate.value,
383
+ elements
384
+ };
385
+ }
386
+ function formspec(...elements) {
387
+ return { elements };
388
+ }
389
+ function formspecWithValidation(options, ...elements) {
390
+ if (options.validate) {
391
+ const result = validateForm(elements);
392
+ if (options.validate === "throw" && !result.valid) {
393
+ const errors = result.issues.filter((i) => i.severity === "error").map((i) => i.message).join("; ");
394
+ throw new Error(`Form validation failed: ${errors}`);
395
+ }
396
+ if (options.validate === true || options.validate === "warn") {
397
+ logValidationIssues(result, options.name);
398
+ }
399
+ }
400
+ return { elements };
401
+ }
402
+ export {
403
+ field,
404
+ formspec,
405
+ formspecWithValidation,
406
+ group,
407
+ is,
408
+ logValidationIssues,
409
+ validateForm,
410
+ when
411
+ };
39
412
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,iBAAiB;AACjB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,qBAAqB;AACrB,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC,qBAAqB;AACrB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAG/E,aAAa;AACb,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"sources":["../src/field.ts","../src/predicate.ts","../src/validation.ts","../src/structure.ts"],"sourcesContent":["/**\n * Field builder functions for creating form field definitions.\n *\n * Each function creates a field descriptor that captures both schema information\n * (name, type) and UI hints (label, placeholder, etc.).\n */\n\nimport type {\n TextField,\n NumberField,\n BooleanField,\n StaticEnumField,\n EnumOptionValue,\n DynamicEnumField,\n DynamicSchemaField,\n ArrayField,\n ObjectField,\n FormElement,\n} from \"@formspec/core\";\n\n/**\n * Field builder namespace containing functions to create each field type.\n *\n * @example\n * ```typescript\n * import { field } from \"@formspec/dsl\";\n *\n * field.text(\"name\", { label: \"Full Name\" });\n * field.number(\"age\", { min: 0, max: 150 });\n * field.enum(\"status\", [\"draft\", \"sent\", \"paid\"]);\n * field.dynamicEnum(\"country\", \"countries\", { label: \"Country\" });\n * ```\n *\n * @public\n */\nexport const field = {\n /**\n * Creates a text input field.\n *\n * @param name - The field name (used as the schema key)\n * @param config - Optional configuration for label, placeholder, etc.\n * @returns A TextField descriptor\n */\n text: <const N extends string>(\n name: N,\n config?: Omit<TextField<N>, \"_type\" | \"_field\" | \"name\">\n ): TextField<N> => ({\n _type: \"field\",\n _field: \"text\",\n name,\n ...config,\n }),\n\n /**\n * Creates a numeric input field.\n *\n * @param name - The field name (used as the schema key)\n * @param config - Optional configuration for label, min, max, etc.\n * @returns A NumberField descriptor\n */\n number: <const N extends string>(\n name: N,\n config?: Omit<NumberField<N>, \"_type\" | \"_field\" | \"name\">\n ): NumberField<N> => ({\n _type: \"field\",\n _field: \"number\",\n name,\n ...config,\n }),\n\n /**\n * Creates a boolean checkbox field.\n *\n * @param name - The field name (used as the schema key)\n * @param config - Optional configuration for label, etc.\n * @returns A BooleanField descriptor\n */\n boolean: <const N extends string>(\n name: N,\n config?: Omit<BooleanField<N>, \"_type\" | \"_field\" | \"name\">\n ): BooleanField<N> => ({\n _type: \"field\",\n _field: \"boolean\",\n name,\n ...config,\n }),\n\n /**\n * Creates a field with static enum options (known at compile time).\n *\n * Literal types are automatically inferred - no `as const` needed:\n * ```typescript\n * field.enum(\"status\", [\"draft\", \"sent\", \"paid\"])\n * // Schema type: \"draft\" | \"sent\" | \"paid\"\n * ```\n *\n * Options can be strings or objects with `id` and `label`:\n * ```typescript\n * field.enum(\"priority\", [\n * { id: \"low\", label: \"Low Priority\" },\n * { id: \"high\", label: \"High Priority\" },\n * ])\n * ```\n *\n * **Note:** All options must be of the same type (all strings OR all objects).\n * Mixing strings and objects will throw a runtime error.\n *\n * @param name - The field name (used as the schema key)\n * @param options - Array of allowed string values or objects with `id` and `label` properties\n * @param config - Optional configuration for label, etc.\n * @returns A StaticEnumField descriptor\n * @throws Error if options array contains mixed types (strings and objects)\n */\n enum: <const N extends string, const O extends readonly EnumOptionValue[]>(\n name: N,\n options: O,\n config?: Omit<StaticEnumField<N, O>, \"_type\" | \"_field\" | \"name\" | \"options\">\n ): StaticEnumField<N, O> => {\n // Validate that all options are of the same type (all strings or all objects)\n if (options.length > 0) {\n const first = options[0];\n // Runtime check: TypeScript allows mixed arrays, but we enforce homogeneity\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const firstIsObject = typeof first === \"object\" && first !== null;\n\n // Check all items match the type of the first item\n for (const opt of options) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const optIsObject = typeof opt === \"object\" && opt !== null;\n if (optIsObject !== firstIsObject) {\n throw new Error(\n `field.enum(\"${name}\"): options must be all strings or all objects with {id, label}, not mixed. ` +\n `Received mixed types in options array.`\n );\n }\n }\n\n // Validate object options have required properties\n if (firstIsObject) {\n for (const opt of options) {\n const obj = opt as { id?: unknown; label?: unknown };\n if (typeof obj.id !== \"string\" || typeof obj.label !== \"string\") {\n throw new Error(\n `field.enum(\"${name}\"): object options must have string \"id\" and \"label\" properties. ` +\n `Received: ${JSON.stringify(opt)}`\n );\n }\n }\n }\n }\n\n return {\n _type: \"field\",\n _field: \"enum\",\n name,\n options,\n ...config,\n };\n },\n\n /**\n * Creates a field with dynamic enum options (fetched from a data source at runtime).\n *\n * The data source must be registered in DataSourceRegistry via module augmentation:\n * ```typescript\n * declare module \"@formspec/core\" {\n * interface DataSourceRegistry {\n * countries: { id: string; code: string; name: string };\n * }\n * }\n *\n * field.dynamicEnum(\"country\", \"countries\", { label: \"Country\" })\n * ```\n *\n * @param name - The field name (used as the schema key)\n * @param source - The data source key (must be in DataSourceRegistry)\n * @param config - Optional configuration for label, params, etc.\n * @returns A DynamicEnumField descriptor\n */\n dynamicEnum: <const N extends string, const Source extends string>(\n name: N,\n source: Source,\n config?: Omit<DynamicEnumField<N, Source>, \"_type\" | \"_field\" | \"name\" | \"source\">\n ): DynamicEnumField<N, Source> => ({\n _type: \"field\",\n _field: \"dynamic_enum\",\n name,\n source,\n ...config,\n }),\n\n /**\n * Creates a field that loads its schema dynamically (e.g., from an extension).\n *\n * @param name - The field name (used as the schema key)\n * @param schemaSource - Identifier for the schema source\n * @param config - Optional configuration for label, etc.\n * @returns A DynamicSchemaField descriptor\n */\n dynamicSchema: <const N extends string>(\n name: N,\n schemaSource: string,\n config?: Omit<DynamicSchemaField<N>, \"_type\" | \"_field\" | \"name\" | \"schemaSource\">\n ): DynamicSchemaField<N> => ({\n _type: \"field\",\n _field: \"dynamic_schema\",\n name,\n schemaSource,\n ...config,\n }),\n\n /**\n * Creates an array field containing repeating items.\n *\n * Use this for lists of values (e.g., multiple addresses, line items).\n *\n * @example\n * ```typescript\n * field.array(\"addresses\",\n * field.text(\"street\", { label: \"Street\" }),\n * field.text(\"city\", { label: \"City\" }),\n * field.text(\"zip\", { label: \"ZIP Code\" }),\n * )\n * ```\n *\n * @param name - The field name (used as the schema key)\n * @param items - The form elements that define each array item\n * @returns An ArrayField descriptor\n */\n array: <const N extends string, const Items extends readonly FormElement[]>(\n name: N,\n ...items: Items\n ): ArrayField<N, Items> => ({\n _type: \"field\",\n _field: \"array\",\n name,\n items,\n }),\n\n /**\n * Creates an array field with additional configuration options.\n *\n * @example\n * ```typescript\n * field.arrayWithConfig(\"lineItems\", {\n * label: \"Line Items\",\n * minItems: 1,\n * maxItems: 10,\n * },\n * field.text(\"description\"),\n * field.number(\"quantity\"),\n * )\n * ```\n *\n * @param name - The field name (used as the schema key)\n * @param config - Configuration for label, minItems, maxItems, etc.\n * @param items - The form elements that define each array item\n * @returns An ArrayField descriptor\n */\n arrayWithConfig: <const N extends string, const Items extends readonly FormElement[]>(\n name: N,\n config: Omit<ArrayField<N, Items>, \"_type\" | \"_field\" | \"name\" | \"items\">,\n ...items: Items\n ): ArrayField<N, Items> => ({\n _type: \"field\",\n _field: \"array\",\n name,\n items,\n ...config,\n }),\n\n /**\n * Creates an object field containing nested properties.\n *\n * Use this for grouping related fields under a single key in the schema.\n *\n * @example\n * ```typescript\n * field.object(\"address\",\n * field.text(\"street\", { label: \"Street\" }),\n * field.text(\"city\", { label: \"City\" }),\n * field.text(\"zip\", { label: \"ZIP Code\" }),\n * )\n * ```\n *\n * @param name - The field name (used as the schema key)\n * @param properties - The form elements that define the object's properties\n * @returns An ObjectField descriptor\n */\n object: <const N extends string, const Properties extends readonly FormElement[]>(\n name: N,\n ...properties: Properties\n ): ObjectField<N, Properties> => ({\n _type: \"field\",\n _field: \"object\",\n name,\n properties,\n }),\n\n /**\n * Creates an object field with additional configuration options.\n *\n * @example\n * ```typescript\n * field.objectWithConfig(\"billingAddress\", { label: \"Billing Address\", required: true },\n * field.text(\"street\"),\n * field.text(\"city\"),\n * )\n * ```\n *\n * @param name - The field name (used as the schema key)\n * @param config - Configuration for label, required, etc.\n * @param properties - The form elements that define the object's properties\n * @returns An ObjectField descriptor\n */\n objectWithConfig: <const N extends string, const Properties extends readonly FormElement[]>(\n name: N,\n config: Omit<ObjectField<N, Properties>, \"_type\" | \"_field\" | \"name\" | \"properties\">,\n ...properties: Properties\n ): ObjectField<N, Properties> => ({\n _type: \"field\",\n _field: \"object\",\n name,\n properties,\n ...config,\n }),\n};\n","/**\n * Predicate builder functions for conditional logic.\n *\n * These functions create predicates for use with `when()`:\n * - `is()` - Check if a field equals a specific value\n *\n * @example\n * ```typescript\n * when(is(\"status\", \"draft\"),\n * field.text(\"notes\"),\n * )\n * ```\n */\n\nimport type { EqualsPredicate } from \"@formspec/core\";\n\n/**\n * Creates an equality predicate that checks if a field equals a specific value.\n *\n * Use this with `when()` to create readable conditional expressions:\n *\n * @example\n * ```typescript\n * // Show cardNumber field when paymentMethod is \"card\"\n * when(is(\"paymentMethod\", \"card\"),\n * field.text(\"cardNumber\", { label: \"Card Number\" }),\n * )\n * ```\n *\n * @typeParam K - The field name (inferred as string literal)\n * @typeParam V - The value type (inferred as literal)\n * @param field - The name of the field to check\n * @param value - The value the field must equal\n * @returns An EqualsPredicate for use with `when()`\n * @public\n */\nexport function is<const K extends string, const V>(field: K, value: V): EqualsPredicate<K, V> {\n return {\n _predicate: \"equals\",\n field,\n value,\n };\n}\n","/**\n * Runtime validation for form specifications.\n *\n * Validates:\n * - No duplicate field names at the same scope level\n * - All field references in conditionals point to existing fields\n */\n\nimport type { FormElement, Group, Conditional, ArrayField, ObjectField } from \"@formspec/core\";\n\n/**\n * Validation issue severity levels.\n *\n * @public\n */\nexport type ValidationSeverity = \"error\" | \"warning\";\n\n/**\n * A validation issue found in a form specification.\n *\n * @public\n */\nexport interface ValidationIssue {\n /** Severity of the issue */\n severity: ValidationSeverity;\n /** Human-readable message describing the issue */\n message: string;\n /** Path to the element with the issue (e.g., \"group.fieldName\") */\n path: string;\n}\n\n/**\n * Result of validating a form specification.\n *\n * @public\n */\nexport interface ValidationResult {\n /** Whether the form is valid (no errors, warnings are ok) */\n valid: boolean;\n /** List of validation issues found */\n issues: ValidationIssue[];\n}\n\n/**\n * Collects all field names from a list of form elements.\n * Returns a Map of field name to count (for duplicate detection).\n */\nfunction collectFieldNames(\n elements: readonly FormElement[],\n path = \"\"\n): Map<string, { count: number; paths: string[] }> {\n const fieldNames = new Map<string, { count: number; paths: string[] }>();\n\n function visit(elements: readonly FormElement[], currentPath: string): void {\n for (const element of elements) {\n switch (element._type) {\n case \"field\": {\n // After type narrowing, element is known to be AnyField\n const field = element;\n const fieldPath = currentPath ? `${currentPath}.${field.name}` : field.name;\n const existing = fieldNames.get(field.name);\n if (existing !== undefined) {\n existing.count++;\n existing.paths.push(fieldPath);\n } else {\n fieldNames.set(field.name, { count: 1, paths: [fieldPath] });\n }\n\n // Recurse into array items and object properties\n if (field._field === \"array\") {\n const arrayField = field as ArrayField<string, readonly FormElement[]>;\n visit(arrayField.items, `${fieldPath}[]`);\n } else if (field._field === \"object\") {\n const objectField = field as ObjectField<string, readonly FormElement[]>;\n visit(objectField.properties, fieldPath);\n }\n break;\n }\n\n case \"group\": {\n const group = element as Group<readonly FormElement[]>;\n const groupPath = currentPath ? `${currentPath}.[${group.label}]` : `[${group.label}]`;\n visit(group.elements, groupPath);\n break;\n }\n\n case \"conditional\": {\n const conditional = element as Conditional<string, unknown, readonly FormElement[]>;\n const conditionalPath = currentPath\n ? `${currentPath}.when(${conditional.field})`\n : `when(${conditional.field})`;\n visit(conditional.elements, conditionalPath);\n break;\n }\n }\n }\n }\n\n visit(elements, path);\n return fieldNames;\n}\n\n/**\n * Collects all field references from conditionals.\n * Returns a list of { fieldName, path } for each reference.\n */\nfunction collectConditionalReferences(\n elements: readonly FormElement[],\n path = \"\"\n): { fieldName: string; path: string }[] {\n const references: { fieldName: string; path: string }[] = [];\n\n function visit(elements: readonly FormElement[], currentPath: string): void {\n for (const element of elements) {\n switch (element._type) {\n case \"field\": {\n // After type narrowing, element is known to be AnyField\n const field = element;\n const fieldPath = currentPath ? `${currentPath}.${field.name}` : field.name;\n\n // Recurse into array items and object properties\n if (field._field === \"array\") {\n const arrayField = field as ArrayField<string, readonly FormElement[]>;\n visit(arrayField.items, `${fieldPath}[]`);\n } else if (field._field === \"object\") {\n const objectField = field as ObjectField<string, readonly FormElement[]>;\n visit(objectField.properties, fieldPath);\n }\n break;\n }\n\n case \"group\": {\n const group = element as Group<readonly FormElement[]>;\n const groupPath = currentPath ? `${currentPath}.[${group.label}]` : `[${group.label}]`;\n visit(group.elements, groupPath);\n break;\n }\n\n case \"conditional\": {\n const conditional = element as Conditional<string, unknown, readonly FormElement[]>;\n const conditionalPath = currentPath\n ? `${currentPath}.when(${conditional.field})`\n : `when(${conditional.field})`;\n\n // Record this reference\n references.push({\n fieldName: conditional.field,\n path: conditionalPath,\n });\n\n // Continue visiting children\n visit(conditional.elements, conditionalPath);\n break;\n }\n }\n }\n }\n\n visit(elements, path);\n return references;\n}\n\n/**\n * Validates a form specification for common issues.\n *\n * Checks for:\n * - Duplicate field names at the root level (warning)\n * - References to non-existent fields in conditionals (error)\n *\n * @example\n * ```typescript\n * const form = formspec(\n * field.text(\"name\"),\n * field.text(\"name\"), // Duplicate!\n * when(\"nonExistent\", \"value\", // Reference to non-existent field!\n * field.text(\"extra\"),\n * ),\n * );\n *\n * const result = validateForm(form.elements);\n * // result.valid === false\n * // result.issues contains duplicate and reference errors\n * ```\n *\n * @param elements - The form elements to validate\n * @returns Validation result with any issues found\n *\n * @public\n */\nexport function validateForm(elements: readonly FormElement[]): ValidationResult {\n const issues: ValidationIssue[] = [];\n\n // Collect all field names\n const fieldNames = collectFieldNames(elements);\n\n // Check for duplicates at root level - duplicates are errors because they cause data loss\n for (const [name, info] of fieldNames) {\n if (info.count > 1 && info.paths[0] !== undefined) {\n issues.push({\n severity: \"error\",\n message: `Duplicate field name \"${name}\" found ${String(info.count)} times at: ${info.paths.join(\", \")}`,\n path: info.paths[0],\n });\n }\n }\n\n // Collect conditional references\n const references = collectConditionalReferences(elements);\n\n // Check that all referenced fields exist\n for (const ref of references) {\n if (!fieldNames.has(ref.fieldName)) {\n issues.push({\n severity: \"error\",\n message: `Conditional references non-existent field \"${ref.fieldName}\"`,\n path: ref.path,\n });\n }\n }\n\n return {\n valid: issues.every((issue) => issue.severity !== \"error\"),\n issues,\n };\n}\n\n/**\n * Logs validation issues to the console.\n *\n * @param result - The validation result to log\n * @param formName - Optional name for the form (for better error messages)\n *\n * @public\n */\nexport function logValidationIssues(result: ValidationResult, formName?: string): void {\n if (result.issues.length === 0) {\n return;\n }\n\n const prefix = formName ? `FormSpec \"${formName}\"` : \"FormSpec\";\n\n for (const issue of result.issues) {\n const location = issue.path ? ` at ${issue.path}` : \"\";\n const message = `${prefix}: ${issue.message}${location}`;\n\n if (issue.severity === \"error\") {\n console.error(message);\n } else {\n console.warn(message);\n }\n }\n}\n","/**\n * Structure builder functions for organizing form elements.\n *\n * These functions create layout and conditional structures:\n * - `group()` - Visual grouping of fields\n * - `when()` - Conditional visibility based on field values\n * - `formspec()` - Top-level form specification\n */\n\nimport type { FormElement, Group, Conditional, FormSpec, Predicate } from \"@formspec/core\";\nimport { validateForm, logValidationIssues } from \"./validation.js\";\n\n/**\n * Options for creating a form specification.\n *\n * @public\n */\nexport interface FormSpecOptions {\n /**\n * Whether to validate the form structure.\n * - `true` or `\"warn\"`: Validate and log warnings/errors to console\n * - `\"throw\"`: Validate and throw an error if validation fails\n * - `false`: Skip validation (default in production for performance)\n *\n * @defaultValue false\n */\n validate?: boolean | \"warn\" | \"throw\";\n\n /**\n * Optional name for the form (used in validation messages).\n */\n name?: string;\n}\n\n/**\n * Creates a visual group of form elements.\n *\n * Groups provide visual organization and can be rendered as fieldsets or sections.\n * The nesting of groups defines the visual hierarchy of the form.\n *\n * @example\n * ```typescript\n * group(\"Customer Information\",\n * field.text(\"name\", { label: \"Name\" }),\n * field.text(\"email\", { label: \"Email\" }),\n * )\n * ```\n *\n * @param label - The group's display label\n * @param elements - The form elements contained in this group\n * @returns A Group descriptor\n *\n * @public\n */\nexport function group<const Elements extends readonly FormElement[]>(\n label: string,\n ...elements: Elements\n): Group<Elements> {\n return { _type: \"group\", label, elements };\n}\n\n/**\n * Creates a conditional wrapper that shows elements based on a predicate.\n *\n * When the predicate evaluates to true, the contained elements are shown.\n * Otherwise, they are hidden (but still part of the schema).\n *\n * @example\n * ```typescript\n * import { is } from \"@formspec/dsl\";\n *\n * field.enum(\"status\", [\"draft\", \"sent\", \"paid\"] as const),\n * when(is(\"status\", \"draft\"),\n * field.text(\"internalNotes\", { label: \"Internal Notes\" }),\n * )\n * ```\n *\n * @param predicate - The condition to evaluate (use `is()` to create)\n * @param elements - The form elements to show when condition is met\n * @returns A Conditional descriptor\n *\n * @public\n */\nexport function when<\n const K extends string,\n const V,\n const Elements extends readonly FormElement[],\n>(predicate: Predicate<K, V>, ...elements: Elements): Conditional<K, V, Elements> {\n return {\n _type: \"conditional\",\n field: predicate.field,\n value: predicate.value,\n elements,\n };\n}\n\n/**\n * Creates a complete form specification.\n *\n * The structure IS the definition:\n * - Nesting with `group()` defines visual layout\n * - Nesting with `when()` defines conditional visibility\n * - Field type implies control type (text field → text input)\n * - Array position implies field ordering\n *\n * Schema is automatically inferred from all fields in the structure.\n *\n * @example\n * ```typescript\n * const InvoiceForm = formspec(\n * group(\"Customer\",\n * field.text(\"customerName\", { label: \"Customer Name\" }),\n * field.dynamicEnum(\"country\", \"fetch_countries\", { label: \"Country\" }),\n * ),\n * group(\"Invoice Details\",\n * field.number(\"amount\", { label: \"Amount\", min: 0 }),\n * field.enum(\"status\", [\"draft\", \"sent\", \"paid\"] as const),\n * when(is(\"status\", \"draft\"),\n * field.text(\"internalNotes\", { label: \"Internal Notes\" }),\n * ),\n * ),\n * );\n * ```\n *\n * @param elements - The top-level form elements\n * @returns A FormSpec descriptor\n *\n * @public\n */\nexport function formspec<const Elements extends readonly FormElement[]>(\n ...elements: Elements\n): FormSpec<Elements> {\n return { elements };\n}\n\n/**\n * Creates a complete form specification with validation options.\n *\n * @example\n * ```typescript\n * const form = formspecWithValidation(\n * { validate: true, name: \"MyForm\" },\n * field.text(\"name\"),\n * field.enum(\"status\", [\"draft\", \"sent\"] as const),\n * when(is(\"status\", \"draft\"),\n * field.text(\"notes\"),\n * ),\n * );\n * ```\n *\n * @param options - Validation options\n * @param elements - The top-level form elements\n * @returns A FormSpec descriptor\n *\n * @public\n */\nexport function formspecWithValidation<const Elements extends readonly FormElement[]>(\n options: FormSpecOptions,\n ...elements: Elements\n): FormSpec<Elements> {\n // Run validation if requested\n if (options.validate) {\n const result = validateForm(elements);\n\n if (options.validate === \"throw\" && !result.valid) {\n const errors = result.issues\n .filter((i) => i.severity === \"error\")\n .map((i) => i.message)\n .join(\"; \");\n throw new Error(`Form validation failed: ${errors}`);\n }\n\n if (options.validate === true || options.validate === \"warn\") {\n logValidationIssues(result, options.name);\n }\n }\n\n return { elements };\n}\n"],"mappings":";AAmCO,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnB,MAAM,CACJ,MACA,YACkB;AAAA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