lib0 0.2.45 → 0.2.48

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 (79) hide show
  1. package/README.md +2 -0
  2. package/array.d.ts +1 -0
  3. package/array.d.ts.map +1 -1
  4. package/array.js +2 -0
  5. package/array.test.d.ts +1 -0
  6. package/array.test.d.ts.map +1 -1
  7. package/cache.d.ts +1 -0
  8. package/cache.d.ts.map +1 -1
  9. package/cache.js +19 -9
  10. package/cache.test.d.ts.map +1 -1
  11. package/dist/{array-b2d24238.cjs → array-acefe0f2.cjs} +6 -2
  12. package/dist/{array-b2d24238.cjs.map → array-acefe0f2.cjs.map} +1 -1
  13. package/dist/array.cjs +2 -1
  14. package/dist/array.cjs.map +1 -1
  15. package/dist/array.d.ts +1 -0
  16. package/dist/array.d.ts.map +1 -1
  17. package/dist/array.test.d.ts +1 -0
  18. package/dist/array.test.d.ts.map +1 -1
  19. package/dist/{broadcastchannel-7da37795.cjs → broadcastchannel-f22849e9.cjs} +2 -2
  20. package/dist/{broadcastchannel-7da37795.cjs.map → broadcastchannel-f22849e9.cjs.map} +1 -1
  21. package/dist/broadcastchannel.cjs +2 -2
  22. package/dist/{buffer-b0dea3b0.cjs → buffer-f5603fd0.cjs} +2 -2
  23. package/dist/buffer-f5603fd0.cjs.map +1 -0
  24. package/dist/buffer.cjs +1 -1
  25. package/dist/cache.cjs +20 -9
  26. package/dist/cache.cjs.map +1 -1
  27. package/dist/cache.d.ts +1 -0
  28. package/dist/cache.d.ts.map +1 -1
  29. package/dist/cache.test.d.ts.map +1 -1
  30. package/dist/component.cjs +3 -3
  31. package/dist/decoding.cjs +1 -1
  32. package/dist/{diff-233747fa.cjs → diff-2593547b.cjs} +2 -2
  33. package/dist/{diff-233747fa.cjs.map → diff-2593547b.cjs.map} +1 -1
  34. package/dist/diff.cjs +3 -3
  35. package/dist/encoding.cjs +1 -1
  36. package/dist/encoding.test.d.ts +1 -0
  37. package/dist/encoding.test.d.ts.map +1 -1
  38. package/dist/{function-f8acb5f5.cjs → function-e4045b1d.cjs} +2 -2
  39. package/dist/{function-f8acb5f5.cjs.map → function-e4045b1d.cjs.map} +1 -1
  40. package/dist/function.cjs +2 -2
  41. package/dist/index.cjs +10 -10
  42. package/dist/{iterator-fe01d209.cjs → iterator-9fc627c1.cjs} +1 -4
  43. package/dist/iterator-9fc627c1.cjs.map +1 -0
  44. package/dist/iterator.cjs +1 -1
  45. package/dist/iterator.d.ts.map +1 -1
  46. package/dist/{logging-f6d41f58.cjs → logging-0a4d8595.cjs} +2 -2
  47. package/dist/{logging-f6d41f58.cjs.map → logging-0a4d8595.cjs.map} +1 -1
  48. package/dist/logging.cjs +3 -3
  49. package/dist/metric.d.ts.map +1 -1
  50. package/dist/observable.cjs +1 -1
  51. package/dist/{prng-25602bac.cjs → prng-69dc1664.cjs} +2 -2
  52. package/dist/{prng-25602bac.cjs.map → prng-69dc1664.cjs.map} +1 -1
  53. package/dist/prng.cjs +2 -2
  54. package/dist/test.cjs +64 -14
  55. package/dist/test.cjs.map +1 -1
  56. package/dist/test.js +64 -14
  57. package/dist/test.js.map +1 -1
  58. package/dist/testing.cjs +6 -6
  59. package/dist/{tree-92f764b3.cjs → tree-b67c7947.cjs} +9 -2
  60. package/dist/tree-b67c7947.cjs.map +1 -0
  61. package/dist/tree.cjs +1 -1
  62. package/dist/tree.d.ts +13 -5
  63. package/dist/tree.d.ts.map +1 -1
  64. package/dist/{websocket-08bd4c7b.cjs → websocket-57086be8.cjs} +1 -1
  65. package/dist/{websocket-08bd4c7b.cjs.map → websocket-57086be8.cjs.map} +1 -1
  66. package/dist/websocket.cjs +2 -2
  67. package/encoding.js +1 -1
  68. package/encoding.test.d.ts +1 -0
  69. package/encoding.test.d.ts.map +1 -1
  70. package/iterator.d.ts.map +1 -1
  71. package/iterator.js +0 -3
  72. package/metric.d.ts.map +1 -1
  73. package/package.json +1 -1
  74. package/tree.d.ts +13 -5
  75. package/tree.d.ts.map +1 -1
  76. package/tree.js +8 -1
  77. package/dist/buffer-b0dea3b0.cjs.map +0 -1
  78. package/dist/iterator-fe01d209.cjs.map +0 -1
  79. package/dist/tree-92f764b3.cjs.map +0 -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
  *
@@ -2347,7 +2349,7 @@
2347
2349
  writeVarString(encoder, data);
2348
2350
  break
2349
2351
  case 'number':
