magmastream 2.9.0-dev.35 → 2.9.0-dev.37

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.js CHANGED
@@ -6,7 +6,7 @@ tslib_1.__exportStar(require("./structures/Manager"), exports);
6
6
  tslib_1.__exportStar(require("./structures/Node"), exports);
7
7
  tslib_1.__exportStar(require("./structures/Player"), exports);
8
8
  tslib_1.__exportStar(require("./structures/Plugin"), exports);
9
- tslib_1.__exportStar(require("./structures/Queue"), exports);
9
+ tslib_1.__exportStar(require("./statestorage/MemoryQueue"), exports);
10
10
  tslib_1.__exportStar(require("./structures/Rest"), exports);
11
11
  tslib_1.__exportStar(require("./structures/Utils"), exports);
12
12
  // wrappers
@@ -14,6 +14,11 @@ tslib_1.__exportStar(require("./wrappers/discord.js"), exports);
14
14
  tslib_1.__exportStar(require("./wrappers/eris"), exports);
15
15
  tslib_1.__exportStar(require("./wrappers/detritus"), exports);
16
16
  tslib_1.__exportStar(require("./wrappers/oceanic"), exports);
17
+ tslib_1.__exportStar(require("./wrappers/seyfert"), exports);
17
18
  // types
18
19
  tslib_1.__exportStar(require("./structures/Types"), exports);
19
20
  tslib_1.__exportStar(require("./structures/Enums"), exports);
