@formspec/core 0.1.0-alpha.11 → 0.1.0-alpha.13
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 +50 -0
- package/dist/core.d.ts +613 -25
- package/dist/extensions/index.d.ts +146 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/guards.d.ts +29 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/index.cjs +90 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +72 -18
- package/dist/index.js.map +1 -1
- package/dist/types/constraint-definitions.d.ts +25 -0
- package/dist/types/constraint-definitions.d.ts.map +1 -0
- package/dist/types/elements.d.ts +10 -0
- package/dist/types/elements.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/ir.d.ts +386 -0
- package/dist/types/ir.d.ts.map +1 -0
- package/package.json +9 -1
- package/dist/types/decorators.d.ts +0 -31
- package/dist/types/decorators.d.ts.map +0 -1
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
|