@forklaunch/validator 0.3.12 → 0.4.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 (75) hide show
  1. package/lib/index-V6qNDTlr.d.mts +476 -0
  2. package/lib/index-V6qNDTlr.d.ts +476 -0
  3. package/lib/index.d.mts +6 -0
  4. package/lib/index.d.ts +6 -2
  5. package/lib/index.js +18 -1
  6. package/lib/index.mjs +0 -0
  7. package/lib/src/typebox/index.d.mts +220 -0
  8. package/lib/src/typebox/index.d.ts +220 -3
  9. package/lib/src/typebox/index.js +448 -1
  10. package/lib/src/typebox/index.mjs +406 -0
  11. package/lib/src/zod/index.d.mts +106 -0
  12. package/lib/src/zod/index.d.ts +106 -3
  13. package/lib/src/zod/index.js +291 -1
  14. package/lib/src/zod/index.mjs +244 -0
  15. package/lib/tests/utils/mockSchemaValidator.d.mts +69 -0
  16. package/lib/tests/utils/mockSchemaValidator.d.ts +29 -25
  17. package/lib/tests/utils/mockSchemaValidator.js +143 -79
  18. package/lib/tests/utils/mockSchemaValidator.mjs +99 -0
  19. package/package.json +21 -8
  20. package/lib/index.d.ts.map +0 -1
  21. package/lib/src/shared/types/schema.types.d.ts +0 -255
  22. package/lib/src/shared/types/schema.types.d.ts.map +0 -1
  23. package/lib/src/shared/types/schema.types.js +0 -1
  24. package/lib/src/typebox/index.d.ts.map +0 -1
  25. package/lib/src/typebox/staticSchemaValidator.d.ts +0 -99
  26. package/lib/src/typebox/staticSchemaValidator.d.ts.map +0 -1
  27. package/lib/src/typebox/staticSchemaValidator.js +0 -99
  28. package/lib/src/typebox/typeboxSchemaValidator.d.ts +0 -122
  29. package/lib/src/typebox/typeboxSchemaValidator.d.ts.map +0 -1
  30. package/lib/src/typebox/typeboxSchemaValidator.js +0 -362
  31. package/lib/src/typebox/types/schema.types.d.ts +0 -59
  32. package/lib/src/typebox/types/schema.types.d.ts.map +0 -1
  33. package/lib/src/typebox/types/schema.types.js +0 -1
  34. package/lib/src/zod/index.d.ts.map +0 -1
  35. package/lib/src/zod/staticSchemaValidator.d.ts +0 -99
  36. package/lib/src/zod/staticSchemaValidator.d.ts.map +0 -1
  37. package/lib/src/zod/staticSchemaValidator.js +0 -99
  38. package/lib/src/zod/types/schema.types.d.ts +0 -71
  39. package/lib/src/zod/types/schema.types.d.ts.map +0 -1
  40. package/lib/src/zod/types/schema.types.js +0 -1
  41. package/lib/src/zod/zodSchemaValidator.d.ts +0 -110
  42. package/lib/src/zod/zodSchemaValidator.d.ts.map +0 -1
  43. package/lib/src/zod/zodSchemaValidator.js +0 -192
  44. package/lib/tests/typebox/advancedParse.test.d.ts +0 -2
  45. package/lib/tests/typebox/advancedParse.test.d.ts.map +0 -1
  46. package/lib/tests/typebox/advancedParse.test.js +0 -514
  47. package/lib/tests/typebox/largeSchema.test.d.ts +0 -2
  48. package/lib/tests/typebox/largeSchema.test.d.ts.map +0 -1
  49. package/lib/tests/typebox/largeSchema.test.js +0 -150
  50. package/lib/tests/typebox/schemaValidator.test.d.ts +0 -2
  51. package/lib/tests/typebox/schemaValidator.test.d.ts.map +0 -1
  52. package/lib/tests/typebox/schemaValidator.test.js +0 -253
  53. package/lib/tests/typebox/typeEquality.test.d.ts +0 -2
  54. package/lib/tests/typebox/typeEquality.test.d.ts.map +0 -1
  55. package/lib/tests/typebox/typeEquality.test.js +0 -100
  56. package/lib/tests/utils/compare.d.ts +0 -2
  57. package/lib/tests/utils/compare.d.ts.map +0 -1
  58. package/lib/tests/utils/compare.js +0 -8
  59. package/lib/tests/utils/mockSchemaValidator.d.ts.map +0 -1
  60. package/lib/tests/zod/advancedParse.test.d.ts +0 -2
  61. package/lib/tests/zod/advancedParse.test.d.ts.map +0 -1
  62. package/lib/tests/zod/advancedParse.test.js +0 -514
  63. package/lib/tests/zod/largeSchema.test.d.ts +0 -2
  64. package/lib/tests/zod/largeSchema.test.d.ts.map +0 -1
  65. package/lib/tests/zod/largeSchema.test.js +0 -150
  66. package/lib/tests/zod/schemaValidator.test.d.ts +0 -2
  67. package/lib/tests/zod/schemaValidator.test.d.ts.map +0 -1
  68. package/lib/tests/zod/schemaValidator.test.js +0 -205
  69. package/lib/tests/zod/typeEquality.test.d.ts +0 -2
  70. package/lib/tests/zod/typeEquality.test.d.ts.map +0 -1
  71. package/lib/tests/zod/typeEquality.test.js +0 -100
  72. package/lib/tsconfig.tsbuildinfo +0 -1
  73. package/lib/vitest.config.d.ts +0 -3
  74. package/lib/vitest.config.d.ts.map +0 -1
  75. package/lib/vitest.config.js +0 -7
