unischema 1.0.1 → 1.1.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.
Files changed (70) hide show
  1. package/README.md +634 -231
  2. package/dist/adapters/backend/index.d.mts +2 -1
  3. package/dist/adapters/backend/index.d.ts +2 -1
  4. package/dist/adapters/backend/index.js +17 -441
  5. package/dist/adapters/backend/index.mjs +9 -433
  6. package/dist/adapters/frontend/index.d.mts +2 -1
  7. package/dist/adapters/frontend/index.d.ts +2 -1
  8. package/dist/adapters/frontend/index.js +10 -421
  9. package/dist/adapters/frontend/index.mjs +8 -419
  10. package/dist/chunk-2JYFKT3R.js +103 -0
  11. package/dist/chunk-3FANCMEF.js +206 -0
  12. package/dist/chunk-3TS35CVJ.mjs +478 -0
  13. package/dist/chunk-ASKTY6EG.js +131 -0
  14. package/dist/chunk-BJLVOIAP.js +491 -0
  15. package/dist/chunk-BNIB23NQ.js +90 -0
  16. package/dist/chunk-BVRXGZLS.js +17 -0
  17. package/dist/chunk-CQYXR2LZ.js +353 -0
  18. package/dist/chunk-ELL7U7IC.mjs +237 -0
  19. package/dist/chunk-FKDWSZIV.mjs +39 -0
  20. package/dist/chunk-FRBZHN4K.mjs +335 -0
  21. package/dist/chunk-FZ7K2PC7.js +248 -0
  22. package/dist/chunk-KHHJD6QK.mjs +85 -0
  23. package/dist/chunk-NUW55QTO.js +48 -0
  24. package/dist/chunk-TTK77YBI.mjs +15 -0
  25. package/dist/chunk-VWP24NYS.mjs +194 -0
  26. package/dist/chunk-XC4DKEXP.mjs +97 -0
  27. package/dist/chunk-XGTUU27F.mjs +124 -0
  28. package/dist/index-BQR7OrY7.d.mts +80 -0
  29. package/dist/index-BQR7OrY7.d.ts +80 -0
  30. package/dist/index.d.mts +3 -2
  31. package/dist/index.d.ts +3 -2
  32. package/dist/index.js +527 -494
  33. package/dist/index.mjs +476 -482
  34. package/dist/{schema-D9DGC9E_.d.mts → schema-CpAjXgEF.d.ts} +182 -79
  35. package/dist/{schema-D9DGC9E_.d.ts → schema-DYU1zGVm.d.mts} +182 -79
  36. package/dist/validators/array.d.mts +15 -0
  37. package/dist/validators/array.d.ts +15 -0
  38. package/dist/validators/array.js +31 -0
  39. package/dist/validators/array.mjs +2 -0
  40. package/dist/validators/common.d.mts +13 -0
  41. package/dist/validators/common.d.ts +13 -0
  42. package/dist/validators/common.js +27 -0
  43. package/dist/validators/common.mjs +2 -0
  44. package/dist/validators/date.d.mts +23 -0
  45. package/dist/validators/date.d.ts +23 -0
  46. package/dist/validators/date.js +47 -0
  47. package/dist/validators/date.mjs +2 -0
  48. package/dist/validators/index.d.mts +46 -0
  49. package/dist/validators/index.d.ts +46 -0
  50. package/dist/validators/index.js +256 -0
  51. package/dist/validators/index.mjs +7 -0
  52. package/dist/validators/number.d.mts +25 -0
  53. package/dist/validators/number.d.ts +25 -0
  54. package/dist/validators/number.js +51 -0
  55. package/dist/validators/number.mjs +2 -0
  56. package/dist/validators/object.d.mts +11 -0
  57. package/dist/validators/object.d.ts +11 -0
  58. package/dist/validators/object.js +23 -0
  59. package/dist/validators/object.mjs +2 -0
  60. package/dist/validators/string.d.mts +37 -0
  61. package/dist/validators/string.d.ts +37 -0
  62. package/dist/validators/string.js +75 -0
  63. package/dist/validators/string.mjs +2 -0
  64. package/package.json +36 -1
  65. package/dist/adapters/backend/index.js.map +0 -1
  66. package/dist/adapters/backend/index.mjs.map +0 -1
  67. package/dist/adapters/frontend/index.js.map +0 -1
  68. package/dist/adapters/frontend/index.mjs.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ var chunkNUW55QTO_js = require('./chunk-NUW55QTO.js');
