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.cjs CHANGED
@@ -863,6 +863,8 @@ const equalFlat$1 = (a, b) => a.length === b.length && every$1(a, (item, index)
863
863
  */
864
864
  const flatten = arr => arr.reduce((acc, val) => acc.concat(val), []);
865
865
 
866
+ const isArray = Array.isArray;
867
+
866
868
  /**
867
869
  * Utility functions for working with EcmaScript objects.
868
870
  *
@@ -2322,7 +2324,7 @@ const writeAny = (encoder, data) => {
2322
2324
  writeVarString(encoder, data);
2323
2325
  break
2324
2326
  case 'number':
2325
- if (isInteger(data) && data <= BITS31) {
2327
+ if (isInteger(data) && abs(data) <= BITS31) {
2326
2328
  // TYPE 125: INTEGER
2327
2329
  write(encoder, 125);
2328
2330
  writeVarInt(encoder, data);
@@ -4279,10 +4281,23 @@ const testflatten = tc => {
4279
4281
  compareArrays(flatten(arr), [1, 2, 3, 4]);
4280
4282
  };
4281
4283
 
4284
+ /**
4285
+ * @param {t.TestCase} tc
4286
+ */
4287
+ const testIsArray = tc => {
4288
+ assert(isArray([]));
4289
+ assert(isArray([1]));
4290
+ assert(isArray(Array.from(new Set([3]))));
4291
+ assert(!isArray(1));
4292
+ assert(!isArray(0));
4293
+ assert(!isArray(''));
4294
+ };
4295
+
4282
4296
  var array = /*#__PURE__*/Object.freeze({
4283
4297
  __proto__: null,
4284
4298
  testAppend: testAppend,
4285
- testflatten: testflatten
4299
+ testflatten: testflatten,
4300
+ testIsArray: testIsArray
4286
4301
  });
4287
4302
 
4288
4303
  const testLogging = () => {
@@ -5047,6 +5062,18 @@ const testStringDecoder = tc => {
5047
5062
  }
5048
5063
  };
5049
5064
 
5065
+ /**
5066
+ * @param {t.TestCase} tc
5067
+ */
5068
+ const testLargeNumberAnyEncoding = tc => {
5069
+ const encoder = createEncoder();
5070
+ const num = -2.2062063918362897e+50;
5071
+ writeAny(encoder, num);
5072
+ const decoder = createDecoder(toUint8Array(encoder));
5073
+ const readNum = readAny(decoder);
5074
+ assert(readNum === num);
5075
+ };
5076
+
5050
5077
  var encoding = /*#__PURE__*/Object.freeze({
5051
5078
  __proto__: null,
5052
5079
  testGolangBinaryEncodingCompatibility: testGolangBinaryEncodingCompatibility,
@@ -5077,7 +5104,8 @@ var encoding = /*#__PURE__*/Object.freeze({
5077
5104
  testIntDiffRleEncoder: testIntDiffRleEncoder,
5078
5105
  testIntEncoders: testIntEncoders,
5079
5106
  testIntDiffEncoder: testIntDiffEncoder,
5080
- testStringDecoder: testStringDecoder
5107
+ testStringDecoder: testStringDecoder,
5108
+ testLargeNumberAnyEncoding: testLargeNumberAnyEncoding
5081
5109
  });
5082
5110
 
5083
5111
  /**
@@ -7344,13 +7372,9 @@ const set = (cache, key, value) => {
7344
7372
  * @return {Entry<K, V> | undefined}
7345
7373
  */
7346
7374
  const getNode = (cache, key) => {
7347
- const now = removeStale(cache);
7348
- const q = cache._q;
7375
+ removeStale(cache);
7349
7376
  const n = cache._map.get(key);
7350
7377
  if (n) {
7351
- removeNode(q, n);
7352
- pushEnd(q, n);
7353
- n.created = now;
7354
7378
  return n
7355
7379
  }
7356
7380
  };
@@ -7367,6 +7391,23 @@ const get = (cache, key) => {
7367
7391
  return n && !(n.val instanceof Promise) ? n.val : undefined
7368
7392
  };
7369
7393
 
7394
+ /**
7395
+ * @template K, V
7396
+ *
7397
+ * @param {Cache<K, V>} cache
7398
+ * @param {K} key
7399
+ */
7400
+ const refreshTimeout = (cache, key) => {
7401
+ const now = getUnixTime();
7402
+ const q = cache._q;
7403
+ const n = cache._map.get(key);
7404
+ if (n) {
7405
+ removeNode(q, n);
7406
+ pushEnd(q, n);
7407
+ n.created = now;
7408
+ }
7409
+ };
7410
+
7370
7411
  /**
7371
7412
  * Works well in conjunktion with setIfUndefined which has an async init function.
7372
7413
  * Using getAsync & setIfUndefined ensures that the init function is only called once.
@@ -7407,13 +7448,10 @@ const remove = (cache, key) => {
7407
7448
  * @return {Promise<V> | V}
7408
7449
  */
7409
7450
  const setIfUndefined = (cache, key, init, removeNull = false) => {
7410
- const now = removeStale(cache);
7451
+ removeStale(cache);
7411
7452
  const q = cache._q;
7412
7453
  const n = cache._map.get(key);
7413
7454
  if (n) {
7414
- removeNode(q, n);
7415
- pushEnd(q, n);
7416
- n.created = now;
7417
7455
  return n.val
7418
7456
  } else {
7419
7457
  const p = init();
@@ -7470,11 +7508,13 @@ const testCache = async tc => {
7470
7508
 
7471
7509
  // write new values and check later if the creation-timestamp was updated
7472
7510
  set(c, 'a', '11');
7473
- await setIfUndefined(c, 'b', () => resolveWith('22')); // this shouldn't override, but update the timestamp
7511
+ set(c, 'b', '22');
7474
7512
 
7475
7513
  await wait(5); // keys should be updated and not timed out. Hence the creation time should be updated
7476
7514
  assert(get(c, 'a') === '11');
7477
- assert(get(c, 'b') === '2');
7515
+ assert(get(c, 'b') === '22');
7516
+ set(c, 'a', '11');
7517
+ set(c, 'b', '22');
7478
7518
  // timestamps should be updated
7479
7519
  assert(aTimestamp1 !== m.get('a').created);
7480
7520
  assert(bTimestamp1 !== m.get('b').created);
@@ -7503,6 +7543,16 @@ const testCache = async tc => {
7503
7543
  const yp = setIfUndefined(c, 'a', () => resolveWith(null), true);
7504
7544
  assert(await yp === null);
7505
7545
  assert(get(c, 'a') === undefined);
7546
+
7547
+ // check manual updating of timeout
7548
+ set(c, 'a', '3');
7549
+ const ts1 = m.get('a').created;
7550
+ await wait(30);
7551
+ refreshTimeout(c, 'a');
7552
+ const ts2 = m.get('a').created;
7553
+ assert(ts1 !== ts2);
7554
+ refreshTimeout(c, 'x'); // for full test coverage
7555
+ assert(m.get('x') == null);
7506
7556
  };
7507
7557
 
7508
7558
  var cache = /*#__PURE__*/Object.freeze({