revbot.js 0.1.4 → 0.1.6
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.d.mts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +39 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -278,6 +278,10 @@ interface clientOptions {
|
|
|
278
278
|
/** The number of retries for failed REST requests. */
|
|
279
279
|
retries: number;
|
|
280
280
|
};
|
|
281
|
+
MessageCache?: {
|
|
282
|
+
/** The maximum size of the cache. */
|
|
283
|
+
maxSize?: number;
|
|
284
|
+
};
|
|
281
285
|
/** Configuration for WebSocket connections. */
|
|
282
286
|
ws?: {
|
|
283
287
|
/** The interval for sending heartbeats in milliseconds. */
|
|
@@ -2314,11 +2318,25 @@ declare abstract class BaseManager<Holds extends {
|
|
|
2314
2318
|
id: string;
|
|
2315
2319
|
}, R = unknown> {
|
|
2316
2320
|
protected readonly client: client;
|
|
2321
|
+
/** Shared default max size for all managers (can be changed globally). */
|
|
2322
|
+
static defaultMaxSize: number;
|
|
2323
|
+
/** Insertion ordered cache of items this manager holds. */
|
|
2317
2324
|
readonly cache: Map<string, Holds>;
|
|
2325
|
+
/** Instance level max size (can be changed per manager instance). */
|
|
2326
|
+
protected maxSize: number;
|
|
2318
2327
|
Holds: any;
|
|
2319
|
-
constructor(client: client);
|
|
2328
|
+
constructor(client: client, maxSize?: number);
|
|
2329
|
+
/**
|
|
2330
|
+
* Adds a raw object to the cache, constructing the holdable class.
|
|
2331
|
+
* Automatically evicts oldest entries if the max size is exceeded.
|
|
2332
|
+
*/
|
|
2320
2333
|
_add(raw: R): Holds;
|
|
2334
|
+
/** Remove an entry by id. */
|
|
2321
2335
|
_remove(id: string): void;
|
|
2336
|
+
/** Adjust the maximum size for this manager at runtime. */
|
|
2337
|
+
setMaxSize(size: number): void;
|
|
2338
|
+
/** Force eviction until cache size is within the limit. */
|
|
2339
|
+
protected enforceMaxSize(): void;
|
|
2322
2340
|
abstract readonly holds: (new (...args: any[]) => Holds) | null;
|
|
2323
2341
|
resolve(resolvable: Holds): Holds | null;
|
|
2324
2342
|
resolve(resolvable: string | R): Holds | null;
|
|
@@ -2423,7 +2441,7 @@ interface MessageQueryOptions {
|
|
|
2423
2441
|
declare class MessageManager extends BaseManager<MessageStruct, Message> {
|
|
2424
2442
|
protected readonly channel: Channel;
|
|
2425
2443
|
holds: typeof MessageStruct;
|
|
2426
|
-
constructor(channel: Channel);
|
|
2444
|
+
constructor(channel: Channel, maxSize?: number);
|
|
2427
2445
|
/**
|
|
2428
2446
|
*
|
|
2429
2447
|
* @param content The content to send. Can be a string or an object with the following properties:
|
package/dist/index.d.ts
CHANGED
|
@@ -278,6 +278,10 @@ interface clientOptions {
|
|
|
278
278
|
/** The number of retries for failed REST requests. */
|
|
279
279
|
retries: number;
|
|
280
280
|
};
|
|
281
|
+
MessageCache?: {
|
|
282
|
+
/** The maximum size of the cache. */
|
|
283
|
+
maxSize?: number;
|
|
284
|
+
};
|
|
281
285
|
/** Configuration for WebSocket connections. */
|
|
282
286
|
ws?: {
|
|
283
287
|
/** The interval for sending heartbeats in milliseconds. */
|
|
@@ -2314,11 +2318,25 @@ declare abstract class BaseManager<Holds extends {
|
|
|
2314
2318
|
id: string;
|
|
2315
2319
|
}, R = unknown> {
|
|
2316
2320
|
protected readonly client: client;
|
|
2321
|
+
/** Shared default max size for all managers (can be changed globally). */
|
|
2322
|
+
static defaultMaxSize: number;
|
|
2323
|
+
/** Insertion ordered cache of items this manager holds. */
|
|
2317
2324
|
readonly cache: Map<string, Holds>;
|
|
2325
|
+
/** Instance level max size (can be changed per manager instance). */
|
|
2326
|
+
protected maxSize: number;
|
|
2318
2327
|
Holds: any;
|
|
2319
|
-
constructor(client: client);
|
|
2328
|
+
constructor(client: client, maxSize?: number);
|
|
2329
|
+
/**
|
|
2330
|
+
* Adds a raw object to the cache, constructing the holdable class.
|
|
2331
|
+
* Automatically evicts oldest entries if the max size is exceeded.
|
|
2332
|
+
*/
|
|
2320
2333
|
_add(raw: R): Holds;
|
|
2334
|
+
/** Remove an entry by id. */
|
|
2321
2335
|
_remove(id: string): void;
|
|
2336
|
+
/** Adjust the maximum size for this manager at runtime. */
|
|
2337
|
+
setMaxSize(size: number): void;
|
|
2338
|
+
/** Force eviction until cache size is within the limit. */
|
|
2339
|
+
protected enforceMaxSize(): void;
|
|
2322
2340
|
abstract readonly holds: (new (...args: any[]) => Holds) | null;
|
|
2323
2341
|
resolve(resolvable: Holds): Holds | null;
|
|
2324
2342
|
resolve(resolvable: string | R): Holds | null;
|
|
@@ -2423,7 +2441,7 @@ interface MessageQueryOptions {
|
|
|
2423
2441
|
declare class MessageManager extends BaseManager<MessageStruct, Message> {
|
|
2424
2442
|
protected readonly channel: Channel;
|
|
2425
2443
|
holds: typeof MessageStruct;
|
|
2426
|
-
constructor(channel: Channel);
|
|
2444
|
+
constructor(channel: Channel, maxSize?: number);
|
|
2427
2445
|
/**
|
|
2428
2446
|
*
|
|
2429
2447
|
* @param content The content to send. Can be a string or an object with the following properties:
|
package/dist/index.js
CHANGED
|
@@ -158,20 +158,48 @@ __export(index_exports, {
|
|
|
158
158
|
module.exports = __toCommonJS(index_exports);
|
|
159
159
|
|
|
160
160
|
// src/managers/baseManager.ts
|
|
161
|
-
var
|
|
162
|
-
constructor(client3) {
|
|
161
|
+
var _BaseManager = class _BaseManager {
|
|
162
|
+
constructor(client3, maxSize = _BaseManager.defaultMaxSize) {
|
|
163
163
|
this.client = client3;
|
|
164
|
+
/** Insertion ordered cache of items this manager holds. */
|
|
164
165
|
this.cache = /* @__PURE__ */ new Map();
|
|
166
|
+
this.maxSize = maxSize;
|
|
165
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Adds a raw object to the cache, constructing the holdable class.
|
|
170
|
+
* Automatically evicts oldest entries if the max size is exceeded.
|
|
171
|
+
*/
|
|
166
172
|
_add(raw) {
|
|
167
173
|
if (!this.holds) throw new Error("Holds is not defined");
|
|
168
174
|
const obj = new this.holds(this.client, raw);
|
|
169
175
|
this.cache.set(obj.id, obj);
|
|
176
|
+
this.enforceMaxSize();
|
|
170
177
|
return obj;
|
|
171
178
|
}
|
|
179
|
+
/** Remove an entry by id. */
|
|
172
180
|
_remove(id) {
|
|
173
181
|
this.cache.delete(id);
|
|
174
182
|
}
|
|
183
|
+
/** Adjust the maximum size for this manager at runtime. */
|
|
184
|
+
setMaxSize(size) {
|
|
185
|
+
if (!Number.isFinite(size) || size < -1)
|
|
186
|
+
throw new RangeError("maxSize must be a non-negative finite number");
|
|
187
|
+
this.maxSize = size;
|
|
188
|
+
this.enforceMaxSize();
|
|
189
|
+
}
|
|
190
|
+
/** Force eviction until cache size is within the limit. */
|
|
191
|
+
enforceMaxSize() {
|
|
192
|
+
if (this.maxSize === -1) return;
|
|
193
|
+
if (this.maxSize === 0) {
|
|
194
|
+
this.cache.clear();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
while (this.cache.size > this.maxSize) {
|
|
198
|
+
const oldestKey = this.cache.keys().next().value;
|
|
199
|
+
if (oldestKey === void 0) break;
|
|
200
|
+
this.cache.delete(oldestKey);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
175
203
|
resolve(resolvable) {
|
|
176
204
|
var _a;
|
|
177
205
|
const id = this.resolveId(resolvable);
|
|
@@ -191,6 +219,9 @@ var BaseManager = class {
|
|
|
191
219
|
return this.cache;
|
|
192
220
|
}
|
|
193
221
|
};
|
|
222
|
+
/** Shared default max size for all managers (can be changed globally). */
|
|
223
|
+
_BaseManager.defaultMaxSize = -1;
|
|
224
|
+
var BaseManager = _BaseManager;
|
|
194
225
|
|
|
195
226
|
// src/utils/bitField.ts
|
|
196
227
|
var DEFAULT_BIT = 0;
|
|
@@ -485,6 +516,9 @@ var DEFAULT_CLIENT_OPTIONS = {
|
|
|
485
516
|
timeout: 15e3,
|
|
486
517
|
retries: 3
|
|
487
518
|
},
|
|
519
|
+
MessageCache: {
|
|
520
|
+
maxSize: 1e3
|
|
521
|
+
},
|
|
488
522
|
ws: {
|
|
489
523
|
heartbeatInterval: 3e4,
|
|
490
524
|
reconnect: true
|
|
@@ -2733,8 +2767,8 @@ var import_stream2 = require("stream");
|
|
|
2733
2767
|
var import_form_data2 = __toESM(require("form-data"));
|
|
2734
2768
|
var import_axios2 = __toESM(require("axios"));
|
|
2735
2769
|
var MessageManager = class extends BaseManager {
|
|
2736
|
-
constructor(channel) {
|
|
2737
|
-
super(channel.client);
|
|
2770
|
+
constructor(channel, maxSize = 1e3) {
|
|
2771
|
+
super(channel.client, maxSize);
|
|
2738
2772
|
this.channel = channel;
|
|
2739
2773
|
this.holds = MessageStruct;
|
|
2740
2774
|
}
|
|
@@ -3243,7 +3277,7 @@ var import_node_events = require("events");
|
|
|
3243
3277
|
var import_axios4 = require("axios");
|
|
3244
3278
|
|
|
3245
3279
|
// package.json
|
|
3246
|
-
var version = "0.1.
|
|
3280
|
+
var version = "0.1.6";
|
|
3247
3281
|
|
|
3248
3282
|
// src/rest/restUtils/rateLimitQueue.ts
|
|
3249
3283
|
var import_axios3 = __toESM(require("axios"));
|