|
| 1 | +import * as v from 'valibot' |
| 2 | +import { Admin, AttributeInput, ButtonComponentType, ComponentInput, DropDownComponentInput, EventArgumentInput, EventInput, EventOptionType, Guest, HttpInput, HttpMethod, LayoutInput, MyType, MyTypeFooArgs, Namer, PageInput, PageType, User } from '../types' |
| 3 | + |
| 4 | +export const ButtonComponentTypeSchema = v.enum_(ButtonComponentType); |
| 5 | + |
| 6 | +export const EventOptionTypeSchema = v.enum_(EventOptionType); |
| 7 | + |
| 8 | +export const HttpMethodSchema = v.enum_(HttpMethod); |
| 9 | + |
| 10 | +export const PageTypeSchema = v.enum_(PageType); |
| 11 | + |
| 12 | +export function AdminSchema(): v.GenericSchema<Admin> { |
| 13 | + return v.object({ |
| 14 | + __typename: v.optional(v.literal('Admin')), |
| 15 | + lastModifiedAt: v.nullish(v.any()) |
| 16 | + }) |
| 17 | +} |
| 18 | + |
| 19 | +export function AttributeInputSchema(): v.GenericSchema<AttributeInput> { |
| 20 | + return v.object({ |
| 21 | + key: v.nullish(v.string()), |
| 22 | + val: v.nullish(v.string()) |
| 23 | + }) |
| 24 | +} |
| 25 | + |
| 26 | +export function ComponentInputSchema(): v.GenericSchema<ComponentInput> { |
| 27 | + return v.object({ |
| 28 | + child: v.lazy(() => v.nullish(ComponentInputSchema())), |
| 29 | + childrens: v.nullish(v.array(v.lazy(() => v.nullable(ComponentInputSchema())))), |
| 30 | + event: v.lazy(() => v.nullish(EventInputSchema())), |
| 31 | + name: v.string(), |
| 32 | + type: ButtonComponentTypeSchema |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +export function DropDownComponentInputSchema(): v.GenericSchema<DropDownComponentInput> { |
| 37 | + return v.object({ |
| 38 | + dropdownComponent: v.lazy(() => v.nullish(ComponentInputSchema())), |
| 39 | + getEvent: v.lazy(() => EventInputSchema()) |
| 40 | + }) |
| 41 | +} |
| 42 | + |
| 43 | +export function EventArgumentInputSchema(): v.GenericSchema<EventArgumentInput> { |
| 44 | + return v.object({ |
| 45 | + name: v.pipe(v.string(), v.minLength(5)), |
| 46 | + value: v.pipe(v.string(), v.regex(/^foo/, "message")) |
| 47 | + }) |
| 48 | +} |
| 49 | + |
| 50 | +export function EventInputSchema(): v.GenericSchema<EventInput> { |
| 51 | + return v.object({ |
| 52 | + arguments: v.array(v.lazy(() => EventArgumentInputSchema())), |
| 53 | + options: v.nullish(v.array(EventOptionTypeSchema)) |
| 54 | + }) |
| 55 | +} |
| 56 | + |
| 57 | +export function GuestSchema(): v.GenericSchema<Guest> { |
| 58 | + return v.object({ |
| 59 | + __typename: v.optional(v.literal('Guest')), |
| 60 | + lastLoggedIn: v.nullish(v.any()) |
| 61 | + }) |
| 62 | +} |
| 63 | + |
| 64 | +export function HttpInputSchema(): v.GenericSchema<HttpInput> { |
| 65 | + return v.object({ |
| 66 | + method: v.nullish(HttpMethodSchema), |
| 67 | + url: v.any() |
| 68 | + }) |
| 69 | +} |
| 70 | + |
| 71 | +export function LayoutInputSchema(): v.GenericSchema<LayoutInput> { |
| 72 | + return v.object({ |
| 73 | + dropdown: v.lazy(() => v.nullish(DropDownComponentInputSchema())) |
| 74 | + }) |
| 75 | +} |
| 76 | + |
| 77 | +export function MyTypeSchema(): v.GenericSchema<MyType> { |
| 78 | + return v.object({ |
| 79 | + __typename: v.optional(v.literal('MyType')), |
| 80 | + foo: v.nullish(v.string()) |
| 81 | + }) |
| 82 | +} |
| 83 | + |
| 84 | +export function MyTypeFooArgsSchema(): v.GenericSchema<MyTypeFooArgs> { |
| 85 | + return v.object({ |
| 86 | + a: v.nullish(v.string()), |
| 87 | + b: v.number(), |
| 88 | + c: v.nullish(v.boolean()), |
| 89 | + d: v.number() |
| 90 | + }) |
| 91 | +} |
| 92 | + |
| 93 | +export function NamerSchema(): v.GenericSchema<Namer> { |
| 94 | + return v.object({ |
| 95 | + name: v.nullish(v.string()) |
| 96 | + }) |
| 97 | +} |
| 98 | + |
| 99 | +export function PageInputSchema(): v.GenericSchema<PageInput> { |
| 100 | + return v.object({ |
| 101 | + attributes: v.nullish(v.array(v.lazy(() => AttributeInputSchema()))), |
| 102 | + date: v.nullish(v.any()), |
| 103 | + height: v.number(), |
| 104 | + id: v.string(), |
| 105 | + layout: v.lazy(() => LayoutInputSchema()), |
| 106 | + pageType: PageTypeSchema, |
| 107 | + postIDs: v.nullish(v.array(v.string())), |
| 108 | + show: v.boolean(), |
| 109 | + tags: v.nullish(v.array(v.nullable(v.string()))), |
| 110 | + title: v.string(), |
| 111 | + width: v.number() |
| 112 | + }) |
| 113 | +} |
| 114 | + |
| 115 | +export function UserSchema(): v.GenericSchema<User> { |
| 116 | + return v.object({ |
| 117 | + __typename: v.optional(v.literal('User')), |
| 118 | + createdAt: v.nullish(v.any()), |
| 119 | + email: v.nullish(v.string()), |
| 120 | + id: v.nullish(v.string()), |
| 121 | + kind: v.nullish(UserKindSchema()), |
| 122 | + name: v.nullish(v.string()), |
| 123 | + password: v.nullish(v.string()), |
| 124 | + updatedAt: v.nullish(v.any()) |
| 125 | + }) |
| 126 | +} |
| 127 | + |
| 128 | +export function UserKindSchema() { |
| 129 | + return v.union([AdminSchema(), GuestSchema()]) |
| 130 | +} |
0 commit comments