formspec 0.1.0-alpha.2 → 0.1.0-alpha.20
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 +89 -0
- package/dist/formspec.d.ts +299 -0
- package/dist/index.cjs +85 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -66
- package/dist/index.js.map +1 -1
- package/package.json +12 -9
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# formspec
|
|
2
|
+
|
|
3
|
+
Umbrella package for the common FormSpec authoring and runtime APIs.
|
|
4
|
+
|
|
5
|
+
It re-exports the most commonly used pieces from:
|
|
6
|
+
|
|
7
|
+
- `@formspec/core`
|
|
8
|
+
- `@formspec/dsl`
|
|
9
|
+
- `@formspec/build`
|
|
10
|
+
- `@formspec/runtime`
|
|
11
|
+
|
|
12
|
+
It does not include the CLI, ESLint plugin, language server, or playground app.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add formspec
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import {
|
|
24
|
+
buildFormSchemas,
|
|
25
|
+
defineResolvers,
|
|
26
|
+
field,
|
|
27
|
+
formspec,
|
|
28
|
+
group,
|
|
29
|
+
is,
|
|
30
|
+
type InferFormSchema,
|
|
31
|
+
when,
|
|
32
|
+
} from "formspec";
|
|
33
|
+
|
|
34
|
+
const OrderForm = formspec(
|
|
35
|
+
group(
|
|
36
|
+
"Order",
|
|
37
|
+
field.text("customerName", { required: true }),
|
|
38
|
+
field.enum("status", ["draft", "submitted"] as const, { required: true })
|
|
39
|
+
),
|
|
40
|
+
when(is("status", "submitted"), field.text("submittedBy"))
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
type OrderData = InferFormSchema<typeof OrderForm>;
|
|
44
|
+
|
|
45
|
+
const { jsonSchema, uiSchema } = buildFormSchemas(OrderForm);
|
|
46
|
+
|
|
47
|
+
const resolvers = defineResolvers(OrderForm, {});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## What You Get
|
|
51
|
+
|
|
52
|
+
### DSL
|
|
53
|
+
|
|
54
|
+
- `formspec`
|
|
55
|
+
- `field`
|
|
56
|
+
- `group`
|
|
57
|
+
- `when`
|
|
58
|
+
- `is`
|
|
59
|
+
- `formspecWithValidation`
|
|
60
|
+
- `validateForm`
|
|
61
|
+
|
|
62
|
+
### Build
|
|
63
|
+
|
|
64
|
+
- `buildFormSchemas`
|
|
65
|
+
- `generateJsonSchema`
|
|
66
|
+
- `generateUiSchema`
|
|
67
|
+
- `writeSchemas`
|
|
68
|
+
- `buildMixedAuthoringSchemas`
|
|
69
|
+
|
|
70
|
+
### Runtime
|
|
71
|
+
|
|
72
|
+
- `defineResolvers`
|
|
73
|
+
|
|
74
|
+
### Types
|
|
75
|
+
|
|
76
|
+
- `InferSchema`
|
|
77
|
+
- `InferFormSchema`
|
|
78
|
+
- core field, layout, and state types
|
|
79
|
+
|
|
80
|
+
## When To Use Individual Packages
|
|
81
|
+
|
|
82
|
+
- Use `@formspec/build` directly for `generateSchemas()` and static TypeScript analysis.
|
|
83
|
+
- Use `@formspec/eslint-plugin` for lint rules.
|
|
84
|
+
- Use `@formspec/cli` for build-time artifact generation from files.
|
|
85
|
+
- Use `@formspec/validator` for runtime JSON Schema validation.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
UNLICENSED
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FormSpec - Type-safe form specifications
|
|
3
|
+
*
|
|
4
|
+
* This package re-exports everything from the FormSpec library for convenience.
|
|
5
|
+
* You can import everything you need from a single package:
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* // DSL functions
|
|
11
|
+
* formspec, field, group, when, is,
|
|
12
|
+
* // Type inference
|
|
13
|
+
* type InferSchema,
|
|
14
|
+
* // Schema generation
|
|
15
|
+
* buildFormSchemas,
|
|
16
|
+
* // Resolvers
|
|
17
|
+
* defineResolvers,
|
|
18
|
+
* // Core types
|
|
19
|
+
* type FormSpec, type FormElement,
|
|
20
|
+
* } from "formspec";
|
|
21
|
+
*
|
|
22
|
+
* // Define a form
|
|
23
|
+
* const InvoiceForm = formspec(
|
|
24
|
+
* group("Customer",
|
|
25
|
+
* field.text("name", { label: "Name", required: true }),
|
|
26
|
+
* field.dynamicEnum("country", "fetch_countries", { label: "Country" }),
|
|
27
|
+
* ),
|
|
28
|
+
* group("Details",
|
|
29
|
+
* field.number("amount", { label: "Amount", min: 0 }),
|
|
30
|
+
* field.enum("status", ["draft", "sent", "paid"]),
|
|
31
|
+
* when(is("status", "draft"),
|
|
32
|
+
* field.text("notes", { label: "Internal Notes" }),
|
|
33
|
+
* ),
|
|
34
|
+
* ),
|
|
35
|
+
* );
|
|
36
|
+
*
|
|
37
|
+
* // Infer the schema type
|
|
38
|
+
* type Schema = InferSchema<typeof InvoiceForm.elements>;
|
|
39
|
+
*
|
|
40
|
+
* // Generate JSON Schema and UI Schema
|
|
41
|
+
* const { jsonSchema, uiSchema } = buildFormSchemas(InvoiceForm);
|
|
42
|
+
*
|
|
43
|
+
* // Define resolvers for dynamic data
|
|
44
|
+
* const resolvers = defineResolvers(InvoiceForm, {
|
|
45
|
+
* fetch_countries: async () => ({
|
|
46
|
+
* options: [{ value: "us", label: "United States" }],
|
|
47
|
+
* validity: "valid",
|
|
48
|
+
* }),
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @packageDocumentation
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
import { AnyField } from '@formspec/core';
|
|
56
|
+
import { ArrayField } from '@formspec/core';
|
|
57
|
+
import { BooleanField } from '@formspec/core';
|
|
58
|
+
import { buildFormSchemas } from '@formspec/build';
|
|
59
|
+
import { buildMixedAuthoringSchemas } from '@formspec/build';
|
|
60
|
+
import { BuildMixedAuthoringSchemasOptions } from '@formspec/build';
|
|
61
|
+
import { BuildResult } from '@formspec/build';
|
|
62
|
+
import { BuildSchema } from '@formspec/dsl';
|
|
63
|
+
import { Conditional } from '@formspec/core';
|
|
64
|
+
import { ControlElement } from '@formspec/build';
|
|
65
|
+
import { createInitialFieldState } from '@formspec/core';
|
|
66
|
+
import { DataSourceOption } from '@formspec/core';
|
|
67
|
+
import { DataSourceRegistry } from '@formspec/core';
|
|
68
|
+
import { DataSourceValueType } from '@formspec/core';
|
|
69
|
+
import { defineResolvers } from '@formspec/runtime';
|
|
70
|
+
import { DynamicEnumField } from '@formspec/core';
|
|
71
|
+
import { DynamicSchemaField } from '@formspec/core';
|
|
72
|
+
import { EnumOption } from '@formspec/dsl';
|
|
73
|
+
import { EnumOptionValue } from '@formspec/dsl';
|
|
74
|
+
import { EqualsPredicate } from '@formspec/core';
|
|
75
|
+
import { ExtractFields } from '@formspec/dsl';
|
|
76
|
+
import { ExtractFieldsFromArray } from '@formspec/dsl';
|
|
77
|
+
import { FetchOptionsResponse } from '@formspec/core';
|
|
78
|
+
import { field } from '@formspec/dsl';
|
|
79
|
+
import { FieldState } from '@formspec/core';
|
|
80
|
+
import { FormElement } from '@formspec/core';
|
|
81
|
+
import { FormSpec } from '@formspec/core';
|
|
82
|
+
import { formspec } from '@formspec/dsl';
|
|
83
|
+
import { FormSpecOptions } from '@formspec/dsl';
|
|
84
|
+
import { formspecWithValidation } from '@formspec/dsl';
|
|
85
|
+
import { FormState } from '@formspec/core';
|
|
86
|
+
import { generateJsonSchema } from '@formspec/build';
|
|
87
|
+
import { generateUiSchema } from '@formspec/build';
|
|
88
|
+
import { Group } from '@formspec/core';
|
|
89
|
+
import { group } from '@formspec/dsl';
|
|
90
|
+
import { GroupLayout } from '@formspec/build';
|
|
91
|
+
import { HorizontalLayout } from '@formspec/build';
|
|
92
|
+
import { InferFieldValue } from '@formspec/dsl';
|
|
93
|
+
import { InferFormSchema } from '@formspec/dsl';
|
|
94
|
+
import { InferSchema } from '@formspec/dsl';
|
|
95
|
+
import { is } from '@formspec/dsl';
|
|
96
|
+
import { isArrayField } from '@formspec/core';
|
|
97
|
+
import { isBooleanField } from '@formspec/core';
|
|
98
|
+
import { isConditional } from '@formspec/core';
|
|
99
|
+
import { isDynamicEnumField } from '@formspec/core';
|
|
100
|
+
import { isDynamicSchemaField } from '@formspec/core';
|
|
101
|
+
import { isField } from '@formspec/core';
|
|
102
|
+
import { isGroup } from '@formspec/core';
|
|
103
|
+
import { isNumberField } from '@formspec/core';
|
|
104
|
+
import { isObjectField } from '@formspec/core';
|
|
105
|
+
import { isStaticEnumField } from '@formspec/core';
|
|
106
|
+
import { isTextField } from '@formspec/core';
|
|
107
|
+
import { JsonSchema2020 } from '@formspec/build';
|
|
108
|
+
import { JSONSchema7 } from '@formspec/build';
|
|
109
|
+
import { JSONSchemaType } from '@formspec/build';
|
|
110
|
+
import { logValidationIssues } from '@formspec/dsl';
|
|
111
|
+
import { MixedAuthoringSchemas } from '@formspec/build';
|
|
112
|
+
import { NumberField } from '@formspec/core';
|
|
113
|
+
import { ObjectField } from '@formspec/core';
|
|
114
|
+
import { Predicate } from '@formspec/core';
|
|
115
|
+
import { Resolver } from '@formspec/runtime';
|
|
116
|
+
import { ResolverMap } from '@formspec/runtime';
|
|
117
|
+
import { ResolverRegistry } from '@formspec/runtime';
|
|
118
|
+
import { Rule } from '@formspec/build';
|
|
119
|
+
import { RuleEffect } from '@formspec/build';
|
|
120
|
+
import { SchemaBasedCondition } from '@formspec/build';
|
|
121
|
+
import { StaticEnumField } from '@formspec/core';
|
|
122
|
+
import { TextField } from '@formspec/core';
|
|
123
|
+
import { UISchema } from '@formspec/build';
|
|
124
|
+
import { UISchemaElement } from '@formspec/build';
|
|
125
|
+
import { UISchemaElementType } from '@formspec/build';
|
|
126
|
+
import { validateForm } from '@formspec/dsl';
|
|
127
|
+
import { ValidationIssue } from '@formspec/dsl';
|
|
128
|
+
import { ValidationResult } from '@formspec/dsl';
|
|
129
|
+
import { ValidationSeverity } from '@formspec/dsl';
|
|
130
|
+
import { Validity } from '@formspec/core';
|
|
131
|
+
import { VerticalLayout } from '@formspec/build';
|
|
132
|
+
import { when } from '@formspec/dsl';
|
|
133
|
+
import { writeSchemas } from '@formspec/build';
|
|
134
|
+
import { WriteSchemasOptions } from '@formspec/build';
|
|
135
|
+
import { WriteSchemasResult } from '@formspec/build';
|
|
136
|
+
|
|
137
|
+
export { AnyField }
|
|
138
|
+
|
|
139
|
+
export { ArrayField }
|
|
140
|
+
|
|
141
|
+
export { BooleanField }
|
|
142
|
+
|
|
143
|
+
export { buildFormSchemas }
|
|
144
|
+
|
|
145
|
+
export { buildMixedAuthoringSchemas }
|
|
146
|
+
|
|
147
|
+
export { BuildMixedAuthoringSchemasOptions }
|
|
148
|
+
|
|
149
|
+
export { BuildResult }
|
|
150
|
+
|
|
151
|
+
export { BuildSchema }
|
|
152
|
+
|
|
153
|
+
export { Conditional }
|
|
154
|
+
|
|
155
|
+
export { ControlElement }
|
|
156
|
+
|
|
157
|
+
export { createInitialFieldState }
|
|
158
|
+
|
|
159
|
+
export { DataSourceOption }
|
|
160
|
+
|
|
161
|
+
export { DataSourceRegistry }
|
|
162
|
+
|
|
163
|
+
export { DataSourceValueType }
|
|
164
|
+
|
|
165
|
+
export { defineResolvers }
|
|
166
|
+
|
|
167
|
+
export { DynamicEnumField }
|
|
168
|
+
|
|
169
|
+
export { DynamicSchemaField }
|
|
170
|
+
|
|
171
|
+
export { EnumOption }
|
|
172
|
+
|
|
173
|
+
export { EnumOptionValue }
|
|
174
|
+
|
|
175
|
+
export { EqualsPredicate }
|
|
176
|
+
|
|
177
|
+
export { ExtractFields }
|
|
178
|
+
|
|
179
|
+
export { ExtractFieldsFromArray }
|
|
180
|
+
|
|
181
|
+
export { FetchOptionsResponse }
|
|
182
|
+
|
|
183
|
+
export { field }
|
|
184
|
+
|
|
185
|
+
export { FieldState }
|
|
186
|
+
|
|
187
|
+
export { FormElement }
|
|
188
|
+
|
|
189
|
+
export { FormSpec }
|
|
190
|
+
|
|
191
|
+
export { formspec }
|
|
192
|
+
|
|
193
|
+
export { FormSpecOptions }
|
|
194
|
+
|
|
195
|
+
export { formspecWithValidation }
|
|
196
|
+
|
|
197
|
+
export { FormState }
|
|
198
|
+
|
|
199
|
+
export { generateJsonSchema }
|
|
200
|
+
|
|
201
|
+
export { generateUiSchema }
|
|
202
|
+
|
|
203
|
+
export { Group }
|
|
204
|
+
|
|
205
|
+
export { group }
|
|
206
|
+
|
|
207
|
+
export { GroupLayout }
|
|
208
|
+
|
|
209
|
+
export { HorizontalLayout }
|
|
210
|
+
|
|
211
|
+
export { InferFieldValue }
|
|
212
|
+
|
|
213
|
+
export { InferFormSchema }
|
|
214
|
+
|
|
215
|
+
export { InferSchema }
|
|
216
|
+
|
|
217
|
+
export { is }
|
|
218
|
+
|
|
219
|
+
export { isArrayField }
|
|
220
|
+
|
|
221
|
+
export { isBooleanField }
|
|
222
|
+
|
|
223
|
+
export { isConditional }
|
|
224
|
+
|
|
225
|
+
export { isDynamicEnumField }
|
|
226
|
+
|
|
227
|
+
export { isDynamicSchemaField }
|
|
228
|
+
|
|
229
|
+
export { isField }
|
|
230
|
+
|
|
231
|
+
export { isGroup }
|
|
232
|
+
|
|
233
|
+
export { isNumberField }
|
|
234
|
+
|
|
235
|
+
export { isObjectField }
|
|
236
|
+
|
|
237
|
+
export { isStaticEnumField }
|
|
238
|
+
|
|
239
|
+
export { isTextField }
|
|
240
|
+
|
|
241
|
+
export { JsonSchema2020 }
|
|
242
|
+
|
|
243
|
+
export { JSONSchema7 }
|
|
244
|
+
|
|
245
|
+
export { JSONSchemaType }
|
|
246
|
+
|
|
247
|
+
export { logValidationIssues }
|
|
248
|
+
|
|
249
|
+
export { MixedAuthoringSchemas }
|
|
250
|
+
|
|
251
|
+
export { NumberField }
|
|
252
|
+
|
|
253
|
+
export { ObjectField }
|
|
254
|
+
|
|
255
|
+
export { Predicate }
|
|
256
|
+
|
|
257
|
+
export { Resolver }
|
|
258
|
+
|
|
259
|
+
export { ResolverMap }
|
|
260
|
+
|
|
261
|
+
export { ResolverRegistry }
|
|
262
|
+
|
|
263
|
+
export { Rule }
|
|
264
|
+
|
|
265
|
+
export { RuleEffect }
|
|
266
|
+
|
|
267
|
+
export { SchemaBasedCondition }
|
|
268
|
+
|
|
269
|
+
export { StaticEnumField }
|
|
270
|
+
|
|
271
|
+
export { TextField }
|
|
272
|
+
|
|
273
|
+
export { UISchema }
|
|
274
|
+
|
|
275
|
+
export { UISchemaElement }
|
|
276
|
+
|
|
277
|
+
export { UISchemaElementType }
|
|
278
|
+
|
|
279
|
+
export { validateForm }
|
|
280
|
+
|
|
281
|
+
export { ValidationIssue }
|
|
282
|
+
|
|
283
|
+
export { ValidationResult }
|
|
284
|
+
|
|
285
|
+
export { ValidationSeverity }
|
|
286
|
+
|
|
287
|
+
export { Validity }
|
|
288
|
+
|
|
289
|
+
export { VerticalLayout }
|
|
290
|
+
|
|
291
|
+
export { when }
|
|
292
|
+
|
|
293
|
+
export { writeSchemas }
|
|
294
|
+
|
|
295
|
+
export { WriteSchemasOptions }
|
|
296
|
+
|
|
297
|
+
export { WriteSchemasResult }
|
|
298
|
+
|
|
299
|
+
export { }
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
buildFormSchemas: () => import_build.buildFormSchemas,
|
|
24
|
+
buildMixedAuthoringSchemas: () => import_build.buildMixedAuthoringSchemas,
|
|
25
|
+
createInitialFieldState: () => import_core.createInitialFieldState,
|
|
26
|
+
defineResolvers: () => import_runtime.defineResolvers,
|
|
27
|
+
field: () => import_dsl.field,
|
|
28
|
+
formspec: () => import_dsl.formspec,
|
|
29
|
+
formspecWithValidation: () => import_dsl.formspecWithValidation,
|
|
30
|
+
generateJsonSchema: () => import_build.generateJsonSchema,
|
|
31
|
+
generateUiSchema: () => import_build.generateUiSchema,
|
|
32
|
+
group: () => import_dsl.group,
|
|
33
|
+
is: () => import_dsl.is,
|
|
34
|
+
isArrayField: () => import_core2.isArrayField,
|
|
35
|
+
isBooleanField: () => import_core2.isBooleanField,
|
|
36
|
+
isConditional: () => import_core2.isConditional,
|
|
37
|
+
isDynamicEnumField: () => import_core2.isDynamicEnumField,
|
|
38
|
+
isDynamicSchemaField: () => import_core2.isDynamicSchemaField,
|
|
39
|
+
isField: () => import_core2.isField,
|
|
40
|
+
isGroup: () => import_core2.isGroup,
|
|
41
|
+
isNumberField: () => import_core2.isNumberField,
|
|
42
|
+
isObjectField: () => import_core2.isObjectField,
|
|
43
|
+
isStaticEnumField: () => import_core2.isStaticEnumField,
|
|
44
|
+
isTextField: () => import_core2.isTextField,
|
|
45
|
+
logValidationIssues: () => import_dsl.logValidationIssues,
|
|
46
|
+
validateForm: () => import_dsl.validateForm,
|
|
47
|
+
when: () => import_dsl.when,
|
|
48
|
+
writeSchemas: () => import_build.writeSchemas
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(index_exports);
|
|
51
|
+
var import_core = require("@formspec/core");
|
|
52
|
+
var import_core2 = require("@formspec/core");
|
|
53
|
+
var import_dsl = require("@formspec/dsl");
|
|
54
|
+
var import_build = require("@formspec/build");
|
|
55
|
+
var import_runtime = require("@formspec/runtime");
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
buildFormSchemas,
|
|
59
|
+
buildMixedAuthoringSchemas,
|
|
60
|
+
createInitialFieldState,
|
|
61
|
+
defineResolvers,
|
|
62
|
+
field,
|
|
63
|
+
formspec,
|
|
64
|
+
formspecWithValidation,
|
|
65
|
+
generateJsonSchema,
|
|
66
|
+
generateUiSchema,
|
|
67
|
+
group,
|
|
68
|
+
is,
|
|
69
|
+
isArrayField,
|
|
70
|
+
isBooleanField,
|
|
71
|
+
isConditional,
|
|
72
|
+
isDynamicEnumField,
|
|
73
|
+
isDynamicSchemaField,
|
|
74
|
+
isField,
|
|
75
|
+
isGroup,
|
|
76
|
+
isNumberField,
|
|
77
|
+
isObjectField,
|
|
78
|
+
isStaticEnumField,
|
|
79
|
+
isTextField,
|
|
80
|
+
logValidationIssues,
|
|
81
|
+
validateForm,
|
|
82
|
+
when,
|
|
83
|
+
writeSchemas
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * FormSpec - Type-safe form specifications\n *\n * This package re-exports everything from the FormSpec library for convenience.\n * You can import everything you need from a single package:\n *\n * @example\n * ```typescript\n * import {\n * // DSL functions\n * formspec, field, group, when, is,\n * // Type inference\n * type InferSchema,\n * // Schema generation\n * buildFormSchemas,\n * // Resolvers\n * defineResolvers,\n * // Core types\n * type FormSpec, type FormElement,\n * } from \"formspec\";\n *\n * // Define a form\n * const InvoiceForm = formspec(\n * group(\"Customer\",\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.dynamicEnum(\"country\", \"fetch_countries\", { label: \"Country\" }),\n * ),\n * group(\"Details\",\n * field.number(\"amount\", { label: \"Amount\", min: 0 }),\n * field.enum(\"status\", [\"draft\", \"sent\", \"paid\"]),\n * when(is(\"status\", \"draft\"),\n * field.text(\"notes\", { label: \"Internal Notes\" }),\n * ),\n * ),\n * );\n *\n * // Infer the schema type\n * type Schema = InferSchema<typeof InvoiceForm.elements>;\n *\n * // Generate JSON Schema and UI Schema\n * const { jsonSchema, uiSchema } = buildFormSchemas(InvoiceForm);\n *\n * // Define resolvers for dynamic data\n * const resolvers = defineResolvers(InvoiceForm, {\n * fetch_countries: async () => ({\n * options: [{ value: \"us\", label: \"United States\" }],\n * validity: \"valid\",\n * }),\n * });\n * ```\n *\n * @packageDocumentation\n */\n\n// =============================================================================\n// Core types\n// =============================================================================\n\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 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} from \"@formspec/core\";\n\nexport { createInitialFieldState } from \"@formspec/core\";\n\n// 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 \"@formspec/core\";\n\n// =============================================================================\n// DSL functions\n// =============================================================================\n\nexport {\n field,\n group,\n when,\n is,\n formspec,\n formspecWithValidation,\n validateForm,\n logValidationIssues,\n} from \"@formspec/dsl\";\n\n// Re-export enum option types (commonly used)\nexport type { EnumOption, EnumOptionValue } from \"@formspec/dsl\";\n\nexport type {\n // Type inference\n InferFieldValue,\n ExtractFields,\n ExtractFieldsFromArray,\n BuildSchema,\n InferSchema,\n InferFormSchema,\n // Validation\n FormSpecOptions,\n ValidationSeverity,\n ValidationIssue,\n ValidationResult,\n} from \"@formspec/dsl\";\n\n// =============================================================================\n// Build tools\n// =============================================================================\n\nexport {\n generateJsonSchema,\n generateUiSchema,\n buildFormSchemas,\n buildMixedAuthoringSchemas,\n writeSchemas,\n} from \"@formspec/build\";\n\nexport type {\n JsonSchema2020,\n JSONSchema7,\n JSONSchemaType,\n UISchema,\n UISchemaElement,\n UISchemaElementType,\n ControlElement,\n VerticalLayout,\n HorizontalLayout,\n GroupLayout,\n Rule,\n RuleEffect,\n SchemaBasedCondition,\n BuildResult,\n BuildMixedAuthoringSchemasOptions,\n MixedAuthoringSchemas,\n WriteSchemasOptions,\n WriteSchemasResult,\n} from \"@formspec/build\";\n\n// =============================================================================\n// Runtime helpers\n// =============================================================================\n\nexport { defineResolvers } from \"@formspec/runtime\";\n\nexport type { Resolver, ResolverMap, ResolverRegistry } from \"@formspec/runtime\";\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8FA,kBAAwC;AAGxC,IAAAA,eAYO;AAMP,iBASO;AAwBP,mBAMO;AA2BP,qBAAgC;","names":["import_core"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -53,10 +53,12 @@
|
|
|
53
53
|
*/
|
|
54
54
|
export type { Validity, FieldState, FormState, DataSourceRegistry, DataSourceOption, FetchOptionsResponse, DataSourceValueType, TextField, NumberField, BooleanField, StaticEnumField, DynamicEnumField, DynamicSchemaField, ArrayField, ObjectField, AnyField, Group, Conditional, FormElement, FormSpec, EqualsPredicate, Predicate, } from "@formspec/core";
|
|
55
55
|
export { createInitialFieldState } from "@formspec/core";
|
|
56
|
-
export {
|
|
56
|
+
export { isField, isTextField, isNumberField, isBooleanField, isStaticEnumField, isDynamicEnumField, isDynamicSchemaField, isArrayField, isObjectField, isGroup, isConditional, } from "@formspec/core";
|
|
57
|
+
export { field, group, when, is, formspec, formspecWithValidation, validateForm, logValidationIssues, } from "@formspec/dsl";
|
|
58
|
+
export type { EnumOption, EnumOptionValue } from "@formspec/dsl";
|
|
57
59
|
export type { InferFieldValue, ExtractFields, ExtractFieldsFromArray, BuildSchema, InferSchema, InferFormSchema, FormSpecOptions, ValidationSeverity, ValidationIssue, ValidationResult, } from "@formspec/dsl";
|
|
58
|
-
export { generateJsonSchema, generateUiSchema, buildFormSchemas, writeSchemas, } from "@formspec/build";
|
|
59
|
-
export type { JSONSchema7, JSONSchemaType, UISchema, UISchemaElement, UISchemaElementType, ControlElement, VerticalLayout, HorizontalLayout, GroupLayout, Rule, RuleEffect, SchemaBasedCondition, BuildResult, WriteSchemasOptions, WriteSchemasResult, } from "@formspec/build";
|
|
60
|
+
export { generateJsonSchema, generateUiSchema, buildFormSchemas, buildMixedAuthoringSchemas, writeSchemas, } from "@formspec/build";
|
|
61
|
+
export type { JsonSchema2020, JSONSchema7, JSONSchemaType, UISchema, UISchemaElement, UISchemaElementType, ControlElement, VerticalLayout, HorizontalLayout, GroupLayout, Rule, RuleEffect, SchemaBasedCondition, BuildResult, BuildMixedAuthoringSchemasOptions, MixedAuthoringSchemas, WriteSchemasOptions, WriteSchemasResult, } from "@formspec/build";
|
|
60
62
|
export { defineResolvers } from "@formspec/runtime";
|
|
61
|
-
export type { Resolver, ResolverMap, ResolverRegistry
|
|
63
|
+
export type { Resolver, ResolverMap, ResolverRegistry } from "@formspec/runtime";
|
|
62
64
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAMH,YAAY,EAEV,QAAQ,EAGR,UAAU,EAGV,SAAS,EAGT,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EAGnB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EAGR,eAAe,EACf,SAAS,GACV,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAMH,YAAY,EAEV,QAAQ,EAGR,UAAU,EAGV,SAAS,EAGT,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EAGnB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EAGR,eAAe,EACf,SAAS,GACV,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,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,gBAAgB,CAAC;AAMxB,OAAO,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,EAAE,EACF,QAAQ,EACR,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAGvB,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEjE,YAAY,EAEV,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,eAAe,EAEf,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAMvB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC1B,YAAY,GACb,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,cAAc,EACd,WAAW,EACX,cAAc,EACd,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,IAAI,EACJ,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,67 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export { generateJsonSchema, generateUiSchema, buildFormSchemas, writeSchemas, } from "@formspec/build";
|
|
63
|
-
// =============================================================================
|
|
64
|
-
// Runtime helpers
|
|
65
|
-
// =============================================================================
|
|
66
|
-
export { defineResolvers } from "@formspec/runtime";
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createInitialFieldState } from "@formspec/core";
|
|
3
|
+
import {
|
|
4
|
+
isField,
|
|
5
|
+
isTextField,
|
|
6
|
+
isNumberField,
|
|
7
|
+
isBooleanField,
|
|
8
|
+
isStaticEnumField,
|
|
9
|
+
isDynamicEnumField,
|
|
10
|
+
isDynamicSchemaField,
|
|
11
|
+
isArrayField,
|
|
12
|
+
isObjectField,
|
|
13
|
+
isGroup,
|
|
14
|
+
isConditional
|
|
15
|
+
} from "@formspec/core";
|
|
16
|
+
import {
|
|
17
|
+
field,
|
|
18
|
+
group,
|
|
19
|
+
when,
|
|
20
|
+
is,
|
|
21
|
+
formspec,
|
|
22
|
+
formspecWithValidation,
|
|
23
|
+
validateForm,
|
|
24
|
+
logValidationIssues
|
|
25
|
+
} from "@formspec/dsl";
|
|
26
|
+
import {
|
|
27
|
+
generateJsonSchema,
|
|
28
|
+
generateUiSchema,
|
|
29
|
+
buildFormSchemas,
|
|
30
|
+
buildMixedAuthoringSchemas,
|
|
31
|
+
writeSchemas
|
|
32
|
+
} from "@formspec/build";
|
|
33
|
+
import { defineResolvers } from "@formspec/runtime";
|
|
34
|
+
export {
|
|
35
|
+
buildFormSchemas,
|
|
36
|
+
buildMixedAuthoringSchemas,
|
|
37
|
+
createInitialFieldState,
|
|
38
|
+
defineResolvers,
|
|
39
|
+
field,
|
|
40
|
+
formspec,
|
|
41
|
+
formspecWithValidation,
|
|
42
|
+
generateJsonSchema,
|
|
43
|
+
generateUiSchema,
|
|
44
|
+
group,
|
|
45
|
+
is,
|
|
46
|
+
isArrayField,
|
|
47
|
+
isBooleanField,
|
|
48
|
+
isConditional,
|
|
49
|
+
isDynamicEnumField,
|
|
50
|
+
isDynamicSchemaField,
|
|
51
|
+
isField,
|
|
52
|
+
isGroup,
|
|
53
|
+
isNumberField,
|
|
54
|
+
isObjectField,
|
|
55
|
+
isStaticEnumField,
|
|
56
|
+
isTextField,
|
|
57
|
+
logValidationIssues,
|
|
58
|
+
validateForm,
|
|
59
|
+
when,
|
|
60
|
+
writeSchemas
|
|
61
|
+
};
|
|
67
62
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * FormSpec - Type-safe form specifications\n *\n * This package re-exports everything from the FormSpec library for convenience.\n * You can import everything you need from a single package:\n *\n * @example\n * ```typescript\n * import {\n * // DSL functions\n * formspec, field, group, when, is,\n * // Type inference\n * type InferSchema,\n * // Schema generation\n * buildFormSchemas,\n * // Resolvers\n * defineResolvers,\n * // Core types\n * type FormSpec, type FormElement,\n * } from \"formspec\";\n *\n * // Define a form\n * const InvoiceForm = formspec(\n * group(\"Customer\",\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.dynamicEnum(\"country\", \"fetch_countries\", { label: \"Country\" }),\n * ),\n * group(\"Details\",\n * field.number(\"amount\", { label: \"Amount\", min: 0 }),\n * field.enum(\"status\", [\"draft\", \"sent\", \"paid\"]),\n * when(is(\"status\", \"draft\"),\n * field.text(\"notes\", { label: \"Internal Notes\" }),\n * ),\n * ),\n * );\n *\n * // Infer the schema type\n * type Schema = InferSchema<typeof InvoiceForm.elements>;\n *\n * // Generate JSON Schema and UI Schema\n * const { jsonSchema, uiSchema } = buildFormSchemas(InvoiceForm);\n *\n * // Define resolvers for dynamic data\n * const resolvers = defineResolvers(InvoiceForm, {\n * fetch_countries: async () => ({\n * options: [{ value: \"us\", label: \"United States\" }],\n * validity: \"valid\",\n * }),\n * });\n * ```\n *\n * @packageDocumentation\n */\n\n// =============================================================================\n// Core types\n// =============================================================================\n\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 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} from \"@formspec/core\";\n\nexport { createInitialFieldState } from \"@formspec/core\";\n\n// 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 \"@formspec/core\";\n\n// =============================================================================\n// DSL functions\n// =============================================================================\n\nexport {\n field,\n group,\n when,\n is,\n formspec,\n formspecWithValidation,\n validateForm,\n logValidationIssues,\n} from \"@formspec/dsl\";\n\n// Re-export enum option types (commonly used)\nexport type { EnumOption, EnumOptionValue } from \"@formspec/dsl\";\n\nexport type {\n // Type inference\n InferFieldValue,\n ExtractFields,\n ExtractFieldsFromArray,\n BuildSchema,\n InferSchema,\n InferFormSchema,\n // Validation\n FormSpecOptions,\n ValidationSeverity,\n ValidationIssue,\n ValidationResult,\n} from \"@formspec/dsl\";\n\n// =============================================================================\n// Build tools\n// =============================================================================\n\nexport {\n generateJsonSchema,\n generateUiSchema,\n buildFormSchemas,\n buildMixedAuthoringSchemas,\n writeSchemas,\n} from \"@formspec/build\";\n\nexport type {\n JsonSchema2020,\n JSONSchema7,\n JSONSchemaType,\n UISchema,\n UISchemaElement,\n UISchemaElementType,\n ControlElement,\n VerticalLayout,\n HorizontalLayout,\n GroupLayout,\n Rule,\n RuleEffect,\n SchemaBasedCondition,\n BuildResult,\n BuildMixedAuthoringSchemasOptions,\n MixedAuthoringSchemas,\n WriteSchemasOptions,\n WriteSchemasResult,\n} from \"@formspec/build\";\n\n// =============================================================================\n// Runtime helpers\n// =============================================================================\n\nexport { defineResolvers } from \"@formspec/runtime\";\n\nexport type { Resolver, ResolverMap, ResolverRegistry } from \"@formspec/runtime\";\n"],"mappings":";AA8FA,SAAS,+BAA+B;AAGxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAwBP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA2BP,SAAS,uBAAuB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formspec",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.20",
|
|
4
4
|
"description": "Type-safe form specifications that compile to JSON Schema and JSON Forms UI Schema",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
7
8
|
"types": "./dist/formspec.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./dist/formspec.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
12
14
|
}
|
|
13
15
|
},
|
|
14
16
|
"files": [
|
|
15
|
-
"dist"
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
16
19
|
],
|
|
17
20
|
"dependencies": {
|
|
18
|
-
"@formspec/core": "0.1.0-alpha.
|
|
19
|
-
"@formspec/
|
|
20
|
-
"@formspec/
|
|
21
|
-
"@formspec/runtime": "0.1.0-alpha.
|
|
21
|
+
"@formspec/core": "0.1.0-alpha.19",
|
|
22
|
+
"@formspec/dsl": "0.1.0-alpha.19",
|
|
23
|
+
"@formspec/build": "0.1.0-alpha.20",
|
|
24
|
+
"@formspec/runtime": "0.1.0-alpha.19"
|
|
22
25
|
},
|
|
23
26
|
"publishConfig": {
|
|
24
27
|
"access": "public"
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
],
|
|
34
37
|
"license": "UNLICENSED",
|
|
35
38
|
"scripts": {
|
|
36
|
-
"build": "tsc",
|
|
39
|
+
"build": "tsup && tsc --emitDeclarationOnly && declaration-file-normalizer dist/index.d.ts && api-extractor run --local",
|
|
37
40
|
"clean": "rm -rf dist temp",
|
|
38
41
|
"typecheck": "tsc --noEmit",
|
|
39
42
|
"api-extractor": "api-extractor run",
|