21
+ // state storage
22
+ tslib_1.__exportStar(require("./statestorage/MemoryQueue"), exports);
23
+ tslib_1.__exportStar(require("./statestorage/JsonQueue"), exports);
24
+ tslib_1.__exportStar(require("./statestorage/RedisQueue"), exports);
@@ -0,0 +1,436 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonQueue = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const Enums_1 = require("../structures/Enums");
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const fs_1 = require("fs");
8
+ /**
9
+ * The player's queue, the `current` property is the currently playing track, think of the rest as the up-coming tracks.
10
+ */
11
+ class JsonQueue {
12
+ guildId;
13
+ manager;
14
+ basePath;
15
+ /**
16
+ * @param guildId The guild ID.
17
+ * @param manager The manager.
18
+ */
19
+ constructor(guildId, manager) {
20
+ this.guildId = guildId;
21
+ this.manager = manager;
22
+ const base = manager.options.stateStorage?.jsonConfig?.path ?? path_1.default.join(process.cwd(), "magmastream", "dist", "sessionData", "players");
23
+ this.basePath = path_1.default.join(base, this.guildId);
24
+ }
25
+ /**
26
+ * @returns The queue path.
27
+ */
28
+ get queuePath() {
29
+ return path_1.default.join(this.basePath, "queue.json");
30
+ }
31
+ /**
32
+ * @returns The current path.
33
+ */
34
+ get currentPath() {
35
+ return path_1.default.join(this.basePath, "current.json");
36
+ }
37
+ /**
38
+ * @returns The previous path.
39
+ */
40
+ get previousPath() {
41
+ return path_1.default.join(this.basePath, "previous.json");
42
+ }
43
+ /**
44
+ * Ensures the directory exists.
45
+ */
46
+ async ensureDir() {
47
+ await fs_1.promises.mkdir(this.basePath, { recursive: true });
48
+ }
49
+ /**
50
+ * @returns The queue.
51
+ */
52
+ async getQueue() {
53
+ const data = await this.readJSON(this.queuePath);
54
+ return Array.isArray(data) ? data : [];
55
+ }
56
+ /**
57
+ * @param queue The queue.
58
+ */
59
+ async setQueue(queue) {
60
+ await this.writeJSON(this.queuePath, queue);
61
+ }
62
+ /**
63
+ * @param filePath The file path.
64
+ * @returns The JSON data.
65
+ */
66
+ async readJSON(filePath) {
67
+ try {
68
+ const raw = await fs_1.promises.readFile(filePath, "utf-8");
69
+ return JSON.parse(raw);
70
+ }
71
+ catch {
72
+ return null;
73
+ }
74
+ }
75
+ /**
76
+ * @param filePath The file path.
77
+ * @param data The data to write.
78
+ */
79
+ async writeJSON(filePath, data) {
80
+ await this.ensureDir();
81
+ await fs_1.promises.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
82
+ }
83
+ /**
84
+ * @param filePath The file path.
85
+ */
86
+ async deleteFile(filePath) {
87
+ try {
88
+ await fs_1.promises.unlink(filePath);
89
+ }
90
+ catch {
91
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Failed to delete file: ${filePath}`);
92
+ }
93
+ }
94
+ /**
95
+ * @returns The current track.
96
+ */
97
+ async getCurrent() {
98
+ return await this.readJSON(this.currentPath);
99
+ }
100
+ /**
101
+ * @param track The track to set.
102
+ */
103
+ async setCurrent(track) {
104
+ if (track) {
105
+ await this.writeJSON(this.currentPath, track);
106
+ }
107
+ else {
108
+ await this.deleteFile(this.currentPath);
109
+ }
110
+ }
111
+ /**
112
+ * @returns The previous tracks.
113
+ */
114
+ async getPrevious() {
115
+ const data = await this.readJSON(this.previousPath);
116
+ return Array.isArray(data) ? data : [];
117
+ }
118
+ /**
119
+ * @param track The track to add.
120
+ */
121
+ async addPrevious(track) {
122
+ const tracks = Array.isArray(track) ? track : [track];
123
+ if (!tracks.length)
124
+ return;
125
+ const current = await this.getPrevious();
126
+ await this.writeJSON(this.previousPath, [...tracks.reverse(), ...current]);
127
+ }
128
+ /**
129
+ * @param track The track to set.
130
+ */
131
+ async setPrevious(track) {
132
+ const tracks = Array.isArray(track) ? track : [track];
133
+ if (!tracks.length)
134
+ return;
135
+ await this.writeJSON(this.previousPath, tracks);
136
+ }
137
+ /**
138
+ * @returns The newest track.
139
+ */
140
+ async popPrevious() {
141
+ const current = await this.getPrevious();
142
+ if (!current.length)
143
+ return null;
144
+ const popped = current.shift();
145
+ await this.writeJSON(this.previousPath, current);
146
+ return popped;
147
+ }
148
+ /**
149
+ * Clears the previous tracks.
150
+ */
151
+ async clearPrevious() {
152
+ await this.deleteFile(this.previousPath);
153
+ }
154
+ /**
155
+ * @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
156
+ * @param [offset=null] The position to add the track(s) at. If not provided, the track(s) will be added at the end of the queue.
157
+ */
158
+ async add(track, offset) {
159
+ const isArray = Array.isArray(track);
160
+ const inputTracks = isArray ? track : [track];
161
+ const tracks = [...inputTracks];
162
+ const queue = await this.getQueue();
163
+ const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
164
+ // Set first track as current if none is active
165
+ if (!(await this.getCurrent())) {
166
+ const current = tracks.shift();
167
+ if (current) {
168
+ await this.setCurrent(current);
169
+ }
170
+ }
171
+ if (typeof offset === "number" && !isNaN(offset)) {
172
+ queue.splice(offset, 0, ...tracks);
173
+ }
174
+ else {
175
+ queue.push(...tracks);
176
+ }
177
+ await this.setQueue(queue);
178
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Added ${tracks.length} track(s) to queue`);
179
+ if (this.manager.players.has(this.guildId) && this.manager.players.get(this.guildId).isAutoplay) {
180
+ if (!isArray) {
181
+ const botUser = (await this.manager.players.get(this.guildId).get("Internal_BotUser"));
182
+ if (botUser && botUser.id === track.requester.id) {
183
+ this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
184
+ changeType: Enums_1.PlayerStateEventTypes.QueueChange,
185
+ details: {
186
+ type: "queue",
187
+ action: "autoPlayAdd",
188
+ tracks: [track],
189
+ },
190
+ });
191
+ return;
192
+ }
193
+ }
194
+ }
195
+ this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
196
+ changeType: Enums_1.PlayerStateEventTypes.QueueChange,
197
+ details: {
198
+ type: "queue",
199
+ action: "add",
200
+ tracks,
201
+ },
202
+ });
203
+ }
204
+ async remove(startOrPos = 0, end) {
205
+ const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
206
+ const queue = await this.getQueue();
207
+ let removed = [];
208
+ if (typeof end === "number") {
209
+ if (startOrPos >= end || startOrPos >= queue.length)
210
+ throw new RangeError("Invalid range.");
211
+ removed = queue.splice(startOrPos, end - startOrPos);
212
+ }
213
+ else {
214
+ removed = queue.splice(startOrPos, 1);
215
+ }
216
+ await this.setQueue(queue);
217
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Removed ${removed.length} track(s) from position ${startOrPos}${end ? ` to ${end}` : ""}`);
218
+ this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
219
+ changeType: Enums_1.PlayerStateEventTypes.QueueChange,
220
+ details: {
221
+ type: "queue",
222
+ action: "remove",
223
+ tracks: removed,
224
+ },
225
+ });
226
+ return removed;
227
+ }
228
+ /**
229
+ * Clears the queue.
230
+ */
231
+ async clear() {
232
+ const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
233
+ await this.deleteFile(this.queuePath);
234
+ this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
235
+ changeType: Enums_1.PlayerStateEventTypes.QueueChange,
236
+ details: {
237
+ type: "queue",
238
+ action: "clear",
239
+ tracks: [],
240
+ },
241
+ });
242
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Cleared the queue for: ${this.guildId}`);
243
+ }
244
+ /**
245
+ * @returns The size of the queue.
246
+ */
247
+ async size() {
248
+ const queue = await this.getQueue();
249
+ return queue.length;
250
+ }
251
+ /**
252
+ * @returns The total size of the queue.
253
+ */
254
+ async totalSize() {
255
+ const size = await this.size();
256
+ return (await this.getCurrent()) ? size + 1 : size;
257
+ }
258
+ /**
259
+ * @returns The total duration of the queue.
260
+ */
261
+ async duration() {
262
+ const queue = await this.getQueue();
263
+ const current = await this.getCurrent();
264
+ const currentDuration = current?.duration || 0;
265
+ const total = queue.reduce((acc, track) => acc + (track.duration || 0), currentDuration);
266
+ return total;
267
+ }
268
+ /**
269
+ * Shuffles the queue.
270
+ */
271
+ async shuffle() {
272
+ const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
273
+ const queue = await this.getQueue();
274
+ for (let i = queue.length - 1; i > 0; i--) {
275
+ const j = Math.floor(Math.random() * (i + 1));
276
+ [queue[i], queue[j]] = [queue[j], queue[i]];
277
+ }
278
+ await this.setQueue(queue);
279
+ this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
280
+ changeType: Enums_1.PlayerStateEventTypes.QueueChange,
281
+ details: {
282
+ type: "queue",
283
+ action: "shuffle",
284
+ },
285
+ });
286
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Shuffled the queue for: ${this.guildId}`);
287
+ }
288
+ /**
289
+ * Shuffles the queue by user.
290
+ */
291
+ async userBlockShuffle() {
292
+ const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
293
+ const queue = await this.getQueue();
294
+ const userMap = new Map();
295
+ for (const track of queue) {
296
+ const userId = track.requester.id;
297
+ if (!userMap.has(userId))
298
+ userMap.set(userId, []);
299
+ userMap.get(userId).push(track);
300
+ }
301
+ const shuffledQueue = [];
302
+ while (shuffledQueue.length < queue.length) {
303
+ for (const [, tracks] of userMap) {
304
+ const track = tracks.shift();
305
+ if (track)
306
+ shuffledQueue.push(track);
307
+ }
308
+ }
309
+ await this.setQueue(shuffledQueue);
310
+ this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
311
+ changeType: Enums_1.PlayerStateEventTypes.QueueChange,
312
+ details: {
313
+ type: "queue",
314
+ action: "userBlock",
315
+ },
316
+ });
317
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] userBlockShuffled the queue for: ${this.guildId}`);
318
+ }
319
+ /**
320
+ * Shuffles the queue by round-robin.
321
+ */
322
+ async roundRobinShuffle() {
323
+ const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
324
+ const queue = await this.getQueue();
325
+ const userMap = new Map();
326
+ for (const track of queue) {
327
+ const userId = track.requester.id;
328
+ if (!userMap.has(userId))
329
+ userMap.set(userId, []);
330
+ userMap.get(userId).push(track);
331
+ }
332
+ // Shuffle each user's tracks
333
+ for (const tracks of userMap.values()) {
334
+ for (let i = tracks.length - 1; i > 0; i--) {
335
+ const j = Math.floor(Math.random() * (i + 1));
336
+ [tracks[i], tracks[j]] = [tracks[j], tracks[i]];
337
+ }
338
+ }
339
+ const users = [...userMap.keys()];
340
+ const queues = users.map((id) => userMap.get(id));
341
+ const shuffledQueue = [];
342
+ while (queues.some((q) => q.length > 0)) {
343
+ for (const q of queues) {
344
+ const track = q.shift();
345
+ if (track)
346
+ shuffledQueue.push(track);
347
+ }
348
+ }
349
+ await this.setQueue(shuffledQueue);
350
+ this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
351
+ changeType: Enums_1.PlayerStateEventTypes.QueueChange,
352
+ details: {
353
+ type: "queue",
354
+ action: "roundRobin",
355
+ },
356
+ });
357
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
358
+ }
359
+ /**
360
+ * Removes the first track from the queue.
361
+ */
362
+ async dequeue() {
363
+ const queue = await this.getQueue();
364
+ const track = queue.shift();
365
+ await this.setQueue(queue);
366
+ return track;
367
+ }
368
+ /**
369
+ * Adds a track to the front of the queue.
370
+ */
371
+ async enqueueFront(track) {
372
+ const tracks = Array.isArray(track) ? track : [track];
373
+ const queue = await this.getQueue();
374
+ await this.setQueue([...tracks.reverse(), ...queue]);
375
+ }
376
+ /**
377
+ * @returns The tracks in the queue.
378
+ */
379
+ async getTracks() {
380
+ return await this.getQueue();
381
+ }
382
+ /**
383
+ * @returns The tracks in the queue from start to end.
384
+ */
385
+ async getSlice(start = 0, end = -1) {
386
+ const queue = await this.getQueue();
387
+ if (end === -1)
388
+ return queue.slice(start);
389
+ return queue.slice(start, end);
390
+ }
391
+ /**
392
+ * Modifies the queue at the specified index.
393
+ */
394
+ async modifyAt(start, deleteCount = 0, ...items) {
395
+ const queue = await this.getQueue();
396
+ const removed = queue.splice(start, deleteCount, ...items);
397
+ await this.setQueue(queue);
398
+ return removed;
399
+ }
400
+ /**
401
+ * Maps the queue to a new array.
402
+ */
403
+ async mapAsync(callback) {
404
+ const queue = await this.getQueue();
405
+ return queue.map(callback);
406
+ }
407
+ /**
408
+ * Filters the queue.
409
+ */
410
+ async filterAsync(callback) {
411
+ const queue = await this.getQueue();
412
+ return queue.filter(callback);
413
+ }
414
+ /**
415
+ * Finds the first track in the queue that satisfies the provided testing function.
416
+ */
417
+ async findAsync(callback) {
418
+ const queue = await this.getQueue();
419
+ return queue.find(callback);
420
+ }
421
+ /**
422
+ * Tests whether at least one element in the queue passes the test implemented by the provided function.
423
+ */
424
+ async someAsync(callback) {
425
+ const queue = await this.getQueue();
426
+ return queue.some(callback);
427
+ }
428
+ /**
429
+ * Tests whether all elements in the queue pass the test implemented by the provided function.
430
+ */
431
+ async everyAsync(callback) {
432
+ const queue = await this.getQueue();
433
+ return queue.every(callback);
434
+ }
435
+ }
436
+ exports.JsonQueue = JsonQueue;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queue = void 0;
4
- const Enums_1 = require("./Enums");
3
+ exports.MemoryQueue = void 0;
4
+ const Enums_1 = require("../structures/Enums");
5
5
  /**
6
6
  * The player's queue, the `current` property is the currently playing track, think of the rest as the up-coming tracks.
7
7
  */
