discord.js 15.0.0-djs-file-upload.1761302390-5ae769c9e → 15.0.0-pr-11006.1765450224-e636950b2

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.
Files changed (44) hide show
  1. package/package.json +18 -20
  2. package/src/client/Client.js +110 -24
  3. package/src/client/websocket/handlers/RATE_LIMITED.js +24 -0
  4. package/src/client/websocket/handlers/READY.js +4 -0
  5. package/src/client/websocket/handlers/index.js +1 -0
  6. package/src/errors/DJSError.js +7 -3
  7. package/src/errors/ErrorCodes.js +2 -4
  8. package/src/errors/Messages.js +2 -3
  9. package/src/index.js +0 -3
  10. package/src/managers/CachedManager.js +5 -5
  11. package/src/managers/ChannelManager.js +10 -7
  12. package/src/managers/GuildBanManager.js +3 -3
  13. package/src/managers/GuildEmojiManager.js +2 -2
  14. package/src/managers/GuildEmojiRoleManager.js +9 -1
  15. package/src/managers/GuildMemberManager.js +44 -23
  16. package/src/managers/GuildMemberRoleManager.js +11 -2
  17. package/src/managers/MessageManager.js +25 -18
  18. package/src/structures/ApplicationCommand.js +4 -5
  19. package/src/structures/ClientApplication.js +2 -0
  20. package/src/structures/Embed.js +1 -1
  21. package/src/structures/Guild.js +11 -1
  22. package/src/structures/GuildInvite.js +1 -1
  23. package/src/structures/GuildMember.js +12 -9
  24. package/src/structures/Message.js +18 -15
  25. package/src/structures/MessagePayload.js +21 -17
  26. package/src/structures/ModalComponentResolver.js +1 -1
  27. package/src/structures/ModalSubmitInteraction.js +6 -6
  28. package/src/structures/PermissionOverwrites.js +1 -1
  29. package/src/structures/Role.js +1 -1
  30. package/src/structures/ThreadChannel.js +1 -1
  31. package/src/structures/Webhook.js +6 -11
  32. package/src/structures/interfaces/TextBasedChannel.js +7 -9
  33. package/src/util/APITypes.js +10 -0
  34. package/src/util/Components.js +52 -42
  35. package/src/util/Constants.js +2 -0
  36. package/src/util/DataResolver.js +5 -2
  37. package/src/util/GuildMemberFlagsBitField.js +1 -1
  38. package/src/util/Options.js +9 -5
  39. package/src/util/Util.js +18 -13
  40. package/typings/index.d.mts +148 -173
  41. package/typings/index.d.ts +148 -173
  42. package/src/client/BaseClient.js +0 -131
  43. package/src/client/WebhookClient.js +0 -119
  44. package/src/structures/AttachmentBuilder.js +0 -185
@@ -1,9 +1,37 @@
1
- /* eslint-disable no-use-before-define */
2
1
  'use strict';
3
2
 
4
- // eslint-disable-next-line import-x/order
3
+ const { lazy } = require('@discordjs/util');
5
4
  const { ComponentType } = require('discord-api-types/v10');
6
5
 
