@forklaunch/validator 0.3.1 → 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.
- package/LICENSE +21 -0
- package/lib/eslint.config.d.mts +3 -0
- package/lib/eslint.config.d.mts.map +1 -0
- package/lib/eslint.config.mjs +10 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +1 -0
- package/lib/jest.config.d.ts +4 -0
- package/lib/jest.config.d.ts.map +1 -0
- package/lib/jest.config.js +21 -0
- package/{dist → lib/src/shared}/types/schema.types.d.ts +47 -7
- package/lib/src/shared/types/schema.types.d.ts.map +1 -0
- package/lib/src/typebox/index.d.ts +3 -0
- package/lib/src/typebox/index.d.ts.map +1 -0
- package/lib/src/typebox/index.js +1 -0
- package/lib/src/typebox/staticSchemaValidator.d.ts +93 -0
- package/lib/src/typebox/staticSchemaValidator.d.ts.map +1 -0
- package/lib/src/typebox/staticSchemaValidator.js +91 -0
- package/lib/src/typebox/typeboxSchemaValidator.d.ts +110 -0
- package/lib/src/typebox/typeboxSchemaValidator.d.ts.map +1 -0
- package/lib/src/typebox/typeboxSchemaValidator.js +343 -0
- package/{dist/typebox/types/typebox.schema.types.d.ts → lib/src/typebox/types/schema.types.d.ts} +9 -13
- package/lib/src/typebox/types/schema.types.d.ts.map +1 -0
- package/lib/src/zod/index.d.ts +3 -0
- package/lib/src/zod/index.d.ts.map +1 -0
- package/lib/src/zod/index.js +1 -0
- package/lib/src/zod/staticSchemaValidator.d.ts +93 -0
- package/lib/src/zod/staticSchemaValidator.d.ts.map +1 -0
- package/lib/src/zod/staticSchemaValidator.js +91 -0
- package/{dist/zod/types/zod.schema.types.d.ts → lib/src/zod/types/schema.types.d.ts} +3 -2
- package/lib/src/zod/types/schema.types.d.ts.map +1 -0
- package/lib/src/zod/types/schema.types.js +1 -0
- package/lib/src/zod/zodSchemaValidator.d.ts +98 -0
- package/lib/src/zod/zodSchemaValidator.d.ts.map +1 -0
- package/lib/src/zod/zodSchemaValidator.js +179 -0
- package/lib/tests/typebox/advancedParse.test.d.ts +2 -0
- package/lib/tests/typebox/advancedParse.test.d.ts.map +1 -0
- package/lib/tests/typebox/advancedParse.test.js +514 -0
- package/lib/tests/typebox/largeSchema.test.d.ts +2 -0
- package/lib/tests/typebox/largeSchema.test.d.ts.map +1 -0
- package/{dist → lib}/tests/typebox/largeSchema.test.js +46 -49
- package/lib/tests/typebox/schemaValidator.test.d.ts +2 -0
- package/lib/tests/typebox/schemaValidator.test.d.ts.map +1 -0
- package/lib/tests/typebox/schemaValidator.test.js +219 -0
- package/{dist/tests/typebox/equality.test.d.ts → lib/tests/typebox/typeEquality.test.d.ts} +1 -0
- package/lib/tests/typebox/typeEquality.test.d.ts.map +1 -0
- package/lib/tests/typebox/typeEquality.test.js +100 -0
- package/lib/tests/utils/compare.d.ts +2 -0
- package/lib/tests/utils/compare.d.ts.map +1 -0
- package/lib/tests/utils/compare.js +8 -0
- package/{dist/tests → lib/tests/utils}/mockSchemaValidator.d.ts +14 -8
- package/lib/tests/utils/mockSchemaValidator.d.ts.map +1 -0
- package/lib/tests/utils/mockSchemaValidator.js +72 -0
- package/lib/tests/zod/advancedParse.test.d.ts +2 -0
- package/lib/tests/zod/advancedParse.test.d.ts.map +1 -0
- package/lib/tests/zod/advancedParse.test.js +514 -0
- package/lib/tests/zod/largeSchema.test.d.ts +2 -0
- package/lib/tests/zod/largeSchema.test.d.ts.map +1 -0
- package/{dist → lib}/tests/zod/largeSchema.test.js +43 -46
- package/lib/tests/zod/schemaValidator.test.d.ts +2 -0
- package/lib/tests/zod/schemaValidator.test.d.ts.map +1 -0
- package/lib/tests/zod/schemaValidator.test.js +179 -0
- package/{dist/tests/zod/equality.test.d.ts → lib/tests/zod/typeEquality.test.d.ts} +1 -0
- package/lib/tests/zod/typeEquality.test.d.ts.map +1 -0
- package/lib/tests/zod/typeEquality.test.js +100 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/vitest.config.d.ts +3 -0
- package/lib/vitest.config.d.ts.map +1 -0
- package/lib/vitest.config.js +7 -0
- package/package.json +35 -39
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/jest.config.d.ts +0 -3
- package/dist/jest.config.js +0 -10
- package/dist/jest.config.js.map +0 -1
- package/dist/tests/mockSchemaValidator.js +0 -60
- package/dist/tests/mockSchemaValidator.js.map +0 -1
- package/dist/tests/typebox/equality.test.js +0 -234
- package/dist/tests/typebox/equality.test.js.map +0 -1
- package/dist/tests/typebox/largeSchema.test.js.map +0 -1
- package/dist/tests/zod/equality.test.js +0 -238
- package/dist/tests/zod/equality.test.js.map +0 -1
- package/dist/tests/zod/largeSchema.test.js.map +0 -1
- package/dist/typebox/index.d.ts +0 -1
- package/dist/typebox/index.js +0 -18
- package/dist/typebox/index.js.map +0 -1
- package/dist/typebox/typebox.schemaValidator.d.ts +0 -150
- package/dist/typebox/typebox.schemaValidator.js +0 -203
- package/dist/typebox/typebox.schemaValidator.js.map +0 -1
- package/dist/typebox/types/typebox.schema.types.js +0 -3
- package/dist/typebox/types/typebox.schema.types.js.map +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -18
- package/dist/types/index.js.map +0 -1
- package/dist/types/schema.types.js +0 -3
- package/dist/types/schema.types.js.map +0 -1
- package/dist/zod/index.d.ts +0 -1
- package/dist/zod/index.js +0 -18
- package/dist/zod/index.js.map +0 -1
- package/dist/zod/types/zod.schema.types.js +0 -3
- package/dist/zod/types/zod.schema.types.js.map +0 -1
- package/dist/zod/zod.schemaValidator.d.ts +0 -147
- package/dist/zod/zod.schemaValidator.js +0 -196
- package/dist/zod/zod.schemaValidator.js.map +0 -1
- /package/{dist/tests/typebox/largeSchema.test.d.ts → lib/src/shared/types/schema.types.js} +0 -0
- /package/{dist/tests/zod/largeSchema.test.d.ts → lib/src/typebox/types/schema.types.js} +0 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { array, number, openapi, optional, parse, schemify, string, union, validate } from '../../src/typebox/staticSchemaValidator';
|
|
3
|
+
import { compare } from '../utils/compare';
|
|
4
|
+
describe('typebox schema validator tests', () => {
|
|
5
|
+
let schema;
|
|
6
|
+
let schemified;
|
|
7
|
+
let expectedSchema;
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
schema = {
|
|
10
|
+
hello: {
|
|
11
|
+
world: string
|
|
12
|
+
},
|
|
13
|
+
foo: {
|
|
14
|
+
bar: number
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
schemified = schemify(schema);
|
|
18
|
+
expectedSchema = Type.Object({
|
|
19
|
+
hello: Type.Object({
|
|
20
|
+
world: Type.String()
|
|
21
|
+
}),
|
|
22
|
+
foo: Type.Object({
|
|
23
|
+
bar: Type.Transform(Type.Union([
|
|
24
|
+
Type.Number(),
|
|
25
|
+
Type.String({ pattern: '^[0-9]+$' }),
|
|
26
|
+
Type.Boolean(),
|
|
27
|
+
Type.Null(),
|
|
28
|
+
Type.Date(),
|
|
29
|
+
Type.BigInt()
|
|
30
|
+
], {
|
|
31
|
+
errorType: 'number-like',
|
|
32
|
+
openapiType: Type.Number()
|
|
33
|
+
}))
|
|
34
|
+
.Decode((value) => {
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
const num = Number(value);
|
|
37
|
+
if (isNaN(num)) {
|
|
38
|
+
throw new Error('Invalid number');
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return num;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
})
|
|
46
|
+
.Encode(Number)
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
test('schemify', async () => {
|
|
51
|
+
compare(schemified, expectedSchema);
|
|
52
|
+
compare(schemified, schemify({
|
|
53
|
+
hello: {
|
|
54
|
+
world: string
|
|
55
|
+
},
|
|
56
|
+
foo: {
|
|
57
|
+
bar: number
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
compare(schemified, schemify({
|
|
61
|
+
hello: schemify({
|
|
62
|
+
world: string
|
|
63
|
+
}),
|
|
64
|
+
foo: {
|
|
65
|
+
bar: number
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
compare(schemified, schemify({
|
|
69
|
+
hello: {
|
|
70
|
+
world: string
|
|
71
|
+
},
|
|
72
|
+
foo: schemify({
|
|
73
|
+
bar: number
|
|
74
|
+
})
|
|
75
|
+
}));
|
|
76
|
+
compare(schemified, schemify({
|
|
77
|
+
hello: schemify({
|
|
78
|
+
world: string
|
|
79
|
+
}),
|
|
80
|
+
foo: schemify({
|
|
81
|
+
bar: number
|
|
82
|
+
})
|
|
83
|
+
}));
|
|
84
|
+
});
|
|
85
|
+
test('optional', async () => {
|
|
86
|
+
const unboxSchemified = optional(schema);
|
|
87
|
+
const boxSchemified = optional(schemified);
|
|
88
|
+
const schemifiedExpected = Type.Optional(expectedSchema);
|
|
89
|
+
compare(unboxSchemified, schemifiedExpected);
|
|
90
|
+
compare(boxSchemified, schemifiedExpected);
|
|
91
|
+
});
|
|
92
|
+
test('array', async () => {
|
|
93
|
+
const unboxSchemified = array(schema);
|
|
94
|
+
const boxSchemified = array(schemified);
|
|
95
|
+
const schemifiedExpected = Type.Array(expectedSchema, {
|
|
96
|
+
errorType: 'array of object'
|
|
97
|
+
});
|
|
98
|
+
compare(unboxSchemified, schemifiedExpected);
|
|
99
|
+
compare(boxSchemified, schemifiedExpected);
|
|
100
|
+
});
|
|
101
|
+
test('union', async () => {
|
|
102
|
+
const unboxSchemified = union([
|
|
103
|
+
schema,
|
|
104
|
+
{
|
|
105
|
+
test: string
|
|
106
|
+
}
|
|
107
|
+
]);
|
|
108
|
+
const unboxSchemified2 = union([
|
|
109
|
+
schema,
|
|
110
|
+
schemify({
|
|
111
|
+
test: string
|
|
112
|
+
})
|
|
113
|
+
]);
|
|
114
|
+
const boxSchemified = union([
|
|
115
|
+
schemified,
|
|
116
|
+
schemify({
|
|
117
|
+
test: string
|
|
118
|
+
})
|
|
119
|
+
]);
|
|
120
|
+
const boxSchemified2 = union([
|
|
121
|
+
schemified,
|
|
122
|
+
{
|
|
123
|
+
test: string
|
|
124
|
+
}
|
|
125
|
+
]);
|
|
126
|
+
const schemifiedExpected = Type.Union([
|
|
127
|
+
expectedSchema,
|
|
128
|
+
Type.Object({
|
|
129
|
+
test: Type.String()
|
|
130
|
+
})
|
|
131
|
+
], {
|
|
132
|
+
errorType: 'any of object, object',
|
|
133
|
+
errorSuffix: true
|
|
134
|
+
});
|
|
135
|
+
compare(unboxSchemified, schemifiedExpected);
|
|
136
|
+
compare(unboxSchemified2, schemifiedExpected);
|
|
137
|
+
compare(boxSchemified, schemifiedExpected);
|
|
138
|
+
compare(boxSchemified2, schemifiedExpected);
|
|
139
|
+
});
|
|
140
|
+
test('literal', async () => {
|
|
141
|
+
const schemified = schemify({
|
|
142
|
+
hello: 'world'
|
|
143
|
+
});
|
|
144
|
+
compare(schemified, Type.Object({
|
|
145
|
+
hello: Type.Literal('world')
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
test('validate', async () => {
|
|
149
|
+
validate(schemified, {
|
|
150
|
+
hello: {
|
|
151
|
+
world: 'world'
|
|
152
|
+
},
|
|
153
|
+
foo: {
|
|
154
|
+
bar: 42
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
expect(validate(schemified, {
|
|
158
|
+
hello: {
|
|
159
|
+
world: 55
|
|
160
|
+
},
|
|
161
|
+
foo: {
|
|
162
|
+
bar: 42
|
|
163
|
+
}
|
|
164
|
+
})).toBe(false);
|
|
165
|
+
});
|
|
166
|
+
test('parse', () => {
|
|
167
|
+
const validParse = parse(schemified, {
|
|
168
|
+
hello: {
|
|
169
|
+
world: 'world'
|
|
170
|
+
},
|
|
171
|
+
foo: {
|
|
172
|
+
bar: 42
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
expect(validParse.ok).toBe(true);
|
|
176
|
+
if (validParse.ok) {
|
|
177
|
+
compare(validParse.value, {
|
|
178
|
+
hello: {
|
|
179
|
+
world: 'world'
|
|
180
|
+
},
|
|
181
|
+
foo: {
|
|
182
|
+
bar: 42
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const failedParse = parse(schemified, {
|
|
187
|
+
hello: {
|
|
188
|
+
world: 55
|
|
189
|
+
},
|
|
190
|
+
foo: {}
|
|
191
|
+
});
|
|
192
|
+
expect(failedParse.ok).toBe(false);
|
|
193
|
+
if (!failedParse.ok) {
|
|
194
|
+
expect(failedParse.error)
|
|
195
|
+
.toBe(`Validation failed with the following errors:
|
|
196
|
+
1. Path: hello > world
|
|
197
|
+
Message: Expected string
|
|
198
|
+
|
|
199
|
+
2. Path: foo > bar
|
|
200
|
+
Message: Expected required property
|
|
201
|
+
|
|
202
|
+
3. Path: foo > bar
|
|
203
|
+
Message: Expected number-like value`);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
test('openapi', async () => {
|
|
207
|
+
const mutation = schemify(schema);
|
|
208
|
+
compare(openapi(schema), Type.Object({
|
|
209
|
+
hello: Type.Object({
|
|
210
|
+
world: Type.String()
|
|
211
|
+
}),
|
|
212
|
+
foo: Type.Object({
|
|
213
|
+
bar: Type.Number()
|
|
214
|
+
})
|
|
215
|
+
}));
|
|
216
|
+
// ensure that no mutation has occurred to schema
|
|
217
|
+
compare(schemify(schema), mutation);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeEquality.test.d.ts","sourceRoot":"","sources":["../../../tests/typebox/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/typebox/staticSchemaValidator';
|
|
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();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../tests/utils/compare.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,aAAc,OAAO,YAAY,OAAO,SAO3D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
2
|
-
import { SchemaValidator } from '
|
|
3
|
-
import { LiteralSchema } from '
|
|
4
|
-
declare module '
|
|
2
|
+
import { SchemaValidator } from '../../index';
|
|
3
|
+
import { LiteralSchema, ParseResult } from '../../src/shared/types/schema.types';
|
|
4
|
+
declare module '../../src/shared/types/schema.types' {
|
|
5
5
|
interface SchemaResolve<T> {
|
|
6
6
|
Mock: T;
|
|
7
7
|
}
|
|
@@ -13,26 +13,31 @@ type RecursiveUnion<T extends readonly string[]> = T extends readonly [
|
|
|
13
13
|
infer F extends string,
|
|
14
14
|
...infer R extends readonly string[]
|
|
15
15
|
] ? R extends [] ? F : `${F} | ${RecursiveUnion<R>}` : '';
|
|
16
|
-
export declare class MockSchemaValidator implements SchemaValidator<(<T extends string>(schema: T) => T), <T extends string>(schema: T) => `optional ${T}`, <T extends string>(schema: T) => `array ${T}`, <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>, <T extends LiteralSchema>(schema: T) => `literal ${T}`, <T extends string>(schema: T, value: string) => boolean, <T extends string>(schema: T) => SchemaObject> {
|
|
16
|
+
export declare class MockSchemaValidator implements SchemaValidator<(<T extends string>(schema: T) => T), <T extends string>(schema: T) => T, <T extends string>(schema: T) => `optional ${T}`, <T extends string>(schema: T) => `array ${T}`, <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>, <T extends LiteralSchema>(schema: T) => `literal ${T}`, <T extends string>(schema: T, value: string) => boolean, <T extends string>(schema: T, value: string) => ParseResult<T>, <T extends string>(schema: T) => SchemaObject> {
|
|
17
17
|
_Type: 'Mock';
|
|
18
18
|
_SchemaCatchall: string;
|
|
19
19
|
_ValidSchemaObject: string;
|
|
20
20
|
string: string;
|
|
21
|
+
uuid: string;
|
|
22
|
+
email: string;
|
|
23
|
+
uri: string;
|
|
21
24
|
number: string;
|
|
22
25
|
bigint: string;
|
|
23
26
|
boolean: string;
|
|
24
27
|
date: string;
|
|
25
28
|
symbol: string;
|
|
26
|
-
|
|
29
|
+
nullish: string;
|
|
27
30
|
any: string;
|
|
28
31
|
unknown: string;
|
|
29
32
|
never: string;
|
|
30
|
-
|
|
33
|
+
compile<T extends string>(schema: T): T;
|
|
34
|
+
schemify<T extends string>(schema: T): T;
|
|
31
35
|
optional<T extends string>(schema: T): `optional ${T}`;
|
|
32
36
|
array<T extends string>(schema: T): `array ${T}`;
|
|
33
37
|
union<T extends readonly string[]>(schemas: T): RecursiveUnion<T>;
|
|
34
38
|
literal<T extends LiteralSchema>(schema: T): `literal ${T}`;
|
|
35
39
|
validate<T extends string>(schema: T, value: string): boolean;
|
|
40
|
+
parse<T extends string>(schema: T, value: string): ParseResult<T>;
|
|
36
41
|
openapi<T extends string>(_schema: T): SchemaObject;
|
|
37
42
|
}
|
|
38
43
|
export declare const mockSchemaValidator: MockSchemaValidator;
|
|
@@ -42,11 +47,11 @@ export declare const bigint: string;
|
|
|
42
47
|
export declare const boolean: string;
|
|
43
48
|
export declare const date: string;
|
|
44
49
|
export declare const symbol: string;
|
|
45
|
-
export declare const
|
|
50
|
+
export declare const nullish: string;
|
|
46
51
|
export declare const any: string;
|
|
47
52
|
export declare const unknown: string;
|
|
48
53
|
export declare const never: string;
|
|
49
|
-
export declare const schemify: <T>(schema: T) => T;
|
|
54
|
+
export declare const schemify: <T extends string>(schema: T) => T;
|
|
50
55
|
export declare const optional: <T extends string>(schema: T) => `optional ${T}`;
|
|
51
56
|
export declare const array: <T extends string>(schema: T) => `array ${T}`;
|
|
52
57
|
export declare const union: <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>;
|
|
@@ -54,3 +59,4 @@ export declare const literal: <T extends LiteralSchema>(schema: T) => `literal $
|
|
|
54
59
|
export declare const validate: <T extends string>(schema: T, value: string) => boolean;
|
|
55
60
|
export declare const openapi: <T extends string>(_schema: T) => SchemaObject;
|
|
56
61
|
export {};
|
|
62
|
+
//# sourceMappingURL=mockSchemaValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockSchemaValidator.d.ts","sourceRoot":"","sources":["../../../tests/utils/mockSchemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACL,aAAa,EACb,WAAW,EACZ,MAAM,qCAAqC,CAAC;AAE7C,OAAO,QAAQ,qCAAqC,CAAC;IACnD,UAAU,aAAa,CAAC,CAAC;QACvB,IAAI,EAAE,CAAC,CAAC;KACT;IAED,UAAU,eAAe,CAAC,CAAC;QACzB,IAAI,EAAE,CAAC,CAAC;KACT;CACF;AAED,KAAK,cAAc,CAAC,CAAC,SAAS,SAAS,MAAM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,OAAO,QAA8B,CAAC;AACnD,eAAO,MAAM,KAAK,QAA4B,CAAC;AAC/C,eAAO,MAAM,QAAQ,GA7CV,CAAC,SAAS,MAAM,iBA6CmD,CAAC;AAC/E,eAAO,MAAM,QAAQ,GA3CV,CAAC,SAAS,MAAM,UAAU,CAAC,KAAG,YAAY,CAAC,EA2CwB,CAAC;AAC/E,eAAO,MAAM,KAAK,GAzCV,CAAC,SAAS,MAAM,UAAU,CAAC,KAAG,SAAS,CAAC,EAyCwB,CAAC;AAEzE,eAAO,MAAM,KAAK,GAxCV,CAAC,SAAS,SAAS,MAAM,EAAE,WAAW,CAAC,KAAG,cAAc,CAAC,CAAC,CAwCM,CAAC;AACzE,eAAO,MAAM,OAAO,GAtCV,CAAC,SAAS,aAAa,UAAU,CAAC,KAAG,WAAW,CAAC,EAsCiB,CAAC;AAC7E,eAAO,MAAM,QAAQ,GApCV,CAAC,SAAS,MAAM,UAAU,CAAC,SAAS,MAAM,KAAG,OAoCsB,CAAC;AAC/E,eAAO,MAAM,OAAO,GAvBV,CAAC,SAAS,MAAM,WAAW,CAAC,KAAG,YAuBmC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export class MockSchemaValidator {
|
|
2
|
+
_Type;
|
|
3
|
+
_SchemaCatchall;
|
|
4
|
+
_ValidSchemaObject;
|
|
5
|
+
string = 'string';
|
|
6
|
+
uuid = 'uuid';
|
|
7
|
+
email = 'email';
|
|
8
|
+
uri = 'uri';
|
|
9
|
+
number = 'number';
|
|
10
|
+
bigint = 'bigint';
|
|
11
|
+
boolean = 'boolean';
|
|
12
|
+
date = 'date';
|
|
13
|
+
symbol = 'symbol';
|
|
14
|
+
nullish = 'nullish';
|
|
15
|
+
any = 'any';
|
|
16
|
+
unknown = 'unknown';
|
|
17
|
+
never = 'never';
|
|
18
|
+
compile(schema) {
|
|
19
|
+
return schema;
|
|
20
|
+
}
|
|
21
|
+
schemify(schema) {
|
|
22
|
+
return schema;
|
|
23
|
+
}
|
|
24
|
+
optional(schema) {
|
|
25
|
+
return ('optional ' + schema);
|
|
26
|
+
}
|
|
27
|
+
array(schema) {
|
|
28
|
+
return ('array ' + schema);
|
|
29
|
+
}
|
|
30
|
+
union(schemas) {
|
|
31
|
+
return schemas.join(' | ');
|
|
32
|
+
}
|
|
33
|
+
literal(schema) {
|
|
34
|
+
return `literal ${schema}`;
|
|
35
|
+
}
|
|
36
|
+
validate(schema, value) {
|
|
37
|
+
return schema === value;
|
|
38
|
+
}
|
|
39
|
+
parse(schema, value) {
|
|
40
|
+
return JSON.stringify(schema) === JSON.stringify(value)
|
|
41
|
+
? {
|
|
42
|
+
ok: true,
|
|
43
|
+
value: schema
|
|
44
|
+
}
|
|
45
|
+
: {
|
|
46
|
+
ok: false,
|
|
47
|
+
error: 'Some error'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
openapi(_schema) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export const mockSchemaValidator = new MockSchemaValidator();
|
|
55
|
+
export const string = mockSchemaValidator.string;
|
|
56
|
+
export const number = mockSchemaValidator.number;
|
|
57
|
+
export const bigint = mockSchemaValidator.bigint;
|
|
58
|
+
export const boolean = mockSchemaValidator.boolean;
|
|
59
|
+
export const date = mockSchemaValidator.date;
|
|
60
|
+
export const symbol = mockSchemaValidator.symbol;
|
|
61
|
+
export const nullish = mockSchemaValidator.nullish;
|
|
62
|
+
export const any = mockSchemaValidator.any;
|
|
63
|
+
export const unknown = mockSchemaValidator.unknown;
|
|
64
|
+
export const never = mockSchemaValidator.never;
|
|
65
|
+
export const schemify = mockSchemaValidator.schemify.bind(mockSchemaValidator);
|
|
66
|
+
export const optional = mockSchemaValidator.optional.bind(mockSchemaValidator);
|
|
67
|
+
export const array = mockSchemaValidator.array.bind(mockSchemaValidator);
|
|
68
|
+
// note, use 'as const' when calling on the input array, for proper type parsing
|
|
69
|
+
export const union = mockSchemaValidator.union.bind(mockSchemaValidator);
|
|
70
|
+
export const literal = mockSchemaValidator.literal.bind(mockSchemaValidator);
|
|
71
|
+
export const validate = mockSchemaValidator.validate.bind(mockSchemaValidator);
|
|
72
|
+
export const openapi = mockSchemaValidator.openapi.bind(mockSchemaValidator);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedParse.test.d.ts","sourceRoot":"","sources":["../../../tests/zod/advancedParse.test.ts"],"names":[],"mappings":""}
|