@@ -1,205 +0,0 @@
1
- import { generateSchema } from '@anatine/zod-openapi';
2
- import { z } from 'zod';
3
- import { array, enum_, isSchema, number, openapi, optional, parse, schemify, string, union, validate } from '../../src/zod';
4
- import { compare } from '../utils/compare';
5
- describe('zod schema validator tests', () => {
6
- let schema;
7
- let schemified;
8
- let expectedSchema;
9
- beforeAll(() => {
10
- schema = {
11
- hello: {
12
- world: string
13
- },
14
- foo: {
15
- bar: number
16
- }
17
- };
18
- schemified = schemify(schema);
19
- expectedSchema = z.object({
20
- hello: z.object({
21
- world: z.string()
22
- }),
23
- foo: z.object({
24
- bar: z.number()
25
- })
26
- });
27
- });
28
- test('schemify', async () => {
29
- compare(schemified, expectedSchema);
30
- compare(schemified, schemify({
31
- hello: {
32
- world: string
33
- },
34
- foo: {
35
- bar: number
36
- }
37
- }));
38
- compare(schemified, schemify({
39
- hello: schemify({
40
- world: string
41
- }),
42
- foo: {
43
- bar: number
44
- }
45
- }));
46
- compare(schemified, schemify({
47
- hello: {
48
- world: string
49
- },
50
- foo: schemify({
51
- bar: number
52
- })
53
- }));
54
- compare(schemified, schemify({
55
- hello: schemify({
56
- world: string
57
- }),
58
- foo: schemify({
59
- bar: number
60
- })
61
- }));
62
- });
63
- test('optional', async () => {
64
- const unboxSchemified = optional(schema);
65
- const boxSchemified = optional(schemified);
66
- const schemifiedExpected = z.optional(expectedSchema);
67
- compare(unboxSchemified, schemifiedExpected);
68
- compare(boxSchemified, schemifiedExpected);
69
- });
70
- test('array', async () => {
71
- const unboxSchemified = array(schema);
72
- const boxSchemified = array(schemified);
73
- const schemifiedExpected = z.array(expectedSchema);
74
- compare(unboxSchemified, schemifiedExpected);
75
- compare(boxSchemified, schemifiedExpected);
76
- });
77
- test('union', async () => {
78
- const unboxSchemified = union([
79
- schema,
80
- {
81
- test: string
82
- }
83
- ]);
84
- const unboxSchemified2 = union([
85
- schema,
86
- schemify({
87
- test: string
88
- })
89
- ]);
90
- const boxSchemified = union([
91
- schemified,
92
- schemify({
93
- test: string
94
- })
95
- ]);
96
- const boxSchemified2 = union([
97
- schemified,
98
- {
99
- test: string
100
- }
101
- ]);
102
- const schemifiedExpected = z.union([
103
- expectedSchema,
104
- z.object({
105
- test: z.string()
106
- })
107
- ]);
108
- compare(unboxSchemified, schemifiedExpected);
109
- compare(unboxSchemified2, schemifiedExpected);
110
- compare(boxSchemified, schemifiedExpected);
111
- compare(boxSchemified2, schemifiedExpected);
112
- });
113
- test('literal', async () => {
114
- const schemified = schemify({
115
- hello: 'world'
116
- });
117
- compare(schemified, z.object({
118
- hello: z.literal('world')
119
- }));
120
- });
121
- test('enum', async () => {
122
- let TestSingleEnum;
123
- (function (TestSingleEnum) {
124
- TestSingleEnum["WORLD"] = "world";
125
- })(TestSingleEnum || (TestSingleEnum = {}));
126
- const schemified = enum_(TestSingleEnum);
127
- compare(schemified, z.union([z.literal('world')]));
128
- let TestMultipleEnum;
129
- (function (TestMultipleEnum) {
130
- TestMultipleEnum["WORLD"] = "world";
131
- TestMultipleEnum["HELLO"] = "hello";
132
- })(TestMultipleEnum || (TestMultipleEnum = {}));
133
- const schemifiedMultiple = enum_(TestMultipleEnum);
134
- compare(schemifiedMultiple, z.union([z.literal('world'), z.literal('hello')]));
135
- });
136
- test('isSchema', () => {
137
- expect(isSchema(z.string())).toBe(true);
138
- expect(isSchema(z.number())).toBe(true);
139
- expect(isSchema(z.object({ foo: z.string() }))).toBe(true);
140
- expect(isSchema(schemified)).toBe(true);
141
- expect(isSchema('not a schema')).toBe(false);
142
- expect(isSchema(42)).toBe(false);
143
- expect(isSchema({})).toBe(false);
144
- expect(isSchema(null)).toBe(false);
145
- expect(isSchema(undefined)).toBe(false);
146
- });
147
- test('validate', async () => {
148
- validate(schemified, {
149
- hello: {
150
- world: 'world'
151
- },
152
- foo: {
153
- bar: 42
154
- }
155
- });
156
- expect(validate(schemified, {
157
- hello: {
158
- world: 55
159
- },
160
- foo: {}
161
- })).toBe(false);
162
- });
163
- test('parse', () => {
164
- const validParse = parse(schemified, {
165
- hello: {
166
- world: 'world'
167
- },
168
- foo: {
169
- bar: 42
170
- }
171
- });
172
- expect(validParse.ok).toBe(true);
173
- if (validParse.ok) {
174
- compare(validParse.value, {
175
- hello: {
176
- world: 'world'
177
- },
178
- foo: {
179
- bar: 42
180
- }
181
- });
182
- }
183
- const failedParse = parse(schemified, {
184
- hello: {
185
- world: 55
186
- },
187
- foo: {}
188
- });
189
- expect(failedParse.ok).toBe(false);
190
- if (!failedParse.ok) {
191
- expect(failedParse.error)
192
- .toBe(`Validation failed with the following errors:
193
- 1. Path: hello > world
194
- Message: Expected string, received number
195
-
196
- 2. Path: foo > bar
197
- Message: Expected number, received nan`);
198
- }
199
- });
200
- test('openapi', async () => {
201
- const schemified = schemify(schema);
202
- const openApi = openapi(schemified);
203
- expect(openApi).toEqual(generateSchema(schemified));
204
- });
205
- });
@@ -1,2 +0,0 @@
1
- export declare function assert<T extends never>(): void;
2
- //# sourceMappingURL=typeEquality.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeEquality.test.d.ts","sourceRoot":"","sources":["../../../tests/zod/typeEquality.test.ts"],"names":[],"mappings":"AAgHA,wBAAgB,MAAM,CAAC,CAAC,SAAS,KAAK,UAAM"}
@@ -1,100 +0,0 @@
1
- import { array, bigint, boolean, date, never, nullish, number, optional, schemify, string, symbol, union } from '../../src/zod';
2
- const one = array({
3
- name: {
4
- j: union([string, number, date, boolean, bigint, nullish, symbol, never]),
5
- t: optional(union([
6
- array({
7
- y: array(number)
8
- }),
9
- string
10
- ])),
11
- m: {
12
- a: optional(string),
13
- b: number,
14
- c: {
15
- d: string,
16
- e: number
17
- }
18
- }
19
- },
20
- 200: {
21
- j: string
22
- },
23
- m: {
24
- a: true
25
- }
26
- });
27
- const two = array({
28
- name: {
29
- j: union([string, number, date, boolean, bigint, nullish, symbol, never]),
30
- t: optional(union([
31
- array({
32
- y: array(number)
33
- }),
34
- string
35
- ])),
36
- m: schemify({
37
- a: optional(string),
38
- b: number,
39
- c: {
40
- d: string,
41
- e: number
42
- }
43
- })
44
- },
45
- 200: {
46
- j: string
47
- },
48
- m: {
49
- a: true
50
- }
51
- });
52
- const three = schemify(array(schemify({
53
- name: schemify({
54
- j: union([
55
- string,
56
- number,
57
- date,
58
- boolean,
59
- bigint,
60
- nullish,
61
- symbol,
62
- never
63
- ]),
64
- t: optional(union([
65
- array({
66
- y: array(number)
67
- }),
68
- string
69
- ])),
70
- m: schemify({
71
- a: optional(string),
72
- b: number,
73
- c: {
74
- d: string,
75
- e: number
76
- }
77
- })
78
- }),
79
- 200: schemify({
80
- j: string
81
- }),
82
- m: schemify({
83
- a: true
84
- })
85
- })));
86
- export function assert() { }
87
- assert();
88
- assert();
89
- assert();
90
- assert();
91
- const shortOne = {
92
- s: string,
93
- non: number
94
- };
95
- const shortTwo = schemify({
96
- s: string,
97
- non: number
98
- });
99
- assert();
100
- assert();