@forklaunch/validator 0.3.0 → 0.3.2

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/lib/eslint.config.d.mts +3 -0
  3. package/lib/eslint.config.d.mts.map +1 -0
  4. package/lib/eslint.config.mjs +10 -0
  5. package/lib/index.d.ts +2 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +1 -0
  8. package/lib/jest.config.d.ts +4 -0
  9. package/lib/jest.config.d.ts.map +1 -0
  10. package/lib/jest.config.js +21 -0
  11. package/{dist → lib/src/shared}/types/schema.types.d.ts +47 -7
  12. package/lib/src/shared/types/schema.types.d.ts.map +1 -0
  13. package/lib/src/typebox/index.d.ts +3 -0
  14. package/lib/src/typebox/index.d.ts.map +1 -0
  15. package/lib/src/typebox/index.js +1 -0
  16. package/lib/src/typebox/staticSchemaValidator.d.ts +93 -0
  17. package/lib/src/typebox/staticSchemaValidator.d.ts.map +1 -0
  18. package/lib/src/typebox/staticSchemaValidator.js +91 -0
  19. package/lib/src/typebox/typeboxSchemaValidator.d.ts +110 -0
  20. package/lib/src/typebox/typeboxSchemaValidator.d.ts.map +1 -0
  21. package/lib/src/typebox/typeboxSchemaValidator.js +343 -0
  22. package/{dist/typebox/types/typebox.schema.types.d.ts → lib/src/typebox/types/schema.types.d.ts} +9 -13
  23. package/lib/src/typebox/types/schema.types.d.ts.map +1 -0
  24. package/lib/src/zod/index.d.ts +3 -0
  25. package/lib/src/zod/index.d.ts.map +1 -0
  26. package/lib/src/zod/index.js +1 -0
  27. package/lib/src/zod/staticSchemaValidator.d.ts +93 -0
  28. package/lib/src/zod/staticSchemaValidator.d.ts.map +1 -0
  29. package/lib/src/zod/staticSchemaValidator.js +91 -0
  30. package/{dist/zod/types/zod.schema.types.d.ts → lib/src/zod/types/schema.types.d.ts} +3 -2
  31. package/lib/src/zod/types/schema.types.d.ts.map +1 -0
  32. package/lib/src/zod/types/schema.types.js +1 -0
  33. package/lib/src/zod/zodSchemaValidator.d.ts +98 -0
  34. package/lib/src/zod/zodSchemaValidator.d.ts.map +1 -0
  35. package/lib/src/zod/zodSchemaValidator.js +179 -0
  36. package/lib/tests/typebox/advancedParse.test.d.ts +2 -0
  37. package/lib/tests/typebox/advancedParse.test.d.ts.map +1 -0
  38. package/lib/tests/typebox/advancedParse.test.js +514 -0
  39. package/lib/tests/typebox/largeSchema.test.d.ts +2 -0
  40. package/lib/tests/typebox/largeSchema.test.d.ts.map +1 -0
  41. package/{dist → lib}/tests/typebox/largeSchema.test.js +46 -49
  42. package/lib/tests/typebox/schemaValidator.test.d.ts +2 -0
  43. package/lib/tests/typebox/schemaValidator.test.d.ts.map +1 -0
  44. package/lib/tests/typebox/schemaValidator.test.js +219 -0
  45. package/{dist/tests/typebox/equality.test.d.ts → lib/tests/typebox/typeEquality.test.d.ts} +1 -0
  46. package/lib/tests/typebox/typeEquality.test.d.ts.map +1 -0
  47. package/lib/tests/typebox/typeEquality.test.js +100 -0
  48. package/lib/tests/utils/compare.d.ts +2 -0
  49. package/lib/tests/utils/compare.d.ts.map +1 -0
  50. package/lib/tests/utils/compare.js +8 -0
  51. package/{dist/tests → lib/tests/utils}/mockSchemaValidator.d.ts +14 -8
  52. package/lib/tests/utils/mockSchemaValidator.d.ts.map +1 -0
  53. package/lib/tests/utils/mockSchemaValidator.js +72 -0
  54. package/lib/tests/zod/advancedParse.test.d.ts +2 -0
  55. package/lib/tests/zod/advancedParse.test.d.ts.map +1 -0
  56. package/lib/tests/zod/advancedParse.test.js +514 -0
  57. package/lib/tests/zod/largeSchema.test.d.ts +2 -0
  58. package/lib/tests/zod/largeSchema.test.d.ts.map +1 -0
  59. package/{dist → lib}/tests/zod/largeSchema.test.js +43 -46
  60. package/lib/tests/zod/schemaValidator.test.d.ts +2 -0
  61. package/lib/tests/zod/schemaValidator.test.d.ts.map +1 -0
  62. package/lib/tests/zod/schemaValidator.test.js +179 -0
  63. package/{dist/tests/zod/equality.test.d.ts → lib/tests/zod/typeEquality.test.d.ts} +1 -0
  64. package/lib/tests/zod/typeEquality.test.d.ts.map +1 -0
  65. package/lib/tests/zod/typeEquality.test.js +100 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -0
  67. package/lib/vitest.config.d.ts +3 -0
  68. package/lib/vitest.config.d.ts.map +1 -0
  69. package/lib/vitest.config.js +7 -0
  70. package/package.json +35 -39
  71. package/dist/index.d.ts +0 -1
  72. package/dist/index.js +0 -18
  73. package/dist/index.js.map +0 -1
  74. package/dist/jest.config.d.ts +0 -3
  75. package/dist/jest.config.js +0 -10
  76. package/dist/jest.config.js.map +0 -1
  77. package/dist/tests/mockSchemaValidator.js +0 -60
  78. package/dist/tests/mockSchemaValidator.js.map +0 -1
  79. package/dist/tests/typebox/equality.test.js +0 -234
  80. package/dist/tests/typebox/equality.test.js.map +0 -1
  81. package/dist/tests/typebox/largeSchema.test.js.map +0 -1
  82. package/dist/tests/zod/equality.test.js +0 -238
  83. package/dist/tests/zod/equality.test.js.map +0 -1
  84. package/dist/tests/zod/largeSchema.test.js.map +0 -1
  85. package/dist/typebox/index.d.ts +0 -1
  86. package/dist/typebox/index.js +0 -18
  87. package/dist/typebox/index.js.map +0 -1
  88. package/dist/typebox/typebox.schemaValidator.d.ts +0 -150
  89. package/dist/typebox/typebox.schemaValidator.js +0 -203
  90. package/dist/typebox/typebox.schemaValidator.js.map +0 -1
  91. package/dist/typebox/types/typebox.schema.types.js +0 -3
  92. package/dist/typebox/types/typebox.schema.types.js.map +0 -1
  93. package/dist/types/index.d.ts +0 -1
  94. package/dist/types/index.js +0 -18
  95. package/dist/types/index.js.map +0 -1
  96. package/dist/types/schema.types.js +0 -3
  97. package/dist/types/schema.types.js.map +0 -1
  98. package/dist/zod/index.d.ts +0 -1
  99. package/dist/zod/index.js +0 -18
  100. package/dist/zod/index.js.map +0 -1
  101. package/dist/zod/types/zod.schema.types.js +0 -3
  102. package/dist/zod/types/zod.schema.types.js.map +0 -1
  103. package/dist/zod/zod.schemaValidator.d.ts +0 -147
  104. package/dist/zod/zod.schemaValidator.js +0 -196
  105. package/dist/zod/zod.schemaValidator.js.map +0 -1
  106. /package/{dist/tests/typebox/largeSchema.test.d.ts → lib/src/shared/types/schema.types.js} +0 -0
  107. /package/{dist/tests/zod/largeSchema.test.d.ts → lib/src/typebox/types/schema.types.js} +0 -0
