formspec 0.1.0-alpha.1 → 0.1.0-alpha.11

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 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.cjs ADDED
@@ -0,0 +1,60 @@
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
+ createInitialFieldState: () => import_core.createInitialFieldState,
25
+ defineResolvers: () => import_runtime.defineResolvers,
26
+ field: () => import_dsl.field,
27
+ formspec: () => import_dsl.formspec,
28
+ formspecWithValidation: () => import_dsl.formspecWithValidation,
29
+ generateJsonSchema: () => import_build.generateJsonSchema,
30
+ generateUiSchema: () => import_build.generateUiSchema,
31
+ group: () => import_dsl.group,
32
+ is: () => import_dsl.is,
33
+ logValidationIssues: () => import_dsl.logValidationIssues,
34
+ validateForm: () => import_dsl.validateForm,
35
+ when: () => import_dsl.when,
36
+ writeSchemas: () => import_build.writeSchemas
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+ var import_core = require("@formspec/core");
40
+ var import_dsl = require("@formspec/dsl");
41
+ var import_build = require("@formspec/build");
42
+ var import_runtime = require("@formspec/runtime");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ buildFormSchemas,
46
+ createInitialFieldState,
47
+ defineResolvers,
48
+ field,
49
+ formspec,
50
+ formspecWithValidation,
51
+ generateJsonSchema,
52
+ generateUiSchema,
53
+ group,
54
+ is,
55
+ logValidationIssues,
56
+ validateForm,
57
+ when,
58
+ writeSchemas
59
+ });
60
+ //# 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// =============================================================================\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 writeSchemas,\n} from \"@formspec/build\";\n\nexport type {\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 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;AA8FA,kBAAwC;AAMxC,iBASO;AAwBP,mBAKO;AAwBP,qBAAgC;","names":[]}
package/dist/index.d.ts CHANGED
@@ -53,10 +53,11 @@
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 { field, group, when, is, formspec, formspecWithValidation, validateForm, logValidationIssues } from "@formspec/dsl";
56
+ export { field, group, when, is, formspec, formspecWithValidation, validateForm, logValidationIssues, } from "@formspec/dsl";
57
+ export type { EnumOption, EnumOptionValue } from "@formspec/dsl";
57
58
  export type { InferFieldValue, ExtractFields, ExtractFieldsFromArray, BuildSchema, InferSchema, InferFormSchema, FormSpecOptions, ValidationSeverity, ValidationIssue, ValidationResult, } from "@formspec/dsl";
58
59
  export { generateJsonSchema, generateUiSchema, buildFormSchemas, writeSchemas, } from "@formspec/build";
59
60
  export type { JSONSchema7, JSONSchemaType, UISchema, UISchemaElement, UISchemaElementType, ControlElement, VerticalLayout, HorizontalLayout, GroupLayout, Rule, RuleEffect, SchemaBasedCondition, BuildResult, WriteSchemasOptions, WriteSchemasResult, } from "@formspec/build";
60
61
  export { defineResolvers } from "@formspec/runtime";
61
- export type { Resolver, ResolverMap, ResolverRegistry, } from "@formspec/runtime";
62
+ export type { Resolver, ResolverMap, ResolverRegistry } from "@formspec/runtime";
62
63
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAMzD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,sBAAsB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE5H,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,EACV,QAAQ,EACR,WAAW,EACX,gBAAgB,GACjB,MAAM,mBAAmB,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;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 CHANGED
@@ -1,67 +1,36 @@
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";
1
+ // src/index.ts
2
+ import { createInitialFieldState } from "@formspec/core";
3
+ import {
4
+ field,
5
+ group,
6
+ when,
7
+ is,
8
+ formspec,
9
+ formspecWithValidation,
10
+ validateForm,
11
+ logValidationIssues
12
+ } from "@formspec/dsl";
13
+ import {
14
+ generateJsonSchema,
15
+ generateUiSchema,
16
+ buildFormSchemas,
17
+ writeSchemas
18
+ } from "@formspec/build";
19
+ import { defineResolvers } from "@formspec/runtime";
20
+ export {
21
+ buildFormSchemas,
22
+ createInitialFieldState,
23
+ defineResolvers,
24
+ field,
25
+ formspec,
26
+ formspecWithValidation,
27
+ generateJsonSchema,
28
+ generateUiSchema,
29
+ group,
30
+ is,
31
+ logValidationIssues,
32
+ validateForm,
33
+ when,
34
+ writeSchemas
35
+ };
67
36
  //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AA0CH,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,sBAAsB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAiB5H,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"}
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// =============================================================================\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 writeSchemas,\n} from \"@formspec/build\";\n\nexport type {\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 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;AAMxC;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,OACK;AAwBP,SAAS,uBAAuB;","names":[]}
package/package.json CHANGED
@@ -1,24 +1,27 @@
1
1
  {
2
2
  "name": "formspec",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.11",
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.js",
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.0",
19
- "@formspec/dsl": "0.1.0-alpha.0",
20
- "@formspec/build": "0.1.0-alpha.1",
21
- "@formspec/runtime": "0.1.0-alpha.0"
21
+ "@formspec/core": "0.1.0-alpha.11",
22
+ "@formspec/dsl": "0.1.0-alpha.11",
23
+ "@formspec/build": "0.1.0-alpha.11",
24
+ "@formspec/runtime": "0.1.0-alpha.11"
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",