Linux websever 5.15.0-153-generic #163-Ubuntu SMP Thu Aug 7 16:37:18 UTC 2025 x86_64
Apache/2.4.52 (Ubuntu)
: 192.168.3.70 | : 192.168.1.99
Cant Read [ /etc/named.conf ]
8.1.2-1ubuntu2.23
urlab
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
var /
www /
html /
cqt /
node_modules /
zod /
src /
v3 /
tests /
[ HOME SHELL ]
Name
Size
Permission
Action
Mocker.ts
1.31
KB
-rw-r--r--
all-errors.test.ts
4.64
KB
-rw-r--r--
anyunknown.test.ts
673
B
-rw-r--r--
array.test.ts
1.89
KB
-rw-r--r--
async-parsing.test.ts
12.34
KB
-rw-r--r--
async-refinements.test.ts
1.57
KB
-rw-r--r--
base.test.ts
782
B
-rw-r--r--
bigint.test.ts
1.93
KB
-rw-r--r--
branded.test.ts
1.69
KB
-rw-r--r--
catch.test.ts
6.4
KB
-rw-r--r--
coerce.test.ts
6.49
KB
-rw-r--r--
complex.test.ts
1.87
KB
-rw-r--r--
custom.test.ts
950
B
-rw-r--r--
date.test.ts
983
B
-rw-r--r--
deepmasking.test.ts
5.09
KB
-rw-r--r--
default.test.ts
3.44
KB
-rw-r--r--
description.test.ts
1.29
KB
-rw-r--r--
discriminated-unions.test.ts
8.34
KB
-rw-r--r--
enum.test.ts
2.67
KB
-rw-r--r--
error.test.ts
16.42
KB
-rw-r--r--
firstparty.test.ts
2.33
KB
-rw-r--r--
firstpartyschematypes.test.ts
788
B
-rw-r--r--
function.test.ts
6.42
KB
-rw-r--r--
generics.test.ts
1.49
KB
-rw-r--r--
instanceof.test.ts
1.13
KB
-rw-r--r--
intersection.test.ts
3.02
KB
-rw-r--r--
language-server.source.ts
1.25
KB
-rw-r--r--
language-server.test.ts
8.12
KB
-rw-r--r--
literal.test.ts
1.04
KB
-rw-r--r--
map.test.ts
3.46
KB
-rw-r--r--
masking.test.ts
85
B
-rw-r--r--
mocker.test.ts
389
B
-rw-r--r--
nan.test.ts
587
B
-rw-r--r--
nativeEnum.test.ts
2.29
KB
-rw-r--r--
nullable.test.ts
1.14
KB
-rw-r--r--
number.test.ts
6.22
KB
-rw-r--r--
object-augmentation.test.ts
569
B
-rw-r--r--
object-in-es5-env.test.ts
778
B
-rw-r--r--
object.test.ts
11.5
KB
-rw-r--r--
optional.test.ts
1.19
KB
-rw-r--r--
parseUtil.test.ts
869
B
-rw-r--r--
parser.test.ts
1.1
KB
-rw-r--r--
partials.test.ts
6.83
KB
-rw-r--r--
pickomit.test.ts
3.54
KB
-rw-r--r--
pipeline.test.ts
823
B
-rw-r--r--
preprocess.test.ts
4.42
KB
-rw-r--r--
primitive.test.ts
11.93
KB
-rw-r--r--
promise.test.ts
2.43
KB
-rw-r--r--
readonly.test.ts
7.17
KB
-rw-r--r--
record.test.ts
3.65
KB
-rw-r--r--
recursive.test.ts
3.85
KB
-rw-r--r--
refine.test.ts
7.98
KB
-rw-r--r--
safeparse.test.ts
628
B
-rw-r--r--
set.test.ts
4.68
KB
-rw-r--r--
standard-schema.test.ts
2.53
KB
-rw-r--r--
string.test.ts
64.08
KB
-rw-r--r--
transformer.test.ts
5.55
KB
-rw-r--r--
tuple.test.ts
2.63
KB
-rw-r--r--
unions.test.ts
1.5
KB
-rw-r--r--
validations.test.ts
3.74
KB
-rw-r--r--
void.test.ts
349
B
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : discriminated-unions.test.ts
// @ts-ignore TS6133 import { expect, test } from "vitest"; import * as z from "zod/v3"; test("valid", () => { expect( z .discriminatedUnion("type", [ z.object({ type: z.literal("a"), a: z.string() }), z.object({ type: z.literal("b"), b: z.string() }), ]) .parse({ type: "a", a: "abc" }) ).toEqual({ type: "a", a: "abc" }); }); test("valid - discriminator value of various primitive types", () => { const schema = z.discriminatedUnion("type", [ z.object({ type: z.literal("1"), val: z.literal(1) }), z.object({ type: z.literal(1), val: z.literal(2) }), z.object({ type: z.literal(BigInt(1)), val: z.literal(3) }), z.object({ type: z.literal("true"), val: z.literal(4) }), z.object({ type: z.literal(true), val: z.literal(5) }), z.object({ type: z.literal("null"), val: z.literal(6) }), z.object({ type: z.literal(null), val: z.literal(7) }), z.object({ type: z.literal("undefined"), val: z.literal(8) }), z.object({ type: z.literal(undefined), val: z.literal(9) }), z.object({ type: z.literal("transform"), val: z.literal(10) }), z.object({ type: z.literal("refine"), val: z.literal(11) }), z.object({ type: z.literal("superRefine"), val: z.literal(12) }), ]); expect(schema.parse({ type: "1", val: 1 })).toEqual({ type: "1", val: 1 }); expect(schema.parse({ type: 1, val: 2 })).toEqual({ type: 1, val: 2 }); expect(schema.parse({ type: BigInt(1), val: 3 })).toEqual({ type: BigInt(1), val: 3, }); expect(schema.parse({ type: "true", val: 4 })).toEqual({ type: "true", val: 4, }); expect(schema.parse({ type: true, val: 5 })).toEqual({ type: true, val: 5, }); expect(schema.parse({ type: "null", val: 6 })).toEqual({ type: "null", val: 6, }); expect(schema.parse({ type: null, val: 7 })).toEqual({ type: null, val: 7, }); expect(schema.parse({ type: "undefined", val: 8 })).toEqual({ type: "undefined", val: 8, }); expect(schema.parse({ type: undefined, val: 9 })).toEqual({ type: undefined, val: 9, }); }); test("invalid - null", () => { try { z.discriminatedUnion("type", [ z.object({ type: z.literal("a"), a: z.string() }), z.object({ type: z.literal("b"), b: z.string() }), ]).parse(null); throw new Error(); } catch (e: any) { expect(JSON.parse(e.message)).toEqual([ { code: z.ZodIssueCode.invalid_type, expected: z.ZodParsedType.object, message: "Expected object, received null", received: z.ZodParsedType.null, path: [], }, ]); } }); test("invalid discriminator value", () => { try { z.discriminatedUnion("type", [ z.object({ type: z.literal("a"), a: z.string() }), z.object({ type: z.literal("b"), b: z.string() }), ]).parse({ type: "x", a: "abc" }); throw new Error(); } catch (e: any) { expect(JSON.parse(e.message)).toEqual([ { code: z.ZodIssueCode.invalid_union_discriminator, options: ["a", "b"], message: "Invalid discriminator value. Expected 'a' | 'b'", path: ["type"], }, ]); } }); test("valid discriminator value, invalid data", () => { try { z.discriminatedUnion("type", [ z.object({ type: z.literal("a"), a: z.string() }), z.object({ type: z.literal("b"), b: z.string() }), ]).parse({ type: "a", b: "abc" }); throw new Error(); } catch (e: any) { expect(JSON.parse(e.message)).toEqual([ { code: z.ZodIssueCode.invalid_type, expected: z.ZodParsedType.string, message: "Required", path: ["a"], received: z.ZodParsedType.undefined, }, ]); } }); test("wrong schema - missing discriminator", () => { try { z.discriminatedUnion("type", [ z.object({ type: z.literal("a"), a: z.string() }), z.object({ b: z.string() }) as any, ]); throw new Error(); } catch (e: any) { expect(e.message.includes("could not be extracted")).toBe(true); } }); test("wrong schema - duplicate discriminator values", () => { try { z.discriminatedUnion("type", [ z.object({ type: z.literal("a"), a: z.string() }), z.object({ type: z.literal("a"), b: z.string() }), ]); throw new Error(); } catch (e: any) { expect(e.message.includes("has duplicate value")).toEqual(true); } }); test("async - valid", async () => { expect( await z .discriminatedUnion("type", [ z.object({ type: z.literal("a"), a: z .string() .refine(async () => true) .transform(async (val) => Number(val)), }), z.object({ type: z.literal("b"), b: z.string(), }), ]) .parseAsync({ type: "a", a: "1" }) ).toEqual({ type: "a", a: 1 }); }); test("async - invalid", async () => { try { await z .discriminatedUnion("type", [ z.object({ type: z.literal("a"), a: z .string() .refine(async () => true) .transform(async (val) => val), }), z.object({ type: z.literal("b"), b: z.string(), }), ]) .parseAsync({ type: "a", a: 1 }); throw new Error(); } catch (e: any) { expect(JSON.parse(e.message)).toEqual([ { code: "invalid_type", expected: "string", received: "number", path: ["a"], message: "Expected string, received number", }, ]); } }); test("valid - literals with .default or .preprocess", () => { const schema = z.discriminatedUnion("type", [ z.object({ type: z.literal("foo").default("foo"), a: z.string(), }), z.object({ type: z.literal("custom"), method: z.string(), }), z.object({ type: z.preprocess((val) => String(val), z.literal("bar")), c: z.string(), }), ]); expect(schema.parse({ type: "foo", a: "foo" })).toEqual({ type: "foo", a: "foo", }); }); test("enum and nativeEnum", () => { enum MyEnum { d = 0, e = "e", } const schema = z.discriminatedUnion("key", [ z.object({ key: z.literal("a"), // Add other properties specific to this option }), z.object({ key: z.enum(["b", "c"]), // Add other properties specific to this option }), z.object({ key: z.nativeEnum(MyEnum), // Add other properties specific to this option }), ]); // type schema = z.infer<typeof schema>; schema.parse({ key: "a" }); schema.parse({ key: "b" }); schema.parse({ key: "c" }); schema.parse({ key: MyEnum.d }); schema.parse({ key: MyEnum.e }); schema.parse({ key: "e" }); }); test("branded", () => { const schema = z.discriminatedUnion("key", [ z.object({ key: z.literal("a"), // Add other properties specific to this option }), z.object({ key: z.literal("b").brand("asdfaf"), // Add other properties specific to this option }), ]); // type schema = z.infer<typeof schema>; schema.parse({ key: "a" }); schema.parse({ key: "b" }); expect(() => { schema.parse({ key: "c" }); }).toThrow(); }); test("optional and nullable", () => { const schema = z.discriminatedUnion("key", [ z.object({ key: z.literal("a").optional(), a: z.literal(true), }), z.object({ key: z.literal("b").nullable(), b: z.literal(true), // Add other properties specific to this option }), ]); type schema = z.infer<typeof schema>; z.util.assertEqual<schema, { key?: "a" | undefined; a: true } | { key: "b" | null; b: true }>(true); schema.parse({ key: "a", a: true }); schema.parse({ key: undefined, a: true }); schema.parse({ key: "b", b: true }); schema.parse({ key: null, b: true }); expect(() => { schema.parse({ key: null, a: true }); }).toThrow(); expect(() => { schema.parse({ key: "b", a: true }); }).toThrow(); const value = schema.parse({ key: null, b: true }); if (!("key" in value)) value.a; if (value.key === undefined) value.a; if (value.key === "a") value.a; if (value.key === "b") value.b; if (value.key === null) value.b; }); test("readonly array of options", () => { const options = [ z.object({ type: z.literal("x"), val: z.literal(1) }), z.object({ type: z.literal("y"), val: z.literal(2) }), ] as const; expect(z.discriminatedUnion("type", options).parse({ type: "x", val: 1 })).toEqual({ type: "x", val: 1 }); });
Close