2350
- if (isInteger(data) && data <= BITS31) {
2352
+ if (isInteger(data) && abs(data) <= BITS31) {
2351
2353
  // TYPE 125: INTEGER
2352
2354
  write(encoder, 125);
2353
2355
  writeVarInt(encoder, data);
@@ -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 = () => {
@@ -5072,6 +5087,18 @@
5072
5087
  }
5073
5088
  };
5074
5089
 
5090
+ /**
5091
+ * @param {t.TestCase} tc
5092
+ */
5093
+ const testLargeNumberAnyEncoding = tc => {
5094
+ const encoder = createEncoder();
5095
+ const num = -2.2062063918362897e+50;
5096
+ writeAny(encoder, num);
5097
+ const decoder = createDecoder(toUint8Array(encoder));
5098
+ const readNum = readAny(decoder);
5099
+ assert(readNum === num);
5100
+ };
5101
+
5075
5102
  var encoding = /*#__PURE__*/Object.freeze({
5076
5103
  __proto__: null,
5077
5104
  testGolangBinaryEncodingCompatibility: testGolangBinaryEncodingCompatibility,
@@ -5102,7 +5129,8 @@
5102
5129
  testIntDiffRleEncoder: testIntDiffRleEncoder,
5103
5130
  testIntEncoders: testIntEncoders,
5104
5131
  testIntDiffEncoder: testIntDiffEncoder,
5105
- testStringDecoder: testStringDecoder
5132
+ testStringDecoder: testStringDecoder,
5133
+ testLargeNumberAnyEncoding: testLargeNumberAnyEncoding
5106
5134
  });
5107
5135
 
5108
5136
  /**
@@ -7369,13 +7397,9 @@
7369
7397
  * @return {Entry<K, V> | undefined}
7370
7398
  */
7371
7399
  const getNode = (cache, key) => {
7372
- const now = removeStale(cache);
7373
- const q = cache._q;
7400
+ removeStale(cache);
7374
7401
  const n = cache._map.get(key);
7375
7402
  if (n) {
7376
- removeNode(q, n);
7377
- pushEnd(q, n);
7378
- n.created = now;
7379
7403
  return n
7380
7404
  }
7381
7405
  };
@@ -7392,6 +7416,23 @@
7392
7416
  return n && !(n.val instanceof Promise) ? n.val : undefined
7393
7417
  };
7394
7418
 
7419
+ /**
7420
+ * @template K, V
7421
+ *
7422
+ * @param {Cache<K, V>} cache
7423
+ * @param {K} key
7424
+ */
7425
+ const refreshTimeout = (cache, key) => {
7426
+ const now = getUnixTime();
7427
+ const q = cache._q;
7428
+ const n = cache._map.get(key);
7429
+ if (n) {
7430
+ removeNode(q, n);
7431
+ pushEnd(q, n);
7432
+ n.created = now;
7433
+ }
7434
+ };
7435
+
7395
7436
  /**
7396
7437
  * Works well in conjunktion with setIfUndefined which has an async init function.
7397
7438
  * Using getAsync & setIfUndefined ensures that the init function is only called once.
@@ -7432,13 +7473,10 @@
7432
7473
  * @return {Promise<V> | V}
7433
7474
  */
7434
7475
  const setIfUndefined = (cache, key, init, removeNull = false) => {
7435
- const now = removeStale(cache);
7476
+ removeStale(cache);
7436
7477
  const q = cache._q;
7437
7478
  const n = cache._map.get(key);
7438
7479
  if (n) {
7439
- removeNode(q, n);
7440
- pushEnd(q, n);
7441
- n.created = now;
7442
7480
  return n.val
7443
7481
  } else {
7444
7482
  const p = init();
@@ -7495,11 +7533,13 @@
7495
7533
 
7496
7534
  // write new values and check later if the creation-timestamp was updated
7497
7535
  set(c, 'a', '11');
7498
- await setIfUndefined(c, 'b', () => resolveWith('22')); // this shouldn't override, but update the timestamp
7536
+ set(c, 'b', '22');
7499
7537
 
7500
7538
  await wait(5); // keys should be updated and not timed out. Hence the creation time should be updated
7501
7539
  assert(get(c, 'a') === '11');
7502
- assert(get(c, 'b') === '2');
7540
+ assert(get(c, 'b') === '22');
7541
+ set(c, 'a', '11');
7542
+ set(c, 'b', '22');
7503
7543
  // timestamps should be updated
7504
7544
  assert(aTimestamp1 !== m.get('a').created);
7505
7545
  assert(bTimestamp1 !== m.get('b').created);
@@ -7528,6 +7568,16 @@
7528
7568
  const yp = setIfUndefined(c, 'a', () => resolveWith(null), true);
7529
7569
  assert(await yp === null);
7530
7570
  assert(get(c, 'a') === undefined);
7571
+
7572
+ // check manual updating of timeout
7573
+ set(c, 'a', '3');
7574
+ const ts1 = m.get('a').created;
7575
+ await wait(30);
7576
+ refreshTimeout(c, 'a');
7577
+ const ts2 = m.get('a').created;
7578
+ assert(ts1 !== ts2);
7579
+ refreshTimeout(c, 'x'); // for full test coverage
7580
+ assert(m.get('x') == null);
7531
7581
  };
7532
7582
 
7533
7583
  var cache = /*#__PURE__*/Object.freeze({