@bemoje/map 1.0.1 → 1.2.1

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 (66) hide show
  1. package/lib/ExtMap.cjs +354 -0
  2. package/lib/ExtMap.d.cts +110 -0
  3. package/lib/ExtMap.d.ts +110 -0
  4. package/lib/ExtMap.js +352 -0
  5. package/lib/TimeoutWeakMap.cjs +122 -0
  6. package/lib/TimeoutWeakMap.d.cts +75 -0
  7. package/lib/TimeoutWeakMap.d.ts +75 -0
  8. package/lib/TimeoutWeakMap.js +120 -0
  9. package/lib/countUniques.cjs +363 -0
  10. package/lib/countUniques.d.cts +9 -0
  11. package/lib/countUniques.d.ts +9 -0
  12. package/lib/countUniques.js +361 -0
  13. package/lib/entriesArray.cjs +12 -0
  14. package/lib/entriesArray.d.cts +19 -0
  15. package/lib/entriesArray.d.ts +19 -0
  16. package/lib/entriesArray.js +10 -0
  17. package/lib/index.cjs +505 -0
  18. package/lib/index.d.cts +17 -0
  19. package/lib/index.d.ts +17 -0
  20. package/{index.mjs → lib/index.js} +104 -90
  21. package/lib/isGenericMap.cjs +18 -0
  22. package/lib/isGenericMap.d.cts +6 -0
  23. package/lib/isGenericMap.d.ts +6 -0
  24. package/lib/isGenericMap.js +16 -0
  25. package/lib/keysArray.cjs +12 -0
  26. package/lib/keysArray.d.cts +19 -0
  27. package/lib/keysArray.d.ts +19 -0
  28. package/lib/keysArray.js +10 -0
  29. package/lib/mapGetOrDefault.cjs +18 -0
  30. package/lib/mapGetOrDefault.d.cts +8 -0
  31. package/lib/mapGetOrDefault.d.ts +8 -0
  32. package/lib/mapGetOrDefault.js +16 -0
  33. package/lib/mapLoad.cjs +15 -0
  34. package/lib/mapLoad.d.cts +11 -0
  35. package/lib/mapLoad.d.ts +11 -0
  36. package/lib/mapLoad.js +13 -0
  37. package/lib/mapReverse.cjs +24 -0
  38. package/lib/mapReverse.d.cts +15 -0
  39. package/lib/mapReverse.d.ts +15 -0
  40. package/lib/mapReverse.js +22 -0
  41. package/lib/mapUpdate.cjs +14 -0
  42. package/lib/mapUpdate.d.cts +13 -0
  43. package/lib/mapUpdate.d.ts +13 -0
  44. package/lib/mapUpdate.js +12 -0
  45. package/lib/sort.cjs +17 -0
  46. package/lib/sort.d.cts +25 -0
  47. package/lib/sort.d.ts +25 -0
  48. package/lib/sort.js +15 -0
  49. package/lib/sortByKeys.cjs +19 -0
  50. package/lib/sortByKeys.d.cts +24 -0
  51. package/lib/sortByKeys.d.ts +24 -0
  52. package/lib/sortByKeys.js +17 -0
  53. package/lib/sortByValues.cjs +19 -0
  54. package/lib/sortByValues.d.cts +25 -0
  55. package/lib/sortByValues.d.ts +25 -0
  56. package/lib/sortByValues.js +17 -0
  57. package/lib/toMap.cjs +12 -0
  58. package/lib/toMap.d.cts +20 -0
  59. package/lib/toMap.d.ts +20 -0
  60. package/lib/toMap.js +10 -0
  61. package/lib/valuesArray.cjs +12 -0
  62. package/lib/valuesArray.d.cts +19 -0
  63. package/lib/valuesArray.d.ts +19 -0
  64. package/lib/valuesArray.js +10 -0
  65. package/package.json +248 -18
  66. package/index.d.ts +0 -364
