@discordjs/builders 2.0.0-dev.1764374516-19253f6b7 → 2.0.0-dev.1764547345-ec7047572

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -95,15 +95,15 @@ import { Locale } from "discord-api-types/v10";
95
95
  import { z as z2 } from "zod";
96
96
  var idPredicate = z2.int().min(0).max(2147483647).optional();
97
97
  var customIdPredicate = z2.string().min(1).max(100);
98
+ var snowflakePredicate = z2.string().regex(/^(?:0|[1-9]\d*)$/);
98
99
  var memberPermissionsPredicate = z2.coerce.bigint();
99
100
  var localeMapPredicate = z2.strictObject(
100
101
  Object.fromEntries(Object.values(Locale).map((loc) => [loc, z2.string().optional()]))
101
102
  );
102
103
 
103
104
  // src/components/Assertions.ts
104
- var labelPredicate = z3.string().min(1).max(80);
105
105
  var emojiPredicate = z3.strictObject({
106
- id: z3.string().optional(),
106
+ id: snowflakePredicate.optional(),
107
107
  name: z3.string().min(2).max(32).optional(),
108
108
  animated: z3.boolean().optional()
109
109
  }).refine((data) => data.id !== void 0 || data.name !== void 0, {
@@ -113,24 +113,29 @@ var buttonPredicateBase = z3.strictObject({
113
113
  type: z3.literal(ComponentType.Button),
114
114
  disabled: z3.boolean().optional()
115
115
  });
116
+ var buttonLabelPredicate = z3.string().min(1).max(80);
116
117
  var buttonCustomIdPredicateBase = buttonPredicateBase.extend({
117
118
  custom_id: customIdPredicate,
118
119
  emoji: emojiPredicate.optional(),
119
- label: labelPredicate
120
+ label: buttonLabelPredicate.optional()
121
+ }).refine((data) => data.emoji !== void 0 || data.label !== void 0, {
122
+ message: "Buttons with a custom id must have either an emoji or a label."
120
123
  });
121
- var buttonPrimaryPredicate = buttonCustomIdPredicateBase.extend({ style: z3.literal(ButtonStyle.Primary) });
122
- var buttonSecondaryPredicate = buttonCustomIdPredicateBase.extend({ style: z3.literal(ButtonStyle.Secondary) });
123
- var buttonSuccessPredicate = buttonCustomIdPredicateBase.extend({ style: z3.literal(ButtonStyle.Success) });
124
- var buttonDangerPredicate = buttonCustomIdPredicateBase.extend({ style: z3.literal(ButtonStyle.Danger) });
124
+ var buttonPrimaryPredicate = buttonCustomIdPredicateBase.safeExtend({ style: z3.literal(ButtonStyle.Primary) });
125
+ var buttonSecondaryPredicate = buttonCustomIdPredicateBase.safeExtend({ style: z3.literal(ButtonStyle.Secondary) });
126
+ var buttonSuccessPredicate = buttonCustomIdPredicateBase.safeExtend({ style: z3.literal(ButtonStyle.Success) });
127
+ var buttonDangerPredicate = buttonCustomIdPredicateBase.safeExtend({ style: z3.literal(ButtonStyle.Danger) });
125
128
  var buttonLinkPredicate = buttonPredicateBase.extend({
126
129
  style: z3.literal(ButtonStyle.Link),
127
130
  url: z3.url({ protocol: /^(?:https?|discord)$/ }).max(512),
128
131
  emoji: emojiPredicate.optional(),
129
- label: labelPredicate
132
+ label: buttonLabelPredicate.optional()
133
+ }).refine((data) => data.emoji !== void 0 || data.label !== void 0, {
134
+ message: "Link buttons must have either an emoji or a label."
130
135
  });
131
136
  var buttonPremiumPredicate = buttonPredicateBase.extend({
132
137
  style: z3.literal(ButtonStyle.Premium),
133
- sku_id: z3.string()
138
+ sku_id: snowflakePredicate
134
139
  });
135
140
  var buttonPredicate = z3.discriminatedUnion("style", [
136
141
  buttonLinkPredicate,
@@ -151,21 +156,21 @@ var selectMenuBasePredicate = z3.object({
151
156
  var selectMenuChannelPredicate = selectMenuBasePredicate.extend({
152
157
  type: z3.literal(ComponentType.ChannelSelect),
153
158
  channel_types: z3.enum(ChannelType).array().optional(),
154
- default_values: z3.object({ id: z3.string(), type: z3.literal(SelectMenuDefaultValueType.Channel) }).array().max(25).optional()
159
+ default_values: z3.object({ id: snowflakePredicate, type: z3.literal(SelectMenuDefaultValueType.Channel) }).array().max(25).optional()
155
160
  });
156
161
  var selectMenuMentionablePredicate = selectMenuBasePredicate.extend({
157
162
  type: z3.literal(ComponentType.MentionableSelect),
158
163
  default_values: z3.object({
159
- id: z3.string(),
164
+ id: snowflakePredicate,
160
165
  type: z3.literal([SelectMenuDefaultValueType.Role, SelectMenuDefaultValueType.User])
161
166
  }).array().max(25).optional()
162
167
  });
163
168
  var selectMenuRolePredicate = selectMenuBasePredicate.extend({
164
169
  type: z3.literal(ComponentType.RoleSelect),
165
- default_values: z3.object({ id: z3.string(), type: z3.literal(SelectMenuDefaultValueType.Role) }).array().max(25).optional()
170
+ default_values: z3.object({ id: snowflakePredicate, type: z3.literal(SelectMenuDefaultValueType.Role) }).array().max(25).optional()
166
171
  });
167
172
  var selectMenuStringOptionPredicate = z3.object({
168
- label: labelPredicate,
173
+ label: z3.string().min(1).max(100),
169
174
  value: z3.string().min(1).max(100),
170
175
  description: z3.string().min(1).max(100).optional(),
171
176
  emoji: emojiPredicate.optional(),
@@ -203,7 +208,7 @@ var selectMenuStringPredicate = selectMenuBasePredicate.extend({
203
208
  });
204
209
  var selectMenuUserPredicate = selectMenuBasePredicate.extend({
205
210
  type: z3.literal(ComponentType.UserSelect),
206
- default_values: z3.object({ id: z3.string(), type: z3.literal(SelectMenuDefaultValueType.User) }).array().max(25).optional()
211
+ default_values: z3.object({ id: snowflakePredicate, type: z3.literal(SelectMenuDefaultValueType.User) }).array().max(25).optional()
207
212
  });
208
213
  var actionRowPredicate = z3.object({
209
214
  id: idPredicate,
@@ -2512,7 +2517,7 @@ __name(resolveAccessoryComponent, "resolveAccessoryComponent");
2512
2517
  // src/components/label/Assertions.ts
2513
2518
  import { ComponentType as ComponentType24 } from "discord-api-types/v10";
2514
2519
  import { z as z7 } from "zod";
2515
- var labelPredicate2 = z7.object({
2520
+ var labelPredicate = z7.object({
2516
2521
  id: idPredicate,
2517
2522
  type: z7.literal(ComponentType24.Label),
2518
2523
  label: z7.string().min(1).max(45),
@@ -2665,7 +2670,7 @@ var LabelBuilder = class extends ComponentBuilder {
2665
2670
  // The label predicate validates the component.
2666
2671
  component: component?.toJSON(false)
2667
2672
  };
2668
- validate(labelPredicate2, data, validationOverride);
2673
+ validate(labelPredicate, data, validationOverride);
2669
2674
  return data;
2670
2675
  }
2671
2676
  };
@@ -3006,8 +3011,12 @@ var baseChatInputCommandPredicate = sharedNameAndDescriptionPredicate.extend({
3006
3011
  });
3007
3012
  var chatInputCommandOptionsPredicate = z8.union([
3008
3013
  z8.object({ type: basicOptionTypesPredicate }).array(),
3009
- z8.object({ type: z8.literal(ApplicationCommandOptionType.Subcommand) }).array(),
3010
- z8.object({ type: z8.literal(ApplicationCommandOptionType.SubcommandGroup) }).array()
3014
+ z8.object({
3015
+ type: z8.union([
3016
+ z8.literal(ApplicationCommandOptionType.Subcommand),
3017
+ z8.literal(ApplicationCommandOptionType.SubcommandGroup)
3018
+ ])
3019
+ }).array()
3011
3020
  ]);
3012
3021
  var chatInputCommandPredicate = baseChatInputCommandPredicate.extend({
3013
3022
  options: chatInputCommandOptionsPredicate.optional()
@@ -3658,7 +3667,7 @@ var modalPredicate = z10.object({
3658
3667
  type: z10.literal(ComponentType26.ActionRow),
3659
3668
  components: z10.object({ type: z10.literal(ComponentType26.TextInput) }).array().length(1)
3660
3669
  }),
3661
- labelPredicate2,
3670
+ labelPredicate,
3662
3671
  textDisplayPredicate
3663
3672
  ]).array().min(1).max(5)
3664
3673
  });
@@ -4657,7 +4666,7 @@ var rawFilePredicate = z13.object({
4657
4666
  });
4658
4667
  var attachmentPredicate = z13.object({
4659
4668
  // As a string it only makes sense for edits when we do have an attachment snowflake
4660
- id: z13.union([z13.string(), z13.number()]),
4669
+ id: z13.union([snowflakePredicate, z13.number()]),
4661
4670
  description: z13.string().max(1024).optional(),
4662
4671
  duration_secs: z13.number().max(2 ** 31 - 1).optional(),
4663
4672
  filename: z13.string().max(1024).optional(),
@@ -5717,7 +5726,7 @@ var MessageBuilder = class {
5717
5726
  };
5718
5727
 
5719
5728
  // src/index.ts
5720
- var version = "2.0.0-dev.1764374516-19253f6b7";
5729
+ var version = "2.0.0-dev.1764547345-ec7047572";
5721
5730
  export {
5722
5731
  ActionRowBuilder,
5723
5732
  AllowedMentionsBuilder,
@@ -5815,7 +5824,7 @@ export {
5815
5824
  idPredicate,
5816
5825
  integerOptionPredicate,
5817
5826
  isValidationEnabled,
5818
- labelPredicate2 as labelPredicate,
5827
+ labelPredicate,
5819
5828
  localeMapPredicate,
5820
5829
  mediaGalleryItemPredicate,
5821
5830
  mediaGalleryPredicate,
@@ -5841,6 +5850,7 @@ export {
5841
5850
  selectMenuStringPredicate,
5842
5851
  selectMenuUserPredicate,
5843
5852
  separatorPredicate,
5853
+ snowflakePredicate,
5844
5854
  stringOptionPredicate,
5845
5855
  textDisplayPredicate,
5846
5856
  textInputPredicate,