6
+ // Fixes circular dependencies.
7
+ const getActionRow = lazy(() => require('../structures/ActionRow.js').ActionRow);
8
+ const getButtonComponent = lazy(() => require('../structures/ButtonComponent.js').ButtonComponent);
9
+ const getChannelSelectMenuComponent = lazy(
10
+ () => require('../structures/ChannelSelectMenuComponent.js').ChannelSelectMenuComponent,
11
+ );
12
+ const getComponent = lazy(() => require('../structures/Component.js').Component);
13
+ const getContainerComponent = lazy(() => require('../structures/ContainerComponent.js').ContainerComponent);
14
+ const getFileComponent = lazy(() => require('../structures/FileComponent.js').FileComponent);
15
+ const getLabelComponent = lazy(() => require('../structures/LabelComponent.js').LabelComponent);
16
+ const getMediaGalleryComponent = lazy(() => require('../structures/MediaGalleryComponent.js').MediaGalleryComponent);
17
+ const getMentionableSelectMenuComponent = lazy(
18
+ () => require('../structures/MentionableSelectMenuComponent.js').MentionableSelectMenuComponent,
19
+ );
20
+ const getRoleSelectMenuComponent = lazy(
21
+ () => require('../structures/RoleSelectMenuComponent.js').RoleSelectMenuComponent,
22
+ );
23
+ const getSectionComponent = lazy(() => require('../structures/SectionComponent.js').SectionComponent);
24
+ const getSeparatorComponent = lazy(() => require('../structures/SeparatorComponent.js').SeparatorComponent);
25
+ const getStringSelectMenuComponent = lazy(
26
+ () => require('../structures/StringSelectMenuComponent.js').StringSelectMenuComponent,
27
+ );
28
+ const getTextDisplayComponent = lazy(() => require('../structures/TextDisplayComponent.js').TextDisplayComponent);
29
+ const getTextInputComponent = lazy(() => require('../structures/TextInputComponent.js').TextInputComponent);
30
+ const getThumbnailComponent = lazy(() => require('../structures/ThumbnailComponent.js').ThumbnailComponent);
31
+ const getUserSelectMenuComponent = lazy(
32
+ () => require('../structures/UserSelectMenuComponent.js').UserSelectMenuComponent,
33
+ );
34
+
7
35
  /**
8
36
  * @typedef {Object} BaseComponentData
9
37
  * @property {number} [id] the id of this component
@@ -47,7 +75,7 @@ const { ComponentType } = require('discord-api-types/v10');
47
75
  /**
48
76
  * @typedef {BaseComponentData} FileUploadComponentData
49
77
  * @property {string} customId The custom id of the file upload
50
- * @property {number} [minValues] The minimum number of files that can be uploaded (0-10)
78
+ * @property {number} [minValues] The minimum number of files that must be uploaded (0-10)
51
79
  * @property {number} [maxValues] The maximum number of files that can be uploaded (1-10)
52
80
  * @property {boolean} [required] Whether this component is required in modals
53
81
  */
@@ -57,7 +85,7 @@ const { ComponentType } = require('discord-api-types/v10');
57
85
  * @property {string} customId The custom id of the select menu
58
86
  * @property {boolean} [disabled] Whether the select menu is disabled or not
59
87
  * @property {number} [maxValues] The maximum amount of options that can be selected
60
- * @property {number} [minValues] The minimum amount of options that can be selected
88
+ * @property {number} [minValues] The minimum amount of options that must be selected
61
89
  * @property {string} [placeholder] The placeholder of the select menu
62
90
  * @property {boolean} [required] Whether this component is required in modals
63
91
  */
@@ -192,6 +220,25 @@ const { ComponentType } = require('discord-api-types/v10');
192
220
  * SectionComponent|SeparatorComponent|TextDisplayComponent} MessageTopLevelComponent
193
221
  */
194
222
 
223
+ const ComponentTypeToClass = {
224
+ [ComponentType.ActionRow]: getActionRow,
225
+ [ComponentType.Button]: getButtonComponent,
226
+ [ComponentType.StringSelect]: getStringSelectMenuComponent,
227
+ [ComponentType.TextInput]: getTextInputComponent,
228
+ [ComponentType.UserSelect]: getUserSelectMenuComponent,
229
+ [ComponentType.RoleSelect]: getRoleSelectMenuComponent,
230
+ [ComponentType.MentionableSelect]: getMentionableSelectMenuComponent,
231
+ [ComponentType.ChannelSelect]: getChannelSelectMenuComponent,
232
+ [ComponentType.Container]: getContainerComponent,
233
+ [ComponentType.TextDisplay]: getTextDisplayComponent,
234
+ [ComponentType.File]: getFileComponent,
235
+ [ComponentType.MediaGallery]: getMediaGalleryComponent,
236
+ [ComponentType.Section]: getSectionComponent,
237
+ [ComponentType.Separator]: getSeparatorComponent,
238
+ [ComponentType.Thumbnail]: getThumbnailComponent,
239
+ [ComponentType.Label]: getLabelComponent,
240
+ };
241
+
195
242
  /**
196
243
  * Transforms API data into a component
197
244
  *
@@ -200,7 +247,7 @@ const { ComponentType } = require('discord-api-types/v10');
200
247
  * @ignore
201
248
  */
