formspec 0.0.0 → 0.1.0-alpha.10
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 +157 -0
- package/dist/formspec.d.ts +254 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -7
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# formspec
|
|
2
|
+
|
|
3
|
+
Type-safe form specifications that compile to JSON Schema and JSON Forms UI Schema.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install formspec
|
|
9
|
+
# or
|
|
10
|
+
pnpm add formspec
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
This package is ESM-only and requires:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
// package.json
|
|
19
|
+
{
|
|
20
|
+
"type": "module"
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
// tsconfig.json
|
|
26
|
+
{
|
|
27
|
+
"compilerOptions": {
|
|
28
|
+
"module": "NodeNext",
|
|
29
|
+
"moduleResolution": "NodeNext"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { formspec, field, group, when, is, buildFormSchemas, type InferFormSchema } from "formspec";
|
|
38
|
+
|
|
39
|
+
// Define a form
|
|
40
|
+
const ContactForm = formspec(
|
|
41
|
+
field.text("name", { label: "Name", required: true }),
|
|
42
|
+
field.text("email", { label: "Email", required: true }),
|
|
43
|
+
field.enum("subject", ["General", "Support", "Sales"], { label: "Subject" }),
|
|
44
|
+
field.text("message", { label: "Message", required: true }),
|
|
45
|
+
field.boolean("subscribe", { label: "Subscribe to newsletter" })
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// Infer TypeScript type from the form
|
|
49
|
+
type ContactData = InferFormSchema<typeof ContactForm>;
|
|
50
|
+
// { name: string; email: string; subject: "General" | "Support" | "Sales" | undefined; ... }
|
|
51
|
+
|
|
52
|
+
// Generate JSON Schema and UI Schema
|
|
53
|
+
const { jsonSchema, uiSchema } = buildFormSchemas(ContactForm);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
### Field Types
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
field.text("name", { label: "Name", required: true });
|
|
62
|
+
field.number("age", { label: "Age", min: 0, max: 120 });
|
|
63
|
+
field.boolean("active", { label: "Active" });
|
|
64
|
+
field.enum("status", ["draft", "published"], { label: "Status" });
|
|
65
|
+
field.dynamicEnum("country", "fetch_countries", { label: "Country" });
|
|
66
|
+
field.array("tags", field.text("tag"));
|
|
67
|
+
field.object("address", field.text("street"), field.text("city"));
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Grouping
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const Form = formspec(
|
|
74
|
+
group("Personal Info", field.text("firstName"), field.text("lastName")),
|
|
75
|
+
group("Contact", field.text("email"), field.text("phone"))
|
|
76
|
+
);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Conditional Fields
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const Form = formspec(
|
|
83
|
+
field.enum("type", ["personal", "business"]),
|
|
84
|
+
when(
|
|
85
|
+
is("type", "business"),
|
|
86
|
+
field.text("companyName", { label: "Company Name" }),
|
|
87
|
+
field.text("taxId", { label: "Tax ID" })
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Type Inference
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Infer the form data type
|
|
96
|
+
type FormData = InferFormSchema<typeof MyForm>;
|
|
97
|
+
|
|
98
|
+
// Use with form libraries
|
|
99
|
+
const handleSubmit = (data: FormData) => {
|
|
100
|
+
// data is fully typed
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Dynamic Enums with Resolvers
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { defineResolvers } from "formspec";
|
|
108
|
+
|
|
109
|
+
const Form = formspec(field.dynamicEnum("country", "fetch_countries", { label: "Country" }));
|
|
110
|
+
|
|
111
|
+
const resolvers = defineResolvers(Form, {
|
|
112
|
+
fetch_countries: async () => ({
|
|
113
|
+
options: [
|
|
114
|
+
{ value: "us", label: "United States" },
|
|
115
|
+
{ value: "ca", label: "Canada" },
|
|
116
|
+
],
|
|
117
|
+
validity: "valid",
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Write Schemas to Disk
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { writeSchemas } from "formspec";
|
|
126
|
+
|
|
127
|
+
writeSchemas(ContactForm, {
|
|
128
|
+
outDir: "./generated",
|
|
129
|
+
name: "contact-form",
|
|
130
|
+
});
|
|
131
|
+
// Creates: ./generated/contact-form-schema.json
|
|
132
|
+
// ./generated/contact-form-uischema.json
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Package Structure
|
|
136
|
+
|
|
137
|
+
This umbrella package re-exports from several focused packages:
|
|
138
|
+
|
|
139
|
+
| Package | Description |
|
|
140
|
+
| ------------------- | ---------------------------------------------------------- |
|
|
141
|
+
| `@formspec/core` | Core type definitions |
|
|
142
|
+
| `@formspec/dsl` | DSL functions (`formspec`, `field`, `group`, `when`, `is`) |
|
|
143
|
+
| `@formspec/build` | Schema generators (`buildFormSchemas`, `writeSchemas`) |
|
|
144
|
+
| `@formspec/runtime` | Runtime helpers (`defineResolvers`) |
|
|
145
|
+
|
|
146
|
+
You can import from the umbrella package for convenience, or from individual packages for smaller bundle sizes.
|
|
147
|
+
|
|
148
|
+
## Related Packages
|
|
149
|
+
|
|
150
|
+
| Package | Description |
|
|
151
|
+
| ---------------------- | ------------------------------------------------- |
|
|
152
|
+
| `@formspec/decorators` | Decorator-based API for class definitions |
|
|
153
|
+
| `@formspec/cli` | CLI tool for static analysis of decorated classes |
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
UNLICENSED
|
|
@@ -0,0 +1,254 @@
|
|
|
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 { BuildResult } from '@formspec/build';
|
|
60
|
+
import { BuildSchema } from '@formspec/dsl';
|
|
61
|
+
import { Conditional } from '@formspec/core';
|
|
62
|
+
import { ControlElement } from '@formspec/build';
|
|
63
|
+
import { createInitialFieldState } from '@formspec/core';
|
|
64
|
+
import { DataSourceOption } from '@formspec/core';
|
|
65
|
+
import { DataSourceRegistry } from '@formspec/core';
|
|
66
|
+
import { DataSourceValueType } from '@formspec/core';
|
|
67
|
+
import { defineResolvers } from '@formspec/runtime';
|
|
68
|
+
import { DynamicEnumField } from '@formspec/core';
|
|
69
|
+
import { DynamicSchemaField } from '@formspec/core';
|
|
70
|
+
import { EnumOption } from '@formspec/dsl';
|
|
71
|
+
import { EnumOptionValue } from '@formspec/dsl';
|
|
72
|
+
import { EqualsPredicate } from '@formspec/core';
|
|
73
|
+
import { ExtractFields } from '@formspec/dsl';
|
|
74
|
+
import { ExtractFieldsFromArray } from '@formspec/dsl';
|
|
75
|
+
import { FetchOptionsResponse } from '@formspec/core';
|
|
76
|
+
import { field } from '@formspec/dsl';
|
|
77
|
+
import { FieldState } from '@formspec/core';
|
|
78
|
+
import { FormElement } from '@formspec/core';
|
|
79
|
+
import { FormSpec } from '@formspec/core';
|
|
80
|
+
import { formspec } from '@formspec/dsl';
|
|
81
|
+
import { FormSpecOptions } from '@formspec/dsl';
|
|
82
|
+
import { formspecWithValidation } from '@formspec/dsl';
|
|
83
|
+
import { FormState } from '@formspec/core';
|
|
84
|
+
import { generateJsonSchema } from '@formspec/build';
|
|
85
|
+
import { generateUiSchema } from '@formspec/build';
|
|
86
|
+
import { Group } from '@formspec/core';
|
|
87
|
+
import { group } from '@formspec/dsl';
|
|
88
|
+
import { GroupLayout } from '@formspec/build';
|
|
89
|
+
import { HorizontalLayout } from '@formspec/build';
|
|
90
|
+
import { InferFieldValue } from '@formspec/dsl';
|
|
91
|
+
import { InferFormSchema } from '@formspec/dsl';
|
|
92
|
+
import { InferSchema } from '@formspec/dsl';
|
|
93
|
+
import { is } from '@formspec/dsl';
|
|
94
|
+
import { JSONSchema7 } from '@formspec/build';
|
|
95
|
+
import { JSONSchemaType } from '@formspec/build';
|
|
96
|
+
import { logValidationIssues } from '@formspec/dsl';
|
|
97
|
+
import { NumberField } from '@formspec/core';
|
|
98
|
+
import { ObjectField } from '@formspec/core';
|
|
99
|
+
import { Predicate } from '@formspec/core';
|
|
100
|
+
import { Resolver } from '@formspec/runtime';
|
|
101
|
+
import { ResolverMap } from '@formspec/runtime';
|
|
102
|
+
import { ResolverRegistry } from '@formspec/runtime';
|
|
103
|
+
import { Rule } from '@formspec/build';
|
|
104
|
+
import { RuleEffect } from '@formspec/build';
|
|
105
|
+
import { SchemaBasedCondition } from '@formspec/build';
|
|
106
|
+
import { StaticEnumField } from '@formspec/core';
|
|
107
|
+
import { TextField } from '@formspec/core';
|
|
108
|
+
import { UISchema } from '@formspec/build';
|
|
109
|
+
import { UISchemaElement } from '@formspec/build';
|
|
110
|
+
import { UISchemaElementType } from '@formspec/build';
|
|
111
|
+
import { validateForm } from '@formspec/dsl';
|
|
112
|
+
import { ValidationIssue } from '@formspec/dsl';
|
|
113
|
+
import { ValidationResult } from '@formspec/dsl';
|
|
114
|
+
import { ValidationSeverity } from '@formspec/dsl';
|
|
115
|
+
import { Validity } from '@formspec/core';
|
|
116
|
+
import { VerticalLayout } from '@formspec/build';
|
|
117
|
+
import { when } from '@formspec/dsl';
|
|
118
|
+
import { writeSchemas } from '@formspec/build';
|
|
119
|
+
import { WriteSchemasOptions } from '@formspec/build';
|
|
120
|
+
import { WriteSchemasResult } from '@formspec/build';
|
|
121
|
+
|
|
122
|
+
export { AnyField }
|
|
123
|
+
|
|
124
|
+
export { ArrayField }
|
|
125
|
+
|
|
126
|
+
export { BooleanField }
|
|
127
|
+
|
|
128
|
+
export { buildFormSchemas }
|
|
129
|
+
|
|
130
|
+
export { BuildResult }
|
|
131
|
+
|
|
132
|
+
export { BuildSchema }
|
|
133
|
+
|
|
134
|
+
export { Conditional }
|
|
135
|
+
|
|
136
|
+
export { ControlElement }
|
|
137
|
+
|
|
138
|
+
export { createInitialFieldState }
|
|
139
|
+
|
|
140
|
+
export { DataSourceOption }
|
|
141
|
+
|
|
142
|
+
export { DataSourceRegistry }
|
|
143
|
+
|
|
144
|
+
export { DataSourceValueType }
|
|
145
|
+
|
|
146
|
+
export { defineResolvers }
|
|
147
|
+
|
|
148
|
+
export { DynamicEnumField }
|
|
149
|
+
|
|
150
|
+
export { DynamicSchemaField }
|
|
151
|
+
|
|
152
|
+
export { EnumOption }
|
|
153
|
+
|
|
154
|
+
export { EnumOptionValue }
|
|
155
|
+
|
|
156
|
+
export { EqualsPredicate }
|
|
157
|
+
|
|
158
|
+
export { ExtractFields }
|
|
159
|
+
|
|
160
|
+
export { ExtractFieldsFromArray }
|
|
161
|
+
|
|
162
|
+
export { FetchOptionsResponse }
|
|
163
|
+
|
|
164
|
+
export { field }
|
|
165
|
+
|
|
166
|
+
export { FieldState }
|
|
167
|
+
|
|
168
|
+
export { FormElement }
|
|
169
|
+
|
|
170
|
+
export { FormSpec }
|
|
171
|
+
|
|
172
|
+
export { formspec }
|
|
173
|
+
|
|
174
|
+
export { FormSpecOptions }
|
|
175
|
+
|
|
176
|
+
export { formspecWithValidation }
|
|
177
|
+
|
|
178
|
+
export { FormState }
|
|
179
|
+
|
|
180
|
+
export { generateJsonSchema }
|
|
181
|
+
|
|
182
|
+
export { generateUiSchema }
|
|
183
|
+
|
|
184
|
+
export { Group }
|
|
185
|
+
|
|
186
|
+
export { group }
|
|
187
|
+
|
|
188
|
+
export { GroupLayout }
|
|
189
|
+
|
|
190
|
+
export { HorizontalLayout }
|
|
191
|
+
|
|
192
|
+
export { InferFieldValue }
|
|
193
|
+
|
|
194
|
+
export { InferFormSchema }
|
|
195
|
+
|
|
196
|
+
export { InferSchema }
|
|
197
|
+
|
|
198
|
+
export { is }
|
|
199
|
+
|
|
200
|
+
export { JSONSchema7 }
|
|
201
|
+
|
|
202
|
+
export { JSONSchemaType }
|
|
203
|
+
|
|
204
|
+
export { logValidationIssues }
|
|
205
|
+
|
|
206
|
+
export { NumberField }
|
|
207
|
+
|
|
208
|
+
export { ObjectField }
|
|
209
|
+
|
|
210
|
+
export { Predicate }
|
|
211
|
+
|
|
212
|
+
export { Resolver }
|
|
213
|
+
|
|
214
|
+
export { ResolverMap }
|
|
215
|
+
|
|
216
|
+
export { ResolverRegistry }
|
|
217
|
+
|
|
218
|
+
export { Rule }
|
|
219
|
+
|
|
220
|
+
export { RuleEffect }
|
|
221
|
+
|
|
222
|
+
export { SchemaBasedCondition }
|
|
223
|
+
|
|
224
|
+
export { StaticEnumField }
|
|
225
|
+
|
|
226
|
+
export { TextField }
|
|
227
|
+
|
|
228
|
+
export { UISchema }
|
|
229
|
+
|
|
230
|
+
export { UISchemaElement }
|
|
231
|
+
|
|
232
|
+
export { UISchemaElementType }
|
|
233
|
+
|
|
234
|
+
export { validateForm }
|
|
235
|
+
|
|
236
|
+
export { ValidationIssue }
|
|
237
|
+
|
|
238
|
+
export { ValidationResult }
|
|
239
|
+
|
|
240
|
+
export { ValidationSeverity }
|
|
241
|
+
|
|
242
|
+
export { Validity }
|
|
243
|
+
|
|
244
|
+
export { VerticalLayout }
|
|
245
|
+
|
|
246
|
+
export { when }
|
|
247
|
+
|
|
248
|
+
export { writeSchemas }
|
|
249
|
+
|
|
250
|
+
export { WriteSchemasOptions }
|
|
251
|
+
|
|
252
|
+
export { WriteSchemasResult }
|
|
253
|
+
|
|
254
|
+
export { }
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
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
|
+
export { createInitialFieldState } from "@formspec/core";
|
|
56
|
+
export { field, group, when, is, formspec, formspecWithValidation, validateForm, logValidationIssues, } from "@formspec/dsl";
|
|
57
|
+
export type { EnumOption, EnumOptionValue } from "@formspec/dsl";
|
|
58
|
+
export type { InferFieldValue, ExtractFields, ExtractFieldsFromArray, BuildSchema, InferSchema, InferFormSchema, FormSpecOptions, ValidationSeverity, ValidationIssue, ValidationResult, } from "@formspec/dsl";
|
|
59
|
+
export { generateJsonSchema, generateUiSchema, buildFormSchemas, writeSchemas, } from "@formspec/build";
|
|
60
|
+
export type { JSONSchema7, JSONSchemaType, UISchema, UISchemaElement, UISchemaElementType, ControlElement, VerticalLayout, HorizontalLayout, GroupLayout, Rule, RuleEffect, SchemaBasedCondition, BuildResult, WriteSchemasOptions, WriteSchemasResult, } from "@formspec/build";
|
|
61
|
+
export { defineResolvers } from "@formspec/runtime";
|
|
62
|
+
export type { Resolver, ResolverMap, ResolverRegistry } from "@formspec/runtime";
|
|
63
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAMzD,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,YAAY,GACb,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,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,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
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
export { createInitialFieldState } from "@formspec/core";
|
|
55
|
+
// =============================================================================
|
|
56
|
+
// DSL functions
|
|
57
|
+
// =============================================================================
|
|
58
|
+
export { field, group, when, is, formspec, formspecWithValidation, validateForm, logValidationIssues, } from "@formspec/dsl";
|
|
59
|
+
// =============================================================================
|
|
60
|
+
// Build tools
|
|
61
|
+
// =============================================================================
|
|
62
|
+
export { generateJsonSchema, generateUiSchema, buildFormSchemas, writeSchemas, } from "@formspec/build";
|
|
63
|
+
// =============================================================================
|
|
64
|
+
// Runtime helpers
|
|
65
|
+
// =============================================================================
|
|
66
|
+
export { defineResolvers } from "@formspec/runtime";
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AA0CH,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF,OAAO,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,EAAE,EACF,QAAQ,EACR,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAoBvB,gFAAgF;AAChF,cAAc;AACd,gFAAgF;AAEhF,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,GACb,MAAM,iBAAiB,CAAC;AAoBzB,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formspec",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
|
+
"description": "Type-safe form specifications that compile to JSON Schema and JSON Forms UI Schema",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/formspec.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/formspec.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@formspec/core": "0.1.0-alpha.10",
|
|
20
|
+
"@formspec/dsl": "0.1.0-alpha.10",
|
|
21
|
+
"@formspec/build": "0.1.0-alpha.10",
|
|
22
|
+
"@formspec/runtime": "0.1.0-alpha.10"
|
|
7
23
|
},
|
|
8
|
-
"
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"form",
|
|
29
|
+
"forms",
|
|
30
|
+
"json-schema",
|
|
31
|
+
"json-forms",
|
|
32
|
+
"type-safe",
|
|
33
|
+
"typescript"
|
|
34
|
+
],
|
|
9
35
|
"license": "UNLICENSED",
|
|
10
|
-
"
|
|
11
|
-
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc && declaration-file-normalizer dist/index.d.ts && api-extractor run --local",
|
|
38
|
+
"clean": "rm -rf dist temp",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"api-extractor": "api-extractor run",
|
|
41
|
+
"api-extractor:local": "api-extractor run --local",
|
|
42
|
+
"api-documenter": "api-documenter markdown -i temp -o docs"
|
|
43
|
+
}
|
|
44
|
+
}
|