-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
4,077 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: TU | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
tu: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
- run: npm ci | ||
- run: npm run test:tu:coverage | ||
- if: always() | ||
uses: davelosert/vitest-coverage-report-action@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import * as zod from "zod"; | ||
import joi from "joi"; | ||
import myzod from "myzod"; | ||
import {Type as typebox} from "@sinclair/typebox"; | ||
import {Value as typeboxValue} from "@sinclair/typebox/value"; | ||
import {ZodAccelerator} from "../scripts"; | ||
import Bench from "tinybench"; | ||
|
||
const zodSchema = zod.object({ | ||
firstname: zod.string(), | ||
lastname: zod.string(), | ||
age: zod.number(), | ||
email: zod.string(), | ||
gender: zod.enum(["boy", "girl"]), | ||
connected: zod.boolean(), | ||
createdAt: zod.date(), | ||
addresse: zod.object({ | ||
postCode: zod.string(), | ||
city: zod.string(), | ||
number: zod.number() | ||
}), | ||
}).array(); | ||
const joiSchema = joi.array().items( | ||
joi.object({ | ||
firstname: joi.string(), | ||
lastname: joi.string(), | ||
age: joi.number(), | ||
email: joi.string(), | ||
gender: joi.string().valid("boy", "girl"), | ||
connected: joi.boolean(), | ||
createdAt: joi.date(), | ||
addresse: joi.object({ | ||
postCode: joi.string(), | ||
city: joi.string(), | ||
number: joi.number() | ||
}), | ||
}) | ||
); | ||
const myzodSchema = myzod.array( | ||
myzod.object({ | ||
firstname: myzod.string(), | ||
lastname: myzod.string(), | ||
age: myzod.number(), | ||
email: myzod.string(), | ||
gender: myzod.enum(["boy", "girl"]), | ||
connected: myzod.boolean(), | ||
createdAt: myzod.date(), | ||
addresse: myzod.object({ | ||
postCode: myzod.string(), | ||
city: myzod.string(), | ||
number: myzod.number() | ||
}), | ||
}) | ||
); | ||
enum typeboxGender { | ||
boy, | ||
girl | ||
} | ||
const typeboxSchema = typebox.Array( | ||
typebox.Object({ | ||
firstname: typebox.String(), | ||
lastname: typebox.String(), | ||
age: typebox.Number(), | ||
email: typebox.String(), | ||
gender: typebox.Enum(typeboxGender), | ||
connected: typebox.Boolean(), | ||
createdAt: typebox.Date(), | ||
addresse: typebox.Object({ | ||
postCode: typebox.String(), | ||
city: typebox.String(), | ||
number: typebox.Number() | ||
}), | ||
}) | ||
); | ||
const zodAccelerateSchema = ZodAccelerator.build(zodSchema); | ||
|
||
const bench = new Bench({time: 100}); | ||
|
||
const data = Array.from({length: 10}).fill({ | ||
firstname: " Mike ", | ||
lastname: "ee", | ||
age: 21, | ||
email: "test@gmail.com", | ||
gender: "girl", | ||
connected: true, | ||
createdAt: new Date(), | ||
addresse: { | ||
postCode: "22778", | ||
city: "Paris", | ||
number: 67 | ||
}, | ||
}); | ||
|
||
bench | ||
.add("zod", () => { | ||
zodSchema.parse(data); | ||
}) | ||
.add("joi", () => { | ||
joiSchema.validate(data); | ||
}) | ||
.add("@sinclair/typebox", () => { | ||
typeboxValue.Check(typeboxSchema, data); | ||
}) | ||
.add("myzod", () => { | ||
myzodSchema.parse(data); | ||
}) | ||
.add("zodAccelerator", () => { | ||
zodAccelerateSchema.parse(data); | ||
}); | ||
|
||
(async() => { | ||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
console.log("Result test Array :"); | ||
console.table(bench.table()); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import * as zod from "zod"; | ||
import joi from "joi"; | ||
import myzod from "myzod"; | ||
import {Type as typebox} from "@sinclair/typebox"; | ||
import {Value as typeboxValue} from "@sinclair/typebox/value"; | ||
import {ZodAccelerator} from "../scripts"; | ||
import Bench from "tinybench"; | ||
|
||
const zodSchema = zod.object({ | ||
firstname: zod.string(), | ||
lastname: zod.string(), | ||
age: zod.number(), | ||
email: zod.string(), | ||
gender: zod.enum(["boy", "girl"]), | ||
connected: zod.boolean(), | ||
createdAt: zod.date(), | ||
addresse: zod.object({ | ||
postCode: zod.string(), | ||
city: zod.string(), | ||
number: zod.number() | ||
}), | ||
}); | ||
const joiSchema = joi.object({ | ||
firstname: joi.string(), | ||
lastname: joi.string(), | ||
age: joi.number(), | ||
email: joi.string(), | ||
gender: joi.string().valid("boy", "girl"), | ||
connected: joi.boolean(), | ||
createdAt: joi.date(), | ||
addresse: joi.object({ | ||
postCode: joi.string(), | ||
city: joi.string(), | ||
number: joi.number() | ||
}), | ||
}); | ||
const myzodSchema = myzod.object({ | ||
firstname: myzod.string(), | ||
lastname: myzod.string(), | ||
age: myzod.number(), | ||
email: myzod.string(), | ||
gender: myzod.enum(["boy", "girl"]), | ||
connected: myzod.boolean(), | ||
createdAt: myzod.date(), | ||
addresse: myzod.object({ | ||
postCode: myzod.string(), | ||
city: myzod.string(), | ||
number: myzod.number() | ||
}), | ||
}); | ||
enum typeboxGender { | ||
boy, | ||
girl | ||
} | ||
const typeboxSchema = typebox.Object({ | ||
firstname: typebox.String(), | ||
lastname: typebox.String(), | ||
age: typebox.Number(), | ||
email: typebox.String(), | ||
gender: typebox.Enum(typeboxGender), | ||
connected: typebox.Boolean(), | ||
createdAt: typebox.Date(), | ||
addresse: typebox.Object({ | ||
postCode: typebox.String(), | ||
city: typebox.String(), | ||
number: typebox.Number() | ||
}), | ||
}); | ||
const zodAccelerateSchema = ZodAccelerator.build(zodSchema); | ||
|
||
const bench = new Bench({time: 100}); | ||
|
||
const data = { | ||
firstname: " Mike ", | ||
lastname: "ee", | ||
age: 21, | ||
email: "test@gmail.com", | ||
gender: "girl", | ||
connected: true, | ||
createdAt: new Date(), | ||
addresse: { | ||
postCode: "22778", | ||
city: "Paris", | ||
number: 67 | ||
}, | ||
}; | ||
|
||
bench | ||
.add("zod", () => { | ||
zodSchema.parse(data); | ||
}) | ||
.add("joi", () => { | ||
joiSchema.validate(data); | ||
}) | ||
.add("@sinclair/typebox", () => { | ||
typeboxValue.Check(typeboxSchema, data); | ||
}) | ||
.add("myzod", () => { | ||
myzodSchema.parse(data); | ||
}) | ||
.add("zodAccelerator", () => { | ||
zodAccelerateSchema.parse(data); | ||
}); | ||
|
||
(async() => { | ||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
console.log("Result test Object :"); | ||
console.table(bench.table()); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as zod from "zod"; | ||
import joi from "joi"; | ||
import myzod from "myzod"; | ||
import {Type as typebox} from "@sinclair/typebox"; | ||
import {Value as typeboxValue} from "@sinclair/typebox/value"; | ||
import {ZodAccelerator} from "../scripts"; | ||
import Bench from "tinybench"; | ||
|
||
const zodSchema = zod.string(); | ||
const joiSchema = joi.string(); | ||
const myzodSchema = myzod.string(); | ||
const typeboxSchema = typebox.String(); | ||
const zodAccelerateSchema = ZodAccelerator.build(zodSchema); | ||
|
||
const bench = new Bench({time: 100}); | ||
const data = "this is a nice test"; | ||
|
||
bench | ||
.add("zod", () => { | ||
zodSchema.parse(data); | ||
}) | ||
.add("joi", () => { | ||
joiSchema.validate(data); | ||
}) | ||
.add("@sinclair/typebox", () => { | ||
typeboxValue.Check(typeboxSchema, data); | ||
}) | ||
.add("myzod", () => { | ||
myzodSchema.parse(data); | ||
}) | ||
.add("zodAccelerator", () => { | ||
zodAccelerateSchema.parse(data); | ||
}); | ||
|
||
(async() => { | ||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
console.log("Result test String :"); | ||
console.table(bench.table()); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as zod from "zod"; | ||
import joi from "joi"; | ||
import myzod from "myzod"; | ||
import {Type as typebox} from "@sinclair/typebox"; | ||
import {Value as typeboxValue} from "@sinclair/typebox/value"; | ||
import {ZodAccelerator} from "../scripts"; | ||
import Bench from "tinybench"; | ||
|
||
const zodSchema = zod.union([ | ||
zod.literal("123"), | ||
zod.literal("456"), | ||
zod.object({ | ||
test: zod.string() | ||
}), | ||
]); | ||
const joiSchema = null; | ||
const myzodSchema = myzod.union([ | ||
myzod.literal("123"), | ||
myzod.literal("456"), | ||
myzod.object({ | ||
test: myzod.string() | ||
}), | ||
]); | ||
const typeboxSchema = typebox.Union([ | ||
typebox.Literal("123"), | ||
typebox.Literal("456"), | ||
typebox.Object({ | ||
test: typebox.String() | ||
}), | ||
]); | ||
const zodAccelerateSchema = ZodAccelerator.build(zodSchema); | ||
|
||
|
||
const bench = new Bench({time: 100}); | ||
const data = { | ||
test: "test" | ||
}; | ||
|
||
bench | ||
.add("zod", () => { | ||
zodSchema.parse(data); | ||
}) | ||
.add("joi", () => { | ||
throw joiSchema; | ||
}) | ||
.add("@sinclair/typebox", () => { | ||
typeboxValue.Check(typeboxSchema, data); | ||
}) | ||
.add("myzod", () => { | ||
myzodSchema.parse(data); | ||
}) | ||
.add("zodAccelerator", () => { | ||
zodAccelerateSchema.parse(data); | ||
}); | ||
|
||
(async() => { | ||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
console.log("Result test Union :"); | ||
console.table(bench.table()); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// https://github.dev/colinhacks/zod | ||
|
||
import "./lib/accelerators/string"; | ||
import "./lib/accelerators/number"; | ||
import "./lib/accelerators/object"; | ||
import "./lib/accelerators/array"; | ||
import "./lib/accelerators/enum"; | ||
import "./lib/accelerators/boolean"; | ||
import "./lib/accelerators/nullable"; | ||
import "./lib/accelerators/date"; | ||
import "./lib/accelerators/symbol"; | ||
import "./lib/accelerators/undefined"; | ||
import "./lib/accelerators/null"; | ||
import "./lib/accelerators/any"; | ||
import "./lib/accelerators/unknown"; | ||
import "./lib/accelerators/never"; | ||
import "./lib/accelerators/void"; | ||
import "./lib/accelerators/union"; | ||
import "./lib/accelerators/intersection"; | ||
import "./lib/accelerators/tuple"; | ||
import "./lib/accelerators/default"; | ||
import "./lib/accelerators/branded"; | ||
import "./lib/accelerators/nan"; | ||
import "./lib/accelerators/optional"; | ||
import "./lib/accelerators/catch"; | ||
import "./lib/accelerators/record"; | ||
import "./lib/accelerators/literal"; | ||
import "./lib/accelerators/readonly"; | ||
import "./lib/accelerators/bigInt"; | ||
import "./lib/accelerators/effects"; | ||
|
||
export * from "./lib/accelerator"; |
Oops, something went wrong.