202
249
  function createComponent(data) {
203
- return data instanceof Component ? data : new (ComponentTypeToClass[data.type] ?? Component)(data);
250
+ return data instanceof getComponent() ? data : new (ComponentTypeToClass[data.type]?.() ?? getComponent())(data);
204
251
  }
205
252
 
206
253
  /**
@@ -241,40 +288,3 @@ function findComponentByCustomId(components, customId) {
241
288
 
242
289
  exports.createComponent = createComponent;
243
290
  exports.findComponentByCustomId = findComponentByCustomId;
244
-
245
- const { ActionRow } = require('../structures/ActionRow.js');
246
- const { ButtonComponent } = require('../structures/ButtonComponent.js');
247
- const { ChannelSelectMenuComponent } = require('../structures/ChannelSelectMenuComponent.js');
248
- const { Component } = require('../structures/Component.js');
249
- const { ContainerComponent } = require('../structures/ContainerComponent.js');
250
- const { FileComponent } = require('../structures/FileComponent.js');
251
- const { LabelComponent } = require('../structures/LabelComponent.js');
252
- const { MediaGalleryComponent } = require('../structures/MediaGalleryComponent.js');
253
- const { MentionableSelectMenuComponent } = require('../structures/MentionableSelectMenuComponent.js');
254
- const { RoleSelectMenuComponent } = require('../structures/RoleSelectMenuComponent.js');
255
- const { SectionComponent } = require('../structures/SectionComponent.js');
256
- const { SeparatorComponent } = require('../structures/SeparatorComponent.js');
257
- const { StringSelectMenuComponent } = require('../structures/StringSelectMenuComponent.js');
258
- const { TextDisplayComponent } = require('../structures/TextDisplayComponent.js');
259
- const { TextInputComponent } = require('../structures/TextInputComponent.js');
260
- const { ThumbnailComponent } = require('../structures/ThumbnailComponent.js');
261
- const { UserSelectMenuComponent } = require('../structures/UserSelectMenuComponent.js');
262
-
263
- const ComponentTypeToClass = {
264
- [ComponentType.ActionRow]: ActionRow,
265
- [ComponentType.Button]: ButtonComponent,
266
- [ComponentType.StringSelect]: StringSelectMenuComponent,
267
- [ComponentType.TextInput]: TextInputComponent,
268
- [ComponentType.UserSelect]: UserSelectMenuComponent,
269
- [ComponentType.RoleSelect]: RoleSelectMenuComponent,
270
- [ComponentType.MentionableSelect]: MentionableSelectMenuComponent,
271
- [ComponentType.ChannelSelect]: ChannelSelectMenuComponent,
272
- [ComponentType.Container]: ContainerComponent,
273
- [ComponentType.TextDisplay]: TextDisplayComponent,
274
- [ComponentType.File]: FileComponent,
275
- [ComponentType.MediaGallery]: MediaGalleryComponent,
276
- [ComponentType.Section]: SectionComponent,
277
- [ComponentType.Separator]: SeparatorComponent,
278
- [ComponentType.Thumbnail]: ThumbnailComponent,
279
- [ComponentType.Label]: LabelComponent,
280
- };
@@ -202,6 +202,7 @@ exports.UndeletableMessageTypes = [
202
202
  MessageType.ThreadStarterMessage,
203
203
  ];
204
204
 
205
+ /* eslint-disable jsdoc/valid-types */
205
206
  /**
206
207
  * A mapping between sticker formats and their respective image formats.
207
208
  * - {@link StickerFormatType.PNG} -> {@link ImageFormat.PNG}
@@ -221,6 +222,7 @@ exports.StickerFormatExtensionMap = {
221
222
  [StickerFormatType.Lottie]: ImageFormat.Lottie,
222
223
  [StickerFormatType.GIF]: ImageFormat.GIF,
223
224
  };
225
+ /* eslint-enable jsdoc/valid-types */
224
226
 
