msgpackr 1.5.4 → 1.5.7
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 -1
- package/dist/index.js +20 -10
- package/dist/index.min.js +63 -62
- package/dist/node.cjs +21 -12
- package/dist/test.js +7 -580
- package/node-index.js +1 -2
- package/pack.js +12 -9
- package/package.json +2 -2
- package/unpack.d.ts +2 -0
- package/unpack.js +8 -1
package/README.md
CHANGED
|
@@ -159,7 +159,8 @@ The following options properties can be provided to the Packr or Unpackr constru
|
|
|
159
159
|
|
|
160
160
|
* `useRecords` - Setting this to `false` disables the record extension and stores JavaScript objects as MessagePack maps, and unpacks maps as JavaScript `Object`s, which ensures compatibilty with other decoders.
|
|
161
161
|
* `structures` - Provides the array of structures that is to be used for record extension, if you want the structures saved and used again. This array will be modified in place with new record structures that are serialized (if less than 32 structures are in the array).
|
|
162
|
-
* `
|
|
162
|
+
* `moreTypes` - Enable serialization of additional built-in types/classes including typed arrays, `Set`s, `Map`s, and `Error`s.
|
|
163
|
+
* `structuredClone` - This enables the structured cloning extensions that will encode object/cyclic references. `moreTypes` is enabled by default when this is enabled.
|
|
163
164
|
* `mapsAsObjects` - If `true`, this will decode MessagePack maps and JS `Object`s with the map entries decoded to object properties. If `false`, maps are decoded as JavaScript `Map`s. This is disabled by default if `useRecords` is enabled (which allows `Map`s to be preserved), and is enabled by default if `useRecords` is disabled.
|
|
164
165
|
* `useFloat32` - This will enable msgpackr to encode non-integer numbers as `float32`. See next section for possible values.
|
|
165
166
|
* `variableMapSize` - This will use varying map size definition (fixmap, map16, map32) based on the number of keys when encoding objects, which yields slightly more compact encodings (for small objects), but is typically 5-10% slower during encoding. This is necessary if you need to use objects with more than 65535 keys. This is only relevant when record extension is disabled.
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
const C1 = new C1Type();
|
|
29
29
|
C1.name = 'MessagePack 0xC1';
|
|
30
30
|
var sequentialMode = false;
|
|
31
|
+
var inlineObjectReadThreshold = 2;
|
|
32
|
+
try {
|
|
33
|
+
new Function('');
|
|
34
|
+
} catch(error) {
|
|
35
|
+
// if eval variants are not supported, do not create inline object readers ever
|
|
36
|
+
inlineObjectReadThreshold = Infinity;
|
|
37
|
+
}
|
|
31
38
|
|
|
32
39
|
class Unpackr {
|
|
33
40
|
constructor(options) {
|
|
@@ -436,7 +443,7 @@
|
|
|
436
443
|
function createStructureReader(structure, firstId) {
|
|
437
444
|
function readObject() {
|
|
438
445
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
439
|
-
if (readObject.count++ >
|
|
446
|
+
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
440
447
|
let readObject = structure.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read);
|
|
441
448
|
if (structure.highByte === 0)
|
|
442
449
|
structure.read = createSecondByteReader(firstId, structure.read);
|
|
@@ -1041,6 +1048,9 @@
|
|
|
1041
1048
|
maxSharedStructures = hasSharedStructures ? 32 : 0;
|
|
1042
1049
|
if (maxSharedStructures > 8160)
|
|
1043
1050
|
throw new Error('Maximum maxSharedStructure is 8160')
|
|
1051
|
+
if (options.structuredClone && options.moreTypes == undefined) {
|
|
1052
|
+
options.moreTypes = true;
|
|
1053
|
+
}
|
|
1044
1054
|
let maxOwnStructures = options.maxOwnStructures;
|
|
1045
1055
|
if (maxOwnStructures == null)
|
|
1046
1056
|
maxOwnStructures = hasSharedStructures ? 32 : 64;
|
|
@@ -1702,7 +1712,7 @@
|
|
|
1702
1712
|
target[position++] = 0xd6;
|
|
1703
1713
|
target[position++] = 0xff;
|
|
1704
1714
|
targetView.setUint32(position, seconds);
|
|
1705
|
-
} else if (seconds > 0 && seconds <
|
|
1715
|
+
} else if (seconds > 0 && seconds < 0x100000000) {
|
|
1706
1716
|
// Timestamp 64
|
|
1707
1717
|
let { target, targetView, position} = allocateForWrite(10);
|
|
1708
1718
|
target[position++] = 0xd7;
|
|
@@ -1732,8 +1742,8 @@
|
|
|
1732
1742
|
}, {
|
|
1733
1743
|
pack(set, allocateForWrite, pack) {
|
|
1734
1744
|
let array = Array.from(set);
|
|
1735
|
-
let { target, position} = allocateForWrite(this.
|
|
1736
|
-
if (this.
|
|
1745
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1746
|
+
if (this.moreTypes) {
|
|
1737
1747
|
target[position++] = 0xd4;
|
|
1738
1748
|
target[position++] = 0x73; // 's' for Set
|
|
1739
1749
|
target[position++] = 0;
|
|
@@ -1742,8 +1752,8 @@
|
|
|
1742
1752
|
}
|
|
1743
1753
|
}, {
|
|
1744
1754
|
pack(error, allocateForWrite, pack) {
|
|
1745
|
-
let { target, position} = allocateForWrite(this.
|
|
1746
|
-
if (this.
|
|
1755
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1756
|
+
if (this.moreTypes) {
|
|
1747
1757
|
target[position++] = 0xd4;
|
|
1748
1758
|
target[position++] = 0x65; // 'e' for error
|
|
1749
1759
|
target[position++] = 0;
|
|
@@ -1752,8 +1762,8 @@
|
|
|
1752
1762
|
}
|
|
1753
1763
|
}, {
|
|
1754
1764
|
pack(regex, allocateForWrite, pack) {
|
|
1755
|
-
let { target, position} = allocateForWrite(this.
|
|
1756
|
-
if (this.
|
|
1765
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1766
|
+
if (this.moreTypes) {
|
|
1757
1767
|
target[position++] = 0xd4;
|
|
1758
1768
|
target[position++] = 0x78; // 'x' for regeXp
|
|
1759
1769
|
target[position++] = 0;
|
|
@@ -1762,7 +1772,7 @@
|
|
|
1762
1772
|
}
|
|
1763
1773
|
}, {
|
|
1764
1774
|
pack(arrayBuffer, allocateForWrite) {
|
|
1765
|
-
if (this.
|
|
1775
|
+
if (this.moreTypes)
|
|
1766
1776
|
writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
|
|
1767
1777
|
else
|
|
1768
1778
|
writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
|
|
@@ -1770,7 +1780,7 @@
|
|
|
1770
1780
|
}, {
|
|
1771
1781
|
pack(typedArray, allocateForWrite) {
|
|
1772
1782
|
let constructor = typedArray.constructor;
|
|
1773
|
-
if (constructor !== ByteArray && this.
|
|
1783
|
+
if (constructor !== ByteArray && this.moreTypes)
|
|
1774
1784
|
writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite);
|
|
1775
1785
|
else
|
|
1776
1786
|
writeBuffer(typedArray, allocateForWrite);
|
package/dist/index.min.js
CHANGED
|
@@ -1,82 +1,83 @@
|
|
|
1
|
-
(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):(e=e||self,t(e.msgpackr={}))})(this,function(e){
|
|
2
|
-
|
|
1
|
+
(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):(e=e||self,t(e.msgpackr={}))})(this,function(e){"use strict";var t=Math.floor;function n(){try{if(!D.trusted&&!Y){let e=M.sharedLength||0;e<M.length&&(M.length=e)}let e=r();if(B&&(// bundled strings to skip past
|
|
2
|
+
P=B.postBundlePosition),P==E)M.restoreStructures&&s(),M=null,R=null,C&&(C=null);else if(P>E){// over read
|
|
3
3
|
let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}else if(!Y)throw new Error("Data read, but end of buffer not reached");// else more to read, but we are reading sequentially, so don't clear source yet
|
|
4
|
-
return e}catch(e){throw
|
|
5
|
-
let t=e-160;if(
|
|
6
|
-
let e=16>t?g(t):c(t);if(null!=e)return e}return
|
|
4
|
+
return e}catch(e){throw M.restoreStructures&&s(),m(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer"))&&(e.incomplete=!0),e}}function s(){for(let e in M.restoreStructures)M[e]=M.restoreStructures[e];M.restoreStructures=null}function r(){let e=R[P++];if(160>e){if(!(128>e)){if(!(144>e)){e-=144;let t=Array(e);for(let n=0;n<e;n++)t[n]=r();return t}if(e-=128,D.mapsAsObjects){let t={};for(let n=0;n<e;n++)t[h()]=r();return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(r(),r());return t}}else if(64>e)return e;else{let t=M[63&e]||D.getStructures&&o()[63&e];return t?(t.read||(t.read=i(t,63&e)),t.read()):e}}else if(192>e){// fixstr
|
|
5
|
+
let t=e-160;if(j>=P)return _.slice(P-F,(P+=t)-F);if(0==j&&140>E){// for small blocks, avoiding the overhead of the extract call is helpful
|
|
6
|
+
let e=16>t?g(t):c(t);if(null!=e)return e}return H(t)}else{let t;switch(e){case 192:return null;case 193:return B?(t=r(),0<t?B[1].slice(B.position1,B.position1+=t):B[0].slice(B.position0,B.position0-=t)):W;// "never-used", return special object to denote that
|
|
7
7
|
case 194:return!1;case 195:return!0;case 196:// bin 8
|
|
8
|
-
return
|
|
9
|
-
return f(
|
|
10
|
-
let e=re[(127&
|
|
11
|
-
case 204:return
|
|
12
|
-
case 208:return
|
|
8
|
+
return l(R[P++]);case 197:return t=T.getUint16(P),P+=2,l(t);case 198:return t=T.getUint32(P),P+=4,l(t);case 199:// ext 8
|
|
9
|
+
return f(R[P++]);case 200:return t=T.getUint16(P),P+=2,f(t);case 201:return t=T.getUint32(P),P+=4,f(t);case 202:if(t=T.getFloat32(P),2<D.useFloat32){// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
10
|
+
let e=re[(127&R[P])<<1|R[P+1]>>7];return P+=4,(e*t+(0<t?.5:-.5)>>0)/e}return P+=4,t;case 203:return t=T.getFloat64(P),P+=8,t;// uint handlers
|
|
11
|
+
case 204:return R[P++];case 205:return t=T.getUint16(P),P+=2,t;case 206:return t=T.getUint32(P),P+=4,t;case 207:return D.int64AsNumber?(t=4294967296*T.getUint32(P),t+=T.getUint32(P+4)):t=T.getBigUint64(P),P+=8,t;// int handlers
|
|
12
|
+
case 208:return T.getInt8(P++);case 209:return t=T.getInt16(P),P+=2,t;case 210:return t=T.getInt32(P),P+=4,t;case 211:return D.int64AsNumber?(t=4294967296*T.getInt32(P),t+=T.getUint32(P+4)):t=T.getBigInt64(P),P+=8,t;case 212:if(t=R[P++],114==t)return ee(63&R[P++]);else{let e=v[t];if(e)return e.read?(P++,e.read(r())):e.noBuffer?(P++,e()):e(R.subarray(P,++P));throw new Error("Unknown extension "+t)}case 213:return t=R[P],114==t?(P++,ee(63&R[P++],R[P++])):f(2);case 214:// fixext 4
|
|
13
13
|
return f(4);case 215:// fixext 8
|
|
14
14
|
return f(8);case 216:// fixext 16
|
|
15
|
-
return f(16);case 217:return t=
|
|
15
|
+
return f(16);case 217:return t=R[P++],j>=P?_.slice(P-F,(P+=t)-F):J(t);case 218:return t=T.getUint16(P),P+=2,j>=P?_.slice(P-F,(P+=t)-F):K(t);case 219:return t=T.getUint32(P),P+=4,j>=P?_.slice(P-F,(P+=t)-F):Q(t);case 220:return t=T.getUint16(P),P+=2,u(t);case 221:return t=T.getUint32(P),P+=4,u(t);case 222:return t=T.getUint16(P),P+=2,d(t);case 223:return t=T.getUint32(P),P+=4,d(t);default:// negative int
|
|
16
16
|
if(224<=e)return e-256;if(void 0===e){let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}throw new Error("Unknown MessagePack token "+e);}}}function i(e,t){function n(){// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
17
|
-
if(
|
|
18
|
-
}let
|
|
19
|
-
const t=63&
|
|
20
|
-
const t=63&
|
|
21
|
-
const t=63&
|
|
22
|
-
e=t-160;else switch(t){case 217:e=
|
|
23
|
-
Uint8Array.prototype.slice.call(
|
|
24
|
-
return
|
|
25
|
-
let d=16>e?g(e):c(e);return null==d?
|
|
17
|
+
if(n.count++>z){let n=e.read=new Function("r","return function(){return {"+e.map(e=>q.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}}")(r);return 0===e.highByte&&(e.read=G(t,e.read)),n();// second byte is already read, if there is one so immediately read object
|
|
18
|
+
}let s={};for(let t,n=0,i=e.length;n<i;n++)t=e[n],s[t]=r();return s}return n.count=0,0===e.highByte?G(t,n):n}function o(){let e=y(()=>(R=null,D.getStructures()));return M=D._mergeStructures(e,M)}function a(e){let t;if(16>e&&(t=g(e)))return t;if(64<e&&x)return x.decode(R.subarray(P,P+=e));const n=P+e,s=[];for(t="";P<n;){const e=R[P++];if(0==(128&e))s.push(e);else if(192==(224&e)){// 2 bytes
|
|
19
|
+
const t=63&R[P++];s.push((31&e)<<6|t)}else if(224==(240&e)){// 3 bytes
|
|
20
|
+
const t=63&R[P++],n=63&R[P++];s.push((31&e)<<12|t<<6|n)}else if(240==(248&e)){// 4 bytes
|
|
21
|
+
const t=63&R[P++],n=63&R[P++],r=63&R[P++];let i=(7&e)<<18|t<<12|n<<6|r;65535<i&&(i-=65536,s.push(55296|1023&i>>>10),i=56320|1023&i),s.push(i)}else s.push(e);4096<=s.length&&(t+=X.apply(String,s),s.length=0)}return 0<s.length&&(t+=X.apply(String,s)),t}function u(e){let t=Array(e);for(let n=0;n<e;n++)t[n]=r();return t}function d(e){if(D.mapsAsObjects){let t={};for(let n=0;n<e;n++)t[h()]=r();return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(r(),r());return t}}function c(e){let t=P,n=Array(e);for(let s=0;s<e;s++){const e=R[P++];if(0<(128&e))return void(P=t);n[s]=e}return X.apply(String,n)}function g(t){if(4>t){if(!(2>t)){let e=R[P++],n=R[P++];if(0<(128&e)||0<(128&n))return void(P-=2);if(3>t)return X(e,n);let s=R[P++];return 0<(128&s)?void(P-=3):X(e,n,s)}if(0===t)return"";else{let e=R[P++];return 1<(128&e)?void(P-=1):X(e)}}else{let s=R[P++],r=R[P++],a=R[P++],u=R[P++];if(0<(128&s)||0<(128&r)||0<(128&a)||0<(128&u))return void(P-=4);if(6>t){if(4===t)return X(s,r,a,u);else{let t=R[P++];return 0<(128&t)?void(P-=5):X(s,r,a,u,t)}}else if(8>t){let n=R[P++],e=R[P++];if(0<(128&n)||0<(128&e))return void(P-=6);if(7>t)return X(s,r,a,u,n,e);let i=R[P++];return 0<(128&i)?void(P-=7):X(s,r,a,u,n,e,i)}else{let d=R[P++],e=R[P++],c=R[P++],g=R[P++];if(0<(128&d)||0<(128&e)||0<(128&c)||0<(128&g))return void(P-=8);if(10>t){if(8===t)return X(s,r,a,u,d,e,c,g);else{let t=R[P++];return 0<(128&t)?void(P-=9):X(s,r,a,u,d,e,c,g,t)}}else if(12>t){let n=R[P++],i=R[P++];if(0<(128&n)||0<(128&i))return void(P-=10);if(11>t)return X(s,r,a,u,d,e,c,g,n,i);let o=R[P++];return 0<(128&o)?void(P-=11):X(s,r,a,u,d,e,c,g,n,i,o)}else{let p=R[P++],i=R[P++],f=R[P++],h=R[P++];if(0<(128&p)||0<(128&i)||0<(128&f)||0<(128&h))return void(P-=12);if(!(14>t)){let l=R[P++],y=R[P++];if(0<(128&l)||0<(128&y))return void(P-=14);if(15>t)return X(s,r,a,u,d,e,c,g,p,i,f,h,l,y);let n=R[P++];return 0<(128&n)?void(P-=15):X(s,r,a,u,d,e,c,g,p,i,f,h,l,y,n)}if(12===t)return X(s,r,a,u,d,e,c,g,p,i,f,h);else{let t=R[P++];return 0<(128&t)?void(P-=13):X(s,r,a,u,d,e,c,g,p,i,f,h,t)}}}}}function p(){let e,t=R[P++];if(192>t)// fixstr
|
|
22
|
+
e=t-160;else switch(t){case 217:e=R[P++];break;case 218:e=T.getUint16(P),P+=2;break;case 219:e=T.getUint32(P),P+=4;break;default:throw new Error("Expected string");}return a(e)}function l(e){return D.copyBuffers?// specifically use the copying slice (not the node one)
|
|
23
|
+
Uint8Array.prototype.slice.call(R,P,P+=e):R.subarray(P,P+=e)}function f(e){let t=R[P++];if(v[t])return v[t](R.subarray(P,P+=e));throw new Error("Unknown extension type "+t)}function h(){let e=R[P++];if(160<=e&&192>e){if(e-=160,j>=P)// if it has been extracted, must use it (and faster anyway)
|
|
24
|
+
return _.slice(P-F,(P+=e)-F);if(!(0==j&&180>E))return H(e)}else return P--,r();let t,n=4095&(e<<5^(1<e?T.getUint16(P):0<e?R[P]:0)),s=Z[n],o=P,a=P+e-3,u=0;if(s&&s.bytes==e){for(;o<a;){if(t=T.getUint32(o),t!=s[u++]){o=1879048192;break}o+=4}for(a+=3;o<a;)if(t=R[o++],t!=s[u++]){o=1879048192;break}if(o===a)return P=o,s.string;a-=3,o=P}for(s=[],Z[n]=s,s.bytes=e;o<a;)t=T.getUint32(o),s.push(t),o+=4;for(a+=3;o<a;)t=R[o++],s.push(t);// for small blocks, avoiding the overhead of the extract call is helpful
|
|
25
|
+
let d=16>e?g(e):c(e);return null==d?s.string=H(e):s.string=d}// the registration of the record definition extension (as "r")
|
|
26
26
|
// notepack defines extension 0 to mean undefined, so use that as the default here
|
|
27
27
|
// registration of bulk record definition?
|
|
28
28
|
// currentExtensions[0x52] = () =>
|
|
29
|
-
function y(e){let t=
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
let n,
|
|
33
|
-
e[o++]=214,e[o++]=105,e[o++]=i>>24,e[o++]=255&i>>16,e[o++]=255&i>>8,e[o++]=255&i,
|
|
29
|
+
function y(e){let t=E,n=P,s=F,r=j,i=_,o=C,a=B,u=new Uint8Array(R.slice(0,E)),d=M,c=M.slice(0,M.length),g=D,p=Y,l=e();return E=t,P=n,F=s,j=r,_=i,C=o,B=a,R=u,Y=p,M=d,M.splice(0,M.length,...c),D=g,T=new DataView(R.buffer,R.byteOffset,R.byteLength),l}function m(){R=null,C=null,M=null}function b(e){v[e.type]=e.unpack?e.unpack:e}function k(e,t,n){let s=e.byteLength;if(256>s+1){var{target:r,position:i}=n(4+s);r[i++]=199,r[i++]=s+1}else if(65536>s+1){var{target:r,position:i}=n(5+s);r[i++]=200,r[i++]=s+1>>8,r[i++]=255&s+1}else{var{target:r,position:i,targetView:o}=n(7+s);// plus one for the type byte
|
|
30
|
+
r[i++]=201,o.setUint32(i,s+1),i+=4}// "t" for typed array
|
|
31
|
+
r[i++]=116,r[i++]=t,r.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),i)}function U(e,t){let n=e.byteLength;var s,r;if(256>n){var{target:s,position:r}=t(n+2);s[r++]=196,s[r++]=n}else if(65536>n){var{target:s,position:r}=t(n+3);s[r++]=197,s[r++]=n>>8,s[r++]=255&n}else{var{target:s,position:r,targetView:i}=t(n+5);s[r++]=198,i.setUint32(r,n),r+=4}s.set(e,r)}function I(e,t,n,s){let r=e.length;return 1===r?t[n++]=212:2===r?t[n++]=213:4===r?t[n++]=214:8===r?t[n++]=215:16===r?t[n++]=216:256>r?(t[n++]=199,t[n++]=r):65536>r?(t[n++]=200,t[n++]=r>>8,t[n++]=255&r):(t[n++]=201,t[n++]=r>>24,t[n++]=255&r>>16,t[n++]=255&r>>8,t[n++]=255&r),t[n++]=s,t.set(e,n),n+=r,n}function S(e,t){// insert the ids that need to be referenced for structured clones
|
|
32
|
+
let n,s=6*t.length,r=e.length-s;for(t.sort((e,t)=>e.offset>t.offset?1:-1);n=t.pop();){let t=n.offset,i=n.id;e.copyWithin(t+s,t,r),s-=6;let o=t+s;// 'i'
|
|
33
|
+
e[o++]=214,e[o++]=105,e[o++]=i>>24,e[o++]=255&i>>16,e[o++]=255&i>>8,e[o++]=255&i,r=t}return e}function O(e,t){Ie.setUint32(Ae.position+e,Oe-Ae.position-e);let n=Ae;Ae=null,t(n[0]),t(n[1])}function A(e){if(e.Class){if(!e.pack&&!e.write)throw new Error("Extension has no pack or write function");if(e.pack&&!e.type)throw new Error("Extension has no type (numeric code to identify the extension)");fe.unshift(e.Class),le.unshift(e)}b(e)}function*w(e,t){const n=new Le(t);for(const s of e)yield n.pack(s)}async function*L(e,t){const n=new Le(t);for await(const s of e)yield n.pack(s)}/**
|
|
34
34
|
* Given an Iterable/Iterator input which yields buffers, returns an IterableIterator which yields sync decoded objects
|
|
35
35
|
* Or, given an Async Iterable/Iterator which yields promises resolving in buffers, returns an AsyncIterableIterator.
|
|
36
36
|
* @param {Iterable|Iterator|AsyncIterable|AsyncIterableIterator} bufferIterator
|
|
37
37
|
* @param {object} [options] - unpackr options
|
|
38
38
|
* @returns {IterableIterator|Promise.<AsyncIterableIterator}
|
|
39
|
-
*/var
|
|
40
|
-
|
|
39
|
+
*/var x;try{x=new TextDecoder}catch(e){}var R,E,M,_,B,C,T,P=0,D={},F=0,j=0,v=[],N={useRecords:!1,mapsAsObjects:!0};class V{}const W=new V;W.name="MessagePack 0xC1";var Y=!1,z=2;try{new Function("")}catch(e){// if eval variants are not supported, do not create inline object readers ever
|
|
40
|
+
z=1/0}class ${constructor(e){e&&(!1===e.useRecords&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0)),Object.assign(this,e)}unpack(e,t){if(R)// re-entrant execution, save the state and restore it after we do this unpack
|
|
41
|
+
return y(()=>(m(),this?this.unpack(e,t):$.prototype.unpack.call(N,e,t)));E=-1<t?t:e.length,P=0,j=0,_=null,B=null,R=e;// this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
|
|
41
42
|
// technique for getting data from a database where it can be copied into an existing buffer instead of creating
|
|
42
43
|
// new ones
|
|
43
|
-
try{
|
|
44
|
-
let e=
|
|
45
|
-
|
|
46
|
-
return
|
|
47
|
-
},
|
|
48
|
-
let e=
|
|
49
|
-
return new
|
|
50
|
-
for(let n=0;256>n;n++)re[n]=+("1e"+t(45.15-.30103*n));var
|
|
51
|
-
let
|
|
52
|
-
throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+
|
|
53
|
-
if(
|
|
54
|
-
}finally{if(
|
|
55
|
-
let n=
|
|
56
|
-
let i=3*
|
|
57
|
-
(n=e*re[(127&
|
|
58
|
-
|
|
59
|
-
k(e,!e.hasOwnProperty)}}}else if("boolean"===
|
|
60
|
-
if(this.largeBigIntToFloat)
|
|
61
|
-
let t=Object.keys(e),n=t.length;16>n?
|
|
62
|
-
let
|
|
63
|
-
(e,n)=>{let
|
|
64
|
-
let n=Object.keys(e),d=o;o=
|
|
65
|
-
w(o,n,a,c),i=!0,o=d[u]}
|
|
66
|
-
for(let n in o?96<=o&&
|
|
67
|
-
if(e-t>be)throw new Error("Packed buffer would be larger than maximum buffer size");i=n(be,4096*r(
|
|
68
|
-
i=(
|
|
69
|
-
i=
|
|
70
|
-
|
|
71
|
-
let{target:e,targetView:t,position:
|
|
72
|
-
let{target:t,targetView:
|
|
73
|
-
let{target:e,targetView:t,position:
|
|
74
|
-
let{target:
|
|
75
|
-
let{target:n,position:
|
|
76
|
-
|
|
44
|
+
try{T=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(t){if(R=null,e instanceof Uint8Array)throw t;throw new Error("Source must be a Uint8Array or Buffer but was a "+(e&&"object"==typeof e?e.constructor.name:typeof e))}if(this instanceof $){if(D=this,this.structures)return M=this.structures,n();(!M||0<M.length)&&(M=[])}else D=N,(!M||0<M.length)&&(M=[]);return n()}unpackMultiple(e,t){let s,r=0;try{Y=!0;let i=e.length,o=this?this.unpack(e,i):ie.unpack(e,i);if(t){for(t(o);P<i;)if(r=P,!1===t(n()))return;}else{for(s=[o];P<i;)r=P,s.push(n());return s}}catch(e){throw e.lastPosition=r,e.values=s,e}finally{Y=!1,m()}}_mergeStructures(e,t){e=e||[];for(let n,s=0,r=e.length;s<r;s++)n=e[s],n&&(n.isShared=!0,32<=s&&(n.highByte=s-32>>5));for(let n in e.sharedLength=e.length,t||[])if(0<=n){let s=e[n],r=t[n];r&&(s&&((e.restoreStructures||(e.restoreStructures=[]))[n]=s),e[n]=r)}return this.structures=e}decode(e,t){return this.unpack(e,t)}}const q=/^[a-zA-Z_$][a-zA-Z\d_$]*$/,G=(e,t)=>function(){let n=R[P++];if(0===n)return t();let s=32>e?-(e+(n<<5)):e+(n<<5),r=M[s]||o()[s];if(!r)throw new Error("Record id is not defined for "+s);return r.read||(r.read=i(r,e)),r.read()};var H=a,J=a,K=a,Q=a;var X=String.fromCharCode,Z=Array(4096);const ee=(e,t)=>{var n=r();let s=e;void 0!==t&&(e=32>e?-((t<<5)+e):(t<<5)+e,n.highByte=t);let o=M[e];return o&&o.isShared&&((M.restoreStructures||(M.restoreStructures=[]))[e]=o),M[e]=n,n.read=i(n,s),n.read()};var te="object"==typeof self?self:global;v[0]=()=>{},v[0].noBuffer=!0,v[101]=()=>{let e=r();return(te[e[0]]||Error)(e[1])},v[105]=()=>{// id extension (for structured clones)
|
|
45
|
+
let e=T.getUint32(P-4);C||(C=new Map);let t,n=R[P];t=144<=n&&160>n||220==n||221==n?[]:{};let s={target:t};// a placeholder object
|
|
46
|
+
C.set(e,s);let i=r();// read the next value as the target object to id
|
|
47
|
+
return s.used?Object.assign(t,i):(s.target=i,i);// no cycle, can just use the returned read object
|
|
48
|
+
},v[112]=()=>{// pointer extension (for structured clones)
|
|
49
|
+
let e=T.getUint32(P-4),t=C.get(e);return t.used=!0,t.target},v[115]=()=>new Set(r());const ne=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");v[116]=e=>{let t=e[0],n=ne[t];if(!n)throw new Error("Could not find typed array for code "+t);// we have to always slice/copy here to get a new ArrayBuffer that is word/byte aligned
|
|
50
|
+
return new te[n](Uint8Array.prototype.slice.call(e,1).buffer)},v[120]=()=>{let e=r();return new RegExp(e[0],e[1])};const se=[];v[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=P;return P+=t-e.length,B=se,B=[p(),p()],B.position0=0,B.position1=0,B.postBundlePosition=P,P=n,r()},v[255]=e=>4==e.length?new Date(1e3*(16777216*e[0]+(e[1]<<16)+(e[2]<<8)+e[3])):8==e.length?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+1e3*(4294967296*(3&e[3])+16777216*e[4]+(e[5]<<16)+(e[6]<<8)+e[7])):12==e.length?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+1e3*((128&e[4]?-281474976710656:0)+1099511627776*e[6]+4294967296*e[7]+16777216*e[8]+(e[9]<<16)+(e[10]<<8)+e[11])):new Date("invalid");const re=Array(147);// this is a table matching binary exponents to the multiplier to determine significant digit rounding
|
|
51
|
+
for(let n=0;256>n;n++)re[n]=+("1e"+t(45.15-.30103*n));var ie=new $({useRecords:!1});const oe=ie.unpack,ae=ie.unpackMultiple,ue=ie.unpack,de={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let ce,ge=new Float32Array(1),pe=new Uint8Array(ge.buffer,0,4);try{ce=new TextEncoder}catch(e){}let le,fe;const he="undefined"!=typeof Buffer,ye=he?Buffer.allocUnsafeSlow:Uint8Array,me=he?Buffer:Uint8Array,be=he?4294967296:2144337920;let ke,Ue,Ie,Se,Oe=0,Ae=null;const we=Symbol("record-id");class Le extends ${constructor(e){super(e),this.offset=0;let t,n,s,r,i=0,o=me.prototype.utf8Write?function(e,t,n){return ke.utf8Write(e,t,n)}:!!(ce&&ce.encodeInto)&&function(e,t){return ce.encodeInto(e,ke.subarray(t)).written},a=this;e||(e={});let u=e&&e.sequential,d=e.structures||e.saveStructures,c=e.maxSharedStructures;if(null==c&&(c=d?32:0),8160<c)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&null==e.moreTypes&&(e.moreTypes=!0);let g=e.maxOwnStructures;null==g&&(g=d?32:64),this.structures||!1==e.useRecords||(this.structures=[]);// two byte record ids for shared structures
|
|
52
|
+
let p=32<c||64<g+c,l=c+64,f=c+g+64;if(8256<f)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let h=[],y=0,m=0;this.pack=this.encode=function(e,o){if(ke||(ke=new ye(8192),Ie=new DataView(ke.buffer,0,8192),Oe=0),Se=ke.length-10,2048>Se-Oe?(ke=new ye(ke.length),Ie=new DataView(ke.buffer,0,ke.length),Se=ke.length-10,Oe=0):Oe=2147483640&Oe+7,t=Oe,r=a.structuredClone?new Map:null,a.bundleStrings&&"string"!=typeof e?(Ae=[],Ae.size=1/0):Ae=null,s=a.structures,s){s.uninitialized&&(s=a._mergeStructures(a.getStructures()));let e=s.sharedLength||0;if(e>c)//if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
|
|
53
|
+
throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+s.sharedLength);if(!s.transitions){s.transitions=Object.create(null);for(let t,n=0;n<e;n++){if(t=s[n],!t)continue;let e,r=s.transitions;for(let n,s=0,i=t.length;s<i;s++)n=t[s],e=r[n],e||(e=r[n]=Object.create(null)),r=e;r[we]=n+64}i=e}u||(s.nextId=e+64)}n&&(n=!1);try{// update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
54
|
+
if(b(e),Ae&&O(t,b),a.offset=Oe,r&&r.idsToInsert){Oe+=6*r.idsToInsert.length,Oe>Se&&U(Oe),a.offset=Oe;let e=S(ke.subarray(t,Oe),r.idsToInsert);return r=null,e}return o&Te?(ke.start=t,ke.end=Oe,ke):ke.subarray(t,Oe);// position can change if we call pack again in saveStructures, so we get the buffer now
|
|
55
|
+
}finally{if(s){10>m&&m++;let r=s.sharedLength||c;if(s.length>r&&(s.length=r),1e4<y)s.transitions=null,m=0,y=0,0<h.length&&(h=[]);else if(0<h.length&&!u){for(let e=0,t=h.length;e<t;e++)h[e][we]=0;h=[]}if(n&&a.saveStructures){// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
|
|
56
|
+
let n=ke.subarray(t,Oe);return!1===a.saveStructures(s,i)?(a._mergeStructures(a.getStructures()),a.pack(e)):(i=r,n)}}o&Pe&&(Oe=t)}};const b=e=>{Oe>Se&&(ke=U(Oe));var n,s=typeof e;if("string"==s){let s=e.length;if(Ae&&4<=s&&4096>s){if((Ae.size+=s)>61440){let e,n=(Ae[0]?3*Ae[0].length+Ae[1].length:0)+10;Oe+n>Se&&(ke=U(Oe+n)),Ae.position?(ke[Oe]=200,Oe+=3,ke[Oe++]=98,e=Oe-t,Oe+=4,O(t,b),Ie.setUint16(e+t-3,Oe-t-e)):(ke[Oe++]=214,ke[Oe++]=98,e=Oe-t,Oe+=4),Ae=["",""],Ae.size=0,Ae.position=e}let n=/[\u0080-\uFFFF]/.test(e);return Ae[n?0:1]+=e,ke[Oe++]=193,void b(n?-s:s)}let r=32>s?1:256>s?2:65536>s?3:5;// first we estimate the header size, so we can write to the correct location
|
|
57
|
+
let i=3*s;if(Oe+i>Se&&(ke=U(Oe+i)),64>s||!o){let t,i,o,a=Oe+r;for(t=0;t<s;t++)i=e.charCodeAt(t),128>i?ke[a++]=i:2048>i?(ke[a++]=192|i>>6,ke[a++]=128|63&i):55296==(64512&i)&&56320==(64512&(o=e.charCodeAt(t+1)))?(i=65536+((1023&i)<<10)+(1023&o),t++,ke[a++]=240|i>>18,ke[a++]=128|63&i>>12,ke[a++]=128|63&i>>6,ke[a++]=128|63&i):(ke[a++]=224|i>>12,ke[a++]=128|63&i>>6,ke[a++]=128|63&i);n=a-Oe-r}else n=o(e,Oe+r,i);32>n?ke[Oe++]=160|n:256>n?(2>r&&ke.copyWithin(Oe+2,Oe+1,Oe+1+n),ke[Oe++]=217,ke[Oe++]=n):65536>n?(3>r&&ke.copyWithin(Oe+3,Oe+2,Oe+2+n),ke[Oe++]=218,ke[Oe++]=n>>8,ke[Oe++]=255&n):(5>r&&ke.copyWithin(Oe+5,Oe+3,Oe+3+n),ke[Oe++]=219,Ie.setUint32(Oe,n),Oe+=4),Oe+=n}else if("number"===s){if(e>>>0===e)64>e?ke[Oe++]=e:256>e?(ke[Oe++]=204,ke[Oe++]=e):65536>e?(ke[Oe++]=205,ke[Oe++]=e>>8,ke[Oe++]=255&e):(ke[Oe++]=206,Ie.setUint32(Oe,e),Oe+=4);else if(e>>0===e)-32<=e?ke[Oe++]=256+e:-128<=e?(ke[Oe++]=208,ke[Oe++]=e+256):-32768<=e?(ke[Oe++]=209,Ie.setInt16(Oe,e),Oe+=2):(ke[Oe++]=210,Ie.setInt32(Oe,e),Oe+=4);else{let t;if(0<(t=this.useFloat32)&&4294967296>e&&-2147483648<=e){ke[Oe++]=202,Ie.setFloat32(Oe,e);let n;if(4>t||// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
58
|
+
(n=e*re[(127&ke[Oe])<<1|ke[Oe+1]>>7])>>0===n)return void(Oe+=4);// move back into position for writing a double
|
|
59
|
+
Oe--}ke[Oe++]=203,Ie.setFloat64(Oe,e),Oe+=8}}else if("object"===s){if(!e)ke[Oe++]=192;else{if(r){let n=r.get(e);if(n){if(!n.id){let e=r.idsToInsert||(r.idsToInsert=[]);n.id=e.push(n)}return ke[Oe++]=214,ke[Oe++]=112,Ie.setUint32(Oe,n.id),void(Oe+=4)}r.set(e,{offset:Oe-t})}let s=e.constructor;if(s===Object)k(e,!0);else if(s===Array){n=e.length,16>n?ke[Oe++]=144|n:65536>n?(ke[Oe++]=220,ke[Oe++]=n>>8,ke[Oe++]=255&n):(ke[Oe++]=221,Ie.setUint32(Oe,n),Oe+=4);for(let t=0;t<n;t++)b(e[t])}else if(s===Map){n=e.size,16>n?ke[Oe++]=128|n:65536>n?(ke[Oe++]=222,ke[Oe++]=n>>8,ke[Oe++]=255&n):(ke[Oe++]=223,Ie.setUint32(Oe,n),Oe+=4);for(let[t,n]of e)b(t),b(n)}else{for(let t,n=0,s=le.length;n<s;n++)if(t=fe[n],e instanceof t){let t=le[n];if(t.write)return t.type&&(ke[Oe++]=212,ke[Oe++]=t.type,ke[Oe++]=0),void b(t.write.call(this,e));let s=ke,r=Ie,i=Oe;ke=null;let o;try{o=t.pack.call(this,e,e=>(ke=s,s=null,Oe+=e,Oe>Se&&U(Oe),{target:ke,targetView:Ie,position:Oe-e}),b)}finally{s&&(ke=s,Ie=r,Oe=i,Se=ke.length-10)}return void(o&&(o.length+Oe>Se&&U(o.length+Oe),Oe=I(o,ke,Oe,t.type)))}// no extension found, write as object
|
|
60
|
+
k(e,!e.hasOwnProperty)}}}else if("boolean"===s)ke[Oe++]=e?195:194;else if("bigint"===s){if(e<BigInt(1)<<BigInt(63)&&e>=-(BigInt(1)<<BigInt(63)))ke[Oe++]=211,Ie.setBigInt64(Oe,e);else if(e<BigInt(1)<<BigInt(64)&&0<e)ke[Oe++]=207,Ie.setBigUint64(Oe,e);else// overflow
|
|
61
|
+
if(this.largeBigIntToFloat)ke[Oe++]=203,Ie.setFloat64(Oe,+e);else throw new RangeError(e+" was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64");Oe+=8}else if("undefined"===s)this.encodeUndefinedAsNil?ke[Oe++]=192:(ke[Oe++]=212,ke[Oe++]=0,ke[Oe++]=0);else if("function"===s)b(this.writeFunction&&this.writeFunction());else throw new Error("Unknown type: "+s)},k=!1===this.useRecords?this.variableMapSize?e=>{// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
|
|
62
|
+
let t=Object.keys(e),n=t.length;16>n?ke[Oe++]=128|n:65536>n?(ke[Oe++]=222,ke[Oe++]=n>>8,ke[Oe++]=255&n):(ke[Oe++]=223,Ie.setUint32(Oe,n),Oe+=4);let s;for(let r=0;r<n;r++)b(s=t[r]),b(e[s])}:(e,n)=>{ke[Oe++]=222;// always using map 16, so we can preallocate and set the length afterwards
|
|
63
|
+
let s=Oe-t;Oe+=2;let r=0;for(let t in e)(n||e.hasOwnProperty(t))&&(b(t),b(e[t]),r++);ke[s++ +t]=r>>8,ke[s+t]=255&r}:e.progressiveRecords&&!p?// this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
|
|
64
|
+
(e,n)=>{let r,i,o=s.transitions||(s.transitions=Object.create(null)),a=Oe++-t;for(let u in e)if(n||e.hasOwnProperty(u)){if(r=o[u],r)o=r;else{// record doesn't exist, create full new record and insert it
|
|
65
|
+
let n=Object.keys(e),d=o;o=s.transitions;let c=0;for(let e,t=0,s=n.length;t<s;t++)e=n[t],r=o[e],r||(r=o[e]=Object.create(null),c++),o=r;a+t+1==Oe?(Oe--,A(o,n,c)):// otherwise we need to insert the record, moving existing data after the record
|
|
66
|
+
w(o,n,a,c),i=!0,o=d[u]}b(e[u])}if(!i){let n=o[we];n?ke[a+t]=n:w(o,Object.keys(e),a,0)}}:(e,t)=>{let n,r=s.transitions||(s.transitions=Object.create(null)),i=0;for(let s in e)(t||e.hasOwnProperty(s))&&(n=r[s],n||(n=r[s]=Object.create(null),i++),r=n);let o=r[we];// now write the values
|
|
67
|
+
for(let n in o?96<=o&&p?(ke[Oe++]=(31&(o-=96))+96,ke[Oe++]=o>>5):ke[Oe++]=o:A(r,r.__keys__||Object.keys(e),i),e)(t||e.hasOwnProperty(n))&&b(e[n])},U=e=>{var n=Math.min,s=Math.round,r=Math.max;let i;if(16777216<e){// special handling for really large buffers
|
|
68
|
+
if(e-t>be)throw new Error("Packed buffer would be larger than maximum buffer size");i=n(be,4096*s(r((e-t)*(67108864<e?1.25:2),4194304)/4096))}else// faster handling for smaller buffers
|
|
69
|
+
i=(r(e-t<<2,ke.length-1)>>12)+1<<12;let o=new ye(i);return Ie=new DataView(o.buffer,0,i),ke.copy?ke.copy(o,0,t,e):o.set(ke.slice(t,e)),Oe-=t,t=0,Se=o.length-10,ke=o},A=(e,t,r)=>{let i=s.nextId;i||(i=64),i<l&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(i=s.nextOwnId,!(i<f)&&(i=l),s.nextOwnId=i+1):(i>=f&&(// cycle back around
|
|
70
|
+
i=l),s.nextId=i+1);let o=t.highByte=96<=i&&p?i-96>>5:-1;e[we]=i,e.__keys__=t,s[i-64]=t,i<l?(t.isShared=!0,s.sharedLength=i-63,n=!0,0<=o?(ke[Oe++]=(31&i)+96,ke[Oe++]=o):ke[Oe++]=i):(0<=o?(ke[Oe++]=213,ke[Oe++]=114,ke[Oe++]=(31&i)+96,ke[Oe++]=o):(ke[Oe++]=212,ke[Oe++]=114,ke[Oe++]=i),r&&(y+=m*r),h.length>=g&&(h.shift()[we]=0),h.push(e),b(t))},w=(e,n,s,r)=>{let i=ke,o=Oe,a=Se,u=t;ke=Ue,Oe=0,t=0,ke||(Ue=ke=new ye(8192)),Se=ke.length-10,A(e,n,r),Ue=ke;let d=Oe;if(ke=i,Oe=o,Se=a,t=u,1<d){let e=Oe+d-1;e>Se&&U(e);let n=s+t;ke.copyWithin(n+d,n+1,Oe),ke.set(Ue.slice(0,d),n),Oe=e}else ke[s+t]=Ue[0]}}useBuffer(e){// this means we are finished using our own buffer and we can write over it safely
|
|
71
|
+
ke=e,Ie=new DataView(ke.buffer,ke.byteOffset,ke.byteLength),Oe=0}clearSharedData(){this.structures&&(this.structures=[])}}fe=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor/*TypedArray*/,V],le=[{pack(e,n,s){let r=e.getTime()/1e3;if((this.useTimestamp32||0===e.getMilliseconds())&&0<=r&&4294967296>r){// Timestamp 32
|
|
72
|
+
let{target:e,targetView:t,position:s}=n(6);e[s++]=214,e[s++]=255,t.setUint32(s,r)}else if(0<r&&4294967296>r){// Timestamp 64
|
|
73
|
+
let{target:t,targetView:s,position:i}=n(10);t[i++]=215,t[i++]=255,s.setUint32(i,4e6*e.getMilliseconds()+(r/1e3/4294967296>>0)),s.setUint32(i+4,r)}else if(isNaN(r)){if(this.onInvalidDate)return n(0),s(this.onInvalidDate());// Intentionally invalid timestamp
|
|
74
|
+
let{target:e,targetView:t,position:r}=n(3);e[r++]=212,e[r++]=255,e[r++]=255}else{// Timestamp 96
|
|
75
|
+
let{target:s,targetView:i,position:o}=n(15);s[o++]=199,s[o++]=12,s[o++]=255,i.setUint32(o,1e6*e.getMilliseconds()),i.setBigInt64(o+4,BigInt(t(r)))}}},{pack(e,t,n){let s=Array.from(e),{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=115,r[i++]=0),n(s)}},{pack(e,t,n){let{target:s,position:r}=t(this.moreTypes?3:0);this.moreTypes&&(s[r++]=212,s[r++]=101,s[r++]=0),n([e.name,e.message])}},{pack(e,t,n){let{target:s,position:r}=t(this.moreTypes?3:0);this.moreTypes&&(s[r++]=212,s[r++]=120,s[r++]=0),n([e.source,e.flags])}},{pack(e,t){this.moreTypes?k(e,16,t):U(he?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==me&&this.moreTypes?k(e,ne.indexOf(n.name),t):U(e,t)}},{pack(e,t){// specific 0xC1 object
|
|
76
|
+
let{target:n,position:s}=t(1);n[s]=193}}];let xe=new Le({useRecords:!1});const Re=xe.pack,Ee=xe.pack,{NEVER:Me,ALWAYS:_e,DECIMAL_ROUND:Be,DECIMAL_FIT:Ce}=de,Te=512,Pe=1024;e.ALWAYS=_e,e.C1=W,e.DECIMAL_FIT=Ce,e.DECIMAL_ROUND=Be,e.Decoder=$,e.Encoder=Le,e.FLOAT32_OPTIONS=de,e.NEVER=Me,e.Packr=Le,e.REUSE_BUFFER_MODE=Te,e.Unpackr=$,e.addExtension=A,e.clearSource=m,e.decode=ue,e.decodeIter=function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise");const n=new $(t);let s;const r=e=>{let t;// if there's incomplete data from previous chunk, concatinate and try again
|
|
77
|
+
s&&(e=Buffer.concat([s,e]),s=void 0);try{t=n.unpackMultiple(e)}catch(n){if(n.incomplete)s=e.slice(n.lastPosition),t=n.values;else throw n}return t};if("function"==typeof e[Symbol.iterator])return function*(){for(const t of e)yield*r(t)}();return"function"==typeof e[Symbol.asyncIterator]?async function*(){for await(const t of e)yield*r(t)}():void 0},e.encode=Ee,e.encodeIter=/**
|
|
77
78
|
* Given an Iterable first argument, returns an Iterable where each value is packed as a Buffer
|
|
78
79
|
* If the argument is only Async Iterable, the return value will be an Async Iterable.
|
|
79
80
|
* @param {Iterable|Iterator|AsyncIterable|AsyncIterator} objectIterator - iterable source, like a Readable object stream, an array, Set, or custom object
|
|
80
81
|
* @param {options} [options] - msgpackr pack options
|
|
81
82
|
* @returns {IterableIterator|Promise.<AsyncIterableIterator>}
|
|
82
|
-
*/function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable");else{if("function"==typeof e[Symbol.iterator])return w(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return
|
|
83
|
+
*/function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable");else{if("function"==typeof e[Symbol.iterator])return w(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return L(e,t);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}},e.isNativeAccelerationEnabled=!1,e.mapsAsObjects=!0,e.pack=Re,e.roundFloat32=function(e){ge[0]=e;let t=re[(127&pe[3])<<1|pe[2]>>7];return(t*e+(0<e?.5:-.5)>>0)/t},e.unpack=oe,e.unpackMultiple=ae,e.useRecords=!1,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/dist/node.cjs
CHANGED
|
@@ -32,6 +32,13 @@ class C1Type {}
|
|
|
32
32
|
const C1 = new C1Type();
|
|
33
33
|
C1.name = 'MessagePack 0xC1';
|
|
34
34
|
var sequentialMode = false;
|
|
35
|
+
var inlineObjectReadThreshold = 2;
|
|
36
|
+
try {
|
|
37
|
+
new Function('');
|
|
38
|
+
} catch(error) {
|
|
39
|
+
// if eval variants are not supported, do not create inline object readers ever
|
|
40
|
+
inlineObjectReadThreshold = Infinity;
|
|
41
|
+
}
|
|
35
42
|
|
|
36
43
|
class Unpackr {
|
|
37
44
|
constructor(options) {
|
|
@@ -442,7 +449,7 @@ const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
|
|
|
442
449
|
function createStructureReader(structure, firstId) {
|
|
443
450
|
function readObject() {
|
|
444
451
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
445
|
-
if (readObject.count++ >
|
|
452
|
+
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
446
453
|
let readObject = structure.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read);
|
|
447
454
|
if (structure.highByte === 0)
|
|
448
455
|
structure.read = createSecondByteReader(firstId, structure.read);
|
|
@@ -1090,6 +1097,9 @@ class Packr extends Unpackr {
|
|
|
1090
1097
|
maxSharedStructures = hasSharedStructures ? 32 : 0;
|
|
1091
1098
|
if (maxSharedStructures > 8160)
|
|
1092
1099
|
throw new Error('Maximum maxSharedStructure is 8160')
|
|
1100
|
+
if (options.structuredClone && options.moreTypes == undefined) {
|
|
1101
|
+
options.moreTypes = true;
|
|
1102
|
+
}
|
|
1093
1103
|
let maxOwnStructures = options.maxOwnStructures;
|
|
1094
1104
|
if (maxOwnStructures == null)
|
|
1095
1105
|
maxOwnStructures = hasSharedStructures ? 32 : 64;
|
|
@@ -1751,7 +1761,7 @@ extensions = [{
|
|
|
1751
1761
|
target[position++] = 0xd6;
|
|
1752
1762
|
target[position++] = 0xff;
|
|
1753
1763
|
targetView.setUint32(position, seconds);
|
|
1754
|
-
} else if (seconds > 0 && seconds <
|
|
1764
|
+
} else if (seconds > 0 && seconds < 0x100000000) {
|
|
1755
1765
|
// Timestamp 64
|
|
1756
1766
|
let { target, targetView, position} = allocateForWrite(10);
|
|
1757
1767
|
target[position++] = 0xd7;
|
|
@@ -1781,8 +1791,8 @@ extensions = [{
|
|
|
1781
1791
|
}, {
|
|
1782
1792
|
pack(set, allocateForWrite, pack) {
|
|
1783
1793
|
let array = Array.from(set);
|
|
1784
|
-
let { target, position} = allocateForWrite(this.
|
|
1785
|
-
if (this.
|
|
1794
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1795
|
+
if (this.moreTypes) {
|
|
1786
1796
|
target[position++] = 0xd4;
|
|
1787
1797
|
target[position++] = 0x73; // 's' for Set
|
|
1788
1798
|
target[position++] = 0;
|
|
@@ -1791,8 +1801,8 @@ extensions = [{
|
|
|
1791
1801
|
}
|
|
1792
1802
|
}, {
|
|
1793
1803
|
pack(error, allocateForWrite, pack) {
|
|
1794
|
-
let { target, position} = allocateForWrite(this.
|
|
1795
|
-
if (this.
|
|
1804
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1805
|
+
if (this.moreTypes) {
|
|
1796
1806
|
target[position++] = 0xd4;
|
|
1797
1807
|
target[position++] = 0x65; // 'e' for error
|
|
1798
1808
|
target[position++] = 0;
|
|
@@ -1801,8 +1811,8 @@ extensions = [{
|
|
|
1801
1811
|
}
|
|
1802
1812
|
}, {
|
|
1803
1813
|
pack(regex, allocateForWrite, pack) {
|
|
1804
|
-
let { target, position} = allocateForWrite(this.
|
|
1805
|
-
if (this.
|
|
1814
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1815
|
+
if (this.moreTypes) {
|
|
1806
1816
|
target[position++] = 0xd4;
|
|
1807
1817
|
target[position++] = 0x78; // 'x' for regeXp
|
|
1808
1818
|
target[position++] = 0;
|
|
@@ -1811,7 +1821,7 @@ extensions = [{
|
|
|
1811
1821
|
}
|
|
1812
1822
|
}, {
|
|
1813
1823
|
pack(arrayBuffer, allocateForWrite) {
|
|
1814
|
-
if (this.
|
|
1824
|
+
if (this.moreTypes)
|
|
1815
1825
|
writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
|
|
1816
1826
|
else
|
|
1817
1827
|
writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
|
|
@@ -1819,7 +1829,7 @@ extensions = [{
|
|
|
1819
1829
|
}, {
|
|
1820
1830
|
pack(typedArray, allocateForWrite) {
|
|
1821
1831
|
let constructor = typedArray.constructor;
|
|
1822
|
-
if (constructor !== ByteArray && this.
|
|
1832
|
+
if (constructor !== ByteArray && this.moreTypes)
|
|
1823
1833
|
writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite);
|
|
1824
1834
|
else
|
|
1825
1835
|
writeBuffer(typedArray, allocateForWrite);
|
|
@@ -2114,8 +2124,7 @@ function tryRequire(moduleId) {
|
|
|
2114
2124
|
let require$1 = module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node.cjs', document.baseURI).href)));
|
|
2115
2125
|
return require$1(moduleId)
|
|
2116
2126
|
} catch (error) {
|
|
2117
|
-
|
|
2118
|
-
console.warn('For browser usage, directly use msgpackr/unpack or msgpackr/pack modules. ' + error.message.split('\n')[0]);
|
|
2127
|
+
// native module is optional
|
|
2119
2128
|
}
|
|
2120
2129
|
}
|
|
2121
2130
|
|
package/dist/test.js
CHANGED
|
@@ -1,586 +1,9 @@
|
|
|
1
|
-
(function (msgpackr, chai) {
|
|
1
|
+
(function (msgpackr, chai, fs) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
chai = chai && Object.prototype.hasOwnProperty.call(chai, 'default') ? chai['default'] : chai;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
Designs: [
|
|
8
|
-
"Randomized Controlled Trial"
|
|
9
|
-
],
|
|
10
|
-
Types: [
|
|
11
|
-
],
|
|
12
|
-
BriefSummary: "To determine the efficacy, long-term safety, and tolerability of alirocumab 300 mg every 4\n weeks (Q4W), in comparison with placebo, as well as its potential as a starting regimen. The\n dose regimen of 75 mg every 2 weeks (Q2W), as used in other studies, was added as a\n calibrator.",
|
|
13
|
-
Abstract: "To determine the efficacy, long-term safety, and tolerability of alirocumab 300 mg every 4\n weeks (Q4W), in comparison with placebo, as well as its potential as a starting regimen. The\n dose regimen of 75 mg every 2 weeks (Q2W), as used in other studies, was added as a\n calibrator.",
|
|
14
|
-
Acronym: null,
|
|
15
|
-
ArticleId: "Qy3gwKWSoaWRmbmFEQA",
|
|
16
|
-
Authors: null,
|
|
17
|
-
CochraneID: null,
|
|
18
|
-
Confidential: false,
|
|
19
|
-
CorporateAuthor: null,
|
|
20
|
-
Country: "Bulgaria, Canada, Hungary, Israel, Norway, Slovakia, United Kingdom, United States",
|
|
21
|
-
CustomData: null,
|
|
22
|
-
DatabaseType: "ClinicalTrials.gov",
|
|
23
|
-
DOI: null,
|
|
24
|
-
EmbaseAccessionNumber: null,
|
|
25
|
-
Emtree: null,
|
|
26
|
-
ErrataText: null,
|
|
27
|
-
FullTextURL: null,
|
|
28
|
-
Institution: null,
|
|
29
|
-
ISSN: null,
|
|
30
|
-
Issue: null,
|
|
31
|
-
JournalTitle: null,
|
|
32
|
-
MedlineID: null,
|
|
33
|
-
MeSH: "Hypercholesterolemia|Antibodies, Monoclonal",
|
|
34
|
-
Pages: null,
|
|
35
|
-
ParentChildStatus: null,
|
|
36
|
-
ParentID: null,
|
|
37
|
-
PublicationDate: "March 21, 2017",
|
|
38
|
-
PublicationYear: 2017,
|
|
39
|
-
PubType: null,
|
|
40
|
-
ReferenceStudy: null,
|
|
41
|
-
SecondarySourceID: null,
|
|
42
|
-
Source: "Regeneron Pharmaceuticals",
|
|
43
|
-
SourceReferenceId: "NCT01926782",
|
|
44
|
-
TaStudyDesign: "Randomized",
|
|
45
|
-
Title: "A Randomized, Double-Blind, Placebo-Controlled Study to Evaluate the Efficacy and Safety of an Every Four Weeks Treatment Regimen of Alirocumab in Patients With Primary Hypercholesterolemia",
|
|
46
|
-
TrialOutcome: null,
|
|
47
|
-
Volume: null,
|
|
48
|
-
Id: 179246831,
|
|
49
|
-
Created: "2020-04-10T14:48:20.4384957Z",
|
|
50
|
-
VersionNo: 2,
|
|
51
|
-
ExtractData: null,
|
|
52
|
-
Digitized: true,
|
|
53
|
-
IsRapidExtract: false,
|
|
54
|
-
IsUploaded: false
|
|
55
|
-
};
|
|
56
|
-
var design = "Randomized Controlled Trial";
|
|
57
|
-
var conditions = [
|
|
58
|
-
{
|
|
59
|
-
label: "Cholesterol Total Increased",
|
|
60
|
-
id: "SUE_c"
|
|
61
|
-
}
|
|
62
|
-
];
|
|
63
|
-
var phase = 3;
|
|
64
|
-
var name = "NCT01926782";
|
|
65
|
-
var trialIds = [
|
|
66
|
-
"NCT01926782"
|
|
67
|
-
];
|
|
68
|
-
var acronyms = [
|
|
69
|
-
];
|
|
70
|
-
var outcomeCount = 156;
|
|
71
|
-
var id = 179246831;
|
|
72
|
-
var groups = [
|
|
73
|
-
{
|
|
74
|
-
Id: "4r",
|
|
75
|
-
RefId: "B5|O2~Alirocumab 75 mg Q2W/Up 150 mg Q2W Without Concomitant Statin",
|
|
76
|
-
OriginalName: "Alirocumab 75 mg Q2W/Up 150 mg Q2W Without Concomitant Statin",
|
|
77
|
-
N: 37,
|
|
78
|
-
age: 59.3,
|
|
79
|
-
ageSD: 11.3,
|
|
80
|
-
male: 37.83783783783784,
|
|
81
|
-
Interventions: [
|
|
82
|
-
{
|
|
83
|
-
termIds: [
|
|
84
|
-
[
|
|
85
|
-
"SUBYEL",
|
|
86
|
-
"SUB_Oc"
|
|
87
|
-
],
|
|
88
|
-
[
|
|
89
|
-
"SUNUVb"
|
|
90
|
-
]
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
],
|
|
94
|
-
analyzeAs: "Alirocumab",
|
|
95
|
-
analyzableScore: 1.0717734625362931,
|
|
96
|
-
matchingScore: 0
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
Id: "zB",
|
|
100
|
-
RefId: "B6|O3~Alirocumab 300 mg Q4W/Up 150 mg Q2W Without Concomitant Statin",
|
|
101
|
-
OriginalName: "Alirocumab 300 mg Q4W/Up 150 mg Q2W Without Concomitant Statin",
|
|
102
|
-
N: 146,
|
|
103
|
-
age: 59.2,
|
|
104
|
-
ageSD: 10.8,
|
|
105
|
-
male: 45.205479452054796,
|
|
106
|
-
Interventions: [
|
|
107
|
-
{
|
|
108
|
-
termIds: [
|
|
109
|
-
[
|
|
110
|
-
"SUBYEL",
|
|
111
|
-
"SUB_Oc"
|
|
112
|
-
]
|
|
113
|
-
]
|
|
114
|
-
}
|
|
115
|
-
],
|
|
116
|
-
analyzeAs: "Statins",
|
|
117
|
-
analyzableScore: 1.0717734625362931,
|
|
118
|
-
matchingScore: 0
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
Id: "3!",
|
|
122
|
-
RefId: "B4|O1~Placebo Q2W Without Concomitant Statin",
|
|
123
|
-
OriginalName: "Placebo Q2W Without Concomitant Statin",
|
|
124
|
-
N: 73,
|
|
125
|
-
age: 59.4,
|
|
126
|
-
ageSD: 10.2,
|
|
127
|
-
male: 54.794520547945204,
|
|
128
|
-
Interventions: [
|
|
129
|
-
{
|
|
130
|
-
termIds: [
|
|
131
|
-
[
|
|
132
|
-
"SUGeLS"
|
|
133
|
-
],
|
|
134
|
-
[
|
|
135
|
-
"SUBYEL",
|
|
136
|
-
"SUB_Oc"
|
|
137
|
-
]
|
|
138
|
-
]
|
|
139
|
-
}
|
|
140
|
-
],
|
|
141
|
-
analyzeAs: "Control",
|
|
142
|
-
analyzableScore: 1.2020833333333334,
|
|
143
|
-
matchingScore: 0
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
Id: "tv",
|
|
147
|
-
RefId: "E3",
|
|
148
|
-
OriginalName: "Alirocumab 300 mg Q4W/Up 150 mg Q2W",
|
|
149
|
-
Interventions: [
|
|
150
|
-
{
|
|
151
|
-
termIds: [
|
|
152
|
-
[
|
|
153
|
-
"SUCO54",
|
|
154
|
-
"SUNUVb"
|
|
155
|
-
]
|
|
156
|
-
]
|
|
157
|
-
}
|
|
158
|
-
]
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
Id: "jt",
|
|
162
|
-
RefId: "B3|O3~Alirocumab 300 mg Q4W/Up 150 mg Q2W With Concomitant Statin",
|
|
163
|
-
OriginalName: "Alirocumab 300 mg Q4W/Up 150 mg Q2W With Concomitant Statin",
|
|
164
|
-
N: 312,
|
|
165
|
-
age: 61.6,
|
|
166
|
-
ageSD: 10,
|
|
167
|
-
male: 60.8974358974359,
|
|
168
|
-
Interventions: [
|
|
169
|
-
{
|
|
170
|
-
termIds: [
|
|
171
|
-
[
|
|
172
|
-
"SUBYEL",
|
|
173
|
-
"SUB_Oc"
|
|
174
|
-
]
|
|
175
|
-
]
|
|
176
|
-
}
|
|
177
|
-
]
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
Id: "5!",
|
|
181
|
-
RefId: "E2",
|
|
182
|
-
OriginalName: "Alirocumab 75 mg Q2W/Up 150 mg Q2W",
|
|
183
|
-
Interventions: [
|
|
184
|
-
{
|
|
185
|
-
termIds: [
|
|
186
|
-
[
|
|
187
|
-
"SUNUVb"
|
|
188
|
-
]
|
|
189
|
-
]
|
|
190
|
-
}
|
|
191
|
-
]
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
Id: "4E",
|
|
195
|
-
RefId: "B2|O2~Alirocumab 75 mg Q2W/Up 150 mg Q2W With Concomitant Statin",
|
|
196
|
-
OriginalName: "Alirocumab 75 mg Q2W/Up 150 mg Q2W With Concomitant Statin",
|
|
197
|
-
N: 78,
|
|
198
|
-
age: 60.7,
|
|
199
|
-
ageSD: 9.1,
|
|
200
|
-
male: 65.38461538461539,
|
|
201
|
-
Interventions: [
|
|
202
|
-
{
|
|
203
|
-
termIds: [
|
|
204
|
-
[
|
|
205
|
-
"SUBYEL",
|
|
206
|
-
"SUB_Oc"
|
|
207
|
-
],
|
|
208
|
-
[
|
|
209
|
-
"SUNUVb"
|
|
210
|
-
]
|
|
211
|
-
]
|
|
212
|
-
}
|
|
213
|
-
]
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
Id: "i4",
|
|
217
|
-
Interventions: [
|
|
218
|
-
{
|
|
219
|
-
Id: "Ya",
|
|
220
|
-
Name: 178613599,
|
|
221
|
-
Treatments: [
|
|
222
|
-
{
|
|
223
|
-
Id: "((",
|
|
224
|
-
Phase: "k)"
|
|
225
|
-
}
|
|
226
|
-
],
|
|
227
|
-
Type: "Drug",
|
|
228
|
-
termIds: [
|
|
229
|
-
[
|
|
230
|
-
"SUGeLS"
|
|
231
|
-
],
|
|
232
|
-
[
|
|
233
|
-
"SUNUVb"
|
|
234
|
-
]
|
|
235
|
-
],
|
|
236
|
-
terms: [
|
|
237
|
-
[
|
|
238
|
-
"Placebo"
|
|
239
|
-
],
|
|
240
|
-
[
|
|
241
|
-
"Alirocumab"
|
|
242
|
-
]
|
|
243
|
-
]
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
Id: "o)",
|
|
247
|
-
Name: 2159990,
|
|
248
|
-
Treatments: [
|
|
249
|
-
{
|
|
250
|
-
Id: "1$",
|
|
251
|
-
Phase: "k)"
|
|
252
|
-
}
|
|
253
|
-
],
|
|
254
|
-
Type: "Drug",
|
|
255
|
-
termIds: [
|
|
256
|
-
[
|
|
257
|
-
"SUBYEL"
|
|
258
|
-
]
|
|
259
|
-
],
|
|
260
|
-
terms: [
|
|
261
|
-
[
|
|
262
|
-
"Statins"
|
|
263
|
-
]
|
|
264
|
-
]
|
|
265
|
-
}
|
|
266
|
-
],
|
|
267
|
-
RefId: "E1|Placebo Q2W",
|
|
268
|
-
OriginalName: "Placebo Q2W"
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
Id: "Ls",
|
|
272
|
-
RefId: "B1|O1~Placebo Q2W With Concomitant Statin",
|
|
273
|
-
OriginalName: "Placebo Q2W With Concomitant Statin",
|
|
274
|
-
N: 157,
|
|
275
|
-
age: 61.6,
|
|
276
|
-
ageSD: 9.7,
|
|
277
|
-
male: 64.3312101910828,
|
|
278
|
-
Interventions: [
|
|
279
|
-
{
|
|
280
|
-
termIds: [
|
|
281
|
-
[
|
|
282
|
-
"SUGeLS"
|
|
283
|
-
],
|
|
284
|
-
[
|
|
285
|
-
"SUBYEL",
|
|
286
|
-
"SUB_Oc"
|
|
287
|
-
]
|
|
288
|
-
]
|
|
289
|
-
}
|
|
290
|
-
]
|
|
291
|
-
}
|
|
292
|
-
];
|
|
293
|
-
var hasDocData = true;
|
|
294
|
-
var hasRapidExtract = false;
|
|
295
|
-
var N = 803;
|
|
296
|
-
var queryScore = 1.4868329805051381;
|
|
297
|
-
var matchingScore = 7.960635921410255;
|
|
298
|
-
var score = 22.084654254966498;
|
|
299
|
-
var outcomes = [
|
|
300
|
-
{
|
|
301
|
-
id: "179246387",
|
|
302
|
-
type: "Change",
|
|
303
|
-
unit: "%",
|
|
304
|
-
termIds: [
|
|
305
|
-
[
|
|
306
|
-
"SUF0R",
|
|
307
|
-
"SUBskP"
|
|
308
|
-
]
|
|
309
|
-
],
|
|
310
|
-
quantifiers: [
|
|
311
|
-
],
|
|
312
|
-
name: "Calculated LDL-C in Not Receiving Concomitant Statin Therapy - On-Treatment Analysis",
|
|
313
|
-
cells: [
|
|
314
|
-
{
|
|
315
|
-
number: -0.4,
|
|
316
|
-
unit: "%",
|
|
317
|
-
group: "3!",
|
|
318
|
-
varType: "se",
|
|
319
|
-
N: 70,
|
|
320
|
-
se: 2,
|
|
321
|
-
sd: 16.73
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
number: -54.6,
|
|
325
|
-
unit: "%",
|
|
326
|
-
group: "4r",
|
|
327
|
-
varType: "se",
|
|
328
|
-
N: 37,
|
|
329
|
-
se: 2.8,
|
|
330
|
-
sd: 17.03
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
number: -59.4,
|
|
334
|
-
unit: "%",
|
|
335
|
-
group: "zB",
|
|
336
|
-
varType: "se",
|
|
337
|
-
N: 141,
|
|
338
|
-
se: 1.4,
|
|
339
|
-
sd: 16.62
|
|
340
|
-
}
|
|
341
|
-
],
|
|
342
|
-
time: {
|
|
343
|
-
Id: 67122072,
|
|
344
|
-
Low: {
|
|
345
|
-
Value: "Baseline"
|
|
346
|
-
},
|
|
347
|
-
High: {
|
|
348
|
-
"Number": 24,
|
|
349
|
-
Unit: "wk"
|
|
350
|
-
},
|
|
351
|
-
Type: "Total",
|
|
352
|
-
days: 168,
|
|
353
|
-
description: "24wk"
|
|
354
|
-
},
|
|
355
|
-
score: 2.08,
|
|
356
|
-
matchingTerm: "SUF0R",
|
|
357
|
-
suggestedPositive: false,
|
|
358
|
-
sourceUnit: "%"
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
id: "179246389",
|
|
362
|
-
type: "Change",
|
|
363
|
-
unit: "%",
|
|
364
|
-
termIds: [
|
|
365
|
-
[
|
|
366
|
-
"SUF0R",
|
|
367
|
-
"SUBskP"
|
|
368
|
-
]
|
|
369
|
-
],
|
|
370
|
-
quantifiers: [
|
|
371
|
-
],
|
|
372
|
-
name: "Calculated LDL-C in Receiving Concomitant Statin Therapy - On-Treatment Analysis",
|
|
373
|
-
cells: [
|
|
374
|
-
{
|
|
375
|
-
number: -0.3,
|
|
376
|
-
unit: "%",
|
|
377
|
-
group: "Ls",
|
|
378
|
-
varType: "se",
|
|
379
|
-
N: 151,
|
|
380
|
-
se: 2.1,
|
|
381
|
-
sd: 25.81
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
number: -55.1,
|
|
385
|
-
unit: "%",
|
|
386
|
-
group: "4E",
|
|
387
|
-
varType: "se",
|
|
388
|
-
N: 75,
|
|
389
|
-
se: 3,
|
|
390
|
-
sd: 25.98
|
|
391
|
-
},
|
|
392
|
-
{
|
|
393
|
-
number: -62.3,
|
|
394
|
-
unit: "%",
|
|
395
|
-
group: "jt",
|
|
396
|
-
varType: "se",
|
|
397
|
-
N: 302,
|
|
398
|
-
se: 1.5,
|
|
399
|
-
sd: 26.07
|
|
400
|
-
}
|
|
401
|
-
],
|
|
402
|
-
time: {
|
|
403
|
-
Id: 67122072,
|
|
404
|
-
Low: {
|
|
405
|
-
Value: "Baseline"
|
|
406
|
-
},
|
|
407
|
-
High: {
|
|
408
|
-
"Number": 24,
|
|
409
|
-
Unit: "wk"
|
|
410
|
-
},
|
|
411
|
-
Type: "Total",
|
|
412
|
-
days: 168,
|
|
413
|
-
description: "24wk"
|
|
414
|
-
},
|
|
415
|
-
score: 2.08,
|
|
416
|
-
matchingTerm: "SUF0R",
|
|
417
|
-
suggestedPositive: false,
|
|
418
|
-
sourceUnit: "%"
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
id: "179246393",
|
|
422
|
-
type: "Change",
|
|
423
|
-
unit: "%",
|
|
424
|
-
termIds: [
|
|
425
|
-
[
|
|
426
|
-
"SUF0R",
|
|
427
|
-
"SUBskP"
|
|
428
|
-
]
|
|
429
|
-
],
|
|
430
|
-
quantifiers: [
|
|
431
|
-
],
|
|
432
|
-
name: "Calculated LDL-C in Not Receiving Concomitant Statin Therapy - On-Treatment Analysis",
|
|
433
|
-
cells: [
|
|
434
|
-
{
|
|
435
|
-
number: -0.5,
|
|
436
|
-
unit: "%",
|
|
437
|
-
group: "3!",
|
|
438
|
-
varType: "se",
|
|
439
|
-
N: 70,
|
|
440
|
-
se: 2,
|
|
441
|
-
sd: 16.73
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
number: -53.9,
|
|
445
|
-
unit: "%",
|
|
446
|
-
group: "4r",
|
|
447
|
-
varType: "se",
|
|
448
|
-
N: 37,
|
|
449
|
-
se: 2.7,
|
|
450
|
-
sd: 16.42
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
number: -60,
|
|
454
|
-
unit: "%",
|
|
455
|
-
group: "zB",
|
|
456
|
-
varType: "se",
|
|
457
|
-
N: 141,
|
|
458
|
-
se: 1.4,
|
|
459
|
-
sd: 16.62
|
|
460
|
-
}
|
|
461
|
-
],
|
|
462
|
-
time: {
|
|
463
|
-
Id: 67122069,
|
|
464
|
-
Low: {
|
|
465
|
-
Value: "Baseline"
|
|
466
|
-
},
|
|
467
|
-
High: {
|
|
468
|
-
"Number": 12,
|
|
469
|
-
Unit: "wk"
|
|
470
|
-
},
|
|
471
|
-
Type: "Total",
|
|
472
|
-
days: 84,
|
|
473
|
-
description: "12wk"
|
|
474
|
-
},
|
|
475
|
-
score: 2.08,
|
|
476
|
-
matchingTerm: "SUF0R",
|
|
477
|
-
suggestedPositive: false,
|
|
478
|
-
sourceUnit: "%"
|
|
479
|
-
},
|
|
480
|
-
{
|
|
481
|
-
id: "179246394",
|
|
482
|
-
type: "Change",
|
|
483
|
-
unit: "%",
|
|
484
|
-
termIds: [
|
|
485
|
-
[
|
|
486
|
-
"SUF0R",
|
|
487
|
-
"SUBskP"
|
|
488
|
-
]
|
|
489
|
-
],
|
|
490
|
-
quantifiers: [
|
|
491
|
-
],
|
|
492
|
-
name: "Calculated LDL-C in Receiving Concomitant Statin Therapy - On-Treatment Analysis",
|
|
493
|
-
cells: [
|
|
494
|
-
{
|
|
495
|
-
number: 1.4,
|
|
496
|
-
unit: "%",
|
|
497
|
-
group: "Ls",
|
|
498
|
-
varType: "se",
|
|
499
|
-
N: 151,
|
|
500
|
-
se: 1.9,
|
|
501
|
-
sd: 23.35
|
|
502
|
-
},
|
|
503
|
-
{
|
|
504
|
-
number: -47.3,
|
|
505
|
-
unit: "%",
|
|
506
|
-
group: "4E",
|
|
507
|
-
varType: "se",
|
|
508
|
-
N: 75,
|
|
509
|
-
se: 2.8,
|
|
510
|
-
sd: 24.25
|
|
511
|
-
},
|
|
512
|
-
{
|
|
513
|
-
number: -58,
|
|
514
|
-
unit: "%",
|
|
515
|
-
group: "jt",
|
|
516
|
-
varType: "se",
|
|
517
|
-
N: 302,
|
|
518
|
-
se: 1.4,
|
|
519
|
-
sd: 24.33
|
|
520
|
-
}
|
|
521
|
-
],
|
|
522
|
-
time: {
|
|
523
|
-
Id: 67122069,
|
|
524
|
-
Low: {
|
|
525
|
-
Value: "Baseline"
|
|
526
|
-
},
|
|
527
|
-
High: {
|
|
528
|
-
"Number": 12,
|
|
529
|
-
Unit: "wk"
|
|
530
|
-
},
|
|
531
|
-
Type: "Total",
|
|
532
|
-
days: 84,
|
|
533
|
-
description: "12wk"
|
|
534
|
-
},
|
|
535
|
-
score: 2.08,
|
|
536
|
-
matchingTerm: "SUF0R",
|
|
537
|
-
suggestedPositive: false,
|
|
538
|
-
sourceUnit: "%"
|
|
539
|
-
}
|
|
540
|
-
];
|
|
541
|
-
var characteristics = [
|
|
542
|
-
{
|
|
543
|
-
id: "179246354",
|
|
544
|
-
type: "Binary",
|
|
545
|
-
isCharacteristic: true,
|
|
546
|
-
termIds: [
|
|
547
|
-
[
|
|
548
|
-
"SUE_c",
|
|
549
|
-
"SUCbN",
|
|
550
|
-
"SUyJj"
|
|
551
|
-
]
|
|
552
|
-
],
|
|
553
|
-
quantifiers: [
|
|
554
|
-
],
|
|
555
|
-
name: "Patients not having adequate control of their hypercholesterolemia based on their individual level of CVD risk",
|
|
556
|
-
cells: [
|
|
557
|
-
],
|
|
558
|
-
number: 100
|
|
559
|
-
}
|
|
560
|
-
];
|
|
561
|
-
var outcomesScore = 18.97947630112307;
|
|
562
|
-
var sampleData = {
|
|
563
|
-
metadata: metadata,
|
|
564
|
-
design: design,
|
|
565
|
-
conditions: conditions,
|
|
566
|
-
phase: phase,
|
|
567
|
-
name: name,
|
|
568
|
-
trialIds: trialIds,
|
|
569
|
-
acronyms: acronyms,
|
|
570
|
-
outcomeCount: outcomeCount,
|
|
571
|
-
id: id,
|
|
572
|
-
groups: groups,
|
|
573
|
-
hasDocData: hasDocData,
|
|
574
|
-
hasRapidExtract: hasRapidExtract,
|
|
575
|
-
N: N,
|
|
576
|
-
queryScore: queryScore,
|
|
577
|
-
matchingScore: matchingScore,
|
|
578
|
-
score: score,
|
|
579
|
-
outcomes: outcomes,
|
|
580
|
-
characteristics: characteristics,
|
|
581
|
-
outcomesScore: outcomesScore
|
|
582
|
-
};
|
|
583
|
-
|
|
6
|
+
const sampleData = JSON.parse(fs.readFileSync(new URL('./example4.json', (document.currentScript && document.currentScript.src || new URL('test.js', document.baseURI).href))));
|
|
584
7
|
function tryRequire(module) {
|
|
585
8
|
try {
|
|
586
9
|
return require(module)
|
|
@@ -859,6 +282,7 @@
|
|
|
859
282
|
object.children[2] = object.children[0];
|
|
860
283
|
object.childrenAgain = object.children;
|
|
861
284
|
let packr = new Packr({
|
|
285
|
+
moreTypes: true,
|
|
862
286
|
structuredClone: true,
|
|
863
287
|
});
|
|
864
288
|
var serialized = packr.pack(object);
|
|
@@ -883,6 +307,7 @@
|
|
|
883
307
|
uint16Array: new Uint16Array([3,4])
|
|
884
308
|
};
|
|
885
309
|
let packr = new Packr({
|
|
310
|
+
moreTypes: true,
|
|
886
311
|
structuredClone: true,
|
|
887
312
|
});
|
|
888
313
|
var serialized = packr.pack(object);
|
|
@@ -1014,6 +439,7 @@
|
|
|
1014
439
|
map: map,
|
|
1015
440
|
date: new Date(1532219539733),
|
|
1016
441
|
farFutureDate: new Date(3532219539133),
|
|
442
|
+
fartherFutureDate: new Date('2106-08-05T18:48:20.323Z'),
|
|
1017
443
|
ancient: new Date(-3532219539133),
|
|
1018
444
|
invalidDate: new Date('invalid')
|
|
1019
445
|
};
|
|
@@ -1024,6 +450,7 @@
|
|
|
1024
450
|
assert.equal(deserialized.map.get('three'), 3);
|
|
1025
451
|
assert.equal(deserialized.date.getTime(), 1532219539733);
|
|
1026
452
|
assert.equal(deserialized.farFutureDate.getTime(), 3532219539133);
|
|
453
|
+
assert.equal(deserialized.fartherFutureDate.toISOString(), '2106-08-05T18:48:20.323Z');
|
|
1027
454
|
assert.equal(deserialized.ancient.getTime(), -3532219539133);
|
|
1028
455
|
assert.equal(deserialized.invalidDate.toString(), 'Invalid Date');
|
|
1029
456
|
});
|
|
@@ -1252,4 +679,4 @@
|
|
|
1252
679
|
});
|
|
1253
680
|
});
|
|
1254
681
|
|
|
1255
|
-
}(msgpackr, chai));
|
|
682
|
+
}(msgpackr, chai, fs));
|
package/node-index.js
CHANGED
|
@@ -16,7 +16,6 @@ function tryRequire(moduleId) {
|
|
|
16
16
|
let require = createRequire(import.meta.url)
|
|
17
17
|
return require(moduleId)
|
|
18
18
|
} catch (error) {
|
|
19
|
-
|
|
20
|
-
console.warn('For browser usage, directly use msgpackr/unpack or msgpackr/pack modules. ' + error.message.split('\n')[0])
|
|
19
|
+
// native module is optional
|
|
21
20
|
}
|
|
22
21
|
}
|
package/pack.js
CHANGED
|
@@ -44,6 +44,9 @@ export class Packr extends Unpackr {
|
|
|
44
44
|
maxSharedStructures = hasSharedStructures ? 32 : 0
|
|
45
45
|
if (maxSharedStructures > 8160)
|
|
46
46
|
throw new Error('Maximum maxSharedStructure is 8160')
|
|
47
|
+
if (options.structuredClone && options.moreTypes == undefined) {
|
|
48
|
+
options.moreTypes = true
|
|
49
|
+
}
|
|
47
50
|
let maxOwnStructures = options.maxOwnStructures
|
|
48
51
|
if (maxOwnStructures == null)
|
|
49
52
|
maxOwnStructures = hasSharedStructures ? 32 : 64
|
|
@@ -711,7 +714,7 @@ extensions = [{
|
|
|
711
714
|
target[position++] = 0xd6
|
|
712
715
|
target[position++] = 0xff
|
|
713
716
|
targetView.setUint32(position, seconds)
|
|
714
|
-
} else if (seconds > 0 && seconds <
|
|
717
|
+
} else if (seconds > 0 && seconds < 0x100000000) {
|
|
715
718
|
// Timestamp 64
|
|
716
719
|
let { target, targetView, position} = allocateForWrite(10)
|
|
717
720
|
target[position++] = 0xd7
|
|
@@ -741,8 +744,8 @@ extensions = [{
|
|
|
741
744
|
}, {
|
|
742
745
|
pack(set, allocateForWrite, pack) {
|
|
743
746
|
let array = Array.from(set)
|
|
744
|
-
let { target, position} = allocateForWrite(this.
|
|
745
|
-
if (this.
|
|
747
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
|
|
748
|
+
if (this.moreTypes) {
|
|
746
749
|
target[position++] = 0xd4
|
|
747
750
|
target[position++] = 0x73 // 's' for Set
|
|
748
751
|
target[position++] = 0
|
|
@@ -751,8 +754,8 @@ extensions = [{
|
|
|
751
754
|
}
|
|
752
755
|
}, {
|
|
753
756
|
pack(error, allocateForWrite, pack) {
|
|
754
|
-
let { target, position} = allocateForWrite(this.
|
|
755
|
-
if (this.
|
|
757
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
|
|
758
|
+
if (this.moreTypes) {
|
|
756
759
|
target[position++] = 0xd4
|
|
757
760
|
target[position++] = 0x65 // 'e' for error
|
|
758
761
|
target[position++] = 0
|
|
@@ -761,8 +764,8 @@ extensions = [{
|
|
|
761
764
|
}
|
|
762
765
|
}, {
|
|
763
766
|
pack(regex, allocateForWrite, pack) {
|
|
764
|
-
let { target, position} = allocateForWrite(this.
|
|
765
|
-
if (this.
|
|
767
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
|
|
768
|
+
if (this.moreTypes) {
|
|
766
769
|
target[position++] = 0xd4
|
|
767
770
|
target[position++] = 0x78 // 'x' for regeXp
|
|
768
771
|
target[position++] = 0
|
|
@@ -771,7 +774,7 @@ extensions = [{
|
|
|
771
774
|
}
|
|
772
775
|
}, {
|
|
773
776
|
pack(arrayBuffer, allocateForWrite) {
|
|
774
|
-
if (this.
|
|
777
|
+
if (this.moreTypes)
|
|
775
778
|
writeExtBuffer(arrayBuffer, 0x10, allocateForWrite)
|
|
776
779
|
else
|
|
777
780
|
writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite)
|
|
@@ -779,7 +782,7 @@ extensions = [{
|
|
|
779
782
|
}, {
|
|
780
783
|
pack(typedArray, allocateForWrite) {
|
|
781
784
|
let constructor = typedArray.constructor
|
|
782
|
-
if (constructor !== ByteArray && this.
|
|
785
|
+
if (constructor !== ByteArray && this.moreTypes)
|
|
783
786
|
writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite)
|
|
784
787
|
else
|
|
785
788
|
writeBuffer(typedArray, allocateForWrite)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msgpackr",
|
|
3
3
|
"author": "Kris Zyp",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.7",
|
|
5
5
|
"description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "./index.d.ts",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"/*.ts"
|
|
57
57
|
],
|
|
58
58
|
"optionalDependencies": {
|
|
59
|
-
"msgpackr-extract": "^1.
|
|
59
|
+
"msgpackr-extract": "^1.1.4"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@rollup/plugin-json": "^4.1.0",
|
package/unpack.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface Options {
|
|
|
9
9
|
useFloat32?: FLOAT32_OPTIONS
|
|
10
10
|
useRecords?: boolean
|
|
11
11
|
structures?: {}[]
|
|
12
|
+
moreTypes?: boolean
|
|
12
13
|
structuredClone?: boolean
|
|
13
14
|
mapsAsObjects?: boolean
|
|
14
15
|
variableMapSize?: boolean
|
|
@@ -19,6 +20,7 @@ export interface Options {
|
|
|
19
20
|
encodeUndefinedAsNil?: boolean
|
|
20
21
|
maxSharedStructures?: number
|
|
21
22
|
maxOwnStructures?: number
|
|
23
|
+
int64AsNumber?: boolean
|
|
22
24
|
shouldShareStructure?: (keys: string[]) => boolean
|
|
23
25
|
getStructures?(): {}[]
|
|
24
26
|
saveStructures?(structures: {}[]): boolean | void
|
package/unpack.js
CHANGED
|
@@ -27,6 +27,13 @@ export class C1Type {}
|
|
|
27
27
|
export const C1 = new C1Type()
|
|
28
28
|
C1.name = 'MessagePack 0xC1'
|
|
29
29
|
var sequentialMode = false
|
|
30
|
+
var inlineObjectReadThreshold = 2
|
|
31
|
+
try {
|
|
32
|
+
new Function('')
|
|
33
|
+
} catch(error) {
|
|
34
|
+
// if eval variants are not supported, do not create inline object readers ever
|
|
35
|
+
inlineObjectReadThreshold = Infinity
|
|
36
|
+
}
|
|
30
37
|
|
|
31
38
|
export class Unpackr {
|
|
32
39
|
constructor(options) {
|
|
@@ -440,7 +447,7 @@ const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/
|
|
|
440
447
|
function createStructureReader(structure, firstId) {
|
|
441
448
|
function readObject() {
|
|
442
449
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
443
|
-
if (readObject.count++ >
|
|
450
|
+
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
444
451
|
let readObject = structure.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read)
|
|
445
452
|
if (structure.highByte === 0)
|
|
446
453
|
structure.read = createSecondByteReader(firstId, structure.read)
|