mol_vary 0.0.49 → 0.0.50

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/node.mjs CHANGED
@@ -2622,7 +2622,12 @@ var $;
2622
2622
  }
2623
2623
  $mol_fail(new Error(`Unsupported type`));
2624
2624
  };
2625
- dump(data);
2625
+ for (const item of data) {
2626
+ dump(item);
2627
+ if (stack.length)
2628
+ $mol_fail(new Error('Stack underflow', { cause: { stack, item } }));
2629
+ offsets.clear();
2630
+ }
2626
2631
  if (pos !== capacity)
2627
2632
  $mol_fail(new Error('Wrong reserved capacity', { cause: { capacity, size: pos, data } }));
2628
2633
  return this.array.slice(0, pos);
@@ -2805,9 +2810,9 @@ var $;
2805
2810
  default: $mol_fail(new Error('Unsupported tip', { cause: { tip } }));
2806
2811
  }
2807
2812
  };
2808
- const result = read_vary();
2809
- if (pos !== array.byteLength)
2810
- $mol_fail(new Error('Buffer too large', { cause: { size: array.byteLength, taken: pos, result } }));
2813
+ const result = [];
2814
+ while (pos < array.byteLength)
2815
+ result.push(read_vary());
2811
2816
  return result;
2812
2817
  }
2813
2818
  rich_index = new Map([
package/node.test.js CHANGED
@@ -2613,7 +2613,12 @@ var $;
2613
2613
  }
2614
2614
  $mol_fail(new Error(`Unsupported type`));
2615
2615
  };
2616
- dump(data);
2616
+ for (const item of data) {
2617
+ dump(item);
2618
+ if (stack.length)
2619
+ $mol_fail(new Error('Stack underflow', { cause: { stack, item } }));
2620
+ offsets.clear();
2621
+ }
2617
2622
  if (pos !== capacity)
2618
2623
  $mol_fail(new Error('Wrong reserved capacity', { cause: { capacity, size: pos, data } }));
2619
2624
  return this.array.slice(0, pos);
@@ -2796,9 +2801,9 @@ var $;
2796
2801
  default: $mol_fail(new Error('Unsupported tip', { cause: { tip } }));
2797
2802
  }
2798
2803
  };
2799
- const result = read_vary();
2800
- if (pos !== array.byteLength)
2801
- $mol_fail(new Error('Buffer too large', { cause: { size: array.byteLength, taken: pos, result } }));
2804
+ const result = [];
2805
+ while (pos < array.byteLength)
2806
+ result.push(read_vary());
2802
2807
  return result;
2803
2808
  }
2804
2809
  rich_index = new Map([
@@ -4928,8 +4933,8 @@ var $;
4928
4933
  const { L1, L2, L4, L8, LA } = $mol_vary_len;
4929
4934
  const str = $mol_charset_encode;
4930
4935
  function check(vary, ideal, Vary = $mol_vary) {
4931
- const pack = Vary.pack(vary);
4932
- $mol_assert_equal(Vary.take(pack), vary);
4936
+ const pack = Vary.pack([vary]);
4937
+ $mol_assert_equal(Vary.take(pack), [vary]);
4933
4938
  $mol_assert_equal(pack, new Uint8Array(ideal));
4934
4939
  }
4935
4940
  $mol_test({
@@ -4961,8 +4966,9 @@ var $;
4961
4966
  check(256n ** 8n - 1n, [uint | L8, 255, 255, 255, 255, 255, 255, 255, 255]);
4962
4967
  },
4963
4968
  "vary pack with wrong size"($) {
4964
- $mol_assert_fail(() => $mol_vary.take(new Uint8Array([uint | L1])), Error);
4965
- $mol_assert_fail(() => $mol_vary.take(new Uint8Array([uint | L1, 200, 300])), 'Buffer too large');
4969
+ $mol_assert_equal($mol_vary.take(new Uint8Array([])), []);
4970
+ $mol_assert_equal($mol_vary.take(new Uint8Array([uint | 7])), [7]);
4971
+ $mol_assert_equal($mol_vary.take(new Uint8Array([uint | 7, uint | 7])), [7, 7]);
4966
4972
  },
4967
4973
  "vary pack sint0"($) {
4968
4974
  check(-1, [-1]);
@@ -5056,7 +5062,7 @@ var $;
5056
5062
  "vary pack cyclic struct"($) {
5057
5063
  const foo = { bar: null };
5058
5064
  foo.bar = foo;
5059
- $mol_assert_fail(() => $mol_vary.pack(foo), 'Cyclic refs');
5065
+ $mol_assert_fail(() => $mol_vary.pack([foo]), 'Cyclic refs');
5060
5066
  },
5061
5067
  "vary pack Map"($) {
5062
5068
  check(new Map([['foo', 1], [2, 'bar']]), [tupl | 2, list | 2, text | 4, ...str('keys'), text | 4, ...str('vals'), list | 2, text | 3, ...str('foo'), 2, list | 2, 1, text | 3, ...str('bar')]);
@@ -5074,10 +5080,10 @@ var $;
5074
5080
  $mol_assert_equal($mol_dom_serialize($mol_jsx("div", null,
5075
5081
  $mol_jsx("span", null),
5076
5082
  $mol_jsx("br", null),
5077
- " ")), $mol_dom_serialize($mol_vary.take($mol_vary.pack($mol_jsx("div", null,
5078
- $mol_jsx("span", null),
5079
- $mol_jsx("br", null),
5080
- " ")))));
5083
+ " ")), $mol_dom_serialize($mol_vary.take($mol_vary.pack([$mol_jsx("div", null,
5084
+ $mol_jsx("span", null),
5085
+ $mol_jsx("br", null),
5086
+ " ")]))[0]));
5081
5087
  },
5082
5088
  "vary pack custom types in rooms"($) {
5083
5089
  class Foo {
@@ -5100,8 +5106,8 @@ var $;
5100
5106
  rich: ([summ, diff]) => new Foo((summ + diff) / 2, (summ - diff) / 2),
5101
5107
  });
5102
5108
  check(new Foo(4, 2), [tupl | 2, list | 2, text | 4, ...str('summ'), text | 4, ...str('diff'), 6, 2], Vary);
5103
- $mol_assert_equal($mol_vary.take($mol_vary.pack(new Foo(4, 2))), { a: 4, b: 2 });
5104
- $mol_assert_equal(Vary.take(Vary.pack(new Map([[1, 2]]))), new Map([[1, 2]]));
5109
+ $mol_assert_equal($mol_vary.take($mol_vary.pack([new Foo(4, 2)])), [{ a: 4, b: 2 }]);
5110
+ $mol_assert_equal(Vary.take(Vary.pack([new Map([[1, 2]])])), [new Map([[1, 2]])]);
5105
5111
  },
5106
5112
  });
5107
5113
  })($$ = $_1.$$ || ($_1.$$ = {}));