@formspec/constraints 0.1.0-alpha.21 → 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.
@@ -0,0 +1,914 @@
1
+ /**
2
+ * \@formspec/constraints
3
+ *
4
+ * Constraint validation for FormSpec - restrict features based on target
5
+ * environment capabilities.
6
+ *
7
+ * This package provides:
8
+ * - Type definitions for constraint configuration
9
+ * - YAML/TypeScript config file loading
10
+ * - Core validation logic for FormSpec elements
11
+ * - JSON Schema for .formspec.yml validation
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { loadConfig, validateFormSpecElements } from '@formspec/constraints';
16
+ * import { formspec, field } from '@formspec/dsl';
17
+ *
18
+ * // Load constraints from .formspec.yml
19
+ * const { config } = await loadConfig();
20
+ *
21
+ * // Create a form
22
+ * const form = formspec(
23
+ * field.text("name"),
24
+ * field.dynamicEnum("country", "countries"),
25
+ * );
26
+ *
27
+ * // Validate against constraints
28
+ * const result = validateFormSpecElements(form.elements, { constraints: config });
29
+ *
30
+ * if (!result.valid) {
31
+ * console.error('Validation failed:', result.issues);
32
+ * }
33
+ * ```
34
+ *
35
+ * @packageDocumentation
36
+ */
37
+
38
+ /**
39
+ * Union of all field types.
40
+ *
41
+ * @public
42
+ */
43
+ export declare type AnyField = TextField<string> | NumberField<string> | BooleanField<string> | StaticEnumField<string, readonly EnumOptionValue[]> | DynamicEnumField<string, string> | DynamicSchemaField<string> | ArrayField<string, readonly FormElement[]> | ObjectField<string, readonly FormElement[]>;
44
+
45
+ /**
46
+ * An array field containing repeating items.
47
+ *
48
+ * Use this for lists of values (e.g., multiple addresses, line items).
49
+ *
50
+ * @typeParam N - The field name (string literal type)
51
+ * @typeParam Items - The form elements that define each array item
52
+ *
53
+ * @public
54
+ */
55
+ export declare interface ArrayField<N extends string, Items extends readonly FormElement[]> {
56
+ /** Type discriminator for form elements */
57
+ readonly _type: "field";
58
+ /** Field type discriminator - identifies this as an array field */
59
+ readonly _field: "array";
60
+ /** Unique field identifier used as the schema key */
61
+ readonly name: N;
62
+ /** Form elements that define the schema for each array item */
63
+ readonly items: Items;
64
+ /** Display label for the field */
65
+ readonly label?: string;
66
+ /** Whether this field is required for form submission */
67
+ readonly required?: boolean;
68
+ /** Minimum number of items required */
69
+ readonly minItems?: number;
70
+ /** Maximum number of items allowed */
71
+ readonly maxItems?: number;
72
+ }
73
+
74
+ /**
75
+ * A boolean checkbox field.
76
+ *
77
+ * @typeParam N - The field name (string literal type)
78
+ *
79
+ * @public
80
+ */
81
+ export declare interface BooleanField<N extends string> {
82
+ /** Type discriminator for form elements */
83
+ readonly _type: "field";
84
+ /** Field type discriminator - identifies this as a boolean field */
85
+ readonly _field: "boolean";
86
+ /** Unique field identifier used as the schema key */
87
+ readonly name: N;
88
+ /** Display label for the field */
89
+ readonly label?: string;
90
+ /** Whether this field is required for form submission */
91
+ readonly required?: boolean;
92
+ }
93
+
94
+ /**
95
+ * A conditional wrapper that shows/hides elements based on another field's value.
96
+ *
97
+ * @typeParam FieldName - The field to check
98
+ * @typeParam Value - The value that triggers the condition
99
+ * @typeParam Elements - Tuple of contained form elements
100
+ *
101
+ * @public
102
+ */
103
+ export declare interface Conditional<FieldName extends string, Value, Elements extends readonly FormElement[]> {
104
+ /** Type discriminator - identifies this as a conditional element */
105
+ readonly _type: "conditional";
106
+ /** Name of the field whose value determines visibility */
107
+ readonly field: FieldName;
108
+ /** Value that triggers the condition (shows nested elements) */
109
+ readonly value: Value;
110
+ /** Form elements shown when condition is met */
111
+ readonly elements: Elements;
112
+ }
113
+
114
+ /**
115
+ * Complete constraint configuration for a FormSpec project.
116
+ *
117
+ * @public
118
+ */
119
+ export declare interface ConstraintConfig {
120
+ /** Field type constraints */
121
+ fieldTypes?: FieldTypeConstraints;
122
+ /** Layout and structure constraints */
123
+ layout?: LayoutConstraints;
124
+ /** UI Schema feature constraints */
125
+ uiSchema?: UISchemaConstraints;
126
+ /** Field configuration option constraints */
127
+ fieldOptions?: FieldOptionConstraints;
128
+ /** Control options constraints */
129
+ controlOptions?: ControlOptionConstraints;
130
+ }
131
+
132
+ /**
133
+ * Control options constraints - control which JSONForms Control.options are allowed.
134
+ * These are renderer-specific options that may not be universally supported.
135
+ *
136
+ * @public
137
+ */
138
+ export declare interface ControlOptionConstraints {
139
+ /** format - renderer format hint (e.g., "radio", "textarea") */
140
+ format?: Severity;
141
+ /** readonly - read-only mode */
142
+ readonly?: Severity;
143
+ /** multi - multi-select for enums */
144
+ multi?: Severity;
145
+ /** showUnfocusedDescription - show description when unfocused */
146
+ showUnfocusedDescription?: Severity;
147
+ /** hideRequiredAsterisk - hide required indicator */
148
+ hideRequiredAsterisk?: Severity;
149
+ /** Custom control options (extensible dictionary) */
150
+ custom?: Record<string, Severity>;
151
+ }
152
+
153
+ /**
154
+ * Default FormSpec configuration.
155
+ *
156
+ * @beta
157
+ */
158
+ export declare const DEFAULT_CONFIG: FormSpecConfig;
159
+
160
+ /**
161
+ * Default constraint configuration that allows all features.
162
+ * All constraints default to "off" (allowed).
163
+ *
164
+ * @beta
165
+ */
166
+ export declare const DEFAULT_CONSTRAINTS: ResolvedConstraintConfig;
167
+
168
+ /**
169
+ * Creates a constraint configuration directly from an object.
170
+ * Useful for programmatic configuration without YAML.
171
+ *
172
+ * @param config - Partial constraint configuration
173
+ * @returns Complete configuration with defaults applied
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const config = defineConstraints({
178
+ * fieldTypes: {
179
+ * dynamicEnum: 'error',
180
+ * dynamicSchema: 'error',
181
+ * },
182
+ * layout: {
183
+ * group: 'error',
184
+ * },
185
+ * });
186
+ * ```
187
+ *
188
+ * @public
189
+ */
190
+ export declare function defineConstraints(config: ConstraintConfig): ResolvedConstraintConfig;
191
+
192
+ /**
193
+ * A field with dynamic enum options (fetched from a data source at runtime).
194
+ *
195
+ * @typeParam N - The field name (string literal type)
196
+ * @typeParam Source - The data source key (from DataSourceRegistry)
197
+ *
198
+ * @public
199
+ */
200
+ export declare interface DynamicEnumField<N extends string, Source extends string> {
201
+ /** Type discriminator for form elements */
202
+ readonly _type: "field";
203
+ /** Field type discriminator - identifies this as a dynamic enum field */
204
+ readonly _field: "dynamic_enum";
205
+ /** Unique field identifier used as the schema key */
206
+ readonly name: N;
207
+ /** Data source key for fetching options at runtime */
208
+ readonly source: Source;
209
+ /** Display label for the field */
210
+ readonly label?: string;
211
+ /** Whether this field is required for form submission */
212
+ readonly required?: boolean;
213
+ /** Field names whose values are needed to fetch options */
214
+ readonly params?: readonly string[];
215
+ }
216
+
217
+ /**
218
+ * A field that loads its schema dynamically (e.g., from an extension).
219
+ *
220
+ * @typeParam N - The field name (string literal type)
221
+ *
222
+ * @public
223
+ */
224
+ export declare interface DynamicSchemaField<N extends string> {
225
+ /** Type discriminator for form elements */
226
+ readonly _type: "field";
227
+ /** Field type discriminator - identifies this as a dynamic schema field */
228
+ readonly _field: "dynamic_schema";
229
+ /** Unique field identifier used as the schema key */
230
+ readonly name: N;
231
+ /** Identifier for the schema source */
232
+ readonly schemaSource: string;
233
+ /** Display label for the field */
234
+ readonly label?: string;
235
+ /** Whether this field is required for form submission */
236
+ readonly required?: boolean;
237
+ /** Field names whose values are needed to configure the schema */
238
+ readonly params?: readonly string[];
239
+ }
240
+
241
+ /**
242
+ * An enum option with a separate ID and display label.
243
+ *
244
+ * Use this when the stored value (id) should differ from the display text (label).
245
+ *
246
+ * @public
247
+ */
248
+ export declare interface EnumOption {
249
+ readonly id: string;
250
+ readonly label: string;
251
+ }
252
+
253
+ /**
254
+ * Valid enum option types: either plain strings or objects with id/label.
255
+ *
256
+ * @public
257
+ */
258
+ export declare type EnumOptionValue = string | EnumOption;
259
+
260
+ /**
261
+ * Extracts which options are present on a field object.
262
+ * Works with FormSpec field types.
263
+ *
264
+ * @param field - A field object with potential options
265
+ * @returns Array of present option names
266
+ *
267
+ * @beta
268
+ */
269
+ export declare function extractFieldOptions(field: Record<string, unknown>): FieldOption[];
270
+
271
+ /**
272
+ * Known field options that can be validated.
273
+ *
274
+ * @beta
275
+ */
276
+ export declare type FieldOption = "label" | "placeholder" | "required" | "minValue" | "maxValue" | "minItems" | "maxItems";
277
+
278
+ /**
279
+ * Field configuration option constraints - control which field options are allowed.
280
+ *
281
+ * @public
282
+ */
283
+ export declare interface FieldOptionConstraints {
284
+ /** label - field label text */
285
+ label?: Severity;
286
+ /** placeholder - input placeholder text */
287
+ placeholder?: Severity;
288
+ /** required - whether field is required */
289
+ required?: Severity;
290
+ /** minValue - minimum value for numbers */
291
+ minValue?: Severity;
292
+ /** maxValue - maximum value for numbers */
293
+ maxValue?: Severity;
294
+ /** minItems - minimum array length */
295
+ minItems?: Severity;
296
+ /** maxItems - maximum array length */
297
+ maxItems?: Severity;
298
+ }
299
+
300
+ /**
301
+ * Context for field option validation.
302
+ *
303
+ * @beta
304
+ */
305
+ export declare interface FieldOptionsContext {
306
+ /** The field name */
307
+ fieldName: string;
308
+ /** Which options are present on this field */
309
+ presentOptions: FieldOption[];
310
+ /** Path to this field */
311
+ path?: string;
312
+ }
313
+
314
+ /**
315
+ * Field type constraints - control which field types are allowed.
316
+ * Fine-grained control over each DSL field builder.
317
+ *
318
+ * @public
319
+ */
320
+ export declare interface FieldTypeConstraints {
321
+ /** field.text() - basic text input */
322
+ text?: Severity;
323
+ /** field.number() - numeric input */
324
+ number?: Severity;
325
+ /** field.boolean() - checkbox/toggle */
326
+ boolean?: Severity;
327
+ /** field.enum() with literal options */
328
+ staticEnum?: Severity;
329
+ /** field.dynamicEnum() - runtime-fetched options */
330
+ dynamicEnum?: Severity;
331
+ /** field.dynamicSchema() - runtime-fetched schema */
332
+ dynamicSchema?: Severity;
333
+ /** field.array() / field.arrayWithConfig() */
334
+ array?: Severity;
335
+ /** field.object() / field.objectWithConfig() */
336
+ object?: Severity;
337
+ }
338
+
339
+ /**
340
+ * Context for field type validation.
341
+ *
342
+ * @beta
343
+ */
344
+ export declare interface FieldTypeContext {
345
+ /** The _field discriminator value (e.g., "text", "number", "enum") */
346
+ fieldType: string;
347
+ /** The field name */
348
+ fieldName: string;
349
+ /** Optional path for nested fields */
350
+ path?: string;
351
+ }
352
+
353
+ /**
354
+ * Union of all form element types (fields and structural elements).
355
+ *
356
+ * @public
357
+ */
358
+ export declare type FormElement = AnyField | Group<readonly FormElement[]> | Conditional<string, unknown, readonly FormElement[]>;
359
+
360
+ /**
361
+ * A complete form specification.
362
+ *
363
+ * @typeParam Elements - Tuple of top-level form elements
364
+ *
365
+ * @public
366
+ */
367
+ export declare interface FormSpec<Elements extends readonly FormElement[]> {
368
+ /** Top-level form elements */
369
+ readonly elements: Elements;
370
+ }
371
+
372
+ /**
373
+ * Top-level FormSpec configuration file structure.
374
+ * The .formspec.yml file uses this structure.
375
+ *
376
+ * @public
377
+ */
378
+ export declare interface FormSpecConfig {
379
+ /** Constraint configuration */
380
+ constraints?: ConstraintConfig;
381
+ }
382
+
383
+ /**
384
+ * Options for validating FormSpec elements.
385
+ *
386
+ * @public
387
+ */
388
+ export declare interface FormSpecValidationOptions {
389
+ /** Constraint configuration (will be merged with defaults) */
390
+ constraints?: ConstraintConfig;
391
+ }
392
+
393
+ /**
394
+ * Gets the severity level for a field option.
395
+ *
396
+ * @param option - The option to check
397
+ * @param constraints - Field option constraints
398
+ * @returns Severity level, or "off" if not constrained
399
+ *
400
+ * @beta
401
+ */
402
+ export declare function getFieldOptionSeverity(option: FieldOption, constraints: FieldOptionConstraints): Severity;
403
+
404
+ /**
405
+ * Gets the severity level for a field type.
406
+ *
407
+ * @param fieldType - The _field discriminator value
408
+ * @param constraints - Field type constraints
409
+ * @returns Severity level, or "off" if not constrained
410
+ *
411
+ * @beta
412
+ */
413
+ export declare function getFieldTypeSeverity(fieldType: string, constraints: FieldTypeConstraints): Severity;
414
+
415
+ /**
416
+ * A visual grouping of form elements.
417
+ *
418
+ * Groups provide visual organization and can be rendered as fieldsets or sections.
419
+ *
420
+ * @typeParam Elements - Tuple of contained form elements
421
+ *
422
+ * @public
423
+ */
424
+ export declare interface Group<Elements extends readonly FormElement[]> {
425
+ /** Type discriminator - identifies this as a group element */
426
+ readonly _type: "group";
427
+ /** Display label for the group */
428
+ readonly label: string;
429
+ /** Form elements contained within this group */
430
+ readonly elements: Elements;
431
+ }
432
+
433
+ /**
434
+ * Checks if a specific field option is allowed.
435
+ *
436
+ * @param option - The option to check
437
+ * @param constraints - Field option constraints
438
+ * @returns true if allowed, false if disallowed
439
+ *
440
+ * @beta
441
+ */
442
+ export declare function isFieldOptionAllowed(option: FieldOption, constraints: FieldOptionConstraints): boolean;
443
+
444
+ /**
445
+ * Checks if a field type is allowed by the constraints.
446
+ * Useful for quick checks without generating issues.
447
+ *
448
+ * @param fieldType - The _field discriminator value
449
+ * @param constraints - Field type constraints
450
+ * @returns true if allowed, false if disallowed
451
+ *
452
+ * @beta
453
+ */
454
+ export declare function isFieldTypeAllowed(fieldType: string, constraints: FieldTypeConstraints): boolean;
455
+
456
+ /**
457
+ * Checks if a layout type is allowed by the constraints.
458
+ *
459
+ * @param layoutType - The type of layout element
460
+ * @param constraints - Layout constraints
461
+ * @returns true if allowed, false if disallowed
462
+ *
463
+ * @beta
464
+ */
465
+ export declare function isLayoutTypeAllowed(layoutType: "group" | "conditional", constraints: LayoutConstraints): boolean;
466
+
467
+ /**
468
+ * Checks if a nesting depth is allowed.
469
+ *
470
+ * @param depth - Current nesting depth
471
+ * @param constraints - Layout constraints
472
+ * @returns true if allowed, false if exceeds limit
473
+ *
474
+ * @beta
475
+ */
476
+ export declare function isNestingDepthAllowed(depth: number, constraints: LayoutConstraints): boolean;
477
+
478
+ /**
479
+ * Layout and structure constraints - control grouping, conditionals, nesting.
480
+ *
481
+ * @public
482
+ */
483
+ export declare interface LayoutConstraints {
484
+ /** group() - visual grouping of fields */
485
+ group?: Severity;
486
+ /** when() - conditional field visibility */
487
+ conditionals?: Severity;
488
+ /** Maximum nesting depth for objects/arrays (0 = flat only) */
489
+ maxNestingDepth?: number;
490
+ }
491
+
492
+ /**
493
+ * Context for layout validation.
494
+ *
495
+ * @beta
496
+ */
497
+ export declare interface LayoutContext {
498
+ /** The type of layout element ("group" | "conditional") */
499
+ layoutType: "group" | "conditional";
500
+ /** Optional label for the element (for groups) */
501
+ label?: string;
502
+ /** Current nesting depth */
503
+ depth: number;
504
+ /** Path to this element */
505
+ path?: string;
506
+ }
507
+
508
+ /**
509
+ * JSONForms layout type constraints.
510
+ *
511
+ * @public
512
+ */
513
+ export declare interface LayoutTypeConstraints {
514
+ /** VerticalLayout - stack elements vertically */
515
+ VerticalLayout?: Severity;
516
+ /** HorizontalLayout - arrange elements horizontally */
517
+ HorizontalLayout?: Severity;
518
+ /** Group - visual grouping with label */
519
+ Group?: Severity;
520
+ /** Categorization - tabbed/wizard interface */
521
+ Categorization?: Severity;
522
+ /** Category - individual tab/step in Categorization */
523
+ Category?: Severity;
524
+ }
525
+
526
+ /**
527
+ * Loads FormSpec constraint configuration from a .formspec.yml file.
528
+ *
529
+ * @param options - Options for loading configuration
530
+ * @returns The loaded configuration with defaults applied
531
+ *
532
+ * @example
533
+ * ```ts
534
+ * // Load from current directory (searches for .formspec.yml)
535
+ * const result = await loadConfig();
536
+ *
537
+ * // Load from specific directory
538
+ * const result = await loadConfig({ cwd: '/path/to/project' });
539
+ *
540
+ * // Load from specific file
541
+ * const result = await loadConfig({ configPath: '/path/to/config.yml' });
542
+ * ```
543
+ *
544
+ * @public
545
+ */
546
+ export declare function loadConfig(options?: LoadConfigOptions): Promise<LoadConfigResult>;
547
+
548
+ /**
549
+ * Synchronously loads config from a pre-parsed YAML string.
550
+ * Useful for testing or when config is already available.
551
+ *
552
+ * @param yamlContent - The YAML content to parse
553
+ * @returns The parsed and merged configuration
554
+ *
555
+ * @public
556
+ */
557
+ export declare function loadConfigFromString(yamlContent: string): ResolvedConstraintConfig;
558
+
559
+ /**
560
+ * Options for loading configuration.
561
+ *
562
+ * @public
563
+ */
564
+ export declare interface LoadConfigOptions {
565
+ /**
566
+ * The directory to search for config files.
567
+ * Defaults to process.cwd().
568
+ */
569
+ cwd?: string;
570
+ /**
571
+ * Explicit path to a config file.
572
+ * If provided, skips searching for default config file names.
573
+ */
574
+ configPath?: string;
575
+ /**
576
+ * Whether to search parent directories for config files.
577
+ * Defaults to true.
578
+ */
579
+ searchParents?: boolean;
580
+ }
581
+
582
+ /**
583
+ * Result of loading configuration.
584
+ *
585
+ * @public
586
+ */
587
+ export declare interface LoadConfigResult {
588
+ /** The loaded and merged configuration */
589
+ config: ResolvedConstraintConfig;
590
+ /** The path to the config file that was loaded (if any) */
591
+ configPath: string | null;
592
+ /** Whether a config file was found */
593
+ found: boolean;
594
+ }
595
+
596
+ /**
597
+ * Merges user constraints with defaults, filling in any missing values.
598
+ *
599
+ * @beta
600
+ */
601
+ export declare function mergeWithDefaults(config: ConstraintConfig | undefined): ResolvedConstraintConfig;
602
+
603
+ /**
604
+ * A numeric input field.
605
+ *
606
+ * @typeParam N - The field name (string literal type)
607
+ *
608
+ * @public
609
+ */
610
+ export declare interface NumberField<N extends string> {
611
+ /** Type discriminator for form elements */
612
+ readonly _type: "field";
613
+ /** Field type discriminator - identifies this as a number field */
614
+ readonly _field: "number";
615
+ /** Unique field identifier used as the schema key */
616
+ readonly name: N;
617
+ /** Display label for the field */
618
+ readonly label?: string;
619
+ /** Minimum allowed value */
620
+ readonly min?: number;
621
+ /** Maximum allowed value */
622
+ readonly max?: number;
623
+ /** Whether this field is required for form submission */
624
+ readonly required?: boolean;
625
+ /** Value must be a multiple of this number (use 1 for integer semantics) */
626
+ readonly multipleOf?: number;
627
+ }
628
+
629
+ /**
630
+ * An object field containing nested properties.
631
+ *
632
+ * Use this for grouping related fields under a single key in the schema.
633
+ *
634
+ * @typeParam N - The field name (string literal type)
635
+ * @typeParam Properties - The form elements that define the object's properties
636
+ *
637
+ * @public
638
+ */
639
+ export declare interface ObjectField<N extends string, Properties extends readonly FormElement[]> {
640
+ /** Type discriminator for form elements */
641
+ readonly _type: "field";
642
+ /** Field type discriminator - identifies this as an object field */
643
+ readonly _field: "object";
644
+ /** Unique field identifier used as the schema key */
645
+ readonly name: N;
646
+ /** Form elements that define the properties of this object */
647
+ readonly properties: Properties;
648
+ /** Display label for the field */
649
+ readonly label?: string;
650
+ /** Whether this field is required for form submission */
651
+ readonly required?: boolean;
652
+ }
653
+
654
+ /**
655
+ * Fully resolved constraint configuration with all properties required.
656
+ * This is the type returned by mergeWithDefaults().
657
+ *
658
+ * @public
659
+ */
660
+ export declare interface ResolvedConstraintConfig {
661
+ fieldTypes: Required<FieldTypeConstraints>;
662
+ layout: Required<LayoutConstraints>;
663
+ uiSchema: ResolvedUISchemaConstraints;
664
+ fieldOptions: Required<FieldOptionConstraints>;
665
+ controlOptions: Required<ControlOptionConstraints>;
666
+ }
667
+
668
+ /**
669
+ * Fully resolved rule constraints with all properties required.
670
+ *
671
+ * @public
672
+ */
673
+ export declare interface ResolvedRuleConstraints {
674
+ enabled: Severity;
675
+ effects: Required<RuleEffectConstraints>;
676
+ }
677
+
678
+ /**
679
+ * Fully resolved UI schema constraints with all properties required.
680
+ *
681
+ * @public
682
+ */
683
+ export declare interface ResolvedUISchemaConstraints {
684
+ layouts: Required<LayoutTypeConstraints>;
685
+ rules: ResolvedRuleConstraints;
686
+ }
687
+
688
+ /**
689
+ * JSONForms rule constraints.
690
+ *
691
+ * @public
692
+ */
693
+ export declare interface RuleConstraints {
694
+ /** Whether rules are enabled at all */
695
+ enabled?: Severity;
696
+ /** Fine-grained control over rule effects */
697
+ effects?: RuleEffectConstraints;
698
+ }
699
+
700
+ /**
701
+ * JSONForms rule effect constraints.
702
+ *
703
+ * @public
704
+ */
705
+ export declare interface RuleEffectConstraints {
706
+ /** SHOW - show element when condition is true */
707
+ SHOW?: Severity;
708
+ /** HIDE - hide element when condition is true */
709
+ HIDE?: Severity;
710
+ /** ENABLE - enable element when condition is true */
711
+ ENABLE?: Severity;
712
+ /** DISABLE - disable element when condition is true */
713
+ DISABLE?: Severity;
714
+ }
715
+
716
+ /**
717
+ * Severity level for constraint violations.
718
+ * - "error": Violation fails validation
719
+ * - "warn": Violation emits warning but passes
720
+ * - "off": Feature is allowed (no violation)
721
+ *
722
+ * @public
723
+ */
724
+ export declare type Severity = "error" | "warn" | "off";
725
+
726
+ /**
727
+ * A field with static enum options (known at compile time).
728
+ *
729
+ * Options can be plain strings or objects with `id` and `label` properties.
730
+ *
731
+ * @typeParam N - The field name (string literal type)
732
+ * @typeParam O - Tuple of option values (strings or EnumOption objects)
733
+ *
734
+ * @public
735
+ */
736
+ export declare interface StaticEnumField<N extends string, O extends readonly EnumOptionValue[]> {
737
+ /** Type discriminator for form elements */
738
+ readonly _type: "field";
739
+ /** Field type discriminator - identifies this as an enum field */
740
+ readonly _field: "enum";
741
+ /** Unique field identifier used as the schema key */
742
+ readonly name: N;
743
+ /** Array of allowed option values */
744
+ readonly options: O;
745
+ /** Display label for the field */
746
+ readonly label?: string;
747
+ /** Whether this field is required for form submission */
748
+ readonly required?: boolean;
749
+ }
750
+
751
+ /**
752
+ * Form element type definitions.
753
+ *
754
+ * These types define the structure of form specifications.
755
+ * The structure IS the definition - nesting implies layout and conditional logic.
756
+ */
757
+ /**
758
+ * A text input field.
759
+ *
760
+ * @typeParam N - The field name (string literal type)
761
+ *
762
+ * @public
763
+ */
764
+ export declare interface TextField<N extends string> {
765
+ /** Type discriminator for form elements */
766
+ readonly _type: "field";
767
+ /** Field type discriminator - identifies this as a text field */
768
+ readonly _field: "text";
769
+ /** Unique field identifier used as the schema key */
770
+ readonly name: N;
771
+ /** Display label for the field */
772
+ readonly label?: string;
773
+ /** Placeholder text shown when field is empty */
774
+ readonly placeholder?: string;
775
+ /** Whether this field is required for form submission */
776
+ readonly required?: boolean;
777
+ /** Minimum string length */
778
+ readonly minLength?: number;
779
+ /** Maximum string length */
780
+ readonly maxLength?: number;
781
+ /** Regular expression pattern the value must match */
782
+ readonly pattern?: string;
783
+ }
784
+
785
+ /**
786
+ * UI Schema feature constraints - control JSONForms-specific features.
787
+ *
788
+ * @public
789
+ */
790
+ export declare interface UISchemaConstraints {
791
+ /** Layout type constraints */
792
+ layouts?: LayoutTypeConstraints;
793
+ /** Rule (conditional) constraints */
794
+ rules?: RuleConstraints;
795
+ }
796
+
797
+ /**
798
+ * Validates field options against constraints.
799
+ *
800
+ * @param context - Information about the field and its options
801
+ * @param constraints - Field option constraints
802
+ * @returns Array of validation issues (empty if valid)
803
+ *
804
+ * @beta
805
+ */
806
+ export declare function validateFieldOptions(context: FieldOptionsContext, constraints: FieldOptionConstraints): ValidationIssue[];
807
+
808
+ /**
809
+ * Validates a field type against constraints.
810
+ *
811
+ * @param context - Information about the field being validated
812
+ * @param constraints - Field type constraints
813
+ * @returns Array of validation issues (empty if valid)
814
+ *
815
+ * @beta
816
+ */
817
+ export declare function validateFieldTypes(context: FieldTypeContext, constraints: FieldTypeConstraints): ValidationIssue[];
818
+
819
+ /**
820
+ * Validates a complete FormSpec against constraints.
821
+ *
822
+ * @param formSpec - The FormSpec to validate
823
+ * @param options - Validation options including constraints
824
+ * @returns Validation result with all issues found
825
+ *
826
+ * @public
827
+ */
828
+ export declare function validateFormSpec(formSpec: FormSpec<readonly FormElement[]>, options?: FormSpecValidationOptions): ValidationResult;
829
+
830
+ /**
831
+ * Validates FormSpec elements against constraints.
832
+ *
833
+ * This is the main entry point for validating a form specification
834
+ * against a constraint configuration. It walks through all elements
835
+ * and checks each one against the configured constraints.
836
+ *
837
+ * @param elements - FormSpec elements to validate
838
+ * @param options - Validation options including constraints
839
+ * @returns Validation result with all issues found
840
+ *
841
+ * @example
842
+ * ```ts
843
+ * import { formspec, field, group } from '@formspec/dsl';
844
+ * import { validateFormSpecElements, defineConstraints } from '@formspec/constraints';
845
+ *
846
+ * const form = formspec(
847
+ * group("Contact",
848
+ * field.text("name"),
849
+ * field.dynamicEnum("country", "countries"),
850
+ * ),
851
+ * );
852
+ *
853
+ * const result = validateFormSpecElements(form.elements, {
854
+ * constraints: {
855
+ * fieldTypes: { dynamicEnum: 'error' },
856
+ * layout: { group: 'error' },
857
+ * },
858
+ * });
859
+ *
860
+ * if (!result.valid) {
861
+ * console.error('Validation failed:', result.issues);
862
+ * }
863
+ * ```
864
+ *
865
+ * @public
866
+ */
867
+ export declare function validateFormSpecElements(elements: readonly FormElement[], options?: FormSpecValidationOptions): ValidationResult;
868
+
869
+ /**
870
+ * Validates a layout element against constraints.
871
+ *
872
+ * @param context - Information about the layout element
873
+ * @param constraints - Layout constraints
874
+ * @returns Array of validation issues (empty if valid)
875
+ *
876
+ * @beta
877
+ */
878
+ export declare function validateLayout(context: LayoutContext, constraints: LayoutConstraints): ValidationIssue[];
879
+
880
+ /**
881
+ * A single validation issue found during constraint checking.
882
+ *
883
+ * @public
884
+ */
885
+ export declare interface ValidationIssue {
886
+ /** Unique code identifying the issue type */
887
+ code: string;
888
+ /** Human-readable description of the issue */
889
+ message: string;
890
+ /** Severity level of this issue */
891
+ severity: "error" | "warning";
892
+ /** Which constraint category this issue belongs to */
893
+ category: "fieldTypes" | "layout" | "uiSchema" | "fieldOptions" | "controlOptions";
894
+ /** JSON pointer or field path to the issue location */
895
+ path?: string;
896
+ /** Name of the affected field (if applicable) */
897
+ fieldName?: string;
898
+ /** Type of the affected field (if applicable) */
899
+ fieldType?: string;
900
+ }
901
+
902
+ /**
903
+ * Result of validating a FormSpec or schema against constraints.
904
+ *
905
+ * @public
906
+ */
907
+ export declare interface ValidationResult {
908
+ /** Whether validation passed (no errors, warnings OK) */
909
+ valid: boolean;
910
+ /** List of all issues found */
911
+ issues: ValidationIssue[];
912
+ }
913
+
914
+ export { }