225
227
  /**
226
228
  * Holographic color values for role styling.
@@ -3,10 +3,14 @@
3
3
  const { Buffer } = require('node:buffer');
4
4
  const fs = require('node:fs/promises');
5
5
  const path = require('node:path');
6
+ const { lazy } = require('@discordjs/util');
6
7
  const { fetch } = require('undici');
7
8
  const { DiscordjsError, DiscordjsTypeError, ErrorCodes } = require('../errors/index.js');
8
9
  const { BaseInvite } = require('../structures/BaseInvite.js');
9
10
 
11
+ // Fixes circular dependencies.
12
+ const getGuildTemplate = lazy(() => require('../structures/GuildTemplate.js').GuildTemplate);
13
+
10
14
  /**
11
15
  * Data that can be resolved to give an invite code. This can be:
12
16
  * - An invite code
@@ -54,8 +58,7 @@ function resolveInviteCode(data) {
54
58
  * @private
55
59
  */
56
60
  function resolveGuildTemplateCode(data) {
57
- const { GuildTemplate } = require('../structures/GuildTemplate.js');
58
- return resolveCode(data, GuildTemplate.GuildTemplatesPattern);
61
+ return resolveCode(data, getGuildTemplate().GuildTemplatesPattern);
59
62
  }
60
63
 
61
64
  /**
@@ -11,7 +11,7 @@ const { BitField } = require('./BitField.js');
11
11
  */
