revbot.js 0.1.4 → 0.1.5

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
@@ -80,20 +80,48 @@ var __yieldStar = (value) => {
80
80
  };
81
81
 
82
82
  // src/managers/baseManager.ts
83
- var BaseManager = class {
84
- constructor(client3) {
83
+ var _BaseManager = class _BaseManager {
84
+ constructor(client3, maxSize = _BaseManager.defaultMaxSize) {
85
85
  this.client = client3;
86
+ /** Insertion ordered cache of items this manager holds. */
86
87
  this.cache = /* @__PURE__ */ new Map();
88
+ this.maxSize = maxSize;
87
89
  }
90
+ /**
91
+ * Adds a raw object to the cache, constructing the holdable class.
92
+ * Automatically evicts oldest entries if the max size is exceeded.
93
+ */
88
94
  _add(raw) {
89
95
  if (!this.holds) throw new Error("Holds is not defined");
90
96
  const obj = new this.holds(this.client, raw);
91
97
  this.cache.set(obj.id, obj);
98
+ this.enforceMaxSize();
92
99
  return obj;
93
100
  }
101
+ /** Remove an entry by id. */
94
102
  _remove(id) {
95
103
  this.cache.delete(id);
96
104
  }
105
+ /** Adjust the maximum size for this manager at runtime. */
106
+ setMaxSize(size) {
107
+ if (!Number.isFinite(size) || size < 0)
108
+ throw new RangeError("maxSize must be a non-negative finite number");
109
+ this.maxSize = size;
110
+ this.enforceMaxSize();
111
+ }
112
+ /** Force eviction until cache size is within the limit. */
113
+ enforceMaxSize() {
114
+ if (this.cache.size === -1) return;
115
+ if (this.maxSize === 0) {
116
+ this.cache.clear();
117
+ return;
118
+ }
119
+ while (this.cache.size > this.maxSize) {
120
+ const oldestKey = this.cache.keys().next().value;
121
+ if (oldestKey === void 0) break;
122
+ this.cache.delete(oldestKey);
123
+ }
124
+ }
97
125
  resolve(resolvable) {
98
126
  var _a;
99
127
  const id = this.resolveId(resolvable);
@@ -113,6 +141,9 @@ var BaseManager = class {
113
141
  return this.cache;
114
142
  }
115
143
  };
144
+ /** Shared default max size for all managers (can be changed globally). */
145
+ _BaseManager.defaultMaxSize = 1e3;
146
+ var BaseManager = _BaseManager;
116
147
 
117
148
  // src/utils/bitField.ts
118
149
  var DEFAULT_BIT = 0;
@@ -407,6 +438,9 @@ var DEFAULT_CLIENT_OPTIONS = {
407
438
  timeout: 15e3,
408
439
  retries: 3
409
440
  },
441
+ MessageCache: {
442
+ maxSize: 1e3
443
+ },
410
444
  ws: {
411
445
  heartbeatInterval: 3e4,
412
446
  reconnect: true
@@ -2655,8 +2689,8 @@ import { Readable as Readable2 } from "stream";
2655
2689
  import FormData2 from "form-data";
2656
2690
  import axios2 from "axios";
2657
2691
  var MessageManager = class extends BaseManager {
2658
- constructor(channel) {
2659
- super(channel.client);
2692
+ constructor(channel, maxSize = 2) {
2693
+ super(channel.client, maxSize);
2660
2694
  this.channel = channel;
2661
2695
  this.holds = MessageStruct;
2662
2696
  }
@@ -3165,7 +3199,7 @@ import { EventEmitter } from "node:events";
3165
3199
  import { AxiosError } from "axios";
3166
3200
 
3167
3201
  // package.json
3168
- var version = "0.1.4";
3202
+ var version = "0.1.5";
3169
3203
 
3170
3204
  // src/rest/restUtils/rateLimitQueue.ts
3171
3205
  import axios3 from "axios";