msgpackr 1.8.1 → 1.8.2
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/dist/index-no-eval.cjs +7 -8
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +21 -11
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +21 -11
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +1 -1
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.d.cts +73 -0
- package/pack.js +6 -7
- package/package.json +3 -2
- package/struct.js +15 -4
- package/unpack.js +1 -1
package/dist/node.cjs
CHANGED
|
@@ -120,7 +120,7 @@ class Unpackr {
|
|
|
120
120
|
let size = source.length;
|
|
121
121
|
let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
|
|
122
122
|
if (forEach) {
|
|
123
|
-
forEach(value);
|
|
123
|
+
if (forEach(value) === false) return;
|
|
124
124
|
while(position$1 < size) {
|
|
125
125
|
lastPosition = position$1;
|
|
126
126
|
if (forEach(checkedRead()) === false) {
|
|
@@ -1173,7 +1173,7 @@ class Packr extends Unpackr {
|
|
|
1173
1173
|
if (maxSharedStructures > 8160)
|
|
1174
1174
|
throw new Error('Maximum maxSharedStructure is 8160')
|
|
1175
1175
|
if (options.structuredClone && options.moreTypes == undefined) {
|
|
1176
|
-
|
|
1176
|
+
this.moreTypes = true;
|
|
1177
1177
|
}
|
|
1178
1178
|
let maxOwnStructures = options.maxOwnStructures;
|
|
1179
1179
|
if (maxOwnStructures == null)
|
|
@@ -1868,12 +1868,11 @@ class Packr extends Unpackr {
|
|
|
1868
1868
|
if (notifySharedUpdate)
|
|
1869
1869
|
return hasSharedUpdate = true;
|
|
1870
1870
|
position = newPosition;
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
}
|
|
1876
|
-
pack(value);
|
|
1871
|
+
let startTarget = target;
|
|
1872
|
+
pack(value);
|
|
1873
|
+
if (startTarget !== target) {
|
|
1874
|
+
return { position, targetView, target }; // indicate the buffer was re-allocated
|
|
1875
|
+
}
|
|
1877
1876
|
return position;
|
|
1878
1877
|
}, this);
|
|
1879
1878
|
if (newPosition === 0) // bail and go to a msgpack object
|
|
@@ -2793,24 +2792,35 @@ function readStruct(src, position, srcEnd, unpackr) {
|
|
|
2793
2792
|
let objectLiteralProperties = [];
|
|
2794
2793
|
let args = [];
|
|
2795
2794
|
let i = 0;
|
|
2795
|
+
let hasInheritedProperties;
|
|
2796
2796
|
for (let property of properties) { // assign in enumeration order
|
|
2797
|
+
if (unpackr.alwaysLazyProperty && unpackr.alwaysLazyProperty(property.key)) {
|
|
2798
|
+
// these properties are not eagerly evaluated and this can be used for creating properties
|
|
2799
|
+
// that are not serialized as JSON
|
|
2800
|
+
hasInheritedProperties = true;
|
|
2801
|
+
continue;
|
|
2802
|
+
}
|
|
2797
2803
|
Object.defineProperty(prototype, property.key, { get: withSource(property.get), enumerable: true });
|
|
2798
2804
|
let valueFunction = 'v' + i++;
|
|
2799
2805
|
args.push(valueFunction);
|
|
2800
2806
|
objectLiteralProperties.push('[' + JSON.stringify(property.key) + ']:' + valueFunction + '(s)');
|
|
2801
2807
|
}
|
|
2808
|
+
if (hasInheritedProperties) {
|
|
2809
|
+
objectLiteralProperties.push('__proto__:this');
|
|
2810
|
+
}
|
|
2802
2811
|
let toObject = (new Function(...args, 'return function(s){return{' + objectLiteralProperties.join(',') + '}}')).apply(null, properties.map(prop => prop.get));
|
|
2803
2812
|
Object.defineProperty(prototype, 'toJSON', {
|
|
2804
|
-
value() {
|
|
2805
|
-
return toObject(this[sourceSymbol]);
|
|
2813
|
+
value(omitUnderscoredProperties) {
|
|
2814
|
+
return toObject.call(this, this[sourceSymbol]);
|
|
2806
2815
|
}
|
|
2807
2816
|
});
|
|
2808
2817
|
} else {
|
|
2809
2818
|
Object.defineProperty(prototype, 'toJSON', {
|
|
2810
|
-
value() {
|
|
2819
|
+
value(omitUnderscoredProperties) {
|
|
2811
2820
|
// return an enumerable object with own properties to JSON stringify
|
|
2812
2821
|
let resolved = {};
|
|
2813
2822
|
for (let i = 0, l = properties.length; i < l; i++) {
|
|
2823
|
+
// TODO: check alwaysLazyProperty
|
|
2814
2824
|
let key = properties[i].key;
|
|
2815
2825
|
|
|
2816
2826
|
resolved[key] = this[key];
|