4
+
5
+ // src/validators/array/includes.ts
6
+ var includesValidator = (value, params, context) => {
7
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
8
+ const item = params?.item;
9
+ const soft = params?.soft;
10
+ const message = params?.message;
11
+ if (!chunkNUW55QTO_js.isArray(value)) return null;
12
+ if (!value.includes(item)) {
13
+ return chunkNUW55QTO_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 (chunkNUW55QTO_js.isEmpty(value)) return null;
26
+ const item = params?.item;
27
+ const soft = params?.soft;
28
+ const message = params?.message;
29
+ if (!chunkNUW55QTO_js.isArray(value)) return null;
30
+ if (value.includes(item)) {
31
+ return chunkNUW55QTO_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 (chunkNUW55QTO_js.isEmpty(value)) return null;
44
+ const soft = params?.soft;
45
+ const message = params?.message;
46
+ if (!chunkNUW55QTO_js.isArray(value)) return null;
47
+ if (value.length > 0) {
48
+ return chunkNUW55QTO_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 (chunkNUW55QTO_js.isEmpty(value)) return null;
61
+ const soft = params?.soft;
62
+ const message = params?.message;
63
+ if (!chunkNUW55QTO_js.isArray(value)) return null;
64
+ if (value.length === 0) {
65
+ return chunkNUW55QTO_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 (chunkNUW55QTO_js.isEmpty(value)) return null;
78
+ const order = params?.order || "asc";
79
+ const soft = params?.soft;
80
+ const message = params?.message;
81
+ if (!chunkNUW55QTO_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 chunkNUW55QTO_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 chunkNUW55QTO_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 (chunkNUW55QTO_js.isEmpty(value)) return null;
111
+ const soft = params?.soft;
112
+ const message = params?.message;
113
+ if (!chunkNUW55QTO_js.isArray(value)) return null;
114
+ const hasFalsy = value.some((item) => !item);
115
+ if (hasFalsy) {
116
+ return chunkNUW55QTO_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;
@@ -0,0 +1,491 @@
1
+ 'use strict';
2
+
3
+ var chunkBNIB23NQ_js = require('./chunk-BNIB23NQ.js');
4
+ var chunk2JYFKT3R_js = require('./chunk-2JYFKT3R.js');
5
+ var chunkCQYXR2LZ_js = require('./chunk-CQYXR2LZ.js');
6
+ var chunk3FANCMEF_js = require('./chunk-3FANCMEF.js');
7
+ var chunkFZ7K2PC7_js = require('./chunk-FZ7K2PC7.js');
8
+ var chunkASKTY6EG_js = require('./chunk-ASKTY6EG.js');
9
+
10
+ // src/core/validators.ts
11
+ function createError(context, code, message, soft = false) {
12
+ return {
13
+ field: context.path,
14
+ code,
15
+ message,
16
+ severity: soft ? "soft" : "hard"
17
+ };
18
+ }
19
+ var typeValidators = {
20
+ string: (value, _params, context) => {
21
+ if (value !== void 0 && value !== null && typeof value !== "string") {
22
+ return createError(context, "INVALID_TYPE", `Expected string, got ${typeof value}`);
23
+ }
24
+ return null;
25
+ },
26
+ number: (value, _params, context) => {
27
+ if (value !== void 0 && value !== null && typeof value !== "number") {
28
+ return createError(context, "INVALID_TYPE", `Expected number, got ${typeof value}`);
29
+ }
30
+ if (typeof value === "number" && isNaN(value)) {
31
+ return createError(context, "INVALID_NUMBER", "Value is not a valid number");
32
+ }
33
+ return null;
34
+ },
35
+ boolean: (value, _params, context) => {
36
+ if (value !== void 0 && value !== null && typeof value !== "boolean") {
37
+ return createError(context, "INVALID_TYPE", `Expected boolean, got ${typeof value}`);
38
+ }
39
+ return null;
40
+ },
41
+ date: (value, _params, context) => {
42
+ if (value === void 0 || value === null) return null;
43
+ if (value instanceof Date) {
44
+ if (isNaN(value.getTime())) {
45
+ return createError(context, "INVALID_DATE", "Invalid date value");
46
+ }
47
+ return null;
48
+ }
49
+ if (typeof value === "string") {
50
+ const parsed = new Date(value);
51
+ if (isNaN(parsed.getTime())) {
52
+ return createError(context, "INVALID_DATE", "Invalid date format");
53
+ }
54
+ return null;
55
+ }
56
+ return createError(context, "INVALID_TYPE", `Expected date, got ${typeof value}`);
57
+ },
58
+ array: (value, _params, context) => {
59
+ if (value !== void 0 && value !== null && !Array.isArray(value)) {
60
+ return createError(context, "INVALID_TYPE", `Expected array, got ${typeof value}`);
61
+ }
62
+ return null;
63
+ },
64
+ object: (value, _params, context) => {
65
+ if (value !== void 0 && value !== null) {
66
+ if (typeof value !== "object" || Array.isArray(value)) {
67
+ return createError(context, "INVALID_TYPE", `Expected object, got ${typeof value}`);
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+ };
73
+ var ruleValidators = {
74
+ required: (value, _params, context) => {
75
+ const isEmpty = value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
76
+ if (isEmpty) {
77
+ return createError(context, "REQUIRED", "This field is required");
78
+ }
79
+ return null;
80
+ },
81
+ min: (value, params, context) => {
82
+ const min = params?.value;
83
+ const soft = params?.soft;
84
+ const message = params?.message;
85
+ if (value === void 0 || value === null) return null;
86
+ if (typeof value === "number") {
87
+ if (value < min) {
88
+ return createError(
89
+ context,
90
+ "MIN_VALUE",
91
+ message || `Value must be at least ${min}`,
92
+ soft
93
+ );
94
+ }
95
+ }
96
+ if (typeof value === "string") {
97
+ if (value.length < min) {
98
+ return createError(
99
+ context,
100
+ "MIN_LENGTH",
101
+ message || `Must be at least ${min} characters`,
102
+ soft
103
+ );
104
+ }
105
+ }
106
+ if (Array.isArray(value)) {
107
+ if (value.length < min) {
108
+ return createError(
109
+ context,
110
+ "MIN_ITEMS",
111
+ message || `Must have at least ${min} items`,
112
+ soft
113
+ );
114
+ }
115
+ }
116
+ return null;
117
+ },
118
+ max: (value, params, context) => {
119
+ const max = params?.value;
120
+ const soft = params?.soft;
121
+ const message = params?.message;
122
+ if (value === void 0 || value === null) return null;
123
+ if (typeof value === "number") {
124
+ if (value > max) {
125
+ return createError(
126
+ context,
127
+ "MAX_VALUE",
128
+ message || `Value must be at most ${max}`,
129
+ soft
130
+ );
131
+ }
132
+ }
133
+ if (typeof value === "string") {
134
+ if (value.length > max) {
135
+ return createError(
136
+ context,
137
+ "MAX_LENGTH",
138
+ message || `Must be at most ${max} characters`,
139
+ soft
140
+ );
141
+ }
142
+ }
143
+ if (Array.isArray(value)) {
144
+ if (value.length > max) {
145
+ return createError(
146
+ context,
147
+ "MAX_ITEMS",
148
+ message || `Must have at most ${max} items`,
149
+ soft
150
+ );
151
+ }
152
+ }
153
+ return null;
154
+ },
155
+ // String validators
156
+ email: chunkCQYXR2LZ_js.emailValidator,
157
+ url: chunkCQYXR2LZ_js.urlValidator,
158
+ ipAddress: chunkCQYXR2LZ_js.ipAddressValidator,
159
+ ipv6: chunkCQYXR2LZ_js.ipv6Validator,
160
+ alpha: chunkCQYXR2LZ_js.alphaValidator,
161
+ alphanumeric: chunkCQYXR2LZ_js.alphanumericValidator,
162
+ numeric: chunkCQYXR2LZ_js.numericValidator,
163
+ lowercase: chunkCQYXR2LZ_js.lowercaseValidator,
164
+ uppercase: chunkCQYXR2LZ_js.uppercaseValidator,
165
+ slug: chunkCQYXR2LZ_js.slugValidator,
166
+ hex: chunkCQYXR2LZ_js.hexValidator,
167
+ base64: chunkCQYXR2LZ_js.base64Validator,
168
+ json: chunkCQYXR2LZ_js.jsonValidator,
169
+ length: chunkCQYXR2LZ_js.lengthValidator,
170
+ contains: chunkCQYXR2LZ_js.containsValidator,
171
+ startsWith: chunkCQYXR2LZ_js.startsWithValidator,
172
+ endsWith: chunkCQYXR2LZ_js.endsWithValidator,
173
+ // Number validators
174
+ port: chunk3FANCMEF_js.portValidator,
175
+ latitude: chunk3FANCMEF_js.latitudeValidator,
176
+ longitude: chunk3FANCMEF_js.longitudeValidator,
177
+ percentage: chunk3FANCMEF_js.percentageValidator,
178
+ numberBetween: chunk3FANCMEF_js.betweenValidator,
179
+ divisibleBy: chunk3FANCMEF_js.divisibleByValidator,
180
+ multipleOf: chunk3FANCMEF_js.multipleOfValidator,
181
+ even: chunk3FANCMEF_js.evenValidator,
182
+ odd: chunk3FANCMEF_js.oddValidator,
183
+ safe: chunk3FANCMEF_js.safeValidator,
184
+ finite: chunk3FANCMEF_js.finiteValidator,
185
+ // Date validators
186
+ today: chunkFZ7K2PC7_js.todayValidator,
187
+ yesterday: chunkFZ7K2PC7_js.yesterdayValidator,
188
+ tomorrow: chunkFZ7K2PC7_js.tomorrowValidator,
189
+ thisWeek: chunkFZ7K2PC7_js.thisWeekValidator,
190
+ thisMonth: chunkFZ7K2PC7_js.thisMonthValidator,
191
+ thisYear: chunkFZ7K2PC7_js.thisYearValidator,
192
+ weekday: chunkFZ7K2PC7_js.weekdayValidator,
193
+ weekend: chunkFZ7K2PC7_js.weekendValidator,
194
+ age: chunkFZ7K2PC7_js.ageValidator,
195
+ dateBetween: chunkFZ7K2PC7_js.betweenValidator,
196
+ // Array validators
197
+ includes: chunkASKTY6EG_js.includesValidator,
198
+ excludes: chunkASKTY6EG_js.excludesValidator,
199
+ empty: chunkASKTY6EG_js.emptyValidator,
200
+ notEmpty: chunkASKTY6EG_js.notEmptyValidator,
201
+ sorted: chunkASKTY6EG_js.sortedValidator,
202
+ compact: chunkASKTY6EG_js.compactValidator,
203
+ // Object validators
204
+ keys: chunkBNIB23NQ_js.keysValidator,
205
+ pick: chunkBNIB23NQ_js.pickValidator,
206
+ omit: chunkBNIB23NQ_js.omitValidator,
207
+ strict: chunkBNIB23NQ_js.strictValidator,
208
+ // Cross-field validators
209
+ notMatches: chunk2JYFKT3R_js.notMatchesValidator,
210
+ greaterThan: chunk2JYFKT3R_js.greaterThanValidator,
211
+ lessThan: chunk2JYFKT3R_js.lessThanValidator,
212
+ when: chunk2JYFKT3R_js.whenValidator,
213
+ dependsOn: chunk2JYFKT3R_js.dependsOnValidator,
214
+ pattern: (value, params, context) => {
215
+ if (value === void 0 || value === null || value === "") return null;
216
+ const pattern = params?.pattern;
217
+ const soft = params?.soft;
218
+ const message = params?.message;
219
+ if (typeof value !== "string") return null;
220
+ const regex = new RegExp(pattern);
221
+ if (!regex.test(value)) {
222
+ return createError(
223
+ context,
224
+ "PATTERN_MISMATCH",
225
+ message || `Value does not match required pattern`,
226
+ soft
227
+ );
228
+ }
229
+ return null;
230
+ },
231
+ enum: (value, params, context) => {
232
+ if (value === void 0 || value === null) return null;
233
+ const values = params?.values;
234
+ const soft = params?.soft;
235
+ const message = params?.message;
236
+ if (!values.includes(value)) {
237
+ return createError(
238
+ context,
239
+ "INVALID_ENUM",
240
+ message || `Value must be one of: ${values.join(", ")}`,
241
+ soft
242
+ );
243
+ }
244
+ return null;
245
+ },
246
+ custom: (value, params, context) => {
247
+ const validate2 = params?.validate;
248
+ const soft = params?.soft;
249
+ const message = params?.message;
250
+ if (!validate2) return null;
251
+ const result = validate2(value, context);
252
+ if (typeof result === "boolean") {
253
+ if (!result) {
254
+ return createError(
255
+ context,
256
+ "CUSTOM_VALIDATION",
257
+ message || "Validation failed",
258
+ soft
259
+ );
260
+ }
261
+ return null;
262
+ }
263
+ if (!result.valid) {
264
+ return createError(
265
+ context,
266
+ "CUSTOM_VALIDATION",
267
+ result.message || message || "Validation failed",
268
+ soft
269
+ );
270
+ }
271
+ return null;
272
+ },
273
+ // Enterprise patterns - matches field against another field
274
+ matches: (value, params, context) => {
275
+ if (value === void 0 || value === null) return null;
276
+ const otherField = params?.field;
277
+ const soft = params?.soft;
278
+ const message = params?.message;
279
+ const root = context.root;
280
+ const otherValue = root[otherField];
281
+ if (value !== otherValue) {
282
+ return createError(
283
+ context,
284
+ "FIELD_MISMATCH",
285
+ message || `Must match ${otherField}`,
286
+ soft
287
+ );
288
+ }
289
+ return null;
290
+ },
291
+ // Integer validation
292
+ integer: (value, params, context) => {
293
+ if (value === void 0 || value === null) return null;
294
+ const soft = params?.soft;
295
+ const message = params?.message;
296
+ if (typeof value !== "number" || !Number.isInteger(value)) {
297
+ return createError(
298
+ context,
299
+ "NOT_INTEGER",
300
+ message || "Value must be an integer",
301
+ soft
302
+ );
303
+ }
304
+ return null;
305
+ },
306
+ // Positive number validation
307
+ positive: (value, params, context) => {
308
+ if (value === void 0 || value === null) return null;
309
+ const soft = params?.soft;
310
+ const message = params?.message;
311
+ if (typeof value === "number" && value <= 0) {
312
+ return createError(
313
+ context,
314
+ "NOT_POSITIVE",
315
+ message || "Value must be positive",
316
+ soft
317
+ );
318
+ }
319
+ return null;
320
+ },
321
+ // Negative number validation
322
+ negative: (value, params, context) => {
323
+ if (value === void 0 || value === null) return null;
324
+ const soft = params?.soft;
325
+ const message = params?.message;
326
+ if (typeof value === "number" && value >= 0) {
327
+ return createError(
328
+ context,
329
+ "NOT_NEGATIVE",
330
+ message || "Value must be negative",
331
+ soft
332
+ );
333
+ }
334
+ return null;
335
+ }
336
+ };
337
+ var customValidators = /* @__PURE__ */ new Map();
338
+ function registerValidator(name, validator) {
339
+ customValidators.set(name, validator);
340
+ }
341
+ function getValidator(name) {
342
+ return ruleValidators[name] ?? customValidators.get(name);
343
+ }
344
+ function getTypeValidator(type) {
345
+ return typeValidators[type];
346
+ }
347
+
348
+ // src/core/engine.ts
349
+ function validateField(fieldDef, value, context) {
350
+ const errors = [];
351
+ const typeValidator = getTypeValidator(fieldDef.type);
352
+ if (typeValidator) {
353
+ const typeError = typeValidator(value, void 0, context);
354
+ if (typeError) {
355
+ errors.push(typeError);
356
+ return errors;
357
+ }
358
+ }
359
+ if (fieldDef.required) {
360
+ const requiredValidator = getValidator("required");
361
+ if (requiredValidator) {
362
+ const error = requiredValidator(value, void 0, context);
363
+ if (error) {
364
+ errors.push(error);
365
+ return errors;
366
+ }
367
+ }
368
+ } else if (value === void 0 || value === null || value === "") {
369
+ return errors;
370
+ }
371
+ for (const rule of fieldDef.rules) {
372
+ const validator = getValidator(rule.type);
373
+ if (!validator) {
374
+ console.warn(`Unknown validator: ${rule.type}`);
375
+ continue;
376
+ }
377
+ const params = {
378
+ ...rule.params,
379
+ soft: rule.soft,
380
+ message: rule.message
381
+ };
382
+ const error = validator(value, params, context);
383
+ if (error) {
384
+ errors.push(error);
385
+ }
386
+ }
387
+ if (fieldDef.type === "object" && fieldDef.schema && value !== null && value !== void 0) {
388
+ const nestedResult = validateSchema(fieldDef.schema, value, context.path, context.root);
389
+ errors.push(...nestedResult.hardErrors, ...nestedResult.softErrors);
390
+ }
391
+ if (fieldDef.type === "array" && fieldDef.items && Array.isArray(value)) {
392
+ for (let i = 0; i < value.length; i++) {
393
+ const itemContext = {
394
+ path: `${context.path}[${i}]`,
395
+ root: context.root,
396
+ parent: value
397
+ };
398
+ const itemErrors = validateField(fieldDef.items, value[i], itemContext);
399
+ errors.push(...itemErrors);
400
+ }
401
+ }
402
+ return errors;
403
+ }
404
+ function validateSchema(schema, data, basePath = "", root) {
405
+ const hardErrors = [];
406
+ const softErrors = [];
407
+ const rootData = root ?? data;
408
+ for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
409
+ const value = data[fieldName];
410
+ const path = basePath ? `${basePath}.${fieldName}` : fieldName;
411
+ const context = {
412
+ path,
413
+ root: rootData,
414
+ parent: data
415
+ };
416
+ const errors = validateField(fieldDef, value, context);
417
+ for (const error of errors) {
418
+ if (error.severity === "soft") {
419
+ softErrors.push(error);
420
+ } else {
421
+ hardErrors.push(error);
422
+ }
423
+ }
424
+ }
425
+ return {
426
+ valid: hardErrors.length === 0,
427
+ hardErrors,
428
+ softErrors
429
+ };
430
+ }
431
+ function validate(schema, data) {
432
+ return validateSchema(schema, data);
433
+ }
434
+ function isValid(schema, data) {
435
+ return validate(schema, data).valid;
436
+ }
437
+ function assertValid(schema, data) {
438
+ const result = validate(schema, data);
439
+ if (!result.valid) {
440
+ const error = new Error("Validation failed");
441
+ error.errors = result.hardErrors;
442
+ throw error;
443
+ }
444
+ return data;
445
+ }
446
+ function mergeResults(...results) {
447
+ const hardErrors = [];
448
+ const softErrors = [];
449
+ for (const result of results) {
450
+ hardErrors.push(...result.hardErrors);
451
+ softErrors.push(...result.softErrors);
452
+ }
453
+ return {
454
+ valid: hardErrors.length === 0,
455
+ hardErrors,
456
+ softErrors
457
+ };
458
+ }
459
+ function validResult() {
460
+ return {
461
+ valid: true,
462
+ hardErrors: [],
463
+ softErrors: []
464
+ };
465
+ }
466
+ function errorResult(field, code, message, soft = false) {
467
+ const error = {
468
+ field,
469
+ code,
470
+ message,
471
+ severity: soft ? "soft" : "hard"
472
+ };
473
+ return {
474
+ valid: soft,
475
+ hardErrors: soft ? [] : [error],
476
+ softErrors: soft ? [error] : []
477
+ };
478
+ }
479
+
480
+ exports.assertValid = assertValid;
481
+ exports.errorResult = errorResult;
482
+ exports.getTypeValidator = getTypeValidator;
483
+ exports.getValidator = getValidator;
484
+ exports.isValid = isValid;
485
+ exports.mergeResults = mergeResults;
486
+ exports.registerValidator = registerValidator;
487
+ exports.ruleValidators = ruleValidators;
488
+ exports.typeValidators = typeValidators;
489
+ exports.validResult = validResult;
490
+ exports.validate = validate;
491
+ exports.validateSchema = validateSchema;
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ var chunkNUW55QTO_js = require('./chunk-NUW55QTO.js');
4
+
5
+ // src/validators/object/keys.ts
6
+ var keysValidator = (value, params, context) => {
7
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
8
+ const pattern = params?.pattern;
9
+ const soft = params?.soft;
10
+ const message = params?.message;
11
+ if (!chunkNUW55QTO_js.isObject(value)) return null;
12
+ if (pattern) {
13
+ const keys = Object.keys(value);
14
+ const invalidKeys = keys.filter((key) => !pattern.test(key));
15
+ if (invalidKeys.length > 0) {
16
+ return chunkNUW55QTO_js.createError(
17
+ context,
18
+ "INVALID_KEYS",
19
+ message || `Invalid keys: ${invalidKeys.join(", ")}`,
20
+ soft
21
+ );
22
+ }
23
+ }
24
+ return null;
25
+ };
26
+
27
+ // src/validators/object/pick.ts
28
+ var pickValidator = (value, params, context) => {
29
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
30
+ const allowedKeys = params?.keys;
31
+ const soft = params?.soft;
32
+ const message = params?.message;
33
+ if (!chunkNUW55QTO_js.isObject(value) || !allowedKeys) return null;
34
+ const keys = Object.keys(value);
35
+ const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
36
+ if (extraKeys.length > 0) {
37
+ return chunkNUW55QTO_js.createError(
38
+ context,
39
+ "INVALID_PICK",
40
+ message || `Unexpected keys: ${extraKeys.join(", ")}`,
41
+ soft
42
+ );
43
+ }
44
+ return null;
45
+ };
46
+
47
+ // src/validators/object/omit.ts
48
+ var omitValidator = (value, params, context) => {
49
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
50
+ const forbiddenKeys = params?.keys;
51
+ const soft = params?.soft;
52
+ const message = params?.message;
53
+ if (!chunkNUW55QTO_js.isObject(value) || !forbiddenKeys) return null;
54
+ const keys = Object.keys(value);
55
+ const foundForbidden = keys.filter((key) => forbiddenKeys.includes(key));
56
+ if (foundForbidden.length > 0) {
57
+ return chunkNUW55QTO_js.createError(
58
+ context,
59
+ "INVALID_OMIT",
60
+ message || `Forbidden keys found: ${foundForbidden.join(", ")}`,
61
+ soft
62
+ );
63
+ }
64
+ return null;
65
+ };
66
+
67
+ // src/validators/object/strict.ts
68
+ var strictValidator = (value, params, context) => {
69
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
70
+ const allowedKeys = params?.allowedKeys;
71
+ const soft = params?.soft;
72
+ const message = params?.message;
73
+ if (!chunkNUW55QTO_js.isObject(value) || !allowedKeys) return null;
74
+ const keys = Object.keys(value);
75
+ const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
76
+ if (extraKeys.length > 0) {
77
+ return chunkNUW55QTO_js.createError(
78
+ context,
79
+ "INVALID_STRICT",
80
+ message || `Unknown keys not allowed: ${extraKeys.join(", ")}`,
81
+ soft
82
+ );
83
+ }
84
+ return null;
85
+ };
86
+
87
+ exports.keysValidator = keysValidator;
88
+ exports.omitValidator = omitValidator;
89
+ exports.pickValidator = pickValidator;
90
+ exports.strictValidator = strictValidator;