1
1
import * 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'
3
3
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 ( ) ;
7
5
8
6
export const HttpMethodSchema = yup . string < HttpMethod > ( ) . oneOf ( [ HttpMethod . Get , HttpMethod . Post ] ) . defined ( ) ;
9
7
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 ( ) ;
11
11
12
12
function union < T extends { } > ( ...schemas : ReadonlyArray < yup . Schema < T > > ) : yup . MixedSchema < T > {
13
13
return yup . mixed < T > ( ) . test ( {
14
14
test : ( value ) => schemas . some ( ( schema ) => schema . isValidSync ( value ) )
15
15
} ) . defined ( )
16
16
}
17
17
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 ( )
21
21
} ) ;
22
22
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 ( )
26
31
} ) ;
27
32
28
33
export const ComponentInputSchema : yup . ObjectSchema < ComponentInput > = yup . object ( {
@@ -38,30 +43,15 @@ export const DropDownComponentInputSchema: yup.ObjectSchema<DropDownComponentInp
38
43
getEvent : yup . lazy ( ( ) => EventInputSchema . nonNullable ( ) )
39
44
} ) ;
40
45
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
-
61
46
export const LayoutInputSchema : yup . ObjectSchema < LayoutInput > = yup . object ( {
62
47
dropdown : yup . lazy ( ( ) => DropDownComponentInputSchema ) . optional ( )
63
48
} ) ;
64
49
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
+
65
55
export const PageInputSchema : yup . ObjectSchema < PageInput > = yup . object ( {
66
56
attributes : yup . array ( yup . lazy ( ( ) => AttributeInputSchema . nonNullable ( ) ) ) . defined ( ) . nullable ( ) . optional ( ) ,
67
57
date : yup . mixed ( ) . nullable ( ) . optional ( ) ,
@@ -76,6 +66,18 @@ export const PageInputSchema: yup.ObjectSchema<PageInput> = yup.object({
76
66
width : yup . number ( ) . defined ( ) . nonNullable ( )
77
67
} ) ;
78
68
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
+
79
81
export const UserSchema : yup . ObjectSchema < User > = yup . object ( {
80
82
__typename : yup . string < 'User' > ( ) . optional ( ) ,
81
83
createdAt : yup . mixed ( ) . nullable ( ) . optional ( ) ,
@@ -86,5 +88,3 @@ export const UserSchema: yup.ObjectSchema<User> = yup.object({
86
88
password : yup . string ( ) . defined ( ) . nullable ( ) . optional ( ) ,
87
89
updatedAt : yup . mixed ( ) . nullable ( ) . optional ( )
88
90
} ) ;
89
-
90
- export const UserKindSchema : yup . MixedSchema < UserKind > = union < UserKind > ( AdminSchema , GuestSchema ) ;
0 commit comments