formspec 0.1.0-alpha.4 → 0.1.0-alpha.41

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mike North
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,164 +1,95 @@
1
1
  # formspec
2
2
 
3
- Type-safe form specifications that compile to JSON Schema and JSON Forms UI Schema.
3
+ Umbrella package for the common FormSpec authoring and runtime APIs.
4
4
 
5
- ## Installation
5
+ It re-exports the most commonly used pieces from:
6
6
 
7
- ```bash
8
- npm install formspec
9
- # or
10
- pnpm add formspec
11
- ```
7
+ - `@formspec/core`
8
+ - `@formspec/dsl`
9
+ - `@formspec/build`
10
+ - `@formspec/runtime`
12
11
 
13
- ## Requirements
12
+ It does not include the CLI, ESLint plugin, language server, or playground app.
14
13
 
15
- This package is ESM-only and requires:
14
+ ## Install
16
15
 
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
- }
16
+ ```bash
17
+ pnpm add formspec
32
18
  ```
33
19
 
34
20
  ## Quick Start
35
21
 
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",
75
- field.text("firstName"),
76
- field.text("lastName"),
77
- ),
78
- group("Contact",
79
- field.text("email"),
80
- field.text("phone"),
81
- ),
82
- );
83
- ```
84
-
85
- ### Conditional Fields
86
-
87
- ```typescript
88
- const Form = formspec(
89
- field.enum("type", ["personal", "business"]),
90
- when(is("type", "business"),
91
- field.text("companyName", { label: "Company Name" }),
92
- field.text("taxId", { label: "Tax ID" }),
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 })
93
39
  ),
40
+ when(is("status", "submitted"), field.text("submittedBy"))
94
41
  );
95
- ```
96
42
 
97
- ### Type Inference
43
+ type OrderData = InferFormSchema<typeof OrderForm>;
98
44
 
99
- ```typescript
100
- // Infer the form data type
101
- type FormData = InferFormSchema<typeof MyForm>;
45
+ const { jsonSchema, uiSchema } = buildFormSchemas(OrderForm);
102
46
 
103
- // Use with form libraries
104
- const handleSubmit = (data: FormData) => {
105
- // data is fully typed
106
- };
47
+ const resolvers = defineResolvers(OrderForm, {});
107
48
  ```
108
49
 
109
- ### Dynamic Enums with Resolvers
50
+ ## What You Get
110
51
 
111
- ```typescript
112
- import { defineResolvers } from "formspec";
52
+ ### DSL
113
53
 
114
- const Form = formspec(
115
- field.dynamicEnum("country", "fetch_countries", { label: "Country" }),
116
- );
54
+ - `formspec`
55
+ - `field`
56
+ - `group`
57
+ - `when`
58
+ - `is`
59
+ - `formspecWithValidation`
60
+ - `validateForm`
117
61
 
118
- const resolvers = defineResolvers(Form, {
119
- fetch_countries: async () => ({
120
- options: [
121
- { value: "us", label: "United States" },
122
- { value: "ca", label: "Canada" },
123
- ],
124
- validity: "valid",
125
- }),
126
- });
127
- ```
62
+ ### Build
128
63
 
129
- ### Write Schemas to Disk
64
+ - `buildFormSchemas`
65
+ - `generateJsonSchema`
66
+ - `generateUiSchema`
67
+ - `writeSchemas`
130
68
 
131
- ```typescript
132
- import { writeSchemas } from "formspec";
69
+ ### Runtime
133
70
 
134
- writeSchemas(ContactForm, {
135
- outDir: "./generated",
136
- name: "contact-form",
137
- });
138
- // Creates: ./generated/contact-form-schema.json
139
- // ./generated/contact-form-uischema.json
140
- ```
71
+ - `defineResolvers`
141
72
 
142
- ## Package Structure
73
+ ### Types
143
74
 
144
- This umbrella package re-exports from several focused packages:
75
+ - `InferSchema`
76
+ - `InferFormSchema`
77
+ - core field, layout, and state types
78
+ - resolver and validation helper types
145
79
 
146
- | Package | Description |
147
- |---------|-------------|
148
- | `@formspec/core` | Core type definitions |
149
- | `@formspec/dsl` | DSL functions (`formspec`, `field`, `group`, `when`, `is`) |
150
- | `@formspec/build` | Schema generators (`buildFormSchemas`, `writeSchemas`) |
151
- | `@formspec/runtime` | Runtime helpers (`defineResolvers`) |
80
+ ### Utilities
152
81
 
153
- You can import from the umbrella package for convenience, or from individual packages for smaller bundle sizes.
82
+ - `createInitialFieldState`
83
+ - `validateForm`
84
+ - `logValidationIssues`
154
85
 
155
- ## Related Packages
86
+ ## When To Use Individual Packages
156
87
 
157
- | Package | Description |
158
- |---------|-------------|
159
- | `@formspec/decorators` | Decorator-based API for class definitions |
160
- | `@formspec/cli` | CLI tool for static analysis of decorated classes |
88
+ - Use `@formspec/build` directly for `generateSchemas()`, `generateSchemasFromClass()`, `generateSchemasFromProgram()`, `buildMixedAuthoringSchemas()`, and static TypeScript analysis.
89
+ - Use `@formspec/eslint-plugin` for lint rules.
90
+ - Use `@formspec/cli` for build-time artifact generation from files.
91
+ - Use `@formspec/validator` for runtime JSON Schema validation.
161
92
 
162
93
  ## License
163
94
 
164
- UNLICENSED
95
+ This package is part of the FormSpec monorepo and is released under the MIT License. See [LICENSE](./LICENSE) for details.