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
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { isEmpty, isString, createError } from './chunk-KZZ7NVU3.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 };
|