@formspec/dsl 0.1.0-alpha.2 → 0.1.0-alpha.21

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,61 @@
1
+ # @formspec/dsl
2
+
3
+ Chain DSL for defining FormSpec forms with TypeScript inference.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @formspec/dsl @formspec/build
9
+ ```
10
+
11
+ Or use the umbrella package:
12
+
13
+ ```bash
14
+ pnpm add formspec
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```ts
20
+ import { field, formspec, group, is, type InferFormSchema, when } from "@formspec/dsl";
21
+ import { buildFormSchemas } from "@formspec/build";
22
+
23
+ const ProfileForm = formspec(
24
+ group(
25
+ "Profile",
26
+ field.text("displayName", { required: true }),
27
+ field.enum("role", ["admin", "member"] as const, { required: true })
28
+ ),
29
+ when(is("role", "admin"), field.boolean("superUser"))
30
+ );
31
+
32
+ type ProfileData = InferFormSchema<typeof ProfileForm>;
33
+
34
+ const { jsonSchema, uiSchema } = buildFormSchemas(ProfileForm);
35
+ ```
36
+
37
+ ## Main Builders
38
+
39
+ - `formspec(...elements)`
40
+ - `field.text(name, config?)`
41
+ - `field.number(name, config?)`
42
+ - `field.boolean(name, config?)`
43
+ - `field.enum(name, options, config?)`
44
+ - `field.dynamicEnum(name, source, config?)`
45
+ - `field.array(name, ...elements)`
46
+ - `field.arrayWithConfig(name, config, ...elements)`
47
+ - `field.object(name, ...elements)`
48
+ - `field.objectWithConfig(name, config, ...elements)`
49
+ - `group(label, ...elements)`
50
+ - `when(predicate, ...elements)`
51
+ - `is(fieldName, value)`
52
+
53
+ ## Notes
54
+
55
+ - Use `as const` for enum option arrays when you want literal inference from variables.
56
+ - `group()` is layout-only; it does not change the data shape.
57
+ - `when()` affects UI behavior, not whether a field exists in the JSON Schema.
58
+
59
+ ## License
60
+
61
+ UNLICENSED