12
12
  class GuildMemberFlagsBitField extends BitField {
13
13
  /**
14
- * Numeric guild guild member flags.
14
+ * Numeric guild member flags.
15
15
  *
16
16
  * @type {GuildMemberFlags}
17
17
  * @memberof GuildMemberFlagsBitField
@@ -5,12 +5,16 @@ const { DefaultWebSocketManagerOptions } = require('@discordjs/ws');
5
5
  const { version } = require('../../package.json');
6
6
  const { toSnakeCase } = require('./Transformers.js');
7
7
 
8
- // TODO(ckohen): switch order of params so full manager is first and "type" is optional
8
+ /**
9
+ * @typedef {Object} CacheFactoryParams
10
+ * @property {Function} holds The class that the cache will hold.
11
+ * @property {Function} manager The fully extended manager class the cache is being requested from.
12
+ * @property {Function} managerType The base manager class the cache is being requested from.
13
+ */
14
+
9
15
  /**
10
16
  * @typedef {Function} CacheFactory
11
- * @param {Function} managerType The base manager class the cache is being requested from.
12
- * @param {Function} holds The class that the cache will hold.
13
- * @param {Function} manager The fully extended manager class the cache is being requested from.
17
+ * @param {CacheFactoryParams} params The parameters
14
18
  * @returns {Collection} A Collection used to store the cache of the manager.
15
19
  */
16
20
 
@@ -121,7 +125,7 @@ class Options extends null {
121
125
  const { Collection } = require('@discordjs/collection');
122
126
  const { LimitedCollection } = require('./LimitedCollection.js');
123
127
 
124
- return (managerType, _, manager) => {
128
+ return ({ managerType, manager }) => {
125
129
  const setting = settings[manager.name] ?? settings[managerType.name];
126
130
  /* eslint-disable-next-line eqeqeq */
127
131
  if (setting == null) {
package/src/util/Util.js CHANGED
@@ -2,13 +2,18 @@
2
2
 
3
3
  const { parse } = require('node:path');
4
4
  const { Collection } = require('@discordjs/collection');
5
+ const { lazy } = require('@discordjs/util');
5
6
  const { ChannelType, RouteBases, Routes } = require('discord-api-types/v10');
6
7
  const { fetch } = require('undici');
7
- // eslint-disable-next-line import-x/order
8
8
  const { Colors } = require('./Colors.js');
9
9
  // eslint-disable-next-line import-x/order
10
10
  const { DiscordjsError, DiscordjsRangeError, DiscordjsTypeError, ErrorCodes } = require('../errors/index.js');
11
11
 
12
+ // Fixes circular dependencies.
13
+ const getAttachment = lazy(() => require('../structures/Attachment.js').Attachment);
14
+ const getGuildChannel = lazy(() => require('../structures/GuildChannel.js').GuildChannel);
15
+ const getSKU = lazy(() => require('../structures/SKU.js').SKU);
16
+
12
17
  const isObject = data => typeof data === 'object' && data !== null;
13
18
 
14
19
  /**
@@ -352,8 +357,7 @@ function resolveColor(color) {
352
357
  * @returns {Collection}
353
358
  */
354
359
  function discordSort(collection) {
355
- // eslint-disable-next-line no-use-before-define
356
- const isGuildChannel = collection.first() instanceof GuildChannel;
360
+ const isGuildChannel = collection.first() instanceof getGuildChannel();
357
361
  return collection.toSorted(
358
362
  isGuildChannel
359
363
  ? (a, b) => a.rawPosition - b.rawPosition || Number(BigInt(a.id) - BigInt(b.id))
@@ -469,11 +473,19 @@ function cleanCodeBlockContent(text) {
469
473
  return text.replaceAll('```', '`\u200B``');
470
474
  }
471
475
 
476
+ /**
477
+ * Represents the credentials used for a webhook in the form of its id and token.
478
+ *
479
+ * @typedef {Object} WebhookDataIdWithToken
480
+ * @property {Snowflake} id The webhook's id
481
+ * @property {string} token The webhook's token
482
+ */
483
+
472
484
  /**
473
485
  * Parses a webhook URL for the id and token.
474
486
  *
475
487
  * @param {string} url The URL to parse
476
- * @returns {?WebhookClientDataIdWithToken} `null` if the URL is invalid, otherwise the id and the token
488
+ * @returns {?WebhookDataIdWithToken} `null` if the URL is invalid, otherwise the id and the token
477
489
  */
478
490
  function parseWebhookURL(url) {
479
491
  const matches =
@@ -547,8 +559,7 @@ function transformResolved(
547
559
  if (attachments) {
548
560
  result.attachments = new Collection();
549
561
  for (const attachment of Object.values(attachments)) {
550
- // eslint-disable-next-line no-use-before-define
551
- const patched = new Attachment(attachment);
562
+ const patched = new (getAttachment())(attachment);
552
563
  result.attachments.set(attachment.id, patched);
553
564
  }
554
565
  }
@@ -564,8 +575,7 @@ function transformResolved(
564
575
  */
565
576
  function resolveSKUId(resolvable) {
566
577
  if (typeof resolvable === 'string') return resolvable;
567
- // eslint-disable-next-line no-use-before-define
568
- if (resolvable instanceof SKU) return resolvable.id;
578
+ if (resolvable instanceof getSKU()) return resolvable.id;
569
579
  return null;
570
580
  }
571
581
 
@@ -592,8 +602,3 @@ exports.setPosition = setPosition;
592
602
  exports.basename = basename;
593
603
  exports.findName = findName;
594
604
  exports.transformResolved = transformResolved;
595
-
596
- // Fixes Circular
597
- const { Attachment } = require('../structures/Attachment.js');
598
- const { GuildChannel } = require('../structures/GuildChannel.js');
599
- const { SKU } = require('../structures/SKU.js');