@discordjs/builders 2.0.0-pr-11006.1765452229-e636950b2 → 2.0.0-pr-11005.1765454364-f3f6d34e7

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*)$/);
99
98
  var memberPermissionsPredicate = z2.coerce.bigint();
100
99
  var localeMapPredicate = z2.strictObject(
101
100
  Object.fromEntries(Object.values(Locale).map((loc) => [loc, z2.string().optional()]))
102
101
  );
103
102
 
104
103
  // src/components/Assertions.ts
104
+ var labelPredicate = z3.string().min(1).max(80);
105
105
  var emojiPredicate = z3.strictObject({
106
- id: snowflakePredicate.optional(),
106
+ id: z3.string().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,29 +113,24 @@ 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);
117
116
  var buttonCustomIdPredicateBase = buttonPredicateBase.extend({
118
117
  custom_id: customIdPredicate,
119
118
  emoji: emojiPredicate.optional(),
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."
119
+ label: labelPredicate
123
120
  });
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) });
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) });
128
125
  var buttonLinkPredicate = buttonPredicateBase.extend({
129
126
  style: z3.literal(ButtonStyle.Link),
130
127
  url: z3.url({ protocol: /^(?:https?|discord)$/ }).max(512),
131
128
  emoji: emojiPredicate.optional(),
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."
129
+ label: labelPredicate
135
130
  });
136
131
  var buttonPremiumPredicate = buttonPredicateBase.extend({
137
132
  style: z3.literal(ButtonStyle.Premium),
138
- sku_id: snowflakePredicate
133
+ sku_id: z3.string()
139
134
  });
