@buildnbuzz/buzzform 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +146 -138
- package/dist/{adapter-BT9v2OVg.d.mts → adapter-nQW28cyO.d.mts} +8 -2
- package/dist/{adapter-BT9v2OVg.d.ts → adapter-nQW28cyO.d.ts} +8 -2
- package/dist/chunk-63LF7K4O.mjs +171 -0
- package/dist/chunk-63LF7K4O.mjs.map +1 -0
- package/dist/chunk-HWDQN57Q.mjs +423 -0
- package/dist/chunk-HWDQN57Q.mjs.map +1 -0
- package/dist/{chunk-DDDGBPVU.mjs → chunk-IMJ5FRK5.mjs} +1 -1
- package/dist/chunk-IMJ5FRK5.mjs.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +95 -176
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -12
- package/dist/index.mjs.map +1 -1
- package/dist/rhf.d.mts +1 -1
- package/dist/rhf.d.ts +1 -1
- package/dist/rhf.js.map +1 -1
- package/dist/rhf.mjs +1 -1
- package/dist/rhf.mjs.map +1 -1
- package/dist/schema.d.mts +5 -32
- package/dist/schema.d.ts +5 -32
- package/dist/schema.js +160 -171
- package/dist/schema.js.map +1 -1
- package/dist/schema.mjs +18 -12
- package/dist/{utils-BgwyUFGB.d.mts → utils-CS2VrTJU.d.ts} +64 -51
- package/dist/{utils-DVLpbOoW.d.ts → utils-Dzp_68i3.d.mts} +64 -51
- package/dist/zod.d.mts +6 -24
- package/dist/zod.d.ts +6 -24
- package/dist/zod.js +151 -17
- package/dist/zod.js.map +1 -1
- package/dist/zod.mjs +69 -16
- package/dist/zod.mjs.map +1 -1
- package/package.json +4 -3
- package/dist/chunk-DDDGBPVU.mjs.map +0 -1
- package/dist/chunk-K42S5YX3.mjs +0 -599
- package/dist/chunk-K42S5YX3.mjs.map +0 -1
package/dist/schema.js
CHANGED
|
@@ -20,9 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/schema/index.ts
|
|
21
21
|
var schema_exports = {};
|
|
22
22
|
__export(schema_exports, {
|
|
23
|
-
applyCustomValidation: () => applyCustomValidation,
|
|
24
23
|
coerceToDate: () => coerceToDate,
|
|
25
24
|
coerceToNumber: () => coerceToNumber,
|
|
25
|
+
collectFieldValidators: () => collectFieldValidators,
|
|
26
26
|
createArrayFieldSchema: () => createArrayFieldSchema,
|
|
27
27
|
createArrayHelpers: () => createArrayHelpers,
|
|
28
28
|
createCheckboxFieldSchema: () => createCheckboxFieldSchema,
|
|
@@ -44,6 +44,8 @@ __export(schema_exports, {
|
|
|
44
44
|
generateFieldId: () => generateFieldId,
|
|
45
45
|
getNestedValue: () => getNestedValue,
|
|
46
46
|
getPatternErrorMessage: () => getPatternErrorMessage,
|
|
47
|
+
getSiblingData: () => getSiblingData,
|
|
48
|
+
getValueByPath: () => getValueByPath,
|
|
47
49
|
isFileLike: () => isFileLike,
|
|
48
50
|
isFileTypeAccepted: () => isFileTypeAccepted,
|
|
49
51
|
makeOptional: () => makeOptional,
|
|
@@ -77,59 +79,90 @@ function extractValidationConfig(validate) {
|
|
|
77
79
|
}
|
|
78
80
|
return { fn: void 0, isLive: false };
|
|
79
81
|
}
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
function collectFieldValidators(fields, basePath = "") {
|
|
83
|
+
const validators = [];
|
|
84
|
+
for (const field of fields) {
|
|
85
|
+
if ("name" in field && field.name) {
|
|
86
|
+
const fieldPath = basePath ? `${basePath}.${field.name}` : field.name;
|
|
87
|
+
if ("validate" in field && field.validate) {
|
|
88
|
+
const config = extractValidationConfig(field.validate);
|
|
89
|
+
if (config.fn) {
|
|
90
|
+
validators.push({
|
|
91
|
+
path: fieldPath,
|
|
92
|
+
fn: config.fn
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (field.type === "group" && "fields" in field) {
|
|
97
|
+
validators.push(...collectFieldValidators(field.fields, fieldPath));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (field.type === "row" && "fields" in field) {
|
|
101
|
+
validators.push(...collectFieldValidators(field.fields, basePath));
|
|
102
|
+
}
|
|
103
|
+
if (field.type === "collapsible" && "fields" in field) {
|
|
104
|
+
validators.push(...collectFieldValidators(field.fields, basePath));
|
|
105
|
+
}
|
|
106
|
+
if (field.type === "tabs" && "tabs" in field) {
|
|
107
|
+
for (const tab of field.tabs) {
|
|
108
|
+
const tabPath = tab.name ? basePath ? `${basePath}.${tab.name}` : tab.name : basePath;
|
|
109
|
+
validators.push(...collectFieldValidators(tab.fields, tabPath));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
83
112
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
113
|
+
return validators;
|
|
114
|
+
}
|
|
115
|
+
function getSiblingData(data, path) {
|
|
116
|
+
const parts = path.split(".");
|
|
117
|
+
if (parts.length <= 1) {
|
|
118
|
+
return data;
|
|
87
119
|
}
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
120
|
+
const parentParts = parts.slice(0, -1);
|
|
121
|
+
let current = data;
|
|
122
|
+
for (const part of parentParts) {
|
|
123
|
+
if (current && typeof current === "object" && current !== null) {
|
|
124
|
+
current = current[part];
|
|
125
|
+
} else {
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
91
128
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
if (current && typeof current === "object" && current !== null) {
|
|
130
|
+
return current;
|
|
131
|
+
}
|
|
132
|
+
return {};
|
|
133
|
+
}
|
|
134
|
+
function getValueByPath(data, path) {
|
|
135
|
+
const parts = path.split(".");
|
|
136
|
+
let current = data;
|
|
137
|
+
for (const part of parts) {
|
|
138
|
+
if (current && typeof current === "object" && current !== null) {
|
|
139
|
+
current = current[part];
|
|
140
|
+
} else {
|
|
141
|
+
return void 0;
|
|
103
142
|
}
|
|
104
|
-
}
|
|
143
|
+
}
|
|
144
|
+
return current;
|
|
105
145
|
}
|
|
106
146
|
function makeOptional(schema, fieldType) {
|
|
107
147
|
switch (fieldType) {
|
|
108
|
-
// String types: allow empty string
|
|
109
148
|
case "text":
|
|
110
149
|
case "textarea":
|
|
111
150
|
case "email":
|
|
112
151
|
case "password":
|
|
113
152
|
return schema.optional().or(import_zod.z.literal(""));
|
|
114
|
-
// Nullable types
|
|
115
153
|
case "number":
|
|
116
154
|
case "date":
|
|
117
155
|
case "select":
|
|
118
156
|
case "radio":
|
|
119
157
|
return schema.optional().nullable();
|
|
120
|
-
// Boolean types: always have a value
|
|
121
158
|
case "checkbox":
|
|
122
159
|
case "switch":
|
|
123
160
|
return schema;
|
|
124
|
-
// Booleans are never "optional" in the traditional sense
|
|
125
|
-
// Array types
|
|
126
161
|
case "tags":
|
|
127
162
|
case "array":
|
|
128
163
|
return schema.optional().default([]);
|
|
129
|
-
// Upload
|
|
130
164
|
case "upload":
|
|
131
165
|
return schema.optional().nullable();
|
|
132
|
-
// Default
|
|
133
166
|
default:
|
|
134
167
|
return schema.optional();
|
|
135
168
|
}
|
|
@@ -186,25 +219,25 @@ function isFileTypeAccepted(file, accept) {
|
|
|
186
219
|
|
|
187
220
|
// src/schema/builders/text.ts
|
|
188
221
|
function createTextFieldSchema(field) {
|
|
189
|
-
let schema = import_zod2.z.string();
|
|
222
|
+
let schema = import_zod2.z.string({ error: "This field is required" });
|
|
190
223
|
if ("pattern" in field && field.pattern) {
|
|
191
224
|
const pattern = typeof field.pattern === "string" ? new RegExp(field.pattern) : field.pattern;
|
|
192
225
|
schema = schema.regex(pattern, {
|
|
193
|
-
|
|
226
|
+
error: getPatternErrorMessage(field.pattern)
|
|
194
227
|
});
|
|
195
228
|
}
|
|
196
229
|
if (field.minLength) {
|
|
197
230
|
schema = schema.min(field.minLength, {
|
|
198
|
-
|
|
231
|
+
error: `Must be at least ${field.minLength} characters`
|
|
199
232
|
});
|
|
200
233
|
}
|
|
201
234
|
if (field.maxLength) {
|
|
202
235
|
schema = schema.max(field.maxLength, {
|
|
203
|
-
|
|
236
|
+
error: `Must be no more than ${field.maxLength} characters`
|
|
204
237
|
});
|
|
205
238
|
}
|
|
206
239
|
if (field.required) {
|
|
207
|
-
schema = schema.min(1, {
|
|
240
|
+
schema = schema.min(1, { error: "This field is required" });
|
|
208
241
|
}
|
|
209
242
|
let finalSchema = schema;
|
|
210
243
|
if ("trim" in field && field.trim) {
|
|
@@ -212,67 +245,63 @@ function createTextFieldSchema(field) {
|
|
|
212
245
|
return typeof val === "string" ? val.trim() : val;
|
|
213
246
|
}, schema);
|
|
214
247
|
}
|
|
215
|
-
finalSchema = applyCustomValidation(finalSchema, field, field.name);
|
|
216
248
|
if (!field.required) {
|
|
217
249
|
return makeOptional(finalSchema, field.type);
|
|
218
250
|
}
|
|
219
251
|
return finalSchema;
|
|
220
252
|
}
|
|
221
253
|
function createEmailFieldSchema(field) {
|
|
222
|
-
let schema = import_zod2.z.
|
|
254
|
+
let schema = import_zod2.z.email({ error: "Invalid email address" });
|
|
223
255
|
if (field.minLength) {
|
|
224
256
|
schema = schema.min(field.minLength, {
|
|
225
|
-
|
|
257
|
+
error: `Must be at least ${field.minLength} characters`
|
|
226
258
|
});
|
|
227
259
|
}
|
|
228
260
|
if (field.maxLength) {
|
|
229
261
|
schema = schema.max(field.maxLength, {
|
|
230
|
-
|
|
262
|
+
error: `Must be no more than ${field.maxLength} characters`
|
|
231
263
|
});
|
|
232
264
|
}
|
|
233
265
|
if (field.required) {
|
|
234
|
-
schema = schema.min(1, {
|
|
266
|
+
schema = schema.min(1, { error: "Email is required" });
|
|
235
267
|
}
|
|
236
|
-
const finalSchema = applyCustomValidation(schema, field, field.name);
|
|
237
268
|
if (!field.required) {
|
|
238
|
-
return makeOptional(
|
|
269
|
+
return makeOptional(schema, "email");
|
|
239
270
|
}
|
|
240
|
-
return
|
|
271
|
+
return schema;
|
|
241
272
|
}
|
|
242
273
|
function createPasswordFieldSchema(field) {
|
|
243
|
-
let schema = import_zod2.z.string();
|
|
274
|
+
let schema = import_zod2.z.string({ error: "Password is required" });
|
|
244
275
|
if (field.minLength) {
|
|
245
276
|
schema = schema.min(field.minLength, {
|
|
246
|
-
|
|
277
|
+
error: `Password must be at least ${field.minLength} characters`
|
|
247
278
|
});
|
|
248
279
|
}
|
|
249
280
|
if (field.maxLength) {
|
|
250
281
|
schema = schema.max(field.maxLength, {
|
|
251
|
-
|
|
282
|
+
error: `Password must be no more than ${field.maxLength} characters`
|
|
252
283
|
});
|
|
253
284
|
}
|
|
254
285
|
if (field.required) {
|
|
255
|
-
schema = schema.min(1, {
|
|
286
|
+
schema = schema.min(1, { error: "Password is required" });
|
|
256
287
|
}
|
|
257
|
-
const finalSchema = applyCustomValidation(schema, field, field.name);
|
|
258
288
|
if (!field.required) {
|
|
259
|
-
return makeOptional(
|
|
289
|
+
return makeOptional(schema, "password");
|
|
260
290
|
}
|
|
261
|
-
return
|
|
291
|
+
return schema;
|
|
262
292
|
}
|
|
263
293
|
|
|
264
294
|
// src/schema/builders/number.ts
|
|
265
295
|
var import_zod3 = require("zod");
|
|
266
296
|
function createNumberFieldSchema(field) {
|
|
267
|
-
let numSchema = import_zod3.z.number({
|
|
297
|
+
let numSchema = import_zod3.z.number({ error: "Must be a number" });
|
|
268
298
|
if (field.min !== void 0) {
|
|
269
299
|
numSchema = numSchema.min(field.min, `Must be at least ${field.min}`);
|
|
270
300
|
}
|
|
271
301
|
if (field.max !== void 0) {
|
|
272
302
|
numSchema = numSchema.max(field.max, `Must be at most ${field.max}`);
|
|
273
303
|
}
|
|
274
|
-
|
|
275
|
-
schema = applyCustomValidation(schema, field, field.name);
|
|
304
|
+
const schema = import_zod3.z.preprocess(coerceToNumber, numSchema);
|
|
276
305
|
if (field.required) {
|
|
277
306
|
return schema;
|
|
278
307
|
}
|
|
@@ -291,21 +320,20 @@ function createDateFieldSchema(field) {
|
|
|
291
320
|
const isDatetime = field.type === "datetime";
|
|
292
321
|
const minDate = toDate(field.minDate);
|
|
293
322
|
const maxDate = toDate(field.maxDate);
|
|
294
|
-
let dateSchema = import_zod4.z.date({
|
|
323
|
+
let dateSchema = import_zod4.z.date({ error: "Please enter a valid date" });
|
|
295
324
|
if (minDate) {
|
|
296
325
|
const formattedDate = isDatetime ? minDate.toLocaleString() : minDate.toDateString();
|
|
297
326
|
dateSchema = dateSchema.min(minDate, {
|
|
298
|
-
|
|
327
|
+
error: `Date must be on or after ${formattedDate}`
|
|
299
328
|
});
|
|
300
329
|
}
|
|
301
330
|
if (maxDate) {
|
|
302
331
|
const formattedDate = isDatetime ? maxDate.toLocaleString() : maxDate.toDateString();
|
|
303
332
|
dateSchema = dateSchema.max(maxDate, {
|
|
304
|
-
|
|
333
|
+
error: `Date must be on or before ${formattedDate}`
|
|
305
334
|
});
|
|
306
335
|
}
|
|
307
|
-
|
|
308
|
-
schema = applyCustomValidation(schema, field, field.name);
|
|
336
|
+
const schema = import_zod4.z.preprocess(coerceToDate, dateSchema);
|
|
309
337
|
if (field.required) {
|
|
310
338
|
return schema.refine(
|
|
311
339
|
(val) => val instanceof Date && !isNaN(val.getTime()),
|
|
@@ -317,18 +345,21 @@ function createDateFieldSchema(field) {
|
|
|
317
345
|
|
|
318
346
|
// src/schema/builders/select.ts
|
|
319
347
|
var import_zod5 = require("zod");
|
|
320
|
-
var selectValueSchema = import_zod5.z.union([
|
|
348
|
+
var selectValueSchema = import_zod5.z.union([
|
|
349
|
+
import_zod5.z.string({ error: "Please select an option" }),
|
|
350
|
+
import_zod5.z.number({ error: "Please select an option" }),
|
|
351
|
+
import_zod5.z.boolean({ error: "Please select an option" })
|
|
352
|
+
], { error: "Please select an option" });
|
|
321
353
|
function createSelectFieldSchema(field) {
|
|
322
354
|
if (field.hasMany) {
|
|
323
|
-
let arraySchema = import_zod5.z.array(selectValueSchema);
|
|
355
|
+
let arraySchema = import_zod5.z.array(selectValueSchema, { error: "Invalid selection" });
|
|
324
356
|
if (field.required) {
|
|
325
357
|
arraySchema = arraySchema.min(1, "Select at least one option");
|
|
326
358
|
}
|
|
327
|
-
const schema2 = applyCustomValidation(arraySchema, field, field.name);
|
|
328
359
|
if (!field.required) {
|
|
329
|
-
return
|
|
360
|
+
return arraySchema.optional().default([]);
|
|
330
361
|
}
|
|
331
|
-
return
|
|
362
|
+
return arraySchema;
|
|
332
363
|
}
|
|
333
364
|
let schema = selectValueSchema;
|
|
334
365
|
if (field.required) {
|
|
@@ -337,7 +368,6 @@ function createSelectFieldSchema(field) {
|
|
|
337
368
|
"Please select an option"
|
|
338
369
|
);
|
|
339
370
|
}
|
|
340
|
-
schema = applyCustomValidation(schema, field, field.name);
|
|
341
371
|
if (!field.required) {
|
|
342
372
|
return makeOptional(schema, "select");
|
|
343
373
|
}
|
|
@@ -351,7 +381,6 @@ function createRadioFieldSchema(field) {
|
|
|
351
381
|
"Please select an option"
|
|
352
382
|
);
|
|
353
383
|
}
|
|
354
|
-
schema = applyCustomValidation(schema, field, field.name);
|
|
355
384
|
if (!field.required) {
|
|
356
385
|
return makeOptional(schema, "radio");
|
|
357
386
|
}
|
|
@@ -361,146 +390,113 @@ function createRadioFieldSchema(field) {
|
|
|
361
390
|
// src/schema/builders/boolean.ts
|
|
362
391
|
var import_zod6 = require("zod");
|
|
363
392
|
function createCheckboxFieldSchema(field) {
|
|
364
|
-
let schema = import_zod6.z.boolean();
|
|
393
|
+
let schema = import_zod6.z.boolean({ error: "Invalid value" });
|
|
365
394
|
if (field.required) {
|
|
366
|
-
schema = import_zod6.z.boolean().refine((val) => val === true, {
|
|
367
|
-
|
|
395
|
+
schema = import_zod6.z.boolean({ error: "This field is required" }).refine((val) => val === true, {
|
|
396
|
+
error: "This field is required"
|
|
368
397
|
});
|
|
369
398
|
}
|
|
370
|
-
return
|
|
399
|
+
return schema;
|
|
371
400
|
}
|
|
372
401
|
function createSwitchFieldSchema(field) {
|
|
373
|
-
let schema = import_zod6.z.boolean();
|
|
402
|
+
let schema = import_zod6.z.boolean({ error: "Invalid value" });
|
|
374
403
|
if (field.required) {
|
|
375
|
-
schema = import_zod6.z.boolean().refine((val) => val === true, {
|
|
376
|
-
|
|
404
|
+
schema = import_zod6.z.boolean({ error: "This field is required" }).refine((val) => val === true, {
|
|
405
|
+
error: "This field is required"
|
|
377
406
|
});
|
|
378
407
|
}
|
|
379
|
-
return
|
|
408
|
+
return schema;
|
|
380
409
|
}
|
|
381
410
|
|
|
382
411
|
// src/schema/builders/upload.ts
|
|
383
412
|
var import_zod7 = require("zod");
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return
|
|
413
|
+
function matchesMimePattern(fileType, pattern) {
|
|
414
|
+
const normalizedPattern = pattern.toLowerCase().trim();
|
|
415
|
+
const normalizedType = fileType.toLowerCase();
|
|
416
|
+
if (normalizedPattern.endsWith("/*")) {
|
|
417
|
+
const category = normalizedPattern.replace("/*", "");
|
|
418
|
+
return normalizedType.startsWith(category + "/");
|
|
390
419
|
}
|
|
391
|
-
if (
|
|
392
|
-
return
|
|
420
|
+
if (normalizedPattern.startsWith(".")) {
|
|
421
|
+
return true;
|
|
393
422
|
}
|
|
394
|
-
|
|
423
|
+
return normalizedType === normalizedPattern;
|
|
424
|
+
}
|
|
425
|
+
function isFileTypeAccepted2(file, acceptPatterns) {
|
|
426
|
+
if (!file.type) return true;
|
|
427
|
+
return acceptPatterns.some((pattern) => matchesMimePattern(file.type, pattern));
|
|
428
|
+
}
|
|
429
|
+
function createUploadFieldSchema(field) {
|
|
430
|
+
let fileSchema = import_zod7.z.file({ error: "Please select a file" });
|
|
431
|
+
if (field.maxSize) {
|
|
395
432
|
const sizeMB = (field.maxSize / 1024 / 1024).toFixed(1);
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
};
|
|
433
|
+
fileSchema = fileSchema.max(field.maxSize, {
|
|
434
|
+
error: `File must be smaller than ${sizeMB}MB`
|
|
435
|
+
});
|
|
400
436
|
}
|
|
401
437
|
const accept = field.ui?.accept;
|
|
402
438
|
if (accept && accept !== "*") {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
439
|
+
const acceptPatterns = accept.split(",").map((t) => t.trim());
|
|
440
|
+
const hasWildcard = acceptPatterns.some((p) => p.includes("*") || p.startsWith("."));
|
|
441
|
+
if (hasWildcard) {
|
|
442
|
+
fileSchema = fileSchema.refine(
|
|
443
|
+
(file) => isFileTypeAccepted2(file, acceptPatterns),
|
|
444
|
+
`File type not allowed. Accepted: ${accept}`
|
|
445
|
+
);
|
|
446
|
+
} else {
|
|
447
|
+
fileSchema = fileSchema.mime(acceptPatterns, {
|
|
448
|
+
error: `File type not allowed. Accepted: ${accept}`
|
|
449
|
+
});
|
|
408
450
|
}
|
|
409
451
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
452
|
+
const fileOrUrl = import_zod7.z.union([
|
|
453
|
+
fileSchema,
|
|
454
|
+
import_zod7.z.string({ error: "Invalid file" })
|
|
455
|
+
], { error: "Please select a file" });
|
|
413
456
|
if (field.hasMany) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
if (!result.valid) {
|
|
419
|
-
ctx.addIssue({
|
|
420
|
-
code: import_zod7.z.ZodIssueCode.custom,
|
|
421
|
-
message: result.message || "Invalid file",
|
|
422
|
-
path: [i]
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
if (field.required) {
|
|
427
|
-
const validFiles = files.filter((f) => f !== null && f !== void 0);
|
|
428
|
-
if (validFiles.length === 0) {
|
|
429
|
-
ctx.addIssue({
|
|
430
|
-
code: import_zod7.z.ZodIssueCode.custom,
|
|
431
|
-
message: "At least one file is required"
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
if (field.minFiles !== void 0 && field.minFiles > 0) {
|
|
436
|
-
const validFiles = files.filter((f) => f !== null && f !== void 0);
|
|
437
|
-
if (validFiles.length < field.minFiles) {
|
|
438
|
-
ctx.addIssue({
|
|
439
|
-
code: import_zod7.z.ZodIssueCode.custom,
|
|
440
|
-
message: `At least ${field.minFiles} file(s) required`
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
if (field.maxFiles !== void 0) {
|
|
445
|
-
const validFiles = files.filter((f) => f !== null && f !== void 0);
|
|
446
|
-
if (validFiles.length > field.maxFiles) {
|
|
447
|
-
ctx.addIssue({
|
|
448
|
-
code: import_zod7.z.ZodIssueCode.custom,
|
|
449
|
-
message: `Maximum ${field.maxFiles} file(s) allowed`
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
if (!field.required) {
|
|
455
|
-
return schema2.optional().default([]);
|
|
456
|
-
}
|
|
457
|
-
return schema2;
|
|
458
|
-
}
|
|
459
|
-
const schema = import_zod7.z.any().superRefine((value, ctx) => {
|
|
460
|
-
if (field.required && (value === null || value === void 0 || value === "")) {
|
|
461
|
-
ctx.addIssue({
|
|
462
|
-
code: import_zod7.z.ZodIssueCode.custom,
|
|
463
|
-
message: "File is required"
|
|
457
|
+
let arraySchema = import_zod7.z.array(fileOrUrl, { error: "Invalid files" });
|
|
458
|
+
if (field.minFiles !== void 0 && field.minFiles > 0) {
|
|
459
|
+
arraySchema = arraySchema.min(field.minFiles, {
|
|
460
|
+
error: `At least ${field.minFiles} file(s) required`
|
|
464
461
|
});
|
|
465
|
-
return;
|
|
466
462
|
}
|
|
467
|
-
if (
|
|
468
|
-
|
|
463
|
+
if (field.maxFiles !== void 0) {
|
|
464
|
+
arraySchema = arraySchema.max(field.maxFiles, {
|
|
465
|
+
error: `Maximum ${field.maxFiles} file(s) allowed`
|
|
466
|
+
});
|
|
469
467
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
code: import_zod7.z.ZodIssueCode.custom,
|
|
474
|
-
message: result.message || "Invalid file"
|
|
468
|
+
if (field.required) {
|
|
469
|
+
arraySchema = arraySchema.min(1, {
|
|
470
|
+
error: "At least one file is required"
|
|
475
471
|
});
|
|
472
|
+
return arraySchema;
|
|
476
473
|
}
|
|
477
|
-
|
|
478
|
-
if (!field.required) {
|
|
479
|
-
return schema.optional().nullable();
|
|
474
|
+
return arraySchema.optional().default([]);
|
|
480
475
|
}
|
|
481
|
-
|
|
476
|
+
if (field.required) {
|
|
477
|
+
return fileOrUrl;
|
|
478
|
+
}
|
|
479
|
+
return fileOrUrl.optional().nullable();
|
|
482
480
|
}
|
|
483
481
|
|
|
484
482
|
// src/schema/builders/tags.ts
|
|
485
483
|
var import_zod8 = require("zod");
|
|
486
484
|
function createTagsFieldSchema(field) {
|
|
487
|
-
const tagSchema = import_zod8.z.string();
|
|
488
|
-
let schema = import_zod8.z.array(tagSchema);
|
|
485
|
+
const tagSchema = import_zod8.z.string({ error: "Invalid tag" });
|
|
486
|
+
let schema = import_zod8.z.array(tagSchema, { error: "Invalid tags" });
|
|
489
487
|
if (field.minTags !== void 0) {
|
|
490
488
|
schema = schema.min(field.minTags, `At least ${field.minTags} tag(s) required`);
|
|
491
489
|
}
|
|
492
490
|
if (field.maxTags !== void 0) {
|
|
493
491
|
schema = schema.max(field.maxTags, `Maximum ${field.maxTags} tag(s) allowed`);
|
|
494
492
|
}
|
|
495
|
-
let finalSchema = applyCustomValidation(schema, field, field.name);
|
|
496
493
|
if (field.required) {
|
|
497
|
-
|
|
494
|
+
return schema.refine(
|
|
498
495
|
(arr) => Array.isArray(arr) && arr.length > 0,
|
|
499
496
|
"At least one tag is required"
|
|
500
497
|
);
|
|
501
|
-
return finalSchema;
|
|
502
498
|
}
|
|
503
|
-
return
|
|
499
|
+
return schema.optional().default([]);
|
|
504
500
|
}
|
|
505
501
|
|
|
506
502
|
// src/schema/builders/composite.ts
|
|
@@ -539,7 +535,6 @@ function fieldToZod(field) {
|
|
|
539
535
|
return field.schema;
|
|
540
536
|
}
|
|
541
537
|
switch (field.type) {
|
|
542
|
-
// Text-based fields
|
|
543
538
|
case "text":
|
|
544
539
|
return createTextFieldSchema(field);
|
|
545
540
|
case "email":
|
|
@@ -548,35 +543,27 @@ function fieldToZod(field) {
|
|
|
548
543
|
return createPasswordFieldSchema(field);
|
|
549
544
|
case "textarea":
|
|
550
545
|
return createTextFieldSchema(field);
|
|
551
|
-
// Number
|
|
552
546
|
case "number":
|
|
553
547
|
return createNumberFieldSchema(field);
|
|
554
|
-
// Date
|
|
555
548
|
case "date":
|
|
556
549
|
case "datetime":
|
|
557
550
|
return createDateFieldSchema(field);
|
|
558
|
-
// Selection
|
|
559
551
|
case "select":
|
|
560
552
|
return createSelectFieldSchema(field);
|
|
561
553
|
case "radio":
|
|
562
554
|
return createRadioFieldSchema(field);
|
|
563
|
-
// Boolean
|
|
564
555
|
case "checkbox":
|
|
565
556
|
return createCheckboxFieldSchema(field);
|
|
566
557
|
case "switch":
|
|
567
558
|
return createSwitchFieldSchema(field);
|
|
568
|
-
// Upload
|
|
569
559
|
case "upload":
|
|
570
560
|
return createUploadFieldSchema(field);
|
|
571
|
-
// Tags
|
|
572
561
|
case "tags":
|
|
573
562
|
return createTagsFieldSchema(field);
|
|
574
|
-
// Composite (recursive)
|
|
575
563
|
case "array":
|
|
576
564
|
return createArrayFieldSchema(field, fieldsToZodSchema);
|
|
577
565
|
case "group":
|
|
578
566
|
return createGroupFieldSchema(field, fieldsToZodSchema);
|
|
579
|
-
// Layout fields don't produce schemas directly
|
|
580
567
|
case "row":
|
|
581
568
|
case "collapsible":
|
|
582
569
|
case "tabs":
|
|
@@ -736,9 +723,9 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
736
723
|
}
|
|
737
724
|
// Annotate the CommonJS export names for ESM import in node:
|
|
738
725
|
0 && (module.exports = {
|
|
739
|
-
applyCustomValidation,
|
|
740
726
|
coerceToDate,
|
|
741
727
|
coerceToNumber,
|
|
728
|
+
collectFieldValidators,
|
|
742
729
|
createArrayFieldSchema,
|
|
743
730
|
createArrayHelpers,
|
|
744
731
|
createCheckboxFieldSchema,
|
|
@@ -760,6 +747,8 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
760
747
|
generateFieldId,
|
|
761
748
|
getNestedValue,
|
|
762
749
|
getPatternErrorMessage,
|
|
750
|
+
getSiblingData,
|
|
751
|
+
getValueByPath,
|
|
763
752
|
isFileLike,
|
|
764
753
|
isFileTypeAccepted,
|
|
765
754
|
makeOptional,
|