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

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
@@ -42,6 +42,8 @@ This package provides the foundational types used throughout the FormSpec ecosys
42
42
  - **State types**: `FieldState`, `FormState`, `Validity`
43
43
  - **Data source types**: `DataSourceRegistry`, `DataSourceOption`, `FetchOptionsResponse`
44
44
  - **Predicate types**: `EqualsPredicate`, `Predicate`
45
+ - **IR types**: `FormIR`, `FormIRElement`, `FieldNode`, `LayoutNode`, `TypeNode`, `ConstraintNode`, `AnnotationNode`, `Provenance`, `IR_VERSION`
46
+ - **Extension API**: `defineExtension`, `defineConstraint`, `defineAnnotation`, `defineCustomType`
45
47
 
46
48
  ## Usage
47
49
 
@@ -106,6 +108,54 @@ function processForm(form: FormSpec<readonly FormElement[]>) {
106
108
  | `FieldState<T>` | Runtime state of a single field |
107
109
  | `FormState<S>` | Runtime state of entire form |
108
110
 
111
+ ### IR Types
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` |
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"`) |
124
+
125
+ ### Extension API
126
+
127
+ FormSpec's type system is extensible via registration functions:
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 |
135
+
136
+ ```typescript
137
+ import { defineExtension, defineConstraint, defineAnnotation } from "@formspec/core";
138
+
139
+ // Register a complete extension
140
+ const myExtension = defineExtension({
141
+ extensionId: "my-ext",
142
+ constraints: [
143
+ {
144
+ constraintName: "Precision",
145
+ applicableTypes: ["primitive"],
146
+ compositionRule: "override",
147
+ toJsonSchema: (payload, vendorPrefix) => ({ [`${vendorPrefix}-precision`]: payload }),
148
+ },
149
+ ],
150
+ annotations: [
151
+ {
152
+ annotationName: "HelpUrl",
153
+ toJsonSchema: (value, vendorPrefix) => ({ [`${vendorPrefix}-help-url`]: value }),
154
+ },
155
+ ],
156
+ });
157
+ ```
158
+
109
159
  ## License
110
160
 
111
161
  UNLICENSED