140
135
  var buttonPredicate = z3.discriminatedUnion("style", [
141
136
  buttonLinkPredicate,
@@ -156,21 +151,21 @@ var selectMenuBasePredicate = z3.object({
156
151
  var selectMenuChannelPredicate = selectMenuBasePredicate.extend({
157
152
  type: z3.literal(ComponentType.ChannelSelect),
158
153
  channel_types: z3.enum(ChannelType).array().optional(),
159
- default_values: z3.object({ id: snowflakePredicate, type: z3.literal(SelectMenuDefaultValueType.Channel) }).array().max(25).optional()
154
+ default_values: z3.object({ id: z3.string(), type: z3.literal(SelectMenuDefaultValueType.Channel) }).array().max(25).optional()
160
155
  });
161
156
  var selectMenuMentionablePredicate = selectMenuBasePredicate.extend({
162
157
  type: z3.literal(ComponentType.MentionableSelect),
163
158
  default_values: z3.object({
164
- id: snowflakePredicate,
159
+ id: z3.string(),
165
160
  type: z3.literal([SelectMenuDefaultValueType.Role, SelectMenuDefaultValueType.User])
166
161
  }).array().max(25).optional()
167
162
  });
168
163
  var selectMenuRolePredicate = selectMenuBasePredicate.extend({
169
164
  type: z3.literal(ComponentType.RoleSelect),
170
- default_values: z3.object({ id: snowflakePredicate, type: z3.literal(SelectMenuDefaultValueType.Role) }).array().max(25).optional()
165
+ default_values: z3.object({ id: z3.string(), type: z3.literal(SelectMenuDefaultValueType.Role) }).array().max(25).optional()
171
166
  });
172
167
  var selectMenuStringOptionPredicate = z3.object({
173
- label: z3.string().min(1).max(100),
168
+ label: labelPredicate,
174
169
  value: z3.string().min(1).max(100),
175
170
  description: z3.string().min(1).max(100).optional(),
176
171
  emoji: emojiPredicate.optional(),
@@ -208,7 +203,7 @@ var selectMenuStringPredicate = selectMenuBasePredicate.extend({
208
203
  });
209
204
  var selectMenuUserPredicate = selectMenuBasePredicate.extend({
210
205
  type: z3.literal(ComponentType.UserSelect),
211
- default_values: z3.object({ id: snowflakePredicate, type: z3.literal(SelectMenuDefaultValueType.User) }).array().max(25).optional()
206
+ default_values: z3.object({ id: z3.string(), type: z3.literal(SelectMenuDefaultValueType.User) }).array().max(25).optional()
212
207
  });
213
208
  var actionRowPredicate = z3.object({
214
209
  id: idPredicate,
@@ -2517,7 +2512,7 @@ __name(resolveAccessoryComponent, "resolveAccessoryComponent");
2517
2512
  // src/components/label/Assertions.ts
2518
2513
  import { ComponentType as ComponentType24 } from "discord-api-types/v10";
2519
2514
  import { z as z7 } from "zod";
2520
- var labelPredicate = z7.object({
2515
+ var labelPredicate2 = z7.object({
2521
2516
  id: idPredicate,
2522
2517
  type: z7.literal(ComponentType24.Label),
2523
2518
  label: z7.string().min(1).max(45),
@@ -2670,7 +2665,7 @@ var LabelBuilder = class extends ComponentBuilder {
2670
2665
  // The label predicate validates the component.
2671
2666
  component: component?.toJSON(false)
2672
2667
  };
2673
- validate(labelPredicate, data, validationOverride);
2668
+ validate(labelPredicate2, data, validationOverride);
2674
2669
  return data;
2675
2670
  }
2676
2671
  };
@@ -3000,8 +2995,8 @@ var numberOptionPredicate = z8.object({
3000
2995
  ...numericMixinNumberOptionPredicate.shape
3001
2996
  }).and(autocompleteOrNumberChoicesMixinOptionPredicate);
3002
2997
  var stringOptionPredicate = basicOptionPredicate.extend({
3003
- max_length: z8.number().min(1).max(6e3).optional(),
3004
- min_length: z8.number().min(0).max(6e3).optional()
2998
+ max_length: z8.number().min(0).max(6e3).optional(),
2999
+ min_length: z8.number().min(1).max(6e3).optional()
3005
3000
  }).and(autocompleteOrStringChoicesMixinOptionPredicate);
3006
3001
  var baseChatInputCommandPredicate = sharedNameAndDescriptionPredicate.extend({
3007
3002
  contexts: z8.array(z8.enum(InteractionContextType)).optional(),
@@ -3011,12 +3006,8 @@ var baseChatInputCommandPredicate = sharedNameAndDescriptionPredicate.extend({
3011
3006
  });
3012
3007
  var chatInputCommandOptionsPredicate = z8.union([
3013
3008
  z8.object({ type: basicOptionTypesPredicate }).array(),
3014
- z8.object({
3015
- type: z8.union([
3016
- z8.literal(ApplicationCommandOptionType.Subcommand),
3017
- z8.literal(ApplicationCommandOptionType.SubcommandGroup)
3018
- ])
3019
- }).array()
3009
+ z8.object({ type: z8.literal(ApplicationCommandOptionType.Subcommand) }).array(),
3010
+ z8.object({ type: z8.literal(ApplicationCommandOptionType.SubcommandGroup) }).array()
3020
3011
  ]);
3021
3012
  var chatInputCommandPredicate = baseChatInputCommandPredicate.extend({
3022
3013
  options: chatInputCommandOptionsPredicate.optional()
@@ -3667,7 +3658,7 @@ var modalPredicate = z10.object({
3667
3658
  type: z10.literal(ComponentType26.ActionRow),
3668
3659
  components: z10.object({ type: z10.literal(ComponentType26.TextInput) }).array().length(1)
3669
3660
  }),
3670
- labelPredicate,
3661
+ labelPredicate2,
3671
3662
  textDisplayPredicate
3672
3663
  ]).array().min(1).max(5)
3673
3664
  });
@@ -3791,8 +3782,15 @@ var ModalBuilder = class {
3791
3782
  };
3792
3783
 
3793
3784
  // src/messages/embed/Assertions.ts
3794
- import { embedLength } from "@discordjs/util";
3795
3785
  import { z as z11 } from "zod";
3786
+
3787
+ // src/util/componentUtil.ts
3788
+ function embedLength(data) {
3789
+ return (data.title?.length ?? 0) + (data.description?.length ?? 0) + (data.fields?.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) ?? 0) + (data.footer?.text.length ?? 0) + (data.author?.name.length ?? 0);
3790
+ }
3791
+ __name(embedLength, "embedLength");
3792
+
3793
+ // src/messages/embed/Assertions.ts
3796
3794
  var namePredicate3 = z11.string().max(256);
3797
3795
  var URLPredicate = z11.url({ protocol: /^https?$/ });
3798
3796
  var URLWithAttachmentProtocolPredicate = z11.url({ protocol: /^(?:https?|attachment)$/ });
@@ -4647,19 +4645,10 @@ var PollBuilder = class {
4647
4645
  };
4648
4646
 
4649
4647
  // src/messages/Assertions.ts
4650
- import { Buffer as Buffer2 } from "buffer";
4651
4648
  import { AllowedMentionsTypes, ComponentType as ComponentType27, MessageFlags, MessageReferenceType } from "discord-api-types/v10";
4652
4649
  import { z as z13 } from "zod";
4653
- var fileKeyRegex = /^files\[(?<placeholder>\d+?)]$/;
4654
- var rawFilePredicate = z13.object({
4655
- data: z13.union([z13.instanceof(Buffer2), z13.instanceof(Uint8Array), z13.string()]),
4656
- name: z13.string().min(1),
4657
- contentType: z13.string().optional(),
4658
- key: z13.string().regex(fileKeyRegex).optional()
4659
- });
4660
4650
  var attachmentPredicate = z13.object({
4661
- // As a string it only makes sense for edits when we do have an attachment snowflake
4662
- id: z13.union([snowflakePredicate, z13.number()]),
4651
+ id: z13.union([z13.string(), z13.number()]),
4663
4652
  description: z13.string().max(1024).optional(),
4664
4653
  duration_secs: z13.number().max(2 ** 31 - 1).optional(),
4665
4654
  filename: z13.string().max(1024).optional(),
@@ -4745,11 +4734,6 @@ var messageComponentsV2Predicate = baseMessagePredicate.extend({
4745
4734
  poll: z13.null().optional()
4746
4735
  });
4747
4736
  var messagePredicate = z13.union([messageNoComponentsV2Predicate, messageComponentsV2Predicate]);
4748
- var fileBodyMessagePredicate = z13.object({
4749
- body: messagePredicate,
4750
- // No min length to support message edits
4751
- files: rawFilePredicate.array().max(10)
4752
- });
4753
4737
 
4754
4738
  // src/messages/AllowedMentions.ts
4755
4739
  var AllowedMentionsBuilder = class {
@@ -4934,29 +4918,13 @@ var AttachmentBuilder = class {
4934
4918
  * The API data associated with this attachment.
4935
4919
  */
4936
4920
  data;
4937
- /**
4938
- * This data is not included in the output of `toJSON()`. For this class specifically, this refers to binary data
4939
- * that will wind up being included in the multipart/form-data request, if used with the `MessageBuilder`.
4940
- * To retrieve this data, use {@link getRawFile}.
4941
- *
4942
- * @remarks This cannot be set via the constructor, primarily because of the behavior described
4943
- * {@link https://discord.com/developers/docs/reference#editing-message-attachments | here}.
4944
- * That is, when editing a message's attachments, you should only be providing file data for new attachments.
4945
- */
4946
- fileData;
4947
4921
  /**
4948
4922
  * Creates a new attachment builder.
4949
4923
  *
4950
4924
  * @param data - The API data to create this attachment with
4951
- * @example
4952
- * ```ts
4953
- * const attachment = new AttachmentBuilder().setId(1).setFileData(':)').setFilename('smiley.txt')
4954
- * ```
4955
- * @remarks Please note that the `id` field is required, it's rather easy to miss!
4956
4925
  */
4957
4926
  constructor(data = {}) {
4958
4927
  this.data = structuredClone(data);
4959
- this.fileData = {};
4960
4928
  }
4961
4929
  /**
4962
4930
  * Sets the id of the attachment.
@@ -5015,54 +4983,6 @@ var AttachmentBuilder = class {
5015
4983
  this.data.filename = void 0;
5016
4984
  return this;
5017
4985
  }
5018
- /**
5019
- * Sets the file data to upload with this attachment.
5020
- *
5021
- * @param data - The file data
5022
- * @remarks Note that this data is NOT included in the {@link toJSON} output. To retrieve it, use {@link getRawFile}.
5023
- */
5024
- setFileData(data) {
5025
- this.fileData.data = data;
5026
- return this;
5027
- }
5028
- /**
5029
- * Clears the file data from this attachment.
5030
- */
5031
- clearFileData() {
5032
- this.fileData.data = void 0;
5033
- return this;
5034
- }
5035
- /**
5036
- * Sets the content type of the file data to upload with this attachment.
5037
- *
5038
- * @remarks Note that this data is NOT included in the {@link toJSON} output. To retrieve it, use {@link getRawFile}.
5039
- */
5040
- setFileContentType(contentType) {
5041
- this.fileData.contentType = contentType;
5042
- return this;
5043
- }
5044
- /**
5045
- * Clears the content type of the file data from this attachment.
5046
- */
5047
- clearFileContentType() {
5048
- this.fileData.contentType = void 0;
5049
- return this;
5050
- }
5051
- /**
5052
- * Converts this attachment to a {@link RawFile} for uploading.
5053
- *
5054
- * @returns A {@link RawFile} object, or `undefined` if no file data is set
5055
- */
5056
- getRawFile() {
5057
- if (!this.fileData?.data) {
5058
- return;
5059
- }
5060
- return {
5061
- ...this.fileData,
5062
- name: this.data.filename,
5063
- key: this.data.id === void 0 ? void 0 : `files[${this.data.id}]`
5064
- };
5065
- }
5066
4986
  /**
5067
4987
  * Sets the title of this attachment.
5068
4988
  *
@@ -5367,7 +5287,7 @@ var MessageBuilder = class {
5367
5287
  *
5368
5288
  * @param allowedMentions - The allowed mentions to set
5369
5289
  */
5370
- setAllowedMentions(allowedMentions = new AllowedMentionsBuilder()) {
5290
+ setAllowedMentions(allowedMentions) {
5371
5291
  this.data.allowed_mentions = resolveBuilder(allowedMentions, AllowedMentionsBuilder);
5372
5292
  return this;
5373
5293
  }
@@ -5700,31 +5620,10 @@ var MessageBuilder = class {
5700
5620
  validate(messagePredicate, data, validationOverride);
5701
5621
  return data;
5702
5622
  }
5703
- /**
5704
- * Serializes this builder to both JSON body and file data for multipart/form-data requests.
5705
- *
5706
- * @param validationOverride - Force validation to run/not run regardless of your global preference
5707
- * @remarks
5708
- * This method extracts file data from attachments that have files set via {@link AttachmentBuilder.setFileData}.
5709
- * The returned body includes attachment metadata, while files contains the binary data for upload.
5710
- */
5711
- toFileBody(validationOverride) {
5712
- const body = this.toJSON(false);
5713
- const files = [];
5714
- for (const attachment of this.data.attachments) {
5715
- const rawFile = attachment.getRawFile();
5716
- if (rawFile?.data || rawFile?.contentType) {
5717
- files.push(rawFile);
5718
- }
5719
- }
5720
- const combined = { body, files };
5721
- validate(fileBodyMessagePredicate, combined, validationOverride);
5722
- return combined;
5723
- }
5724
5623
  };
5725
5624
 
5726
5625
  // src/index.ts
5727
- var version = "2.0.0-pr-11006.1765452229-e636950b2";
5626
+ var version = "2.0.0-pr-11005.1765454364-f3f6d34e7";
5728
5627
  export {
5729
5628
  ActionRowBuilder,
5730
5629
  AllowedMentionsBuilder,
@@ -5812,16 +5711,16 @@ export {
5812
5711
  embedAuthorPredicate,
5813
5712
  embedFieldPredicate,
5814
5713
  embedFooterPredicate,
5714
+ embedLength,
5815
5715
  embedPredicate,
5816
5716
  emojiPredicate,
5817
5717
  enableValidators,
5818
- fileBodyMessagePredicate,
5819
5718
  filePredicate,
5820
5719
  fileUploadPredicate,
5821
5720
  idPredicate,
5822
5721
  integerOptionPredicate,
5823
5722
  isValidationEnabled,
5824
- labelPredicate,
5723
+ labelPredicate2 as labelPredicate,
5825
5724
  localeMapPredicate,
5826
5725
  mediaGalleryItemPredicate,
5827
5726
  mediaGalleryPredicate,
@@ -5836,7 +5735,6 @@ export {
5836
5735
  pollAnswerPredicate,
5837
5736
  pollPredicate,
5838
5737
  pollQuestionPredicate,
5839
- rawFilePredicate,
5840
5738
  resolveAccessoryComponent,
5841
5739
  resolveBuilder,
5842
5740
  sectionPredicate,
@@ -5847,7 +5745,6 @@ export {
5847
5745
  selectMenuStringPredicate,
5848
5746
  selectMenuUserPredicate,
5849
5747
  separatorPredicate,
5850
- snowflakePredicate,
5851
5748
  stringOptionPredicate,
5852
5749
  textDisplayPredicate,
5853
5750
  textInputPredicate,