-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathschemas.ts
More file actions
147 lines (123 loc) · 4.36 KB
/
schemas.ts
File metadata and controls
147 lines (123 loc) · 4.36 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import * as z from 'zod'
import { Admin, AttributeInput, ButtonComponentType, Comment, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, Namer, PageInput, PageType, User } from '../types'
type Properties<T> = Required<{
[K in keyof T]: z.ZodType<T[K]>;
}>;
type definedNonNullAny = {};
export const isDefinedNonNullAny = (v: any): v is definedNonNullAny => v !== undefined && v !== null;
export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v));
export const ButtonComponentTypeSchema = z.enum(ButtonComponentType);
export const EventOptionTypeSchema = z.enum(EventOptionType);
export const HttpMethodSchema = z.enum(HttpMethod);
export const PageTypeSchema = z.enum(PageType);
export function AdminSchema(): z.ZodObject<Properties<Admin>> {
return z.object({
__typename: z.literal('Admin').optional(),
lastModifiedAt: definedNonNullAnySchema.nullish()
})
}
export function AttributeInputSchema(): z.ZodObject<Properties<AttributeInput>> {
return z.object({
key: z.string().nullish(),
val: z.string().nullish()
})
}
export function CommentSchema(): z.ZodObject<Properties<Comment>> {
return z.object({
__typename: z.literal('Comment').optional(),
replies: z.array(z.lazy(() => CommentSchema())).nullish()
})
}
export function ComponentInputSchema(): z.ZodObject<Properties<ComponentInput>> {
return z.object({
child: z.lazy(() => ComponentInputSchema().nullish()),
childrens: z.array(z.lazy(() => ComponentInputSchema().nullable())).nullish(),
event: z.lazy(() => EventInputSchema().nullish()),
name: z.string(),
type: ButtonComponentTypeSchema
})
}
export function DropDownComponentInputSchema(): z.ZodObject<Properties<DropDownComponentInput>> {
return z.object({
dropdownComponent: z.lazy(() => ComponentInputSchema().nullish()),
getEvent: z.lazy(() => EventInputSchema())
})
}
export function EventArgumentInputSchema(): z.ZodObject<Properties<EventArgumentInput>> {
return z.object({
name: z.string().min(5),
value: z.string().regex(/^foo/, "message")
})
}
export function EventInputSchema(): z.ZodObject<Properties<EventInput>> {
return z.object({
arguments: z.array(z.lazy(() => EventArgumentInputSchema())),
options: z.array(EventOptionTypeSchema).nullish()
})
}
export function GuestSchema(): z.ZodObject<Properties<Guest>> {
return z.object({
__typename: z.literal('Guest').optional(),
lastLoggedIn: definedNonNullAnySchema.nullish()
})
}
export function HttpInputSchema(): z.ZodObject<Properties<HttpInput>> {
return z.object({
method: HttpMethodSchema.nullish(),
url: definedNonNullAnySchema
})
}
export function LayoutInputSchema(): z.ZodObject<Properties<LayoutInput>> {
return z.object({
dropdown: z.lazy(() => DropDownComponentInputSchema().nullish())
})
}
export function MyTypeSchema(): z.ZodObject<Properties<MyType>> {
return z.object({
__typename: z.literal('MyType').optional(),
foo: z.string().nullish()
})
}
export function MyTypeFooArgsSchema(): z.ZodObject<Properties<MyTypeFooArgs>> {
return z.object({
a: z.string().nullish(),
b: z.number(),
c: z.boolean().nullish(),
d: z.number()
})
}
export function NamerSchema(): z.ZodObject<Properties<Namer>> {
return z.object({
name: z.string().nullish()
})
}
export function PageInputSchema(): z.ZodObject<Properties<PageInput>> {
return z.object({
attributes: z.array(z.lazy(() => AttributeInputSchema())).nullish(),
date: definedNonNullAnySchema.nullish(),
height: z.number(),
id: z.string(),
layout: z.lazy(() => LayoutInputSchema()),
pageType: PageTypeSchema,
postIDs: z.array(z.string()).nullish(),
show: z.boolean(),
tags: z.array(z.string().nullable()).nullish(),
title: z.string(),
width: z.number()
})
}
export function UserSchema(): z.ZodObject<Properties<User>> {
return z.object({
__typename: z.literal('User').optional(),
createdAt: definedNonNullAnySchema.nullish(),
email: z.string().nullish(),
id: z.string().nullish(),
kind: z.lazy(() => UserKindSchema().nullish()),
name: z.string().nullish(),
password: z.string().nullish(),
updatedAt: definedNonNullAnySchema.nullish()
})
}
export function UserKindSchema() {
return z.union([AdminSchema(), GuestSchema()])
}