unischema 1.0.1 → 1.2.0
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 +780 -228
- package/dist/adapters/backend/index.d.mts +2 -1
- package/dist/adapters/backend/index.d.ts +2 -1
- package/dist/adapters/backend/index.js +17 -441
- package/dist/adapters/backend/index.mjs +9 -433
- package/dist/adapters/frontend/index.d.mts +2 -1
- package/dist/adapters/frontend/index.d.ts +2 -1
- package/dist/adapters/frontend/index.js +10 -421
- package/dist/adapters/frontend/index.mjs +8 -419
- package/dist/chunk-5A4ITJVD.mjs +124 -0
- package/dist/chunk-66RFUBVU.js +131 -0
- package/dist/chunk-75YSYC4K.mjs +85 -0
- package/dist/chunk-76BBWQDH.js +90 -0
- package/dist/chunk-7XES4A3M.mjs +237 -0
- package/dist/chunk-BVRXGZLS.js +17 -0
- package/dist/chunk-COMVAVFU.mjs +335 -0
- package/dist/chunk-DT2TQZU7.js +796 -0
- package/dist/chunk-FPCCH55A.js +103 -0
- package/dist/chunk-IUXRLMET.js +206 -0
- package/dist/chunk-JEW6U6CB.js +353 -0
- package/dist/chunk-KZCV5IW4.mjs +97 -0
- package/dist/chunk-KZZ7NVU3.mjs +41 -0
- package/dist/chunk-MFEBMQAU.mjs +779 -0
- package/dist/chunk-OIYG5D2I.js +50 -0
- package/dist/chunk-RW6HDA5H.mjs +194 -0
- package/dist/chunk-TTK77YBI.mjs +15 -0
- package/dist/chunk-TXT36BCE.js +248 -0
- package/dist/index-C17xs-fU.d.mts +140 -0
- package/dist/index-C17xs-fU.d.ts +140 -0
- package/dist/index.d.mts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +769 -499
- package/dist/index.mjs +695 -487
- package/dist/{schema-D9DGC9E_.d.ts → schema-DYE8Wz8X.d.mts} +264 -79
- package/dist/{schema-D9DGC9E_.d.mts → schema-Dtp-joeT.d.ts} +264 -79
- package/dist/validators/array.d.mts +15 -0
- package/dist/validators/array.d.ts +15 -0
- package/dist/validators/array.js +31 -0
- package/dist/validators/array.mjs +2 -0
- package/dist/validators/common.d.mts +13 -0
- package/dist/validators/common.d.ts +13 -0
- package/dist/validators/common.js +27 -0
- package/dist/validators/common.mjs +2 -0
- package/dist/validators/date.d.mts +23 -0
- package/dist/validators/date.d.ts +23 -0
- package/dist/validators/date.js +47 -0
- package/dist/validators/date.mjs +2 -0
- package/dist/validators/index.d.mts +46 -0
- package/dist/validators/index.d.ts +46 -0
- package/dist/validators/index.js +256 -0
- package/dist/validators/index.mjs +7 -0
- package/dist/validators/number.d.mts +25 -0
- package/dist/validators/number.d.ts +25 -0
- package/dist/validators/number.js +51 -0
- package/dist/validators/number.mjs +2 -0
- package/dist/validators/object.d.mts +11 -0
- package/dist/validators/object.d.ts +11 -0
- package/dist/validators/object.js +23 -0
- package/dist/validators/object.mjs +2 -0
- package/dist/validators/string.d.mts +37 -0
- package/dist/validators/string.d.ts +37 -0
- package/dist/validators/string.js +75 -0
- package/dist/validators/string.mjs +2 -0
- package/package.json +82 -5
- package/dist/adapters/backend/index.js.map +0 -1
- package/dist/adapters/backend/index.mjs.map +0 -1
- package/dist/adapters/frontend/index.js.map +0 -1
- package/dist/adapters/frontend/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -1,420 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
var typeValidators = {
|
|
11
|
-
string: (value, _params, context) => {
|
|
12
|
-
if (value !== void 0 && value !== null && typeof value !== "string") {
|
|
13
|
-
return createError(context, "INVALID_TYPE", `Expected string, got ${typeof value}`);
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
},
|
|
17
|
-
number: (value, _params, context) => {
|
|
18
|
-
if (value !== void 0 && value !== null && typeof value !== "number") {
|
|
19
|
-
return createError(context, "INVALID_TYPE", `Expected number, got ${typeof value}`);
|
|
20
|
-
}
|
|
21
|
-
if (typeof value === "number" && isNaN(value)) {
|
|
22
|
-
return createError(context, "INVALID_NUMBER", "Value is not a valid number");
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
},
|
|
26
|
-
boolean: (value, _params, context) => {
|
|
27
|
-
if (value !== void 0 && value !== null && typeof value !== "boolean") {
|
|
28
|
-
return createError(context, "INVALID_TYPE", `Expected boolean, got ${typeof value}`);
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
},
|
|
32
|
-
date: (value, _params, context) => {
|
|
33
|
-
if (value === void 0 || value === null) return null;
|
|
34
|
-
if (value instanceof Date) {
|
|
35
|
-
if (isNaN(value.getTime())) {
|
|
36
|
-
return createError(context, "INVALID_DATE", "Invalid date value");
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
if (typeof value === "string") {
|
|
41
|
-
const parsed = new Date(value);
|
|
42
|
-
if (isNaN(parsed.getTime())) {
|
|
43
|
-
return createError(context, "INVALID_DATE", "Invalid date format");
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return createError(context, "INVALID_TYPE", `Expected date, got ${typeof value}`);
|
|
48
|
-
},
|
|
49
|
-
array: (value, _params, context) => {
|
|
50
|
-
if (value !== void 0 && value !== null && !Array.isArray(value)) {
|
|
51
|
-
return createError(context, "INVALID_TYPE", `Expected array, got ${typeof value}`);
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
},
|
|
55
|
-
object: (value, _params, context) => {
|
|
56
|
-
if (value !== void 0 && value !== null) {
|
|
57
|
-
if (typeof value !== "object" || Array.isArray(value)) {
|
|
58
|
-
return createError(context, "INVALID_TYPE", `Expected object, got ${typeof value}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var ruleValidators = {
|
|
65
|
-
required: (value, _params, context) => {
|
|
66
|
-
const isEmpty = value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
67
|
-
if (isEmpty) {
|
|
68
|
-
return createError(context, "REQUIRED", "This field is required");
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
},
|
|
72
|
-
min: (value, params, context) => {
|
|
73
|
-
const min = params?.value;
|
|
74
|
-
const soft = params?.soft;
|
|
75
|
-
const message = params?.message;
|
|
76
|
-
if (value === void 0 || value === null) return null;
|
|
77
|
-
if (typeof value === "number") {
|
|
78
|
-
if (value < min) {
|
|
79
|
-
return createError(
|
|
80
|
-
context,
|
|
81
|
-
"MIN_VALUE",
|
|
82
|
-
message || `Value must be at least ${min}`,
|
|
83
|
-
soft
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (typeof value === "string") {
|
|
88
|
-
if (value.length < min) {
|
|
89
|
-
return createError(
|
|
90
|
-
context,
|
|
91
|
-
"MIN_LENGTH",
|
|
92
|
-
message || `Must be at least ${min} characters`,
|
|
93
|
-
soft
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (Array.isArray(value)) {
|
|
98
|
-
if (value.length < min) {
|
|
99
|
-
return createError(
|
|
100
|
-
context,
|
|
101
|
-
"MIN_ITEMS",
|
|
102
|
-
message || `Must have at least ${min} items`,
|
|
103
|
-
soft
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
},
|
|
109
|
-
max: (value, params, context) => {
|
|
110
|
-
const max = params?.value;
|
|
111
|
-
const soft = params?.soft;
|
|
112
|
-
const message = params?.message;
|
|
113
|
-
if (value === void 0 || value === null) return null;
|
|
114
|
-
if (typeof value === "number") {
|
|
115
|
-
if (value > max) {
|
|
116
|
-
return createError(
|
|
117
|
-
context,
|
|
118
|
-
"MAX_VALUE",
|
|
119
|
-
message || `Value must be at most ${max}`,
|
|
120
|
-
soft
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (typeof value === "string") {
|
|
125
|
-
if (value.length > max) {
|
|
126
|
-
return createError(
|
|
127
|
-
context,
|
|
128
|
-
"MAX_LENGTH",
|
|
129
|
-
message || `Must be at most ${max} characters`,
|
|
130
|
-
soft
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (Array.isArray(value)) {
|
|
135
|
-
if (value.length > max) {
|
|
136
|
-
return createError(
|
|
137
|
-
context,
|
|
138
|
-
"MAX_ITEMS",
|
|
139
|
-
message || `Must have at most ${max} items`,
|
|
140
|
-
soft
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
},
|
|
146
|
-
email: (value, params, context) => {
|
|
147
|
-
if (value === void 0 || value === null || value === "") return null;
|
|
148
|
-
const soft = params?.soft;
|
|
149
|
-
const message = params?.message;
|
|
150
|
-
if (typeof value !== "string") {
|
|
151
|
-
return createError(context, "INVALID_EMAIL", "Email must be a string", soft);
|
|
152
|
-
}
|
|
153
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
154
|
-
if (!emailRegex.test(value)) {
|
|
155
|
-
return createError(
|
|
156
|
-
context,
|
|
157
|
-
"INVALID_EMAIL",
|
|
158
|
-
message || "Invalid email address",
|
|
159
|
-
soft
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
return null;
|
|
163
|
-
},
|
|
164
|
-
pattern: (value, params, context) => {
|
|
165
|
-
if (value === void 0 || value === null || value === "") return null;
|
|
166
|
-
const pattern = params?.pattern;
|
|
167
|
-
const soft = params?.soft;
|
|
168
|
-
const message = params?.message;
|
|
169
|
-
if (typeof value !== "string") return null;
|
|
170
|
-
const regex = new RegExp(pattern);
|
|
171
|
-
if (!regex.test(value)) {
|
|
172
|
-
return createError(
|
|
173
|
-
context,
|
|
174
|
-
"PATTERN_MISMATCH",
|
|
175
|
-
message || `Value does not match required pattern`,
|
|
176
|
-
soft
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
return null;
|
|
180
|
-
},
|
|
181
|
-
url: (value, params, context) => {
|
|
182
|
-
if (value === void 0 || value === null || value === "") return null;
|
|
183
|
-
const soft = params?.soft;
|
|
184
|
-
const message = params?.message;
|
|
185
|
-
if (typeof value !== "string") {
|
|
186
|
-
return createError(context, "INVALID_URL", "URL must be a string", soft);
|
|
187
|
-
}
|
|
188
|
-
try {
|
|
189
|
-
new URL(value);
|
|
190
|
-
return null;
|
|
191
|
-
} catch {
|
|
192
|
-
return createError(
|
|
193
|
-
context,
|
|
194
|
-
"INVALID_URL",
|
|
195
|
-
message || "Invalid URL format",
|
|
196
|
-
soft
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
ipAddress: (value, params, context) => {
|
|
201
|
-
if (value === void 0 || value === null || value === "") return null;
|
|
202
|
-
const soft = params?.soft;
|
|
203
|
-
const message = params?.message;
|
|
204
|
-
if (typeof value !== "string") {
|
|
205
|
-
return createError(context, "INVALID_IP", "IP address must be a string", soft);
|
|
206
|
-
}
|
|
207
|
-
const ipv4Pattern = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
208
|
-
if (!ipv4Pattern.test(value)) {
|
|
209
|
-
return createError(
|
|
210
|
-
context,
|
|
211
|
-
"INVALID_IP",
|
|
212
|
-
message || "Invalid IP address format",
|
|
213
|
-
soft
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
return null;
|
|
217
|
-
},
|
|
218
|
-
enum: (value, params, context) => {
|
|
219
|
-
if (value === void 0 || value === null) return null;
|
|
220
|
-
const values = params?.values;
|
|
221
|
-
const soft = params?.soft;
|
|
222
|
-
const message = params?.message;
|
|
223
|
-
if (!values.includes(value)) {
|
|
224
|
-
return createError(
|
|
225
|
-
context,
|
|
226
|
-
"INVALID_ENUM",
|
|
227
|
-
message || `Value must be one of: ${values.join(", ")}`,
|
|
228
|
-
soft
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
return null;
|
|
232
|
-
},
|
|
233
|
-
custom: (value, params, context) => {
|
|
234
|
-
const validate2 = params?.validate;
|
|
235
|
-
const soft = params?.soft;
|
|
236
|
-
const message = params?.message;
|
|
237
|
-
if (!validate2) return null;
|
|
238
|
-
const result = validate2(value, context);
|
|
239
|
-
if (typeof result === "boolean") {
|
|
240
|
-
if (!result) {
|
|
241
|
-
return createError(
|
|
242
|
-
context,
|
|
243
|
-
"CUSTOM_VALIDATION",
|
|
244
|
-
message || "Validation failed",
|
|
245
|
-
soft
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
if (!result.valid) {
|
|
251
|
-
return createError(
|
|
252
|
-
context,
|
|
253
|
-
"CUSTOM_VALIDATION",
|
|
254
|
-
result.message || message || "Validation failed",
|
|
255
|
-
soft
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
return null;
|
|
259
|
-
},
|
|
260
|
-
// Enterprise patterns - matches field against another field
|
|
261
|
-
matches: (value, params, context) => {
|
|
262
|
-
if (value === void 0 || value === null) return null;
|
|
263
|
-
const otherField = params?.field;
|
|
264
|
-
const soft = params?.soft;
|
|
265
|
-
const message = params?.message;
|
|
266
|
-
const root = context.root;
|
|
267
|
-
const otherValue = root[otherField];
|
|
268
|
-
if (value !== otherValue) {
|
|
269
|
-
return createError(
|
|
270
|
-
context,
|
|
271
|
-
"FIELD_MISMATCH",
|
|
272
|
-
message || `Must match ${otherField}`,
|
|
273
|
-
soft
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
return null;
|
|
277
|
-
},
|
|
278
|
-
// Integer validation
|
|
279
|
-
integer: (value, params, context) => {
|
|
280
|
-
if (value === void 0 || value === null) return null;
|
|
281
|
-
const soft = params?.soft;
|
|
282
|
-
const message = params?.message;
|
|
283
|
-
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
284
|
-
return createError(
|
|
285
|
-
context,
|
|
286
|
-
"NOT_INTEGER",
|
|
287
|
-
message || "Value must be an integer",
|
|
288
|
-
soft
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
return null;
|
|
292
|
-
},
|
|
293
|
-
// Positive number validation
|
|
294
|
-
positive: (value, params, context) => {
|
|
295
|
-
if (value === void 0 || value === null) return null;
|
|
296
|
-
const soft = params?.soft;
|
|
297
|
-
const message = params?.message;
|
|
298
|
-
if (typeof value === "number" && value <= 0) {
|
|
299
|
-
return createError(
|
|
300
|
-
context,
|
|
301
|
-
"NOT_POSITIVE",
|
|
302
|
-
message || "Value must be positive",
|
|
303
|
-
soft
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
return null;
|
|
307
|
-
},
|
|
308
|
-
// Negative number validation
|
|
309
|
-
negative: (value, params, context) => {
|
|
310
|
-
if (value === void 0 || value === null) return null;
|
|
311
|
-
const soft = params?.soft;
|
|
312
|
-
const message = params?.message;
|
|
313
|
-
if (typeof value === "number" && value >= 0) {
|
|
314
|
-
return createError(
|
|
315
|
-
context,
|
|
316
|
-
"NOT_NEGATIVE",
|
|
317
|
-
message || "Value must be negative",
|
|
318
|
-
soft
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
var customValidators = /* @__PURE__ */ new Map();
|
|
325
|
-
function getValidator(name) {
|
|
326
|
-
return ruleValidators[name] ?? customValidators.get(name);
|
|
327
|
-
}
|
|
328
|
-
function getTypeValidator(type) {
|
|
329
|
-
return typeValidators[type];
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// src/core/engine.ts
|
|
333
|
-
function validateField(fieldDef, value, context) {
|
|
334
|
-
const errors = [];
|
|
335
|
-
const typeValidator = getTypeValidator(fieldDef.type);
|
|
336
|
-
if (typeValidator) {
|
|
337
|
-
const typeError = typeValidator(value, void 0, context);
|
|
338
|
-
if (typeError) {
|
|
339
|
-
errors.push(typeError);
|
|
340
|
-
return errors;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if (fieldDef.required) {
|
|
344
|
-
const requiredValidator = getValidator("required");
|
|
345
|
-
if (requiredValidator) {
|
|
346
|
-
const error = requiredValidator(value, void 0, context);
|
|
347
|
-
if (error) {
|
|
348
|
-
errors.push(error);
|
|
349
|
-
return errors;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
} else if (value === void 0 || value === null || value === "") {
|
|
353
|
-
return errors;
|
|
354
|
-
}
|
|
355
|
-
for (const rule of fieldDef.rules) {
|
|
356
|
-
const validator = getValidator(rule.type);
|
|
357
|
-
if (!validator) {
|
|
358
|
-
console.warn(`Unknown validator: ${rule.type}`);
|
|
359
|
-
continue;
|
|
360
|
-
}
|
|
361
|
-
const params = {
|
|
362
|
-
...rule.params,
|
|
363
|
-
soft: rule.soft,
|
|
364
|
-
message: rule.message
|
|
365
|
-
};
|
|
366
|
-
const error = validator(value, params, context);
|
|
367
|
-
if (error) {
|
|
368
|
-
errors.push(error);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (fieldDef.type === "object" && fieldDef.schema && value !== null && value !== void 0) {
|
|
372
|
-
const nestedResult = validateSchema(fieldDef.schema, value, context.path, context.root);
|
|
373
|
-
errors.push(...nestedResult.hardErrors, ...nestedResult.softErrors);
|
|
374
|
-
}
|
|
375
|
-
if (fieldDef.type === "array" && fieldDef.items && Array.isArray(value)) {
|
|
376
|
-
for (let i = 0; i < value.length; i++) {
|
|
377
|
-
const itemContext = {
|
|
378
|
-
path: `${context.path}[${i}]`,
|
|
379
|
-
root: context.root,
|
|
380
|
-
parent: value
|
|
381
|
-
};
|
|
382
|
-
const itemErrors = validateField(fieldDef.items, value[i], itemContext);
|
|
383
|
-
errors.push(...itemErrors);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return errors;
|
|
387
|
-
}
|
|
388
|
-
function validateSchema(schema, data, basePath = "", root) {
|
|
389
|
-
const hardErrors = [];
|
|
390
|
-
const softErrors = [];
|
|
391
|
-
const rootData = root ?? data;
|
|
392
|
-
for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
|
|
393
|
-
const value = data[fieldName];
|
|
394
|
-
const path = basePath ? `${basePath}.${fieldName}` : fieldName;
|
|
395
|
-
const context = {
|
|
396
|
-
path,
|
|
397
|
-
root: rootData,
|
|
398
|
-
parent: data
|
|
399
|
-
};
|
|
400
|
-
const errors = validateField(fieldDef, value, context);
|
|
401
|
-
for (const error of errors) {
|
|
402
|
-
if (error.severity === "soft") {
|
|
403
|
-
softErrors.push(error);
|
|
404
|
-
} else {
|
|
405
|
-
hardErrors.push(error);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return {
|
|
410
|
-
valid: hardErrors.length === 0,
|
|
411
|
-
hardErrors,
|
|
412
|
-
softErrors
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
function validate(schema, data) {
|
|
416
|
-
return validateSchema(schema, data);
|
|
417
|
-
}
|
|
1
|
+
import { validate } from '../../chunk-MFEBMQAU.mjs';
|
|
2
|
+
import '../../chunk-75YSYC4K.mjs';
|
|
3
|
+
import '../../chunk-KZCV5IW4.mjs';
|
|
4
|
+
import '../../chunk-COMVAVFU.mjs';
|
|
5
|
+
import '../../chunk-RW6HDA5H.mjs';
|
|
6
|
+
import '../../chunk-7XES4A3M.mjs';
|
|
7
|
+
import '../../chunk-5A4ITJVD.mjs';
|
|
8
|
+
import '../../chunk-KZZ7NVU3.mjs';
|
|
418
9
|
|
|
419
10
|
// src/adapters/frontend/form.ts
|
|
420
11
|
function createForm(schema, options = {}) {
|
|
@@ -864,5 +455,3 @@ function coerceValue(value, type) {
|
|
|
864
455
|
}
|
|
865
456
|
|
|
866
457
|
export { FormController, coerceValue, createForm, debounceValidation, focusFirstError, getFieldError, getFieldErrors, getFieldWarning, getFieldWarnings, getFirstErrorField, groupErrorsByField, hasFieldError, hasFieldWarning, parseApiErrors, toErrorMap, toWarningsMap };
|
|
867
|
-
//# sourceMappingURL=index.mjs.map
|
|
868
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isEmpty, isArray, createError } from './chunk-KZZ7NVU3.mjs';
|
|
2
|
+
|
|
3
|
+
// src/validators/array/includes.ts
|
|
4
|
+
var includesValidator = (value, params, context) => {
|
|
5
|
+
if (isEmpty(value)) return null;
|
|
6
|
+
const item = params?.item;
|
|
7
|
+
const soft = params?.soft;
|
|
8
|
+
const message = params?.message;
|
|
9
|
+
if (!isArray(value)) return null;
|
|
10
|
+
if (!value.includes(item)) {
|
|
11
|
+
return createError(
|
|
12
|
+
context,
|
|
13
|
+
"INVALID_INCLUDES",
|
|
14
|
+
message || `Array must include ${JSON.stringify(item)}`,
|
|
15
|
+
soft
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/validators/array/excludes.ts
|
|
22
|
+
var excludesValidator = (value, params, context) => {
|
|
23
|
+
if (isEmpty(value)) return null;
|
|
24
|
+
const item = params?.item;
|
|
25
|
+
const soft = params?.soft;
|
|
26
|
+
const message = params?.message;
|
|
27
|
+
if (!isArray(value)) return null;
|
|
28
|
+
if (value.includes(item)) {
|
|
29
|
+
return createError(
|
|
30
|
+
context,
|
|
31
|
+
"INVALID_EXCLUDES",
|
|
32
|
+
message || `Array must not include ${JSON.stringify(item)}`,
|
|
33
|
+
soft
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/validators/array/empty.ts
|
|
40
|
+
var emptyValidator = (value, params, context) => {
|
|
41
|
+
if (isEmpty(value)) return null;
|
|
42
|
+
const soft = params?.soft;
|
|
43
|
+
const message = params?.message;
|
|
44
|
+
if (!isArray(value)) return null;
|
|
45
|
+
if (value.length > 0) {
|
|
46
|
+
return createError(
|
|
47
|
+
context,
|
|
48
|
+
"INVALID_EMPTY",
|
|
49
|
+
message || "Array must be empty",
|
|
50
|
+
soft
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/validators/array/notEmpty.ts
|
|
57
|
+
var notEmptyValidator = (value, params, context) => {
|
|
58
|
+
if (isEmpty(value)) return null;
|
|
59
|
+
const soft = params?.soft;
|
|
60
|
+
const message = params?.message;
|
|
61
|
+
if (!isArray(value)) return null;
|
|
62
|
+
if (value.length === 0) {
|
|
63
|
+
return createError(
|
|
64
|
+
context,
|
|
65
|
+
"INVALID_NOT_EMPTY",
|
|
66
|
+
message || "Array must not be empty",
|
|
67
|
+
soft
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/validators/array/sorted.ts
|
|
74
|
+
var sortedValidator = (value, params, context) => {
|
|
75
|
+
if (isEmpty(value)) return null;
|
|
76
|
+
const order = params?.order || "asc";
|
|
77
|
+
const soft = params?.soft;
|
|
78
|
+
const message = params?.message;
|
|
79
|
+
if (!isArray(value)) return null;
|
|
80
|
+
for (let i = 1; i < value.length; i++) {
|
|
81
|
+
const prev = value[i - 1];
|
|
82
|
+
const curr = value[i];
|
|
83
|
+
if (order === "asc") {
|
|
84
|
+
if (prev > curr) {
|
|
85
|
+
return createError(
|
|
86
|
+
context,
|
|
87
|
+
"INVALID_SORTED",
|
|
88
|
+
message || "Array must be sorted in ascending order",
|
|
89
|
+
soft
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (prev < curr) {
|
|
94
|
+
return createError(
|
|
95
|
+
context,
|
|
96
|
+
"INVALID_SORTED",
|
|
97
|
+
message || "Array must be sorted in descending order",
|
|
98
|
+
soft
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/validators/array/compact.ts
|
|
107
|
+
var compactValidator = (value, params, context) => {
|
|
108
|
+
if (isEmpty(value)) return null;
|
|
109
|
+
const soft = params?.soft;
|
|
110
|
+
const message = params?.message;
|
|
111
|
+
if (!isArray(value)) return null;
|
|
112
|
+
const hasFalsy = value.some((item) => !item);
|
|
113
|
+
if (hasFalsy) {
|
|
114
|
+
return createError(
|
|
115
|
+
context,
|
|
116
|
+
"INVALID_COMPACT",
|
|
117
|
+
message || "Array must not contain falsy values",
|
|
118
|
+
soft
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export { compactValidator, emptyValidator, excludesValidator, includesValidator, notEmptyValidator, sortedValidator };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
|
|
4
|
+
|
|
5
|
+
// src/validators/array/includes.ts
|
|
6
|
+
var includesValidator = (value, params, context) => {
|
|
7
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
8
|
+
const item = params?.item;
|
|
9
|
+
const soft = params?.soft;
|
|
10
|
+
const message = params?.message;
|
|
11
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
12
|
+
if (!value.includes(item)) {
|
|
13
|
+
return chunkOIYG5D2I_js.createError(
|
|
14
|
+
context,
|
|
15
|
+
"INVALID_INCLUDES",
|
|
16
|
+
message || `Array must include ${JSON.stringify(item)}`,
|
|
17
|
+
soft
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/validators/array/excludes.ts
|
|
24
|
+
var excludesValidator = (value, params, context) => {
|
|
25
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
26
|
+
const item = params?.item;
|
|
27
|
+
const soft = params?.soft;
|
|
28
|
+
const message = params?.message;
|
|
29
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
30
|
+
if (value.includes(item)) {
|
|
31
|
+
return chunkOIYG5D2I_js.createError(
|
|
32
|
+
context,
|
|
33
|
+
"INVALID_EXCLUDES",
|
|
34
|
+
message || `Array must not include ${JSON.stringify(item)}`,
|
|
35
|
+
soft
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/validators/array/empty.ts
|
|
42
|
+
var emptyValidator = (value, params, context) => {
|
|
43
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
44
|
+
const soft = params?.soft;
|
|
45
|
+
const message = params?.message;
|
|
46
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
47
|
+
if (value.length > 0) {
|
|
48
|
+
return chunkOIYG5D2I_js.createError(
|
|
49
|
+
context,
|
|
50
|
+
"INVALID_EMPTY",
|
|
51
|
+
message || "Array must be empty",
|
|
52
|
+
soft
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/validators/array/notEmpty.ts
|
|
59
|
+
var notEmptyValidator = (value, params, context) => {
|
|
60
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
61
|
+
const soft = params?.soft;
|
|
62
|
+
const message = params?.message;
|
|
63
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
64
|
+
if (value.length === 0) {
|
|
65
|
+
return chunkOIYG5D2I_js.createError(
|
|
66
|
+
context,
|
|
67
|
+
"INVALID_NOT_EMPTY",
|
|
68
|
+
message || "Array must not be empty",
|
|
69
|
+
soft
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/validators/array/sorted.ts
|
|
76
|
+
var sortedValidator = (value, params, context) => {
|
|
77
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
78
|
+
const order = params?.order || "asc";
|
|
79
|
+
const soft = params?.soft;
|
|
80
|
+
const message = params?.message;
|
|
81
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
82
|
+
for (let i = 1; i < value.length; i++) {
|
|
83
|
+
const prev = value[i - 1];
|
|
84
|
+
const curr = value[i];
|
|
85
|
+
if (order === "asc") {
|
|
86
|
+
if (prev > curr) {
|
|
87
|
+
return chunkOIYG5D2I_js.createError(
|
|
88
|
+
context,
|
|
89
|
+
"INVALID_SORTED",
|
|
90
|
+
message || "Array must be sorted in ascending order",
|
|
91
|
+
soft
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
if (prev < curr) {
|
|
96
|
+
return chunkOIYG5D2I_js.createError(
|
|
97
|
+
context,
|
|
98
|
+
"INVALID_SORTED",
|
|
99
|
+
message || "Array must be sorted in descending order",
|
|
100
|
+
soft
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/validators/array/compact.ts
|
|
109
|
+
var compactValidator = (value, params, context) => {
|
|
110
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
111
|
+
const soft = params?.soft;
|
|
112
|
+
const message = params?.message;
|
|
113
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
114
|
+
const hasFalsy = value.some((item) => !item);
|
|
115
|
+
if (hasFalsy) {
|
|
116
|
+
return chunkOIYG5D2I_js.createError(
|
|
117
|
+
context,
|
|
118
|
+
"INVALID_COMPACT",
|
|
119
|
+
message || "Array must not contain falsy values",
|
|
120
|
+
soft
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
exports.compactValidator = compactValidator;
|
|
127
|
+
exports.emptyValidator = emptyValidator;
|
|
128
|
+
exports.excludesValidator = excludesValidator;
|
|
129
|
+
exports.includesValidator = includesValidator;
|
|
130
|
+
exports.notEmptyValidator = notEmptyValidator;
|
|
131
|
+
exports.sortedValidator = sortedValidator;
|