@formspec/core 0.1.0-alpha.12 → 0.1.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -110,28 +110,28 @@ function processForm(form: FormSpec<readonly FormElement[]>) {
110
110
 
111
111
  ### IR Types
112
112
 
113
- | Type | Description |
114
- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
115
- | `FormIR` | Root IR node — contains elements, type registry, IR version |
116
- | `FormIRElement` | Union of `FieldNode` and `LayoutNode` |
117
- | `FieldNode` | IR field with name, type, constraints, annotations |
118
- | `LayoutNode` | Union of `GroupLayoutNode` and `ConditionalLayoutNode` |
119
- | `TypeNode` | Union: `PrimitiveTypeNode`, `EnumTypeNode`, `ArrayTypeNode`, `ObjectTypeNode`, `UnionTypeNode`, `ReferenceTypeNode`, `DynamicTypeNode`, `CustomTypeNode` |
120
- | `ConstraintNode` | Union: `NumericConstraintNode`, `LengthConstraintNode`, `PatternConstraintNode`, `ArrayCardinalityConstraintNode`, `EnumMemberConstraintNode`, `CustomConstraintNode` |
113
+ | Type | Description |
114
+ | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
115
+ | `FormIR` | Root IR node — contains elements, type registry, IR version |
116
+ | `FormIRElement` | Union of `FieldNode` and `LayoutNode` |
117
+ | `FieldNode` | IR field with name, type, constraints, annotations |
118
+ | `LayoutNode` | Union of `GroupLayoutNode` and `ConditionalLayoutNode` |
119
+ | `TypeNode` | Union: `PrimitiveTypeNode`, `EnumTypeNode`, `ArrayTypeNode`, `ObjectTypeNode`, `UnionTypeNode`, `ReferenceTypeNode`, `DynamicTypeNode`, `CustomTypeNode` |
120
+ | `ConstraintNode` | Union: `NumericConstraintNode`, `LengthConstraintNode`, `PatternConstraintNode`, `ArrayCardinalityConstraintNode`, `EnumMemberConstraintNode`, `CustomConstraintNode` |
121
121
  | `AnnotationNode` | Union: `DisplayNameAnnotationNode`, `DescriptionAnnotationNode`, `PlaceholderAnnotationNode`, `DefaultValueAnnotationNode`, `DeprecatedAnnotationNode`, `FormatHintAnnotationNode`, `CustomAnnotationNode` |
122
- | `Provenance` | Source location tracking — file, line, column, surface |
123
- | `IR_VERSION` | Current IR version (`"0.1.0"`) |
122
+ | `Provenance` | Source location tracking — file, line, column, surface |
123
+ | `IR_VERSION` | Current IR version (`"0.1.0"`) |
124
124
 
125
125
  ### Extension API
126
126
 
127
127
  FormSpec's type system is extensible via registration functions:
128
128
 
129
- | Function | Description |
130
- | ------------------------- | -------------------------------------------------------------------------------- |
131
- | `defineExtension(def)` | Register a complete extension with constraints, annotations, types, and vocabulary keywords |
132
- | `defineConstraint(reg)` | Register a custom constraint (e.g., `multipleOf`, `uniqueItems`) |
133
- | `defineAnnotation(reg)` | Register a custom annotation (e.g., tooltip, help URL) |
134
- | `defineCustomType(reg)` | Register a custom type node for JSON Schema generation |
129
+ | Function | Description |
130
+ | ----------------------- | ------------------------------------------------------------------------------------------- |
131
+ | `defineExtension(def)` | Register a complete extension with constraints, annotations, types, and vocabulary keywords |
132
+ | `defineConstraint(reg)` | Register a custom constraint (e.g., `multipleOf`, `uniqueItems`) |
133
+ | `defineAnnotation(reg)` | Register a custom annotation (e.g., tooltip, help URL) |
134
+ | `defineCustomType(reg)` | Register a custom type node for JSON Schema generation |
135
135
 
136
136
  ```typescript
137
137
  import { defineExtension, defineConstraint, defineAnnotation } from "@formspec/core";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=constraint-definitions.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constraint-definitions.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/constraint-definitions.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=guards.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/guards.test.ts"],"names":[],"mappings":""}
package/dist/core.d.ts CHANGED
@@ -85,17 +85,22 @@ export declare interface BooleanField<N extends string> {
85
85
  /**
86
86
  * Built-in constraint names mapped to their expected value type for parsing.
87
87
  * Constraints are surface-agnostic — they manifest as both TSDoc tags
88
- * (e.g., `@Minimum 0`) and chain DSL options (e.g., `{ minimum: 0 }`).
88
+ * (e.g., `@minimum 0`) and chain DSL options (e.g., `{ minimum: 0 }`).
89
+ *
90
+ * Keys use camelCase matching JSON Schema property names.
89
91
  */
90
92
  export declare const BUILTIN_CONSTRAINT_DEFINITIONS: {
91
- readonly Minimum: "number";
92
- readonly Maximum: "number";
93
- readonly ExclusiveMinimum: "number";
94
- readonly ExclusiveMaximum: "number";
95
- readonly MinLength: "number";
96
- readonly MaxLength: "number";
97
- readonly Pattern: "string";
98
- readonly EnumOptions: "json";
93
+ readonly minimum: "number";
94
+ readonly maximum: "number";
95
+ readonly exclusiveMinimum: "number";
96
+ readonly exclusiveMaximum: "number";
97
+ readonly multipleOf: "number";
98
+ readonly minLength: "number";
99
+ readonly maxLength: "number";
100
+ readonly minItems: "number";
101
+ readonly maxItems: "number";
102
+ readonly pattern: "string";
103
+ readonly enumOptions: "json";
99
104
  };
100
105
 
101
106
  /** Type of a built-in constraint name. */
@@ -399,6 +404,8 @@ export declare interface DynamicSchemaField<N extends string> {
399
404
  readonly label?: string;
400
405
  /** Whether this field is required for form submission */
401
406
  readonly required?: boolean;
407
+ /** Field names whose values are needed to configure the schema */
408
+ readonly params?: readonly string[];
402
409
  }
403
410
 
404
411
  /** Dynamic type — schema resolved at runtime from a named data source. */
@@ -664,6 +671,50 @@ export declare interface GroupLayoutNode {
664
671
  */
665
672
  export declare const IR_VERSION: "0.1.0";
666
673
 
674
+ /** Narrows a FormElement to an array field. */
675
+ export declare function isArrayField(element: FormElement): element is ArrayField<string, readonly FormElement[]>;
676
+
677
+ /** Narrows a FormElement to a boolean checkbox field. */
678
+ export declare function isBooleanField(element: FormElement): element is BooleanField<string>;
679
+
680
+ /**
681
+ * Type guard: checks whether a tag name is a known built-in constraint.
682
+ *
683
+ * Uses `Object.hasOwn()` rather than `in` to prevent prototype-chain
684
+ * matches on names like `"toString"` or `"constructor"`.
685
+ *
686
+ * Callers should normalize with {@link normalizeConstraintTagName} first
687
+ * if the input may be PascalCase.
688
+ */
689
+ export declare function isBuiltinConstraintName(tagName: string): tagName is BuiltinConstraintName;
690
+
691
+ /** Narrows a FormElement to a conditional wrapper. */
692
+ export declare function isConditional(element: FormElement): element is Conditional<string, unknown, readonly FormElement[]>;
693
+
694
+ /** Narrows a FormElement to a dynamic enum field. */
695
+ export declare function isDynamicEnumField(element: FormElement): element is DynamicEnumField<string, string>;
696
+
697
+ /** Narrows a FormElement to a dynamic schema field. */
698
+ export declare function isDynamicSchemaField(element: FormElement): element is DynamicSchemaField<string>;
699
+
700
+ /** Narrows a FormElement to any field type. */
701
+ export declare function isField(element: FormElement): element is AnyField;
702
+
703
+ /** Narrows a FormElement to a visual group. */
704
+ export declare function isGroup(element: FormElement): element is Group<readonly FormElement[]>;
705
+
706
+ /** Narrows a FormElement to a numeric input field. */
707
+ export declare function isNumberField(element: FormElement): element is NumberField<string>;
708
+
709
+ /** Narrows a FormElement to an object field. */
710
+ export declare function isObjectField(element: FormElement): element is ObjectField<string, readonly FormElement[]>;
711
+
712
+ /** Narrows a FormElement to a static enum field. */
713
+ export declare function isStaticEnumField(element: FormElement): element is StaticEnumField<string, readonly EnumOptionValue[]>;
714
+
715
+ /** Narrows a FormElement to a text input field. */
716
+ export declare function isTextField(element: FormElement): element is TextField<string>;
717
+
667
718
  /**
668
719
  * A JSON-serializable value. All IR nodes must be representable as JSON.
669
720
  */
@@ -692,6 +743,19 @@ export declare interface LengthConstraintNode {
692
743
  readonly provenance: Provenance;
693
744
  }
694
745
 
746
+ /**
747
+ * Normalizes a constraint tag name from PascalCase to camelCase.
748
+ *
749
+ * Lowercases the first character so that e.g. `"Minimum"` becomes `"minimum"`.
750
+ * Callers must strip the `@` prefix before calling this function.
751
+ *
752
+ * @example
753
+ * normalizeConstraintTagName("Minimum") // "minimum"
754
+ * normalizeConstraintTagName("MinLength") // "minLength"
755
+ * normalizeConstraintTagName("minimum") // "minimum" (idempotent)
756
+ */
757
+ export declare function normalizeConstraintTagName(tagName: string): string;
758
+
695
759
  /**
696
760
  * A numeric input field.
697
761
  *
@@ -712,6 +776,8 @@ export declare interface NumberField<N extends string> {
712
776
  readonly max?: number;
713
777
  /** Whether this field is required for form submission */
714
778
  readonly required?: boolean;
779
+ /** Value must be a multiple of this number (use 1 for integer semantics) */
780
+ readonly multipleOf?: number;
715
781
  }
716
782
 
717
783
  /**
@@ -931,6 +997,12 @@ export declare interface TextField<N extends string> {
931
997
  readonly placeholder?: string;
932
998
  /** Whether this field is required for form submission */
933
999
  readonly required?: boolean;
1000
+ /** Minimum string length */
1001
+ readonly minLength?: number;
1002
+ /** Maximum string length */
1003
+ readonly maxLength?: number;
1004
+ /** Regular expression pattern the value must match */
1005
+ readonly pattern?: string;
934
1006
  }
935
1007
 
936
1008
  /** A named type definition stored in the type registry. */
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Type guards for FormSpec form elements.
3
+ *
4
+ * Each guard narrows a {@link FormElement} to a specific field, group, or conditional type.
5
+ */
6
+ import type { FormElement, AnyField, TextField, NumberField, BooleanField, StaticEnumField, DynamicEnumField, DynamicSchemaField, ArrayField, ObjectField, Group, Conditional, EnumOptionValue } from "./types/elements.js";
7
+ /** Narrows a FormElement to any field type. */
8
+ export declare function isField(element: FormElement): element is AnyField;
9
+ /** Narrows a FormElement to a text input field. */
10
+ export declare function isTextField(element: FormElement): element is TextField<string>;
11
+ /** Narrows a FormElement to a numeric input field. */
12
+ export declare function isNumberField(element: FormElement): element is NumberField<string>;
13
+ /** Narrows a FormElement to a boolean checkbox field. */
14
+ export declare function isBooleanField(element: FormElement): element is BooleanField<string>;
15
+ /** Narrows a FormElement to a static enum field. */
16
+ export declare function isStaticEnumField(element: FormElement): element is StaticEnumField<string, readonly EnumOptionValue[]>;
17
+ /** Narrows a FormElement to a dynamic enum field. */
18
+ export declare function isDynamicEnumField(element: FormElement): element is DynamicEnumField<string, string>;
19
+ /** Narrows a FormElement to a dynamic schema field. */
20
+ export declare function isDynamicSchemaField(element: FormElement): element is DynamicSchemaField<string>;
21
+ /** Narrows a FormElement to an array field. */
22
+ export declare function isArrayField(element: FormElement): element is ArrayField<string, readonly FormElement[]>;
23
+ /** Narrows a FormElement to an object field. */
24
+ export declare function isObjectField(element: FormElement): element is ObjectField<string, readonly FormElement[]>;
25
+ /** Narrows a FormElement to a visual group. */
26
+ export declare function isGroup(element: FormElement): element is Group<readonly FormElement[]>;
27
+ /** Narrows a FormElement to a conditional wrapper. */
28
+ export declare function isConditional(element: FormElement): element is Conditional<string, unknown, readonly FormElement[]>;
29
+ //# sourceMappingURL=guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,KAAK,EACL,WAAW,EACX,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAE7B,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,IAAI,QAAQ,CAEjE;AAED,mDAAmD;AACnD,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,CAE9E;AAED,sDAAsD;AACtD,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAElF;AAED,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAEpF;AAED,oDAAoD;AACpD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,WAAW,GACnB,OAAO,IAAI,eAAe,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC,CAEhE;AAED,qDAAqD;AACrD,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,WAAW,GACnB,OAAO,IAAI,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAE7C;AAED,uDAAuD;AACvD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAEhG;AAED,+CAA+C;AAC/C,wBAAgB,YAAY,CAC1B,OAAO,EAAE,WAAW,GACnB,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,CAEvD;AAED,gDAAgD;AAChD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,WAAW,GACnB,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,CAExD;AAED,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,IAAI,KAAK,CAAC,SAAS,WAAW,EAAE,CAAC,CAEtF;AAED,sDAAsD;AACtD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,WAAW,GACnB,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC,CAEjE"}
package/dist/index.cjs CHANGED
@@ -26,7 +26,20 @@ __export(index_exports, {
26
26
  defineAnnotation: () => defineAnnotation,
27
27
  defineConstraint: () => defineConstraint,
28
28
  defineCustomType: () => defineCustomType,
29
- defineExtension: () => defineExtension
29
+ defineExtension: () => defineExtension,
30
+ isArrayField: () => isArrayField,
31
+ isBooleanField: () => isBooleanField,
32
+ isBuiltinConstraintName: () => isBuiltinConstraintName,
33
+ isConditional: () => isConditional,
34
+ isDynamicEnumField: () => isDynamicEnumField,
35
+ isDynamicSchemaField: () => isDynamicSchemaField,
36
+ isField: () => isField,
37
+ isGroup: () => isGroup,
38
+ isNumberField: () => isNumberField,
39
+ isObjectField: () => isObjectField,
40
+ isStaticEnumField: () => isStaticEnumField,
41
+ isTextField: () => isTextField,
42
+ normalizeConstraintTagName: () => normalizeConstraintTagName
30
43
  });
31
44
  module.exports = __toCommonJS(index_exports);
32
45
 
@@ -43,15 +56,24 @@ function createInitialFieldState(value) {
43
56
 
44
57
  // src/types/constraint-definitions.ts
45
58
  var BUILTIN_CONSTRAINT_DEFINITIONS = {
46
- Minimum: "number",
47
- Maximum: "number",
48
- ExclusiveMinimum: "number",
49
- ExclusiveMaximum: "number",
50
- MinLength: "number",
51
- MaxLength: "number",
52
- Pattern: "string",
53
- EnumOptions: "json"
59
+ minimum: "number",
60
+ maximum: "number",
61
+ exclusiveMinimum: "number",
62
+ exclusiveMaximum: "number",
63
+ multipleOf: "number",
64
+ minLength: "number",
65
+ maxLength: "number",
66
+ minItems: "number",
67
+ maxItems: "number",
68
+ pattern: "string",
69
+ enumOptions: "json"
54
70
  };
71
+ function normalizeConstraintTagName(tagName) {
72
+ return tagName.charAt(0).toLowerCase() + tagName.slice(1);
73
+ }
74
+ function isBuiltinConstraintName(tagName) {
75
+ return Object.hasOwn(BUILTIN_CONSTRAINT_DEFINITIONS, tagName);
76
+ }
55
77
 
56
78
  // src/types/ir.ts
57
79
  var IR_VERSION = "0.1.0";
@@ -69,6 +91,41 @@ function defineConstraint(reg) {
69
91
  function defineAnnotation(reg) {
70
92
  return reg;
71
93
  }
94
+
95
+ // src/guards.ts
96
+ function isField(element) {
97
+ return element._type === "field";
98
+ }
99
+ function isTextField(element) {
100
+ return element._type === "field" && element._field === "text";
101
+ }
102
+ function isNumberField(element) {
103
+ return element._type === "field" && element._field === "number";
104
+ }
105
+ function isBooleanField(element) {
106
+ return element._type === "field" && element._field === "boolean";
107
+ }
108
+ function isStaticEnumField(element) {
109
+ return element._type === "field" && element._field === "enum";
110
+ }
111
+ function isDynamicEnumField(element) {
112
+ return element._type === "field" && element._field === "dynamic_enum";
113
+ }
114
+ function isDynamicSchemaField(element) {
115
+ return element._type === "field" && element._field === "dynamic_schema";
116
+ }
117
+ function isArrayField(element) {
118
+ return element._type === "field" && element._field === "array";
119
+ }
120
+ function isObjectField(element) {
121
+ return element._type === "field" && element._field === "object";
122
+ }
123
+ function isGroup(element) {
124
+ return element._type === "group";
125
+ }
126
+ function isConditional(element) {
127
+ return element._type === "conditional";
128
+ }
72
129
  // Annotate the CommonJS export names for ESM import in node:
73
130
  0 && (module.exports = {
74
131
  BUILTIN_CONSTRAINT_DEFINITIONS,
@@ -77,6 +134,19 @@ function defineAnnotation(reg) {
77
134
  defineAnnotation,
78
135
  defineConstraint,
79
136
  defineCustomType,
80
- defineExtension
137
+ defineExtension,
138
+ isArrayField,
139
+ isBooleanField,
140
+ isBuiltinConstraintName,
141
+ isConditional,
142
+ isDynamicEnumField,
143
+ isDynamicSchemaField,
144
+ isField,
145
+ isGroup,
146
+ isNumberField,
147
+ isObjectField,
148
+ isStaticEnumField,
149
+ isTextField,
150
+ normalizeConstraintTagName
81
151
  });
82
152
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/types/field-state.ts","../src/types/constraint-definitions.ts","../src/types/ir.ts","../src/extensions/index.ts"],"sourcesContent":["/**\n * `@formspec/core` - Core type definitions for FormSpec\n *\n * This package provides the foundational types used throughout the FormSpec ecosystem:\n * - Form element types (fields, groups, conditionals)\n * - Field and form state types\n * - Data source registry for dynamic enums\n * - Canonical IR types (FormIR, FieldNode, TypeNode, ConstraintNode, AnnotationNode, etc.)\n *\n * @packageDocumentation\n */\n\n// Re-export all types\nexport type {\n // Validity\n Validity,\n\n // Field state\n FieldState,\n\n // Form state\n FormState,\n\n // Data sources\n DataSourceRegistry,\n DataSourceOption,\n FetchOptionsResponse,\n DataSourceValueType,\n\n // Elements\n TextField,\n NumberField,\n BooleanField,\n EnumOption,\n EnumOptionValue,\n StaticEnumField,\n DynamicEnumField,\n DynamicSchemaField,\n ArrayField,\n ObjectField,\n AnyField,\n Group,\n Conditional,\n FormElement,\n FormSpec,\n\n // Predicates\n EqualsPredicate,\n Predicate,\n\n // Built-in constraints\n BuiltinConstraintName,\n\n // Canonical IR\n JsonValue,\n Provenance,\n PathTarget,\n TypeNode,\n PrimitiveTypeNode,\n EnumMember,\n EnumTypeNode,\n ArrayTypeNode,\n ObjectProperty,\n ObjectTypeNode,\n UnionTypeNode,\n ReferenceTypeNode,\n DynamicTypeNode,\n CustomTypeNode,\n ConstraintNode,\n NumericConstraintNode,\n LengthConstraintNode,\n PatternConstraintNode,\n ArrayCardinalityConstraintNode,\n EnumMemberConstraintNode,\n CustomConstraintNode,\n AnnotationNode,\n DisplayNameAnnotationNode,\n DescriptionAnnotationNode,\n PlaceholderAnnotationNode,\n DefaultValueAnnotationNode,\n DeprecatedAnnotationNode,\n FormatHintAnnotationNode,\n CustomAnnotationNode,\n FieldNode,\n LayoutNode,\n GroupLayoutNode,\n ConditionalLayoutNode,\n FormIRElement,\n TypeDefinition,\n FormIR,\n} from \"./types/index.js\";\n\n// Re-export functions and constants\nexport {\n createInitialFieldState,\n BUILTIN_CONSTRAINT_DEFINITIONS,\n IR_VERSION,\n} from \"./types/index.js\";\n\n// Extension API\nexport type {\n ExtensionDefinition,\n CustomTypeRegistration,\n CustomConstraintRegistration,\n CustomAnnotationRegistration,\n VocabularyKeywordRegistration,\n} from \"./extensions/index.js\";\n\nexport {\n defineExtension,\n defineCustomType,\n defineConstraint,\n defineAnnotation,\n} from \"./extensions/index.js\";\n","import type { Validity } from \"./validity.js\";\n\n/**\n * Represents the runtime state of a single form field.\n *\n * @typeParam T - The value type of the field\n */\nexport interface FieldState<T> {\n /** Current value of the field */\n readonly value: T;\n\n /** Whether the field has been modified by the user */\n readonly dirty: boolean;\n\n /** Whether the field has been focused and blurred */\n readonly touched: boolean;\n\n /** Current validity state */\n readonly validity: Validity;\n\n /** Validation error messages, if any */\n readonly errors: readonly string[];\n}\n\n/**\n * Creates initial field state with default values.\n *\n * @typeParam T - The value type of the field\n * @param value - The initial value for the field\n * @returns Initial field state\n */\nexport function createInitialFieldState<T>(value: T): FieldState<T> {\n return {\n value,\n dirty: false,\n touched: false,\n validity: \"unknown\",\n errors: [],\n };\n}\n","/**\n * Built-in constraint definitions for FormSpec constraint validation.\n *\n * This is the single source of truth for which constraints FormSpec\n * recognizes. Both `@formspec/build` (schema generation)\n * and `@formspec/eslint-plugin` (lint-time validation) import from here.\n */\n\n/**\n * Built-in constraint names mapped to their expected value type for parsing.\n * Constraints are surface-agnostic — they manifest as both TSDoc tags\n * (e.g., `@Minimum 0`) and chain DSL options (e.g., `{ minimum: 0 }`).\n */\nexport const BUILTIN_CONSTRAINT_DEFINITIONS = {\n Minimum: \"number\",\n Maximum: \"number\",\n ExclusiveMinimum: \"number\",\n ExclusiveMaximum: \"number\",\n MinLength: \"number\",\n MaxLength: \"number\",\n Pattern: \"string\",\n EnumOptions: \"json\",\n} as const;\n\n/** Type of a built-in constraint name. */\nexport type BuiltinConstraintName = keyof typeof BUILTIN_CONSTRAINT_DEFINITIONS;\n","/**\n * Canonical Intermediate Representation (IR) types for FormSpec.\n *\n * The IR is the shared intermediate structure that both authoring surfaces\n * (chain DSL and TSDoc-annotated types) compile to. All downstream operations\n * — JSON Schema generation, UI Schema generation, constraint validation,\n * diagnostics — consume the IR exclusively.\n *\n * All types are plain, serializable objects (no live compiler references).\n *\n * @see {@link https://github.com/stripe/formspec-workspace/blob/main/scratch/design/001-canonical-ir.md}\n */\n\n// =============================================================================\n// IR VERSION\n// =============================================================================\n\n/**\n * The current IR format version. Centralized here so all canonicalizers\n * and consumers reference a single source of truth.\n */\nexport const IR_VERSION = \"0.1.0\" as const;\n\n// =============================================================================\n// UTILITY TYPES\n// =============================================================================\n\n/**\n * A JSON-serializable value. All IR nodes must be representable as JSON.\n */\nexport type JsonValue =\n | null\n | boolean\n | number\n | string\n | readonly JsonValue[]\n | { readonly [key: string]: JsonValue };\n\n// =============================================================================\n// PROVENANCE\n// =============================================================================\n\n/**\n * Describes the origin of an IR node.\n * Enables diagnostics that point to the source of a contradiction or error.\n */\nexport interface Provenance {\n /** The authoring surface that produced this node. */\n readonly surface: \"tsdoc\" | \"chain-dsl\" | \"extension\" | \"inferred\";\n /** Absolute path to the source file. */\n readonly file: string;\n /** 1-based line number in the source file. */\n readonly line: number;\n /** 0-based column number in the source file. */\n readonly column: number;\n /** Length of the source span in characters (for IDE underline ranges). */\n readonly length?: number;\n /**\n * The specific tag, call, or construct that produced this node.\n * Examples: `@minimum`, `field.number({ min: 0 })`, `optional`\n */\n readonly tagName?: string;\n}\n\n// =============================================================================\n// PATH TARGET\n// =============================================================================\n\n/**\n * A path targeting a sub-field within a complex type.\n * Used by constraints and annotations to target nested properties.\n */\nexport interface PathTarget {\n /**\n * Sequence of property names forming a path from the annotated field's type\n * to the target sub-field.\n * e.g., `[\"value\"]` or `[\"address\", \"zip\"]`\n */\n readonly segments: readonly string[];\n}\n\n// =============================================================================\n// TYPE NODES\n// =============================================================================\n\n/**\n * Discriminated union of all type representations in the IR.\n */\nexport type TypeNode =\n | PrimitiveTypeNode\n | EnumTypeNode\n | ArrayTypeNode\n | ObjectTypeNode\n | UnionTypeNode\n | ReferenceTypeNode\n | DynamicTypeNode\n | CustomTypeNode;\n\n/**\n * Primitive types mapping directly to JSON Schema primitives.\n *\n * Note: integer is NOT a primitive kind — integer semantics are expressed\n * via a `multipleOf: 1` constraint on a number type.\n */\nexport interface PrimitiveTypeNode {\n readonly kind: \"primitive\";\n readonly primitiveKind: \"string\" | \"number\" | \"boolean\" | \"null\";\n}\n\n/** A member of a static enum type. */\nexport interface EnumMember {\n /** The serialized value stored in data. */\n readonly value: string | number;\n /** Optional per-member display name. */\n readonly displayName?: string;\n}\n\n/** Static enum type — members known at build time. */\nexport interface EnumTypeNode {\n readonly kind: \"enum\";\n readonly members: readonly EnumMember[];\n}\n\n/** Array type with a single items type. */\nexport interface ArrayTypeNode {\n readonly kind: \"array\";\n readonly items: TypeNode;\n}\n\n/** A named property within an object type. */\nexport interface ObjectProperty {\n readonly name: string;\n readonly type: TypeNode;\n readonly optional: boolean;\n /**\n * Use-site constraints on this property.\n * Distinct from constraints on the property's type — these are\n * use-site constraints (e.g., `@minimum :amount 0` targets the\n * `amount` property of a `MonetaryAmount` field).\n */\n readonly constraints: readonly ConstraintNode[];\n /** Use-site annotations on this property. */\n readonly annotations: readonly AnnotationNode[];\n readonly provenance: Provenance;\n}\n\n/** Object type with named properties. */\nexport interface ObjectTypeNode {\n readonly kind: \"object\";\n /**\n * Named properties of this object. Order is preserved from the source\n * declaration for deterministic output.\n */\n readonly properties: readonly ObjectProperty[];\n /**\n * Whether additional properties beyond those listed are permitted.\n * Defaults to false — object types in FormSpec are closed.\n */\n readonly additionalProperties: boolean;\n}\n\n/** Union type for non-enum unions. Nullable types are `T | null` using this. */\nexport interface UnionTypeNode {\n readonly kind: \"union\";\n readonly members: readonly TypeNode[];\n}\n\n/** Named type reference — preserved as references for `$defs`/`$ref` emission. */\nexport interface ReferenceTypeNode {\n readonly kind: \"reference\";\n /**\n * The fully-qualified name of the referenced type.\n * For TypeScript interfaces/type aliases: `\"<module>#<TypeName>\"`.\n * For built-in types: the primitive kind string.\n */\n readonly name: string;\n /**\n * Type arguments if this is a generic instantiation.\n * e.g., `Array<string>` → `{ name: \"Array\", typeArguments: [PrimitiveTypeNode(\"string\")] }`\n */\n readonly typeArguments: readonly TypeNode[];\n}\n\n/** Dynamic type — schema resolved at runtime from a named data source. */\nexport interface DynamicTypeNode {\n readonly kind: \"dynamic\";\n readonly dynamicKind: \"enum\" | \"schema\";\n /** Key identifying the runtime data source or schema provider. */\n readonly sourceKey: string;\n /**\n * For dynamic enums: field names whose current values are passed as\n * parameters to the data source resolver.\n */\n readonly parameterFields: readonly string[];\n}\n\n/** Custom type registered by an extension. */\nexport interface CustomTypeNode {\n readonly kind: \"custom\";\n /**\n * The extension-qualified type identifier.\n * Format: `\"<vendor-prefix>/<extension-name>/<type-name>\"`\n * e.g., `\"x-stripe/monetary/MonetaryAmount\"`\n */\n readonly typeId: string;\n /**\n * Opaque payload serialized by the extension that registered this type.\n * Must be JSON-serializable.\n */\n readonly payload: JsonValue;\n}\n\n// =============================================================================\n// CONSTRAINT NODES\n// =============================================================================\n\n/**\n * Discriminated union of all constraint types.\n * Constraints are set-influencing: they narrow the set of valid values.\n */\nexport type ConstraintNode =\n | NumericConstraintNode\n | LengthConstraintNode\n | PatternConstraintNode\n | ArrayCardinalityConstraintNode\n | EnumMemberConstraintNode\n | CustomConstraintNode;\n\n/**\n * Numeric constraints: bounds and multipleOf.\n *\n * `minimum` and `maximum` are inclusive; `exclusiveMinimum` and\n * `exclusiveMaximum` are exclusive bounds (matching JSON Schema 2020-12\n * semantics).\n *\n * Type applicability: may only attach to fields with `PrimitiveTypeNode(\"number\")`\n * or a `ReferenceTypeNode` that resolves to one.\n */\nexport interface NumericConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind:\n | \"minimum\"\n | \"maximum\"\n | \"exclusiveMinimum\"\n | \"exclusiveMaximum\"\n | \"multipleOf\";\n readonly value: number;\n /** If present, targets a nested sub-field rather than the field itself. */\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/**\n * String length and array item count constraints.\n *\n * `minLength`/`maxLength` apply to strings; `minItems`/`maxItems` apply to\n * arrays. They share the same node shape because the composition rules are\n * identical.\n *\n * Type applicability: `minLength`/`maxLength` require `PrimitiveTypeNode(\"string\")`;\n * `minItems`/`maxItems` require `ArrayTypeNode`.\n */\nexport interface LengthConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"minLength\" | \"maxLength\" | \"minItems\" | \"maxItems\";\n readonly value: number;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/**\n * String pattern constraint (ECMA-262 regex without delimiters).\n *\n * Multiple `pattern` constraints on the same field compose via intersection:\n * all patterns must match simultaneously.\n *\n * Type applicability: requires `PrimitiveTypeNode(\"string\")`.\n */\nexport interface PatternConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"pattern\";\n /** ECMA-262 regular expression, without delimiters. */\n readonly pattern: string;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Array uniqueness constraint. */\nexport interface ArrayCardinalityConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"uniqueItems\";\n readonly value: true;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Enum member subset constraint (refinement — only narrows). */\nexport interface EnumMemberConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"allowedMembers\";\n readonly members: readonly (string | number)[];\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Extension-registered custom constraint. */\nexport interface CustomConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"custom\";\n /** Extension-qualified ID: `\"<vendor-prefix>/<extension-name>/<constraint-name>\"` */\n readonly constraintId: string;\n /** JSON-serializable payload defined by the extension. */\n readonly payload: JsonValue;\n /** How this constraint composes with others of the same `constraintId`. */\n readonly compositionRule: \"intersect\" | \"override\";\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// ANNOTATION NODES\n// =============================================================================\n\n/**\n * Discriminated union of all annotation types.\n * Annotations are value-influencing: they describe or present a field\n * but do not affect which values are valid.\n */\nexport type AnnotationNode =\n | DisplayNameAnnotationNode\n | DescriptionAnnotationNode\n | PlaceholderAnnotationNode\n | DefaultValueAnnotationNode\n | DeprecatedAnnotationNode\n | FormatHintAnnotationNode\n | CustomAnnotationNode;\n\nexport interface DisplayNameAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"displayName\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface DescriptionAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"description\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface PlaceholderAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"placeholder\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface DefaultValueAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"defaultValue\";\n /** Must be JSON-serializable and type-compatible (verified during Validate phase). */\n readonly value: JsonValue;\n readonly provenance: Provenance;\n}\n\nexport interface DeprecatedAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"deprecated\";\n /** Optional deprecation message. */\n readonly message?: string;\n readonly provenance: Provenance;\n}\n\n/** UI rendering hint — does not affect schema validation. */\nexport interface FormatHintAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"formatHint\";\n /** Renderer-specific format identifier: \"textarea\", \"radio\", \"date\", \"color\", etc. */\n readonly format: string;\n readonly provenance: Provenance;\n}\n\n/** Extension-registered custom annotation. */\nexport interface CustomAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"custom\";\n /** Extension-qualified ID: `\"<vendor-prefix>/<extension-name>/<annotation-name>\"` */\n readonly annotationId: string;\n readonly value: JsonValue;\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// FIELD NODE\n// =============================================================================\n\n/** A single form field after canonicalization. */\nexport interface FieldNode {\n readonly kind: \"field\";\n /** The field's key in the data schema. */\n readonly name: string;\n /** The resolved type of this field. */\n readonly type: TypeNode;\n /** Whether this field is required in the data schema. */\n readonly required: boolean;\n /** Set-influencing constraints, after merging. */\n readonly constraints: readonly ConstraintNode[];\n /** Value-influencing annotations, after merging. */\n readonly annotations: readonly AnnotationNode[];\n /** Where this field was declared. */\n readonly provenance: Provenance;\n /**\n * Debug only — ordered list of constraint/annotation nodes that participated\n * in merging, including dominated ones.\n */\n readonly mergeHistory?: readonly {\n readonly node: ConstraintNode | AnnotationNode;\n readonly dominated: boolean;\n }[];\n}\n\n// =============================================================================\n// LAYOUT NODES\n// =============================================================================\n\n/** Union of layout node types. */\nexport type LayoutNode = GroupLayoutNode | ConditionalLayoutNode;\n\n/** A visual grouping of form elements. */\nexport interface GroupLayoutNode {\n readonly kind: \"group\";\n readonly label: string;\n /** Elements contained in this group — may be fields or nested groups. */\n readonly elements: readonly FormIRElement[];\n readonly provenance: Provenance;\n}\n\n/** Conditional visibility based on another field's value. */\nexport interface ConditionalLayoutNode {\n readonly kind: \"conditional\";\n /** The field whose value triggers visibility. */\n readonly fieldName: string;\n /** The value that makes the condition true (SHOW). */\n readonly value: JsonValue;\n /** Elements shown when the condition is met. */\n readonly elements: readonly FormIRElement[];\n readonly provenance: Provenance;\n}\n\n/** Union of all IR element types. */\nexport type FormIRElement = FieldNode | LayoutNode;\n\n// =============================================================================\n// TYPE REGISTRY\n// =============================================================================\n\n/** A named type definition stored in the type registry. */\nexport interface TypeDefinition {\n /** The fully-qualified reference name (key in the registry). */\n readonly name: string;\n /** The resolved type node. */\n readonly type: TypeNode;\n /** Where this type was declared. */\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// FORM IR (TOP-LEVEL)\n// =============================================================================\n\n/**\n * The complete Canonical Intermediate Representation for a form.\n *\n * Output of the Canonicalize phase; input to Validate, Generate (JSON Schema),\n * and Generate (UI Schema) phases.\n *\n * Serializable to JSON — no live compiler objects.\n */\nexport interface FormIR {\n readonly kind: \"form-ir\";\n /**\n * Schema version for the IR format itself.\n * Should equal `IR_VERSION`.\n */\n readonly irVersion: string;\n /** Top-level elements of the form: fields and layout nodes. */\n readonly elements: readonly FormIRElement[];\n /**\n * Registry of named types referenced by fields in this form.\n * Keys are fully-qualified type names matching `ReferenceTypeNode.name`.\n */\n readonly typeRegistry: Readonly<Record<string, TypeDefinition>>;\n /** Provenance of the form definition itself. */\n readonly provenance: Provenance;\n}\n","/**\n * Extension API for registering custom types, constraints, annotations,\n * and vocabulary keywords with FormSpec.\n *\n * Extensions allow third-party packages (e.g., \"Decimal\", \"DateOnly\") to\n * plug into the FormSpec pipeline. The types and factory functions defined\n * here are consumed by the FormSpec build pipeline.\n *\n * @packageDocumentation\n */\n\nimport type { JsonValue, TypeNode } from \"../types/ir.js\";\n\n// =============================================================================\n// REGISTRATION TYPES\n// =============================================================================\n\n/**\n * Registration for a custom type that maps to a JSON Schema representation.\n *\n * Custom types are referenced via {@link CustomTypeNode} in the IR and\n * resolved to JSON Schema via `toJsonSchema` during generation.\n */\nexport interface CustomTypeRegistration {\n /** The type name, unique within the extension. */\n readonly typeName: string;\n /**\n * Converts the custom type's payload into a JSON Schema fragment.\n *\n * @param payload - The opaque JSON payload from the {@link CustomTypeNode}.\n * @param vendorPrefix - The vendor prefix for extension keywords (e.g., \"x-stripe\").\n * @returns A JSON Schema fragment representing this type.\n */\n readonly toJsonSchema: (payload: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a custom constraint that maps to JSON Schema keywords.\n *\n * Custom constraints are referenced via {@link CustomConstraintNode} in the IR.\n */\nexport interface CustomConstraintRegistration {\n /** The constraint name, unique within the extension. */\n readonly constraintName: string;\n /**\n * How this constraint composes with other constraints of the same kind.\n * - \"intersect\": combine with logical AND (both must hold)\n * - \"override\": last writer wins\n */\n readonly compositionRule: \"intersect\" | \"override\";\n /**\n * TypeNode kinds this constraint is applicable to, or `null` for any type.\n * Used by the validator to emit TYPE_MISMATCH diagnostics.\n */\n readonly applicableTypes: readonly TypeNode[\"kind\"][] | null;\n /**\n * Converts the custom constraint's payload into JSON Schema keywords.\n *\n * @param payload - The opaque JSON payload from the {@link CustomConstraintNode}.\n * @param vendorPrefix - The vendor prefix for extension keywords.\n * @returns A JSON Schema fragment with the constraint keywords.\n */\n readonly toJsonSchema: (payload: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a custom annotation that may produce JSON Schema keywords.\n *\n * Custom annotations are referenced via {@link CustomAnnotationNode} in the IR.\n * They describe or present a field but do not affect which values are valid.\n */\nexport interface CustomAnnotationRegistration {\n /** The annotation name, unique within the extension. */\n readonly annotationName: string;\n /**\n * Optionally converts the annotation value into JSON Schema keywords.\n * If omitted, the annotation has no JSON Schema representation (UI-only).\n */\n readonly toJsonSchema?: (value: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a vocabulary keyword to include in a JSON Schema `$vocabulary` declaration.\n */\nexport interface VocabularyKeywordRegistration {\n /** The keyword name (without vendor prefix). */\n readonly keyword: string;\n /** JSON Schema that describes the valid values for this keyword. */\n readonly schema: JsonValue;\n}\n\n// =============================================================================\n// EXTENSION DEFINITION\n// =============================================================================\n\n/**\n * A complete extension definition bundling types, constraints, annotations,\n * and vocabulary keywords.\n *\n * @example\n * ```typescript\n * const monetaryExtension = defineExtension({\n * extensionId: \"x-stripe/monetary\",\n * types: [\n * defineCustomType({\n * typeName: \"Decimal\",\n * toJsonSchema: (_payload, prefix) => ({\n * type: \"string\",\n * [`${prefix}-decimal`]: true,\n * }),\n * }),\n * ],\n * });\n * ```\n */\nexport interface ExtensionDefinition {\n /** Globally unique extension identifier, e.g., \"x-stripe/monetary\". */\n readonly extensionId: string;\n /** Custom type registrations provided by this extension. */\n readonly types?: readonly CustomTypeRegistration[];\n /** Custom constraint registrations provided by this extension. */\n readonly constraints?: readonly CustomConstraintRegistration[];\n /** Custom annotation registrations provided by this extension. */\n readonly annotations?: readonly CustomAnnotationRegistration[];\n /** Vocabulary keyword registrations provided by this extension. */\n readonly vocabularyKeywords?: readonly VocabularyKeywordRegistration[];\n}\n\n// =============================================================================\n// FACTORY FUNCTIONS\n// =============================================================================\n\n/**\n * Defines a complete extension. Currently an identity function that provides\n * type-checking and IDE autocompletion for the definition shape.\n *\n * @param def - The extension definition.\n * @returns The same definition, validated at the type level.\n */\nexport function defineExtension(def: ExtensionDefinition): ExtensionDefinition {\n return def;\n}\n\n/**\n * Defines a custom type registration. Currently an identity function that\n * provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom type registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineCustomType(reg: CustomTypeRegistration): CustomTypeRegistration {\n return reg;\n}\n\n/**\n * Defines a custom constraint registration. Currently an identity function\n * that provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom constraint registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineConstraint(reg: CustomConstraintRegistration): CustomConstraintRegistration {\n return reg;\n}\n\n/**\n * Defines a custom annotation registration. Currently an identity function\n * that provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom annotation registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineAnnotation(reg: CustomAnnotationRegistration): CustomAnnotationRegistration {\n return reg;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC+BO,SAAS,wBAA2B,OAAyB;AAClE,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,IACP,SAAS;AAAA,IACT,UAAU;AAAA,IACV,QAAQ,CAAC;AAAA,EACX;AACF;;;AC1BO,IAAM,iCAAiC;AAAA,EAC5C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,SAAS;AAAA,EACT,aAAa;AACf;;;ACDO,IAAM,aAAa;;;ACsHnB,SAAS,gBAAgB,KAA+C;AAC7E,SAAO;AACT;AASO,SAAS,iBAAiB,KAAqD;AACpF,SAAO;AACT;AASO,SAAS,iBAAiB,KAAiE;AAChG,SAAO;AACT;AASO,SAAS,iBAAiB,KAAiE;AAChG,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/types/field-state.ts","../src/types/constraint-definitions.ts","../src/types/ir.ts","../src/extensions/index.ts","../src/guards.ts"],"sourcesContent":["/**\n * `@formspec/core` - Core type definitions for FormSpec\n *\n * This package provides the foundational types used throughout the FormSpec ecosystem:\n * - Form element types (fields, groups, conditionals)\n * - Field and form state types\n * - Data source registry for dynamic enums\n * - Canonical IR types (FormIR, FieldNode, TypeNode, ConstraintNode, AnnotationNode, etc.)\n *\n * @packageDocumentation\n */\n\n// Re-export all types\nexport type {\n // Validity\n Validity,\n\n // Field state\n FieldState,\n\n // Form state\n FormState,\n\n // Data sources\n DataSourceRegistry,\n DataSourceOption,\n FetchOptionsResponse,\n DataSourceValueType,\n\n // Elements\n TextField,\n NumberField,\n BooleanField,\n EnumOption,\n EnumOptionValue,\n StaticEnumField,\n DynamicEnumField,\n DynamicSchemaField,\n ArrayField,\n ObjectField,\n AnyField,\n Group,\n Conditional,\n FormElement,\n FormSpec,\n\n // Predicates\n EqualsPredicate,\n Predicate,\n\n // Built-in constraints\n BuiltinConstraintName,\n\n // Canonical IR\n JsonValue,\n Provenance,\n PathTarget,\n TypeNode,\n PrimitiveTypeNode,\n EnumMember,\n EnumTypeNode,\n ArrayTypeNode,\n ObjectProperty,\n ObjectTypeNode,\n UnionTypeNode,\n ReferenceTypeNode,\n DynamicTypeNode,\n CustomTypeNode,\n ConstraintNode,\n NumericConstraintNode,\n LengthConstraintNode,\n PatternConstraintNode,\n ArrayCardinalityConstraintNode,\n EnumMemberConstraintNode,\n CustomConstraintNode,\n AnnotationNode,\n DisplayNameAnnotationNode,\n DescriptionAnnotationNode,\n PlaceholderAnnotationNode,\n DefaultValueAnnotationNode,\n DeprecatedAnnotationNode,\n FormatHintAnnotationNode,\n CustomAnnotationNode,\n FieldNode,\n LayoutNode,\n GroupLayoutNode,\n ConditionalLayoutNode,\n FormIRElement,\n TypeDefinition,\n FormIR,\n} from \"./types/index.js\";\n\n// Re-export functions and constants\nexport {\n createInitialFieldState,\n BUILTIN_CONSTRAINT_DEFINITIONS,\n normalizeConstraintTagName,\n isBuiltinConstraintName,\n IR_VERSION,\n} from \"./types/index.js\";\n\n// Extension API\nexport type {\n ExtensionDefinition,\n CustomTypeRegistration,\n CustomConstraintRegistration,\n CustomAnnotationRegistration,\n VocabularyKeywordRegistration,\n} from \"./extensions/index.js\";\n\nexport {\n defineExtension,\n defineCustomType,\n defineConstraint,\n defineAnnotation,\n} from \"./extensions/index.js\";\n\n// Re-export type guards\nexport {\n isField,\n isTextField,\n isNumberField,\n isBooleanField,\n isStaticEnumField,\n isDynamicEnumField,\n isDynamicSchemaField,\n isArrayField,\n isObjectField,\n isGroup,\n isConditional,\n} from \"./guards.js\";\n","import type { Validity } from \"./validity.js\";\n\n/**\n * Represents the runtime state of a single form field.\n *\n * @typeParam T - The value type of the field\n */\nexport interface FieldState<T> {\n /** Current value of the field */\n readonly value: T;\n\n /** Whether the field has been modified by the user */\n readonly dirty: boolean;\n\n /** Whether the field has been focused and blurred */\n readonly touched: boolean;\n\n /** Current validity state */\n readonly validity: Validity;\n\n /** Validation error messages, if any */\n readonly errors: readonly string[];\n}\n\n/**\n * Creates initial field state with default values.\n *\n * @typeParam T - The value type of the field\n * @param value - The initial value for the field\n * @returns Initial field state\n */\nexport function createInitialFieldState<T>(value: T): FieldState<T> {\n return {\n value,\n dirty: false,\n touched: false,\n validity: \"unknown\",\n errors: [],\n };\n}\n","/**\n * Built-in constraint definitions for FormSpec constraint validation.\n *\n * This is the single source of truth for which constraints FormSpec\n * recognizes. Both `@formspec/build` (schema generation)\n * and `@formspec/eslint-plugin` (lint-time validation) import from here.\n */\n\n/**\n * Built-in constraint names mapped to their expected value type for parsing.\n * Constraints are surface-agnostic — they manifest as both TSDoc tags\n * (e.g., `@minimum 0`) and chain DSL options (e.g., `{ minimum: 0 }`).\n *\n * Keys use camelCase matching JSON Schema property names.\n */\nexport const BUILTIN_CONSTRAINT_DEFINITIONS = {\n minimum: \"number\",\n maximum: \"number\",\n exclusiveMinimum: \"number\",\n exclusiveMaximum: \"number\",\n multipleOf: \"number\",\n minLength: \"number\",\n maxLength: \"number\",\n minItems: \"number\",\n maxItems: \"number\",\n pattern: \"string\",\n enumOptions: \"json\",\n} as const;\n\n/** Type of a built-in constraint name. */\nexport type BuiltinConstraintName = keyof typeof BUILTIN_CONSTRAINT_DEFINITIONS;\n\n/**\n * Normalizes a constraint tag name from PascalCase to camelCase.\n *\n * Lowercases the first character so that e.g. `\"Minimum\"` becomes `\"minimum\"`.\n * Callers must strip the `@` prefix before calling this function.\n *\n * @example\n * normalizeConstraintTagName(\"Minimum\") // \"minimum\"\n * normalizeConstraintTagName(\"MinLength\") // \"minLength\"\n * normalizeConstraintTagName(\"minimum\") // \"minimum\" (idempotent)\n */\nexport function normalizeConstraintTagName(tagName: string): string {\n return tagName.charAt(0).toLowerCase() + tagName.slice(1);\n}\n\n/**\n * Type guard: checks whether a tag name is a known built-in constraint.\n *\n * Uses `Object.hasOwn()` rather than `in` to prevent prototype-chain\n * matches on names like `\"toString\"` or `\"constructor\"`.\n *\n * Callers should normalize with {@link normalizeConstraintTagName} first\n * if the input may be PascalCase.\n */\nexport function isBuiltinConstraintName(tagName: string): tagName is BuiltinConstraintName {\n return Object.hasOwn(BUILTIN_CONSTRAINT_DEFINITIONS, tagName);\n}\n","/**\n * Canonical Intermediate Representation (IR) types for FormSpec.\n *\n * The IR is the shared intermediate structure that both authoring surfaces\n * (chain DSL and TSDoc-annotated types) compile to. All downstream operations\n * — JSON Schema generation, UI Schema generation, constraint validation,\n * diagnostics — consume the IR exclusively.\n *\n * All types are plain, serializable objects (no live compiler references).\n *\n * @see {@link https://github.com/stripe/formspec-workspace/blob/main/scratch/design/001-canonical-ir.md}\n */\n\n// =============================================================================\n// IR VERSION\n// =============================================================================\n\n/**\n * The current IR format version. Centralized here so all canonicalizers\n * and consumers reference a single source of truth.\n */\nexport const IR_VERSION = \"0.1.0\" as const;\n\n// =============================================================================\n// UTILITY TYPES\n// =============================================================================\n\n/**\n * A JSON-serializable value. All IR nodes must be representable as JSON.\n */\nexport type JsonValue =\n | null\n | boolean\n | number\n | string\n | readonly JsonValue[]\n | { readonly [key: string]: JsonValue };\n\n// =============================================================================\n// PROVENANCE\n// =============================================================================\n\n/**\n * Describes the origin of an IR node.\n * Enables diagnostics that point to the source of a contradiction or error.\n */\nexport interface Provenance {\n /** The authoring surface that produced this node. */\n readonly surface: \"tsdoc\" | \"chain-dsl\" | \"extension\" | \"inferred\";\n /** Absolute path to the source file. */\n readonly file: string;\n /** 1-based line number in the source file. */\n readonly line: number;\n /** 0-based column number in the source file. */\n readonly column: number;\n /** Length of the source span in characters (for IDE underline ranges). */\n readonly length?: number;\n /**\n * The specific tag, call, or construct that produced this node.\n * Examples: `@minimum`, `field.number({ min: 0 })`, `optional`\n */\n readonly tagName?: string;\n}\n\n// =============================================================================\n// PATH TARGET\n// =============================================================================\n\n/**\n * A path targeting a sub-field within a complex type.\n * Used by constraints and annotations to target nested properties.\n */\nexport interface PathTarget {\n /**\n * Sequence of property names forming a path from the annotated field's type\n * to the target sub-field.\n * e.g., `[\"value\"]` or `[\"address\", \"zip\"]`\n */\n readonly segments: readonly string[];\n}\n\n// =============================================================================\n// TYPE NODES\n// =============================================================================\n\n/**\n * Discriminated union of all type representations in the IR.\n */\nexport type TypeNode =\n | PrimitiveTypeNode\n | EnumTypeNode\n | ArrayTypeNode\n | ObjectTypeNode\n | UnionTypeNode\n | ReferenceTypeNode\n | DynamicTypeNode\n | CustomTypeNode;\n\n/**\n * Primitive types mapping directly to JSON Schema primitives.\n *\n * Note: integer is NOT a primitive kind — integer semantics are expressed\n * via a `multipleOf: 1` constraint on a number type.\n */\nexport interface PrimitiveTypeNode {\n readonly kind: \"primitive\";\n readonly primitiveKind: \"string\" | \"number\" | \"boolean\" | \"null\";\n}\n\n/** A member of a static enum type. */\nexport interface EnumMember {\n /** The serialized value stored in data. */\n readonly value: string | number;\n /** Optional per-member display name. */\n readonly displayName?: string;\n}\n\n/** Static enum type — members known at build time. */\nexport interface EnumTypeNode {\n readonly kind: \"enum\";\n readonly members: readonly EnumMember[];\n}\n\n/** Array type with a single items type. */\nexport interface ArrayTypeNode {\n readonly kind: \"array\";\n readonly items: TypeNode;\n}\n\n/** A named property within an object type. */\nexport interface ObjectProperty {\n readonly name: string;\n readonly type: TypeNode;\n readonly optional: boolean;\n /**\n * Use-site constraints on this property.\n * Distinct from constraints on the property's type — these are\n * use-site constraints (e.g., `@minimum :amount 0` targets the\n * `amount` property of a `MonetaryAmount` field).\n */\n readonly constraints: readonly ConstraintNode[];\n /** Use-site annotations on this property. */\n readonly annotations: readonly AnnotationNode[];\n readonly provenance: Provenance;\n}\n\n/** Object type with named properties. */\nexport interface ObjectTypeNode {\n readonly kind: \"object\";\n /**\n * Named properties of this object. Order is preserved from the source\n * declaration for deterministic output.\n */\n readonly properties: readonly ObjectProperty[];\n /**\n * Whether additional properties beyond those listed are permitted.\n * Defaults to false — object types in FormSpec are closed.\n */\n readonly additionalProperties: boolean;\n}\n\n/** Union type for non-enum unions. Nullable types are `T | null` using this. */\nexport interface UnionTypeNode {\n readonly kind: \"union\";\n readonly members: readonly TypeNode[];\n}\n\n/** Named type reference — preserved as references for `$defs`/`$ref` emission. */\nexport interface ReferenceTypeNode {\n readonly kind: \"reference\";\n /**\n * The fully-qualified name of the referenced type.\n * For TypeScript interfaces/type aliases: `\"<module>#<TypeName>\"`.\n * For built-in types: the primitive kind string.\n */\n readonly name: string;\n /**\n * Type arguments if this is a generic instantiation.\n * e.g., `Array<string>` → `{ name: \"Array\", typeArguments: [PrimitiveTypeNode(\"string\")] }`\n */\n readonly typeArguments: readonly TypeNode[];\n}\n\n/** Dynamic type — schema resolved at runtime from a named data source. */\nexport interface DynamicTypeNode {\n readonly kind: \"dynamic\";\n readonly dynamicKind: \"enum\" | \"schema\";\n /** Key identifying the runtime data source or schema provider. */\n readonly sourceKey: string;\n /**\n * For dynamic enums: field names whose current values are passed as\n * parameters to the data source resolver.\n */\n readonly parameterFields: readonly string[];\n}\n\n/** Custom type registered by an extension. */\nexport interface CustomTypeNode {\n readonly kind: \"custom\";\n /**\n * The extension-qualified type identifier.\n * Format: `\"<vendor-prefix>/<extension-name>/<type-name>\"`\n * e.g., `\"x-stripe/monetary/MonetaryAmount\"`\n */\n readonly typeId: string;\n /**\n * Opaque payload serialized by the extension that registered this type.\n * Must be JSON-serializable.\n */\n readonly payload: JsonValue;\n}\n\n// =============================================================================\n// CONSTRAINT NODES\n// =============================================================================\n\n/**\n * Discriminated union of all constraint types.\n * Constraints are set-influencing: they narrow the set of valid values.\n */\nexport type ConstraintNode =\n | NumericConstraintNode\n | LengthConstraintNode\n | PatternConstraintNode\n | ArrayCardinalityConstraintNode\n | EnumMemberConstraintNode\n | CustomConstraintNode;\n\n/**\n * Numeric constraints: bounds and multipleOf.\n *\n * `minimum` and `maximum` are inclusive; `exclusiveMinimum` and\n * `exclusiveMaximum` are exclusive bounds (matching JSON Schema 2020-12\n * semantics).\n *\n * Type applicability: may only attach to fields with `PrimitiveTypeNode(\"number\")`\n * or a `ReferenceTypeNode` that resolves to one.\n */\nexport interface NumericConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind:\n | \"minimum\"\n | \"maximum\"\n | \"exclusiveMinimum\"\n | \"exclusiveMaximum\"\n | \"multipleOf\";\n readonly value: number;\n /** If present, targets a nested sub-field rather than the field itself. */\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/**\n * String length and array item count constraints.\n *\n * `minLength`/`maxLength` apply to strings; `minItems`/`maxItems` apply to\n * arrays. They share the same node shape because the composition rules are\n * identical.\n *\n * Type applicability: `minLength`/`maxLength` require `PrimitiveTypeNode(\"string\")`;\n * `minItems`/`maxItems` require `ArrayTypeNode`.\n */\nexport interface LengthConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"minLength\" | \"maxLength\" | \"minItems\" | \"maxItems\";\n readonly value: number;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/**\n * String pattern constraint (ECMA-262 regex without delimiters).\n *\n * Multiple `pattern` constraints on the same field compose via intersection:\n * all patterns must match simultaneously.\n *\n * Type applicability: requires `PrimitiveTypeNode(\"string\")`.\n */\nexport interface PatternConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"pattern\";\n /** ECMA-262 regular expression, without delimiters. */\n readonly pattern: string;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Array uniqueness constraint. */\nexport interface ArrayCardinalityConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"uniqueItems\";\n readonly value: true;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Enum member subset constraint (refinement — only narrows). */\nexport interface EnumMemberConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"allowedMembers\";\n readonly members: readonly (string | number)[];\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Extension-registered custom constraint. */\nexport interface CustomConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"custom\";\n /** Extension-qualified ID: `\"<vendor-prefix>/<extension-name>/<constraint-name>\"` */\n readonly constraintId: string;\n /** JSON-serializable payload defined by the extension. */\n readonly payload: JsonValue;\n /** How this constraint composes with others of the same `constraintId`. */\n readonly compositionRule: \"intersect\" | \"override\";\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// ANNOTATION NODES\n// =============================================================================\n\n/**\n * Discriminated union of all annotation types.\n * Annotations are value-influencing: they describe or present a field\n * but do not affect which values are valid.\n */\nexport type AnnotationNode =\n | DisplayNameAnnotationNode\n | DescriptionAnnotationNode\n | PlaceholderAnnotationNode\n | DefaultValueAnnotationNode\n | DeprecatedAnnotationNode\n | FormatHintAnnotationNode\n | CustomAnnotationNode;\n\nexport interface DisplayNameAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"displayName\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface DescriptionAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"description\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface PlaceholderAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"placeholder\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface DefaultValueAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"defaultValue\";\n /** Must be JSON-serializable and type-compatible (verified during Validate phase). */\n readonly value: JsonValue;\n readonly provenance: Provenance;\n}\n\nexport interface DeprecatedAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"deprecated\";\n /** Optional deprecation message. */\n readonly message?: string;\n readonly provenance: Provenance;\n}\n\n/** UI rendering hint — does not affect schema validation. */\nexport interface FormatHintAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"formatHint\";\n /** Renderer-specific format identifier: \"textarea\", \"radio\", \"date\", \"color\", etc. */\n readonly format: string;\n readonly provenance: Provenance;\n}\n\n/** Extension-registered custom annotation. */\nexport interface CustomAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"custom\";\n /** Extension-qualified ID: `\"<vendor-prefix>/<extension-name>/<annotation-name>\"` */\n readonly annotationId: string;\n readonly value: JsonValue;\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// FIELD NODE\n// =============================================================================\n\n/** A single form field after canonicalization. */\nexport interface FieldNode {\n readonly kind: \"field\";\n /** The field's key in the data schema. */\n readonly name: string;\n /** The resolved type of this field. */\n readonly type: TypeNode;\n /** Whether this field is required in the data schema. */\n readonly required: boolean;\n /** Set-influencing constraints, after merging. */\n readonly constraints: readonly ConstraintNode[];\n /** Value-influencing annotations, after merging. */\n readonly annotations: readonly AnnotationNode[];\n /** Where this field was declared. */\n readonly provenance: Provenance;\n /**\n * Debug only — ordered list of constraint/annotation nodes that participated\n * in merging, including dominated ones.\n */\n readonly mergeHistory?: readonly {\n readonly node: ConstraintNode | AnnotationNode;\n readonly dominated: boolean;\n }[];\n}\n\n// =============================================================================\n// LAYOUT NODES\n// =============================================================================\n\n/** Union of layout node types. */\nexport type LayoutNode = GroupLayoutNode | ConditionalLayoutNode;\n\n/** A visual grouping of form elements. */\nexport interface GroupLayoutNode {\n readonly kind: \"group\";\n readonly label: string;\n /** Elements contained in this group — may be fields or nested groups. */\n readonly elements: readonly FormIRElement[];\n readonly provenance: Provenance;\n}\n\n/** Conditional visibility based on another field's value. */\nexport interface ConditionalLayoutNode {\n readonly kind: \"conditional\";\n /** The field whose value triggers visibility. */\n readonly fieldName: string;\n /** The value that makes the condition true (SHOW). */\n readonly value: JsonValue;\n /** Elements shown when the condition is met. */\n readonly elements: readonly FormIRElement[];\n readonly provenance: Provenance;\n}\n\n/** Union of all IR element types. */\nexport type FormIRElement = FieldNode | LayoutNode;\n\n// =============================================================================\n// TYPE REGISTRY\n// =============================================================================\n\n/** A named type definition stored in the type registry. */\nexport interface TypeDefinition {\n /** The fully-qualified reference name (key in the registry). */\n readonly name: string;\n /** The resolved type node. */\n readonly type: TypeNode;\n /** Where this type was declared. */\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// FORM IR (TOP-LEVEL)\n// =============================================================================\n\n/**\n * The complete Canonical Intermediate Representation for a form.\n *\n * Output of the Canonicalize phase; input to Validate, Generate (JSON Schema),\n * and Generate (UI Schema) phases.\n *\n * Serializable to JSON — no live compiler objects.\n */\nexport interface FormIR {\n readonly kind: \"form-ir\";\n /**\n * Schema version for the IR format itself.\n * Should equal `IR_VERSION`.\n */\n readonly irVersion: string;\n /** Top-level elements of the form: fields and layout nodes. */\n readonly elements: readonly FormIRElement[];\n /**\n * Registry of named types referenced by fields in this form.\n * Keys are fully-qualified type names matching `ReferenceTypeNode.name`.\n */\n readonly typeRegistry: Readonly<Record<string, TypeDefinition>>;\n /** Provenance of the form definition itself. */\n readonly provenance: Provenance;\n}\n","/**\n * Extension API for registering custom types, constraints, annotations,\n * and vocabulary keywords with FormSpec.\n *\n * Extensions allow third-party packages (e.g., \"Decimal\", \"DateOnly\") to\n * plug into the FormSpec pipeline. The types and factory functions defined\n * here are consumed by the FormSpec build pipeline.\n *\n * @packageDocumentation\n */\n\nimport type { JsonValue, TypeNode } from \"../types/ir.js\";\n\n// =============================================================================\n// REGISTRATION TYPES\n// =============================================================================\n\n/**\n * Registration for a custom type that maps to a JSON Schema representation.\n *\n * Custom types are referenced via {@link CustomTypeNode} in the IR and\n * resolved to JSON Schema via `toJsonSchema` during generation.\n */\nexport interface CustomTypeRegistration {\n /** The type name, unique within the extension. */\n readonly typeName: string;\n /**\n * Converts the custom type's payload into a JSON Schema fragment.\n *\n * @param payload - The opaque JSON payload from the {@link CustomTypeNode}.\n * @param vendorPrefix - The vendor prefix for extension keywords (e.g., \"x-stripe\").\n * @returns A JSON Schema fragment representing this type.\n */\n readonly toJsonSchema: (payload: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a custom constraint that maps to JSON Schema keywords.\n *\n * Custom constraints are referenced via {@link CustomConstraintNode} in the IR.\n */\nexport interface CustomConstraintRegistration {\n /** The constraint name, unique within the extension. */\n readonly constraintName: string;\n /**\n * How this constraint composes with other constraints of the same kind.\n * - \"intersect\": combine with logical AND (both must hold)\n * - \"override\": last writer wins\n */\n readonly compositionRule: \"intersect\" | \"override\";\n /**\n * TypeNode kinds this constraint is applicable to, or `null` for any type.\n * Used by the validator to emit TYPE_MISMATCH diagnostics.\n */\n readonly applicableTypes: readonly TypeNode[\"kind\"][] | null;\n /**\n * Converts the custom constraint's payload into JSON Schema keywords.\n *\n * @param payload - The opaque JSON payload from the {@link CustomConstraintNode}.\n * @param vendorPrefix - The vendor prefix for extension keywords.\n * @returns A JSON Schema fragment with the constraint keywords.\n */\n readonly toJsonSchema: (payload: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a custom annotation that may produce JSON Schema keywords.\n *\n * Custom annotations are referenced via {@link CustomAnnotationNode} in the IR.\n * They describe or present a field but do not affect which values are valid.\n */\nexport interface CustomAnnotationRegistration {\n /** The annotation name, unique within the extension. */\n readonly annotationName: string;\n /**\n * Optionally converts the annotation value into JSON Schema keywords.\n * If omitted, the annotation has no JSON Schema representation (UI-only).\n */\n readonly toJsonSchema?: (value: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a vocabulary keyword to include in a JSON Schema `$vocabulary` declaration.\n */\nexport interface VocabularyKeywordRegistration {\n /** The keyword name (without vendor prefix). */\n readonly keyword: string;\n /** JSON Schema that describes the valid values for this keyword. */\n readonly schema: JsonValue;\n}\n\n// =============================================================================\n// EXTENSION DEFINITION\n// =============================================================================\n\n/**\n * A complete extension definition bundling types, constraints, annotations,\n * and vocabulary keywords.\n *\n * @example\n * ```typescript\n * const monetaryExtension = defineExtension({\n * extensionId: \"x-stripe/monetary\",\n * types: [\n * defineCustomType({\n * typeName: \"Decimal\",\n * toJsonSchema: (_payload, prefix) => ({\n * type: \"string\",\n * [`${prefix}-decimal`]: true,\n * }),\n * }),\n * ],\n * });\n * ```\n */\nexport interface ExtensionDefinition {\n /** Globally unique extension identifier, e.g., \"x-stripe/monetary\". */\n readonly extensionId: string;\n /** Custom type registrations provided by this extension. */\n readonly types?: readonly CustomTypeRegistration[];\n /** Custom constraint registrations provided by this extension. */\n readonly constraints?: readonly CustomConstraintRegistration[];\n /** Custom annotation registrations provided by this extension. */\n readonly annotations?: readonly CustomAnnotationRegistration[];\n /** Vocabulary keyword registrations provided by this extension. */\n readonly vocabularyKeywords?: readonly VocabularyKeywordRegistration[];\n}\n\n// =============================================================================\n// FACTORY FUNCTIONS\n// =============================================================================\n\n/**\n * Defines a complete extension. Currently an identity function that provides\n * type-checking and IDE autocompletion for the definition shape.\n *\n * @param def - The extension definition.\n * @returns The same definition, validated at the type level.\n */\nexport function defineExtension(def: ExtensionDefinition): ExtensionDefinition {\n return def;\n}\n\n/**\n * Defines a custom type registration. Currently an identity function that\n * provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom type registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineCustomType(reg: CustomTypeRegistration): CustomTypeRegistration {\n return reg;\n}\n\n/**\n * Defines a custom constraint registration. Currently an identity function\n * that provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom constraint registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineConstraint(reg: CustomConstraintRegistration): CustomConstraintRegistration {\n return reg;\n}\n\n/**\n * Defines a custom annotation registration. Currently an identity function\n * that provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom annotation registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineAnnotation(reg: CustomAnnotationRegistration): CustomAnnotationRegistration {\n return reg;\n}\n","/**\n * Type guards for FormSpec form elements.\n *\n * Each guard narrows a {@link FormElement} to a specific field, group, or conditional type.\n */\n\nimport type {\n FormElement,\n AnyField,\n TextField,\n NumberField,\n BooleanField,\n StaticEnumField,\n DynamicEnumField,\n DynamicSchemaField,\n ArrayField,\n ObjectField,\n Group,\n Conditional,\n EnumOptionValue,\n} from \"./types/elements.js\";\n\n/** Narrows a FormElement to any field type. */\nexport function isField(element: FormElement): element is AnyField {\n return element._type === \"field\";\n}\n\n/** Narrows a FormElement to a text input field. */\nexport function isTextField(element: FormElement): element is TextField<string> {\n return element._type === \"field\" && element._field === \"text\";\n}\n\n/** Narrows a FormElement to a numeric input field. */\nexport function isNumberField(element: FormElement): element is NumberField<string> {\n return element._type === \"field\" && element._field === \"number\";\n}\n\n/** Narrows a FormElement to a boolean checkbox field. */\nexport function isBooleanField(element: FormElement): element is BooleanField<string> {\n return element._type === \"field\" && element._field === \"boolean\";\n}\n\n/** Narrows a FormElement to a static enum field. */\nexport function isStaticEnumField(\n element: FormElement\n): element is StaticEnumField<string, readonly EnumOptionValue[]> {\n return element._type === \"field\" && element._field === \"enum\";\n}\n\n/** Narrows a FormElement to a dynamic enum field. */\nexport function isDynamicEnumField(\n element: FormElement\n): element is DynamicEnumField<string, string> {\n return element._type === \"field\" && element._field === \"dynamic_enum\";\n}\n\n/** Narrows a FormElement to a dynamic schema field. */\nexport function isDynamicSchemaField(element: FormElement): element is DynamicSchemaField<string> {\n return element._type === \"field\" && element._field === \"dynamic_schema\";\n}\n\n/** Narrows a FormElement to an array field. */\nexport function isArrayField(\n element: FormElement\n): element is ArrayField<string, readonly FormElement[]> {\n return element._type === \"field\" && element._field === \"array\";\n}\n\n/** Narrows a FormElement to an object field. */\nexport function isObjectField(\n element: FormElement\n): element is ObjectField<string, readonly FormElement[]> {\n return element._type === \"field\" && element._field === \"object\";\n}\n\n/** Narrows a FormElement to a visual group. */\nexport function isGroup(element: FormElement): element is Group<readonly FormElement[]> {\n return element._type === \"group\";\n}\n\n/** Narrows a FormElement to a conditional wrapper. */\nexport function isConditional(\n element: FormElement\n): element is Conditional<string, unknown, readonly FormElement[]> {\n return element._type === \"conditional\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC+BO,SAAS,wBAA2B,OAAyB;AAClE,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,IACP,SAAS;AAAA,IACT,UAAU;AAAA,IACV,QAAQ,CAAC;AAAA,EACX;AACF;;;ACxBO,IAAM,iCAAiC;AAAA,EAC5C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa;AACf;AAgBO,SAAS,2BAA2B,SAAyB;AAClE,SAAO,QAAQ,OAAO,CAAC,EAAE,YAAY,IAAI,QAAQ,MAAM,CAAC;AAC1D;AAWO,SAAS,wBAAwB,SAAmD;AACzF,SAAO,OAAO,OAAO,gCAAgC,OAAO;AAC9D;;;ACrCO,IAAM,aAAa;;;ACsHnB,SAAS,gBAAgB,KAA+C;AAC7E,SAAO;AACT;AASO,SAAS,iBAAiB,KAAqD;AACpF,SAAO;AACT;AASO,SAAS,iBAAiB,KAAiE;AAChG,SAAO;AACT;AASO,SAAS,iBAAiB,KAAiE;AAChG,SAAO;AACT;;;ACvJO,SAAS,QAAQ,SAA2C;AACjE,SAAO,QAAQ,UAAU;AAC3B;AAGO,SAAS,YAAY,SAAoD;AAC9E,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,cAAc,SAAsD;AAClF,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,eAAe,SAAuD;AACpF,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,kBACd,SACgE;AAChE,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,mBACd,SAC6C;AAC7C,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,qBAAqB,SAA6D;AAChG,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,aACd,SACuD;AACvD,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,cACd,SACwD;AACxD,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,QAAQ,SAAgE;AACtF,SAAO,QAAQ,UAAU;AAC3B;AAGO,SAAS,cACd,SACiE;AACjE,SAAO,QAAQ,UAAU;AAC3B;","names":[]}
package/dist/index.d.ts CHANGED
@@ -10,7 +10,8 @@
10
10
  * @packageDocumentation
11
11
  */
12
12
  export type { Validity, FieldState, FormState, DataSourceRegistry, DataSourceOption, FetchOptionsResponse, DataSourceValueType, TextField, NumberField, BooleanField, EnumOption, EnumOptionValue, StaticEnumField, DynamicEnumField, DynamicSchemaField, ArrayField, ObjectField, AnyField, Group, Conditional, FormElement, FormSpec, EqualsPredicate, Predicate, BuiltinConstraintName, JsonValue, Provenance, PathTarget, TypeNode, PrimitiveTypeNode, EnumMember, EnumTypeNode, ArrayTypeNode, ObjectProperty, ObjectTypeNode, UnionTypeNode, ReferenceTypeNode, DynamicTypeNode, CustomTypeNode, ConstraintNode, NumericConstraintNode, LengthConstraintNode, PatternConstraintNode, ArrayCardinalityConstraintNode, EnumMemberConstraintNode, CustomConstraintNode, AnnotationNode, DisplayNameAnnotationNode, DescriptionAnnotationNode, PlaceholderAnnotationNode, DefaultValueAnnotationNode, DeprecatedAnnotationNode, FormatHintAnnotationNode, CustomAnnotationNode, FieldNode, LayoutNode, GroupLayoutNode, ConditionalLayoutNode, FormIRElement, TypeDefinition, FormIR, } from "./types/index.js";
13
- export { createInitialFieldState, BUILTIN_CONSTRAINT_DEFINITIONS, IR_VERSION, } from "./types/index.js";
13
+ export { createInitialFieldState, BUILTIN_CONSTRAINT_DEFINITIONS, normalizeConstraintTagName, isBuiltinConstraintName, IR_VERSION, } from "./types/index.js";
14
14
  export type { ExtensionDefinition, CustomTypeRegistration, CustomConstraintRegistration, CustomAnnotationRegistration, VocabularyKeywordRegistration, } from "./extensions/index.js";
15
15
  export { defineExtension, defineCustomType, defineConstraint, defineAnnotation, } from "./extensions/index.js";
16
+ export { isField, isTextField, isNumberField, isBooleanField, isStaticEnumField, isDynamicEnumField, isDynamicSchemaField, isArrayField, isObjectField, isGroup, isConditional, } from "./guards.js";
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,YAAY,EAEV,QAAQ,EAGR,UAAU,EAGV,SAAS,EAGT,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EAGnB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EAGR,eAAe,EACf,SAAS,EAGT,qBAAqB,EAGrB,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,MAAM,GACP,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,uBAAuB,EACvB,8BAA8B,EAC9B,UAAU,GACX,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EACV,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,YAAY,EAEV,QAAQ,EAGR,UAAU,EAGV,SAAS,EAGT,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EAGnB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EAGR,eAAe,EACf,SAAS,EAGT,qBAAqB,EAGrB,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,MAAM,GACP,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,uBAAuB,EACvB,8BAA8B,EAC9B,0BAA0B,EAC1B,uBAAuB,EACvB,UAAU,GACX,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EACV,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,OAAO,EACP,WAAW,EACX,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,OAAO,EACP,aAAa,GACd,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -11,15 +11,24 @@ function createInitialFieldState(value) {
11
11
 
12
12
  // src/types/constraint-definitions.ts
13
13
  var BUILTIN_CONSTRAINT_DEFINITIONS = {
14
- Minimum: "number",
15
- Maximum: "number",
16
- ExclusiveMinimum: "number",
17
- ExclusiveMaximum: "number",
18
- MinLength: "number",
19
- MaxLength: "number",
20
- Pattern: "string",
21
- EnumOptions: "json"
14
+ minimum: "number",
15
+ maximum: "number",
16
+ exclusiveMinimum: "number",
17
+ exclusiveMaximum: "number",
18
+ multipleOf: "number",
19
+ minLength: "number",
20
+ maxLength: "number",
21
+ minItems: "number",
22
+ maxItems: "number",
23
+ pattern: "string",
24
+ enumOptions: "json"
22
25
  };
26
+ function normalizeConstraintTagName(tagName) {
27
+ return tagName.charAt(0).toLowerCase() + tagName.slice(1);
28
+ }
29
+ function isBuiltinConstraintName(tagName) {
30
+ return Object.hasOwn(BUILTIN_CONSTRAINT_DEFINITIONS, tagName);
31
+ }
23
32
 
24
33
  // src/types/ir.ts
25
34
  var IR_VERSION = "0.1.0";
@@ -37,6 +46,41 @@ function defineConstraint(reg) {
37
46
  function defineAnnotation(reg) {
38
47
  return reg;
39
48
  }
49
+
50
+ // src/guards.ts
51
+ function isField(element) {
52
+ return element._type === "field";
53
+ }
54
+ function isTextField(element) {
55
+ return element._type === "field" && element._field === "text";
56
+ }
57
+ function isNumberField(element) {
58
+ return element._type === "field" && element._field === "number";
59
+ }
60
+ function isBooleanField(element) {
61
+ return element._type === "field" && element._field === "boolean";
62
+ }
63
+ function isStaticEnumField(element) {
64
+ return element._type === "field" && element._field === "enum";
65
+ }
66
+ function isDynamicEnumField(element) {
67
+ return element._type === "field" && element._field === "dynamic_enum";
68
+ }
69
+ function isDynamicSchemaField(element) {
70
+ return element._type === "field" && element._field === "dynamic_schema";
71
+ }
72
+ function isArrayField(element) {
73
+ return element._type === "field" && element._field === "array";
74
+ }
75
+ function isObjectField(element) {
76
+ return element._type === "field" && element._field === "object";
77
+ }
78
+ function isGroup(element) {
79
+ return element._type === "group";
80
+ }
81
+ function isConditional(element) {
82
+ return element._type === "conditional";
83
+ }
40
84
  export {
41
85
  BUILTIN_CONSTRAINT_DEFINITIONS,
42
86
  IR_VERSION,
@@ -44,6 +88,19 @@ export {
44
88
  defineAnnotation,
45
89
  defineConstraint,
46
90
  defineCustomType,
47
- defineExtension
91
+ defineExtension,
92
+ isArrayField,
93
+ isBooleanField,
94
+ isBuiltinConstraintName,
95
+ isConditional,
96
+ isDynamicEnumField,
97
+ isDynamicSchemaField,
98
+ isField,
99
+ isGroup,
100
+ isNumberField,
101
+ isObjectField,
102
+ isStaticEnumField,
103
+ isTextField,
104
+ normalizeConstraintTagName
48
105
  };
49
106
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types/field-state.ts","../src/types/constraint-definitions.ts","../src/types/ir.ts","../src/extensions/index.ts"],"sourcesContent":["import type { Validity } from \"./validity.js\";\n\n/**\n * Represents the runtime state of a single form field.\n *\n * @typeParam T - The value type of the field\n */\nexport interface FieldState<T> {\n /** Current value of the field */\n readonly value: T;\n\n /** Whether the field has been modified by the user */\n readonly dirty: boolean;\n\n /** Whether the field has been focused and blurred */\n readonly touched: boolean;\n\n /** Current validity state */\n readonly validity: Validity;\n\n /** Validation error messages, if any */\n readonly errors: readonly string[];\n}\n\n/**\n * Creates initial field state with default values.\n *\n * @typeParam T - The value type of the field\n * @param value - The initial value for the field\n * @returns Initial field state\n */\nexport function createInitialFieldState<T>(value: T): FieldState<T> {\n return {\n value,\n dirty: false,\n touched: false,\n validity: \"unknown\",\n errors: [],\n };\n}\n","/**\n * Built-in constraint definitions for FormSpec constraint validation.\n *\n * This is the single source of truth for which constraints FormSpec\n * recognizes. Both `@formspec/build` (schema generation)\n * and `@formspec/eslint-plugin` (lint-time validation) import from here.\n */\n\n/**\n * Built-in constraint names mapped to their expected value type for parsing.\n * Constraints are surface-agnostic — they manifest as both TSDoc tags\n * (e.g., `@Minimum 0`) and chain DSL options (e.g., `{ minimum: 0 }`).\n */\nexport const BUILTIN_CONSTRAINT_DEFINITIONS = {\n Minimum: \"number\",\n Maximum: \"number\",\n ExclusiveMinimum: \"number\",\n ExclusiveMaximum: \"number\",\n MinLength: \"number\",\n MaxLength: \"number\",\n Pattern: \"string\",\n EnumOptions: \"json\",\n} as const;\n\n/** Type of a built-in constraint name. */\nexport type BuiltinConstraintName = keyof typeof BUILTIN_CONSTRAINT_DEFINITIONS;\n","/**\n * Canonical Intermediate Representation (IR) types for FormSpec.\n *\n * The IR is the shared intermediate structure that both authoring surfaces\n * (chain DSL and TSDoc-annotated types) compile to. All downstream operations\n * — JSON Schema generation, UI Schema generation, constraint validation,\n * diagnostics — consume the IR exclusively.\n *\n * All types are plain, serializable objects (no live compiler references).\n *\n * @see {@link https://github.com/stripe/formspec-workspace/blob/main/scratch/design/001-canonical-ir.md}\n */\n\n// =============================================================================\n// IR VERSION\n// =============================================================================\n\n/**\n * The current IR format version. Centralized here so all canonicalizers\n * and consumers reference a single source of truth.\n */\nexport const IR_VERSION = \"0.1.0\" as const;\n\n// =============================================================================\n// UTILITY TYPES\n// =============================================================================\n\n/**\n * A JSON-serializable value. All IR nodes must be representable as JSON.\n */\nexport type JsonValue =\n | null\n | boolean\n | number\n | string\n | readonly JsonValue[]\n | { readonly [key: string]: JsonValue };\n\n// =============================================================================\n// PROVENANCE\n// =============================================================================\n\n/**\n * Describes the origin of an IR node.\n * Enables diagnostics that point to the source of a contradiction or error.\n */\nexport interface Provenance {\n /** The authoring surface that produced this node. */\n readonly surface: \"tsdoc\" | \"chain-dsl\" | \"extension\" | \"inferred\";\n /** Absolute path to the source file. */\n readonly file: string;\n /** 1-based line number in the source file. */\n readonly line: number;\n /** 0-based column number in the source file. */\n readonly column: number;\n /** Length of the source span in characters (for IDE underline ranges). */\n readonly length?: number;\n /**\n * The specific tag, call, or construct that produced this node.\n * Examples: `@minimum`, `field.number({ min: 0 })`, `optional`\n */\n readonly tagName?: string;\n}\n\n// =============================================================================\n// PATH TARGET\n// =============================================================================\n\n/**\n * A path targeting a sub-field within a complex type.\n * Used by constraints and annotations to target nested properties.\n */\nexport interface PathTarget {\n /**\n * Sequence of property names forming a path from the annotated field's type\n * to the target sub-field.\n * e.g., `[\"value\"]` or `[\"address\", \"zip\"]`\n */\n readonly segments: readonly string[];\n}\n\n// =============================================================================\n// TYPE NODES\n// =============================================================================\n\n/**\n * Discriminated union of all type representations in the IR.\n */\nexport type TypeNode =\n | PrimitiveTypeNode\n | EnumTypeNode\n | ArrayTypeNode\n | ObjectTypeNode\n | UnionTypeNode\n | ReferenceTypeNode\n | DynamicTypeNode\n | CustomTypeNode;\n\n/**\n * Primitive types mapping directly to JSON Schema primitives.\n *\n * Note: integer is NOT a primitive kind — integer semantics are expressed\n * via a `multipleOf: 1` constraint on a number type.\n */\nexport interface PrimitiveTypeNode {\n readonly kind: \"primitive\";\n readonly primitiveKind: \"string\" | \"number\" | \"boolean\" | \"null\";\n}\n\n/** A member of a static enum type. */\nexport interface EnumMember {\n /** The serialized value stored in data. */\n readonly value: string | number;\n /** Optional per-member display name. */\n readonly displayName?: string;\n}\n\n/** Static enum type — members known at build time. */\nexport interface EnumTypeNode {\n readonly kind: \"enum\";\n readonly members: readonly EnumMember[];\n}\n\n/** Array type with a single items type. */\nexport interface ArrayTypeNode {\n readonly kind: \"array\";\n readonly items: TypeNode;\n}\n\n/** A named property within an object type. */\nexport interface ObjectProperty {\n readonly name: string;\n readonly type: TypeNode;\n readonly optional: boolean;\n /**\n * Use-site constraints on this property.\n * Distinct from constraints on the property's type — these are\n * use-site constraints (e.g., `@minimum :amount 0` targets the\n * `amount` property of a `MonetaryAmount` field).\n */\n readonly constraints: readonly ConstraintNode[];\n /** Use-site annotations on this property. */\n readonly annotations: readonly AnnotationNode[];\n readonly provenance: Provenance;\n}\n\n/** Object type with named properties. */\nexport interface ObjectTypeNode {\n readonly kind: \"object\";\n /**\n * Named properties of this object. Order is preserved from the source\n * declaration for deterministic output.\n */\n readonly properties: readonly ObjectProperty[];\n /**\n * Whether additional properties beyond those listed are permitted.\n * Defaults to false — object types in FormSpec are closed.\n */\n readonly additionalProperties: boolean;\n}\n\n/** Union type for non-enum unions. Nullable types are `T | null` using this. */\nexport interface UnionTypeNode {\n readonly kind: \"union\";\n readonly members: readonly TypeNode[];\n}\n\n/** Named type reference — preserved as references for `$defs`/`$ref` emission. */\nexport interface ReferenceTypeNode {\n readonly kind: \"reference\";\n /**\n * The fully-qualified name of the referenced type.\n * For TypeScript interfaces/type aliases: `\"<module>#<TypeName>\"`.\n * For built-in types: the primitive kind string.\n */\n readonly name: string;\n /**\n * Type arguments if this is a generic instantiation.\n * e.g., `Array<string>` → `{ name: \"Array\", typeArguments: [PrimitiveTypeNode(\"string\")] }`\n */\n readonly typeArguments: readonly TypeNode[];\n}\n\n/** Dynamic type — schema resolved at runtime from a named data source. */\nexport interface DynamicTypeNode {\n readonly kind: \"dynamic\";\n readonly dynamicKind: \"enum\" | \"schema\";\n /** Key identifying the runtime data source or schema provider. */\n readonly sourceKey: string;\n /**\n * For dynamic enums: field names whose current values are passed as\n * parameters to the data source resolver.\n */\n readonly parameterFields: readonly string[];\n}\n\n/** Custom type registered by an extension. */\nexport interface CustomTypeNode {\n readonly kind: \"custom\";\n /**\n * The extension-qualified type identifier.\n * Format: `\"<vendor-prefix>/<extension-name>/<type-name>\"`\n * e.g., `\"x-stripe/monetary/MonetaryAmount\"`\n */\n readonly typeId: string;\n /**\n * Opaque payload serialized by the extension that registered this type.\n * Must be JSON-serializable.\n */\n readonly payload: JsonValue;\n}\n\n// =============================================================================\n// CONSTRAINT NODES\n// =============================================================================\n\n/**\n * Discriminated union of all constraint types.\n * Constraints are set-influencing: they narrow the set of valid values.\n */\nexport type ConstraintNode =\n | NumericConstraintNode\n | LengthConstraintNode\n | PatternConstraintNode\n | ArrayCardinalityConstraintNode\n | EnumMemberConstraintNode\n | CustomConstraintNode;\n\n/**\n * Numeric constraints: bounds and multipleOf.\n *\n * `minimum` and `maximum` are inclusive; `exclusiveMinimum` and\n * `exclusiveMaximum` are exclusive bounds (matching JSON Schema 2020-12\n * semantics).\n *\n * Type applicability: may only attach to fields with `PrimitiveTypeNode(\"number\")`\n * or a `ReferenceTypeNode` that resolves to one.\n */\nexport interface NumericConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind:\n | \"minimum\"\n | \"maximum\"\n | \"exclusiveMinimum\"\n | \"exclusiveMaximum\"\n | \"multipleOf\";\n readonly value: number;\n /** If present, targets a nested sub-field rather than the field itself. */\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/**\n * String length and array item count constraints.\n *\n * `minLength`/`maxLength` apply to strings; `minItems`/`maxItems` apply to\n * arrays. They share the same node shape because the composition rules are\n * identical.\n *\n * Type applicability: `minLength`/`maxLength` require `PrimitiveTypeNode(\"string\")`;\n * `minItems`/`maxItems` require `ArrayTypeNode`.\n */\nexport interface LengthConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"minLength\" | \"maxLength\" | \"minItems\" | \"maxItems\";\n readonly value: number;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/**\n * String pattern constraint (ECMA-262 regex without delimiters).\n *\n * Multiple `pattern` constraints on the same field compose via intersection:\n * all patterns must match simultaneously.\n *\n * Type applicability: requires `PrimitiveTypeNode(\"string\")`.\n */\nexport interface PatternConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"pattern\";\n /** ECMA-262 regular expression, without delimiters. */\n readonly pattern: string;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Array uniqueness constraint. */\nexport interface ArrayCardinalityConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"uniqueItems\";\n readonly value: true;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Enum member subset constraint (refinement — only narrows). */\nexport interface EnumMemberConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"allowedMembers\";\n readonly members: readonly (string | number)[];\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Extension-registered custom constraint. */\nexport interface CustomConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"custom\";\n /** Extension-qualified ID: `\"<vendor-prefix>/<extension-name>/<constraint-name>\"` */\n readonly constraintId: string;\n /** JSON-serializable payload defined by the extension. */\n readonly payload: JsonValue;\n /** How this constraint composes with others of the same `constraintId`. */\n readonly compositionRule: \"intersect\" | \"override\";\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// ANNOTATION NODES\n// =============================================================================\n\n/**\n * Discriminated union of all annotation types.\n * Annotations are value-influencing: they describe or present a field\n * but do not affect which values are valid.\n */\nexport type AnnotationNode =\n | DisplayNameAnnotationNode\n | DescriptionAnnotationNode\n | PlaceholderAnnotationNode\n | DefaultValueAnnotationNode\n | DeprecatedAnnotationNode\n | FormatHintAnnotationNode\n | CustomAnnotationNode;\n\nexport interface DisplayNameAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"displayName\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface DescriptionAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"description\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface PlaceholderAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"placeholder\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface DefaultValueAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"defaultValue\";\n /** Must be JSON-serializable and type-compatible (verified during Validate phase). */\n readonly value: JsonValue;\n readonly provenance: Provenance;\n}\n\nexport interface DeprecatedAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"deprecated\";\n /** Optional deprecation message. */\n readonly message?: string;\n readonly provenance: Provenance;\n}\n\n/** UI rendering hint — does not affect schema validation. */\nexport interface FormatHintAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"formatHint\";\n /** Renderer-specific format identifier: \"textarea\", \"radio\", \"date\", \"color\", etc. */\n readonly format: string;\n readonly provenance: Provenance;\n}\n\n/** Extension-registered custom annotation. */\nexport interface CustomAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"custom\";\n /** Extension-qualified ID: `\"<vendor-prefix>/<extension-name>/<annotation-name>\"` */\n readonly annotationId: string;\n readonly value: JsonValue;\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// FIELD NODE\n// =============================================================================\n\n/** A single form field after canonicalization. */\nexport interface FieldNode {\n readonly kind: \"field\";\n /** The field's key in the data schema. */\n readonly name: string;\n /** The resolved type of this field. */\n readonly type: TypeNode;\n /** Whether this field is required in the data schema. */\n readonly required: boolean;\n /** Set-influencing constraints, after merging. */\n readonly constraints: readonly ConstraintNode[];\n /** Value-influencing annotations, after merging. */\n readonly annotations: readonly AnnotationNode[];\n /** Where this field was declared. */\n readonly provenance: Provenance;\n /**\n * Debug only — ordered list of constraint/annotation nodes that participated\n * in merging, including dominated ones.\n */\n readonly mergeHistory?: readonly {\n readonly node: ConstraintNode | AnnotationNode;\n readonly dominated: boolean;\n }[];\n}\n\n// =============================================================================\n// LAYOUT NODES\n// =============================================================================\n\n/** Union of layout node types. */\nexport type LayoutNode = GroupLayoutNode | ConditionalLayoutNode;\n\n/** A visual grouping of form elements. */\nexport interface GroupLayoutNode {\n readonly kind: \"group\";\n readonly label: string;\n /** Elements contained in this group — may be fields or nested groups. */\n readonly elements: readonly FormIRElement[];\n readonly provenance: Provenance;\n}\n\n/** Conditional visibility based on another field's value. */\nexport interface ConditionalLayoutNode {\n readonly kind: \"conditional\";\n /** The field whose value triggers visibility. */\n readonly fieldName: string;\n /** The value that makes the condition true (SHOW). */\n readonly value: JsonValue;\n /** Elements shown when the condition is met. */\n readonly elements: readonly FormIRElement[];\n readonly provenance: Provenance;\n}\n\n/** Union of all IR element types. */\nexport type FormIRElement = FieldNode | LayoutNode;\n\n// =============================================================================\n// TYPE REGISTRY\n// =============================================================================\n\n/** A named type definition stored in the type registry. */\nexport interface TypeDefinition {\n /** The fully-qualified reference name (key in the registry). */\n readonly name: string;\n /** The resolved type node. */\n readonly type: TypeNode;\n /** Where this type was declared. */\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// FORM IR (TOP-LEVEL)\n// =============================================================================\n\n/**\n * The complete Canonical Intermediate Representation for a form.\n *\n * Output of the Canonicalize phase; input to Validate, Generate (JSON Schema),\n * and Generate (UI Schema) phases.\n *\n * Serializable to JSON — no live compiler objects.\n */\nexport interface FormIR {\n readonly kind: \"form-ir\";\n /**\n * Schema version for the IR format itself.\n * Should equal `IR_VERSION`.\n */\n readonly irVersion: string;\n /** Top-level elements of the form: fields and layout nodes. */\n readonly elements: readonly FormIRElement[];\n /**\n * Registry of named types referenced by fields in this form.\n * Keys are fully-qualified type names matching `ReferenceTypeNode.name`.\n */\n readonly typeRegistry: Readonly<Record<string, TypeDefinition>>;\n /** Provenance of the form definition itself. */\n readonly provenance: Provenance;\n}\n","/**\n * Extension API for registering custom types, constraints, annotations,\n * and vocabulary keywords with FormSpec.\n *\n * Extensions allow third-party packages (e.g., \"Decimal\", \"DateOnly\") to\n * plug into the FormSpec pipeline. The types and factory functions defined\n * here are consumed by the FormSpec build pipeline.\n *\n * @packageDocumentation\n */\n\nimport type { JsonValue, TypeNode } from \"../types/ir.js\";\n\n// =============================================================================\n// REGISTRATION TYPES\n// =============================================================================\n\n/**\n * Registration for a custom type that maps to a JSON Schema representation.\n *\n * Custom types are referenced via {@link CustomTypeNode} in the IR and\n * resolved to JSON Schema via `toJsonSchema` during generation.\n */\nexport interface CustomTypeRegistration {\n /** The type name, unique within the extension. */\n readonly typeName: string;\n /**\n * Converts the custom type's payload into a JSON Schema fragment.\n *\n * @param payload - The opaque JSON payload from the {@link CustomTypeNode}.\n * @param vendorPrefix - The vendor prefix for extension keywords (e.g., \"x-stripe\").\n * @returns A JSON Schema fragment representing this type.\n */\n readonly toJsonSchema: (payload: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a custom constraint that maps to JSON Schema keywords.\n *\n * Custom constraints are referenced via {@link CustomConstraintNode} in the IR.\n */\nexport interface CustomConstraintRegistration {\n /** The constraint name, unique within the extension. */\n readonly constraintName: string;\n /**\n * How this constraint composes with other constraints of the same kind.\n * - \"intersect\": combine with logical AND (both must hold)\n * - \"override\": last writer wins\n */\n readonly compositionRule: \"intersect\" | \"override\";\n /**\n * TypeNode kinds this constraint is applicable to, or `null` for any type.\n * Used by the validator to emit TYPE_MISMATCH diagnostics.\n */\n readonly applicableTypes: readonly TypeNode[\"kind\"][] | null;\n /**\n * Converts the custom constraint's payload into JSON Schema keywords.\n *\n * @param payload - The opaque JSON payload from the {@link CustomConstraintNode}.\n * @param vendorPrefix - The vendor prefix for extension keywords.\n * @returns A JSON Schema fragment with the constraint keywords.\n */\n readonly toJsonSchema: (payload: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a custom annotation that may produce JSON Schema keywords.\n *\n * Custom annotations are referenced via {@link CustomAnnotationNode} in the IR.\n * They describe or present a field but do not affect which values are valid.\n */\nexport interface CustomAnnotationRegistration {\n /** The annotation name, unique within the extension. */\n readonly annotationName: string;\n /**\n * Optionally converts the annotation value into JSON Schema keywords.\n * If omitted, the annotation has no JSON Schema representation (UI-only).\n */\n readonly toJsonSchema?: (value: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a vocabulary keyword to include in a JSON Schema `$vocabulary` declaration.\n */\nexport interface VocabularyKeywordRegistration {\n /** The keyword name (without vendor prefix). */\n readonly keyword: string;\n /** JSON Schema that describes the valid values for this keyword. */\n readonly schema: JsonValue;\n}\n\n// =============================================================================\n// EXTENSION DEFINITION\n// =============================================================================\n\n/**\n * A complete extension definition bundling types, constraints, annotations,\n * and vocabulary keywords.\n *\n * @example\n * ```typescript\n * const monetaryExtension = defineExtension({\n * extensionId: \"x-stripe/monetary\",\n * types: [\n * defineCustomType({\n * typeName: \"Decimal\",\n * toJsonSchema: (_payload, prefix) => ({\n * type: \"string\",\n * [`${prefix}-decimal`]: true,\n * }),\n * }),\n * ],\n * });\n * ```\n */\nexport interface ExtensionDefinition {\n /** Globally unique extension identifier, e.g., \"x-stripe/monetary\". */\n readonly extensionId: string;\n /** Custom type registrations provided by this extension. */\n readonly types?: readonly CustomTypeRegistration[];\n /** Custom constraint registrations provided by this extension. */\n readonly constraints?: readonly CustomConstraintRegistration[];\n /** Custom annotation registrations provided by this extension. */\n readonly annotations?: readonly CustomAnnotationRegistration[];\n /** Vocabulary keyword registrations provided by this extension. */\n readonly vocabularyKeywords?: readonly VocabularyKeywordRegistration[];\n}\n\n// =============================================================================\n// FACTORY FUNCTIONS\n// =============================================================================\n\n/**\n * Defines a complete extension. Currently an identity function that provides\n * type-checking and IDE autocompletion for the definition shape.\n *\n * @param def - The extension definition.\n * @returns The same definition, validated at the type level.\n */\nexport function defineExtension(def: ExtensionDefinition): ExtensionDefinition {\n return def;\n}\n\n/**\n * Defines a custom type registration. Currently an identity function that\n * provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom type registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineCustomType(reg: CustomTypeRegistration): CustomTypeRegistration {\n return reg;\n}\n\n/**\n * Defines a custom constraint registration. Currently an identity function\n * that provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom constraint registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineConstraint(reg: CustomConstraintRegistration): CustomConstraintRegistration {\n return reg;\n}\n\n/**\n * Defines a custom annotation registration. Currently an identity function\n * that provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom annotation registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineAnnotation(reg: CustomAnnotationRegistration): CustomAnnotationRegistration {\n return reg;\n}\n"],"mappings":";AA+BO,SAAS,wBAA2B,OAAyB;AAClE,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,IACP,SAAS;AAAA,IACT,UAAU;AAAA,IACV,QAAQ,CAAC;AAAA,EACX;AACF;;;AC1BO,IAAM,iCAAiC;AAAA,EAC5C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,SAAS;AAAA,EACT,aAAa;AACf;;;ACDO,IAAM,aAAa;;;ACsHnB,SAAS,gBAAgB,KAA+C;AAC7E,SAAO;AACT;AASO,SAAS,iBAAiB,KAAqD;AACpF,SAAO;AACT;AASO,SAAS,iBAAiB,KAAiE;AAChG,SAAO;AACT;AASO,SAAS,iBAAiB,KAAiE;AAChG,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/types/field-state.ts","../src/types/constraint-definitions.ts","../src/types/ir.ts","../src/extensions/index.ts","../src/guards.ts"],"sourcesContent":["import type { Validity } from \"./validity.js\";\n\n/**\n * Represents the runtime state of a single form field.\n *\n * @typeParam T - The value type of the field\n */\nexport interface FieldState<T> {\n /** Current value of the field */\n readonly value: T;\n\n /** Whether the field has been modified by the user */\n readonly dirty: boolean;\n\n /** Whether the field has been focused and blurred */\n readonly touched: boolean;\n\n /** Current validity state */\n readonly validity: Validity;\n\n /** Validation error messages, if any */\n readonly errors: readonly string[];\n}\n\n/**\n * Creates initial field state with default values.\n *\n * @typeParam T - The value type of the field\n * @param value - The initial value for the field\n * @returns Initial field state\n */\nexport function createInitialFieldState<T>(value: T): FieldState<T> {\n return {\n value,\n dirty: false,\n touched: false,\n validity: \"unknown\",\n errors: [],\n };\n}\n","/**\n * Built-in constraint definitions for FormSpec constraint validation.\n *\n * This is the single source of truth for which constraints FormSpec\n * recognizes. Both `@formspec/build` (schema generation)\n * and `@formspec/eslint-plugin` (lint-time validation) import from here.\n */\n\n/**\n * Built-in constraint names mapped to their expected value type for parsing.\n * Constraints are surface-agnostic — they manifest as both TSDoc tags\n * (e.g., `@minimum 0`) and chain DSL options (e.g., `{ minimum: 0 }`).\n *\n * Keys use camelCase matching JSON Schema property names.\n */\nexport const BUILTIN_CONSTRAINT_DEFINITIONS = {\n minimum: \"number\",\n maximum: \"number\",\n exclusiveMinimum: \"number\",\n exclusiveMaximum: \"number\",\n multipleOf: \"number\",\n minLength: \"number\",\n maxLength: \"number\",\n minItems: \"number\",\n maxItems: \"number\",\n pattern: \"string\",\n enumOptions: \"json\",\n} as const;\n\n/** Type of a built-in constraint name. */\nexport type BuiltinConstraintName = keyof typeof BUILTIN_CONSTRAINT_DEFINITIONS;\n\n/**\n * Normalizes a constraint tag name from PascalCase to camelCase.\n *\n * Lowercases the first character so that e.g. `\"Minimum\"` becomes `\"minimum\"`.\n * Callers must strip the `@` prefix before calling this function.\n *\n * @example\n * normalizeConstraintTagName(\"Minimum\") // \"minimum\"\n * normalizeConstraintTagName(\"MinLength\") // \"minLength\"\n * normalizeConstraintTagName(\"minimum\") // \"minimum\" (idempotent)\n */\nexport function normalizeConstraintTagName(tagName: string): string {\n return tagName.charAt(0).toLowerCase() + tagName.slice(1);\n}\n\n/**\n * Type guard: checks whether a tag name is a known built-in constraint.\n *\n * Uses `Object.hasOwn()` rather than `in` to prevent prototype-chain\n * matches on names like `\"toString\"` or `\"constructor\"`.\n *\n * Callers should normalize with {@link normalizeConstraintTagName} first\n * if the input may be PascalCase.\n */\nexport function isBuiltinConstraintName(tagName: string): tagName is BuiltinConstraintName {\n return Object.hasOwn(BUILTIN_CONSTRAINT_DEFINITIONS, tagName);\n}\n","/**\n * Canonical Intermediate Representation (IR) types for FormSpec.\n *\n * The IR is the shared intermediate structure that both authoring surfaces\n * (chain DSL and TSDoc-annotated types) compile to. All downstream operations\n * — JSON Schema generation, UI Schema generation, constraint validation,\n * diagnostics — consume the IR exclusively.\n *\n * All types are plain, serializable objects (no live compiler references).\n *\n * @see {@link https://github.com/stripe/formspec-workspace/blob/main/scratch/design/001-canonical-ir.md}\n */\n\n// =============================================================================\n// IR VERSION\n// =============================================================================\n\n/**\n * The current IR format version. Centralized here so all canonicalizers\n * and consumers reference a single source of truth.\n */\nexport const IR_VERSION = \"0.1.0\" as const;\n\n// =============================================================================\n// UTILITY TYPES\n// =============================================================================\n\n/**\n * A JSON-serializable value. All IR nodes must be representable as JSON.\n */\nexport type JsonValue =\n | null\n | boolean\n | number\n | string\n | readonly JsonValue[]\n | { readonly [key: string]: JsonValue };\n\n// =============================================================================\n// PROVENANCE\n// =============================================================================\n\n/**\n * Describes the origin of an IR node.\n * Enables diagnostics that point to the source of a contradiction or error.\n */\nexport interface Provenance {\n /** The authoring surface that produced this node. */\n readonly surface: \"tsdoc\" | \"chain-dsl\" | \"extension\" | \"inferred\";\n /** Absolute path to the source file. */\n readonly file: string;\n /** 1-based line number in the source file. */\n readonly line: number;\n /** 0-based column number in the source file. */\n readonly column: number;\n /** Length of the source span in characters (for IDE underline ranges). */\n readonly length?: number;\n /**\n * The specific tag, call, or construct that produced this node.\n * Examples: `@minimum`, `field.number({ min: 0 })`, `optional`\n */\n readonly tagName?: string;\n}\n\n// =============================================================================\n// PATH TARGET\n// =============================================================================\n\n/**\n * A path targeting a sub-field within a complex type.\n * Used by constraints and annotations to target nested properties.\n */\nexport interface PathTarget {\n /**\n * Sequence of property names forming a path from the annotated field's type\n * to the target sub-field.\n * e.g., `[\"value\"]` or `[\"address\", \"zip\"]`\n */\n readonly segments: readonly string[];\n}\n\n// =============================================================================\n// TYPE NODES\n// =============================================================================\n\n/**\n * Discriminated union of all type representations in the IR.\n */\nexport type TypeNode =\n | PrimitiveTypeNode\n | EnumTypeNode\n | ArrayTypeNode\n | ObjectTypeNode\n | UnionTypeNode\n | ReferenceTypeNode\n | DynamicTypeNode\n | CustomTypeNode;\n\n/**\n * Primitive types mapping directly to JSON Schema primitives.\n *\n * Note: integer is NOT a primitive kind — integer semantics are expressed\n * via a `multipleOf: 1` constraint on a number type.\n */\nexport interface PrimitiveTypeNode {\n readonly kind: \"primitive\";\n readonly primitiveKind: \"string\" | \"number\" | \"boolean\" | \"null\";\n}\n\n/** A member of a static enum type. */\nexport interface EnumMember {\n /** The serialized value stored in data. */\n readonly value: string | number;\n /** Optional per-member display name. */\n readonly displayName?: string;\n}\n\n/** Static enum type — members known at build time. */\nexport interface EnumTypeNode {\n readonly kind: \"enum\";\n readonly members: readonly EnumMember[];\n}\n\n/** Array type with a single items type. */\nexport interface ArrayTypeNode {\n readonly kind: \"array\";\n readonly items: TypeNode;\n}\n\n/** A named property within an object type. */\nexport interface ObjectProperty {\n readonly name: string;\n readonly type: TypeNode;\n readonly optional: boolean;\n /**\n * Use-site constraints on this property.\n * Distinct from constraints on the property's type — these are\n * use-site constraints (e.g., `@minimum :amount 0` targets the\n * `amount` property of a `MonetaryAmount` field).\n */\n readonly constraints: readonly ConstraintNode[];\n /** Use-site annotations on this property. */\n readonly annotations: readonly AnnotationNode[];\n readonly provenance: Provenance;\n}\n\n/** Object type with named properties. */\nexport interface ObjectTypeNode {\n readonly kind: \"object\";\n /**\n * Named properties of this object. Order is preserved from the source\n * declaration for deterministic output.\n */\n readonly properties: readonly ObjectProperty[];\n /**\n * Whether additional properties beyond those listed are permitted.\n * Defaults to false — object types in FormSpec are closed.\n */\n readonly additionalProperties: boolean;\n}\n\n/** Union type for non-enum unions. Nullable types are `T | null` using this. */\nexport interface UnionTypeNode {\n readonly kind: \"union\";\n readonly members: readonly TypeNode[];\n}\n\n/** Named type reference — preserved as references for `$defs`/`$ref` emission. */\nexport interface ReferenceTypeNode {\n readonly kind: \"reference\";\n /**\n * The fully-qualified name of the referenced type.\n * For TypeScript interfaces/type aliases: `\"<module>#<TypeName>\"`.\n * For built-in types: the primitive kind string.\n */\n readonly name: string;\n /**\n * Type arguments if this is a generic instantiation.\n * e.g., `Array<string>` → `{ name: \"Array\", typeArguments: [PrimitiveTypeNode(\"string\")] }`\n */\n readonly typeArguments: readonly TypeNode[];\n}\n\n/** Dynamic type — schema resolved at runtime from a named data source. */\nexport interface DynamicTypeNode {\n readonly kind: \"dynamic\";\n readonly dynamicKind: \"enum\" | \"schema\";\n /** Key identifying the runtime data source or schema provider. */\n readonly sourceKey: string;\n /**\n * For dynamic enums: field names whose current values are passed as\n * parameters to the data source resolver.\n */\n readonly parameterFields: readonly string[];\n}\n\n/** Custom type registered by an extension. */\nexport interface CustomTypeNode {\n readonly kind: \"custom\";\n /**\n * The extension-qualified type identifier.\n * Format: `\"<vendor-prefix>/<extension-name>/<type-name>\"`\n * e.g., `\"x-stripe/monetary/MonetaryAmount\"`\n */\n readonly typeId: string;\n /**\n * Opaque payload serialized by the extension that registered this type.\n * Must be JSON-serializable.\n */\n readonly payload: JsonValue;\n}\n\n// =============================================================================\n// CONSTRAINT NODES\n// =============================================================================\n\n/**\n * Discriminated union of all constraint types.\n * Constraints are set-influencing: they narrow the set of valid values.\n */\nexport type ConstraintNode =\n | NumericConstraintNode\n | LengthConstraintNode\n | PatternConstraintNode\n | ArrayCardinalityConstraintNode\n | EnumMemberConstraintNode\n | CustomConstraintNode;\n\n/**\n * Numeric constraints: bounds and multipleOf.\n *\n * `minimum` and `maximum` are inclusive; `exclusiveMinimum` and\n * `exclusiveMaximum` are exclusive bounds (matching JSON Schema 2020-12\n * semantics).\n *\n * Type applicability: may only attach to fields with `PrimitiveTypeNode(\"number\")`\n * or a `ReferenceTypeNode` that resolves to one.\n */\nexport interface NumericConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind:\n | \"minimum\"\n | \"maximum\"\n | \"exclusiveMinimum\"\n | \"exclusiveMaximum\"\n | \"multipleOf\";\n readonly value: number;\n /** If present, targets a nested sub-field rather than the field itself. */\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/**\n * String length and array item count constraints.\n *\n * `minLength`/`maxLength` apply to strings; `minItems`/`maxItems` apply to\n * arrays. They share the same node shape because the composition rules are\n * identical.\n *\n * Type applicability: `minLength`/`maxLength` require `PrimitiveTypeNode(\"string\")`;\n * `minItems`/`maxItems` require `ArrayTypeNode`.\n */\nexport interface LengthConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"minLength\" | \"maxLength\" | \"minItems\" | \"maxItems\";\n readonly value: number;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/**\n * String pattern constraint (ECMA-262 regex without delimiters).\n *\n * Multiple `pattern` constraints on the same field compose via intersection:\n * all patterns must match simultaneously.\n *\n * Type applicability: requires `PrimitiveTypeNode(\"string\")`.\n */\nexport interface PatternConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"pattern\";\n /** ECMA-262 regular expression, without delimiters. */\n readonly pattern: string;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Array uniqueness constraint. */\nexport interface ArrayCardinalityConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"uniqueItems\";\n readonly value: true;\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Enum member subset constraint (refinement — only narrows). */\nexport interface EnumMemberConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"allowedMembers\";\n readonly members: readonly (string | number)[];\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n/** Extension-registered custom constraint. */\nexport interface CustomConstraintNode {\n readonly kind: \"constraint\";\n readonly constraintKind: \"custom\";\n /** Extension-qualified ID: `\"<vendor-prefix>/<extension-name>/<constraint-name>\"` */\n readonly constraintId: string;\n /** JSON-serializable payload defined by the extension. */\n readonly payload: JsonValue;\n /** How this constraint composes with others of the same `constraintId`. */\n readonly compositionRule: \"intersect\" | \"override\";\n readonly path?: PathTarget;\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// ANNOTATION NODES\n// =============================================================================\n\n/**\n * Discriminated union of all annotation types.\n * Annotations are value-influencing: they describe or present a field\n * but do not affect which values are valid.\n */\nexport type AnnotationNode =\n | DisplayNameAnnotationNode\n | DescriptionAnnotationNode\n | PlaceholderAnnotationNode\n | DefaultValueAnnotationNode\n | DeprecatedAnnotationNode\n | FormatHintAnnotationNode\n | CustomAnnotationNode;\n\nexport interface DisplayNameAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"displayName\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface DescriptionAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"description\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface PlaceholderAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"placeholder\";\n readonly value: string;\n readonly provenance: Provenance;\n}\n\nexport interface DefaultValueAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"defaultValue\";\n /** Must be JSON-serializable and type-compatible (verified during Validate phase). */\n readonly value: JsonValue;\n readonly provenance: Provenance;\n}\n\nexport interface DeprecatedAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"deprecated\";\n /** Optional deprecation message. */\n readonly message?: string;\n readonly provenance: Provenance;\n}\n\n/** UI rendering hint — does not affect schema validation. */\nexport interface FormatHintAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"formatHint\";\n /** Renderer-specific format identifier: \"textarea\", \"radio\", \"date\", \"color\", etc. */\n readonly format: string;\n readonly provenance: Provenance;\n}\n\n/** Extension-registered custom annotation. */\nexport interface CustomAnnotationNode {\n readonly kind: \"annotation\";\n readonly annotationKind: \"custom\";\n /** Extension-qualified ID: `\"<vendor-prefix>/<extension-name>/<annotation-name>\"` */\n readonly annotationId: string;\n readonly value: JsonValue;\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// FIELD NODE\n// =============================================================================\n\n/** A single form field after canonicalization. */\nexport interface FieldNode {\n readonly kind: \"field\";\n /** The field's key in the data schema. */\n readonly name: string;\n /** The resolved type of this field. */\n readonly type: TypeNode;\n /** Whether this field is required in the data schema. */\n readonly required: boolean;\n /** Set-influencing constraints, after merging. */\n readonly constraints: readonly ConstraintNode[];\n /** Value-influencing annotations, after merging. */\n readonly annotations: readonly AnnotationNode[];\n /** Where this field was declared. */\n readonly provenance: Provenance;\n /**\n * Debug only — ordered list of constraint/annotation nodes that participated\n * in merging, including dominated ones.\n */\n readonly mergeHistory?: readonly {\n readonly node: ConstraintNode | AnnotationNode;\n readonly dominated: boolean;\n }[];\n}\n\n// =============================================================================\n// LAYOUT NODES\n// =============================================================================\n\n/** Union of layout node types. */\nexport type LayoutNode = GroupLayoutNode | ConditionalLayoutNode;\n\n/** A visual grouping of form elements. */\nexport interface GroupLayoutNode {\n readonly kind: \"group\";\n readonly label: string;\n /** Elements contained in this group — may be fields or nested groups. */\n readonly elements: readonly FormIRElement[];\n readonly provenance: Provenance;\n}\n\n/** Conditional visibility based on another field's value. */\nexport interface ConditionalLayoutNode {\n readonly kind: \"conditional\";\n /** The field whose value triggers visibility. */\n readonly fieldName: string;\n /** The value that makes the condition true (SHOW). */\n readonly value: JsonValue;\n /** Elements shown when the condition is met. */\n readonly elements: readonly FormIRElement[];\n readonly provenance: Provenance;\n}\n\n/** Union of all IR element types. */\nexport type FormIRElement = FieldNode | LayoutNode;\n\n// =============================================================================\n// TYPE REGISTRY\n// =============================================================================\n\n/** A named type definition stored in the type registry. */\nexport interface TypeDefinition {\n /** The fully-qualified reference name (key in the registry). */\n readonly name: string;\n /** The resolved type node. */\n readonly type: TypeNode;\n /** Where this type was declared. */\n readonly provenance: Provenance;\n}\n\n// =============================================================================\n// FORM IR (TOP-LEVEL)\n// =============================================================================\n\n/**\n * The complete Canonical Intermediate Representation for a form.\n *\n * Output of the Canonicalize phase; input to Validate, Generate (JSON Schema),\n * and Generate (UI Schema) phases.\n *\n * Serializable to JSON — no live compiler objects.\n */\nexport interface FormIR {\n readonly kind: \"form-ir\";\n /**\n * Schema version for the IR format itself.\n * Should equal `IR_VERSION`.\n */\n readonly irVersion: string;\n /** Top-level elements of the form: fields and layout nodes. */\n readonly elements: readonly FormIRElement[];\n /**\n * Registry of named types referenced by fields in this form.\n * Keys are fully-qualified type names matching `ReferenceTypeNode.name`.\n */\n readonly typeRegistry: Readonly<Record<string, TypeDefinition>>;\n /** Provenance of the form definition itself. */\n readonly provenance: Provenance;\n}\n","/**\n * Extension API for registering custom types, constraints, annotations,\n * and vocabulary keywords with FormSpec.\n *\n * Extensions allow third-party packages (e.g., \"Decimal\", \"DateOnly\") to\n * plug into the FormSpec pipeline. The types and factory functions defined\n * here are consumed by the FormSpec build pipeline.\n *\n * @packageDocumentation\n */\n\nimport type { JsonValue, TypeNode } from \"../types/ir.js\";\n\n// =============================================================================\n// REGISTRATION TYPES\n// =============================================================================\n\n/**\n * Registration for a custom type that maps to a JSON Schema representation.\n *\n * Custom types are referenced via {@link CustomTypeNode} in the IR and\n * resolved to JSON Schema via `toJsonSchema` during generation.\n */\nexport interface CustomTypeRegistration {\n /** The type name, unique within the extension. */\n readonly typeName: string;\n /**\n * Converts the custom type's payload into a JSON Schema fragment.\n *\n * @param payload - The opaque JSON payload from the {@link CustomTypeNode}.\n * @param vendorPrefix - The vendor prefix for extension keywords (e.g., \"x-stripe\").\n * @returns A JSON Schema fragment representing this type.\n */\n readonly toJsonSchema: (payload: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a custom constraint that maps to JSON Schema keywords.\n *\n * Custom constraints are referenced via {@link CustomConstraintNode} in the IR.\n */\nexport interface CustomConstraintRegistration {\n /** The constraint name, unique within the extension. */\n readonly constraintName: string;\n /**\n * How this constraint composes with other constraints of the same kind.\n * - \"intersect\": combine with logical AND (both must hold)\n * - \"override\": last writer wins\n */\n readonly compositionRule: \"intersect\" | \"override\";\n /**\n * TypeNode kinds this constraint is applicable to, or `null` for any type.\n * Used by the validator to emit TYPE_MISMATCH diagnostics.\n */\n readonly applicableTypes: readonly TypeNode[\"kind\"][] | null;\n /**\n * Converts the custom constraint's payload into JSON Schema keywords.\n *\n * @param payload - The opaque JSON payload from the {@link CustomConstraintNode}.\n * @param vendorPrefix - The vendor prefix for extension keywords.\n * @returns A JSON Schema fragment with the constraint keywords.\n */\n readonly toJsonSchema: (payload: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a custom annotation that may produce JSON Schema keywords.\n *\n * Custom annotations are referenced via {@link CustomAnnotationNode} in the IR.\n * They describe or present a field but do not affect which values are valid.\n */\nexport interface CustomAnnotationRegistration {\n /** The annotation name, unique within the extension. */\n readonly annotationName: string;\n /**\n * Optionally converts the annotation value into JSON Schema keywords.\n * If omitted, the annotation has no JSON Schema representation (UI-only).\n */\n readonly toJsonSchema?: (value: JsonValue, vendorPrefix: string) => Record<string, unknown>;\n}\n\n/**\n * Registration for a vocabulary keyword to include in a JSON Schema `$vocabulary` declaration.\n */\nexport interface VocabularyKeywordRegistration {\n /** The keyword name (without vendor prefix). */\n readonly keyword: string;\n /** JSON Schema that describes the valid values for this keyword. */\n readonly schema: JsonValue;\n}\n\n// =============================================================================\n// EXTENSION DEFINITION\n// =============================================================================\n\n/**\n * A complete extension definition bundling types, constraints, annotations,\n * and vocabulary keywords.\n *\n * @example\n * ```typescript\n * const monetaryExtension = defineExtension({\n * extensionId: \"x-stripe/monetary\",\n * types: [\n * defineCustomType({\n * typeName: \"Decimal\",\n * toJsonSchema: (_payload, prefix) => ({\n * type: \"string\",\n * [`${prefix}-decimal`]: true,\n * }),\n * }),\n * ],\n * });\n * ```\n */\nexport interface ExtensionDefinition {\n /** Globally unique extension identifier, e.g., \"x-stripe/monetary\". */\n readonly extensionId: string;\n /** Custom type registrations provided by this extension. */\n readonly types?: readonly CustomTypeRegistration[];\n /** Custom constraint registrations provided by this extension. */\n readonly constraints?: readonly CustomConstraintRegistration[];\n /** Custom annotation registrations provided by this extension. */\n readonly annotations?: readonly CustomAnnotationRegistration[];\n /** Vocabulary keyword registrations provided by this extension. */\n readonly vocabularyKeywords?: readonly VocabularyKeywordRegistration[];\n}\n\n// =============================================================================\n// FACTORY FUNCTIONS\n// =============================================================================\n\n/**\n * Defines a complete extension. Currently an identity function that provides\n * type-checking and IDE autocompletion for the definition shape.\n *\n * @param def - The extension definition.\n * @returns The same definition, validated at the type level.\n */\nexport function defineExtension(def: ExtensionDefinition): ExtensionDefinition {\n return def;\n}\n\n/**\n * Defines a custom type registration. Currently an identity function that\n * provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom type registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineCustomType(reg: CustomTypeRegistration): CustomTypeRegistration {\n return reg;\n}\n\n/**\n * Defines a custom constraint registration. Currently an identity function\n * that provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom constraint registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineConstraint(reg: CustomConstraintRegistration): CustomConstraintRegistration {\n return reg;\n}\n\n/**\n * Defines a custom annotation registration. Currently an identity function\n * that provides type-checking and IDE autocompletion.\n *\n * @param reg - The custom annotation registration.\n * @returns The same registration, validated at the type level.\n */\nexport function defineAnnotation(reg: CustomAnnotationRegistration): CustomAnnotationRegistration {\n return reg;\n}\n","/**\n * Type guards for FormSpec form elements.\n *\n * Each guard narrows a {@link FormElement} to a specific field, group, or conditional type.\n */\n\nimport type {\n FormElement,\n AnyField,\n TextField,\n NumberField,\n BooleanField,\n StaticEnumField,\n DynamicEnumField,\n DynamicSchemaField,\n ArrayField,\n ObjectField,\n Group,\n Conditional,\n EnumOptionValue,\n} from \"./types/elements.js\";\n\n/** Narrows a FormElement to any field type. */\nexport function isField(element: FormElement): element is AnyField {\n return element._type === \"field\";\n}\n\n/** Narrows a FormElement to a text input field. */\nexport function isTextField(element: FormElement): element is TextField<string> {\n return element._type === \"field\" && element._field === \"text\";\n}\n\n/** Narrows a FormElement to a numeric input field. */\nexport function isNumberField(element: FormElement): element is NumberField<string> {\n return element._type === \"field\" && element._field === \"number\";\n}\n\n/** Narrows a FormElement to a boolean checkbox field. */\nexport function isBooleanField(element: FormElement): element is BooleanField<string> {\n return element._type === \"field\" && element._field === \"boolean\";\n}\n\n/** Narrows a FormElement to a static enum field. */\nexport function isStaticEnumField(\n element: FormElement\n): element is StaticEnumField<string, readonly EnumOptionValue[]> {\n return element._type === \"field\" && element._field === \"enum\";\n}\n\n/** Narrows a FormElement to a dynamic enum field. */\nexport function isDynamicEnumField(\n element: FormElement\n): element is DynamicEnumField<string, string> {\n return element._type === \"field\" && element._field === \"dynamic_enum\";\n}\n\n/** Narrows a FormElement to a dynamic schema field. */\nexport function isDynamicSchemaField(element: FormElement): element is DynamicSchemaField<string> {\n return element._type === \"field\" && element._field === \"dynamic_schema\";\n}\n\n/** Narrows a FormElement to an array field. */\nexport function isArrayField(\n element: FormElement\n): element is ArrayField<string, readonly FormElement[]> {\n return element._type === \"field\" && element._field === \"array\";\n}\n\n/** Narrows a FormElement to an object field. */\nexport function isObjectField(\n element: FormElement\n): element is ObjectField<string, readonly FormElement[]> {\n return element._type === \"field\" && element._field === \"object\";\n}\n\n/** Narrows a FormElement to a visual group. */\nexport function isGroup(element: FormElement): element is Group<readonly FormElement[]> {\n return element._type === \"group\";\n}\n\n/** Narrows a FormElement to a conditional wrapper. */\nexport function isConditional(\n element: FormElement\n): element is Conditional<string, unknown, readonly FormElement[]> {\n return element._type === \"conditional\";\n}\n"],"mappings":";AA+BO,SAAS,wBAA2B,OAAyB;AAClE,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,IACP,SAAS;AAAA,IACT,UAAU;AAAA,IACV,QAAQ,CAAC;AAAA,EACX;AACF;;;ACxBO,IAAM,iCAAiC;AAAA,EAC5C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa;AACf;AAgBO,SAAS,2BAA2B,SAAyB;AAClE,SAAO,QAAQ,OAAO,CAAC,EAAE,YAAY,IAAI,QAAQ,MAAM,CAAC;AAC1D;AAWO,SAAS,wBAAwB,SAAmD;AACzF,SAAO,OAAO,OAAO,gCAAgC,OAAO;AAC9D;;;ACrCO,IAAM,aAAa;;;ACsHnB,SAAS,gBAAgB,KAA+C;AAC7E,SAAO;AACT;AASO,SAAS,iBAAiB,KAAqD;AACpF,SAAO;AACT;AASO,SAAS,iBAAiB,KAAiE;AAChG,SAAO;AACT;AASO,SAAS,iBAAiB,KAAiE;AAChG,SAAO;AACT;;;ACvJO,SAAS,QAAQ,SAA2C;AACjE,SAAO,QAAQ,UAAU;AAC3B;AAGO,SAAS,YAAY,SAAoD;AAC9E,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,cAAc,SAAsD;AAClF,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,eAAe,SAAuD;AACpF,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,kBACd,SACgE;AAChE,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,mBACd,SAC6C;AAC7C,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,qBAAqB,SAA6D;AAChG,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,aACd,SACuD;AACvD,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,cACd,SACwD;AACxD,SAAO,QAAQ,UAAU,WAAW,QAAQ,WAAW;AACzD;AAGO,SAAS,QAAQ,SAAgE;AACtF,SAAO,QAAQ,UAAU;AAC3B;AAGO,SAAS,cACd,SACiE;AACjE,SAAO,QAAQ,UAAU;AAC3B;","names":[]}
@@ -8,18 +8,45 @@
8
8
  /**
9
9
  * Built-in constraint names mapped to their expected value type for parsing.
10
10
  * Constraints are surface-agnostic — they manifest as both TSDoc tags
11
- * (e.g., `@Minimum 0`) and chain DSL options (e.g., `{ minimum: 0 }`).
11
+ * (e.g., `@minimum 0`) and chain DSL options (e.g., `{ minimum: 0 }`).
12
+ *
13
+ * Keys use camelCase matching JSON Schema property names.
12
14
  */
13
15
  export declare const BUILTIN_CONSTRAINT_DEFINITIONS: {
14
- readonly Minimum: "number";
15
- readonly Maximum: "number";
16
- readonly ExclusiveMinimum: "number";
17
- readonly ExclusiveMaximum: "number";
18
- readonly MinLength: "number";
19
- readonly MaxLength: "number";
20
- readonly Pattern: "string";
21
- readonly EnumOptions: "json";
16
+ readonly minimum: "number";
17
+ readonly maximum: "number";
18
+ readonly exclusiveMinimum: "number";
19
+ readonly exclusiveMaximum: "number";
20
+ readonly multipleOf: "number";
21
+ readonly minLength: "number";
22
+ readonly maxLength: "number";
23
+ readonly minItems: "number";
24
+ readonly maxItems: "number";
25
+ readonly pattern: "string";
26
+ readonly enumOptions: "json";
22
27
  };
23
28
  /** Type of a built-in constraint name. */
24
29
  export type BuiltinConstraintName = keyof typeof BUILTIN_CONSTRAINT_DEFINITIONS;
30
+ /**
31
+ * Normalizes a constraint tag name from PascalCase to camelCase.
32
+ *
33
+ * Lowercases the first character so that e.g. `"Minimum"` becomes `"minimum"`.
34
+ * Callers must strip the `@` prefix before calling this function.
35
+ *
36
+ * @example
37
+ * normalizeConstraintTagName("Minimum") // "minimum"
38
+ * normalizeConstraintTagName("MinLength") // "minLength"
39
+ * normalizeConstraintTagName("minimum") // "minimum" (idempotent)
40
+ */
41
+ export declare function normalizeConstraintTagName(tagName: string): string;
42
+ /**
43
+ * Type guard: checks whether a tag name is a known built-in constraint.
44
+ *
45
+ * Uses `Object.hasOwn()` rather than `in` to prevent prototype-chain
46
+ * matches on names like `"toString"` or `"constructor"`.
47
+ *
48
+ * Callers should normalize with {@link normalizeConstraintTagName} first
49
+ * if the input may be PascalCase.
50
+ */
51
+ export declare function isBuiltinConstraintName(tagName: string): tagName is BuiltinConstraintName;
25
52
  //# sourceMappingURL=constraint-definitions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constraint-definitions.d.ts","sourceRoot":"","sources":["../../src/types/constraint-definitions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;CASjC,CAAC;AAEX,0CAA0C;AAC1C,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,8BAA8B,CAAC"}
1
+ {"version":3,"file":"constraint-definitions.d.ts","sourceRoot":"","sources":["../../src/types/constraint-definitions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;CAYjC,CAAC;AAEX,0CAA0C;AAC1C,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,8BAA8B,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,qBAAqB,CAEzF"}
@@ -22,6 +22,12 @@ export interface TextField<N extends string> {
22
22
  readonly placeholder?: string;
23
23
  /** Whether this field is required for form submission */
24
24
  readonly required?: boolean;
25
+ /** Minimum string length */
26
+ readonly minLength?: number;
27
+ /** Maximum string length */
28
+ readonly maxLength?: number;
29
+ /** Regular expression pattern the value must match */
30
+ readonly pattern?: string;
25
31
  }
26
32
  /**
27
33
  * A numeric input field.
@@ -43,6 +49,8 @@ export interface NumberField<N extends string> {
43
49
  readonly max?: number;
44
50
  /** Whether this field is required for form submission */
45
51
  readonly required?: boolean;
52
+ /** Value must be a multiple of this number (use 1 for integer semantics) */
53
+ readonly multipleOf?: number;
46
54
  }
47
55
  /**
48
56
  * A boolean checkbox field.
@@ -136,6 +144,8 @@ export interface DynamicSchemaField<N extends string> {
136
144
  readonly label?: string;
137
145
  /** Whether this field is required for form submission */
138
146
  readonly required?: boolean;
147
+ /** Field names whose values are needed to configure the schema */
148
+ readonly params?: readonly string[];
139
149
  }
