msgpackr 1.7.0 → 1.7.1

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.min.js CHANGED
@@ -1,7 +1,7 @@
1
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(e){try{if(!F.trusted&&!q){let e=M.sharedLength||0;e<M.length&&(M.length=e)}let t;if(F.randomAccessStructure&&64>R[z]&&32<=R[z]&&Y?(t=Y(R,z,E,F),R=null,!(e&&e.lazy)&&t&&(t=t.toJSON()),z=E):t=s(),C&&(// bundled strings to skip past
2
- z=C.postBundlePosition),z==E)M?.restoreStructures&&r(),M=null,R=null,D&&(D=null);else if(z>E)// over read
2
+ z=C.postBundlePosition),z==E)M&&M.restoreStructures&&r(),M=null,R=null,D&&(D=null);else if(z>E)// over read
3
3
  throw new Error("Unexpected end of MessagePack data");else if(!q)throw new Error("Data read, but end of buffer not reached "+JSON.stringify(t).slice(0,100));// else more to read, but we are reading sequentially, so don't clear source yet
4
- return t}catch(e){throw M?.restoreStructures&&r(),m(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||z>E)&&(e.incomplete=!0),e}}function r(){for(let e in M.restoreStructures)M[e]=M.restoreStructures[e];M.restoreStructures=null}function s(){let e=R[z++];if(160>e){if(!(128>e)){if(!(144>e)){e-=144;let t=Array(e);for(let n=0;n<e;n++)t[n]=s();return F.freezeData?Object.freeze(t):t}if(e-=128,F.mapsAsObjects){let t={};for(let n,r=0;r<e;r++)n=h(),"__proto__"===n&&(n="__proto_"),t[n]=s();return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(s(),s());return t}}else if(64>e)return e;else{let t=M[63&e]||F.getStructures&&o()[63&e];return t?(t.read||(t.read=i(t,63&e)),t.read()):e}}else if(192>e){// fixstr
4
+ return t}catch(e){throw M&&M.restoreStructures&&r(),m(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||z>E)&&(e.incomplete=!0),e}}function r(){for(let e in M.restoreStructures)M[e]=M.restoreStructures[e];M.restoreStructures=null}function s(){let e=R[z++];if(160>e){if(!(128>e)){if(!(144>e)){e-=144;let t=Array(e);for(let n=0;n<e;n++)t[n]=s();return F.freezeData?Object.freeze(t):t}if(e-=128,F.mapsAsObjects){let t={};for(let n,r=0;r<e;r++)n=h(),"__proto__"===n&&(n="__proto_"),t[n]=s();return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(s(),s());return t}}else if(64>e)return e;else{let t=M[63&e]||F.getStructures&&o()[63&e];return t?(t.read||(t.read=i(t,63&e)),t.read()):e}}else if(192>e){// fixstr
5
5
  let t=e-160;if(N>=z)return B.slice(z-P,(z+=t)-P);if(0==N&&140>E){// for small blocks, avoiding the overhead of the extract call is helpful
6
6
  let e=16>t?g(t):c(t);if(null!=e)return e}return K(t)}else{let t;switch(e){case 192:return null;case 193:return C?(t=s(),0<t?C[1].slice(C.position1,C.position1+=t):C[0].slice(C.position0,C.position0-=t)):W;// "never-used", return special object to denote that
7
7
  case 194:return!1;case 195:return!0;case 196:if(t=R[z++],void 0===t)throw new Error("Unexpected end of buffer");return l(t);case 197:return t=T.getUint16(z),z+=2,l(t);case 198:return t=T.getUint32(z),z+=4,l(t);case 199:// ext 8
@@ -29,7 +29,7 @@ function y(e){let t=E,n=z,r=P,s=N,i=B,o=D,a=C,u=new Uint8Array(R.slice(0,E)),d=M
29
29
  s[i++]=201,o.setUint32(i,r+1),i+=4}// "t" for typed array
30
30
  s[i++]=116,s[i++]=t,s.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),i)}function k(e,t){let n=e.byteLength;var r,s;if(256>n){var{target:r,position:s}=t(n+2);r[s++]=196,r[s++]=n}else if(65536>n){var{target:r,position:s}=t(n+3);r[s++]=197,r[s++]=n>>8,r[s++]=255&n}else{var{target:r,position:s,targetView:i}=t(n+5);r[s++]=198,i.setUint32(s,n),s+=4}r.set(e,s)}function U(e,t,n,r){let s=e.length;return 1===s?t[n++]=212:2===s?t[n++]=213:4===s?t[n++]=214:8===s?t[n++]=215:16===s?t[n++]=216:256>s?(t[n++]=199,t[n++]=s):65536>s?(t[n++]=200,t[n++]=s>>8,t[n++]=255&s):(t[n++]=201,t[n++]=s>>24,t[n++]=255&s>>16,t[n++]=255&s>>8,t[n++]=255&s),t[n++]=r,t.set(e,n),n+=s,n}function _(e,t){// insert the ids that need to be referenced for structured clones
31
31
  let n,r=6*t.length,s=e.length-r;for(t.sort((e,t)=>e.offset>t.offset?1:-1);n=t.pop();){let t=n.offset,i=n.id;e.copyWithin(t+r,t,s),r-=6;let o=t+r;// 'i'
32
- e[o++]=214,e[o++]=105,e[o++]=i>>24,e[o++]=255&i>>16,e[o++]=255&i>>8,e[o++]=255&i,s=t}return e}function I(e,t){if(0<we.length){_e.setUint32(we.position+e,Ae-we.position-e);let n=we;we=null,t(n[0]),t(n[1])}}function O(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)");he.unshift(e.Class),fe.unshift(e)}b(e)}function A(e,t){return e.isCompatible=e=>{let n=!e||(t.lastNamedStructuresLength||0)===e.length;return n||// we want to merge these existing structures immediately since we already have it and we are in the right transaction
32
+ e[o++]=214,e[o++]=105,e[o++]=i>>24,e[o++]=255&i>>16,e[o++]=255&i>>8,e[o++]=255&i,s=t}return e}function I(e,t,n){if(0<we.length){_e.setUint32(we.position+e,Ae+n-we.position-e);let r=we;we=null,t(r[0]),t(r[1])}}function O(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)");he.unshift(e.Class),fe.unshift(e)}b(e)}function A(e,t){return e.isCompatible=e=>{let n=!e||(t.lastNamedStructuresLength||0)===e.length;return n||// we want to merge these existing structures immediately since we already have it and we are in the right transaction
33
33
  t._mergeStructures(e),n},e}function*w(e,t){const n=new xe(t);for(const r of e)yield n.pack(r)}async function*L(e,t){const n=new xe(t);for await(const r of e)yield n.pack(r)}/**
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.
@@ -50,8 +50,8 @@ let e=T.getUint32(z-4),t=D.get(e);return t.used=!0,t.target},j[115]=()=>new Set(
50
50
  return new globalThis[n](Uint8Array.prototype.slice.call(e,1).buffer)},j[120]=()=>{let e=s();return new RegExp(e[0],e[1])};const se=[];j[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=z;return z+=t-e.length,C=se,C=[p(),p()],C.position0=0,C.position1=0,C.postBundlePosition=z,z=n,s()},j[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 ie=Array(147);// this is a table matching binary exponents to the multiplier to determine significant digit rounding
51
51
  for(let n=0;256>n;n++)ie[n]=+("1e"+t(45.15-.30103*n));var oe=new J({useRecords:!1});const ae=oe.unpack,ue=oe.unpackMultiple,de=oe.unpack,ce={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let ge,pe=new Float32Array(1),le=new Uint8Array(pe.buffer,0,4);try{ge=new TextEncoder}catch(e){}let fe,he;const ye="undefined"!=typeof Buffer,me=ye?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,be=ye?Buffer:Uint8Array,Se=ye?4294967296:2144337920;let ke,Ue,_e,Ie,Oe,Ae=0,we=null;const Le=Symbol("record-id");class xe extends J{constructor(e){super(e),this.offset=0;let t,n,r,s,i=be.prototype.utf8Write?function(e,t){return ke.utf8Write(e,t,4294967295)}:!!(ge&&ge.encodeInto)&&function(e,t){return ge.encodeInto(e,ke.subarray(t)).written},o=this;e||(e={});let a=e&&e.sequential,u=e.structures||e.saveStructures,d=e.maxSharedStructures;if(null==d&&(d=u?32:0),8160<d)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&null==e.moreTypes&&(e.moreTypes=!0);let c=e.maxOwnStructures;null==c&&(c=u?32:64),this.structures||!1==e.useRecords||(this.structures=[]);// two byte record ids for shared structures
52
52
  let g=32<d||64<c+d,p=d+64,l=d+c+64;if(8256<l)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let f=[],h=0,y=0;this.pack=this.encode=function(e,i){if(ke||(ke=new me(8192),_e=ke.dataView=new DataView(ke.buffer,0,8192),Ae=0),Ie=ke.length-10,2048>Ie-Ae?(ke=new me(ke.length),_e=ke.dataView=new DataView(ke.buffer,0,ke.length),Ie=ke.length-10,Ae=0):Ae=2147483640&Ae+7,t=Ae,s=o.structuredClone?new Map:null,o.bundleStrings&&"string"!=typeof e?(we=[],we.size=1/0):we=null,r=o.structures,r){r.uninitialized&&(r=o._mergeStructures(o.getStructures()));let e=r.sharedLength||0;if(e>d)//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 "+r.sharedLength);if(!r.transitions){r.transitions=Object.create(null);for(let t,n=0;n<e;n++){if(t=r[n],!t)continue;let e,s=r.transitions;for(let n,r=0,i=t.length;r<i;r++)n=t[r],e=s[n],e||(e=s[n]=Object.create(null)),s=e;s[Le]=n+64}this.lastNamedStructuresLength=e}a||(r.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(o.randomAccessStructure&&e.constructor&&e.constructor===Object?w(e):m(e),we&&I(t,m),o.offset=Ae,s&&s.idsToInsert){Ae+=6*s.idsToInsert.length,Ae>Ie&&S(Ae),o.offset=Ae;let e=_(ke.subarray(t,Ae),s.idsToInsert);return s=null,e}return i&ze?(ke.start=t,ke.end=Ae,ke):ke.subarray(t,Ae);// position can change if we call pack again in saveStructures, so we get the buffer now
53
+ throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+r.sharedLength);if(!r.transitions){r.transitions=Object.create(null);for(let t,n=0;n<e;n++){if(t=r[n],!t)continue;let e,s=r.transitions;for(let n,r=0,i=t.length;r<i;r++)n=t[r],e=s[n],e||(e=s[n]=Object.create(null)),s=e;s[Le]=n+64}this.lastNamedStructuresLength=e}a||(r.nextId=e+64)}n&&(n=!1);try{if(o.randomAccessStructure&&e.constructor&&e.constructor===Object?w(e):m(e),s&&s.idsToInsert){let e=6*s.idsToInsert.length;we&&I(t,m,e),Ae+=e,Ae>Ie&&S(Ae),o.offset=Ae;let n=_(ke.subarray(t,Ae),s.idsToInsert);return s=null,n}// update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
54
+ return we&&I(t,m,0),o.offset=Ae,i&ze?(ke.start=t,ke.end=Ae,ke):ke.subarray(t,Ae);// position can change if we call pack again in saveStructures, so we get the buffer now
55
55
  }finally{if(r){10>y&&y++;let s=r.sharedLength||0;if(r.length>s&&(r.length=s),1e4<h)r.transitions=null,y=0,h=0,0<f.length&&(f=[]);else if(0<f.length&&!a){for(let e=0,t=f.length;e<t;e++)f[e][Le]=0;f=[]}if(n&&o.saveStructures){// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
56
56
  let n=ke.subarray(t,Ae),i=A(r,o);return!1===o.saveStructures(i,i.isCompatible)?o.pack(e):(o.lastNamedStructuresLength=s,n)}}i&Fe&&(Ae=t)}};const m=e=>{Ae>Ie&&(ke=S(Ae));var n,r=typeof e;if("string"==r){let r=e.length;if(we&&4<=r&&4096>r){if((we.size+=r)>61440){let e,n=(we[0]?3*we[0].length+we[1].length:0)+10;Ae+n>Ie&&(ke=S(Ae+n)),we.position?(ke[Ae]=200,Ae+=3,ke[Ae++]=98,e=Ae-t,Ae+=4,I(t,m),_e.setUint16(e+t-3,Ae-t-e)):(ke[Ae++]=214,ke[Ae++]=98,e=Ae-t,Ae+=4),we=["",""],we.size=0,we.position=e}let n=/[\u0080-\uFFFF]/.test(e);return we[n?0:1]+=e,ke[Ae++]=193,void m(n?-r:r)}let s=32>r?1:256>r?2:65536>r?3:5;// first we estimate the header size, so we can write to the correct location
57
57
  let o=3*r;if(Ae+o>Ie&&(ke=S(Ae+o)),64>r||!i){let t,i,o,a=Ae+s;for(t=0;t<r;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-Ae-s}else n=i(e,Ae+s);32>n?ke[Ae++]=160|n:256>n?(2>s&&ke.copyWithin(Ae+2,Ae+1,Ae+1+n),ke[Ae++]=217,ke[Ae++]=n):65536>n?(3>s&&ke.copyWithin(Ae+3,Ae+2,Ae+2+n),ke[Ae++]=218,ke[Ae++]=n>>8,ke[Ae++]=255&n):(5>s&&ke.copyWithin(Ae+5,Ae+3,Ae+3+n),ke[Ae++]=219,_e.setUint32(Ae,n),Ae+=4),Ae+=n}else if("number"===r){if(e>>>0===e)32>e||128>e&&!1===this.useRecords||64>e&&!this.randomAccessStructure?ke[Ae++]=e:256>e?(ke[Ae++]=204,ke[Ae++]=e):65536>e?(ke[Ae++]=205,ke[Ae++]=e>>8,ke[Ae++]=255&e):(ke[Ae++]=206,_e.setUint32(Ae,e),Ae+=4);else if(e>>0===e)-32<=e?ke[Ae++]=256+e:-128<=e?(ke[Ae++]=208,ke[Ae++]=e+256):-32768<=e?(ke[Ae++]=209,_e.setInt16(Ae,e),Ae+=2):(ke[Ae++]=210,_e.setInt32(Ae,e),Ae+=4);else{let t;if(0<(t=this.useFloat32)&&4294967296>e&&-2147483648<=e){ke[Ae++]=202,_e.setFloat32(Ae,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