11import * as yup from 'yup'
2- import { Admin , AttributeInput , ButtonComponentType , ComponentInput , DropDownComponentInput , EventArgumentInput , EventInput , EventOptionType , Guest , HttpInput , HttpMethod , LayoutInput , PageInput , PageType , User , UserKind } from '../types'
2+ import { PageType , HttpMethod , HttpInput , EventOptionType , EventArgumentInput , EventInput , ComponentInput , DropDownComponentInput , LayoutInput , ButtonComponentType , AttributeInput , PageInput , Guest , Admin , UserKind , User } from '../types'
33
4- export const ButtonComponentTypeSchema = yup . string < ButtonComponentType > ( ) . oneOf ( [ ButtonComponentType . Button , ButtonComponentType . Submit ] ) . defined ( ) ;
5-
6- export const EventOptionTypeSchema = yup . string < EventOptionType > ( ) . oneOf ( [ EventOptionType . Reload , EventOptionType . Retry ] ) . defined ( ) ;
4+ export const PageTypeSchema = yup . string < PageType > ( ) . oneOf ( [ PageType . BasicAuth , PageType . Lp , PageType . Restricted , PageType . Service ] ) . defined ( ) ;
75
86export const HttpMethodSchema = yup . string < HttpMethod > ( ) . oneOf ( [ HttpMethod . Get , HttpMethod . Post ] ) . defined ( ) ;
97
10- export const PageTypeSchema = yup . string < PageType > ( ) . oneOf ( [ PageType . BasicAuth , PageType . Lp , PageType . Restricted , PageType . Service ] ) . defined ( ) ;
8+ export const EventOptionTypeSchema = yup . string < EventOptionType > ( ) . oneOf ( [ EventOptionType . Reload , EventOptionType . Retry ] ) . defined ( ) ;
9+
10+ export const ButtonComponentTypeSchema = yup . string < ButtonComponentType > ( ) . oneOf ( [ ButtonComponentType . Button , ButtonComponentType . Submit ] ) . defined ( ) ;
1111
1212function union < T extends { } > ( ...schemas : ReadonlyArray < yup . Schema < T > > ) : yup . MixedSchema < T > {
1313 return yup . mixed < T > ( ) . test ( {
1414 test : ( value ) => schemas . some ( ( schema ) => schema . isValidSync ( value ) )
1515 } ) . defined ( )
1616}
1717
18- export const AdminSchema : yup . ObjectSchema < Admin > = yup . object ( {
19- __typename : yup . string < 'Admin' > ( ) . optional ( ) ,
20- lastModifiedAt : yup . mixed ( ) . nullable ( ) . optional ( )
18+ export const HttpInputSchema : yup . ObjectSchema < HttpInput > = yup . object ( {
19+ method : HttpMethodSchema . nullable ( ) . optional ( ) ,
20+ url : yup . mixed ( ) . nonNullable ( )
2121} ) ;
2222
23- export const AttributeInputSchema : yup . ObjectSchema < AttributeInput > = yup . object ( {
24- key : yup . string ( ) . defined ( ) . nullable ( ) . optional ( ) ,
25- val : yup . string ( ) . defined ( ) . nullable ( ) . optional ( )
23+ export const EventArgumentInputSchema : yup . ObjectSchema < EventArgumentInput > = yup . object ( {
24+ name : yup . string ( ) . defined ( ) . nonNullable ( ) . min ( 5 ) ,
25+ value : yup . string ( ) . defined ( ) . nonNullable ( ) . matches ( / ^ f o o / )
26+ } ) ;
27+
28+ export const EventInputSchema : yup . ObjectSchema < EventInput > = yup . object ( {
29+ arguments : yup . array ( yup . lazy ( ( ) => EventArgumentInputSchema . nonNullable ( ) ) ) . defined ( ) ,
30+ options : yup . array ( EventOptionTypeSchema . nonNullable ( ) ) . defined ( ) . nullable ( ) . optional ( )
2631} ) ;
2732
2833export const ComponentInputSchema : yup . ObjectSchema < ComponentInput > = yup . object ( {
@@ -38,30 +43,15 @@ export const DropDownComponentInputSchema: yup.ObjectSchema<DropDownComponentInp
3843 getEvent : yup . lazy ( ( ) => EventInputSchema . nonNullable ( ) )
3944} ) ;
4045
41- export const EventArgumentInputSchema : yup . ObjectSchema < EventArgumentInput > = yup . object ( {
42- name : yup . string ( ) . defined ( ) . nonNullable ( ) . min ( 5 ) ,
43- value : yup . string ( ) . defined ( ) . nonNullable ( ) . matches ( / ^ f o o / )
44- } ) ;
45-
46- export const EventInputSchema : yup . ObjectSchema < EventInput > = yup . object ( {
47- arguments : yup . array ( yup . lazy ( ( ) => EventArgumentInputSchema . nonNullable ( ) ) ) . defined ( ) ,
48- options : yup . array ( EventOptionTypeSchema . nonNullable ( ) ) . defined ( ) . nullable ( ) . optional ( )
49- } ) ;
50-
51- export const GuestSchema : yup . ObjectSchema < Guest > = yup . object ( {
52- __typename : yup . string < 'Guest' > ( ) . optional ( ) ,
53- lastLoggedIn : yup . mixed ( ) . nullable ( ) . optional ( )
54- } ) ;
55-
56- export const HttpInputSchema : yup . ObjectSchema < HttpInput > = yup . object ( {
57- method : HttpMethodSchema . nullable ( ) . optional ( ) ,
58- url : yup . mixed ( ) . nonNullable ( )
59- } ) ;
60-
6146export const LayoutInputSchema : yup . ObjectSchema < LayoutInput > = yup . object ( {
6247 dropdown : yup . lazy ( ( ) => DropDownComponentInputSchema ) . optional ( )
6348} ) ;
6449
50+ export const AttributeInputSchema : yup . ObjectSchema < AttributeInput > = yup . object ( {
51+ key : yup . string ( ) . defined ( ) . nullable ( ) . optional ( ) ,
52+ val : yup . string ( ) . defined ( ) . nullable ( ) . optional ( )
53+ } ) ;
54+
6555export const PageInputSchema : yup . ObjectSchema < PageInput > = yup . object ( {
6656 attributes : yup . array ( yup . lazy ( ( ) => AttributeInputSchema . nonNullable ( ) ) ) . defined ( ) . nullable ( ) . optional ( ) ,
6757 date : yup . mixed ( ) . nullable ( ) . optional ( ) ,
@@ -76,6 +66,18 @@ export const PageInputSchema: yup.ObjectSchema<PageInput> = yup.object({
7666 width : yup . number ( ) . defined ( ) . nonNullable ( )
7767} ) ;
7868
69+ export const GuestSchema : yup . ObjectSchema < Guest > = yup . object ( {
70+ __typename : yup . string < 'Guest' > ( ) . optional ( ) ,
71+ lastLoggedIn : yup . mixed ( ) . nullable ( ) . optional ( )
72+ } ) ;
73+
74+ export const AdminSchema : yup . ObjectSchema < Admin > = yup . object ( {
75+ __typename : yup . string < 'Admin' > ( ) . optional ( ) ,
76+ lastModifiedAt : yup . mixed ( ) . nullable ( ) . optional ( )
77+ } ) ;
78+
79+ export const UserKindSchema : yup . MixedSchema < UserKind > = union < UserKind > ( AdminSchema , GuestSchema ) ;
80+
7981export const UserSchema : yup . ObjectSchema < User > = yup . object ( {
8082 __typename : yup . string < 'User' > ( ) . optional ( ) ,
8183 createdAt : yup . mixed ( ) . nullable ( ) . optional ( ) ,
@@ -86,5 +88,3 @@ export const UserSchema: yup.ObjectSchema<User> = yup.object({
8688 password : yup . string ( ) . defined ( ) . nullable ( ) . optional ( ) ,
8789 updatedAt : yup . mixed ( ) . nullable ( ) . optional ( )
8890} ) ;
89-
90- export const UserKindSchema : yup . MixedSchema < UserKind > = union < UserKind > ( AdminSchema , GuestSchema ) ;
0 commit comments