@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,179 @@
1
+ import { generateSchema } from '@anatine/zod-openapi';
2
+ import { z } from 'zod';
3
+ import { array, 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('validate', async () => {
122
+ validate(schemified, {
123
+ hello: {
124
+ world: 'world'
125
+ },
126
+ foo: {
127
+ bar: 42
128
+ }
129
+ });
130
+ expect(validate(schemified, {
131
+ hello: {
132
+ world: 55
133
+ },
134
+ foo: {}
135
+ })).toBe(false);
136
+ });
137
+ test('parse', () => {
138
+ const validParse = parse(schemified, {
139
+ hello: {
140
+ world: 'world'
141
+ },
142
+ foo: {
143
+ bar: 42
144
+ }
145
+ });
146
+ expect(validParse.ok).toBe(true);
147
+ if (validParse.ok) {
148
+ compare(validParse.value, {
149
+ hello: {
150
+ world: 'world'
151
+ },
152
+ foo: {
153
+ bar: 42
154
+ }
155
+ });
156
+ }
157
+ const failedParse = parse(schemified, {
158
+ hello: {
159
+ world: 55
160
+ },
161
+ foo: {}
162
+ });
163
+ expect(failedParse.ok).toBe(false);
164
+ if (!failedParse.ok) {
165
+ expect(failedParse.error)
166
+ .toBe(`Validation failed with the following errors:
167
+ 1. Path: hello > world
168
+ Message: Expected string, received number
169
+
170
+ 2. Path: foo > bar
171
+ Message: Expected number, received nan`);
172
+ }
173
+ });
174
+ test('openapi', async () => {
175
+ const schemified = schemify(schema);
176
+ const openApi = openapi(schemified);
177
+ expect(openApi).toEqual(generateSchema(schemified));
178
+ });
179
+ });
@@ -1 +1,2 @@
1
1
  export declare function assert<T extends never>(): void;
2
+ //# sourceMappingURL=typeEquality.test.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,100 @@
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();