mol_vary 0.0.39 → 0.0.41
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.d.ts +2 -1
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +25 -13
- package/node.js.map +1 -1
- package/node.mjs +25 -13
- package/node.test.js +28 -16
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +2 -1
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +25 -13
- package/web.js.map +1 -1
- package/web.mjs +25 -13
- package/web.test.js +3 -3
- package/web.test.js.map +1 -1
package/node.mjs
CHANGED
|
@@ -2711,17 +2711,16 @@ var $;
|
|
|
2711
2711
|
const vals = new Array(len);
|
|
2712
2712
|
for (let i = 0; i < len; ++i)
|
|
2713
2713
|
vals[i] = read_vary();
|
|
2714
|
-
const
|
|
2715
|
-
let
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
}
|
|
2714
|
+
const node = this.rich_node(keys);
|
|
2715
|
+
let rich = node.get(null);
|
|
2716
|
+
if (!rich)
|
|
2717
|
+
node.set(null, rich = (...vals) => {
|
|
2718
|
+
const obj = {};
|
|
2719
|
+
for (let i = 0; i < len; ++i)
|
|
2720
|
+
obj[keys[i]] = vals[i];
|
|
2721
|
+
return obj;
|
|
2722
|
+
});
|
|
2723
|
+
const obj = rich(...vals);
|
|
2725
2724
|
stream.push(obj);
|
|
2726
2725
|
return obj;
|
|
2727
2726
|
};
|
|
@@ -2781,9 +2780,22 @@ var $;
|
|
|
2781
2780
|
$mol_fail(new Error('Buffer too large', { cause: { size: buffer.byteLength, taken: pos, result } }));
|
|
2782
2781
|
return result;
|
|
2783
2782
|
}
|
|
2784
|
-
static
|
|
2783
|
+
static rich_index = new Map([
|
|
2784
|
+
[null, () => ({})]
|
|
2785
|
+
]);
|
|
2786
|
+
static rich_node(keys) {
|
|
2787
|
+
let node = this.rich_index;
|
|
2788
|
+
for (const key of keys) {
|
|
2789
|
+
let sub = node.get(key);
|
|
2790
|
+
if (sub)
|
|
2791
|
+
node = sub;
|
|
2792
|
+
else
|
|
2793
|
+
node.set(key, node = new Map);
|
|
2794
|
+
}
|
|
2795
|
+
return node;
|
|
2796
|
+
}
|
|
2785
2797
|
static type(Class, keys, lean, rich) {
|
|
2786
|
-
this.
|
|
2798
|
+
this.rich_node(keys).set(null, rich);
|
|
2787
2799
|
Class.prototype[$.$mol_vary_lean] = (val) => [keys, lean(val)];
|
|
2788
2800
|
}
|
|
2789
2801
|
}
|
package/node.test.js
CHANGED
|
@@ -2702,17 +2702,16 @@ var $;
|
|
|
2702
2702
|
const vals = new Array(len);
|
|
2703
2703
|
for (let i = 0; i < len; ++i)
|
|
2704
2704
|
vals[i] = read_vary();
|
|
2705
|
-
const
|
|
2706
|
-
let
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
}
|
|
2705
|
+
const node = this.rich_node(keys);
|
|
2706
|
+
let rich = node.get(null);
|
|
2707
|
+
if (!rich)
|
|
2708
|
+
node.set(null, rich = (...vals) => {
|
|
2709
|
+
const obj = {};
|
|
2710
|
+
for (let i = 0; i < len; ++i)
|
|
2711
|
+
obj[keys[i]] = vals[i];
|
|
2712
|
+
return obj;
|
|
2713
|
+
});
|
|
2714
|
+
const obj = rich(...vals);
|
|
2716
2715
|
stream.push(obj);
|
|
2717
2716
|
return obj;
|
|
2718
2717
|
};
|
|
@@ -2772,9 +2771,22 @@ var $;
|
|
|
2772
2771
|
$mol_fail(new Error('Buffer too large', { cause: { size: buffer.byteLength, taken: pos, result } }));
|
|
2773
2772
|
return result;
|
|
2774
2773
|
}
|
|
2775
|
-
static
|
|
2774
|
+
static rich_index = new Map([
|
|
2775
|
+
[null, () => ({})]
|
|
2776
|
+
]);
|
|
2777
|
+
static rich_node(keys) {
|
|
2778
|
+
let node = this.rich_index;
|
|
2779
|
+
for (const key of keys) {
|
|
2780
|
+
let sub = node.get(key);
|
|
2781
|
+
if (sub)
|
|
2782
|
+
node = sub;
|
|
2783
|
+
else
|
|
2784
|
+
node.set(key, node = new Map);
|
|
2785
|
+
}
|
|
2786
|
+
return node;
|
|
2787
|
+
}
|
|
2776
2788
|
static type(Class, keys, lean, rich) {
|
|
2777
|
-
this.
|
|
2789
|
+
this.rich_node(keys).set(null, rich);
|
|
2778
2790
|
Class.prototype[$.$mol_vary_lean] = (val) => [keys, lean(val)];
|
|
2779
2791
|
}
|
|
2780
2792
|
}
|
|
@@ -4987,7 +4999,7 @@ var $;
|
|
|
4987
4999
|
check([part, part], [list | 2, blob | 2, uint | L1, 1, 2, link | 0]);
|
|
4988
5000
|
},
|
|
4989
5001
|
"vary pack struct"($) {
|
|
4990
|
-
check({
|
|
5002
|
+
check({ x: 1, y: 2 }, [tupl | 2, list | 2, text | 1, ...str('x'), text | 1, ...str('y'), 1, 2]);
|
|
4991
5003
|
check({ x: {}, y: { a: 1 } }, [tupl | 2, list | 2, text | 1, ...str('x'), text | 1, ...str('y'), tupl | 0, list | 0, tupl | 1, list | 1, text | 1, ...str('a'), 1]);
|
|
4992
5004
|
},
|
|
4993
5005
|
"vary pack struct shape dedup"($) {
|
|
@@ -5067,8 +5079,8 @@ var $;
|
|
|
5067
5079
|
return [this.a, this.b].values();
|
|
5068
5080
|
}
|
|
5069
5081
|
}
|
|
5070
|
-
$mol_vary.type(Foo, ['
|
|
5071
|
-
check(new Foo(1, 2), [tupl | 2, list | 2, text |
|
|
5082
|
+
$mol_vary.type(Foo, ['custom_a', 'custom_b'], foo => [foo.a, foo.b], (a = 0, b = 0) => new Foo(a, b));
|
|
5083
|
+
check(new Foo(1, 2), [tupl | 2, list | 2, text | 8, ...str('custom_a'), text | 8, ...str('custom_b'), 1, 2]);
|
|
5072
5084
|
},
|
|
5073
5085
|
});
|
|
5074
5086
|
})($$ = $_1.$$ || ($_1.$$ = {}));
|