-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathschemas.ts
More file actions
137 lines (117 loc) · 3.93 KB
/
schemas.ts
File metadata and controls
137 lines (117 loc) · 3.93 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
import * as v from 'valibot'
import { Admin, AttributeInput, ButtonComponentType, Comment, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, Namer, PageInput, PageType, User } from '../types'
export const ButtonComponentTypeSchema = v.enum_(ButtonComponentType);
export const EventOptionTypeSchema = v.enum_(EventOptionType);
export const HttpMethodSchema = v.enum_(HttpMethod);
export const PageTypeSchema = v.enum_(PageType);
export function AdminSchema(): v.GenericSchema<Admin> {
return v.object({
__typename: v.optional(v.literal('Admin')),
lastModifiedAt: v.nullish(v.any())
})
}
export function AttributeInputSchema(): v.GenericSchema<AttributeInput> {
return v.object({
key: v.nullish(v.string()),
val: v.nullish(v.string())
})
}
export function CommentSchema(): v.GenericSchema<Comment> {
return v.object({
__typename: v.optional(v.literal('Comment')),
replies: v.nullish(v.array(v.lazy(() => CommentSchema())))
})
}
export function ComponentInputSchema(): v.GenericSchema<ComponentInput> {
return v.object({
child: v.lazy(() => v.nullish(ComponentInputSchema())),
childrens: v.nullish(v.array(v.lazy(() => v.nullable(ComponentInputSchema())))),
event: v.lazy(() => v.nullish(EventInputSchema())),
name: v.string(),
type: ButtonComponentTypeSchema
})
}
export function DropDownComponentInputSchema(): v.GenericSchema<DropDownComponentInput> {
return v.object({
dropdownComponent: v.lazy(() => v.nullish(ComponentInputSchema())),
getEvent: v.lazy(() => EventInputSchema())
})
}
export function EventArgumentInputSchema(): v.GenericSchema<EventArgumentInput> {
return v.object({
name: v.pipe(v.string(), v.minLength(5)),
value: v.pipe(v.string(), v.regex(/^foo/, "message"))
})
}
export function EventInputSchema(): v.GenericSchema<EventInput> {
return v.object({
arguments: v.array(v.lazy(() => EventArgumentInputSchema())),
options: v.nullish(v.array(EventOptionTypeSchema))
})
}
export function GuestSchema(): v.GenericSchema<Guest> {
return v.object({
__typename: v.optional(v.literal('Guest')),
lastLoggedIn: v.nullish(v.any())
})
}
export function HttpInputSchema(): v.GenericSchema<HttpInput> {
return v.object({
method: v.nullish(HttpMethodSchema),
url: v.any()
})
}
export function LayoutInputSchema(): v.GenericSchema<LayoutInput> {
return v.object({
dropdown: v.lazy(() => v.nullish(DropDownComponentInputSchema()))
})
}
export function MyTypeSchema(): v.GenericSchema<MyType> {
return v.object({
__typename: v.optional(v.literal('MyType')),
foo: v.nullish(v.string())
})
}
export function MyTypeFooArgsSchema(): v.GenericSchema<MyTypeFooArgs> {
return v.object({
a: v.nullish(v.string()),
b: v.number(),
c: v.nullish(v.boolean()),
d: v.number()
})
}
export function NamerSchema(): v.GenericSchema<Namer> {
return v.object({
name: v.nullish(v.string())
})
}
export function PageInputSchema(): v.GenericSchema<PageInput> {
return v.object({
attributes: v.nullish(v.array(v.lazy(() => AttributeInputSchema()))),
date: v.nullish(v.any()),
height: v.number(),
id: v.string(),
layout: v.lazy(() => LayoutInputSchema()),
pageType: PageTypeSchema,
postIDs: v.nullish(v.array(v.string())),
show: v.boolean(),
tags: v.nullish(v.array(v.nullable(v.string()))),
title: v.string(),
width: v.number()
})
}
export function UserSchema(): v.GenericSchema<User> {
return v.object({
__typename: v.optional(v.literal('User')),
createdAt: v.nullish(v.any()),
email: v.nullish(v.string()),
id: v.nullish(v.string()),
kind: v.lazy(() => v.nullish(UserKindSchema())),
name: v.nullish(v.string()),
password: v.nullish(v.string()),
updatedAt: v.nullish(v.any())
})
}
export function UserKindSchema() {
return v.union([AdminSchema(), GuestSchema()])
}