@@ -47,38 +47,55 @@ const choiceBasePredicate = z.object({
4747 name : choiceValueStringPredicate ,
4848 name_localizations : localeMapPredicate . optional ( ) ,
4949} ) ;
50- const choiceStringPredicate = choiceBasePredicate . extend ( {
50+ const choiceStringPredicate = z . object ( {
51+ ...choiceBasePredicate . shape ,
5152 value : choiceValueStringPredicate ,
5253} ) ;
53- const choiceNumberPredicate = choiceBasePredicate . extend ( {
54+ const choiceNumberPredicate = z . object ( {
55+ ...choiceBasePredicate . shape ,
5456 value : choiceValueNumberPredicate ,
5557} ) ;
5658
5759const choiceBaseMixinPredicate = z . object ( {
5860 autocomplete : z . literal ( false ) . optional ( ) ,
5961} ) ;
60- const choiceStringMixinPredicate = choiceBaseMixinPredicate . extend ( {
62+ const choiceStringMixinPredicate = z . object ( {
63+ ...choiceBaseMixinPredicate . shape ,
6164 choices : choiceStringPredicate . array ( ) . max ( 25 ) . optional ( ) ,
6265} ) ;
63- const choiceNumberMixinPredicate = choiceBaseMixinPredicate . extend ( {
66+ const choiceNumberMixinPredicate = z . object ( {
67+ ...choiceBaseMixinPredicate . shape ,
6468 choices : choiceNumberPredicate . array ( ) . max ( 25 ) . optional ( ) ,
6569} ) ;
6670
67- const basicOptionTypesPredicate = z . literal ( [
68- ApplicationCommandOptionType . Attachment ,
69- ApplicationCommandOptionType . Boolean ,
70- ApplicationCommandOptionType . Channel ,
71- ApplicationCommandOptionType . Integer ,
72- ApplicationCommandOptionType . Mentionable ,
73- ApplicationCommandOptionType . Number ,
74- ApplicationCommandOptionType . Role ,
75- ApplicationCommandOptionType . String ,
76- ApplicationCommandOptionType . User ,
77- ] ) ;
78-
79- export const basicOptionPredicate = sharedNameAndDescriptionPredicate . extend ( {
71+ export const baseBasicOptionPredicate = z . object ( {
72+ ...sharedNameAndDescriptionPredicate . shape ,
8073 required : z . boolean ( ) . optional ( ) ,
81- type : basicOptionTypesPredicate ,
74+ } ) ;
75+
76+ export const attachmentOptionPredicate = z . object ( {
77+ ...baseBasicOptionPredicate . shape ,
78+ type : z . literal ( ApplicationCommandOptionType . Attachment ) ,
79+ } ) ;
80+
81+ export const booleanOptionPredicate = z . object ( {
82+ ...baseBasicOptionPredicate . shape ,
83+ type : z . literal ( ApplicationCommandOptionType . Boolean ) ,
84+ } ) ;
85+
86+ export const mentionableOptionPredicate = z . object ( {
87+ ...baseBasicOptionPredicate . shape ,
88+ type : z . literal ( ApplicationCommandOptionType . Mentionable ) ,
89+ } ) ;
90+
91+ export const roleOptionPredicate = z . object ( {
92+ ...baseBasicOptionPredicate . shape ,
93+ type : z . literal ( ApplicationCommandOptionType . Role ) ,
94+ } ) ;
95+
96+ export const userOptionPredicate = z . object ( {
97+ ...baseBasicOptionPredicate . shape ,
98+ type : z . literal ( ApplicationCommandOptionType . User ) ,
8299} ) ;
83100
84101const autocompleteOrStringChoicesMixinOptionPredicate = z . discriminatedUnion ( 'autocomplete' , [
@@ -92,58 +109,70 @@ const autocompleteOrNumberChoicesMixinOptionPredicate = z.discriminatedUnion('au
92109] ) ;
93110
94111export const channelOptionPredicate = z . object ( {
95- ...basicOptionPredicate . shape ,
112+ ...baseBasicOptionPredicate . shape ,
96113 ...channelMixinOptionPredicate . shape ,
114+ type : z . literal ( ApplicationCommandOptionType . Channel ) ,
97115} ) ;
98116
99117export const integerOptionPredicate = z
100118 . object ( {
101- ...basicOptionPredicate . shape ,
119+ ...baseBasicOptionPredicate . shape ,
102120 ...numericMixinIntegerOptionPredicate . shape ,
121+ type : z . literal ( ApplicationCommandOptionType . Integer ) ,
103122 } )
104123 . and ( autocompleteOrNumberChoicesMixinOptionPredicate ) ;
105124
106125export const numberOptionPredicate = z
107126 . object ( {
108- ...basicOptionPredicate . shape ,
127+ ...baseBasicOptionPredicate . shape ,
109128 ...numericMixinNumberOptionPredicate . shape ,
129+ type : z . literal ( ApplicationCommandOptionType . Number ) ,
110130 } )
111131 . and ( autocompleteOrNumberChoicesMixinOptionPredicate ) ;
112132
113- export const stringOptionPredicate = basicOptionPredicate
114- . extend ( {
133+ export const stringOptionPredicate = z
134+ . object ( {
135+ ...baseBasicOptionPredicate . shape ,
115136 max_length : z . number ( ) . min ( 0 ) . max ( 6_000 ) . optional ( ) ,
116137 min_length : z . number ( ) . min ( 1 ) . max ( 6_000 ) . optional ( ) ,
138+ type : z . literal ( ApplicationCommandOptionType . String ) ,
117139 } )
118140 . and ( autocompleteOrStringChoicesMixinOptionPredicate ) ;
119141
120- const baseChatInputCommandPredicate = sharedNameAndDescriptionPredicate . extend ( {
121- contexts : z . array ( z . enum ( InteractionContextType ) ) . optional ( ) ,
122- default_member_permissions : memberPermissionsPredicate . optional ( ) ,
123- integration_types : z . array ( z . enum ( ApplicationIntegrationType ) ) . optional ( ) ,
124- nsfw : z . boolean ( ) . optional ( ) ,
125- } ) ;
126-
127- // Because you can only add options via builders, there's no need to validate whole objects here otherwise
128- const chatInputCommandOptionsPredicate = z . union ( [
129- z . object ( { type : basicOptionTypesPredicate } ) . array ( ) ,
130- z . object ( { type : z . literal ( ApplicationCommandOptionType . Subcommand ) } ) . array ( ) ,
131- z . object ( { type : z . literal ( ApplicationCommandOptionType . SubcommandGroup ) } ) . array ( ) ,
132- ] ) ;
133-
134- export const chatInputCommandPredicate = baseChatInputCommandPredicate . extend ( {
135- options : chatInputCommandOptionsPredicate . optional ( ) ,
142+ const basicOptionPredicates = [
143+ attachmentOptionPredicate ,
144+ booleanOptionPredicate ,
145+ channelOptionPredicate ,
146+ integerOptionPredicate ,
147+ mentionableOptionPredicate ,
148+ numberOptionPredicate ,
149+ roleOptionPredicate ,
150+ stringOptionPredicate ,
151+ userOptionPredicate ,
152+ ] ;
153+
154+ export const chatInputCommandSubcommandPredicate = z . object ( {
155+ ... sharedNameAndDescriptionPredicate . shape ,
156+ type : z . literal ( ApplicationCommandOptionType . Subcommand ) ,
157+ options : z . array ( z . union ( basicOptionPredicates ) ) . max ( 25 ) ,
136158} ) ;
137159
138- export const chatInputCommandSubcommandGroupPredicate = sharedNameAndDescriptionPredicate . extend ( {
160+ export const chatInputCommandSubcommandGroupPredicate = z . object ( {
161+ ...sharedNameAndDescriptionPredicate . shape ,
139162 type : z . literal ( ApplicationCommandOptionType . SubcommandGroup ) ,
140- options : z
141- . array ( z . object ( { type : z . literal ( ApplicationCommandOptionType . Subcommand ) } ) )
142- . min ( 1 )
143- . max ( 25 ) ,
163+ options : z . array ( chatInputCommandSubcommandPredicate ) . min ( 1 ) . max ( 25 ) ,
144164} ) ;
145165
146- export const chatInputCommandSubcommandPredicate = sharedNameAndDescriptionPredicate . extend ( {
147- type : z . literal ( ApplicationCommandOptionType . Subcommand ) ,
148- options : z . array ( z . object ( { type : basicOptionTypesPredicate } ) ) . max ( 25 ) ,
166+ export const chatInputCommandPredicate = z . object ( {
167+ ...sharedNameAndDescriptionPredicate . shape ,
168+ contexts : z . array ( z . enum ( InteractionContextType ) ) . optional ( ) ,
169+ default_member_permissions : memberPermissionsPredicate . optional ( ) ,
170+ integration_types : z . array ( z . enum ( ApplicationIntegrationType ) ) . optional ( ) ,
171+ nsfw : z . boolean ( ) . optional ( ) ,
172+ options : z
173+ . union ( [
174+ z . array ( z . union ( basicOptionPredicates ) ) . max ( 25 ) ,
175+ z . array ( z . union ( [ chatInputCommandSubcommandPredicate , chatInputCommandSubcommandGroupPredicate ] ) ) . max ( 25 ) ,
176+ ] )
177+ . optional ( ) ,
149178} ) ;
0 commit comments