@@ -2,8 +2,6 @@ import { ButtonStyle, ChannelType, ComponentType, SelectMenuDefaultValueType } f
22import { z } from 'zod' ;
33import { idPredicate , customIdPredicate , snowflakePredicate } from '../Assertions.js' ;
44
5- const labelPredicate = z . string ( ) . min ( 1 ) . max ( 80 ) ;
6-
75export const emojiPredicate = z
86 . strictObject ( {
97 id : snowflakePredicate . optional ( ) ,
@@ -19,23 +17,33 @@ const buttonPredicateBase = z.strictObject({
1917 disabled : z . boolean ( ) . optional ( ) ,
2018} ) ;
2119
22- const buttonCustomIdPredicateBase = buttonPredicateBase . extend ( {
23- custom_id : customIdPredicate ,
24- emoji : emojiPredicate . optional ( ) ,
25- label : labelPredicate ,
26- } ) ;
20+ const buttonLabelPredicate = z . string ( ) . min ( 1 ) . max ( 80 ) ;
2721
28- const buttonPrimaryPredicate = buttonCustomIdPredicateBase . extend ( { style : z . literal ( ButtonStyle . Primary ) } ) ;
29- const buttonSecondaryPredicate = buttonCustomIdPredicateBase . extend ( { style : z . literal ( ButtonStyle . Secondary ) } ) ;
30- const buttonSuccessPredicate = buttonCustomIdPredicateBase . extend ( { style : z . literal ( ButtonStyle . Success ) } ) ;
31- const buttonDangerPredicate = buttonCustomIdPredicateBase . extend ( { style : z . literal ( ButtonStyle . Danger ) } ) ;
22+ const buttonCustomIdPredicateBase = buttonPredicateBase
23+ . extend ( {
24+ custom_id : customIdPredicate ,
25+ emoji : emojiPredicate . optional ( ) ,
26+ label : buttonLabelPredicate . optional ( ) ,
27+ } )
28+ . refine ( ( data ) => data . emoji !== undefined || data . label !== undefined , {
29+ message : 'Buttons with a custom id must have either an emoji or a label.' ,
30+ } ) ;
3231
33- const buttonLinkPredicate = buttonPredicateBase . extend ( {
34- style : z . literal ( ButtonStyle . Link ) ,
35- url : z . url ( { protocol : / ^ (?: h t t p s ? | d i s c o r d ) $ / } ) . max ( 512 ) ,
36- emoji : emojiPredicate . optional ( ) ,
37- label : labelPredicate ,
38- } ) ;
32+ const buttonPrimaryPredicate = buttonCustomIdPredicateBase . safeExtend ( { style : z . literal ( ButtonStyle . Primary ) } ) ;
33+ const buttonSecondaryPredicate = buttonCustomIdPredicateBase . safeExtend ( { style : z . literal ( ButtonStyle . Secondary ) } ) ;
34+ const buttonSuccessPredicate = buttonCustomIdPredicateBase . safeExtend ( { style : z . literal ( ButtonStyle . Success ) } ) ;
35+ const buttonDangerPredicate = buttonCustomIdPredicateBase . safeExtend ( { style : z . literal ( ButtonStyle . Danger ) } ) ;
36+
37+ const buttonLinkPredicate = buttonPredicateBase
38+ . extend ( {
39+ style : z . literal ( ButtonStyle . Link ) ,
40+ url : z . url ( { protocol : / ^ (?: h t t p s ? | d i s c o r d ) $ / } ) . max ( 512 ) ,
41+ emoji : emojiPredicate . optional ( ) ,
42+ label : buttonLabelPredicate . optional ( ) ,
43+ } )
44+ . refine ( ( data ) => data . emoji !== undefined || data . label !== undefined , {
45+ message : 'Link buttons must have either an emoji or a label.' ,
46+ } ) ;
3947
4048const buttonPremiumPredicate = buttonPredicateBase . extend ( {
4149 style : z . literal ( ButtonStyle . Premium ) ,
@@ -92,7 +100,7 @@ export const selectMenuRolePredicate = selectMenuBasePredicate.extend({
92100} ) ;
93101
94102export const selectMenuStringOptionPredicate = z . object ( {
95- label : labelPredicate ,
103+ label : z . string ( ) . min ( 1 ) . max ( 100 ) ,
96104 value : z . string ( ) . min ( 1 ) . max ( 100 ) ,
97105 description : z . string ( ) . min ( 1 ) . max ( 100 ) . optional ( ) ,
98106 emoji : emojiPredicate . optional ( ) ,
0 commit comments