msgpackr 1.9.1 → 1.9.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 +13 -1
- package/dist/index-no-eval.cjs +36 -12
- 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 +36 -12
- 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 +36 -12
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +134 -14
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +13 -5
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.d.cts +5 -5
- package/index.d.ts +5 -5
- package/pack.d.cts +1 -0
- package/pack.js +23 -7
- package/package.json +14 -6
- package/unpack.d.cts +2 -0
- package/unpack.js +13 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msgpackr",
|
|
3
3
|
"author": "Kris Zyp",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.3",
|
|
5
5
|
"description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "./index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"benchmark": "node ./tests/benchmark.cjs",
|
|
23
|
-
"build": "rollup -c && cpy index.d.ts . --rename=index.d.cts",
|
|
23
|
+
"build": "rollup -c && cpy index.d.ts . --rename=index.d.cts && cpy pack.d.ts . --rename=pack.d.cts && cpy unpack.d.ts . --rename=unpack.d.cts",
|
|
24
24
|
"dry-run": "npm publish --dry-run",
|
|
25
25
|
"prepare": "npm run build",
|
|
26
26
|
"test": "mocha tests/test**.*js -u tdd --experimental-json-modules"
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"type": "module",
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
|
+
"types": {
|
|
32
|
+
"require": "./index.d.cts",
|
|
33
|
+
"import": "./index.d.ts"
|
|
34
|
+
},
|
|
31
35
|
"node": {
|
|
32
36
|
"require": "./dist/node.cjs",
|
|
33
37
|
"import": "./node-index.js"
|
|
@@ -36,13 +40,13 @@
|
|
|
36
40
|
"require": "./dist/node.cjs",
|
|
37
41
|
"import": "./node-index.js"
|
|
38
42
|
},
|
|
39
|
-
"types": {
|
|
40
|
-
"require": "./index.d.cts",
|
|
41
|
-
"import": "./index.d.ts"
|
|
42
|
-
},
|
|
43
43
|
"default": "./index.js"
|
|
44
44
|
},
|
|
45
45
|
"./pack": {
|
|
46
|
+
"types": {
|
|
47
|
+
"require": "./pack.d.cts",
|
|
48
|
+
"import": "./pack.d.ts"
|
|
49
|
+
},
|
|
46
50
|
"node": {
|
|
47
51
|
"import": "./index.js",
|
|
48
52
|
"require": "./dist/node.cjs"
|
|
@@ -54,6 +58,10 @@
|
|
|
54
58
|
"default": "./pack.js"
|
|
55
59
|
},
|
|
56
60
|
"./unpack": {
|
|
61
|
+
"types": {
|
|
62
|
+
"require": "./unpack.d.cts",
|
|
63
|
+
"import": "./unpack.d.ts"
|
|
64
|
+
},
|
|
57
65
|
"node": {
|
|
58
66
|
"import": "./index.js",
|
|
59
67
|
"require": "./dist/node.cjs"
|
package/unpack.d.cts
ADDED
package/unpack.js
CHANGED
|
@@ -119,10 +119,10 @@ export class Unpackr {
|
|
|
119
119
|
let size = source.length
|
|
120
120
|
let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size)
|
|
121
121
|
if (forEach) {
|
|
122
|
-
if (forEach(value) === false) return;
|
|
122
|
+
if (forEach(value, lastPosition, position) === false) return;
|
|
123
123
|
while(position < size) {
|
|
124
124
|
lastPosition = position
|
|
125
|
-
if (forEach(checkedRead()) === false) {
|
|
125
|
+
if (forEach(checkedRead(), lastPosition, position) === false) {
|
|
126
126
|
return
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -199,6 +199,10 @@ export function checkedRead(options) {
|
|
|
199
199
|
position = bundledStrings.postBundlePosition
|
|
200
200
|
bundledStrings = null
|
|
201
201
|
}
|
|
202
|
+
if (sequentialMode)
|
|
203
|
+
// we only need to restore the structures if there was an error, but if we completed a read,
|
|
204
|
+
// we can clear this out and keep the structures we read
|
|
205
|
+
currentStructures.restoreStructures = null
|
|
202
206
|
|
|
203
207
|
if (position == srcEnd) {
|
|
204
208
|
// finished reading this source, cleanup references
|
|
@@ -971,7 +975,10 @@ const recordDefinition = (id, highByte) => {
|
|
|
971
975
|
structure.highByte = highByte
|
|
972
976
|
}
|
|
973
977
|
let existingStructure = currentStructures[id]
|
|
974
|
-
|
|
978
|
+
// If it is a shared structure, we need to restore any changes after reading.
|
|
979
|
+
// Also in sequential mode, we may get incomplete reads and thus errors, and we need to restore
|
|
980
|
+
// to the state prior to an incomplete read in order to properly resume.
|
|
981
|
+
if (existingStructure && (existingStructure.isShared || sequentialMode)) {
|
|
975
982
|
(currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure
|
|
976
983
|
}
|
|
977
984
|
currentStructures[id] = structure
|
|
@@ -981,10 +988,10 @@ const recordDefinition = (id, highByte) => {
|
|
|
981
988
|
currentExtensions[0] = () => {} // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
982
989
|
currentExtensions[0].noBuffer = true
|
|
983
990
|
|
|
984
|
-
let
|
|
991
|
+
let errors = { Error, TypeError, ReferenceError };
|
|
985
992
|
currentExtensions[0x65] = () => {
|
|
986
993
|
let data = read()
|
|
987
|
-
return (
|
|
994
|
+
return (errors[data[0]] || Error)(data[1])
|
|
988
995
|
}
|
|
989
996
|
|
|
990
997
|
currentExtensions[0x69] = (data) => {
|
|
@@ -1022,6 +1029,7 @@ currentExtensions[0x73] = () => new Set(read())
|
|
|
1022
1029
|
|
|
1023
1030
|
export const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array')
|
|
1024
1031
|
|
|
1032
|
+
let glbl = typeof globalThis === 'object' ? globalThis : window;
|
|
1025
1033
|
currentExtensions[0x74] = (data) => {
|
|
1026
1034
|
let typeCode = data[0]
|
|
1027
1035
|
let typedArrayName = typedArrays[typeCode]
|