Skip to content

Commit 0368e8e

Browse files
authored
Merge pull request #1731 from sinclairzx81/master
Add TypeMap (Zod & Valibot)
2 parents ab3273c + ab7bc5a commit 0368e8e

File tree

7 files changed

+144
-8
lines changed

7 files changed

+144
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* [runtypes](https://github.com/pelotom/runtypes)
4545
* [@sapphire/shapeshift](https://github.com/sapphiredev/shapeshift)
4646
* [@sinclair/typebox](https://github.com/sinclairzx81/typebox)
47+
* [@sinclair/typemap](https://github.com/sinclairzx81/typemap)
4748
* [simple-runtypes](https://github.com/hoeck/simple-runtypes)
4849
* [spectypes](https://github.com/iyegoroff/spectypes)
4950
* [stnl](https://github.com/re-utils/stnl)

cases/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const cases = [
3131
'sinclair-typebox-ahead-of-time',
3232
'sinclair-typebox-dynamic',
3333
'sinclair-typebox-just-in-time',
34+
'sinclair-typemap-valibot',
35+
'sinclair-typemap-zod',
3436
'spectypes',
3537
'stnl',
3638
'succulent',

cases/sinclair-typemap-valibot.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { createCase } from '../benchmarks';
2+
import { Compile } from '@sinclair/typemap';
3+
import { object, number, string, boolean, strictObject } from 'valibot';
4+
5+
const LooseSchema = Compile(
6+
object({
7+
number: number(),
8+
negNumber: number(),
9+
maxNumber: number(),
10+
string: string(),
11+
longString: string(),
12+
boolean: boolean(),
13+
deeplyNested: object({
14+
foo: string(),
15+
num: number(),
16+
bool: boolean(),
17+
}),
18+
}),
19+
);
20+
21+
const StrictSchema = Compile(
22+
strictObject({
23+
number: number(),
24+
negNumber: number(),
25+
maxNumber: number(),
26+
string: string(),
27+
longString: string(),
28+
boolean: boolean(),
29+
deeplyNested: strictObject({
30+
foo: string(),
31+
num: number(),
32+
bool: boolean(),
33+
}),
34+
}),
35+
);
36+
37+
createCase('@sinclair/typemap/valibot', 'assertLoose', () => {
38+
return data => {
39+
if (!LooseSchema.Check(data)) {
40+
throw new Error('validation failure');
41+
}
42+
return true;
43+
};
44+
});
45+
createCase('@sinclair/typemap/valibot', 'assertStrict', () => {
46+
return data => {
47+
if (!StrictSchema.Check(data)) {
48+
throw new Error('validation failure');
49+
}
50+
return true;
51+
};
52+
});

cases/sinclair-typemap-zod.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { createCase } from '../benchmarks';
2+
import { Compile } from '@sinclair/typemap';
3+
import * as z from 'zod';
4+
5+
const LooseSchema = Compile(
6+
z
7+
.object({
8+
number: z.number(),
9+
negNumber: z.number(),
10+
maxNumber: z.number(),
11+
string: z.string(),
12+
longString: z.string(),
13+
boolean: z.boolean(),
14+
deeplyNested: z
15+
.object({
16+
foo: z.string(),
17+
num: z.number(),
18+
bool: z.boolean(),
19+
})
20+
.passthrough(),
21+
})
22+
.passthrough(),
23+
);
24+
25+
const StrictSchema = Compile(
26+
z
27+
.object({
28+
number: z.number(),
29+
negNumber: z.number(),
30+
maxNumber: z.number(),
31+
string: z.string(),
32+
longString: z.string(),
33+
boolean: z.boolean(),
34+
deeplyNested: z
35+
.object({
36+
foo: z.string(),
37+
num: z.number(),
38+
bool: z.boolean(),
39+
})
40+
.strict(),
41+
})
42+
.strict(),
43+
);
44+
45+
createCase('@sinclair/typemap/zod', 'assertLoose', () => {
46+
return data => {
47+
if (!LooseSchema.Check(data)) {
48+
throw new Error('validation failure');
49+
}
50+
return true;
51+
};
52+
});
53+
createCase('@sinclair/typemap/zod', 'assertStrict', () => {
54+
return data => {
55+
if (!StrictSchema.Check(data)) {
56+
throw new Error('validation failure');
57+
}
58+
return true;
59+
};
60+
});

package-lock.json

Lines changed: 25 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@mondrian-framework/model": "2.0.68",
4343
"@sapphire/shapeshift": "3.9.7",
4444
"@sinclair/typebox": "0.34.30",
45+
"@sinclair/typemap": "0.8.19",
4546
"@skarab/tson": "1.5.1",
4647
"@toi/toi": "1.3.0",
4748
"@typeofweb/schema": "0.7.3",
@@ -99,7 +100,7 @@
99100
"typia": "8.0.1",
100101
"undici": "7.5.0",
101102
"unknownutil": "3.18.1",
102-
"valibot": "0.42.1",
103+
"valibot": "1.0.0-rc.4",
103104
"vality": "6.3.4",
104105
"vega": "5.31.0",
105106
"vega-lite": "5.11.0",

test/benchmarks.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import '../cases/simple-runtypes';
3636
import '../cases/sinclair-typebox-ahead-of-time';
3737
import '../cases/sinclair-typebox-dynamic';
3838
import '../cases/sinclair-typebox-just-in-time';
39+
import '../cases/sinclair-typemap-valibot';
40+
import '../cases/sinclair-typemap-zod';
3941
import '../cases/spectypes';
4042
import '../cases/stnl';
4143
import '../cases/succulent';

0 commit comments

Comments
 (0)