@internetarchive/ads-table 0.0.3 → 0.0.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/.rollup.cache/Users/jeffwklein/work/archive/ads-common/packages/ads-table/dist/ads-table.js +2 -2
- package/.rollup.cache/Users/jeffwklein/work/archive/ads-common/packages/ads-table/dist/ads-table.js.map +1 -1
- package/.rollup.cache/Users/jeffwklein/work/archive/ads-common/packages/ads-table/dist/index.d.ts +1 -1
- package/.rollup.cache/Users/jeffwklein/work/archive/ads-common/packages/ads-table/dist/index.js +1 -1
- package/.rollup.cache/Users/jeffwklein/work/archive/ads-common/packages/ads-table/dist/index.js.map +1 -1
- package/.rollup.cache/Users/jeffwklein/work/archive/ads-common/packages/ads-table/dist/types.js +1 -1
- package/.rollup.cache/Users/jeffwklein/work/archive/ads-common/packages/ads-table/dist/types.js.map +1 -1
- package/.rollup.cache/Users/jeffwklein/work/archive/ads-common/packages/ads-table/tsconfig.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +293 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ads-table.ts +2 -2
- package/src/index.ts +1 -0
- package/src/types.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.js
CHANGED
|
@@ -101,6 +101,292 @@ EventHelpers.defaultEventOptions = {
|
|
|
101
101
|
bubbles: true,
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
class QuickLRU extends Map {
|
|
105
|
+
constructor(options = {}) {
|
|
106
|
+
super();
|
|
107
|
+
|
|
108
|
+
if (!(options.maxSize && options.maxSize > 0)) {
|
|
109
|
+
throw new TypeError('`maxSize` must be a number greater than 0');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (typeof options.maxAge === 'number' && options.maxAge === 0) {
|
|
113
|
+
throw new TypeError('`maxAge` must be a number greater than 0');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// TODO: Use private class fields when ESLint supports them.
|
|
117
|
+
this.maxSize = options.maxSize;
|
|
118
|
+
this.maxAge = options.maxAge || Number.POSITIVE_INFINITY;
|
|
119
|
+
this.onEviction = options.onEviction;
|
|
120
|
+
this.cache = new Map();
|
|
121
|
+
this.oldCache = new Map();
|
|
122
|
+
this._size = 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// TODO: Use private class methods when targeting Node.js 16.
|
|
126
|
+
_emitEvictions(cache) {
|
|
127
|
+
if (typeof this.onEviction !== 'function') {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (const [key, item] of cache) {
|
|
132
|
+
this.onEviction(key, item.value);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
_deleteIfExpired(key, item) {
|
|
137
|
+
if (typeof item.expiry === 'number' && item.expiry <= Date.now()) {
|
|
138
|
+
if (typeof this.onEviction === 'function') {
|
|
139
|
+
this.onEviction(key, item.value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return this.delete(key);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_getOrDeleteIfExpired(key, item) {
|
|
149
|
+
const deleted = this._deleteIfExpired(key, item);
|
|
150
|
+
if (deleted === false) {
|
|
151
|
+
return item.value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_getItemValue(key, item) {
|
|
156
|
+
return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_peek(key, cache) {
|
|
160
|
+
const item = cache.get(key);
|
|
161
|
+
|
|
162
|
+
return this._getItemValue(key, item);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
_set(key, value) {
|
|
166
|
+
this.cache.set(key, value);
|
|
167
|
+
this._size++;
|
|
168
|
+
|
|
169
|
+
if (this._size >= this.maxSize) {
|
|
170
|
+
this._size = 0;
|
|
171
|
+
this._emitEvictions(this.oldCache);
|
|
172
|
+
this.oldCache = this.cache;
|
|
173
|
+
this.cache = new Map();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
_moveToRecent(key, item) {
|
|
178
|
+
this.oldCache.delete(key);
|
|
179
|
+
this._set(key, item);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
* _entriesAscending() {
|
|
183
|
+
for (const item of this.oldCache) {
|
|
184
|
+
const [key, value] = item;
|
|
185
|
+
if (!this.cache.has(key)) {
|
|
186
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
187
|
+
if (deleted === false) {
|
|
188
|
+
yield item;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
for (const item of this.cache) {
|
|
194
|
+
const [key, value] = item;
|
|
195
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
196
|
+
if (deleted === false) {
|
|
197
|
+
yield item;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
get(key) {
|
|
203
|
+
if (this.cache.has(key)) {
|
|
204
|
+
const item = this.cache.get(key);
|
|
205
|
+
|
|
206
|
+
return this._getItemValue(key, item);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (this.oldCache.has(key)) {
|
|
210
|
+
const item = this.oldCache.get(key);
|
|
211
|
+
if (this._deleteIfExpired(key, item) === false) {
|
|
212
|
+
this._moveToRecent(key, item);
|
|
213
|
+
return item.value;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
set(key, value, {maxAge = this.maxAge} = {}) {
|
|
219
|
+
const expiry =
|
|
220
|
+
typeof maxAge === 'number' && maxAge !== Number.POSITIVE_INFINITY ?
|
|
221
|
+
Date.now() + maxAge :
|
|
222
|
+
undefined;
|
|
223
|
+
if (this.cache.has(key)) {
|
|
224
|
+
this.cache.set(key, {
|
|
225
|
+
value,
|
|
226
|
+
expiry
|
|
227
|
+
});
|
|
228
|
+
} else {
|
|
229
|
+
this._set(key, {value, expiry});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
has(key) {
|
|
236
|
+
if (this.cache.has(key)) {
|
|
237
|
+
return !this._deleteIfExpired(key, this.cache.get(key));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (this.oldCache.has(key)) {
|
|
241
|
+
return !this._deleteIfExpired(key, this.oldCache.get(key));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
peek(key) {
|
|
248
|
+
if (this.cache.has(key)) {
|
|
249
|
+
return this._peek(key, this.cache);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (this.oldCache.has(key)) {
|
|
253
|
+
return this._peek(key, this.oldCache);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
delete(key) {
|
|
258
|
+
const deleted = this.cache.delete(key);
|
|
259
|
+
if (deleted) {
|
|
260
|
+
this._size--;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return this.oldCache.delete(key) || deleted;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
clear() {
|
|
267
|
+
this.cache.clear();
|
|
268
|
+
this.oldCache.clear();
|
|
269
|
+
this._size = 0;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
resize(newSize) {
|
|
273
|
+
if (!(newSize && newSize > 0)) {
|
|
274
|
+
throw new TypeError('`maxSize` must be a number greater than 0');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const items = [...this._entriesAscending()];
|
|
278
|
+
const removeCount = items.length - newSize;
|
|
279
|
+
if (removeCount < 0) {
|
|
280
|
+
this.cache = new Map(items);
|
|
281
|
+
this.oldCache = new Map();
|
|
282
|
+
this._size = items.length;
|
|
283
|
+
} else {
|
|
284
|
+
if (removeCount > 0) {
|
|
285
|
+
this._emitEvictions(items.slice(0, removeCount));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
this.oldCache = new Map(items.slice(removeCount));
|
|
289
|
+
this.cache = new Map();
|
|
290
|
+
this._size = 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
this.maxSize = newSize;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
* keys() {
|
|
297
|
+
for (const [key] of this) {
|
|
298
|
+
yield key;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
* values() {
|
|
303
|
+
for (const [, value] of this) {
|
|
304
|
+
yield value;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
* [Symbol.iterator]() {
|
|
309
|
+
for (const item of this.cache) {
|
|
310
|
+
const [key, value] = item;
|
|
311
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
312
|
+
if (deleted === false) {
|
|
313
|
+
yield [key, value.value];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
for (const item of this.oldCache) {
|
|
318
|
+
const [key, value] = item;
|
|
319
|
+
if (!this.cache.has(key)) {
|
|
320
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
321
|
+
if (deleted === false) {
|
|
322
|
+
yield [key, value.value];
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
* entriesDescending() {
|
|
329
|
+
let items = [...this.cache];
|
|
330
|
+
for (let i = items.length - 1; i >= 0; --i) {
|
|
331
|
+
const item = items[i];
|
|
332
|
+
const [key, value] = item;
|
|
333
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
334
|
+
if (deleted === false) {
|
|
335
|
+
yield [key, value.value];
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
items = [...this.oldCache];
|
|
340
|
+
for (let i = items.length - 1; i >= 0; --i) {
|
|
341
|
+
const item = items[i];
|
|
342
|
+
const [key, value] = item;
|
|
343
|
+
if (!this.cache.has(key)) {
|
|
344
|
+
const deleted = this._deleteIfExpired(key, value);
|
|
345
|
+
if (deleted === false) {
|
|
346
|
+
yield [key, value.value];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
* entriesAscending() {
|
|
353
|
+
for (const [key, value] of this._entriesAscending()) {
|
|
354
|
+
yield [key, value.value];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
get size() {
|
|
359
|
+
if (!this._size) {
|
|
360
|
+
return this.oldCache.size;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
let oldCacheSize = 0;
|
|
364
|
+
for (const key of this.oldCache.keys()) {
|
|
365
|
+
if (!this.cache.has(key)) {
|
|
366
|
+
oldCacheSize++;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return Math.min(this._size + oldCacheSize, this.maxSize);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
entries() {
|
|
374
|
+
return this.entriesAscending();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
forEach(callbackFunction, thisArgument = this) {
|
|
378
|
+
for (const [key, value] of this.entriesAscending()) {
|
|
379
|
+
callbackFunction.call(thisArgument, value, key, this);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
get [Symbol.toStringTag]() {
|
|
384
|
+
return JSON.stringify([...this.entriesAscending()]);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
new QuickLRU({maxSize: 100_000});
|
|
389
|
+
|
|
104
390
|
// browser-related utility functions
|
|
105
391
|
var UserOperatingSystem;
|
|
106
392
|
(function (UserOperatingSystem) {
|
|
@@ -649,11 +935,17 @@ const UndefinedHelpers = (dataType) => {
|
|
|
649
935
|
},
|
|
650
936
|
};
|
|
651
937
|
};
|
|
938
|
+
// quickly define a wrapper around an interface key, applying sorting / formatting rules from a given type
|
|
939
|
+
const FromKey = (targetDataType, key) => ({
|
|
940
|
+
...targetDataType,
|
|
941
|
+
compare: (a, b) => { var _a; return ((_a = targetDataType.compare) === null || _a === void 0 ? void 0 : _a.call(targetDataType, a[key], b[key])) || 0; },
|
|
942
|
+
format: (item) => targetDataType.format(item[key]),
|
|
943
|
+
});
|
|
652
944
|
// will return a DataType to have an undefined comparison function, turning sorting off for this data type
|
|
653
945
|
const NonSortable = (dataType) => ({
|
|
654
946
|
...dataType,
|
|
655
947
|
compare: undefined,
|
|
656
948
|
});
|
|
657
949
|
|
|
658
|
-
export { AdsSimpleTable, AdsTable, BytesDataType, DateDataType, NonSortable, NumberDataType, StringDataType, UndefinedHelpers };
|
|
950
|
+
export { AdsSimpleTable, AdsTable, BytesDataType, DateDataType, FromKey, NonSortable, NumberDataType, StringDataType, UndefinedHelpers };
|
|
659
951
|
//# sourceMappingURL=index.js.map
|