8
- class Queue extends Array {
8
+ class MemoryQueue extends Array {
9
9
  /** The current track */
10
10
  current = null;
11
11
  /** The previous tracks */
@@ -26,12 +26,21 @@ class Queue extends Array {
26
26
  /** The guild property. */
27
27
  this.guildId = guildId;
28
28
  }
29
+ /**
30
+ * @returns The current track.
31
+ */
29
32
  async getCurrent() {
30
33
  return this.current;
31
34
  }
35
+ /**
36
+ * @param track The track to set.
37
+ */
32
38
  async setCurrent(track) {
33
39
  this.current = track;
34
40
  }
41
+ /**
42
+ * @returns The previous tracks.
43
+ */
35
44
  async getPrevious() {
36
45
  return [...this.previous];
37
46
  }
@@ -47,12 +56,21 @@ class Queue extends Array {
47
56
  }
48
57
  }
49
58
  }
59
+ /**
60
+ * @param tracks The tracks to set.
61
+ */
50
62
  async setPrevious(tracks) {
51
63
  this.previous = [...tracks];
52
64
  }
65
+ /**
66
+ * @returns The newest track.
67
+ */
53
68
  async popPrevious() {
54
69
  return this.previous.shift() || null; // get newest track
55
70
  }
71
+ /**
72
+ * Clears the previous tracks.
73
+ */
56
74
  async clearPrevious() {
57
75
  this.previous = [];
58
76
  }
