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