@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 +61 -0
- package/dist/dsl.d.ts +665 -0
- package/dist/field.d.ts +15 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/index.cjs +446 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +411 -38
- package/dist/index.js.map +1 -1
- package/dist/inference.d.ts +122 -1
- package/dist/inference.d.ts.map +1 -1
- package/dist/predicate.d.ts +1 -0
- package/dist/predicate.d.ts.map +1 -1
- package/dist/structure.d.ts +10 -0
- package/dist/structure.d.ts.map +1 -1
- package/dist/validation.d.ts +10 -0
- package/dist/validation.d.ts.map +1 -1
- package/package.json +9 -6
- package/dist/__tests__/builders.test.js +0 -193
- package/dist/__tests__/builders.test.js.map +0 -1
- package/dist/__tests__/inference.test-d.js +0 -83
- package/dist/__tests__/inference.test-d.js.map +0 -1
- package/dist/__tests__/validation.test.js +0 -180
- package/dist/__tests__/validation.test.js.map +0 -1
- package/dist/field.js +0 -221
- package/dist/field.js.map +0 -1
- package/dist/inference.js +0 -8
- package/dist/inference.js.map +0 -1
- package/dist/predicate.js +0 -40
- package/dist/predicate.js.map +0 -1
- package/dist/structure.js +0 -129
- package/dist/structure.js.map +0 -1
- package/dist/validation.js +0 -186
- package/dist/validation.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inference.test-d.js","sourceRoot":"","sources":["../../src/__tests__/inference.test-d.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAW/D,gFAAgF;AACh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;AAE3F,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF,wCAAwC;AACxC,MAAM,WAAW,GAAG,QAAQ,CAC1B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAClB,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EACtB,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAU,CAAC,CACtD,CAAC;AAEF,UAAU,CACR,EAAmB,CACpB,CAAC;AAEF,gFAAgF;AAChF,0CAA0C;AAC1C,gFAAgF;AAEhF,uCAAuC;AACvC,aAAa,CAAS,EAAwC,CAAC,CAAC;AAEhE,yCAAyC;AACzC,aAAa,CAAS,EAAyC,CAAC,CAAC;AAEjE,uCAAuC;AACvC,aAAa,CAAqB,EAA2C,CAAC,CAAC"}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { formspecWithValidation, field, group, when, is, validateForm } from "../index.js";
|
|
3
|
-
describe("validateForm", () => {
|
|
4
|
-
describe("duplicate field detection", () => {
|
|
5
|
-
it("should detect duplicate field names at root level", () => {
|
|
6
|
-
const elements = [
|
|
7
|
-
field.text("name"),
|
|
8
|
-
field.text("email"),
|
|
9
|
-
field.text("name"), // duplicate
|
|
10
|
-
];
|
|
11
|
-
const result = validateForm(elements);
|
|
12
|
-
expect(result.valid).toBe(true); // duplicates are warnings, not errors
|
|
13
|
-
expect(result.issues).toHaveLength(1);
|
|
14
|
-
expect(result.issues[0].severity).toBe("warning");
|
|
15
|
-
expect(result.issues[0].message).toContain('Duplicate field name "name"');
|
|
16
|
-
expect(result.issues[0].message).toContain("2 times");
|
|
17
|
-
});
|
|
18
|
-
it("should detect duplicate field names inside groups", () => {
|
|
19
|
-
const elements = [
|
|
20
|
-
group("Personal", field.text("name")),
|
|
21
|
-
group("Business", field.text("name")),
|
|
22
|
-
];
|
|
23
|
-
const result = validateForm(elements);
|
|
24
|
-
expect(result.issues).toHaveLength(1);
|
|
25
|
-
expect(result.issues[0].severity).toBe("warning");
|
|
26
|
-
expect(result.issues[0].message).toContain('Duplicate field name "name"');
|
|
27
|
-
});
|
|
28
|
-
it("should detect duplicate field names inside conditionals", () => {
|
|
29
|
-
const elements = [
|
|
30
|
-
field.enum("type", ["a", "b"]),
|
|
31
|
-
field.text("value"),
|
|
32
|
-
when(is("type", "a"), field.text("value")),
|
|
33
|
-
];
|
|
34
|
-
const result = validateForm(elements);
|
|
35
|
-
expect(result.issues).toHaveLength(1);
|
|
36
|
-
expect(result.issues[0].severity).toBe("warning");
|
|
37
|
-
});
|
|
38
|
-
it("should allow same field names inside different array items (separate scope)", () => {
|
|
39
|
-
// Fields inside arrays are in a different scope - this is valid
|
|
40
|
-
const elements = [
|
|
41
|
-
field.array("addresses", field.text("street"), field.text("city")),
|
|
42
|
-
];
|
|
43
|
-
const result = validateForm(elements);
|
|
44
|
-
expect(result.valid).toBe(true);
|
|
45
|
-
expect(result.issues).toHaveLength(0);
|
|
46
|
-
});
|
|
47
|
-
it("should not flag unique field names", () => {
|
|
48
|
-
const elements = [
|
|
49
|
-
field.text("firstName"),
|
|
50
|
-
field.text("lastName"),
|
|
51
|
-
field.text("email"),
|
|
52
|
-
];
|
|
53
|
-
const result = validateForm(elements);
|
|
54
|
-
expect(result.valid).toBe(true);
|
|
55
|
-
expect(result.issues).toHaveLength(0);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
describe("field reference validation", () => {
|
|
59
|
-
it("should detect references to non-existent fields", () => {
|
|
60
|
-
const elements = [
|
|
61
|
-
field.text("name"),
|
|
62
|
-
when(is("status", "draft"), // "status" doesn't exist!
|
|
63
|
-
field.text("notes")),
|
|
64
|
-
];
|
|
65
|
-
const result = validateForm(elements);
|
|
66
|
-
expect(result.valid).toBe(false);
|
|
67
|
-
expect(result.issues).toHaveLength(1);
|
|
68
|
-
expect(result.issues[0].severity).toBe("error");
|
|
69
|
-
expect(result.issues[0].message).toContain('non-existent field "status"');
|
|
70
|
-
});
|
|
71
|
-
it("should pass when conditional references existing field", () => {
|
|
72
|
-
const elements = [
|
|
73
|
-
field.enum("status", ["draft", "sent"]),
|
|
74
|
-
when(is("status", "draft"), field.text("notes")),
|
|
75
|
-
];
|
|
76
|
-
const result = validateForm(elements);
|
|
77
|
-
expect(result.valid).toBe(true);
|
|
78
|
-
expect(result.issues).toHaveLength(0);
|
|
79
|
-
});
|
|
80
|
-
it("should detect reference errors in nested conditionals", () => {
|
|
81
|
-
const elements = [
|
|
82
|
-
field.enum("type", ["a", "b"]),
|
|
83
|
-
when(is("type", "a"), when(is("subtype", "x"), // "subtype" doesn't exist!
|
|
84
|
-
field.text("extra"))),
|
|
85
|
-
];
|
|
86
|
-
const result = validateForm(elements);
|
|
87
|
-
expect(result.valid).toBe(false);
|
|
88
|
-
expect(result.issues.some((i) => i.message.includes('"subtype"'))).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
it("should allow forward references (field defined after conditional)", () => {
|
|
91
|
-
// This is valid - the conditional references a field that's defined later
|
|
92
|
-
const elements = [
|
|
93
|
-
when(is("status", "draft"), field.text("notes")),
|
|
94
|
-
field.enum("status", ["draft", "sent"]),
|
|
95
|
-
];
|
|
96
|
-
const result = validateForm(elements);
|
|
97
|
-
expect(result.valid).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe("combined issues", () => {
|
|
101
|
-
it("should report multiple issues", () => {
|
|
102
|
-
const elements = [
|
|
103
|
-
field.text("name"),
|
|
104
|
-
field.text("name"), // duplicate
|
|
105
|
-
when(is("nonExistent", "value"), // reference error
|
|
106
|
-
field.text("extra")),
|
|
107
|
-
];
|
|
108
|
-
const result = validateForm(elements);
|
|
109
|
-
expect(result.valid).toBe(false);
|
|
110
|
-
expect(result.issues).toHaveLength(2);
|
|
111
|
-
expect(result.issues.filter((i) => i.severity === "warning")).toHaveLength(1);
|
|
112
|
-
expect(result.issues.filter((i) => i.severity === "error")).toHaveLength(1);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
describe("formspecWithValidation", () => {
|
|
117
|
-
let consoleWarnSpy;
|
|
118
|
-
let consoleErrorSpy;
|
|
119
|
-
beforeEach(() => {
|
|
120
|
-
consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
121
|
-
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
122
|
-
});
|
|
123
|
-
afterEach(() => {
|
|
124
|
-
consoleWarnSpy.mockRestore();
|
|
125
|
-
consoleErrorSpy.mockRestore();
|
|
126
|
-
});
|
|
127
|
-
it("should not validate when validate=false", () => {
|
|
128
|
-
formspecWithValidation({ validate: false }, field.text("name"), when(is("nonExistent", "value"), field.text("notes")));
|
|
129
|
-
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
130
|
-
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
131
|
-
});
|
|
132
|
-
it("should log warnings when validate=true", () => {
|
|
133
|
-
formspecWithValidation({ validate: true }, field.text("name"), field.text("name"));
|
|
134
|
-
expect(consoleWarnSpy).toHaveBeenCalled();
|
|
135
|
-
});
|
|
136
|
-
it("should log errors when validate=true and there are errors", () => {
|
|
137
|
-
formspecWithValidation({ validate: true }, field.text("name"), when(is("nonExistent", "value"), field.text("notes")));
|
|
138
|
-
expect(consoleErrorSpy).toHaveBeenCalled();
|
|
139
|
-
});
|
|
140
|
-
it("should include form name in validation messages", () => {
|
|
141
|
-
formspecWithValidation({ validate: true, name: "TestForm" }, field.text("name"), field.text("name"));
|
|
142
|
-
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining("TestForm"));
|
|
143
|
-
});
|
|
144
|
-
it("should throw when validate='throw' and there are errors", () => {
|
|
145
|
-
expect(() => formspecWithValidation({ validate: "throw" }, field.text("name"), when(is("nonExistent", "value"), field.text("notes")))).toThrow("Form validation failed");
|
|
146
|
-
});
|
|
147
|
-
it("should not throw when validate='throw' and there are only warnings", () => {
|
|
148
|
-
expect(() => formspecWithValidation({ validate: "throw" }, field.text("name"), field.text("name"))).not.toThrow();
|
|
149
|
-
});
|
|
150
|
-
it("should work with validate='warn'", () => {
|
|
151
|
-
formspecWithValidation({ validate: "warn" }, field.text("name"), field.text("name"));
|
|
152
|
-
expect(consoleWarnSpy).toHaveBeenCalled();
|
|
153
|
-
});
|
|
154
|
-
it("should return correct form structure regardless of validation", () => {
|
|
155
|
-
const form = formspecWithValidation({ validate: true, name: "Test" }, field.text("name"), field.number("age"));
|
|
156
|
-
expect(form.elements).toHaveLength(2);
|
|
157
|
-
expect(form.elements[0]._type).toBe("field");
|
|
158
|
-
expect(form.elements[1]._type).toBe("field");
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
describe("validation with complex structures", () => {
|
|
162
|
-
it("should validate fields inside object fields", () => {
|
|
163
|
-
const elements = [
|
|
164
|
-
field.object("address", field.text("street"), field.text("street")),
|
|
165
|
-
];
|
|
166
|
-
const result = validateForm(elements);
|
|
167
|
-
expect(result.issues).toHaveLength(1);
|
|
168
|
-
expect(result.issues[0].message).toContain('"street"');
|
|
169
|
-
});
|
|
170
|
-
it("should validate deeply nested structures", () => {
|
|
171
|
-
const elements = [
|
|
172
|
-
group("Outer", group("Inner", field.enum("type", ["a", "b"]), when(is("type", "a"), field.object("details", field.text("name"), when(is("missing", "value"), // doesn't exist!
|
|
173
|
-
field.text("extra")))))),
|
|
174
|
-
];
|
|
175
|
-
const result = validateForm(elements);
|
|
176
|
-
expect(result.valid).toBe(false);
|
|
177
|
-
expect(result.issues.some((i) => i.message.includes('"missing"'))).toBe(true);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
//# sourceMappingURL=validation.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.test.js","sourceRoot":"","sources":["../../src/__tests__/validation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAA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AAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/field.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Field builder functions for creating form field definitions.
|
|
3
|
-
*
|
|
4
|
-
* Each function creates a field descriptor that captures both schema information
|
|
5
|
-
* (name, type) and UI hints (label, placeholder, etc.).
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Field builder namespace containing functions to create each field type.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { field } from "@formspec/dsl";
|
|
13
|
-
*
|
|
14
|
-
* field.text("name", { label: "Full Name" });
|
|
15
|
-
* field.number("age", { min: 0, max: 150 });
|
|
16
|
-
* field.enum("status", ["draft", "sent", "paid"]);
|
|
17
|
-
* field.dynamicEnum("country", "countries", { label: "Country" });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export const field = {
|
|
21
|
-
/**
|
|
22
|
-
* Creates a text input field.
|
|
23
|
-
*
|
|
24
|
-
* @param name - The field name (used as the schema key)
|
|
25
|
-
* @param config - Optional configuration for label, placeholder, etc.
|
|
26
|
-
* @returns A TextField descriptor
|
|
27
|
-
*/
|
|
28
|
-
text: (name, config) => ({
|
|
29
|
-
_type: "field",
|
|
30
|
-
_field: "text",
|
|
31
|
-
name,
|
|
32
|
-
...config,
|
|
33
|
-
}),
|
|
34
|
-
/**
|
|
35
|
-
* Creates a numeric input field.
|
|
36
|
-
*
|
|
37
|
-
* @param name - The field name (used as the schema key)
|
|
38
|
-
* @param config - Optional configuration for label, min, max, etc.
|
|
39
|
-
* @returns A NumberField descriptor
|
|
40
|
-
*/
|
|
41
|
-
number: (name, config) => ({
|
|
42
|
-
_type: "field",
|
|
43
|
-
_field: "number",
|
|
44
|
-
name,
|
|
45
|
-
...config,
|
|
46
|
-
}),
|
|
47
|
-
/**
|
|
48
|
-
* Creates a boolean checkbox field.
|
|
49
|
-
*
|
|
50
|
-
* @param name - The field name (used as the schema key)
|
|
51
|
-
* @param config - Optional configuration for label, etc.
|
|
52
|
-
* @returns A BooleanField descriptor
|
|
53
|
-
*/
|
|
54
|
-
boolean: (name, config) => ({
|
|
55
|
-
_type: "field",
|
|
56
|
-
_field: "boolean",
|
|
57
|
-
name,
|
|
58
|
-
...config,
|
|
59
|
-
}),
|
|
60
|
-
/**
|
|
61
|
-
* Creates a field with static enum options (known at compile time).
|
|
62
|
-
*
|
|
63
|
-
* Literal types are automatically inferred - no `as const` needed:
|
|
64
|
-
* ```typescript
|
|
65
|
-
* field.enum("status", ["draft", "sent", "paid"])
|
|
66
|
-
* // Schema type: "draft" | "sent" | "paid"
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* @param name - The field name (used as the schema key)
|
|
70
|
-
* @param options - Array of allowed string values
|
|
71
|
-
* @param config - Optional configuration for label, etc.
|
|
72
|
-
* @returns A StaticEnumField descriptor
|
|
73
|
-
*/
|
|
74
|
-
enum: (name, options, config) => ({
|
|
75
|
-
_type: "field",
|
|
76
|
-
_field: "enum",
|
|
77
|
-
name,
|
|
78
|
-
options,
|
|
79
|
-
...config,
|
|
80
|
-
}),
|
|
81
|
-
/**
|
|
82
|
-
* Creates a field with dynamic enum options (fetched from a data source at runtime).
|
|
83
|
-
*
|
|
84
|
-
* The data source must be registered in DataSourceRegistry via module augmentation:
|
|
85
|
-
* ```typescript
|
|
86
|
-
* declare module "@formspec/core" {
|
|
87
|
-
* interface DataSourceRegistry {
|
|
88
|
-
* countries: { id: string; code: string; name: string };
|
|
89
|
-
* }
|
|
90
|
-
* }
|
|
91
|
-
*
|
|
92
|
-
* field.dynamicEnum("country", "countries", { label: "Country" })
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* @param name - The field name (used as the schema key)
|
|
96
|
-
* @param source - The data source key (must be in DataSourceRegistry)
|
|
97
|
-
* @param config - Optional configuration for label, params, etc.
|
|
98
|
-
* @returns A DynamicEnumField descriptor
|
|
99
|
-
*/
|
|
100
|
-
dynamicEnum: (name, source, config) => ({
|
|
101
|
-
_type: "field",
|
|
102
|
-
_field: "dynamic_enum",
|
|
103
|
-
name,
|
|
104
|
-
source,
|
|
105
|
-
...config,
|
|
106
|
-
}),
|
|
107
|
-
/**
|
|
108
|
-
* Creates a field that loads its schema dynamically (e.g., from an extension).
|
|
109
|
-
*
|
|
110
|
-
* @param name - The field name (used as the schema key)
|
|
111
|
-
* @param schemaSource - Identifier for the schema source
|
|
112
|
-
* @param config - Optional configuration for label, etc.
|
|
113
|
-
* @returns A DynamicSchemaField descriptor
|
|
114
|
-
*/
|
|
115
|
-
dynamicSchema: (name, schemaSource, config) => ({
|
|
116
|
-
_type: "field",
|
|
117
|
-
_field: "dynamic_schema",
|
|
118
|
-
name,
|
|
119
|
-
schemaSource,
|
|
120
|
-
...config,
|
|
121
|
-
}),
|
|
122
|
-
/**
|
|
123
|
-
* Creates an array field containing repeating items.
|
|
124
|
-
*
|
|
125
|
-
* Use this for lists of values (e.g., multiple addresses, line items).
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```typescript
|
|
129
|
-
* field.array("addresses",
|
|
130
|
-
* field.text("street", { label: "Street" }),
|
|
131
|
-
* field.text("city", { label: "City" }),
|
|
132
|
-
* field.text("zip", { label: "ZIP Code" }),
|
|
133
|
-
* )
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
* @param name - The field name (used as the schema key)
|
|
137
|
-
* @param items - The form elements that define each array item
|
|
138
|
-
* @returns An ArrayField descriptor
|
|
139
|
-
*/
|
|
140
|
-
array: (name, ...items) => ({
|
|
141
|
-
_type: "field",
|
|
142
|
-
_field: "array",
|
|
143
|
-
name,
|
|
144
|
-
items,
|
|
145
|
-
}),
|
|
146
|
-
/**
|
|
147
|
-
* Creates an array field with additional configuration options.
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```typescript
|
|
151
|
-
* field.arrayWithConfig("lineItems", {
|
|
152
|
-
* label: "Line Items",
|
|
153
|
-
* minItems: 1,
|
|
154
|
-
* maxItems: 10,
|
|
155
|
-
* },
|
|
156
|
-
* field.text("description"),
|
|
157
|
-
* field.number("quantity"),
|
|
158
|
-
* )
|
|
159
|
-
* ```
|
|
160
|
-
*
|
|
161
|
-
* @param name - The field name (used as the schema key)
|
|
162
|
-
* @param config - Configuration for label, minItems, maxItems, etc.
|
|
163
|
-
* @param items - The form elements that define each array item
|
|
164
|
-
* @returns An ArrayField descriptor
|
|
165
|
-
*/
|
|
166
|
-
arrayWithConfig: (name, config, ...items) => ({
|
|
167
|
-
_type: "field",
|
|
168
|
-
_field: "array",
|
|
169
|
-
name,
|
|
170
|
-
items,
|
|
171
|
-
...config,
|
|
172
|
-
}),
|
|
173
|
-
/**
|
|
174
|
-
* Creates an object field containing nested properties.
|
|
175
|
-
*
|
|
176
|
-
* Use this for grouping related fields under a single key in the schema.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```typescript
|
|
180
|
-
* field.object("address",
|
|
181
|
-
* field.text("street", { label: "Street" }),
|
|
182
|
-
* field.text("city", { label: "City" }),
|
|
183
|
-
* field.text("zip", { label: "ZIP Code" }),
|
|
184
|
-
* )
|
|
185
|
-
* ```
|
|
186
|
-
*
|
|
187
|
-
* @param name - The field name (used as the schema key)
|
|
188
|
-
* @param properties - The form elements that define the object's properties
|
|
189
|
-
* @returns An ObjectField descriptor
|
|
190
|
-
*/
|
|
191
|
-
object: (name, ...properties) => ({
|
|
192
|
-
_type: "field",
|
|
193
|
-
_field: "object",
|
|
194
|
-
name,
|
|
195
|
-
properties,
|
|
196
|
-
}),
|
|
197
|
-
/**
|
|
198
|
-
* Creates an object field with additional configuration options.
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```typescript
|
|
202
|
-
* field.objectWithConfig("billingAddress", { label: "Billing Address", required: true },
|
|
203
|
-
* field.text("street"),
|
|
204
|
-
* field.text("city"),
|
|
205
|
-
* )
|
|
206
|
-
* ```
|
|
207
|
-
*
|
|
208
|
-
* @param name - The field name (used as the schema key)
|
|
209
|
-
* @param config - Configuration for label, required, etc.
|
|
210
|
-
* @param properties - The form elements that define the object's properties
|
|
211
|
-
* @returns An ObjectField descriptor
|
|
212
|
-
*/
|
|
213
|
-
objectWithConfig: (name, config, ...properties) => ({
|
|
214
|
-
_type: "field",
|
|
215
|
-
_field: "object",
|
|
216
|
-
name,
|
|
217
|
-
properties,
|
|
218
|
-
...config,
|
|
219
|
-
}),
|
|
220
|
-
};
|
|
221
|
-
//# sourceMappingURL=field.js.map
|
package/dist/field.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB;;;;;;OAMG;IACH,IAAI,EAAE,CACJ,IAAO,EACP,MAAwD,EAC1C,EAAE,CAAC,CAAC;QAClB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,MAAM;QACd,IAAI;QACJ,GAAG,MAAM;KACV,CAAC;IAEF;;;;;;OAMG;IACH,MAAM,EAAE,CACN,IAAO,EACP,MAA0D,EAC1C,EAAE,CAAC,CAAC;QACpB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,IAAI;QACJ,GAAG,MAAM;KACV,CAAC;IAEF;;;;;;OAMG;IACH,OAAO,EAAE,CACP,IAAO,EACP,MAA2D,EAC1C,EAAE,CAAC,CAAC;QACrB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,SAAS;QACjB,IAAI;QACJ,GAAG,MAAM;KACV,CAAC;IAEF;;;;;;;;;;;;;OAaG;IACH,IAAI,EAAE,CACJ,IA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,EAAE,CAAC,CAAC;QAChC,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,IAAI;QACJ,UAAU;QACV,GAAG,MAAM;KACV,CAAC;CACH,CAAC"}
|
package/dist/inference.js
DELETED
package/dist/inference.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inference.js","sourceRoot":"","sources":["../src/inference.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/predicate.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Predicate builder functions for conditional logic.
|
|
3
|
-
*
|
|
4
|
-
* These functions create predicates for use with `when()`:
|
|
5
|
-
* - `is()` - Check if a field equals a specific value
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* when(is("status", "draft"),
|
|
10
|
-
* field.text("notes"),
|
|
11
|
-
* )
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Creates an equality predicate that checks if a field equals a specific value.
|
|
16
|
-
*
|
|
17
|
-
* Use this with `when()` to create readable conditional expressions:
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* // Show cardNumber field when paymentMethod is "card"
|
|
22
|
-
* when(is("paymentMethod", "card"),
|
|
23
|
-
* field.text("cardNumber", { label: "Card Number" }),
|
|
24
|
-
* )
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @typeParam K - The field name (inferred as string literal)
|
|
28
|
-
* @typeParam V - The value type (inferred as literal)
|
|
29
|
-
* @param field - The name of the field to check
|
|
30
|
-
* @param value - The value the field must equal
|
|
31
|
-
* @returns An EqualsPredicate for use with `when()`
|
|
32
|
-
*/
|
|
33
|
-
export function is(field, value) {
|
|
34
|
-
return {
|
|
35
|
-
_predicate: "equals",
|
|
36
|
-
field,
|
|
37
|
-
value,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=predicate.js.map
|
package/dist/predicate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"predicate.js","sourceRoot":"","sources":["../src/predicate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,EAAE,CAChB,KAAQ,EACR,KAAQ;IAER,OAAO;QACL,UAAU,EAAE,QAAQ;QACpB,KAAK;QACL,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/dist/structure.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structure builder functions for organizing form elements.
|
|
3
|
-
*
|
|
4
|
-
* These functions create layout and conditional structures:
|
|
5
|
-
* - `group()` - Visual grouping of fields
|
|
6
|
-
* - `when()` - Conditional visibility based on field values
|
|
7
|
-
* - `formspec()` - Top-level form specification
|
|
8
|
-
*/
|
|
9
|
-
import { validateForm, logValidationIssues } from "./validation.js";
|
|
10
|
-
/**
|
|
11
|
-
* Creates a visual group of form elements.
|
|
12
|
-
*
|
|
13
|
-
* Groups provide visual organization and can be rendered as fieldsets or sections.
|
|
14
|
-
* The nesting of groups defines the visual hierarchy of the form.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* group("Customer Information",
|
|
19
|
-
* field.text("name", { label: "Name" }),
|
|
20
|
-
* field.text("email", { label: "Email" }),
|
|
21
|
-
* )
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @param label - The group's display label
|
|
25
|
-
* @param elements - The form elements contained in this group
|
|
26
|
-
* @returns A Group descriptor
|
|
27
|
-
*/
|
|
28
|
-
export function group(label, ...elements) {
|
|
29
|
-
return { _type: "group", label, elements };
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Creates a conditional wrapper that shows elements based on a predicate.
|
|
33
|
-
*
|
|
34
|
-
* When the predicate evaluates to true, the contained elements are shown.
|
|
35
|
-
* Otherwise, they are hidden (but still part of the schema).
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* import { is } from "@formspec/dsl";
|
|
40
|
-
*
|
|
41
|
-
* field.enum("status", ["draft", "sent", "paid"] as const),
|
|
42
|
-
* when(is("status", "draft"),
|
|
43
|
-
* field.text("internalNotes", { label: "Internal Notes" }),
|
|
44
|
-
* )
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @param predicate - The condition to evaluate (use `is()` to create)
|
|
48
|
-
* @param elements - The form elements to show when condition is met
|
|
49
|
-
* @returns A Conditional descriptor
|
|
50
|
-
*/
|
|
51
|
-
export function when(predicate, ...elements) {
|
|
52
|
-
return {
|
|
53
|
-
_type: "conditional",
|
|
54
|
-
field: predicate.field,
|
|
55
|
-
value: predicate.value,
|
|
56
|
-
elements,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Creates a complete form specification.
|
|
61
|
-
*
|
|
62
|
-
* The structure IS the definition:
|
|
63
|
-
* - Nesting with `group()` defines visual layout
|
|
64
|
-
* - Nesting with `when()` defines conditional visibility
|
|
65
|
-
* - Field type implies control type (text field → text input)
|
|
66
|
-
* - Array position implies field ordering
|
|
67
|
-
*
|
|
68
|
-
* Schema is automatically inferred from all fields in the structure.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const InvoiceForm = formspec(
|
|
73
|
-
* group("Customer",
|
|
74
|
-
* field.text("customerName", { label: "Customer Name" }),
|
|
75
|
-
* field.dynamicEnum("country", "fetch_countries", { label: "Country" }),
|
|
76
|
-
* ),
|
|
77
|
-
* group("Invoice Details",
|
|
78
|
-
* field.number("amount", { label: "Amount", min: 0 }),
|
|
79
|
-
* field.enum("status", ["draft", "sent", "paid"] as const),
|
|
80
|
-
* when(is("status", "draft"),
|
|
81
|
-
* field.text("internalNotes", { label: "Internal Notes" }),
|
|
82
|
-
* ),
|
|
83
|
-
* ),
|
|
84
|
-
* );
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @param elements - The top-level form elements
|
|
88
|
-
* @returns A FormSpec descriptor
|
|
89
|
-
*/
|
|
90
|
-
export function formspec(...elements) {
|
|
91
|
-
return { elements };
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Creates a complete form specification with validation options.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
* const form = formspecWithValidation(
|
|
99
|
-
* { validate: true, name: "MyForm" },
|
|
100
|
-
* field.text("name"),
|
|
101
|
-
* field.enum("status", ["draft", "sent"] as const),
|
|
102
|
-
* when(is("status", "draft"),
|
|
103
|
-
* field.text("notes"),
|
|
104
|
-
* ),
|
|
105
|
-
* );
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* @param options - Validation options
|
|
109
|
-
* @param elements - The top-level form elements
|
|
110
|
-
* @returns A FormSpec descriptor
|
|
111
|
-
*/
|
|
112
|
-
export function formspecWithValidation(options, ...elements) {
|
|
113
|
-
// Run validation if requested
|
|
114
|
-
if (options.validate) {
|
|
115
|
-
const result = validateForm(elements);
|
|
116
|
-
if (options.validate === "throw" && !result.valid) {
|
|
117
|
-
const errors = result.issues
|
|
118
|
-
.filter((i) => i.severity === "error")
|
|
119
|
-
.map((i) => i.message)
|
|
120
|
-
.join("; ");
|
|
121
|
-
throw new Error(`Form validation failed: ${errors}`);
|
|
122
|
-
}
|
|
123
|
-
if (options.validate === true || options.validate === "warn") {
|
|
124
|
-
logValidationIssues(result, options.name);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return { elements };
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=structure.js.map
|
package/dist/structure.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"structure.js","sourceRoot":"","sources":["../src/structure.ts"],"names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