@formspec/core 0.1.0-alpha.2 → 0.1.0-alpha.9
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 +111 -0
- package/dist/core.d.ts +430 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/data-source.d.ts.map +1 -1
- package/dist/types/decorators.d.ts +30 -0
- package/dist/types/decorators.d.ts.map +1 -0
- package/dist/types/decorators.js +38 -0
- package/dist/types/decorators.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @formspec/core
|
|
2
|
+
|
|
3
|
+
Core type definitions for the FormSpec library.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @formspec/core
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @formspec/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
> **Note:** Most users should install the `formspec` umbrella package instead, which re-exports everything from this package.
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
This package is ESM-only and requires:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
// package.json
|
|
21
|
+
{
|
|
22
|
+
"type": "module"
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
// tsconfig.json
|
|
28
|
+
{
|
|
29
|
+
"compilerOptions": {
|
|
30
|
+
"module": "NodeNext",
|
|
31
|
+
"moduleResolution": "NodeNext"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Overview
|
|
37
|
+
|
|
38
|
+
This package provides the foundational types used throughout the FormSpec ecosystem:
|
|
39
|
+
|
|
40
|
+
- **Form element types**: `TextField`, `NumberField`, `BooleanField`, `StaticEnumField`, `DynamicEnumField`, `ArrayField`, `ObjectField`
|
|
41
|
+
- **Structural types**: `Group`, `Conditional`, `FormElement`, `FormSpec`
|
|
42
|
+
- **State types**: `FieldState`, `FormState`, `Validity`
|
|
43
|
+
- **Data source types**: `DataSourceRegistry`, `DataSourceOption`, `FetchOptionsResponse`
|
|
44
|
+
- **Predicate types**: `EqualsPredicate`, `Predicate`
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import type {
|
|
50
|
+
FormSpec,
|
|
51
|
+
FormElement,
|
|
52
|
+
TextField,
|
|
53
|
+
NumberField,
|
|
54
|
+
AnyField,
|
|
55
|
+
Group,
|
|
56
|
+
Conditional,
|
|
57
|
+
} from "@formspec/core";
|
|
58
|
+
|
|
59
|
+
// Type guard for field elements
|
|
60
|
+
function isField(element: FormElement): element is AnyField {
|
|
61
|
+
return element._type === "field";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Process form elements
|
|
65
|
+
function processForm(form: FormSpec<readonly FormElement[]>) {
|
|
66
|
+
for (const element of form.elements) {
|
|
67
|
+
if (isField(element)) {
|
|
68
|
+
console.log(`Field: ${element.name} (${element._field})`);
|
|
69
|
+
} else if (element._type === "group") {
|
|
70
|
+
console.log(`Group: ${element.label}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Type Reference
|
|
77
|
+
|
|
78
|
+
### Field Types
|
|
79
|
+
|
|
80
|
+
| Type | Description |
|
|
81
|
+
| -------------------- | ------------------------------------------- |
|
|
82
|
+
| `TextField` | Text input field |
|
|
83
|
+
| `NumberField` | Numeric input field |
|
|
84
|
+
| `BooleanField` | Boolean/checkbox field |
|
|
85
|
+
| `StaticEnumField` | Dropdown with static options |
|
|
86
|
+
| `DynamicEnumField` | Dropdown with dynamic options from resolver |
|
|
87
|
+
| `DynamicSchemaField` | Field with dynamic schema from resolver |
|
|
88
|
+
| `ArrayField` | Array of nested elements |
|
|
89
|
+
| `ObjectField` | Nested object with child fields |
|
|
90
|
+
| `AnyField` | Union of all field types |
|
|
91
|
+
|
|
92
|
+
### Structural Types
|
|
93
|
+
|
|
94
|
+
| Type | Description |
|
|
95
|
+
| ------------- | ------------------------------------------- |
|
|
96
|
+
| `Group` | Groups related fields with a label |
|
|
97
|
+
| `Conditional` | Shows fields based on predicate |
|
|
98
|
+
| `FormElement` | Union of `AnyField`, `Group`, `Conditional` |
|
|
99
|
+
| `FormSpec<E>` | Complete form specification |
|
|
100
|
+
|
|
101
|
+
### State Types
|
|
102
|
+
|
|
103
|
+
| Type | Description |
|
|
104
|
+
| --------------- | ----------------------------------- |
|
|
105
|
+
| `Validity` | `"valid"`, `"invalid"`, `"unknown"` |
|
|
106
|
+
| `FieldState<T>` | Runtime state of a single field |
|
|
107
|
+
| `FormState<S>` | Runtime state of entire form |
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
UNLICENSED
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@formspec/core` - Core type definitions for FormSpec
|
|
3
|
+
*
|
|
4
|
+
* This package provides the foundational types used throughout the FormSpec ecosystem:
|
|
5
|
+
* - Form element types (fields, groups, conditionals)
|
|
6
|
+
* - Field and form state types
|
|
7
|
+
* - Data source registry for dynamic enums
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Union of all field types.
|
|
14
|
+
*/
|
|
15
|
+
export declare type AnyField = TextField<string> | NumberField<string> | BooleanField<string> | StaticEnumField<string, readonly EnumOptionValue[]> | DynamicEnumField<string, string> | DynamicSchemaField<string> | ArrayField<string, readonly FormElement[]> | ObjectField<string, readonly FormElement[]>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* An array field containing repeating items.
|
|
19
|
+
*
|
|
20
|
+
* Use this for lists of values (e.g., multiple addresses, line items).
|
|
21
|
+
*
|
|
22
|
+
* @typeParam N - The field name (string literal type)
|
|
23
|
+
* @typeParam Items - The form elements that define each array item
|
|
24
|
+
*/
|
|
25
|
+
export declare interface ArrayField<N extends string, Items extends readonly FormElement[]> {
|
|
26
|
+
/** Type discriminator for form elements */
|
|
27
|
+
readonly _type: "field";
|
|
28
|
+
/** Field type discriminator - identifies this as an array field */
|
|
29
|
+
readonly _field: "array";
|
|
30
|
+
/** Unique field identifier used as the schema key */
|
|
31
|
+
readonly name: N;
|
|
32
|
+
/** Form elements that define the schema for each array item */
|
|
33
|
+
readonly items: Items;
|
|
34
|
+
/** Display label for the field */
|
|
35
|
+
readonly label?: string;
|
|
36
|
+
/** Whether this field is required for form submission */
|
|
37
|
+
readonly required?: boolean;
|
|
38
|
+
/** Minimum number of items required */
|
|
39
|
+
readonly minItems?: number;
|
|
40
|
+
/** Maximum number of items allowed */
|
|
41
|
+
readonly maxItems?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A boolean checkbox field.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam N - The field name (string literal type)
|
|
48
|
+
*/
|
|
49
|
+
export declare interface BooleanField<N extends string> {
|
|
50
|
+
/** Type discriminator for form elements */
|
|
51
|
+
readonly _type: "field";
|
|
52
|
+
/** Field type discriminator - identifies this as a boolean field */
|
|
53
|
+
readonly _field: "boolean";
|
|
54
|
+
/** Unique field identifier used as the schema key */
|
|
55
|
+
readonly name: N;
|
|
56
|
+
/** Display label for the field */
|
|
57
|
+
readonly label?: string;
|
|
58
|
+
/** Whether this field is required for form submission */
|
|
59
|
+
readonly required?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A conditional wrapper that shows/hides elements based on another field's value.
|
|
64
|
+
*
|
|
65
|
+
* @typeParam FieldName - The field to check
|
|
66
|
+
* @typeParam Value - The value that triggers the condition
|
|
67
|
+
* @typeParam Elements - Tuple of contained form elements
|
|
68
|
+
*/
|
|
69
|
+
export declare interface Conditional<FieldName extends string, Value, Elements extends readonly FormElement[]> {
|
|
70
|
+
/** Type discriminator - identifies this as a conditional element */
|
|
71
|
+
readonly _type: "conditional";
|
|
72
|
+
/** Name of the field whose value determines visibility */
|
|
73
|
+
readonly field: FieldName;
|
|
74
|
+
/** Value that triggers the condition (shows nested elements) */
|
|
75
|
+
readonly value: Value;
|
|
76
|
+
/** Form elements shown when condition is met */
|
|
77
|
+
readonly elements: Elements;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Constraint decorator names that are valid as TSDoc tags, mapped to
|
|
82
|
+
* their expected value type for parsing.
|
|
83
|
+
*
|
|
84
|
+
* Both `@formspec/build` (schema generation) and `@formspec/eslint-plugin`
|
|
85
|
+
* (lint-time validation) import this to determine which JSDoc tags to
|
|
86
|
+
* recognize and how to parse their values.
|
|
87
|
+
*/
|
|
88
|
+
export declare const CONSTRAINT_TAG_DEFINITIONS: {
|
|
89
|
+
readonly Minimum: "number";
|
|
90
|
+
readonly Maximum: "number";
|
|
91
|
+
readonly ExclusiveMinimum: "number";
|
|
92
|
+
readonly ExclusiveMaximum: "number";
|
|
93
|
+
readonly MinLength: "number";
|
|
94
|
+
readonly MaxLength: "number";
|
|
95
|
+
readonly Pattern: "string";
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** Type of a constraint tag name. */
|
|
99
|
+
export declare type ConstraintTagName = keyof typeof CONSTRAINT_TAG_DEFINITIONS;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Creates initial field state with default values.
|
|
103
|
+
*
|
|
104
|
+
* @typeParam T - The value type of the field
|
|
105
|
+
* @param value - The initial value for the field
|
|
106
|
+
* @returns Initial field state
|
|
107
|
+
*/
|
|
108
|
+
export declare function createInitialFieldState<T>(value: T): FieldState<T>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A single option returned by a data source resolver.
|
|
112
|
+
*
|
|
113
|
+
* @typeParam T - The data type for additional option metadata
|
|
114
|
+
*/
|
|
115
|
+
export declare interface DataSourceOption<T = unknown> {
|
|
116
|
+
/** The value stored when this option is selected */
|
|
117
|
+
readonly value: string;
|
|
118
|
+
/** The display label for this option */
|
|
119
|
+
readonly label: string;
|
|
120
|
+
/** Optional additional data associated with this option */
|
|
121
|
+
readonly data?: T;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Registry for dynamic data sources.
|
|
126
|
+
*
|
|
127
|
+
* Extend this interface via module augmentation to register your data sources:
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* declare module "@formspec/core" {
|
|
132
|
+
* interface DataSourceRegistry {
|
|
133
|
+
* countries: { id: string; code: string; name: string };
|
|
134
|
+
* templates: { id: string; name: string; category: string };
|
|
135
|
+
* }
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare interface DataSourceRegistry {
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Gets the value type for a registered data source.
|
|
144
|
+
*
|
|
145
|
+
* If the source has an `id` property, that becomes the value type.
|
|
146
|
+
* Otherwise, defaults to `string`.
|
|
147
|
+
*/
|
|
148
|
+
export declare type DataSourceValueType<Source extends string> = Source extends keyof DataSourceRegistry ? DataSourceRegistry[Source] extends {
|
|
149
|
+
id: infer ID;
|
|
150
|
+
} ? ID : string : string;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A field with dynamic enum options (fetched from a data source at runtime).
|
|
154
|
+
*
|
|
155
|
+
* @typeParam N - The field name (string literal type)
|
|
156
|
+
* @typeParam Source - The data source key (from DataSourceRegistry)
|
|
157
|
+
*/
|
|
158
|
+
export declare interface DynamicEnumField<N extends string, Source extends string> {
|
|
159
|
+
/** Type discriminator for form elements */
|
|
160
|
+
readonly _type: "field";
|
|
161
|
+
/** Field type discriminator - identifies this as a dynamic enum field */
|
|
162
|
+
readonly _field: "dynamic_enum";
|
|
163
|
+
/** Unique field identifier used as the schema key */
|
|
164
|
+
readonly name: N;
|
|
165
|
+
/** Data source key for fetching options at runtime */
|
|
166
|
+
readonly source: Source;
|
|
167
|
+
/** Display label for the field */
|
|
168
|
+
readonly label?: string;
|
|
169
|
+
/** Whether this field is required for form submission */
|
|
170
|
+
readonly required?: boolean;
|
|
171
|
+
/** Field names whose values are needed to fetch options */
|
|
172
|
+
readonly params?: readonly string[];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* A field that loads its schema dynamically (e.g., from an extension).
|
|
177
|
+
*
|
|
178
|
+
* @typeParam N - The field name (string literal type)
|
|
179
|
+
*/
|
|
180
|
+
export declare interface DynamicSchemaField<N extends string> {
|
|
181
|
+
/** Type discriminator for form elements */
|
|
182
|
+
readonly _type: "field";
|
|
183
|
+
/** Field type discriminator - identifies this as a dynamic schema field */
|
|
184
|
+
readonly _field: "dynamic_schema";
|
|
185
|
+
/** Unique field identifier used as the schema key */
|
|
186
|
+
readonly name: N;
|
|
187
|
+
/** Identifier for the schema source */
|
|
188
|
+
readonly schemaSource: string;
|
|
189
|
+
/** Display label for the field */
|
|
190
|
+
readonly label?: string;
|
|
191
|
+
/** Whether this field is required for form submission */
|
|
192
|
+
readonly required?: boolean;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* An enum option with a separate ID and display label.
|
|
197
|
+
*
|
|
198
|
+
* Use this when the stored value (id) should differ from the display text (label).
|
|
199
|
+
*/
|
|
200
|
+
export declare interface EnumOption {
|
|
201
|
+
readonly id: string;
|
|
202
|
+
readonly label: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Valid enum option types: either plain strings or objects with id/label.
|
|
207
|
+
*/
|
|
208
|
+
export declare type EnumOptionValue = string | EnumOption;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Predicate types for conditional logic.
|
|
212
|
+
*
|
|
213
|
+
* Predicates are used with `when()` to define conditions in a readable way.
|
|
214
|
+
*/
|
|
215
|
+
/**
|
|
216
|
+
* An equality predicate that checks if a field equals a specific value.
|
|
217
|
+
*
|
|
218
|
+
* @typeParam K - The field name to check
|
|
219
|
+
* @typeParam V - The value to compare against
|
|
220
|
+
*/
|
|
221
|
+
export declare interface EqualsPredicate<K extends string, V> {
|
|
222
|
+
/** Predicate type discriminator */
|
|
223
|
+
readonly _predicate: "equals";
|
|
224
|
+
/** Name of the field to check */
|
|
225
|
+
readonly field: K;
|
|
226
|
+
/** Value that the field must equal */
|
|
227
|
+
readonly value: V;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Response from a data source resolver function.
|
|
232
|
+
*
|
|
233
|
+
* @typeParam T - The data type for option metadata
|
|
234
|
+
*/
|
|
235
|
+
export declare interface FetchOptionsResponse<T = unknown> {
|
|
236
|
+
/** The available options */
|
|
237
|
+
readonly options: readonly DataSourceOption<T>[];
|
|
238
|
+
/** Validity state of the fetch operation */
|
|
239
|
+
readonly validity: "valid" | "invalid" | "unknown";
|
|
240
|
+
/** Optional message (e.g., error description) */
|
|
241
|
+
readonly message?: string;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Represents the runtime state of a single form field.
|
|
246
|
+
*
|
|
247
|
+
* @typeParam T - The value type of the field
|
|
248
|
+
*/
|
|
249
|
+
export declare interface FieldState<T> {
|
|
250
|
+
/** Current value of the field */
|
|
251
|
+
readonly value: T;
|
|
252
|
+
/** Whether the field has been modified by the user */
|
|
253
|
+
readonly dirty: boolean;
|
|
254
|
+
/** Whether the field has been focused and blurred */
|
|
255
|
+
readonly touched: boolean;
|
|
256
|
+
/** Current validity state */
|
|
257
|
+
readonly validity: Validity;
|
|
258
|
+
/** Validation error messages, if any */
|
|
259
|
+
readonly errors: readonly string[];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Union of all form element types (fields and structural elements).
|
|
264
|
+
*/
|
|
265
|
+
export declare type FormElement = AnyField | Group<readonly FormElement[]> | Conditional<string, unknown, readonly FormElement[]>;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* A complete form specification.
|
|
269
|
+
*
|
|
270
|
+
* @typeParam Elements - Tuple of top-level form elements
|
|
271
|
+
*/
|
|
272
|
+
export declare interface FormSpec<Elements extends readonly FormElement[]> {
|
|
273
|
+
/** Top-level form elements */
|
|
274
|
+
readonly elements: Elements;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Names of all built-in FormSpec decorators. */
|
|
278
|
+
export declare const FORMSPEC_DECORATOR_NAMES: readonly ["Field", "Group", "ShowWhen", "EnumOptions", "Minimum", "Maximum", "ExclusiveMinimum", "ExclusiveMaximum", "MinLength", "MaxLength", "Pattern"];
|
|
279
|
+
|
|
280
|
+
/** Type of a FormSpec decorator name. */
|
|
281
|
+
export declare type FormSpecDecoratorName = (typeof FORMSPEC_DECORATOR_NAMES)[number];
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Represents the runtime state of an entire form.
|
|
285
|
+
*
|
|
286
|
+
* @typeParam Schema - The form schema type (maps field names to value types)
|
|
287
|
+
*/
|
|
288
|
+
export declare interface FormState<Schema extends Record<string, unknown>> {
|
|
289
|
+
/** State for each field, keyed by field name */
|
|
290
|
+
readonly fields: {
|
|
291
|
+
readonly [K in keyof Schema]: FieldState<Schema[K]>;
|
|
292
|
+
};
|
|
293
|
+
/** Whether any field has been modified */
|
|
294
|
+
readonly dirty: boolean;
|
|
295
|
+
/** Whether the form is currently being submitted */
|
|
296
|
+
readonly submitting: boolean;
|
|
297
|
+
/** Overall form validity (derived from all field validities) */
|
|
298
|
+
readonly validity: Validity;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A visual grouping of form elements.
|
|
303
|
+
*
|
|
304
|
+
* Groups provide visual organization and can be rendered as fieldsets or sections.
|
|
305
|
+
*
|
|
306
|
+
* @typeParam Elements - Tuple of contained form elements
|
|
307
|
+
*/
|
|
308
|
+
export declare interface Group<Elements extends readonly FormElement[]> {
|
|
309
|
+
/** Type discriminator - identifies this as a group element */
|
|
310
|
+
readonly _type: "group";
|
|
311
|
+
/** Display label for the group */
|
|
312
|
+
readonly label: string;
|
|
313
|
+
/** Form elements contained within this group */
|
|
314
|
+
readonly elements: Elements;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* A numeric input field.
|
|
319
|
+
*
|
|
320
|
+
* @typeParam N - The field name (string literal type)
|
|
321
|
+
*/
|
|
322
|
+
export declare interface NumberField<N extends string> {
|
|
323
|
+
/** Type discriminator for form elements */
|
|
324
|
+
readonly _type: "field";
|
|
325
|
+
/** Field type discriminator - identifies this as a number field */
|
|
326
|
+
readonly _field: "number";
|
|
327
|
+
/** Unique field identifier used as the schema key */
|
|
328
|
+
readonly name: N;
|
|
329
|
+
/** Display label for the field */
|
|
330
|
+
readonly label?: string;
|
|
331
|
+
/** Minimum allowed value */
|
|
332
|
+
readonly min?: number;
|
|
333
|
+
/** Maximum allowed value */
|
|
334
|
+
readonly max?: number;
|
|
335
|
+
/** Whether this field is required for form submission */
|
|
336
|
+
readonly required?: boolean;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* An object field containing nested properties.
|
|
341
|
+
*
|
|
342
|
+
* Use this for grouping related fields under a single key in the schema.
|
|
343
|
+
*
|
|
344
|
+
* @typeParam N - The field name (string literal type)
|
|
345
|
+
* @typeParam Properties - The form elements that define the object's properties
|
|
346
|
+
*/
|
|
347
|
+
export declare interface ObjectField<N extends string, Properties extends readonly FormElement[]> {
|
|
348
|
+
/** Type discriminator for form elements */
|
|
349
|
+
readonly _type: "field";
|
|
350
|
+
/** Field type discriminator - identifies this as an object field */
|
|
351
|
+
readonly _field: "object";
|
|
352
|
+
/** Unique field identifier used as the schema key */
|
|
353
|
+
readonly name: N;
|
|
354
|
+
/** Form elements that define the properties of this object */
|
|
355
|
+
readonly properties: Properties;
|
|
356
|
+
/** Display label for the field */
|
|
357
|
+
readonly label?: string;
|
|
358
|
+
/** Whether this field is required for form submission */
|
|
359
|
+
readonly required?: boolean;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Union of all predicate types.
|
|
364
|
+
*
|
|
365
|
+
* Currently only supports equality, but can be extended with:
|
|
366
|
+
* - `OneOfPredicate` - field value is one of several options
|
|
367
|
+
* - `NotPredicate` - negation of another predicate
|
|
368
|
+
* - `AndPredicate` / `OrPredicate` - logical combinations
|
|
369
|
+
*/
|
|
370
|
+
export declare type Predicate<K extends string = string, V = unknown> = EqualsPredicate<K, V>;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* A field with static enum options (known at compile time).
|
|
374
|
+
*
|
|
375
|
+
* Options can be plain strings or objects with `id` and `label` properties.
|
|
376
|
+
*
|
|
377
|
+
* @typeParam N - The field name (string literal type)
|
|
378
|
+
* @typeParam O - Tuple of option values (strings or EnumOption objects)
|
|
379
|
+
*/
|
|
380
|
+
export declare interface StaticEnumField<N extends string, O extends readonly EnumOptionValue[]> {
|
|
381
|
+
/** Type discriminator for form elements */
|
|
382
|
+
readonly _type: "field";
|
|
383
|
+
/** Field type discriminator - identifies this as an enum field */
|
|
384
|
+
readonly _field: "enum";
|
|
385
|
+
/** Unique field identifier used as the schema key */
|
|
386
|
+
readonly name: N;
|
|
387
|
+
/** Array of allowed option values */
|
|
388
|
+
readonly options: O;
|
|
389
|
+
/** Display label for the field */
|
|
390
|
+
readonly label?: string;
|
|
391
|
+
/** Whether this field is required for form submission */
|
|
392
|
+
readonly required?: boolean;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Form element type definitions.
|
|
397
|
+
*
|
|
398
|
+
* These types define the structure of form specifications.
|
|
399
|
+
* The structure IS the definition - nesting implies layout and conditional logic.
|
|
400
|
+
*/
|
|
401
|
+
/**
|
|
402
|
+
* A text input field.
|
|
403
|
+
*
|
|
404
|
+
* @typeParam N - The field name (string literal type)
|
|
405
|
+
*/
|
|
406
|
+
export declare interface TextField<N extends string> {
|
|
407
|
+
/** Type discriminator for form elements */
|
|
408
|
+
readonly _type: "field";
|
|
409
|
+
/** Field type discriminator - identifies this as a text field */
|
|
410
|
+
readonly _field: "text";
|
|
411
|
+
/** Unique field identifier used as the schema key */
|
|
412
|
+
readonly name: N;
|
|
413
|
+
/** Display label for the field */
|
|
414
|
+
readonly label?: string;
|
|
415
|
+
/** Placeholder text shown when field is empty */
|
|
416
|
+
readonly placeholder?: string;
|
|
417
|
+
/** Whether this field is required for form submission */
|
|
418
|
+
readonly required?: boolean;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Represents the validity state of a field or form.
|
|
423
|
+
*
|
|
424
|
+
* - `"valid"` - All validations pass
|
|
425
|
+
* - `"invalid"` - One or more validations failed
|
|
426
|
+
* - `"unknown"` - Validation state not yet determined (e.g., async validation pending)
|
|
427
|
+
*/
|
|
428
|
+
export declare type Validity = "valid" | "invalid" | "unknown";
|
|
429
|
+
|
|
430
|
+
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
|
11
|
-
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, } from "./types/index.js";
|
|
12
|
-
export { createInitialFieldState } from "./types/index.js";
|
|
11
|
+
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, FormSpecDecoratorName, ConstraintTagName, } from "./types/index.js";
|
|
12
|
+
export { createInitialFieldState, FORMSPEC_DECORATOR_NAMES, CONSTRAINT_TAG_DEFINITIONS, } from "./types/index.js";
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;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,EACrB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
|
11
11
|
// Re-export functions
|
|
12
|
-
export { createInitialFieldState } from "./types/index.js";
|
|
12
|
+
export { createInitialFieldState, FORMSPEC_DECORATOR_NAMES, CONSTRAINT_TAG_DEFINITIONS, } from "./types/index.js";
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA6CH,sBAAsB;AACtB,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-source.d.ts","sourceRoot":"","sources":["../../src/types/data-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,kBAAkB;CAElC;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,wCAAwC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,OAAO;IAC/C,4BAA4B;IAC5B,QAAQ,CAAC,OAAO,EAA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1
|
+
/**
|
|
2
|
+
* Canonical set of FormSpec decorator names.
|
|
3
|
+
*
|
|
4
|
+
* This is the single source of truth for which decorators FormSpec recognizes.
|
|
5
|
+
* Both `@formspec/eslint-plugin` and `@formspec/build` import from here.
|
|
6
|
+
*/
|
|
7
|
+
/** Names of all built-in FormSpec decorators. */
|
|
8
|
+
export declare const FORMSPEC_DECORATOR_NAMES: readonly ["Field", "Group", "ShowWhen", "EnumOptions", "Minimum", "Maximum", "ExclusiveMinimum", "ExclusiveMaximum", "MinLength", "MaxLength", "Pattern"];
|
|
9
|
+
/** Type of a FormSpec decorator name. */
|
|
10
|
+
export type FormSpecDecoratorName = (typeof FORMSPEC_DECORATOR_NAMES)[number];
|
|
11
|
+
/**
|
|
12
|
+
* Constraint decorator names that are valid as TSDoc tags, mapped to
|
|
13
|
+
* their expected value type for parsing.
|
|
14
|
+
*
|
|
15
|
+
* Both `@formspec/build` (schema generation) and `@formspec/eslint-plugin`
|
|
16
|
+
* (lint-time validation) import this to determine which JSDoc tags to
|
|
17
|
+
* recognize and how to parse their values.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CONSTRAINT_TAG_DEFINITIONS: {
|
|
20
|
+
readonly Minimum: "number";
|
|
21
|
+
readonly Maximum: "number";
|
|
22
|
+
readonly ExclusiveMinimum: "number";
|
|
23
|
+
readonly ExclusiveMaximum: "number";
|
|
24
|
+
readonly MinLength: "number";
|
|
25
|
+
readonly MaxLength: "number";
|
|
26
|
+
readonly Pattern: "string";
|
|
27
|
+
};
|
|
28
|
+
/** Type of a constraint tag name. */
|
|
29
|
+
export type ConstraintTagName = keyof typeof CONSTRAINT_TAG_DEFINITIONS;
|
|
30
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/types/decorators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iDAAiD;AACjD,eAAO,MAAM,wBAAwB,2JAY3B,CAAC;AAEX,yCAAyC;AACzC,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9E;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;CAQ7B,CAAC;AAEX,qCAAqC;AACrC,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical set of FormSpec decorator names.
|
|
3
|
+
*
|
|
4
|
+
* This is the single source of truth for which decorators FormSpec recognizes.
|
|
5
|
+
* Both `@formspec/eslint-plugin` and `@formspec/build` import from here.
|
|
6
|
+
*/
|
|
7
|
+
/** Names of all built-in FormSpec decorators. */
|
|
8
|
+
export const FORMSPEC_DECORATOR_NAMES = [
|
|
9
|
+
"Field",
|
|
10
|
+
"Group",
|
|
11
|
+
"ShowWhen",
|
|
12
|
+
"EnumOptions",
|
|
13
|
+
"Minimum",
|
|
14
|
+
"Maximum",
|
|
15
|
+
"ExclusiveMinimum",
|
|
16
|
+
"ExclusiveMaximum",
|
|
17
|
+
"MinLength",
|
|
18
|
+
"MaxLength",
|
|
19
|
+
"Pattern",
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Constraint decorator names that are valid as TSDoc tags, mapped to
|
|
23
|
+
* their expected value type for parsing.
|
|
24
|
+
*
|
|
25
|
+
* Both `@formspec/build` (schema generation) and `@formspec/eslint-plugin`
|
|
26
|
+
* (lint-time validation) import this to determine which JSDoc tags to
|
|
27
|
+
* recognize and how to parse their values.
|
|
28
|
+
*/
|
|
29
|
+
export const CONSTRAINT_TAG_DEFINITIONS = {
|
|
30
|
+
Minimum: "number",
|
|
31
|
+
Maximum: "number",
|
|
32
|
+
ExclusiveMinimum: "number",
|
|
33
|
+
ExclusiveMaximum: "number",
|
|
34
|
+
MinLength: "number",
|
|
35
|
+
MaxLength: "number",
|
|
36
|
+
Pattern: "string",
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/types/decorators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iDAAiD;AACjD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,OAAO;IACP,OAAO;IACP,UAAU;IACV,aAAa;IACb,SAAS;IACT,SAAS;IACT,kBAAkB;IAClB,kBAAkB;IAClB,WAAW;IACX,WAAW;IACX,SAAS;CACD,CAAC;AAKX;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,gBAAgB,EAAE,QAAQ;IAC1B,gBAAgB,EAAE,QAAQ;IAC1B,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;IACnB,OAAO,EAAE,QAAQ;CACT,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,4 +5,6 @@ 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 { FORMSPEC_DECORATOR_NAMES, CONSTRAINT_TAG_DEFINITIONS } from "./decorators.js";
|
|
9
|
+
export type { FormSpecDecoratorName, ConstraintTagName } from "./decorators.js";
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,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AAwB,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AACvF,YAAY,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/types/index.js
CHANGED
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAK/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAK/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AA+B3D,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formspec/core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.9",
|
|
4
4
|
"description": "Core utilities for formspec",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
16
17
|
],
|
|
17
18
|
"publishConfig": {
|
|
18
19
|
"access": "public"
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"keywords": [],
|
|
21
22
|
"license": "UNLICENSED",
|
|
22
23
|
"scripts": {
|
|
23
|
-
"build": "tsc",
|
|
24
|
+
"build": "tsc && api-extractor run --local",
|
|
24
25
|
"clean": "rm -rf dist temp",
|
|
25
26
|
"typecheck": "tsc --noEmit",
|
|
26
27
|
"api-extractor": "api-extractor run",
|