140
150
  /**
141
151
  * An array field containing repeating items.
@@ -1 +1 @@
1
- {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../src/types/elements.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,MAAM;IACzC,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,kCAAkC;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,C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;IAC9D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW,CAC1B,SAAS,SAAS,MAAM,EACxB,KAAK,EACL,QAAQ,SAAS,SAAS,WAAW,EAAE;IAEvC,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,KAAK,CAAC,SAAS,WAAW,EAAE,CAAC,GAC7B,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC,CAAC;AAMzD;;;;GAIG;AACH,MAAM,WAAW,QAAQ,CAAC,QAAQ,SAAS,SAAS,WAAW,EAAE;IAC/D,8BAA8B;IAC9B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B"}
@@ -5,7 +5,7 @@ export type { FormState } from "./form-state.js";
5
5
  export type { DataSourceRegistry, DataSourceOption, FetchOptionsResponse, DataSourceValueType, } from "./data-source.js";
6
6
  export type { TextField, NumberField, BooleanField, EnumOption, EnumOptionValue, StaticEnumField, DynamicEnumField, DynamicSchemaField, ArrayField, ObjectField, AnyField, Group, Conditional, FormElement, FormSpec, } from "./elements.js";
7
7
  export type { EqualsPredicate, Predicate } from "./predicate.js";
8
- export { BUILTIN_CONSTRAINT_DEFINITIONS } from "./constraint-definitions.js";
8
+ export { BUILTIN_CONSTRAINT_DEFINITIONS, normalizeConstraintTagName, isBuiltinConstraintName, } from "./constraint-definitions.js";
9
9
  export type { BuiltinConstraintName } from "./constraint-definitions.js";
10
10
  export { IR_VERSION } from "./ir.js";
11
11
  export type { JsonValue, Provenance, PathTarget, TypeNode, PrimitiveTypeNode, EnumMember, EnumTypeNode, ArrayTypeNode, ObjectProperty, ObjectTypeNode, UnionTypeNode, ReferenceTypeNode, DynamicTypeNode, CustomTypeNode, ConstraintNode, NumericConstraintNode, LengthConstraintNode, PatternConstraintNode, ArrayCardinalityConstraintNode, EnumMemberConstraintNode, CustomConstraintNode, AnnotationNode, DisplayNameAnnotationNode, DescriptionAnnotationNode, PlaceholderAnnotationNode, DefaultValueAnnotationNode, DeprecatedAnnotationNode, FormatHintAnnotationNode, CustomAnnotationNode, FieldNode, LayoutNode, GroupLayoutNode, ConditionalLayoutNode, FormIRElement, TypeDefinition, FormIR, } from "./ir.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,GACT,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAC7E,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,YAAY,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,MAAM,GACP,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,GACT,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,YAAY,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,MAAM,GACP,MAAM,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formspec/core",
3
- "version": "0.1.0-alpha.12",
3
+ "version": "0.1.0-alpha.14",
4
4
  "description": "Core utilities for formspec",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -18,7 +18,8 @@
18
18
  "README.md"
19
19
  ],
20
20
  "devDependencies": {
21
- "tsd": "^0.31.0"
21
+ "tsd": "^0.31.0",
22
+ "vitest": "^3.2.4"
22
23
  },
23
24
  "tsd": {
24
25
  "directory": "src/__tests__"
@@ -32,7 +33,7 @@
32
33
  "build": "tsup && tsc --emitDeclarationOnly && api-extractor run --local",
33
34
  "clean": "rm -rf dist temp",
34
35
  "typecheck": "tsc --noEmit",
35
- "test": "tsd",
36
+ "test": "vitest run && tsd",
36
37
  "test:types": "tsd",
37
38
  "api-extractor": "api-extractor run",
38
39
  "api-extractor:local": "api-extractor run --local",