@@ -86,16 +104,18 @@ class Queue extends Array {
86
104
  * @param [offset=null] The position to add the track(s) at. If not provided, the track(s) will be added at the end of the queue.
87
105
  */
88
106
  async add(track, offset) {
107
+ const isArray = Array.isArray(track);
108
+ const tracks = isArray ? [...track] : [track];
89
109
  // Get the track info as a string
90
- const trackInfo = Array.isArray(track) ? track.map((t) => JSON.stringify(t, null, 2)).join(", ") : JSON.stringify(track, null, 2);
110
+ const trackInfo = isArray ? tracks.map((t) => JSON.stringify(t, null, 2)).join(", ") : JSON.stringify(track, null, 2);
91
111
  // Emit a debug message
92
- this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[QUEUE] Added ${Array.isArray(track) ? track.length : 1} track(s) to queue: ${trackInfo}`);
112
+ this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[QUEUE] Added ${tracks.length} track(s) to queue: ${trackInfo}`);
93
113
  const oldPlayer = this.manager.players.get(this.guildId) ? { ...this.manager.players.get(this.guildId) } : null;
94
114
  // If the queue is empty, set the track as the current track
95
115
  if (!this.current) {
96
- if (Array.isArray(track)) {
97
- this.current = track.shift() || null;
98
- this.push(...track);
116
+ if (isArray) {
117
+ this.current = tracks.shift() || null;
118
+ this.push(...tracks);
99
119
  }
100
120
  else {
101
121
  this.current = track;
@@ -113,8 +133,8 @@ class Queue extends Array {
113
133
  throw new RangeError(`Offset must be between 0 and ${this.length}.`);
114
134
  }
115
135
  // Add the track(s) at the offset position
116
- if (Array.isArray(track)) {
117
- this.splice(offset, 0, ...track);
136
+ if (isArray) {
137
+ this.splice(offset, 0, ...tracks);
118
138
  }
119
139
  else {
120
140
  this.splice(offset, 0, track);
@@ -122,8 +142,8 @@ class Queue extends Array {
122
142
  }
123
143
  else {
124
144
  // If no offset is provided, add the track(s) at the end of the queue
125
- if (Array.isArray(track)) {
126
- this.push(...track);
145
+ if (isArray) {
146
+ this.push(...tracks);
127
147
  }
128
148
  else {
129
149
  this.push(track);
@@ -131,7 +151,7 @@ class Queue extends Array {
131
151
  }
132
152
  }
133
153
  if (this.manager.players.has(this.guildId) && this.manager.players.get(this.guildId).isAutoplay) {
134
- if (!Array.isArray(track)) {
154
+ if (!isArray) {
135
155
  const botUser = this.manager.players.get(this.guildId).get("Internal_BotUser");
136
156
  if (botUser && botUser.id === track.requester.id) {
137
157
  this.manager.emit(Enums_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this.manager.players.get(this.guildId), {
@@ -139,7 +159,7 @@ class Queue extends Array {
139
159
  details: {
140
160
  type: "queue",
141
161
  action: "autoPlayAdd",
142
- tracks: Array.isArray(track) ? track : [track],
162
+ tracks: [track],
143
163
  },
144
164
  });
145
165
  return;
@@ -152,7 +172,7 @@ class Queue extends Array {
152
172
  details: {
153
173
  type: "queue",
154
174
  action: "add",
155
- tracks: Array.isArray(track) ? track : [track],
175
+ tracks: isArray ? tracks : [track],
156
176
  },
157
177
  });
158
178
  }
@@ -329,9 +349,16 @@ class Queue extends Array {
329
349
  // Emit a debug message indicating the queue has been shuffled for a specific guild ID.
330
350
  this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[QUEUE] roundRobinShuffled the queue for: ${this.guildId}`);
331
351
  }
352
+ /**
353
+ * Removes the first element from the queue.
354
+ */
332
355
  async dequeue() {
333
356
  return super.shift();
334
357
  }
358
+ /**
359
+ * Adds the specified track or tracks to the front of the queue.
360
+ * @param track The track or tracks to add.
361
+ */
335
362
  async enqueueFront(track) {
336
363
  if (Array.isArray(track)) {
337
364
  this.unshift(...track);
@@ -340,29 +367,57 @@ class Queue extends Array {
340
367
  this.unshift(track);
341
368
  }
342
369
  }
370
+ /**
371
+ * @returns A shallow copy of the queue.
372
+ */
343
373
  async getTracks() {
344
374
  return [...this]; // clone to avoid direct mutation
345
375
  }
376
+ /**
377
+ * @returns A shallow copy of the queue.
378
+ */
346
379
  async getSlice(start, end) {
347
380
  return this.slice(start, end); // Native sync method, still wrapped in a Promise
348
381
  }
382
+ /**
383
+ * Modifies the queue at the specified index.
384
+ * @param start The index at which to start modifying the queue.
385
+ * @param deleteCount The number of elements to remove from the queue.
386
+ * @param items The elements to add to the queue.
387
+ * @returns The modified queue.
388
+ */
349
389
  async modifyAt(start, deleteCount = 0, ...items) {
350
390
  return super.splice(start, deleteCount, ...items);
351
391
  }
392
+ /**
393
+ * @returns A new array with the results of calling a provided function on every element in the queue.
394
+ */
352
395
  async mapAsync(callback) {
353
396
  return this.map(callback);
354
397
  }
398
+ /**
399
+ * @returns A new array with all elements that pass the test implemented by the provided function.
400
+ */
355
401
  async filterAsync(callback) {
356
402
  return this.filter(callback);
357
403
  }
404
+ /**
405
+ * @returns The first element in the queue that satisfies the provided testing function.
406
+ */
358
407
  async findAsync(callback) {
359
408
  return this.find(callback);
360
409
  }
410
+ /**
411
+ * @returns Whether at least one element in the queue satisfies the provided testing function.
412
+ */
361
413
  async someAsync(callback) {
362
414
  return this.some(callback);
363
415
  }
416
+ /**
417
+ * @returns Whether all elements in the queue satisfy the provided testing function.
418
+ */
364
419
  async everyAsync(callback) {
365
420
  return this.every(callback);
366
421
  }
367
422
  }
368
- exports.Queue = Queue;
423
+ exports.MemoryQueue = MemoryQueue;