@formspec/constraints 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 +263 -0
- package/dist/__tests__/loader.test.d.ts +2 -0
- package/dist/__tests__/loader.test.d.ts.map +1 -0
- package/dist/__tests__/loader.test.js +133 -0
- package/dist/__tests__/loader.test.js.map +1 -0
- package/dist/__tests__/validators.test.d.ts +2 -0
- package/dist/__tests__/validators.test.d.ts.map +1 -0
- package/dist/__tests__/validators.test.js +404 -0
- package/dist/__tests__/validators.test.js.map +1 -0
- package/dist/browser.d.ts +51 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +65 -0
- package/dist/browser.js.map +1 -0
- package/dist/constraints.d.ts +544 -0
- package/dist/defaults.d.ts +15 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +106 -0
- package/dist/defaults.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +81 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +140 -0
- package/dist/loader.js.map +1 -0
- package/dist/types.d.ts +200 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validators/field-options.d.ts +49 -0
- package/dist/validators/field-options.d.ts.map +1 -0
- package/dist/validators/field-options.js +79 -0
- package/dist/validators/field-options.js.map +1 -0
- package/dist/validators/field-types.d.ts +38 -0
- package/dist/validators/field-types.d.ts.map +1 -0
- package/dist/validators/field-types.js +93 -0
- package/dist/validators/field-types.js.map +1 -0
- package/dist/validators/formspec.d.ts +54 -0
- package/dist/validators/formspec.d.ts.map +1 -0
- package/dist/validators/formspec.js +152 -0
- package/dist/validators/formspec.js.map +1 -0
- package/dist/validators/index.d.ts +5 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +5 -0
- package/dist/validators/index.js.map +1 -0
- package/dist/validators/layout.d.ts +39 -0
- package/dist/validators/layout.d.ts.map +1 -0
- package/dist/validators/layout.js +107 -0
- package/dist/validators/layout.js.map +1 -0
- package/formspec.schema.json +245 -0
- package/package.json +57 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { field, group, when, is, formspec } from "@formspec/dsl";
|
|
3
|
+
import { validateFormSpecElements, validateFormSpec, validateFieldTypes, validateLayout, validateFieldOptions, extractFieldOptions, defineConstraints, isFieldTypeAllowed, getFieldTypeSeverity, isFieldOptionAllowed, getFieldOptionSeverity, isLayoutTypeAllowed, isNestingDepthAllowed, } from "../index.js";
|
|
4
|
+
describe("validateFieldTypes", () => {
|
|
5
|
+
it("returns no issues when field type is allowed", () => {
|
|
6
|
+
const issues = validateFieldTypes({ fieldType: "text", fieldName: "name" }, { text: "off" });
|
|
7
|
+
expect(issues).toHaveLength(0);
|
|
8
|
+
});
|
|
9
|
+
it("returns error when field type is disallowed", () => {
|
|
10
|
+
const issues = validateFieldTypes({ fieldType: "dynamic_enum", fieldName: "country" }, { dynamicEnum: "error" });
|
|
11
|
+
expect(issues).toHaveLength(1);
|
|
12
|
+
expect(issues[0]).toMatchObject({
|
|
13
|
+
code: "DISALLOWED_FIELD_TYPE",
|
|
14
|
+
severity: "error",
|
|
15
|
+
fieldName: "country",
|
|
16
|
+
fieldType: "dynamic_enum",
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it("returns warning when field type has warn severity", () => {
|
|
20
|
+
const issues = validateFieldTypes({ fieldType: "array", fieldName: "items" }, { array: "warn" });
|
|
21
|
+
expect(issues).toHaveLength(1);
|
|
22
|
+
expect(issues[0]?.severity).toBe("warning");
|
|
23
|
+
});
|
|
24
|
+
it("includes path in issue when provided", () => {
|
|
25
|
+
const issues = validateFieldTypes({ fieldType: "object", fieldName: "address", path: "user/address" }, { object: "error" });
|
|
26
|
+
expect(issues[0]?.path).toBe("user/address");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe("validateLayout", () => {
|
|
30
|
+
it("returns no issues when group is allowed", () => {
|
|
31
|
+
const issues = validateLayout({ layoutType: "group", label: "Contact", depth: 0 }, { group: "off" });
|
|
32
|
+
expect(issues).toHaveLength(0);
|
|
33
|
+
});
|
|
34
|
+
it("returns error when group is disallowed", () => {
|
|
35
|
+
const issues = validateLayout({ layoutType: "group", label: "Contact", depth: 0 }, { group: "error" });
|
|
36
|
+
expect(issues).toHaveLength(1);
|
|
37
|
+
expect(issues[0]).toMatchObject({
|
|
38
|
+
code: "DISALLOWED_GROUP",
|
|
39
|
+
severity: "error",
|
|
40
|
+
});
|
|
41
|
+
expect(issues[0]?.message).toContain("Contact");
|
|
42
|
+
});
|
|
43
|
+
it("returns error when conditional is disallowed", () => {
|
|
44
|
+
const issues = validateLayout({ layoutType: "conditional", depth: 0 }, { conditionals: "error" });
|
|
45
|
+
expect(issues).toHaveLength(1);
|
|
46
|
+
expect(issues[0]).toMatchObject({
|
|
47
|
+
code: "DISALLOWED_CONDITIONAL",
|
|
48
|
+
severity: "error",
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it("returns error when nesting depth exceeded", () => {
|
|
52
|
+
const issues = validateLayout({ layoutType: "group", depth: 3 }, { maxNestingDepth: 2 });
|
|
53
|
+
expect(issues).toHaveLength(1);
|
|
54
|
+
expect(issues[0]).toMatchObject({
|
|
55
|
+
code: "EXCEEDED_NESTING_DEPTH",
|
|
56
|
+
severity: "error",
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
it("allows nesting at exact max depth", () => {
|
|
60
|
+
const issues = validateLayout({ layoutType: "group", depth: 2 }, { maxNestingDepth: 2 });
|
|
61
|
+
// Should only have group issue if group is disallowed, not depth issue
|
|
62
|
+
const depthIssues = issues.filter((i) => i.code === "EXCEEDED_NESTING_DEPTH");
|
|
63
|
+
expect(depthIssues).toHaveLength(0);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe("validateFieldOptions", () => {
|
|
67
|
+
it("returns no issues when options are allowed", () => {
|
|
68
|
+
const issues = validateFieldOptions({ fieldName: "age", presentOptions: ["minValue", "maxValue"] }, { minValue: "off", maxValue: "off" });
|
|
69
|
+
expect(issues).toHaveLength(0);
|
|
70
|
+
});
|
|
71
|
+
it("returns error when option is disallowed", () => {
|
|
72
|
+
const issues = validateFieldOptions({ fieldName: "notes", presentOptions: ["placeholder"] }, { placeholder: "error" });
|
|
73
|
+
expect(issues).toHaveLength(1);
|
|
74
|
+
expect(issues[0]).toMatchObject({
|
|
75
|
+
code: "DISALLOWED_FIELD_OPTION",
|
|
76
|
+
severity: "error",
|
|
77
|
+
fieldName: "notes",
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
it("returns multiple issues for multiple disallowed options", () => {
|
|
81
|
+
const issues = validateFieldOptions({ fieldName: "items", presentOptions: ["minItems", "maxItems"] }, { minItems: "error", maxItems: "error" });
|
|
82
|
+
expect(issues).toHaveLength(2);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("extractFieldOptions", () => {
|
|
86
|
+
it("extracts present options from field object", () => {
|
|
87
|
+
const options = extractFieldOptions({
|
|
88
|
+
name: "age",
|
|
89
|
+
label: "Age",
|
|
90
|
+
minValue: 0,
|
|
91
|
+
maxValue: 120,
|
|
92
|
+
});
|
|
93
|
+
expect(options).toContain("label");
|
|
94
|
+
expect(options).toContain("minValue");
|
|
95
|
+
expect(options).toContain("maxValue");
|
|
96
|
+
expect(options).not.toContain("placeholder");
|
|
97
|
+
});
|
|
98
|
+
it("returns empty array for field with no options", () => {
|
|
99
|
+
const options = extractFieldOptions({ name: "test" });
|
|
100
|
+
expect(options).toHaveLength(0);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe("validateFormSpecElements", () => {
|
|
104
|
+
it("validates a simple form with no constraints", () => {
|
|
105
|
+
const form = formspec(field.text("name", { label: "Name" }), field.number("age", { label: "Age" }));
|
|
106
|
+
const result = validateFormSpecElements(form.elements);
|
|
107
|
+
expect(result.valid).toBe(true);
|
|
108
|
+
expect(result.issues).toHaveLength(0);
|
|
109
|
+
});
|
|
110
|
+
it("validates field types against constraints", () => {
|
|
111
|
+
const form = formspec(field.text("name"), field.dynamicEnum("country", "countries"));
|
|
112
|
+
const result = validateFormSpecElements(form.elements, {
|
|
113
|
+
constraints: {
|
|
114
|
+
fieldTypes: { dynamicEnum: "error" },
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
expect(result.valid).toBe(false);
|
|
118
|
+
expect(result.issues).toHaveLength(1);
|
|
119
|
+
expect(result.issues[0]).toMatchObject({
|
|
120
|
+
code: "DISALLOWED_FIELD_TYPE",
|
|
121
|
+
fieldType: "dynamic_enum",
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
it("validates groups against constraints", () => {
|
|
125
|
+
const form = formspec(group("Contact", field.text("name"), field.text("email")));
|
|
126
|
+
const result = validateFormSpecElements(form.elements, {
|
|
127
|
+
constraints: {
|
|
128
|
+
layout: { group: "error" },
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
expect(result.valid).toBe(false);
|
|
132
|
+
expect(result.issues.some((i) => i.code === "DISALLOWED_GROUP")).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
it("validates conditionals against constraints", () => {
|
|
135
|
+
const form = formspec(field.enum("type", ["personal", "business"]), when(is("type", "business"), field.text("company")));
|
|
136
|
+
const result = validateFormSpecElements(form.elements, {
|
|
137
|
+
constraints: {
|
|
138
|
+
layout: { conditionals: "error" },
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
expect(result.valid).toBe(false);
|
|
142
|
+
expect(result.issues.some((i) => i.code === "DISALLOWED_CONDITIONAL")).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
it("validates nested object fields", () => {
|
|
145
|
+
const form = formspec(field.object("address", field.text("street"), field.object("country", field.text("code"), field.text("name"))));
|
|
146
|
+
const result = validateFormSpecElements(form.elements, {
|
|
147
|
+
constraints: {
|
|
148
|
+
layout: { maxNestingDepth: 1 },
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
expect(result.valid).toBe(false);
|
|
152
|
+
expect(result.issues.some((i) => i.code === "EXCEEDED_NESTING_DEPTH")).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
it("validates field options", () => {
|
|
155
|
+
const form = formspec(field.number("quantity", { min: 1, max: 100 }));
|
|
156
|
+
const result = validateFormSpecElements(form.elements, {
|
|
157
|
+
constraints: {
|
|
158
|
+
fieldOptions: { minValue: "error", maxValue: "error" },
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
expect(result.valid).toBe(false);
|
|
162
|
+
expect(result.issues).toHaveLength(2);
|
|
163
|
+
expect(result.issues.every((i) => i.code === "DISALLOWED_FIELD_OPTION")).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
it("passes with warnings but valid=true", () => {
|
|
166
|
+
const form = formspec(field.dynamicEnum("country", "countries"));
|
|
167
|
+
const result = validateFormSpecElements(form.elements, {
|
|
168
|
+
constraints: {
|
|
169
|
+
fieldTypes: { dynamicEnum: "warn" },
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
expect(result.valid).toBe(true);
|
|
173
|
+
expect(result.issues).toHaveLength(1);
|
|
174
|
+
expect(result.issues[0]?.severity).toBe("warning");
|
|
175
|
+
});
|
|
176
|
+
it("validates array items recursively", () => {
|
|
177
|
+
const form = formspec(field.array("items", field.text("description"), field.dynamicEnum("category", "categories")));
|
|
178
|
+
const result = validateFormSpecElements(form.elements, {
|
|
179
|
+
constraints: {
|
|
180
|
+
fieldTypes: { dynamicEnum: "error" },
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
expect(result.valid).toBe(false);
|
|
184
|
+
expect(result.issues.some((i) => i.fieldType === "dynamic_enum")).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
describe("defineConstraints", () => {
|
|
188
|
+
it("merges partial config with defaults", () => {
|
|
189
|
+
const config = defineConstraints({
|
|
190
|
+
fieldTypes: { dynamicEnum: "error" },
|
|
191
|
+
});
|
|
192
|
+
expect(config.fieldTypes.dynamicEnum).toBe("error");
|
|
193
|
+
expect(config.fieldTypes.text).toBe("off");
|
|
194
|
+
expect(config.layout.group).toBe("off");
|
|
195
|
+
});
|
|
196
|
+
it("preserves all provided values", () => {
|
|
197
|
+
const config = defineConstraints({
|
|
198
|
+
fieldTypes: {
|
|
199
|
+
text: "warn",
|
|
200
|
+
number: "error",
|
|
201
|
+
},
|
|
202
|
+
layout: {
|
|
203
|
+
group: "error",
|
|
204
|
+
maxNestingDepth: 2,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
expect(config.fieldTypes.text).toBe("warn");
|
|
208
|
+
expect(config.fieldTypes.number).toBe("error");
|
|
209
|
+
expect(config.layout.group).toBe("error");
|
|
210
|
+
expect(config.layout.maxNestingDepth).toBe(2);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
describe("validateFormSpec", () => {
|
|
214
|
+
it("validates a FormSpec object directly", () => {
|
|
215
|
+
const form = formspec(field.text("name"), field.dynamicEnum("country", "countries"));
|
|
216
|
+
const result = validateFormSpec(form, {
|
|
217
|
+
constraints: {
|
|
218
|
+
fieldTypes: { dynamicEnum: "error" },
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
expect(result.valid).toBe(false);
|
|
222
|
+
expect(result.issues).toHaveLength(1);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
describe("isFieldTypeAllowed", () => {
|
|
226
|
+
it("returns true when field type severity is off", () => {
|
|
227
|
+
expect(isFieldTypeAllowed("text", { text: "off" })).toBe(true);
|
|
228
|
+
});
|
|
229
|
+
it("returns true when field type is not in constraints", () => {
|
|
230
|
+
expect(isFieldTypeAllowed("text", {})).toBe(true);
|
|
231
|
+
});
|
|
232
|
+
it("returns false when field type severity is error", () => {
|
|
233
|
+
expect(isFieldTypeAllowed("dynamic_enum", { dynamicEnum: "error" })).toBe(false);
|
|
234
|
+
});
|
|
235
|
+
it("returns false when field type severity is warn", () => {
|
|
236
|
+
expect(isFieldTypeAllowed("array", { array: "warn" })).toBe(false);
|
|
237
|
+
});
|
|
238
|
+
it("handles unknown field types gracefully", () => {
|
|
239
|
+
// Unknown field types should not cause errors
|
|
240
|
+
expect(isFieldTypeAllowed("unknown_type", { text: "error" })).toBe(true);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
describe("getFieldTypeSeverity", () => {
|
|
244
|
+
it("returns severity when field type is constrained", () => {
|
|
245
|
+
expect(getFieldTypeSeverity("dynamic_enum", { dynamicEnum: "error" })).toBe("error");
|
|
246
|
+
});
|
|
247
|
+
it("returns off when field type is not constrained", () => {
|
|
248
|
+
expect(getFieldTypeSeverity("text", {})).toBe("off");
|
|
249
|
+
});
|
|
250
|
+
it("returns warn when field type has warn severity", () => {
|
|
251
|
+
expect(getFieldTypeSeverity("array", { array: "warn" })).toBe("warn");
|
|
252
|
+
});
|
|
253
|
+
it("returns off for unknown field types", () => {
|
|
254
|
+
expect(getFieldTypeSeverity("unknown_type", { text: "error" })).toBe("off");
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
describe("isFieldOptionAllowed", () => {
|
|
258
|
+
it("returns true when option severity is off", () => {
|
|
259
|
+
expect(isFieldOptionAllowed("label", { label: "off" })).toBe(true);
|
|
260
|
+
});
|
|
261
|
+
it("returns true when option is not in constraints", () => {
|
|
262
|
+
expect(isFieldOptionAllowed("placeholder", {})).toBe(true);
|
|
263
|
+
});
|
|
264
|
+
it("returns false when option severity is error", () => {
|
|
265
|
+
expect(isFieldOptionAllowed("minValue", { minValue: "error" })).toBe(false);
|
|
266
|
+
});
|
|
267
|
+
it("returns false when option severity is warn", () => {
|
|
268
|
+
expect(isFieldOptionAllowed("maxItems", { maxItems: "warn" })).toBe(false);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
describe("getFieldOptionSeverity", () => {
|
|
272
|
+
it("returns severity when option is constrained", () => {
|
|
273
|
+
expect(getFieldOptionSeverity("placeholder", { placeholder: "error" })).toBe("error");
|
|
274
|
+
});
|
|
275
|
+
it("returns off when option is not constrained", () => {
|
|
276
|
+
expect(getFieldOptionSeverity("label", {})).toBe("off");
|
|
277
|
+
});
|
|
278
|
+
it("returns warn when option has warn severity", () => {
|
|
279
|
+
expect(getFieldOptionSeverity("required", { required: "warn" })).toBe("warn");
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
describe("isLayoutTypeAllowed", () => {
|
|
283
|
+
it("returns true when group is allowed", () => {
|
|
284
|
+
expect(isLayoutTypeAllowed("group", { group: "off" })).toBe(true);
|
|
285
|
+
});
|
|
286
|
+
it("returns true when layout type is not in constraints", () => {
|
|
287
|
+
expect(isLayoutTypeAllowed("group", {})).toBe(true);
|
|
288
|
+
expect(isLayoutTypeAllowed("conditional", {})).toBe(true);
|
|
289
|
+
});
|
|
290
|
+
it("returns false when group is disallowed", () => {
|
|
291
|
+
expect(isLayoutTypeAllowed("group", { group: "error" })).toBe(false);
|
|
292
|
+
});
|
|
293
|
+
it("returns false when conditional is disallowed", () => {
|
|
294
|
+
expect(isLayoutTypeAllowed("conditional", { conditionals: "error" })).toBe(false);
|
|
295
|
+
});
|
|
296
|
+
it("returns false when layout type has warn severity", () => {
|
|
297
|
+
expect(isLayoutTypeAllowed("group", { group: "warn" })).toBe(false);
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
describe("isNestingDepthAllowed", () => {
|
|
301
|
+
it("returns true when depth is within limit", () => {
|
|
302
|
+
expect(isNestingDepthAllowed(2, { maxNestingDepth: 5 })).toBe(true);
|
|
303
|
+
});
|
|
304
|
+
it("returns true when depth equals max", () => {
|
|
305
|
+
expect(isNestingDepthAllowed(3, { maxNestingDepth: 3 })).toBe(true);
|
|
306
|
+
});
|
|
307
|
+
it("returns false when depth exceeds max", () => {
|
|
308
|
+
expect(isNestingDepthAllowed(4, { maxNestingDepth: 3 })).toBe(false);
|
|
309
|
+
});
|
|
310
|
+
it("returns true when maxNestingDepth is not set", () => {
|
|
311
|
+
expect(isNestingDepthAllowed(10, {})).toBe(true);
|
|
312
|
+
});
|
|
313
|
+
it("returns true when maxNestingDepth is Infinity", () => {
|
|
314
|
+
expect(isNestingDepthAllowed(100, { maxNestingDepth: Infinity })).toBe(true);
|
|
315
|
+
});
|
|
316
|
+
it("handles depth of 0", () => {
|
|
317
|
+
expect(isNestingDepthAllowed(0, { maxNestingDepth: 0 })).toBe(true);
|
|
318
|
+
expect(isNestingDepthAllowed(0, { maxNestingDepth: 5 })).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
describe("extractFieldOptions", () => {
|
|
322
|
+
it("maps NumberField min/max to minValue/maxValue constraints", () => {
|
|
323
|
+
// NumberField in core uses min/max, but constraints use minValue/maxValue
|
|
324
|
+
const options = extractFieldOptions({
|
|
325
|
+
name: "quantity",
|
|
326
|
+
min: 1,
|
|
327
|
+
max: 100,
|
|
328
|
+
});
|
|
329
|
+
expect(options).toContain("minValue");
|
|
330
|
+
expect(options).toContain("maxValue");
|
|
331
|
+
});
|
|
332
|
+
it("extracts all known options", () => {
|
|
333
|
+
const options = extractFieldOptions({
|
|
334
|
+
name: "test",
|
|
335
|
+
label: "Test",
|
|
336
|
+
placeholder: "Enter value",
|
|
337
|
+
required: true,
|
|
338
|
+
min: 0,
|
|
339
|
+
max: 100,
|
|
340
|
+
minItems: 1,
|
|
341
|
+
maxItems: 10,
|
|
342
|
+
});
|
|
343
|
+
expect(options).toEqual(expect.arrayContaining([
|
|
344
|
+
"label",
|
|
345
|
+
"placeholder",
|
|
346
|
+
"required",
|
|
347
|
+
"minValue",
|
|
348
|
+
"maxValue",
|
|
349
|
+
"minItems",
|
|
350
|
+
"maxItems",
|
|
351
|
+
]));
|
|
352
|
+
});
|
|
353
|
+
it("ignores unknown properties", () => {
|
|
354
|
+
const options = extractFieldOptions({
|
|
355
|
+
name: "test",
|
|
356
|
+
unknownOption: "value",
|
|
357
|
+
anotherUnknown: 123,
|
|
358
|
+
});
|
|
359
|
+
expect(options).toHaveLength(0);
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
describe("validateFieldTypes - negative cases", () => {
|
|
363
|
+
it("ignores unknown field types", () => {
|
|
364
|
+
const issues = validateFieldTypes({ fieldType: "custom_unknown_type", fieldName: "test" }, { text: "error" });
|
|
365
|
+
expect(issues).toHaveLength(0);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
describe("validateLayout - warning severity", () => {
|
|
369
|
+
it("returns warning when group has warn severity", () => {
|
|
370
|
+
const issues = validateLayout({ layoutType: "group", label: "Test", depth: 0 }, { group: "warn" });
|
|
371
|
+
expect(issues).toHaveLength(1);
|
|
372
|
+
expect(issues[0]?.severity).toBe("warning");
|
|
373
|
+
});
|
|
374
|
+
it("returns warning when conditional has warn severity", () => {
|
|
375
|
+
const issues = validateLayout({ layoutType: "conditional", depth: 0 }, { conditionals: "warn" });
|
|
376
|
+
expect(issues).toHaveLength(1);
|
|
377
|
+
expect(issues[0]?.severity).toBe("warning");
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
describe("validateFieldOptions - warning severity", () => {
|
|
381
|
+
it("returns warning when option has warn severity", () => {
|
|
382
|
+
const issues = validateFieldOptions({ fieldName: "test", presentOptions: ["placeholder"] }, { placeholder: "warn" });
|
|
383
|
+
expect(issues).toHaveLength(1);
|
|
384
|
+
expect(issues[0]?.severity).toBe("warning");
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
describe("validateFormSpecElements - edge cases", () => {
|
|
388
|
+
it("handles empty elements array", () => {
|
|
389
|
+
const result = validateFormSpecElements([]);
|
|
390
|
+
expect(result.valid).toBe(true);
|
|
391
|
+
expect(result.issues).toHaveLength(0);
|
|
392
|
+
});
|
|
393
|
+
it("handles deeply nested objects", () => {
|
|
394
|
+
const form = formspec(field.object("level1", field.object("level2", field.object("level3", field.text("deepField")))));
|
|
395
|
+
const result = validateFormSpecElements(form.elements, {
|
|
396
|
+
constraints: {
|
|
397
|
+
layout: { maxNestingDepth: 2 },
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
expect(result.valid).toBe(false);
|
|
401
|
+
expect(result.issues.some((i) => i.code === "EXCEEDED_NESTING_DEPTH")).toBe(true);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
//# sourceMappingURL=validators.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.test.js","sourceRoot":"","sources":["../../src/__tests__/validators.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,MAAM,GAAG,kBAAkB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7F,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,MAAM,GAAG,kBAAkB,CAC/B,EAAE,SAAS,EAAE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AE,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACvC,MAAM,IAAI,GAAG,QAAQ,CACnB,KAAK,CAAC,MAAM,CACV,QAAQ,EACR,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CACxE,CACF,CAAC;QAEF,MAAM,MAAM,GAAG,wBAAwB,CAAC,IAAI,CAAC,QAAQ,EAAE;YACrD,WAAW,EAAE;gBACX,MAAM,EAAE,EAAE,eAAe,EAAE,CAAC,EAAE;aAC/B;SACF,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,wBAAwB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe exports from @formspec/constraints.
|
|
3
|
+
*
|
|
4
|
+
* This entry point excludes the file-based config loader (loadConfig)
|
|
5
|
+
* which requires Node.js APIs. Use this entry point for browser builds.
|
|
6
|
+
*
|
|
7
|
+
* For browser use:
|
|
8
|
+
* - Use loadConfigFromString() to parse YAML config strings
|
|
9
|
+
* - Use defineConstraints() for programmatic configuration
|
|
10
|
+
* - Use validateFormSpec() for validation
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
export type { Severity, FieldTypeConstraints, LayoutConstraints, LayoutTypeConstraints, RuleEffectConstraints, RuleConstraints, UISchemaConstraints, FieldOptionConstraints, ControlOptionConstraints, ConstraintConfig, ResolvedConstraintConfig, ResolvedUISchemaConstraints, ResolvedRuleConstraints, FormSpecConfig, ValidationIssue, ValidationResult, } from "./types.js";
|
|
15
|
+
import type { ConstraintConfig, ResolvedConstraintConfig } from "./types.js";
|
|
16
|
+
import { mergeWithDefaults, DEFAULT_CONSTRAINTS, DEFAULT_CONFIG } from "./defaults.js";
|
|
17
|
+
export { DEFAULT_CONSTRAINTS, DEFAULT_CONFIG, mergeWithDefaults };
|
|
18
|
+
/**
|
|
19
|
+
* Synchronously loads config from a pre-parsed YAML string.
|
|
20
|
+
* Useful for browser environments or when config is already available.
|
|
21
|
+
*
|
|
22
|
+
* @param yamlContent - The YAML content to parse
|
|
23
|
+
* @returns The parsed and merged configuration
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadConfigFromString(yamlContent: string): ResolvedConstraintConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a constraint configuration directly from an object.
|
|
28
|
+
* Useful for programmatic configuration without YAML.
|
|
29
|
+
*
|
|
30
|
+
* @param config - Partial constraint configuration
|
|
31
|
+
* @returns Complete configuration with defaults applied
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const config = defineConstraints({
|
|
36
|
+
* fieldTypes: {
|
|
37
|
+
* dynamicEnum: 'error',
|
|
38
|
+
* dynamicSchema: 'error',
|
|
39
|
+
* },
|
|
40
|
+
* layout: {
|
|
41
|
+
* group: 'error',
|
|
42
|
+
* },
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function defineConstraints(config: ConstraintConfig): ResolvedConstraintConfig;
|
|
47
|
+
export { validateFormSpecElements, validateFormSpec, type FormSpecValidationOptions, } from "./validators/formspec.js";
|
|
48
|
+
export { validateFieldTypes, isFieldTypeAllowed, getFieldTypeSeverity, type FieldTypeContext, } from "./validators/field-types.js";
|
|
49
|
+
export { validateLayout, isLayoutTypeAllowed, isNestingDepthAllowed, type LayoutContext, } from "./validators/layout.js";
|
|
50
|
+
export { validateFieldOptions, extractFieldOptions, isFieldOptionAllowed, getFieldOptionSeverity, type FieldOptionsContext, type FieldOption, } from "./validators/field-options.js";
|
|
51
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,YAAY,EACV,QAAQ,EACR,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EAChB,wBAAwB,EACxB,2BAA2B,EAC3B,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAKpB,OAAO,KAAK,EAAkB,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAC7F,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGvF,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,wBAAwB,CAYlF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,wBAAwB,CAEpF;AAGD,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,KAAK,yBAAyB,GAC/B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,gBAAgB,GACtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,aAAa,GACnB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,KAAK,mBAAmB,EACxB,KAAK,WAAW,GACjB,MAAM,+BAA+B,CAAC"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe exports from @formspec/constraints.
|
|
3
|
+
*
|
|
4
|
+
* This entry point excludes the file-based config loader (loadConfig)
|
|
5
|
+
* which requires Node.js APIs. Use this entry point for browser builds.
|
|
6
|
+
*
|
|
7
|
+
* For browser use:
|
|
8
|
+
* - Use loadConfigFromString() to parse YAML config strings
|
|
9
|
+
* - Use defineConstraints() for programmatic configuration
|
|
10
|
+
* - Use validateFormSpec() for validation
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
// Re-export browser-safe loader functions
|
|
15
|
+
// These are defined inline to avoid pulling in Node.js imports from loader.ts
|
|
16
|
+
import { parse as parseYaml } from "yaml";
|
|
17
|
+
import { mergeWithDefaults, DEFAULT_CONSTRAINTS, DEFAULT_CONFIG } from "./defaults.js";
|
|
18
|
+
// Re-export defaults
|
|
19
|
+
export { DEFAULT_CONSTRAINTS, DEFAULT_CONFIG, mergeWithDefaults };
|
|
20
|
+
/**
|
|
21
|
+
* Synchronously loads config from a pre-parsed YAML string.
|
|
22
|
+
* Useful for browser environments or when config is already available.
|
|
23
|
+
*
|
|
24
|
+
* @param yamlContent - The YAML content to parse
|
|
25
|
+
* @returns The parsed and merged configuration
|
|
26
|
+
*/
|
|
27
|
+
export function loadConfigFromString(yamlContent) {
|
|
28
|
+
const parsed = parseYaml(yamlContent);
|
|
29
|
+
if (parsed === null || parsed === undefined) {
|
|
30
|
+
return mergeWithDefaults(undefined);
|
|
31
|
+
}
|
|
32
|
+
if (typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
33
|
+
throw new Error(`Invalid config content: expected an object, got ${typeof parsed}`);
|
|
34
|
+
}
|
|
35
|
+
return mergeWithDefaults(parsed.constraints);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a constraint configuration directly from an object.
|
|
39
|
+
* Useful for programmatic configuration without YAML.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Partial constraint configuration
|
|
42
|
+
* @returns Complete configuration with defaults applied
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const config = defineConstraints({
|
|
47
|
+
* fieldTypes: {
|
|
48
|
+
* dynamicEnum: 'error',
|
|
49
|
+
* dynamicSchema: 'error',
|
|
50
|
+
* },
|
|
51
|
+
* layout: {
|
|
52
|
+
* group: 'error',
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function defineConstraints(config) {
|
|
58
|
+
return mergeWithDefaults(config);
|
|
59
|
+
}
|
|
60
|
+
// Re-export validators (these are all browser-safe)
|
|
61
|
+
export { validateFormSpecElements, validateFormSpec, } from "./validators/formspec.js";
|
|
62
|
+
export { validateFieldTypes, isFieldTypeAllowed, getFieldTypeSeverity, } from "./validators/field-types.js";
|
|
63
|
+
export { validateLayout, isLayoutTypeAllowed, isNestingDepthAllowed, } from "./validators/layout.js";
|
|
64
|
+
export { validateFieldOptions, extractFieldOptions, isFieldOptionAllowed, getFieldOptionSeverity, } from "./validators/field-options.js";
|
|
65
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAsBH,0CAA0C;AAC1C,8EAA8E;AAC9E,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEvF,qBAAqB;AACrB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC;AAElE;;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