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,335 @@
1
+ import { isEmpty, isString, createError } from './chunk-FKDWSZIV.mjs';
2
+
3
+ // src/validators/string/email.ts
4
+ var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
5
+ var emailValidator = (value, params, context) => {
6
+ if (isEmpty(value)) return null;
7
+ const soft = params?.soft;
8
+ const message = params?.message;
9
+ if (!isString(value)) {
10
+ return createError(context, "INVALID_EMAIL", "Email must be a string", soft);
11
+ }
12
+ if (!EMAIL_REGEX.test(value)) {
13
+ return createError(
14
+ context,
15
+ "INVALID_EMAIL",
16
+ message || "Invalid email address",
17
+ soft
18
+ );
19
+ }
20
+ return null;
21
+ };
22
+
23
+ // src/validators/string/url.ts
24
+ var urlValidator = (value, params, context) => {
25
+ if (isEmpty(value)) return null;
26
+ const soft = params?.soft;
27
+ const message = params?.message;
28
+ if (!isString(value)) {
29
+ return createError(context, "INVALID_URL", "URL must be a string", soft);
30
+ }
31
+ try {
32
+ new URL(value);
33
+ return null;
34
+ } catch {
35
+ return createError(
36
+ context,
37
+ "INVALID_URL",
38
+ message || "Invalid URL format",
39
+ soft
40
+ );
41
+ }
42
+ };
43
+
44
+ // src/validators/string/ipAddress.ts
45
+ var IPV4_REGEX = /^((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]?)$/;
46
+ var ipAddressValidator = (value, params, context) => {
47
+ if (isEmpty(value)) return null;
48
+ const soft = params?.soft;
49
+ const message = params?.message;
50
+ if (!isString(value)) {
51
+ return createError(context, "INVALID_IP", "IP address must be a string", soft);
52
+ }
53
+ if (!IPV4_REGEX.test(value)) {
54
+ return createError(
55
+ context,
56
+ "INVALID_IP",
57
+ message || "Invalid IP address format",
58
+ soft
59
+ );
60
+ }
61
+ return null;
62
+ };
63
+
64
+ // src/validators/string/ipv6.ts
65
+ var IPV6_REGEX = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|::)$/;
66
+ var ipv6Validator = (value, params, context) => {
67
+ if (isEmpty(value)) return null;
68
+ const soft = params?.soft;
69
+ const message = params?.message;
70
+ if (!isString(value)) {
71
+ return createError(context, "INVALID_IPV6", "IPv6 address must be a string", soft);
72
+ }
73
+ if (!IPV6_REGEX.test(value)) {
74
+ return createError(
75
+ context,
76
+ "INVALID_IPV6",
77
+ message || "Invalid IPv6 address format",
78
+ soft
79
+ );
80
+ }
81
+ return null;
82
+ };
83
+
84
+ // src/validators/string/alpha.ts
85
+ var ALPHA_REGEX = /^[a-zA-Z]+$/;
86
+ var alphaValidator = (value, params, context) => {
87
+ if (isEmpty(value)) return null;
88
+ const soft = params?.soft;
89
+ const message = params?.message;
90
+ if (!isString(value)) {
91
+ return createError(context, "INVALID_ALPHA", "Value must be a string", soft);
92
+ }
93
+ if (!ALPHA_REGEX.test(value)) {
94
+ return createError(
95
+ context,
96
+ "INVALID_ALPHA",
97
+ message || "Must contain only letters",
98
+ soft
99
+ );
100
+ }
101
+ return null;
102
+ };
103
+
104
+ // src/validators/string/alphanumeric.ts
105
+ var ALPHANUMERIC_REGEX = /^[a-zA-Z0-9]+$/;
106
+ var alphanumericValidator = (value, params, context) => {
107
+ if (isEmpty(value)) return null;
108
+ const soft = params?.soft;
109
+ const message = params?.message;
110
+ if (!isString(value)) {
111
+ return createError(context, "INVALID_ALPHANUMERIC", "Value must be a string", soft);
112
+ }
113
+ if (!ALPHANUMERIC_REGEX.test(value)) {
114
+ return createError(
115
+ context,
116
+ "INVALID_ALPHANUMERIC",
117
+ message || "Must contain only letters and numbers",
118
+ soft
119
+ );
120
+ }
121
+ return null;
122
+ };
123
+
124
+ // src/validators/string/numeric.ts
125
+ var NUMERIC_REGEX = /^[0-9]+$/;
126
+ var numericValidator = (value, params, context) => {
127
+ if (isEmpty(value)) return null;
128
+ const soft = params?.soft;
129
+ const message = params?.message;
130
+ if (!isString(value)) {
131
+ return createError(context, "INVALID_NUMERIC", "Value must be a string", soft);
132
+ }
133
+ if (!NUMERIC_REGEX.test(value)) {
134
+ return createError(
135
+ context,
136
+ "INVALID_NUMERIC",
137
+ message || "Must contain only numbers",
138
+ soft
139
+ );
140
+ }
141
+ return null;
142
+ };
143
+
144
+ // src/validators/string/lowercase.ts
145
+ var lowercaseValidator = (value, params, context) => {
146
+ if (isEmpty(value)) return null;
147
+ const soft = params?.soft;
148
+ const message = params?.message;
149
+ if (!isString(value)) {
150
+ return createError(context, "INVALID_LOWERCASE", "Value must be a string", soft);
151
+ }
152
+ if (value !== value.toLowerCase()) {
153
+ return createError(
154
+ context,
155
+ "INVALID_LOWERCASE",
156
+ message || "Must be lowercase",
157
+ soft
158
+ );
159
+ }
160
+ return null;
161
+ };
162
+
163
+ // src/validators/string/uppercase.ts
164
+ var uppercaseValidator = (value, params, context) => {
165
+ if (isEmpty(value)) return null;
166
+ const soft = params?.soft;
167
+ const message = params?.message;
168
+ if (!isString(value)) {
169
+ return createError(context, "INVALID_UPPERCASE", "Value must be a string", soft);
170
+ }
171
+ if (value !== value.toUpperCase()) {
172
+ return createError(
173
+ context,
174
+ "INVALID_UPPERCASE",
175
+ message || "Must be uppercase",
176
+ soft
177
+ );
178
+ }
179
+ return null;
180
+ };
181
+
182
+ // src/validators/string/slug.ts
183
+ var SLUG_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
184
+ var slugValidator = (value, params, context) => {
185
+ if (isEmpty(value)) return null;
186
+ const soft = params?.soft;
187
+ const message = params?.message;
188
+ if (!isString(value)) {
189
+ return createError(context, "INVALID_SLUG", "Slug must be a string", soft);
190
+ }
191
+ if (!SLUG_REGEX.test(value)) {
192
+ return createError(
193
+ context,
194
+ "INVALID_SLUG",
195
+ message || "Must be a valid URL slug (lowercase, numbers, hyphens)",
196
+ soft
197
+ );
198
+ }
199
+ return null;
200
+ };
201
+
202
+ // src/validators/string/hex.ts
203
+ var HEX_REGEX = /^(0x)?[0-9a-fA-F]+$/;
204
+ var hexValidator = (value, params, context) => {
205
+ if (isEmpty(value)) return null;
206
+ const soft = params?.soft;
207
+ const message = params?.message;
208
+ if (!isString(value)) {
209
+ return createError(context, "INVALID_HEX", "Hex value must be a string", soft);
210
+ }
211
+ if (!HEX_REGEX.test(value)) {
212
+ return createError(
213
+ context,
214
+ "INVALID_HEX",
215
+ message || "Must be a valid hexadecimal string",
216
+ soft
217
+ );
218
+ }
219
+ return null;
220
+ };
221
+
222
+ // src/validators/string/base64.ts
223
+ var BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
224
+ var base64Validator = (value, params, context) => {
225
+ if (isEmpty(value)) return null;
226
+ const soft = params?.soft;
227
+ const message = params?.message;
228
+ if (!isString(value)) {
229
+ return createError(context, "INVALID_BASE64", "Base64 value must be a string", soft);
230
+ }
231
+ if (!BASE64_REGEX.test(value)) {
232
+ return createError(
233
+ context,
234
+ "INVALID_BASE64",
235
+ message || "Must be a valid base64 string",
236
+ soft
237
+ );
238
+ }
239
+ return null;
240
+ };
241
+
242
+ // src/validators/string/json.ts
243
+ var jsonValidator = (value, params, context) => {
244
+ if (isEmpty(value)) return null;
245
+ const soft = params?.soft;
246
+ const message = params?.message;
247
+ if (!isString(value)) {
248
+ return createError(context, "INVALID_JSON", "JSON value must be a string", soft);
249
+ }
250
+ try {
251
+ JSON.parse(value);
252
+ return null;
253
+ } catch {
254
+ return createError(
255
+ context,
256
+ "INVALID_JSON",
257
+ message || "Must be valid JSON",
258
+ soft
259
+ );
260
+ }
261
+ };
262
+
263
+ // src/validators/string/length.ts
264
+ var lengthValidator = (value, params, context) => {
265
+ if (isEmpty(value)) return null;
266
+ const length = params?.length;
267
+ const soft = params?.soft;
268
+ const message = params?.message;
269
+ if (!isString(value)) return null;
270
+ if (value.length !== length) {
271
+ return createError(
272
+ context,
273
+ "INVALID_LENGTH",
274
+ message || `Must be exactly ${length} characters`,
275
+ soft
276
+ );
277
+ }
278
+ return null;
279
+ };
280
+
281
+ // src/validators/string/contains.ts
282
+ var containsValidator = (value, params, context) => {
283
+ if (isEmpty(value)) return null;
284
+ const substring = params?.substring;
285
+ const soft = params?.soft;
286
+ const message = params?.message;
287
+ if (!isString(value)) return null;
288
+ if (!value.includes(substring)) {
289
+ return createError(
290
+ context,
291
+ "INVALID_CONTAINS",
292
+ message || `Must contain "${substring}"`,
293
+ soft
294
+ );
295
+ }
296
+ return null;
297
+ };
298
+
299
+ // src/validators/string/startsWith.ts
300
+ var startsWithValidator = (value, params, context) => {
301
+ if (isEmpty(value)) return null;
302
+ const prefix = params?.prefix;
303
+ const soft = params?.soft;
304
+ const message = params?.message;
305
+ if (!isString(value)) return null;
306
+ if (!value.startsWith(prefix)) {
307
+ return createError(
308
+ context,
309
+ "INVALID_STARTS_WITH",
310
+ message || `Must start with "${prefix}"`,
311
+ soft
312
+ );
313
+ }
314
+ return null;
315
+ };
316
+
317
+ // src/validators/string/endsWith.ts
318
+ var endsWithValidator = (value, params, context) => {
319
+ if (isEmpty(value)) return null;
320
+ const suffix = params?.suffix;
321
+ const soft = params?.soft;
322
+ const message = params?.message;
323
+ if (!isString(value)) return null;
324
+ if (!value.endsWith(suffix)) {
325
+ return createError(
326
+ context,
327
+ "INVALID_ENDS_WITH",
328
+ message || `Must end with "${suffix}"`,
329
+ soft
330
+ );
331
+ }
332
+ return null;
333
+ };
334
+
335
+ export { alphaValidator, alphanumericValidator, base64Validator, containsValidator, emailValidator, endsWithValidator, hexValidator, ipAddressValidator, ipv6Validator, jsonValidator, lengthValidator, lowercaseValidator, numericValidator, slugValidator, startsWithValidator, uppercaseValidator, urlValidator };
@@ -0,0 +1,248 @@
1
+ 'use strict';
2
+
3
+ var chunkNUW55QTO_js = require('./chunk-NUW55QTO.js');
4
+
5
+ // src/validators/date/today.ts
6
+ var todayValidator = (value, params, context) => {
7
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
8
+ const soft = params?.soft;
9
+ const message = params?.message;
10
+ const date = chunkNUW55QTO_js.parseDate(value);
11
+ if (!date) return null;
12
+ const today = /* @__PURE__ */ new Date();
13
+ today.setHours(0, 0, 0, 0);
14
+ date.setHours(0, 0, 0, 0);
15
+ if (date.getTime() !== today.getTime()) {
16
+ return chunkNUW55QTO_js.createError(
17
+ context,
18
+ "INVALID_TODAY",
19
+ message || "Date must be today",
20
+ soft
21
+ );
22
+ }
23
+ return null;
24
+ };
25
+
26
+ // src/validators/date/yesterday.ts
27
+ var yesterdayValidator = (value, params, context) => {
28
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
29
+ const soft = params?.soft;
30
+ const message = params?.message;
31
+ const date = chunkNUW55QTO_js.parseDate(value);
32
+ if (!date) return null;
33
+ const yesterday = /* @__PURE__ */ new Date();
34
+ yesterday.setDate(yesterday.getDate() - 1);
35
+ yesterday.setHours(0, 0, 0, 0);
36
+ date.setHours(0, 0, 0, 0);
37
+ if (date.getTime() !== yesterday.getTime()) {
38
+ return chunkNUW55QTO_js.createError(
39
+ context,
40
+ "INVALID_YESTERDAY",
41
+ message || "Date must be yesterday",
42
+ soft
43
+ );
44
+ }
45
+ return null;
46
+ };
47
+
48
+ // src/validators/date/tomorrow.ts
49
+ var tomorrowValidator = (value, params, context) => {
50
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
51
+ const soft = params?.soft;
52
+ const message = params?.message;
53
+ const date = chunkNUW55QTO_js.parseDate(value);
54
+ if (!date) return null;
55
+ const tomorrow = /* @__PURE__ */ new Date();
56
+ tomorrow.setDate(tomorrow.getDate() + 1);
57
+ tomorrow.setHours(0, 0, 0, 0);
58
+ date.setHours(0, 0, 0, 0);
59
+ if (date.getTime() !== tomorrow.getTime()) {
60
+ return chunkNUW55QTO_js.createError(
61
+ context,
62
+ "INVALID_TOMORROW",
63
+ message || "Date must be tomorrow",
64
+ soft
65
+ );
66
+ }
67
+ return null;
68
+ };
69
+
70
+ // src/validators/date/thisWeek.ts
71
+ var thisWeekValidator = (value, params, context) => {
72
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
73
+ const soft = params?.soft;
74
+ const message = params?.message;
75
+ const date = chunkNUW55QTO_js.parseDate(value);
76
+ if (!date) return null;
77
+ const now = /* @__PURE__ */ new Date();
78
+ const startOfWeek = new Date(now);
79
+ startOfWeek.setDate(now.getDate() - now.getDay());
80
+ startOfWeek.setHours(0, 0, 0, 0);
81
+ const endOfWeek = new Date(startOfWeek);
82
+ endOfWeek.setDate(startOfWeek.getDate() + 6);
83
+ endOfWeek.setHours(23, 59, 59, 999);
84
+ if (date < startOfWeek || date > endOfWeek) {
85
+ return chunkNUW55QTO_js.createError(
86
+ context,
87
+ "INVALID_THIS_WEEK",
88
+ message || "Date must be within this week",
89
+ soft
90
+ );
91
+ }
92
+ return null;
93
+ };
94
+
95
+ // src/validators/date/thisMonth.ts
96
+ var thisMonthValidator = (value, params, context) => {
97
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
98
+ const soft = params?.soft;
99
+ const message = params?.message;
100
+ const date = chunkNUW55QTO_js.parseDate(value);
101
+ if (!date) return null;
102
+ const now = /* @__PURE__ */ new Date();
103
+ const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
104
+ const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59, 999);
105
+ if (date < startOfMonth || date > endOfMonth) {
106
+ return chunkNUW55QTO_js.createError(
107
+ context,
108
+ "INVALID_THIS_MONTH",
109
+ message || "Date must be within this month",
110
+ soft
111
+ );
112
+ }
113
+ return null;
114
+ };
115
+
116
+ // src/validators/date/thisYear.ts
117
+ var thisYearValidator = (value, params, context) => {
118
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
119
+ const soft = params?.soft;
120
+ const message = params?.message;
121
+ const date = chunkNUW55QTO_js.parseDate(value);
122
+ if (!date) return null;
123
+ const now = /* @__PURE__ */ new Date();
124
+ const startOfYear = new Date(now.getFullYear(), 0, 1);
125
+ const endOfYear = new Date(now.getFullYear(), 11, 31, 23, 59, 59, 999);
126
+ if (date < startOfYear || date > endOfYear) {
127
+ return chunkNUW55QTO_js.createError(
128
+ context,
129
+ "INVALID_THIS_YEAR",
130
+ message || "Date must be within this year",
131
+ soft
132
+ );
133
+ }
134
+ return null;
135
+ };
136
+
137
+ // src/validators/date/weekday.ts
138
+ var weekdayValidator = (value, params, context) => {
139
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
140
+ const soft = params?.soft;
141
+ const message = params?.message;
142
+ const date = chunkNUW55QTO_js.parseDate(value);
143
+ if (!date) return null;
144
+ const day = date.getDay();
145
+ if (day === 0 || day === 6) {
146
+ return chunkNUW55QTO_js.createError(
147
+ context,
148
+ "INVALID_WEEKDAY",
149
+ message || "Date must be a weekday",
150
+ soft
151
+ );
152
+ }
153
+ return null;
154
+ };
155
+
156
+ // src/validators/date/weekend.ts
157
+ var weekendValidator = (value, params, context) => {
158
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
159
+ const soft = params?.soft;
160
+ const message = params?.message;
161
+ const date = chunkNUW55QTO_js.parseDate(value);
162
+ if (!date) return null;
163
+ const day = date.getDay();
164
+ if (day !== 0 && day !== 6) {
165
+ return chunkNUW55QTO_js.createError(
166
+ context,
167
+ "INVALID_WEEKEND",
168
+ message || "Date must be a weekend",
169
+ soft
170
+ );
171
+ }
172
+ return null;
173
+ };
174
+
175
+ // src/validators/date/age.ts
176
+ var ageValidator = (value, params, context) => {
177
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
178
+ const min = params?.min;
179
+ const max = params?.max;
180
+ const soft = params?.soft;
181
+ const message = params?.message;
182
+ const birthDate = chunkNUW55QTO_js.parseDate(value);
183
+ if (!birthDate) return null;
184
+ const today = /* @__PURE__ */ new Date();
185
+ let age = today.getFullYear() - birthDate.getFullYear();
186
+ const monthDiff = today.getMonth() - birthDate.getMonth();
187
+ if (monthDiff < 0 || monthDiff === 0 && today.getDate() < birthDate.getDate()) {
188
+ age--;
189
+ }
190
+ if (min !== void 0 && age < min) {
191
+ return chunkNUW55QTO_js.createError(
192
+ context,
193
+ "INVALID_AGE_MIN",
194
+ message || `Age must be at least ${min}`,
195
+ soft
196
+ );
197
+ }
198
+ if (max !== void 0 && age > max) {
199
+ return chunkNUW55QTO_js.createError(
200
+ context,
201
+ "INVALID_AGE_MAX",
202
+ message || `Age must be at most ${max}`,
203
+ soft
204
+ );
205
+ }
206
+ return null;
207
+ };
208
+
209
+ // src/validators/date/between.ts
210
+ var betweenValidator = (value, params, context) => {
211
+ if (chunkNUW55QTO_js.isEmpty(value)) return null;
212
+ const start = params?.start;
213
+ const end = params?.end;
214
+ const soft = params?.soft;
215
+ const message = params?.message;
216
+ const date = chunkNUW55QTO_js.parseDate(value);
217
+ if (!date) return null;
218
+ const startDate = chunkNUW55QTO_js.parseDate(start);
219
+ const endDate = chunkNUW55QTO_js.parseDate(end);
220
+ if (startDate && date < startDate) {
221
+ return chunkNUW55QTO_js.createError(
222
+ context,
223
+ "INVALID_DATE_BEFORE",
224
+ message || `Date must be after ${startDate.toLocaleDateString()}`,
225
+ soft
226
+ );
227
+ }
228
+ if (endDate && date > endDate) {
229
+ return chunkNUW55QTO_js.createError(
230
+ context,
231
+ "INVALID_DATE_AFTER",
232
+ message || `Date must be before ${endDate.toLocaleDateString()}`,
233
+ soft
234
+ );
235
+ }
236
+ return null;
237
+ };
238
+
239
+ exports.ageValidator = ageValidator;
240
+ exports.betweenValidator = betweenValidator;
241
+ exports.thisMonthValidator = thisMonthValidator;
242
+ exports.thisWeekValidator = thisWeekValidator;
243
+ exports.thisYearValidator = thisYearValidator;
244
+ exports.todayValidator = todayValidator;
245
+ exports.tomorrowValidator = tomorrowValidator;
246
+ exports.weekdayValidator = weekdayValidator;
247
+ exports.weekendValidator = weekendValidator;
248
+ exports.yesterdayValidator = yesterdayValidator;
@@ -0,0 +1,85 @@
1
+ import { isEmpty, isObject, createError } from './chunk-FKDWSZIV.mjs';
2
+
3
+ // src/validators/object/keys.ts
4
+ var keysValidator = (value, params, context) => {
5
+ if (isEmpty(value)) return null;
6
+ const pattern = params?.pattern;
7
+ const soft = params?.soft;
8
+ const message = params?.message;
9
+ if (!isObject(value)) return null;
10
+ if (pattern) {
11
+ const keys = Object.keys(value);
12
+ const invalidKeys = keys.filter((key) => !pattern.test(key));
13
+ if (invalidKeys.length > 0) {
14
+ return createError(
15
+ context,
16
+ "INVALID_KEYS",
17
+ message || `Invalid keys: ${invalidKeys.join(", ")}`,
18
+ soft
19
+ );
20
+ }
21
+ }
22
+ return null;
23
+ };
24
+
25
+ // src/validators/object/pick.ts
26
+ var pickValidator = (value, params, context) => {
27
+ if (isEmpty(value)) return null;
28
+ const allowedKeys = params?.keys;
29
+ const soft = params?.soft;
30
+ const message = params?.message;
31
+ if (!isObject(value) || !allowedKeys) return null;
32
+ const keys = Object.keys(value);
33
+ const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
34
+ if (extraKeys.length > 0) {
35
+ return createError(
36
+ context,
37
+ "INVALID_PICK",
38
+ message || `Unexpected keys: ${extraKeys.join(", ")}`,
39
+ soft
40
+ );
41
+ }
42
+ return null;
43
+ };
44
+
45
+ // src/validators/object/omit.ts
46
+ var omitValidator = (value, params, context) => {
47
+ if (isEmpty(value)) return null;
48
+ const forbiddenKeys = params?.keys;
49
+ const soft = params?.soft;
50
+ const message = params?.message;
51
+ if (!isObject(value) || !forbiddenKeys) return null;
52
+ const keys = Object.keys(value);
53
+ const foundForbidden = keys.filter((key) => forbiddenKeys.includes(key));
54
+ if (foundForbidden.length > 0) {
55
+ return createError(
56
+ context,
57
+ "INVALID_OMIT",
58
+ message || `Forbidden keys found: ${foundForbidden.join(", ")}`,
59
+ soft
60
+ );
61
+ }
62
+ return null;
63
+ };
64
+
65
+ // src/validators/object/strict.ts
66
+ var strictValidator = (value, params, context) => {
67
+ if (isEmpty(value)) return null;
68
+ const allowedKeys = params?.allowedKeys;
69
+ const soft = params?.soft;
70
+ const message = params?.message;
71
+ if (!isObject(value) || !allowedKeys) return null;
72
+ const keys = Object.keys(value);
73
+ const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
74
+ if (extraKeys.length > 0) {
75
+ return createError(
76
+ context,
77
+ "INVALID_STRICT",
78
+ message || `Unknown keys not allowed: ${extraKeys.join(", ")}`,
79
+ soft
80
+ );
81
+ }
82
+ return null;
83
+ };
84
+
85
+ export { keysValidator, omitValidator, pickValidator, strictValidator };
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ // src/validators/utils.ts
4
+ function createError(context, code, message, soft = false) {
5
+ return {
6
+ field: context.path,
7
+ code,
8
+ message,
9
+ severity: soft ? "soft" : "hard"
10
+ };
11
+ }
12
+ function isEmpty(value) {
13
+ return value === void 0 || value === null || value === "";
14
+ }
15
+ function isString(value) {
16
+ return typeof value === "string";
17
+ }
18
+ function isNumber(value) {
19
+ return typeof value === "number" && !isNaN(value);
20
+ }
21
+ function isDate(value) {
22
+ return value instanceof Date && !isNaN(value.getTime());
23
+ }
24
+ function parseDate(value) {
25
+ if (value instanceof Date) {
26
+ return isNaN(value.getTime()) ? null : value;
27
+ }
28
+ if (typeof value === "string") {
29
+ const parsed = new Date(value);
30
+ return isNaN(parsed.getTime()) ? null : parsed;
31
+ }
32
+ return null;
33
+ }
34
+ function isArray(value) {
35
+ return Array.isArray(value);
36
+ }
37
+ function isObject(value) {
38
+ return typeof value === "object" && value !== null && !Array.isArray(value);
39
+ }
40
+
41
+ exports.createError = createError;
42
+ exports.isArray = isArray;
43
+ exports.isDate = isDate;
44
+ exports.isEmpty = isEmpty;
45
+ exports.isNumber = isNumber;
46
+ exports.isObject = isObject;
47
+ exports.isString = isString;
48
+ exports.parseDate = parseDate;