forked from colinhacks/zod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrazySchema.ts
42 lines (40 loc) · 1.4 KB
/
crazySchema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as z from "../index";
export const crazySchema = z.object({
tuple: z.tuple([
z.string().nullable().optional(),
z.number().nullable().optional(),
z.boolean().nullable().optional(),
z.null().nullable().optional(),
z.undefined().nullable().optional(),
z.literal("1234").nullable().optional(),
]),
merged: z
.object({
k1: z.string().optional(),
})
.merge(z.object({ k1: z.string().nullable(), k2: z.number() })),
union: z.array(z.union([z.literal("asdf"), z.literal(12)])).nonempty(),
array: z.array(z.number()),
// sumTransformer: z.transformer(z.array(z.number()), z.number(), (arg) => {
// return arg.reduce((a, b) => a + b, 0);
// }),
sumMinLength: z.array(z.number()).refine((arg) => arg.length > 5),
intersection: z.intersection(
z.object({ p1: z.string().optional() }),
z.object({ p1: z.number().optional() })
),
enum: z.intersection(z.enum(["zero", "one"]), z.enum(["one", "two"])),
nonstrict: z.object({ points: z.number() }).nonstrict(),
numProm: z.promise(z.number()),
lenfun: z.function(z.tuple([z.string()]), z.boolean()),
});
export const asyncCrazySchema = crazySchema.extend({
// async_transform: z.transformer(
// z.array(z.number()),
// z.number(),
// async (arg) => {
// return arg.reduce((a, b) => a + b, 0);
// }
// ),
async_refine: z.array(z.number()).refine(async (arg) => arg.length > 5),
});