Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
49
node_modules/zod/dist/esm/v3/benchmarks/datetime.js
generated
vendored
Normal file
49
node_modules/zod/dist/esm/v3/benchmarks/datetime.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import Benchmark from "benchmark";
|
||||
const datetimeValidationSuite = new Benchmark.Suite("datetime");
|
||||
const DATA = "2021-01-01";
|
||||
const MONTHS_31 = new Set([1, 3, 5, 7, 8, 10, 12]);
|
||||
const MONTHS_30 = new Set([4, 6, 9, 11]);
|
||||
const simpleDatetimeRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
|
||||
const datetimeRegexNoLeapYearValidation = /^\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\d|2\d))$/;
|
||||
const datetimeRegexWithLeapYearValidation = /^((\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\d|3[01])|(0[469]|11)-(0[1-9]|[12]\d|30)|(02)-(0[1-9]|1\d|2[0-8])))$/;
|
||||
datetimeValidationSuite
|
||||
.add("new Date()", () => {
|
||||
return !Number.isNaN(new Date(DATA).getTime());
|
||||
})
|
||||
.add("regex (no validation)", () => {
|
||||
return simpleDatetimeRegex.test(DATA);
|
||||
})
|
||||
.add("regex (no leap year)", () => {
|
||||
return datetimeRegexNoLeapYearValidation.test(DATA);
|
||||
})
|
||||
.add("regex (w/ leap year)", () => {
|
||||
return datetimeRegexWithLeapYearValidation.test(DATA);
|
||||
})
|
||||
.add("capture groups + code", () => {
|
||||
const match = DATA.match(simpleDatetimeRegex);
|
||||
if (!match)
|
||||
return false;
|
||||
// Extract year, month, and day from the capture groups
|
||||
const year = Number.parseInt(match[1], 10);
|
||||
const month = Number.parseInt(match[2], 10); // month is 0-indexed in JavaScript Date, so subtract 1
|
||||
const day = Number.parseInt(match[3], 10);
|
||||
if (month === 2) {
|
||||
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
|
||||
return day <= 29;
|
||||
}
|
||||
return day <= 28;
|
||||
}
|
||||
if (MONTHS_30.has(month)) {
|
||||
return day <= 30;
|
||||
}
|
||||
if (MONTHS_31.has(month)) {
|
||||
return day <= 31;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${datetimeValidationSuite.name}: ${e.target}`);
|
||||
});
|
||||
export default {
|
||||
suites: [datetimeValidationSuite],
|
||||
};
|
74
node_modules/zod/dist/esm/v3/benchmarks/discriminatedUnion.js
generated
vendored
Normal file
74
node_modules/zod/dist/esm/v3/benchmarks/discriminatedUnion.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import Benchmark from "benchmark";
|
||||
import { z } from "zod/v3";
|
||||
const doubleSuite = new Benchmark.Suite("z.discriminatedUnion: double");
|
||||
const manySuite = new Benchmark.Suite("z.discriminatedUnion: many");
|
||||
const aSchema = z.object({
|
||||
type: z.literal("a"),
|
||||
});
|
||||
const objA = {
|
||||
type: "a",
|
||||
};
|
||||
const bSchema = z.object({
|
||||
type: z.literal("b"),
|
||||
});
|
||||
const objB = {
|
||||
type: "b",
|
||||
};
|
||||
const cSchema = z.object({
|
||||
type: z.literal("c"),
|
||||
});
|
||||
const objC = {
|
||||
type: "c",
|
||||
};
|
||||
const dSchema = z.object({
|
||||
type: z.literal("d"),
|
||||
});
|
||||
const double = z.discriminatedUnion("type", [aSchema, bSchema]);
|
||||
const many = z.discriminatedUnion("type", [aSchema, bSchema, cSchema, dSchema]);
|
||||
doubleSuite
|
||||
.add("valid: a", () => {
|
||||
double.parse(objA);
|
||||
})
|
||||
.add("valid: b", () => {
|
||||
double.parse(objB);
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
double.parse(null);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.add("invalid: wrong shape", () => {
|
||||
try {
|
||||
double.parse(objC);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${doubleSuite.name}: ${e.target}`);
|
||||
});
|
||||
manySuite
|
||||
.add("valid: a", () => {
|
||||
many.parse(objA);
|
||||
})
|
||||
.add("valid: c", () => {
|
||||
many.parse(objC);
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
many.parse(null);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.add("invalid: wrong shape", () => {
|
||||
try {
|
||||
many.parse({ type: "unknown" });
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${manySuite.name}: ${e.target}`);
|
||||
});
|
||||
export default {
|
||||
suites: [doubleSuite, manySuite],
|
||||
};
|
54
node_modules/zod/dist/esm/v3/benchmarks/index.js
generated
vendored
Normal file
54
node_modules/zod/dist/esm/v3/benchmarks/index.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import datetimeBenchmarks from "./datetime.js";
|
||||
import discriminatedUnionBenchmarks from "./discriminatedUnion.js";
|
||||
import ipv4Benchmarks from "./ipv4.js";
|
||||
import objectBenchmarks from "./object.js";
|
||||
import primitiveBenchmarks from "./primitives.js";
|
||||
import realworld from "./realworld.js";
|
||||
import stringBenchmarks from "./string.js";
|
||||
import unionBenchmarks from "./union.js";
|
||||
const argv = process.argv.slice(2);
|
||||
let suites = [];
|
||||
if (!argv.length) {
|
||||
suites = [
|
||||
...realworld.suites,
|
||||
...primitiveBenchmarks.suites,
|
||||
...stringBenchmarks.suites,
|
||||
...objectBenchmarks.suites,
|
||||
...unionBenchmarks.suites,
|
||||
...discriminatedUnionBenchmarks.suites,
|
||||
];
|
||||
}
|
||||
else {
|
||||
if (argv.includes("--realworld")) {
|
||||
suites.push(...realworld.suites);
|
||||
}
|
||||
if (argv.includes("--primitives")) {
|
||||
suites.push(...primitiveBenchmarks.suites);
|
||||
}
|
||||
if (argv.includes("--string")) {
|
||||
suites.push(...stringBenchmarks.suites);
|
||||
}
|
||||
if (argv.includes("--object")) {
|
||||
suites.push(...objectBenchmarks.suites);
|
||||
}
|
||||
if (argv.includes("--union")) {
|
||||
suites.push(...unionBenchmarks.suites);
|
||||
}
|
||||
if (argv.includes("--discriminatedUnion")) {
|
||||
suites.push(...datetimeBenchmarks.suites);
|
||||
}
|
||||
if (argv.includes("--datetime")) {
|
||||
suites.push(...datetimeBenchmarks.suites);
|
||||
}
|
||||
if (argv.includes("--ipv4")) {
|
||||
suites.push(...ipv4Benchmarks.suites);
|
||||
}
|
||||
}
|
||||
for (const suite of suites) {
|
||||
suite.run({});
|
||||
}
|
||||
// exit on Ctrl-C
|
||||
process.on("SIGINT", function () {
|
||||
console.log("Exiting...");
|
||||
process.exit();
|
||||
});
|
49
node_modules/zod/dist/esm/v3/benchmarks/ipv4.js
generated
vendored
Normal file
49
node_modules/zod/dist/esm/v3/benchmarks/ipv4.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import Benchmark from "benchmark";
|
||||
const suite = new Benchmark.Suite("ipv4");
|
||||
const DATA = "127.0.0.1";
|
||||
const ipv4RegexA = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
|
||||
const ipv4RegexB = /^(?:(?:(?=(25[0-5]))\1|(?=(2[0-4][0-9]))\2|(?=(1[0-9]{2}))\3|(?=([0-9]{1,2}))\4)\.){3}(?:(?=(25[0-5]))\5|(?=(2[0-4][0-9]))\6|(?=(1[0-9]{2}))\7|(?=([0-9]{1,2}))\8)$/;
|
||||
const ipv4RegexC = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
|
||||
const ipv4RegexD = /^(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/;
|
||||
const ipv4RegexE = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]|)\d)$/;
|
||||
const ipv4RegexF = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
|
||||
const ipv4RegexG = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/;
|
||||
const ipv4RegexH = /^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$/;
|
||||
const ipv4RegexI = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
||||
suite
|
||||
.add("A", () => {
|
||||
return ipv4RegexA.test(DATA);
|
||||
})
|
||||
.add("B", () => {
|
||||
return ipv4RegexB.test(DATA);
|
||||
})
|
||||
.add("C", () => {
|
||||
return ipv4RegexC.test(DATA);
|
||||
})
|
||||
.add("D", () => {
|
||||
return ipv4RegexD.test(DATA);
|
||||
})
|
||||
.add("E", () => {
|
||||
return ipv4RegexE.test(DATA);
|
||||
})
|
||||
.add("F", () => {
|
||||
return ipv4RegexF.test(DATA);
|
||||
})
|
||||
.add("G", () => {
|
||||
return ipv4RegexG.test(DATA);
|
||||
})
|
||||
.add("H", () => {
|
||||
return ipv4RegexH.test(DATA);
|
||||
})
|
||||
.add("I", () => {
|
||||
return ipv4RegexI.test(DATA);
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${suite.name}: ${e.target}`);
|
||||
});
|
||||
export default {
|
||||
suites: [suite],
|
||||
};
|
||||
if (require.main === module) {
|
||||
suite.run();
|
||||
}
|
65
node_modules/zod/dist/esm/v3/benchmarks/object.js
generated
vendored
Normal file
65
node_modules/zod/dist/esm/v3/benchmarks/object.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
import Benchmark from "benchmark";
|
||||
import { z } from "zod/v3";
|
||||
const emptySuite = new Benchmark.Suite("z.object: empty");
|
||||
const shortSuite = new Benchmark.Suite("z.object: short");
|
||||
const longSuite = new Benchmark.Suite("z.object: long");
|
||||
const empty = z.object({});
|
||||
const short = z.object({
|
||||
string: z.string(),
|
||||
});
|
||||
const long = z.object({
|
||||
string: z.string(),
|
||||
number: z.number(),
|
||||
boolean: z.boolean(),
|
||||
});
|
||||
emptySuite
|
||||
.add("valid", () => {
|
||||
empty.parse({});
|
||||
})
|
||||
.add("valid: extra keys", () => {
|
||||
empty.parse({ string: "string" });
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
empty.parse(null);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${emptySuite.name}: ${e.target}`);
|
||||
});
|
||||
shortSuite
|
||||
.add("valid", () => {
|
||||
short.parse({ string: "string" });
|
||||
})
|
||||
.add("valid: extra keys", () => {
|
||||
short.parse({ string: "string", number: 42 });
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
short.parse(null);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${shortSuite.name}: ${e.target}`);
|
||||
});
|
||||
longSuite
|
||||
.add("valid", () => {
|
||||
long.parse({ string: "string", number: 42, boolean: true });
|
||||
})
|
||||
.add("valid: extra keys", () => {
|
||||
long.parse({ string: "string", number: 42, boolean: true, list: [] });
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
long.parse(null);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${longSuite.name}: ${e.target}`);
|
||||
});
|
||||
export default {
|
||||
suites: [emptySuite, shortSuite, longSuite],
|
||||
};
|
154
node_modules/zod/dist/esm/v3/benchmarks/primitives.js
generated
vendored
Normal file
154
node_modules/zod/dist/esm/v3/benchmarks/primitives.js
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
import Benchmark from "benchmark";
|
||||
import { z } from "zod/v3";
|
||||
import { Mocker } from "../tests/Mocker.js";
|
||||
const val = new Mocker();
|
||||
const enumSuite = new Benchmark.Suite("z.enum");
|
||||
const enumSchema = z.enum(["a", "b", "c"]);
|
||||
enumSuite
|
||||
.add("valid", () => {
|
||||
enumSchema.parse("a");
|
||||
})
|
||||
.add("invalid", () => {
|
||||
try {
|
||||
enumSchema.parse("x");
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`z.enum: ${e.target}`);
|
||||
});
|
||||
const longEnumSuite = new Benchmark.Suite("long z.enum");
|
||||
const longEnumSchema = z.enum([
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
"four",
|
||||
"five",
|
||||
"six",
|
||||
"seven",
|
||||
"eight",
|
||||
"nine",
|
||||
"ten",
|
||||
"eleven",
|
||||
"twelve",
|
||||
"thirteen",
|
||||
"fourteen",
|
||||
"fifteen",
|
||||
"sixteen",
|
||||
"seventeen",
|
||||
]);
|
||||
longEnumSuite
|
||||
.add("valid", () => {
|
||||
longEnumSchema.parse("five");
|
||||
})
|
||||
.add("invalid", () => {
|
||||
try {
|
||||
longEnumSchema.parse("invalid");
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`long z.enum: ${e.target}`);
|
||||
});
|
||||
const undefinedSuite = new Benchmark.Suite("z.undefined");
|
||||
const undefinedSchema = z.undefined();
|
||||
undefinedSuite
|
||||
.add("valid", () => {
|
||||
undefinedSchema.parse(undefined);
|
||||
})
|
||||
.add("invalid", () => {
|
||||
try {
|
||||
undefinedSchema.parse(1);
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`z.undefined: ${e.target}`);
|
||||
});
|
||||
const literalSuite = new Benchmark.Suite("z.literal");
|
||||
const short = "short";
|
||||
const bad = "bad";
|
||||
const literalSchema = z.literal("short");
|
||||
literalSuite
|
||||
.add("valid", () => {
|
||||
literalSchema.parse(short);
|
||||
})
|
||||
.add("invalid", () => {
|
||||
try {
|
||||
literalSchema.parse(bad);
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`z.literal: ${e.target}`);
|
||||
});
|
||||
const numberSuite = new Benchmark.Suite("z.number");
|
||||
const numberSchema = z.number().int();
|
||||
numberSuite
|
||||
.add("valid", () => {
|
||||
numberSchema.parse(1);
|
||||
})
|
||||
.add("invalid type", () => {
|
||||
try {
|
||||
numberSchema.parse("bad");
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.add("invalid number", () => {
|
||||
try {
|
||||
numberSchema.parse(0.5);
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`z.number: ${e.target}`);
|
||||
});
|
||||
const dateSuite = new Benchmark.Suite("z.date");
|
||||
const plainDate = z.date();
|
||||
const minMaxDate = z.date().min(new Date("2021-01-01")).max(new Date("2030-01-01"));
|
||||
dateSuite
|
||||
.add("valid", () => {
|
||||
plainDate.parse(new Date());
|
||||
})
|
||||
.add("invalid", () => {
|
||||
try {
|
||||
plainDate.parse(1);
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.add("valid min and max", () => {
|
||||
minMaxDate.parse(new Date("2023-01-01"));
|
||||
})
|
||||
.add("invalid min", () => {
|
||||
try {
|
||||
minMaxDate.parse(new Date("2019-01-01"));
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.add("invalid max", () => {
|
||||
try {
|
||||
minMaxDate.parse(new Date("2031-01-01"));
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`z.date: ${e.target}`);
|
||||
});
|
||||
const symbolSuite = new Benchmark.Suite("z.symbol");
|
||||
const symbolSchema = z.symbol();
|
||||
symbolSuite
|
||||
.add("valid", () => {
|
||||
symbolSchema.parse(val.symbol);
|
||||
})
|
||||
.add("invalid", () => {
|
||||
try {
|
||||
symbolSchema.parse(1);
|
||||
}
|
||||
catch (_e) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`z.symbol: ${e.target}`);
|
||||
});
|
||||
export default {
|
||||
suites: [enumSuite, longEnumSuite, undefinedSuite, literalSuite, numberSuite, dateSuite, symbolSuite],
|
||||
};
|
51
node_modules/zod/dist/esm/v3/benchmarks/realworld.js
generated
vendored
Normal file
51
node_modules/zod/dist/esm/v3/benchmarks/realworld.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import Benchmark from "benchmark";
|
||||
import { z } from "zod/v3";
|
||||
const shortSuite = new Benchmark.Suite("realworld");
|
||||
const People = z.array(z.object({
|
||||
type: z.literal("person"),
|
||||
hair: z.enum(["blue", "brown"]),
|
||||
active: z.boolean(),
|
||||
name: z.string(),
|
||||
age: z.number().int(),
|
||||
hobbies: z.array(z.string()),
|
||||
address: z.object({
|
||||
street: z.string(),
|
||||
zip: z.string(),
|
||||
country: z.string(),
|
||||
}),
|
||||
}));
|
||||
let i = 0;
|
||||
function num() {
|
||||
return ++i;
|
||||
}
|
||||
function str() {
|
||||
return (++i % 100).toString(16);
|
||||
}
|
||||
function array(fn) {
|
||||
return Array.from({ length: ++i % 10 }, () => fn());
|
||||
}
|
||||
const people = Array.from({ length: 100 }, () => {
|
||||
return {
|
||||
type: "person",
|
||||
hair: i % 2 ? "blue" : "brown",
|
||||
active: !!(i % 2),
|
||||
name: str(),
|
||||
age: num(),
|
||||
hobbies: array(str),
|
||||
address: {
|
||||
street: str(),
|
||||
zip: str(),
|
||||
country: str(),
|
||||
},
|
||||
};
|
||||
});
|
||||
shortSuite
|
||||
.add("valid", () => {
|
||||
People.parse(people);
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${shortSuite.name}: ${e.target}`);
|
||||
});
|
||||
export default {
|
||||
suites: [shortSuite],
|
||||
};
|
50
node_modules/zod/dist/esm/v3/benchmarks/string.js
generated
vendored
Normal file
50
node_modules/zod/dist/esm/v3/benchmarks/string.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import Benchmark from "benchmark";
|
||||
import { z } from "zod/v3";
|
||||
const SUITE_NAME = "z.string";
|
||||
const suite = new Benchmark.Suite(SUITE_NAME);
|
||||
const empty = "";
|
||||
const short = "short";
|
||||
const long = "long".repeat(256);
|
||||
const manual = (str) => {
|
||||
if (typeof str !== "string") {
|
||||
throw new Error("Not a string");
|
||||
}
|
||||
return str;
|
||||
};
|
||||
const stringSchema = z.string();
|
||||
const optionalStringSchema = z.string().optional();
|
||||
const optionalNullableStringSchema = z.string().optional().nullable();
|
||||
suite
|
||||
.add("empty string", () => {
|
||||
stringSchema.parse(empty);
|
||||
})
|
||||
.add("short string", () => {
|
||||
stringSchema.parse(short);
|
||||
})
|
||||
.add("long string", () => {
|
||||
stringSchema.parse(long);
|
||||
})
|
||||
.add("optional string", () => {
|
||||
optionalStringSchema.parse(long);
|
||||
})
|
||||
.add("nullable string", () => {
|
||||
optionalNullableStringSchema.parse(long);
|
||||
})
|
||||
.add("nullable (null) string", () => {
|
||||
optionalNullableStringSchema.parse(null);
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
stringSchema.parse(null);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.add("manual parser: long", () => {
|
||||
manual(long);
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${SUITE_NAME}: ${e.target}`);
|
||||
});
|
||||
export default {
|
||||
suites: [suite],
|
||||
};
|
74
node_modules/zod/dist/esm/v3/benchmarks/union.js
generated
vendored
Normal file
74
node_modules/zod/dist/esm/v3/benchmarks/union.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import Benchmark from "benchmark";
|
||||
import { z } from "zod/v3";
|
||||
const doubleSuite = new Benchmark.Suite("z.union: double");
|
||||
const manySuite = new Benchmark.Suite("z.union: many");
|
||||
const aSchema = z.object({
|
||||
type: z.literal("a"),
|
||||
});
|
||||
const objA = {
|
||||
type: "a",
|
||||
};
|
||||
const bSchema = z.object({
|
||||
type: z.literal("b"),
|
||||
});
|
||||
const objB = {
|
||||
type: "b",
|
||||
};
|
||||
const cSchema = z.object({
|
||||
type: z.literal("c"),
|
||||
});
|
||||
const objC = {
|
||||
type: "c",
|
||||
};
|
||||
const dSchema = z.object({
|
||||
type: z.literal("d"),
|
||||
});
|
||||
const double = z.union([aSchema, bSchema]);
|
||||
const many = z.union([aSchema, bSchema, cSchema, dSchema]);
|
||||
doubleSuite
|
||||
.add("valid: a", () => {
|
||||
double.parse(objA);
|
||||
})
|
||||
.add("valid: b", () => {
|
||||
double.parse(objB);
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
double.parse(null);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.add("invalid: wrong shape", () => {
|
||||
try {
|
||||
double.parse(objC);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${doubleSuite.name}: ${e.target}`);
|
||||
});
|
||||
manySuite
|
||||
.add("valid: a", () => {
|
||||
many.parse(objA);
|
||||
})
|
||||
.add("valid: c", () => {
|
||||
many.parse(objC);
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
many.parse(null);
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.add("invalid: wrong shape", () => {
|
||||
try {
|
||||
many.parse({ type: "unknown" });
|
||||
}
|
||||
catch (_err) { }
|
||||
})
|
||||
.on("cycle", (e) => {
|
||||
console.log(`${manySuite.name}: ${e.target}`);
|
||||
});
|
||||
export default {
|
||||
suites: [doubleSuite, manySuite],
|
||||
};
|
Reference in New Issue
Block a user