package/lib/ExtMap.js ADDED
@@ -0,0 +1,352 @@
1
+ import { isIterable, map, filter } from 'iter-tools';
2
+ import { inspect } from 'util';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+
7
+ // ../object/src/defineMethod.ts
8
+ function defineMethod(obj, key, value, des = {}) {
9
+ return Object.defineProperty(obj, key, {
10
+ value,
11
+ configurable: true,
12
+ writable: true,
13
+ enumerable: false,
14
+ ...des
15
+ });
16
+ }
17
+ __name(defineMethod, "defineMethod");
18
+
19
+ // ../object/src/entriesOf.ts
20
+ function entriesOf(obj) {
21
+ return Object.entries(obj);
22
+ }
23
+ __name(entriesOf, "entriesOf");
24
+
25
+ // ../composition/src/View.ts
26
+ var TARGET_SYMBOL = /* @__PURE__ */ Symbol("target");
27
+ var View = class {
28
+ static {
29
+ __name(this, "View");
30
+ }
31
+ [TARGET_SYMBOL];
32
+ constructor(target) {
33
+ this[TARGET_SYMBOL] = target;
34
+ }
35
+ get [Symbol.toStringTag]() {
36
+ return this.constructor.name;
37
+ }
38
+ get target() {
39
+ return this[TARGET_SYMBOL];
40
+ }
41
+ };
42
+
43
+ // ../composition/src/inheritProxifiedPrototypeProperty.ts
44
+ function inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, key) {
45
+ const des = Reflect.getOwnPropertyDescriptor(TargetClass.prototype, key);
46
+ if (!des) {
47
+ return;
48
+ }
49
+ if (des.value && typeof des.value === "function") {
50
+ return Object.defineProperty(ViewerClass.prototype, key, {
51
+ value(...args) {
52
+ return this.target[key](...args);
53
+ },
54
+ writable: true,
55
+ configurable: true,
56
+ enumerable: false
57
+ });
58
+ } else if (des && !des.get && !des.set) {
59
+ return Object.defineProperty(ViewerClass.prototype, key, {
60
+ get() {
61
+ return this.target[key];
62
+ },
63
+ set: des.writable ? /* @__PURE__ */ __name(function set(value) {
64
+ this.target[key] = value;
65
+ }, "set") : void 0,
66
+ configurable: true,
67
+ enumerable: false
68
+ });
69
+ } else {
70
+ Object.defineProperty(ViewerClass.prototype, key, {
71
+ get: des.get ? function() {
72
+ return this.target[key];
73
+ } : void 0,
74
+ set: des.set ? function(value) {
75
+ this.target[key] = value;
76
+ } : void 0,
77
+ configurable: true,
78
+ enumerable: false
79
+ });
80
+ }
81
+ }
82
+ __name(inheritProxifiedPrototypeProperty, "inheritProxifiedPrototypeProperty");
83
+
84
+ // ../composition/src/inheritProxifiedPrototype.ts
85
+ function inheritProxifiedPrototype(ViewerClass, TargetClass, omitKeys) {
86
+ Reflect.ownKeys(TargetClass.prototype).filter((k) => {
87
+ return k !== "constructor" && k !== Symbol.toStringTag;
88
+ }).filter((k) => {
89
+ return omitKeys ? !omitKeys.includes(k) : true;
90
+ }).forEach((k) => {
91
+ return inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, k);
92
+ });
93
+ return ViewerClass;
94
+ }
95
+ __name(inheritProxifiedPrototype, "inheritProxifiedPrototype");
96
+
97
+ // src/entriesArray.ts
98
+ function entriesArray(ins) {
99
+ return Array.from(ins);
100
+ }
101
+ __name(entriesArray, "entriesArray");
102
+ function filterIterableValues(mapLike, predicate) {
103
+ return filter(([k, v]) => {
104
+ return predicate(v, k);
105
+ }, mapLike);
106
+ }
107
+ __name(filterIterableValues, "filterIterableValues");
108
+
109
+ // src/keysArray.ts
110
+ function keysArray(ins) {
111
+ return Array.from(ins.keys());
112
+ }
113
+ __name(keysArray, "keysArray");
114
+
115
+ // src/mapGetOrDefault.ts
116
+ function mapGetOrDefault(map3, key, factory) {
117
+ let value = map3.get(key);
118
+ if (value !== void 0 || map3.has(key)) {
119
+ return value;
120
+ }
121
+ value = factory(key, map3);
122
+ map3.set(key, value);
123
+ return value;
124
+ }
125
+ __name(mapGetOrDefault, "mapGetOrDefault");
126
+ function mapIterableKeys(mapLike, mapper) {
127
+ return map(([k, v]) => {
128
+ return [
129
+ mapper(k, v),
130
+ v
131
+ ];
132
+ }, mapLike);
133
+ }
134
+ __name(mapIterableKeys, "mapIterableKeys");
135
+ function mapIterableValues(mapLike, mapper) {
136
+ return map(([k, v]) => {
137
+ return [
138
+ k,
139
+ mapper(v, k)
140
+ ];
141
+ }, mapLike);
142
+ }
143
+ __name(mapIterableValues, "mapIterableValues");
144
+
145
+ // src/mapLoad.ts
146
+ function mapLoad(ins, entries) {
147
+ for (const [key, value] of entries) {
148
+ ins.set(key, value);
149
+ }
150
+ return ins;
151
+ }
152
+ __name(mapLoad, "mapLoad");
153
+
154
+ // src/mapReverse.ts
155
+ function mapReverse(ins) {
156
+ const entries = Array.from(ins).reverse();
157
+ ins.clear();
158
+ mapLoad(ins, entries);
159
+ return ins;
160
+ }
161
+ __name(mapReverse, "mapReverse");
162
+
163
+ // src/mapUpdate.ts
164
+ function mapUpdate(ins, key, update) {
165
+ const newValue = update(ins.get(key), key, ins);
166
+ ins.set(key, newValue);
167
+ return ins;
168
+ }
169
+ __name(mapUpdate, "mapUpdate");
170
+
171
+ // ../iter/src/reduceIterableValues.ts
172
+ function reduceIterableValues(mapLike, reducer, initial) {
173
+ let accumulator = initial;
174
+ for (const [k, v] of mapLike) {
175
+ accumulator = reducer(accumulator, v, k);
176
+ }
177
+ return accumulator;
178
+ }
179
+ __name(reduceIterableValues, "reduceIterableValues");
180
+
181
+ // src/sort.ts
182
+ function sort(ins, compare) {
183
+ const entries = Array.from(ins).sort(compare);
184
+ ins.clear();
185
+ for (const [k, v] of entries) {
186
+ ins.set(k, v);
187
+ }
188
+ return ins;
189
+ }
190
+ __name(sort, "sort");
191
+
192
+ // src/sortByKeys.ts
193
+ function sortByKeys(ins, compare) {
194
+ const entries = Array.from(ins).sort((a, b) => {
195
+ return compare(a[0], b[0]);
196
+ });
197
+ ins.clear();
198
+ for (const [k, v] of entries) {
199
+ ins.set(k, v);
200
+ }
201
+ return ins;
202
+ }
203
+ __name(sortByKeys, "sortByKeys");
204
+
205
+ // src/sortByValues.ts
206
+ function sortByValues(ins, compare) {
207
+ const entries = Array.from(ins).sort((a, b) => {
208
+ return compare(a[1], b[1]);
209
+ });
210
+ ins.clear();
211
+ for (const [k, v] of entries) {
212
+ ins.set(k, v);
213
+ }
214
+ return ins;
215
+ }
216
+ __name(sortByValues, "sortByValues");
217
+
218
+ // ../fn/src/setNameAndLength.ts
219
+ function setNameAndLength(source, target, lengthDelta = 0) {
220
+ return Object.defineProperties(target, {
221
+ name: {
222
+ configurable: true,
223
+ value: source.name
224
+ },
225
+ length: {
226
+ configurable: true,
227
+ value: source.length + lengthDelta
228
+ }
229
+ });
230
+ }
231
+ __name(setNameAndLength, "setNameAndLength");
232
+
233
+ // ../fn/src/thisify.ts
234
+ function thisify(fn) {
235
+ return setNameAndLength(fn, /* @__PURE__ */ __name(function f(...args) {
236
+ return fn(this, ...args);
237
+ }, "f"), -1);
238
+ }
239
+ __name(thisify, "thisify");
240
+
241
+ // src/toMap.ts
242
+ function toMap(ins) {
243
+ return new Map(ins);
244
+ }
245
+ __name(toMap, "toMap");
246
+
247
+ // ../iter/src/toObjectIterable.ts
248
+ function toObjectIterable(mapLike) {
249
+ const object = {};
250
+ for (const [key, value] of mapLike) {
251
+ if (typeof key !== "string" && typeof key !== "number" && typeof key !== "symbol") {
252
+ object[String(key)] = value;
253
+ } else {
254
+ object[key] = value;
255
+ }
256
+ }
257
+ return object;
258
+ }
259
+ __name(toObjectIterable, "toObjectIterable");
260
+
261
+ // ../fn/src/transformReturnValue.ts
262
+ function transformReturnValue(fn, transform) {
263
+ return setNameAndLength(fn, function(...args) {
264
+ const result = fn.apply(this, args);
265
+ return transform(result);
266
+ });
267
+ }
268
+ __name(transformReturnValue, "transformReturnValue");
269
+
270
+ // src/valuesArray.ts
271
+ function valuesArray(ins) {
272
+ return Array.from(ins.values());
273
+ }
274
+ __name(valuesArray, "valuesArray");
275
+
276
+ // src/ExtMap.ts
277
+ var ExtMap = class _ExtMap extends View {
278
+ static {
279
+ __name(this, "ExtMap");
280
+ }
281
+ constructor(arg) {
282
+ super(new Map(isIterable(arg) ? arg : arg ? entriesOf(arg) : void 0));
283
+ }
284
+ /**
285
+ * Creates a new ExtMap instance from a regular object.
286
+ *
287
+ * @param obj - An object whose key-value pairs will be used to initialize the map
288
+ * @returns A new ExtMap instance containing the entries from the object
289
+ */
290
+ static fromObject(obj) {
291
+ return new _ExtMap(Object.entries(obj));
292
+ }
293
+ /**
294
+ * Creates a new ExtMap instance from an iterable of key-value pairs.
295
+ *
296
+ * @param entries - An iterable of key-value pairs to initialize the map
297
+ * @returns A new ExtMap instance containing the provided entries
298
+ */
299
+ static fromIterable(entries) {
300
+ return new _ExtMap(entries);
301
+ }
302
+ /**
303
+ * Creates a shallow copy of the map.
304
+ *
305
+ * @returns A new ExtMap instance with the same entries
306
+ */
307
+ clone() {
308
+ return new _ExtMap(this);
309
+ }
310
+ /**
311
+ * Converts the map to a JSON-serializable format.
312
+ *
313
+ * @returns Array of key-value pairs suitable for JSON serialization
314
+ */
315
+ toJSON() {
316
+ return [
317
+ ...this.entries()
318
+ ];
319
+ }
320
+ /**
321
+ * Custom inspection method for better debugging output.
322
+ *
323
+ * @param _depth - The depth of inspection
324
+ * @param _options - Options for inspection
325
+ * @returns A string representation of the map
326
+ */
327
+ [inspect.custom](_depth, _options) {
328
+ return inspect(this.target, {
329
+ breakLength: 50
330
+ });
331
+ }
332
+ };
333
+ inheritProxifiedPrototype(ExtMap, Map, []);
334
+ defineMethod(ExtMap.prototype, "load", thisify(mapLoad));
335
+ defineMethod(ExtMap.prototype, "sort", thisify(sort));
336
+ defineMethod(ExtMap.prototype, "sortByKeys", thisify(sortByKeys));
337
+ defineMethod(ExtMap.prototype, "sortByValues", thisify(sortByValues));
338
+ defineMethod(ExtMap.prototype, "reverse", thisify(mapReverse));
339
+ defineMethod(ExtMap.prototype, "update", thisify(mapUpdate));
340
+ defineMethod(ExtMap.prototype, "getOrDefault", thisify(mapGetOrDefault));
341
+ defineMethod(ExtMap.prototype, "keysArray", thisify(keysArray));
342
+ defineMethod(ExtMap.prototype, "valuesArray", thisify(valuesArray));
343
+ defineMethod(ExtMap.prototype, "entriesArray", thisify(entriesArray));
344
+ defineMethod(ExtMap.prototype, "toObject", thisify(toObjectIterable));
345
+ defineMethod(ExtMap.prototype, "toMap", thisify(toMap));
346
+ defineMethod(ExtMap.prototype, "reduce", thisify(reduceIterableValues));
347
+ defineMethod(ExtMap.prototype, "map", thisify(transformReturnValue(mapIterableValues, ExtMap.fromIterable)));
348
+ defineMethod(ExtMap.prototype, "mapKeys", thisify(transformReturnValue(mapIterableKeys, ExtMap.fromIterable)));
349
+ defineMethod(ExtMap.prototype, "mapValues", thisify(transformReturnValue(mapIterableValues, ExtMap.fromIterable)));
350
+ defineMethod(ExtMap.prototype, "filter", thisify(transformReturnValue(filterIterableValues, ExtMap.fromIterable)));
351
+
352
+ export { ExtMap };
@@ -0,0 +1,122 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+
6
+ // src/TimeoutWeakMap.ts
7
+ var TimeoutWeakMap = class {
8
+ static {
9
+ __name(this, "TimeoutWeakMap");
10
+ }
11
+ timeoutMs;
12
+ wmap = /* @__PURE__ */ new WeakMap();
13
+ /**
14
+ * @param timeoutMs Default timeout in milliseconds for entries
15
+ */
16
+ constructor(timeoutMs) {
17
+ this.timeoutMs = timeoutMs;
18
+ }
19
+ /**
20
+ * Retrieves the value for the given key and refreshes its timeout.
21
+ *
22
+ * @param key The key to retrieve
23
+ * @returns The value if found, undefined otherwise
24
+ */
25
+ get(key) {
26
+ const vt = this.wmap.get(key);
27
+ if (!vt) {
28
+ return void 0;
29
+ }
30
+ const [value, timeout] = vt;
31
+ timeout.refresh();
32
+ return value;
33
+ }
34
+ /**
35
+ * Sets a key-value pair with an optional custom timeout.
36
+ *
37
+ * @param key The key to set
38
+ * @param value The value to associate with the key
39
+ * @param timeoutMs Optional timeout override for this entry
40
+ * @returns This instance for chaining
41
+ */
42
+ set(key, value, timeoutMs) {
43
+ this.wmap.set(key, [
44
+ value,
45
+ setTimeout(() => {
46
+ this.delete(key);
47
+ }, timeoutMs ?? this.timeoutMs).unref()
48
+ ]);
49
+ return this;
50
+ }
51
+ /**
52
+ * Removes a key-value pair and clears its timeout.
53
+ *
54
+ * @param key The key to delete
55
+ * @returns True if the key existed and was deleted, false otherwise
56
+ */
57
+ delete(key) {
58
+ const vt = this.wmap.get(key);
59
+ if (!vt) {
60
+ return false;
61
+ }
62
+ const timeout = vt[1];
63
+ clearTimeout(timeout);
64
+ return this.wmap.delete(key);
65
+ }
66
+ /**
67
+ * Checks if a key exists in the map.
68
+ * Does not refresh the timeout.
69
+ *
70
+ * @param key The key to check
71
+ * @returns True if the key exists, false otherwise
72
+ */
73
+ has(key) {
74
+ return this.wmap.has(key);
75
+ }
76
+ /**
77
+ * Loads multiple key-value pairs into the map.
78
+ *
79
+ * @param entries Iterable of key-value pairs to load
80
+ * @param timeoutMs Optional timeout override for all entries
81
+ * @returns This instance for chaining
82
+ */
83
+ load(entries, timeoutMs) {
84
+ for (const [key, value] of entries) {
85
+ this.set(key, value, timeoutMs);
86
+ }
87
+ return this;
88
+ }
89
+ /**
90
+ * Updates an existing value or creates a new one using an update function.
91
+ *
92
+ * @param key The key to update
93
+ * @param update Function that receives the current value and returns the new value
94
+ * @returns This instance for chaining
95
+ */
96
+ update(key, update) {
97
+ return this.set(key, update(this.get(key), key, this));
98
+ }
99
+ /**
100
+ * Gets a value or creates it using a factory function if it doesn't exist.
101
+ * Refreshes timeout if the value exists.
102
+ *
103
+ * @param key The key to get or create
104
+ * @param factory Function to create the value if it doesn't exist
105
+ * @param timeoutMs Optional timeout override for new entries
106
+ * @returns The existing or newly created value
107
+ */
108
+ getOrDefault(key, factory, timeoutMs) {
109
+ const vt = this.wmap.get(key);
110
+ if (vt) {
111
+ const [value, timeout] = vt;
112
+ timeout.refresh();
113
+ return value;
114
+ } else {
115
+ const value = factory(key, this);
116
+ this.set(key, value, timeoutMs);
117
+ return value;
118
+ }
119
+ }
120
+ };
121
+
122
+ exports.TimeoutWeakMap = TimeoutWeakMap;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * A WeakMap with automatic timeout-based expiry for entries.
3
+ *
4
+ * Entries are automatically removed after a specified timeout period.
5
+ * Accessing an entry refreshes its timeout, extending its lifetime.
6
+ * This is useful for caching scenarios where you want automatic cleanup
7
+ * of unused entries while keeping frequently accessed ones alive.
8
+ */
9
+ declare class TimeoutWeakMap<K extends object, V> {
10
+ readonly timeoutMs: number;
11
+ protected readonly wmap: WeakMap<K, [V, NodeJS.Timeout]>;
12
+ /**
13
+ * @param timeoutMs Default timeout in milliseconds for entries
14
+ */
15
+ constructor(timeoutMs: number);
16
+ /**
17
+ * Retrieves the value for the given key and refreshes its timeout.
18
+ *
19
+ * @param key The key to retrieve
20
+ * @returns The value if found, undefined otherwise
21
+ */
22
+ get(key: K): V | undefined;
23
+ /**
24
+ * Sets a key-value pair with an optional custom timeout.
25
+ *
26
+ * @param key The key to set
27
+ * @param value The value to associate with the key
28
+ * @param timeoutMs Optional timeout override for this entry
29
+ * @returns This instance for chaining
30
+ */
31
+ set(key: K, value: V, timeoutMs?: number): this;
32
+ /**
33
+ * Removes a key-value pair and clears its timeout.
34
+ *
35
+ * @param key The key to delete
36
+ * @returns True if the key existed and was deleted, false otherwise
37
+ */
38
+ delete(key: K): boolean;
39
+ /**
40
+ * Checks if a key exists in the map.
41
+ * Does not refresh the timeout.
42
+ *
43
+ * @param key The key to check
44
+ * @returns True if the key exists, false otherwise
45
+ */
46
+ has(key: K): boolean;
47
+ /**
48
+ * Loads multiple key-value pairs into the map.
49
+ *
50
+ * @param entries Iterable of key-value pairs to load
51
+ * @param timeoutMs Optional timeout override for all entries
52
+ * @returns This instance for chaining
53
+ */
54
+ load(entries: Iterable<[K, V]>, timeoutMs?: number): this;
55
+ /**
56
+ * Updates an existing value or creates a new one using an update function.
57
+ *
58
+ * @param key The key to update
59
+ * @param update Function that receives the current value and returns the new value
60
+ * @returns This instance for chaining
61
+ */
62
+ update(key: K, update: (value: V | undefined, key: K, map: this) => V): this;
63
+ /**
64
+ * Gets a value or creates it using a factory function if it doesn't exist.
65
+ * Refreshes timeout if the value exists.
66
+ *
67
+ * @param key The key to get or create
68
+ * @param factory Function to create the value if it doesn't exist
69
+ * @param timeoutMs Optional timeout override for new entries
70
+ * @returns The existing or newly created value
71
+ */
72
+ getOrDefault(key: K, factory: (key: K, map: this) => V, timeoutMs?: number): V;
73
+ }
74
+
75
+ export { TimeoutWeakMap };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * A WeakMap with automatic timeout-based expiry for entries.
3
+ *
4
+ * Entries are automatically removed after a specified timeout period.
5
+ * Accessing an entry refreshes its timeout, extending its lifetime.
6
+ * This is useful for caching scenarios where you want automatic cleanup
7
+ * of unused entries while keeping frequently accessed ones alive.
8
+ */
9
+ declare class TimeoutWeakMap<K extends object, V> {
10
+ readonly timeoutMs: number;
11
+ protected readonly wmap: WeakMap<K, [V, NodeJS.Timeout]>;
12
+ /**
13
+ * @param timeoutMs Default timeout in milliseconds for entries
14
+ */
15
+ constructor(timeoutMs: number);
16
+ /**
17
+ * Retrieves the value for the given key and refreshes its timeout.
18
+ *
19
+ * @param key The key to retrieve
20
+ * @returns The value if found, undefined otherwise
21
+ */
22
+ get(key: K): V | undefined;
23
+ /**
24
+ * Sets a key-value pair with an optional custom timeout.
25
+ *
26
+ * @param key The key to set
27
+ * @param value The value to associate with the key
28
+ * @param timeoutMs Optional timeout override for this entry
29
+ * @returns This instance for chaining
30
+ */
31
+ set(key: K, value: V, timeoutMs?: number): this;
32
+ /**
33
+ * Removes a key-value pair and clears its timeout.
34
+ *
35
+ * @param key The key to delete
36
+ * @returns True if the key existed and was deleted, false otherwise
37
+ */
38
+ delete(key: K): boolean;
39
+ /**
40
+ * Checks if a key exists in the map.
41
+ * Does not refresh the timeout.
42
+ *
43
+ * @param key The key to check
44
+ * @returns True if the key exists, false otherwise
45
+ */
46
+ has(key: K): boolean;
47
+ /**
48
+ * Loads multiple key-value pairs into the map.
49
+ *
50
+ * @param entries Iterable of key-value pairs to load
51
+ * @param timeoutMs Optional timeout override for all entries
52
+ * @returns This instance for chaining
53
+ */
54
+ load(entries: Iterable<[K, V]>, timeoutMs?: number): this;
55
+ /**
56
+ * Updates an existing value or creates a new one using an update function.
57
+ *
58
+ * @param key The key to update
59
+ * @param update Function that receives the current value and returns the new value
60
+ * @returns This instance for chaining
61
+ */
62
+ update(key: K, update: (value: V | undefined, key: K, map: this) => V): this;
63
+ /**
64
+ * Gets a value or creates it using a factory function if it doesn't exist.
65
+ * Refreshes timeout if the value exists.
66
+ *
67
+ * @param key The key to get or create
68
+ * @param factory Function to create the value if it doesn't exist
69
+ * @param timeoutMs Optional timeout override for new entries
70
+ * @returns The existing or newly created value
71
+ */
72
+ getOrDefault(key: K, factory: (key: K, map: this) => V, timeoutMs?: number): V;
73
+ }
74
+
75
+ export { TimeoutWeakMap };