lib0 0.2.44 → 0.2.47
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 +12 -9
- package/array.d.ts +1 -0
- package/array.d.ts.map +1 -1
- package/array.js +2 -0
- package/array.test.d.ts +1 -0
- package/array.test.d.ts.map +1 -1
- package/cache.d.ts +3 -1
- package/cache.d.ts.map +1 -1
- package/cache.js +40 -11
- package/cache.test.d.ts.map +1 -1
- package/dist/{array-b2d24238.cjs → array-acefe0f2.cjs} +6 -2
- package/dist/{array-b2d24238.cjs.map → array-acefe0f2.cjs.map} +1 -1
- package/dist/array.cjs +2 -1
- package/dist/array.cjs.map +1 -1
- package/dist/array.d.ts +1 -0
- package/dist/array.d.ts.map +1 -1
- package/dist/array.test.d.ts +1 -0
- package/dist/array.test.d.ts.map +1 -1
- package/dist/cache.cjs +41 -10
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.ts +3 -1
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.test.d.ts.map +1 -1
- package/dist/component.cjs +3 -3
- package/dist/{diff-233747fa.cjs → diff-2593547b.cjs} +2 -2
- package/dist/{diff-233747fa.cjs.map → diff-2593547b.cjs.map} +1 -1
- package/dist/diff.cjs +3 -3
- package/dist/{function-f8acb5f5.cjs → function-e4045b1d.cjs} +2 -2
- package/dist/{function-f8acb5f5.cjs.map → function-e4045b1d.cjs.map} +1 -1
- package/dist/function.cjs +2 -2
- package/dist/index.cjs +5 -5
- package/dist/{logging-f6d41f58.cjs → logging-0a4d8595.cjs} +2 -2
- package/dist/{logging-f6d41f58.cjs.map → logging-0a4d8595.cjs.map} +1 -1
- package/dist/logging.cjs +3 -3
- package/dist/observable.cjs +1 -1
- package/dist/test.cjs +79 -13
- package/dist/test.cjs.map +1 -1
- package/dist/test.js +79 -13
- package/dist/test.js.map +1 -1
- package/dist/testing.cjs +4 -4
- package/dist/{websocket-08bd4c7b.cjs → websocket-57086be8.cjs} +1 -1
- package/dist/{websocket-08bd4c7b.cjs.map → websocket-57086be8.cjs.map} +1 -1
- package/dist/websocket.cjs +2 -2
- package/package.json +1 -1
package/dist/test.js
CHANGED
|
@@ -862,6 +862,8 @@
|
|
|
862
862
|
*/
|
|
863
863
|
const flatten = arr => arr.reduce((acc, val) => acc.concat(val), []);
|
|
864
864
|
|
|
865
|
+
const isArray = Array.isArray;
|
|
866
|
+
|
|
865
867
|
/**
|
|
866
868
|
* Utility functions for working with EcmaScript objects.
|
|
867
869
|
*
|
|
@@ -4304,10 +4306,23 @@
|
|
|
4304
4306
|
compareArrays(flatten(arr), [1, 2, 3, 4]);
|
|
4305
4307
|
};
|
|
4306
4308
|
|
|
4309
|
+
/**
|
|
4310
|
+
* @param {t.TestCase} tc
|
|
4311
|
+
*/
|
|
4312
|
+
const testIsArray = tc => {
|
|
4313
|
+
assert(isArray([]));
|
|
4314
|
+
assert(isArray([1]));
|
|
4315
|
+
assert(isArray(Array.from(new Set([3]))));
|
|
4316
|
+
assert(!isArray(1));
|
|
4317
|
+
assert(!isArray(0));
|
|
4318
|
+
assert(!isArray(''));
|
|
4319
|
+
};
|
|
4320
|
+
|
|
4307
4321
|
var array = /*#__PURE__*/Object.freeze({
|
|
4308
4322
|
__proto__: null,
|
|
4309
4323
|
testAppend: testAppend,
|
|
4310
|
-
testflatten: testflatten
|
|
4324
|
+
testflatten: testflatten,
|
|
4325
|
+
testIsArray: testIsArray
|
|
4311
4326
|
});
|
|
4312
4327
|
|
|
4313
4328
|
const testLogging = () => {
|
|
@@ -7369,13 +7384,9 @@
|
|
|
7369
7384
|
* @return {Entry<K, V> | undefined}
|
|
7370
7385
|
*/
|
|
7371
7386
|
const getNode = (cache, key) => {
|
|
7372
|
-
|
|
7373
|
-
const q = cache._q;
|
|
7387
|
+
removeStale(cache);
|
|
7374
7388
|
const n = cache._map.get(key);
|
|
7375
7389
|
if (n) {
|
|
7376
|
-
removeNode(q, n);
|
|
7377
|
-
pushEnd(q, n);
|
|
7378
|
-
n.created = now;
|
|
7379
7390
|
return n
|
|
7380
7391
|
}
|
|
7381
7392
|
};
|
|
@@ -7392,6 +7403,23 @@
|
|
|
7392
7403
|
return n && !(n.val instanceof Promise) ? n.val : undefined
|
|
7393
7404
|
};
|
|
7394
7405
|
|
|
7406
|
+
/**
|
|
7407
|
+
* @template K, V
|
|
7408
|
+
*
|
|
7409
|
+
* @param {Cache<K, V>} cache
|
|
7410
|
+
* @param {K} key
|
|
7411
|
+
*/
|
|
7412
|
+
const refreshTimeout = (cache, key) => {
|
|
7413
|
+
const now = getUnixTime();
|
|
7414
|
+
const q = cache._q;
|
|
7415
|
+
const n = cache._map.get(key);
|
|
7416
|
+
if (n) {
|
|
7417
|
+
removeNode(q, n);
|
|
7418
|
+
pushEnd(q, n);
|
|
7419
|
+
n.created = now;
|
|
7420
|
+
}
|
|
7421
|
+
};
|
|
7422
|
+
|
|
7395
7423
|
/**
|
|
7396
7424
|
* Works well in conjunktion with setIfUndefined which has an async init function.
|
|
7397
7425
|
* Using getAsync & setIfUndefined ensures that the init function is only called once.
|
|
@@ -7407,22 +7435,35 @@
|
|
|
7407
7435
|
return n ? n.val : undefined
|
|
7408
7436
|
};
|
|
7409
7437
|
|
|
7438
|
+
/**
|
|
7439
|
+
* @template K, V
|
|
7440
|
+
*
|
|
7441
|
+
* @param {Cache<K, V>} cache
|
|
7442
|
+
* @param {K} key
|
|
7443
|
+
*/
|
|
7444
|
+
const remove = (cache, key) => {
|
|
7445
|
+
const n = cache._map.get(key);
|
|
7446
|
+
if (n) {
|
|
7447
|
+
removeNode(cache._q, n);
|
|
7448
|
+
cache._map.delete(key);
|
|
7449
|
+
return n.val && !(n.val instanceof Promise) ? n.val : undefined
|
|
7450
|
+
}
|
|
7451
|
+
};
|
|
7452
|
+
|
|
7410
7453
|
/**
|
|
7411
7454
|
* @template K, V
|
|
7412
7455
|
*
|
|
7413
7456
|
* @param {Cache<K, V>} cache
|
|
7414
7457
|
* @param {K} key
|
|
7415
7458
|
* @param {function():Promise<V>} init
|
|
7459
|
+
* @param {boolean} removeNull Optional argument that automatically removes values that resolve to null/undefined from the cache.
|
|
7416
7460
|
* @return {Promise<V> | V}
|
|
7417
7461
|
*/
|
|
7418
|
-
const setIfUndefined = (cache, key, init) => {
|
|
7419
|
-
|
|
7462
|
+
const setIfUndefined = (cache, key, init, removeNull = false) => {
|
|
7463
|
+
removeStale(cache);
|
|
7420
7464
|
const q = cache._q;
|
|
7421
7465
|
const n = cache._map.get(key);
|
|
7422
7466
|
if (n) {
|
|
7423
|
-
removeNode(q, n);
|
|
7424
|
-
pushEnd(q, n);
|
|
7425
|
-
n.created = now;
|
|
7426
7467
|
return n.val
|
|
7427
7468
|
} else {
|
|
7428
7469
|
const p = init();
|
|
@@ -7433,6 +7474,9 @@
|
|
|
7433
7474
|
if (p === node.val) {
|
|
7434
7475
|
node.val = v;
|
|
7435
7476
|
}
|
|
7477
|
+
if (removeNull && v == null) {
|
|
7478
|
+
remove(cache, key);
|
|
7479
|
+
}
|
|
7436
7480
|
});
|
|
7437
7481
|
return p
|
|
7438
7482
|
}
|
|
@@ -7476,11 +7520,13 @@
|
|
|
7476
7520
|
|
|
7477
7521
|
// write new values and check later if the creation-timestamp was updated
|
|
7478
7522
|
set(c, 'a', '11');
|
|
7479
|
-
|
|
7523
|
+
set(c, 'b', '22');
|
|
7480
7524
|
|
|
7481
7525
|
await wait(5); // keys should be updated and not timed out. Hence the creation time should be updated
|
|
7482
7526
|
assert(get(c, 'a') === '11');
|
|
7483
|
-
assert(get(c, 'b') === '
|
|
7527
|
+
assert(get(c, 'b') === '22');
|
|
7528
|
+
set(c, 'a', '11');
|
|
7529
|
+
set(c, 'b', '22');
|
|
7484
7530
|
// timestamps should be updated
|
|
7485
7531
|
assert(aTimestamp1 !== m.get('a').created);
|
|
7486
7532
|
assert(bTimestamp1 !== m.get('b').created);
|
|
@@ -7499,6 +7545,26 @@
|
|
|
7499
7545
|
await xp;
|
|
7500
7546
|
// we override the Entry.val property in cache when p resolves. However, we must prevent that when the value is overriden before p is resolved.
|
|
7501
7547
|
assert(get(c, 'a') === 'y');
|
|
7548
|
+
|
|
7549
|
+
// test that we can remove properties
|
|
7550
|
+
remove(c, 'a');
|
|
7551
|
+
remove(c, 'does not exist'); // remove a non-existent property to achieve full test-coverage
|
|
7552
|
+
assert(get(c, 'a') === undefined);
|
|
7553
|
+
|
|
7554
|
+
// test that the optional property in setifUndefined works
|
|
7555
|
+
const yp = setIfUndefined(c, 'a', () => resolveWith(null), true);
|
|
7556
|
+
assert(await yp === null);
|
|
7557
|
+
assert(get(c, 'a') === undefined);
|
|
7558
|
+
|
|
7559
|
+
// check manual updating of timeout
|
|
7560
|
+
set(c, 'a', '3');
|
|
7561
|
+
const ts1 = m.get('a').created;
|
|
7562
|
+
await wait(30);
|
|
7563
|
+
refreshTimeout(c, 'a');
|
|
7564
|
+
const ts2 = m.get('a').created;
|
|
7565
|
+
assert(ts1 !== ts2);
|
|
7566
|
+
refreshTimeout(c, 'x'); // for full test coverage
|
|
7567
|
+
assert(m.get('x') == null);
|
|
7502
7568
|
};
|
|
7503
7569
|
|
|
7504
7570
|
var cache = /*#__PURE__*/Object.freeze({
|