@@ -0,0 +1,514 @@
1
+ import { any, bigint, boolean, date, email, never, nullish, number, SchemaValidator, string, symbol, unknown, uri, uuid } from '../../src/typebox';
2
+ import { compare } from '../utils/compare';
3
+ describe('typebox advanced parse', () => {
4
+ const schemaValidator = SchemaValidator();
5
+ describe('string', () => {
6
+ test('valid string', () => {
7
+ compare(schemaValidator.parse(string, 'hello'), {
8
+ ok: true,
9
+ value: 'hello'
10
+ });
11
+ });
12
+ test('invalid string with number', () => {
13
+ expect(schemaValidator.parse(string, 123).ok).toBe(false);
14
+ });
15
+ test('invalid string with boolean', () => {
16
+ expect(schemaValidator.parse(string, true).ok).toBe(false);
17
+ });
18
+ test('invalid string with object', () => {
19
+ expect(schemaValidator.parse(string, { hello: 'world' }).ok).toBe(false);
20
+ });
21
+ test('invalid string with array', () => {
22
+ expect(schemaValidator.parse(string, ['hello', 'world']).ok).toBe(false);
23
+ });
24
+ test('invalid string with null', () => {
25
+ expect(schemaValidator.parse(string, null).ok).toBe(false);
26
+ });
27
+ test('invalid string with undefined', () => {
28
+ expect(schemaValidator.parse(string, undefined).ok).toBe(false);
29
+ });
30
+ test('invalid string with symbol', () => {
31
+ expect(schemaValidator.parse(string, Symbol('hello')).ok).toBe(false);
32
+ });
33
+ test('invalid string with bigint', () => {
34
+ expect(schemaValidator.parse(string, BigInt(123)).ok).toBe(false);
35
+ });
36
+ test('invalid string with date', () => {
37
+ expect(schemaValidator.parse(string, new Date()).ok).toBe(false);
38
+ });
39
+ });
40
+ describe('uuid', () => {
41
+ test('valid uuid', () => {
42
+ compare(schemaValidator.parse(uuid, 'f651c6c5-f628-48de-904c-f37509a97ab6'), {
43
+ ok: true,
44
+ value: 'f651c6c5-f628-48de-904c-f37509a97ab6'
45
+ });
46
+ });
47
+ test('invalid uuid', () => {
48
+ expect(schemaValidator.parse(uuid, 'hello').ok).toBe(false);
49
+ });
50
+ });
51
+ describe('uri', () => {
52
+ test('valid uri', () => {
53
+ compare(schemaValidator.parse(uri, 'https://forklaunch.com'), {
54
+ ok: true,
55
+ value: 'https://forklaunch.com'
56
+ });
57
+ });
58
+ test('invalid uri', () => {
59
+ expect(schemaValidator.parse(uri, 'hello').ok).toBe(false);
60
+ });
61
+ });
62
+ describe('email', () => {
63
+ test('valid email', () => {
64
+ compare(schemaValidator.parse(email, 'test@forklaunch.com'), {
65
+ ok: true,
66
+ value: 'test@forklaunch.com'
67
+ });
68
+ });
69
+ test('invalid email', () => {
70
+ expect(schemaValidator.parse(email, 'hello').ok).toBe(false);
71
+ });
72
+ });
73
+ describe('number', () => {
74
+ test('valid number', () => {
75
+ compare(schemaValidator.parse(number, 123), {
76
+ ok: true,
77
+ value: 123
78
+ });
79
+ });
80
+ test('valid number with numeric string', () => {
81
+ compare(schemaValidator.parse(number, 123), {
82
+ ok: true,
83
+ value: 123
84
+ });
85
+ });
86
+ test('valid number with boolean', () => {
87
+ compare(schemaValidator.parse(number, true), {
88
+ ok: true,
89
+ value: 1
90
+ });
91
+ });
92
+ test('valid number with null', () => {
93
+ compare(schemaValidator.parse(number, null), {
94
+ ok: true,
95
+ value: 0
96
+ });
97
+ });
98
+ test('valid number with date', () => {
99
+ compare(schemaValidator.parse(number, new Date(0)), {
100
+ ok: true,
101
+ value: 0
102
+ });
103
+ });
104
+ test('valid number with bigint', () => {
105
+ compare(schemaValidator.parse(number, BigInt(123)), {
106
+ ok: true,
107
+ value: 123
108
+ });
109
+ });
110
+ test('invalid number with string', () => {
111
+ expect(schemaValidator.parse(number, 'hello').ok).toBe(false);
112
+ });
113
+ test('invalid number with object', () => {
114
+ expect(schemaValidator.parse(number, { hello: 'world' }).ok).toBe(false);
115
+ });
116
+ test('invalid number with array', () => {
117
+ expect(schemaValidator.parse(number, ['hello', 'world']).ok).toBe(false);
118
+ });
119
+ test('invalid number with undefined', () => {
120
+ expect(schemaValidator.parse(number, undefined).ok).toBe(false);
121
+ });
122
+ test('invalid number with symbol', () => {
123
+ expect(schemaValidator.parse(number, Symbol('hello')).ok).toBe(false);
124
+ });
125
+ });
126
+ describe('bigint', () => {
127
+ test('valid bigint', () => {
128
+ const parsed = schemaValidator.parse(bigint, BigInt('12345678901234567890'));
129
+ if (parsed.ok) {
130
+ compare(parsed.value, BigInt('12345678901234567890'));
131
+ }
132
+ else {
133
+ fail();
134
+ }
135
+ });
136
+ test('valid bigint with number', () => {
137
+ const parsed = schemaValidator.parse(bigint, 123123);
138
+ if (parsed.ok) {
139
+ compare(parsed.value, BigInt(123123));
140
+ }
141
+ else {
142
+ fail();
143
+ }
144
+ });
145
+ test('valid bigint with boolean', () => {
146
+ const parsed = schemaValidator.parse(bigint, true);
147
+ if (parsed.ok) {
148
+ compare(parsed.value, BigInt(1));
149
+ }
150
+ else {
151
+ fail();
152
+ }
153
+ });
154
+ test('valid bigint with date', () => {
155
+ const parsed = schemaValidator.parse(bigint, new Date(0));
156
+ if (parsed.ok) {
157
+ compare(parsed.value, BigInt(0));
158
+ }
159
+ else {
160
+ fail();
161
+ }
162
+ });
163
+ test('invalid bigint with string', () => {
164
+ expect(schemaValidator.parse(bigint, 'hello').ok).toBe(false);
165
+ });
166
+ test('invalid bigint with object', () => {
167
+ expect(schemaValidator.parse(bigint, { hello: 'world' }).ok).toBe(false);
168
+ });
169
+ test('invalid bigint with array', () => {
170
+ expect(schemaValidator.parse(bigint, ['hello', 'world']).ok).toBe(false);
171
+ });
172
+ test('invalid bigint with null', () => {
173
+ expect(schemaValidator.parse(bigint, null).ok).toBe(false);
174
+ });
175
+ test('invalid bigint with undefined', () => {
176
+ expect(schemaValidator.parse(bigint, undefined).ok).toBe(false);
177
+ });
178
+ test('invalid bigint with symbol', () => {
179
+ expect(schemaValidator.parse(bigint, Symbol('hello')).ok).toBe(false);
180
+ });
181
+ });
182
+ describe('boolean', () => {
183
+ test('valid boolean', () => {
184
+ compare(schemaValidator.parse(boolean, true), {
185
+ ok: true,
186
+ value: true
187
+ });
188
+ });
189
+ test('valid boolean with boolean string', () => {
190
+ compare(schemaValidator.parse(boolean, 'true'), {
191
+ ok: true,
192
+ value: true
193
+ });
194
+ });
195
+ test('invalid boolean with string', () => {
196
+ expect(schemaValidator.parse(boolean, 'hello').ok).toBe(false);
197
+ });
198
+ test('invalid boolean with number', () => {
199
+ expect(schemaValidator.parse(boolean, 123).ok).toBe(false);
200
+ });
201
+ test('invalid boolean with object', () => {
202
+ expect(schemaValidator.parse(boolean, { hello: 'world' }).ok).toBe(false);
203
+ });
204
+ test('invalid boolean with array', () => {
205
+ expect(schemaValidator.parse(boolean, ['hello', 'world']).ok).toBe(false);
206
+ });
207
+ test('invalid boolean with null', () => {
208
+ expect(schemaValidator.parse(boolean, null).ok).toBe(false);
209
+ });
210
+ test('invalid boolean with undefined', () => {
211
+ expect(schemaValidator.parse(boolean, undefined).ok).toBe(false);
212
+ });
213
+ test('invalid boolean with symbol', () => {
214
+ expect(schemaValidator.parse(boolean, Symbol('hello')).ok).toBe(false);
215
+ });
216
+ test('invalid boolean with bigint', () => {
217
+ expect(schemaValidator.parse(boolean, BigInt(123)).ok).toBe(false);
218
+ });
219
+ test('invalid boolean with date', () => {
220
+ expect(schemaValidator.parse(boolean, new Date()).ok).toBe(false);
221
+ });
222
+ });
223
+ describe('date', () => {
224
+ test('valid date', () => {
225
+ const dateTest = new Date();
226
+ compare(schemaValidator.parse(date, dateTest), {
227
+ ok: true,
228
+ value: dateTest
229
+ });
230
+ });
231
+ test('valid date with datestring', () => {
232
+ compare(schemaValidator.parse(date, '2021-01-01'), {
233
+ ok: true,
234
+ value: new Date('2021-01-01')
235
+ });
236
+ });
237
+ test('valid date with number', () => {
238
+ compare(schemaValidator.parse(date, 123), {
239
+ ok: true,
240
+ value: new Date(123)
241
+ });
242
+ });
243
+ test('valid date with boolean', () => {
244
+ compare(schemaValidator.parse(date, true), {
245
+ ok: true,
246
+ value: new Date(1)
247
+ });
248
+ });
249
+ test('valid date with null', () => {
250
+ compare(schemaValidator.parse(date, null), {
251
+ ok: true,
252
+ value: new Date(0)
253
+ });
254
+ });
255
+ test('invalid date with string', () => {
256
+ expect(schemaValidator.parse(date, 'hello').ok).toBe(false);
257
+ });
258
+ test('invalid date with object', () => {
259
+ expect(schemaValidator.parse(date, { hello: 'world' }).ok).toBe(false);
260
+ });
261
+ test('invalid date with array', () => {
262
+ expect(schemaValidator.parse(date, ['hello', 'world']).ok).toBe(false);
263
+ });
264
+ test('invalid date with undefined', () => {
265
+ expect(schemaValidator.parse(date, undefined).ok).toBe(false);
266
+ });
267
+ test('invalid date with symbol', () => {
268
+ expect(schemaValidator.parse(date, Symbol('hello')).ok).toBe(false);
269
+ });
270
+ test('invalid date with bigint', () => {
271
+ expect(schemaValidator.parse(date, BigInt(123)).ok).toBe(false);
272
+ });
273
+ });
274
+ describe('symbol', () => {
275
+ test('valid symbol', () => {
276
+ const symbolTest = Symbol('hello');
277
+ compare(schemaValidator.parse(symbol, symbolTest), {
278
+ ok: true,
279
+ value: symbolTest
280
+ });
281
+ });
282
+ test('invalid symbol with string', () => {
283
+ expect(schemaValidator.parse(symbol, 'hello').ok).toBe(false);
284
+ });
285
+ test('invalid symbol with number', () => {
286
+ expect(schemaValidator.parse(symbol, 123).ok).toBe(false);
287
+ });
288
+ test('invalid symbol with boolean', () => {
289
+ expect(schemaValidator.parse(symbol, true).ok).toBe(false);
290
+ });
291
+ test('invalid symbol with object', () => {
292
+ expect(schemaValidator.parse(symbol, { hello: 'world' }).ok).toBe(false);
293
+ });
294
+ test('invalid symbol with array', () => {
295
+ expect(schemaValidator.parse(symbol, ['hello', 'world']).ok).toBe(false);
296
+ });
297
+ test('invalid symbol with null', () => {
298
+ expect(schemaValidator.parse(symbol, null).ok).toBe(false);
299
+ });
300
+ test('invalid symbol with undefined', () => {
301
+ expect(schemaValidator.parse(symbol, undefined).ok).toBe(false);
302
+ });
303
+ test('invalid symbol with bigint', () => {
304
+ expect(schemaValidator.parse(symbol, BigInt(123)).ok).toBe(false);
305
+ });
306
+ test('invalid symbol with date', () => {
307
+ expect(schemaValidator.parse(symbol, new Date()).ok).toBe(false);
308
+ });
309
+ });
310
+ describe('nullish', () => {
311
+ test('valid nullish with null', () => {
312
+ compare(schemaValidator.parse(nullish, null), {
313
+ ok: true,
314
+ value: null
315
+ });
316
+ });
317
+ test('valid nullish with undefined', () => {
318
+ compare(schemaValidator.parse(nullish, undefined), {
319
+ ok: true,
320
+ value: undefined
321
+ });
322
+ });
323
+ test('invalid nullish with string', () => {
324
+ expect(schemaValidator.parse(nullish, 'hello').ok).toBe(false);
325
+ });
326
+ test('invalid nullish with number', () => {
327
+ expect(schemaValidator.parse(nullish, 123).ok).toBe(false);
328
+ });
329
+ test('invalid nullish with boolean', () => {
330
+ expect(schemaValidator.parse(nullish, true).ok).toBe(false);
331
+ });
332
+ test('invalid nullish with object', () => {
333
+ expect(schemaValidator.parse(nullish, { hello: 'world' }).ok).toBe(false);
334
+ });
335
+ test('invalid nullish with array', () => {
336
+ expect(schemaValidator.parse(nullish, ['hello', 'world']).ok).toBe(false);
337
+ });
338
+ test('invalid nullish with symbol', () => {
339
+ expect(schemaValidator.parse(nullish, Symbol('hello')).ok).toBe(false);
340
+ });
341
+ test('invalid nullish with bigint', () => {
342
+ expect(schemaValidator.parse(nullish, BigInt(123)).ok).toBe(false);
343
+ });
344
+ test('invalid nullish with date', () => {
345
+ expect(schemaValidator.parse(nullish, new Date()).ok).toBe(false);
346
+ });
347
+ });
348
+ describe('any', () => {
349
+ test('valid any with string', () => {
350
+ compare(schemaValidator.parse(any, 'hello'), {
351
+ ok: true,
352
+ value: 'hello'
353
+ });
354
+ });
355
+ test('valid any with number', () => {
356
+ compare(schemaValidator.parse(any, 123), {
357
+ ok: true,
358
+ value: 123
359
+ });
360
+ });
361
+ test('valid any with boolean', () => {
362
+ compare(schemaValidator.parse(any, true), {
363
+ ok: true,
364
+ value: true
365
+ });
366
+ });
367
+ test('valid any with object', () => {
368
+ compare(schemaValidator.parse(any, { hello: 'world' }), {
369
+ ok: true,
370
+ value: { hello: 'world' }
371
+ });
372
+ });
373
+ test('valid any with array', () => {
374
+ compare(schemaValidator.parse(any, ['hello', 'world']), {
375
+ ok: true,
376
+ value: ['hello', 'world']
377
+ });
378
+ });
379
+ test('valid any with null', () => {
380
+ compare(schemaValidator.parse(any, null), {
381
+ ok: true,
382
+ value: null
383
+ });
384
+ });
385
+ test('valid any with undefined', () => {
386
+ compare(schemaValidator.parse(any, undefined), {
387
+ ok: true,
388
+ value: undefined
389
+ });
390
+ });
391
+ test('valid any with symbol', () => {
392
+ const symbolTest = Symbol('hello');
393
+ compare(schemaValidator.parse(any, symbolTest), {
394
+ ok: true,
395
+ value: symbolTest
396
+ });
397
+ });
398
+ test('valid any with bigint', () => {
399
+ const parsed = schemaValidator.parse(any, BigInt(123));
400
+ if (parsed.ok) {
401
+ compare(parsed.value, BigInt(123));
402
+ }
403
+ else {
404
+ fail();
405
+ }
406
+ });
407
+ test('valid any with date', () => {
408
+ const dateTest = new Date();
409
+ compare(schemaValidator.parse(any, dateTest), {
410
+ ok: true,
411
+ value: dateTest
412
+ });
413
+ });
414
+ });
415
+ describe('unknown', () => {
416
+ test('valid unknown with string', () => {
417
+ compare(schemaValidator.parse(unknown, 'hello'), {
418
+ ok: true,
419
+ value: 'hello'
420
+ });
421
+ });
422
+ test('valid unknown with number', () => {
423
+ compare(schemaValidator.parse(unknown, 123), {
424
+ ok: true,
425
+ value: 123
426
+ });
427
+ });
428
+ test('valid unknown with boolean', () => {
429
+ compare(schemaValidator.parse(unknown, true), {
430
+ ok: true,
431
+ value: true
432
+ });
433
+ });
434
+ test('valid unknown with object', () => {
435
+ compare(schemaValidator.parse(unknown, { hello: 'world' }), {
436
+ ok: true,
437
+ value: { hello: 'world' }
438
+ });
439
+ });
440
+ test('valid unknown with array', () => {
441
+ compare(schemaValidator.parse(unknown, ['hello', 'world']), {
442
+ ok: true,
443
+ value: ['hello', 'world']
444
+ });
445
+ });
446
+ test('valid unknown with null', () => {
447
+ compare(schemaValidator.parse(unknown, null), {
448
+ ok: true,
449
+ value: null
450
+ });
451
+ });
452
+ test('valid unknown with undefined', () => {
453
+ compare(schemaValidator.parse(unknown, undefined), {
454
+ ok: true,
455
+ value: undefined
456
+ });
457
+ });
458
+ test('valid unknown with symbol', () => {
459
+ const symbolTest = Symbol('hello');
460
+ compare(schemaValidator.parse(unknown, symbolTest), {
461
+ ok: true,
462
+ value: symbolTest
463
+ });
464
+ });
465
+ test('valid unknown with bigint', () => {
466
+ const parsed = schemaValidator.parse(unknown, BigInt(123));
467
+ if (parsed.ok) {
468
+ compare(parsed.value, BigInt(123));
469
+ }
470
+ else {
471
+ fail();
472
+ }
473
+ });
474
+ test('valid unknown with date', () => {
475
+ const dateTest = new Date();
476
+ compare(schemaValidator.parse(unknown, dateTest), {
477
+ ok: true,
478
+ value: dateTest
479
+ });
480
+ });
481
+ });
482
+ describe('never', () => {
483
+ test('invalid never with string', () => {
484
+ expect(schemaValidator.parse(never, 'hello').ok).toBe(false);
485
+ });
486
+ test('invalid never with number', () => {
487
+ expect(schemaValidator.parse(never, 123).ok).toBe(false);
488
+ });
489
+ test('invalid never with boolean', () => {
490
+ expect(schemaValidator.parse(never, true).ok).toBe(false);
491
+ });
492
+ test('invalid never with object', () => {
493
+ expect(schemaValidator.parse(never, { hello: 'world' }).ok).toBe(false);
494
+ });
495
+ test('invalid never with array', () => {
496
+ expect(schemaValidator.parse(never, ['hello', 'world']).ok).toBe(false);
497
+ });
498
+ test('invalid never with null', () => {
499
+ expect(schemaValidator.parse(never, null).ok).toBe(false);
500
+ });
501
+ test('invalid never with undefined', () => {
502
+ expect(schemaValidator.parse(never, undefined).ok).toBe(false);
503
+ });
504
+ test('invalid never with symbol', () => {
505
+ expect(schemaValidator.parse(never, Symbol('hello')).ok).toBe(false);
506
+ });
507
+ test('invalid never with bigint', () => {
508
+ expect(schemaValidator.parse(never, BigInt(123)).ok).toBe(false);
509
+ });
510
+ test('invalid never with date', () => {
511
+ expect(schemaValidator.parse(never, new Date()).ok).toBe(false);
512
+ });
513
+ });
514
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=largeSchema.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"largeSchema.test.d.ts","sourceRoot":"","sources":["../../../tests/typebox/largeSchema.test.ts"],"names":[],"mappings":""}
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const typebox_schemaValidator_1 = require("../../typebox/typebox.schemaValidator");
4
- describe('Typebox Large Schema Tests', () => {
5
- it('Deep Union', () => {
1
+ import { array, bigint, boolean, date, never, nullish, number, optional, string, symbol, union } from '../../src/typebox/staticSchemaValidator';
2
+ describe('typebox large schema tests', () => {
3
+ it('deep union', () => {
6
4
  const deepOne = {
7
5
  s: {
8
6
  s: {
@@ -36,7 +34,7 @@ describe('Typebox Large Schema Tests', () => {
36
34
  };
37
35
  const deepTwo = {
38
36
  k: {
39
- o: typebox_schemaValidator_1.number,
37
+ o: number,
40
38
  s: {
41
39
  s: {
42
40
  s: {
@@ -50,7 +48,7 @@ describe('Typebox Large Schema Tests', () => {
50
48
  s: {
51
49
  s: {
52
50
  s: {
53
- b: typebox_schemaValidator_1.string
51
+ b: string
54
52
  }
55
53
  }
56
54
  }
@@ -66,47 +64,47 @@ describe('Typebox Large Schema Tests', () => {
66
64
  }
67
65
  }
68
66
  };
69
- const deepUnion = (0, typebox_schemaValidator_1.union)([deepOne, deepTwo]);
67
+ const deepUnion = union([deepOne, deepTwo]);
70
68
  });
71
- it('Realistic Schema', () => {
72
- const realistic = (0, typebox_schemaValidator_1.array)({
69
+ it('realistic schema', () => {
70
+ const realistic = array({
73
71
  level1: {
74
72
  name: {
75
- j: (0, typebox_schemaValidator_1.union)([
76
- typebox_schemaValidator_1.string,
77
- typebox_schemaValidator_1.number,
78
- typebox_schemaValidator_1.date,
79
- typebox_schemaValidator_1.boolean,
80
- typebox_schemaValidator_1.bigint,
81
- typebox_schemaValidator_1.empty,
82
- typebox_schemaValidator_1.symbol,
83
- typebox_schemaValidator_1.never
73
+ j: union([
74
+ string,
75
+ number,
76
+ date,
77
+ boolean,
78
+ bigint,
79
+ nullish,
80
+ symbol,
81
+ never
84
82
  ]),
85
- t: (0, typebox_schemaValidator_1.optional)((0, typebox_schemaValidator_1.union)([
86
- (0, typebox_schemaValidator_1.array)({
87
- y: (0, typebox_schemaValidator_1.array)(typebox_schemaValidator_1.number)
83
+ t: optional(union([
84
+ array({
85
+ y: array(number)
88
86
  }),
89
- typebox_schemaValidator_1.string
87
+ string
90
88
  ])),
91
89
  m: {
92
- a: (0, typebox_schemaValidator_1.optional)(typebox_schemaValidator_1.string),
93
- b: typebox_schemaValidator_1.number,
90
+ a: optional(string),
91
+ b: number,
94
92
  c: {
95
- d: typebox_schemaValidator_1.string,
96
- e: typebox_schemaValidator_1.number,
93
+ d: string,
94
+ e: number,
97
95
  f: {
98
- g: typebox_schemaValidator_1.string,
99
- h: typebox_schemaValidator_1.number,
96
+ g: string,
97
+ h: number,
100
98
  i: {
101
- j: typebox_schemaValidator_1.string,
102
- k: typebox_schemaValidator_1.number,
99
+ j: string,
100
+ k: number,
103
101
  l: {
104
- m: typebox_schemaValidator_1.boolean,
105
- n: (0, typebox_schemaValidator_1.array)(typebox_schemaValidator_1.string),
106
- o: (0, typebox_schemaValidator_1.optional)((0, typebox_schemaValidator_1.union)([typebox_schemaValidator_1.string, typebox_schemaValidator_1.number])),
102
+ m: boolean,
103
+ n: array(string),
104
+ o: optional(union([string, number])),
107
105
  p: {
108
- q: typebox_schemaValidator_1.string,
109
- r: typebox_schemaValidator_1.number
106
+ q: string,
107
+ r: number
110
108
  }
111
109
  }
112
110
  }
@@ -115,32 +113,32 @@ describe('Typebox Large Schema Tests', () => {
115
113
  }
116
114
  },
117
115
  additionalField1: {
118
- a: (0, typebox_schemaValidator_1.union)([typebox_schemaValidator_1.string, typebox_schemaValidator_1.boolean, typebox_schemaValidator_1.bigint, typebox_schemaValidator_1.empty]),
119
- b: (0, typebox_schemaValidator_1.optional)((0, typebox_schemaValidator_1.array)(typebox_schemaValidator_1.number)),
116
+ a: union([string, boolean, bigint, nullish]),
117
+ b: optional(array(number)),
120
118
  c: {
121
- d: typebox_schemaValidator_1.string,
122
- e: typebox_schemaValidator_1.number,
119
+ d: string,
120
+ e: number,
123
121
  f: {
124
- g: typebox_schemaValidator_1.string,
125
- h: typebox_schemaValidator_1.number
122
+ g: string,
123
+ h: number
126
124
  }
127
125
  }
128
126
  },
129
127
  additionalField2: {
130
- x: typebox_schemaValidator_1.string,
131
- y: (0, typebox_schemaValidator_1.union)([typebox_schemaValidator_1.string, (0, typebox_schemaValidator_1.array)(typebox_schemaValidator_1.boolean)]),
128
+ x: string,
129
+ y: union([string, array(boolean)]),
132
130
  z: {
133
- a: typebox_schemaValidator_1.string,
134
- b: typebox_schemaValidator_1.number
131
+ a: string,
132
+ b: number
135
133
  }
136
134
  }
137
135
  },
138
136
  code: {
139
137
  200: {
140
- j: typebox_schemaValidator_1.string
138
+ j: string
141
139
  },
142
140
  404: {
143
- k: typebox_schemaValidator_1.string
141
+ k: string
144
142
  }
145
143
  },
146
144
  flag: {
@@ -150,4 +148,3 @@ describe('Typebox Large Schema Tests', () => {
150
148
  });
151
149
  });
152
150
  });
153
- //# sourceMappingURL=largeSchema.test.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schemaValidator.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaValidator.test.d.ts","sourceRoot":"","sources":["../../../tests/typebox/schemaValidator.test.ts"],"names":[],"mappings":""}