@mark1russell7/collections 0.8.0 → 0.9.0
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/README.md +8 -1
- package/build/index.d.ts +51 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +160 -31
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/bounded.ts +24 -6
- package/src/behaviors/evented.ts +75 -25
- package/src/behaviors/lru.ts +18 -22
- package/src/behaviors/ttl.ts +12 -0
- package/src/core/removals.ts +85 -0
- package/src/index.ts +1 -0
package/build/index.js
CHANGED
|
@@ -456,6 +456,38 @@ const onWhen = (emitter, event, predicate, listener) => {
|
|
|
456
456
|
if (predicate(payload)) listener(payload);
|
|
457
457
|
});
|
|
458
458
|
};
|
|
459
|
+
// src/core/removals.ts
|
|
460
|
+
/** The key of the removal channel on a layer. */
|
|
461
|
+
const removals = Symbol.for("@mark1russell7/collections/removals");
|
|
462
|
+
/**
|
|
463
|
+
* This function gives the removal channel of a collection, or `undefined` when no layer of it removes.
|
|
464
|
+
*/
|
|
465
|
+
function removalsOf(collection) {
|
|
466
|
+
const channel = collection[removals];
|
|
467
|
+
if (typeof channel !== "object" || channel === null) return void 0;
|
|
468
|
+
return typeof channel.on === "function" ? channel : void 0;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* This function makes the channel of a removing layer over `next`.
|
|
472
|
+
* The channel forwards each removal below. It calls `below` first, so the layer corrects its own state first.
|
|
473
|
+
*/
|
|
474
|
+
function removalSource(next, below) {
|
|
475
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
476
|
+
const emit = (removal) => {
|
|
477
|
+
for (const listener of [...listeners]) listener(removal);
|
|
478
|
+
};
|
|
479
|
+
removalsOf(next)?.on((removal) => {
|
|
480
|
+
below?.(removal);
|
|
481
|
+
emit(removal);
|
|
482
|
+
});
|
|
483
|
+
return {
|
|
484
|
+
channel: { on(listener) {
|
|
485
|
+
listeners.add(listener);
|
|
486
|
+
return () => void listeners.delete(listener);
|
|
487
|
+
} },
|
|
488
|
+
emit
|
|
489
|
+
};
|
|
490
|
+
}
|
|
459
491
|
// src/storage/listeners.ts
|
|
460
492
|
/**
|
|
461
493
|
* The default handler of the error of a listener. It throws the error again in a microtask, as an
|
|
@@ -4509,6 +4541,7 @@ function boundedList(options) {
|
|
|
4509
4541
|
const { policy = "throw", onOverflow } = options;
|
|
4510
4542
|
const capacity = checkCapacity(options.capacity, "boundedList");
|
|
4511
4543
|
return (next) => {
|
|
4544
|
+
const source = removalSource(next);
|
|
4512
4545
|
const handleOverflow = (element, dropFrom = "first") => {
|
|
4513
4546
|
if (onOverflow) {
|
|
4514
4547
|
const context = {
|
|
@@ -4523,8 +4556,12 @@ function boundedList(options) {
|
|
|
4523
4556
|
case "throw": throw new Error(`List is full (capacity: ${capacity})`);
|
|
4524
4557
|
case "drop-oldest":
|
|
4525
4558
|
if (!next.isEmpty) {
|
|
4526
|
-
|
|
4527
|
-
|
|
4559
|
+
const value = dropFrom === "last" ? next.pop() : next.shift();
|
|
4560
|
+
source.emit({
|
|
4561
|
+
value,
|
|
4562
|
+
end: dropFrom,
|
|
4563
|
+
reason: "drop"
|
|
4564
|
+
});
|
|
4528
4565
|
}
|
|
4529
4566
|
break;
|
|
4530
4567
|
case "drop-newest": return;
|
|
@@ -4536,6 +4573,7 @@ function boundedList(options) {
|
|
|
4536
4573
|
};
|
|
4537
4574
|
const shifted = (index) => policy === "drop-oldest" ? Math.max(0, index - 1) : index;
|
|
4538
4575
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
4576
|
+
if (prop === removals) return source.channel;
|
|
4539
4577
|
if (prop === "capacity") return capacity;
|
|
4540
4578
|
if (prop === "isFull") return target.size >= capacity;
|
|
4541
4579
|
if (prop === "remainingCapacity") return Math.max(0, capacity - target.size);
|
|
@@ -4619,6 +4657,7 @@ function boundedQueue(options) {
|
|
|
4619
4657
|
const { policy = "throw", onOverflow } = options;
|
|
4620
4658
|
const capacity = checkCapacity(options.capacity, "boundedQueue");
|
|
4621
4659
|
return (next) => {
|
|
4660
|
+
const source = removalSource(next);
|
|
4622
4661
|
const handleOverflow = (element) => {
|
|
4623
4662
|
if (onOverflow) {
|
|
4624
4663
|
const context = {
|
|
@@ -4632,7 +4671,11 @@ function boundedQueue(options) {
|
|
|
4632
4671
|
switch (policy) {
|
|
4633
4672
|
case "throw": throw new Error(`Queue is full (capacity: ${capacity})`);
|
|
4634
4673
|
case "drop-oldest":
|
|
4635
|
-
if (!next.isEmpty)
|
|
4674
|
+
if (!next.isEmpty) source.emit({
|
|
4675
|
+
value: next.poll(),
|
|
4676
|
+
end: "first",
|
|
4677
|
+
reason: "drop"
|
|
4678
|
+
});
|
|
4636
4679
|
break;
|
|
4637
4680
|
case "drop-newest":
|
|
4638
4681
|
case "reject": return;
|
|
@@ -4642,6 +4685,7 @@ function boundedQueue(options) {
|
|
|
4642
4685
|
}
|
|
4643
4686
|
};
|
|
4644
4687
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
4688
|
+
if (prop === removals) return source.channel;
|
|
4645
4689
|
if (prop === "capacity") return capacity;
|
|
4646
4690
|
if (prop === "isFull") return target.size >= capacity;
|
|
4647
4691
|
if (prop === "remainingCapacity") return Math.max(0, capacity - target.size);
|
|
@@ -4671,6 +4715,7 @@ function boundedDeque(options) {
|
|
|
4671
4715
|
const { policy = "throw", onOverflow } = options;
|
|
4672
4716
|
const capacity = checkCapacity(options.capacity, "boundedDeque");
|
|
4673
4717
|
return (next) => {
|
|
4718
|
+
const source = removalSource(next);
|
|
4674
4719
|
const handleOverflow = (element, dropFrom) => {
|
|
4675
4720
|
if (onOverflow) {
|
|
4676
4721
|
const context = {
|
|
@@ -4685,8 +4730,12 @@ function boundedDeque(options) {
|
|
|
4685
4730
|
case "throw": throw new Error(`Deque is full (capacity: ${capacity})`);
|
|
4686
4731
|
case "drop-oldest":
|
|
4687
4732
|
if (!next.isEmpty) {
|
|
4688
|
-
|
|
4689
|
-
|
|
4733
|
+
const value = dropFrom === "last" ? next.removeLast() : next.removeFirst();
|
|
4734
|
+
source.emit({
|
|
4735
|
+
value,
|
|
4736
|
+
end: dropFrom,
|
|
4737
|
+
reason: "drop"
|
|
4738
|
+
});
|
|
4690
4739
|
}
|
|
4691
4740
|
break;
|
|
4692
4741
|
case "drop-newest":
|
|
@@ -4697,6 +4746,7 @@ function boundedDeque(options) {
|
|
|
4697
4746
|
}
|
|
4698
4747
|
};
|
|
4699
4748
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
4749
|
+
if (prop === removals) return source.channel;
|
|
4700
4750
|
if (prop === "capacity") return capacity;
|
|
4701
4751
|
if (prop === "isFull") return target.size >= capacity;
|
|
4702
4752
|
if (prop === "remainingCapacity") return Math.max(0, capacity - target.size);
|
|
@@ -4731,6 +4781,9 @@ function boundedMap(options) {
|
|
|
4731
4781
|
const capacity = checkCapacity(options.capacity, "boundedMap");
|
|
4732
4782
|
return (next) => {
|
|
4733
4783
|
let insertionOrder = [];
|
|
4784
|
+
const source = removalSource(next, ({ key }) => {
|
|
4785
|
+
insertionOrder = insertionOrder.filter((k) => !next.keyEq(k, key));
|
|
4786
|
+
});
|
|
4734
4787
|
const handleOverflow = (key, value) => {
|
|
4735
4788
|
if (onOverflow) onOverflow({
|
|
4736
4789
|
key,
|
|
@@ -4742,9 +4795,17 @@ function boundedMap(options) {
|
|
|
4742
4795
|
switch (policy) {
|
|
4743
4796
|
case "throw": throw new Error(`Map is full (capacity: ${capacity})`);
|
|
4744
4797
|
case "drop-oldest":
|
|
4745
|
-
|
|
4798
|
+
while (insertionOrder.length > 0) {
|
|
4746
4799
|
const oldestKey = insertionOrder.shift();
|
|
4800
|
+
if (!next.has(oldestKey)) continue;
|
|
4801
|
+
const value = next.get(oldestKey);
|
|
4747
4802
|
next.delete(oldestKey);
|
|
4803
|
+
source.emit({
|
|
4804
|
+
key: oldestKey,
|
|
4805
|
+
value,
|
|
4806
|
+
reason: "drop"
|
|
4807
|
+
});
|
|
4808
|
+
break;
|
|
4748
4809
|
}
|
|
4749
4810
|
break;
|
|
4750
4811
|
case "drop-newest":
|
|
@@ -4755,6 +4816,7 @@ function boundedMap(options) {
|
|
|
4755
4816
|
}
|
|
4756
4817
|
};
|
|
4757
4818
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
4819
|
+
if (prop === removals) return source.channel;
|
|
4758
4820
|
if (prop === "capacity") return capacity;
|
|
4759
4821
|
if (prop === "isFull") return target.size >= capacity;
|
|
4760
4822
|
if (prop === "remainingCapacity") return Math.max(0, capacity - target.size);
|
|
@@ -5084,6 +5146,24 @@ function safe() {
|
|
|
5084
5146
|
}
|
|
5085
5147
|
// src/behaviors/evented.ts
|
|
5086
5148
|
/**
|
|
5149
|
+
* This function gives each removal below `next` to `listener` and counts the removals.
|
|
5150
|
+
* With the counts, a layer tells a refused add (the size did not grow) from an add that caused a drop.
|
|
5151
|
+
*/
|
|
5152
|
+
function hear(next, listener) {
|
|
5153
|
+
const heard = {
|
|
5154
|
+
all: 0,
|
|
5155
|
+
first: 0
|
|
5156
|
+
};
|
|
5157
|
+
removalsOf(next)?.on((removal) => {
|
|
5158
|
+
heard.all++;
|
|
5159
|
+
if ("end" in removal && removal.end === "first") heard.first++;
|
|
5160
|
+
listener(removal);
|
|
5161
|
+
});
|
|
5162
|
+
return heard;
|
|
5163
|
+
}
|
|
5164
|
+
/** This function tells if a call added an element: the size grew, after the removals of the layers below. */
|
|
5165
|
+
const added = (size, sizeBefore, heard, heardBefore) => size - sizeBefore + heard.all - heardBefore > 0;
|
|
5166
|
+
/**
|
|
5087
5167
|
* This function makes an evented List middleware.
|
|
5088
5168
|
*
|
|
5089
5169
|
* This function emits events for add, remove, set, clear, sort, and reverse operations.
|
|
@@ -5091,28 +5171,44 @@ function safe() {
|
|
|
5091
5171
|
function eventedList() {
|
|
5092
5172
|
return (next) => {
|
|
5093
5173
|
const emitter = new Emitter();
|
|
5174
|
+
const heard = hear(next, ({ value, end, reason }) => emitter.emit("remove", end === void 0 ? {
|
|
5175
|
+
value,
|
|
5176
|
+
reason
|
|
5177
|
+
} : {
|
|
5178
|
+
value,
|
|
5179
|
+
index: end === "first" ? 0 : next.size,
|
|
5180
|
+
reason
|
|
5181
|
+
}));
|
|
5094
5182
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
5095
5183
|
if (prop === "on") return emitter.on.bind(emitter);
|
|
5096
5184
|
const value = Reflect.get(target, prop, receiver);
|
|
5097
5185
|
if (typeof value === "function") switch (prop) {
|
|
5098
5186
|
case "add":
|
|
5099
5187
|
case "push": return function(element) {
|
|
5188
|
+
const size = target.size;
|
|
5189
|
+
const all = heard.all;
|
|
5100
5190
|
const result = value.call(target, element);
|
|
5101
|
-
emitter.emit("add", { value: element });
|
|
5191
|
+
if (added(target.size, size, heard, all)) emitter.emit("add", { value: element });
|
|
5102
5192
|
return result;
|
|
5103
5193
|
};
|
|
5104
5194
|
case "unshift": return function(element) {
|
|
5195
|
+
const size = target.size;
|
|
5196
|
+
const all = heard.all;
|
|
5105
5197
|
value.call(target, element);
|
|
5106
|
-
emitter.emit("add", {
|
|
5198
|
+
if (added(target.size, size, heard, all)) emitter.emit("add", {
|
|
5107
5199
|
value: element,
|
|
5108
5200
|
index: 0
|
|
5109
5201
|
});
|
|
5110
5202
|
};
|
|
5111
5203
|
case "insert": return function(index, element) {
|
|
5204
|
+
const size = target.size;
|
|
5205
|
+
const all = heard.all;
|
|
5206
|
+
const first = heard.first;
|
|
5112
5207
|
value.call(target, index, element);
|
|
5208
|
+
if (!added(target.size, size, heard, all)) return;
|
|
5113
5209
|
emitter.emit("add", {
|
|
5114
5210
|
value: element,
|
|
5115
|
-
index
|
|
5211
|
+
index: heard.first > first ? Math.max(0, index - 1) : index
|
|
5116
5212
|
});
|
|
5117
5213
|
};
|
|
5118
5214
|
case "set": return function(index, element) {
|
|
@@ -5139,7 +5235,10 @@ function eventedList() {
|
|
|
5139
5235
|
};
|
|
5140
5236
|
case "pop": return function() {
|
|
5141
5237
|
const removed = value.call(target);
|
|
5142
|
-
emitter.emit("remove", {
|
|
5238
|
+
emitter.emit("remove", {
|
|
5239
|
+
value: removed,
|
|
5240
|
+
index: target.size
|
|
5241
|
+
});
|
|
5143
5242
|
return removed;
|
|
5144
5243
|
};
|
|
5145
5244
|
case "shift": return function() {
|
|
@@ -5173,6 +5272,10 @@ function eventedList() {
|
|
|
5173
5272
|
function eventedQueue() {
|
|
5174
5273
|
return (next) => {
|
|
5175
5274
|
const emitter = new Emitter();
|
|
5275
|
+
hear(next, ({ value, reason }) => emitter.emit("dequeue", {
|
|
5276
|
+
value,
|
|
5277
|
+
reason
|
|
5278
|
+
}));
|
|
5176
5279
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
5177
5280
|
if (prop === "on") return emitter.on.bind(emitter);
|
|
5178
5281
|
const value = Reflect.get(target, prop, receiver);
|
|
@@ -5205,23 +5308,25 @@ function eventedQueue() {
|
|
|
5205
5308
|
function eventedDeque() {
|
|
5206
5309
|
return (next) => {
|
|
5207
5310
|
const emitter = new Emitter();
|
|
5311
|
+
const heard = hear(next, ({ value, end, reason }) => emitter.emit(end === "last" ? "removeLast" : "removeFirst", {
|
|
5312
|
+
value,
|
|
5313
|
+
reason
|
|
5314
|
+
}));
|
|
5208
5315
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
5209
5316
|
if (prop === "on") return emitter.on.bind(emitter);
|
|
5210
5317
|
const value = Reflect.get(target, prop, receiver);
|
|
5211
5318
|
if (typeof value === "function") switch (prop) {
|
|
5212
5319
|
case "addFirst":
|
|
5213
5320
|
case "offerFirst":
|
|
5214
|
-
case "push": return function(element) {
|
|
5215
|
-
const result = value.call(target, element);
|
|
5216
|
-
emitter.emit("addFirst", { value: element });
|
|
5217
|
-
return result;
|
|
5218
|
-
};
|
|
5219
5321
|
case "addLast":
|
|
5220
5322
|
case "offerLast":
|
|
5221
5323
|
case "offer":
|
|
5222
|
-
case "add":
|
|
5324
|
+
case "add":
|
|
5325
|
+
case "push": return function(element) {
|
|
5326
|
+
const size = target.size;
|
|
5327
|
+
const all = heard.all;
|
|
5223
5328
|
const result = value.call(target, element);
|
|
5224
|
-
emitter.emit("addLast", { value: element });
|
|
5329
|
+
if (added(target.size, size, heard, all)) emitter.emit(prop === "addFirst" || prop === "offerFirst" ? "addFirst" : "addLast", { value: element });
|
|
5225
5330
|
return result;
|
|
5226
5331
|
};
|
|
5227
5332
|
case "removeFirst":
|
|
@@ -5254,13 +5359,20 @@ function eventedDeque() {
|
|
|
5254
5359
|
function eventedMap() {
|
|
5255
5360
|
return (next) => {
|
|
5256
5361
|
const emitter = new Emitter();
|
|
5362
|
+
const heard = hear(next, ({ key, value, reason }) => emitter.emit("delete", {
|
|
5363
|
+
key,
|
|
5364
|
+
value,
|
|
5365
|
+
reason
|
|
5366
|
+
}));
|
|
5257
5367
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
5258
5368
|
if (prop === "on") return emitter.on.bind(emitter);
|
|
5259
5369
|
const value = Reflect.get(target, prop, receiver);
|
|
5260
5370
|
if (typeof value === "function") switch (prop) {
|
|
5261
5371
|
case "set": return function(key, val) {
|
|
5372
|
+
const size = target.size;
|
|
5373
|
+
const all = heard.all;
|
|
5262
5374
|
const oldValue = value.call(target, key, val);
|
|
5263
|
-
emitter.emit("set", {
|
|
5375
|
+
if (oldValue !== void 0 || added(target.size, size, heard, all)) emitter.emit("set", {
|
|
5264
5376
|
key,
|
|
5265
5377
|
value: val,
|
|
5266
5378
|
oldValue
|
|
@@ -5290,6 +5402,10 @@ function eventedMap() {
|
|
|
5290
5402
|
function evented() {
|
|
5291
5403
|
return (next) => {
|
|
5292
5404
|
const emitter = new Emitter();
|
|
5405
|
+
hear(next, ({ value, reason }) => emitter.emit("remove", {
|
|
5406
|
+
value,
|
|
5407
|
+
reason
|
|
5408
|
+
}));
|
|
5293
5409
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
5294
5410
|
if (prop === "on") return emitter.on.bind(emitter);
|
|
5295
5411
|
const value = Reflect.get(target, prop, receiver);
|
|
@@ -5662,6 +5778,10 @@ function lruMap(options) {
|
|
|
5662
5778
|
else tail = node.prev;
|
|
5663
5779
|
nodeMap.delete(node.key);
|
|
5664
5780
|
};
|
|
5781
|
+
const source = removalSource(next, ({ key }) => {
|
|
5782
|
+
const node = nodeMap.get(key);
|
|
5783
|
+
if (node) removeNode(node);
|
|
5784
|
+
});
|
|
5665
5785
|
const dropStaleNodes = () => {
|
|
5666
5786
|
for (const node of [...nodeMap.values()]) if (!next.has(node.key)) removeNode(node);
|
|
5667
5787
|
};
|
|
@@ -5676,24 +5796,23 @@ function lruMap(options) {
|
|
|
5676
5796
|
value: candidate.value,
|
|
5677
5797
|
timestamp: candidate.lastAccessed
|
|
5678
5798
|
});
|
|
5799
|
+
source.emit({
|
|
5800
|
+
key: candidate.key,
|
|
5801
|
+
value: candidate.value,
|
|
5802
|
+
reason: "evict"
|
|
5803
|
+
});
|
|
5679
5804
|
return;
|
|
5680
5805
|
}
|
|
5681
5806
|
};
|
|
5682
5807
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
5808
|
+
if (prop === removals) return source.channel;
|
|
5683
5809
|
if (prop === "isFull") return target.size >= capacity;
|
|
5684
5810
|
const composite = compositeMapMethod(receiver, prop);
|
|
5685
5811
|
if (composite) return composite;
|
|
5686
5812
|
const value = Reflect.get(target, prop, receiver);
|
|
5687
5813
|
if (typeof value === "function") switch (prop) {
|
|
5688
5814
|
case "get": return function(key) {
|
|
5689
|
-
|
|
5690
|
-
try {
|
|
5691
|
-
result = value.call(target, key);
|
|
5692
|
-
} catch (error) {
|
|
5693
|
-
const stale = nodeMap.get(key);
|
|
5694
|
-
if (stale) removeNode(stale);
|
|
5695
|
-
throw error;
|
|
5696
|
-
}
|
|
5815
|
+
const result = value.call(target, key);
|
|
5697
5816
|
const node = nodeMap.get(key);
|
|
5698
5817
|
if (node) moveToHead(node);
|
|
5699
5818
|
return result;
|
|
@@ -5701,10 +5820,7 @@ function lruMap(options) {
|
|
|
5701
5820
|
case "has": return function(key) {
|
|
5702
5821
|
const result = value.call(target, key);
|
|
5703
5822
|
const node = nodeMap.get(key);
|
|
5704
|
-
if (node)
|
|
5705
|
-
if (result) moveToHead(node);
|
|
5706
|
-
else removeNode(node);
|
|
5707
|
-
}
|
|
5823
|
+
if (node && result) moveToHead(node);
|
|
5708
5824
|
return result;
|
|
5709
5825
|
};
|
|
5710
5826
|
case "set": return function(key, val) {
|
|
@@ -5920,6 +6036,7 @@ function ttlMap(options) {
|
|
|
5920
6036
|
return (next) => {
|
|
5921
6037
|
const metadata = /* @__PURE__ */ new Map();
|
|
5922
6038
|
let intervalId = null;
|
|
6039
|
+
const source = removalSource(next, ({ key }) => void metadata.delete(key));
|
|
5923
6040
|
const sweep = () => {
|
|
5924
6041
|
const now = Date.now();
|
|
5925
6042
|
for (const [key, entry] of metadata) {
|
|
@@ -5932,6 +6049,11 @@ function ttlMap(options) {
|
|
|
5932
6049
|
createdAt: entry.createdAt,
|
|
5933
6050
|
expiredAt: now
|
|
5934
6051
|
});
|
|
6052
|
+
source.emit({
|
|
6053
|
+
key,
|
|
6054
|
+
value: entry.value,
|
|
6055
|
+
reason: "expire"
|
|
6056
|
+
});
|
|
5935
6057
|
}
|
|
5936
6058
|
};
|
|
5937
6059
|
intervalId = startExpirationTimer(sweep, checkInterval);
|
|
@@ -5943,6 +6065,7 @@ function ttlMap(options) {
|
|
|
5943
6065
|
};
|
|
5944
6066
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
5945
6067
|
if (prop === "dispose") return dispose;
|
|
6068
|
+
if (prop === removals) return source.channel;
|
|
5946
6069
|
const composite = compositeMapMethod(receiver, prop);
|
|
5947
6070
|
if (composite) return composite;
|
|
5948
6071
|
sweep();
|
|
@@ -6006,6 +6129,7 @@ function ttlCollection(options) {
|
|
|
6006
6129
|
return (next) => {
|
|
6007
6130
|
const metadata = /* @__PURE__ */ new Map();
|
|
6008
6131
|
let intervalId = null;
|
|
6132
|
+
const source = removalSource(next, ({ value }) => void metadata.delete(value));
|
|
6009
6133
|
const checkExpired = () => {
|
|
6010
6134
|
const now = Date.now();
|
|
6011
6135
|
const expired = [];
|
|
@@ -6020,6 +6144,10 @@ function ttlCollection(options) {
|
|
|
6020
6144
|
createdAt: entry.createdAt,
|
|
6021
6145
|
expiredAt: now
|
|
6022
6146
|
});
|
|
6147
|
+
source.emit({
|
|
6148
|
+
value: element,
|
|
6149
|
+
reason: "expire"
|
|
6150
|
+
});
|
|
6023
6151
|
}
|
|
6024
6152
|
}
|
|
6025
6153
|
};
|
|
@@ -6032,6 +6160,7 @@ function ttlCollection(options) {
|
|
|
6032
6160
|
};
|
|
6033
6161
|
return new Proxy(next, { get(target, prop, receiver) {
|
|
6034
6162
|
if (prop === "dispose") return dispose;
|
|
6163
|
+
if (prop === removals) return source.channel;
|
|
6035
6164
|
const value = Reflect.get(target, prop, receiver);
|
|
6036
6165
|
if (typeof value === "function") switch (prop) {
|
|
6037
6166
|
case "add": return function(element) {
|
|
@@ -7956,6 +8085,6 @@ function stringHashCode(str) {
|
|
|
7956
8085
|
}
|
|
7957
8086
|
return hash;
|
|
7958
8087
|
}
|
|
7959
|
-
export { ArrayDeque, ArrayList, AsyncEmitter, AsyncQueue, Channel, CollectionBuilder, DEFAULT_CONFLICT_POLICY, DEFAULT_EVICTION_POLICY, DEFAULT_GROWTH_POLICY, DEFAULT_OVERFLOW_POLICY, DEFAULT_RETRY_POLICY, DEFAULT_UNDERFLOW_POLICY, DEFAULT_VALIDATION_POLICY, Emitter, EventBatcher, HashMap, HashSet, KEY_DIGITS, LRUCache, LinkedHashMap, LinkedList, PriorityQueue, StorageListeners, SummaryTree, TTLCache, TreeMap, TreeSet, arrayContains, arrayDeque, arrayIterator, arrayList, arrayRemove, arrayRemoveAll, asSettled, asyncQueue, average, averagingNumber, blockMethods, booleanCompare, bounded, boundedDeque, boundedList, boundedMap, boundedQueue, buffered, buildList, buildMap, bundle, channel, checkBounds, checkInsertBounds, checkRangeBounds, chunk, clamp, collect, toArray as collectToArray, toList as collectToList, toMap as collectToMap, toSet as collectToSet, combineHashes, compareKeys, comparing, comparingKey, compose, concat, count, counting, createEmitter, dateCompare, deepEq, defaultCompare, defaultEq, defaultHash, delegate, distinct, distinctConsecutive, dropIndex, emptyList, emptyMap, emptyQueue, enhanceMethod, enumerate, eqBy, evented, eventedDeque, eventedList, eventedMap, eventedQueue, every, fanIn, fanOut, filter, filtering, find, findIndex, findLastIndex, first, flatMap, flatMapping, flatten, forwardEvent, groupBy, groupingBy, groupingByWith, hasCapability, hashBy, hashMap, hashNumber, hashSet, hashString, immutableListOf, immutableMapOf, interceptMethods, isValidKey, toMap$1 as iterToMap, joining, keyBetween, keysBetween, keysForDrop, last, linkedHashMap, linkedList, listOf, lruCache, lruMap, map, mapOf, mapping, max, maxBy, merge, min, minBy, mutableListOf, mutableMapOf, nCopies, none, nullsFirst, nullsLast, numberCompare, onWhen, partition, partitioningBy, pipe, pipeline, priorityQueue, queueOf, range, rangeTo, readWriteLock, readonly, readonlyCollection, readonlyList, readonlyMap, readonlyQueue, reduce, reducing, reducingWith, reentrantSynchronized, reportListenerError, requireNonEmpty, requireNonNull, reverse, reverseArrayIterator, reversed, safe, safeDeque, safeList, safeMap, safeQueue, scan, select, shallowEq, singletonList, singletonMap, skip, skipWhile, some, sort, stringCompare, stringCompareIgnoreCase, stringHashCode, sum, summarizingNumber, summaryTree, summingNumber, synchronized, synchronizedCollection, synchronizedList, synchronizedMap, synchronizedSet, take, takeWhile, tap, teeing, thenComparing, ticker, timeout, toArray$1 as toArray, toList$1 as toList, toMap$2 as toMap, toSet$1 as toSet, treeMap, treeSet, ttlCache, ttlCollection, ttlMap, unbuffered, unmodifiableCollection, unmodifiableList, unmodifiableMap, window, workerPool, zip };
|
|
8088
|
+
export { ArrayDeque, ArrayList, AsyncEmitter, AsyncQueue, Channel, CollectionBuilder, DEFAULT_CONFLICT_POLICY, DEFAULT_EVICTION_POLICY, DEFAULT_GROWTH_POLICY, DEFAULT_OVERFLOW_POLICY, DEFAULT_RETRY_POLICY, DEFAULT_UNDERFLOW_POLICY, DEFAULT_VALIDATION_POLICY, Emitter, EventBatcher, HashMap, HashSet, KEY_DIGITS, LRUCache, LinkedHashMap, LinkedList, PriorityQueue, StorageListeners, SummaryTree, TTLCache, TreeMap, TreeSet, arrayContains, arrayDeque, arrayIterator, arrayList, arrayRemove, arrayRemoveAll, asSettled, asyncQueue, average, averagingNumber, blockMethods, booleanCompare, bounded, boundedDeque, boundedList, boundedMap, boundedQueue, buffered, buildList, buildMap, bundle, channel, checkBounds, checkInsertBounds, checkRangeBounds, chunk, clamp, collect, toArray as collectToArray, toList as collectToList, toMap as collectToMap, toSet as collectToSet, combineHashes, compareKeys, comparing, comparingKey, compose, concat, count, counting, createEmitter, dateCompare, deepEq, defaultCompare, defaultEq, defaultHash, delegate, distinct, distinctConsecutive, dropIndex, emptyList, emptyMap, emptyQueue, enhanceMethod, enumerate, eqBy, evented, eventedDeque, eventedList, eventedMap, eventedQueue, every, fanIn, fanOut, filter, filtering, find, findIndex, findLastIndex, first, flatMap, flatMapping, flatten, forwardEvent, groupBy, groupingBy, groupingByWith, hasCapability, hashBy, hashMap, hashNumber, hashSet, hashString, immutableListOf, immutableMapOf, interceptMethods, isValidKey, toMap$1 as iterToMap, joining, keyBetween, keysBetween, keysForDrop, last, linkedHashMap, linkedList, listOf, lruCache, lruMap, map, mapOf, mapping, max, maxBy, merge, min, minBy, mutableListOf, mutableMapOf, nCopies, none, nullsFirst, nullsLast, numberCompare, onWhen, partition, partitioningBy, pipe, pipeline, priorityQueue, queueOf, range, rangeTo, readWriteLock, readonly, readonlyCollection, readonlyList, readonlyMap, readonlyQueue, reduce, reducing, reducingWith, reentrantSynchronized, removalSource, removals, removalsOf, reportListenerError, requireNonEmpty, requireNonNull, reverse, reverseArrayIterator, reversed, safe, safeDeque, safeList, safeMap, safeQueue, scan, select, shallowEq, singletonList, singletonMap, skip, skipWhile, some, sort, stringCompare, stringCompareIgnoreCase, stringHashCode, sum, summarizingNumber, summaryTree, summingNumber, synchronized, synchronizedCollection, synchronizedList, synchronizedMap, synchronizedSet, take, takeWhile, tap, teeing, thenComparing, ticker, timeout, toArray$1 as toArray, toList$1 as toList, toMap$2 as toMap, toSet$1 as toSet, treeMap, treeSet, ttlCache, ttlCollection, ttlMap, unbuffered, unmodifiableCollection, unmodifiableList, unmodifiableMap, window, workerPool, zip };
|
|
7960
8089
|
|
|
7961
8090
|
//# sourceMappingURL=index.js.map
|