Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cbor-x

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cbor-x - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

dist/index.js.map

1

decode.d.ts

@@ -22,2 +22,3 @@ export enum FLOAT32_OPTIONS {

maxOwnStructures?: number
useSelfDescribedHeader?: boolean
shouldShareStructure?: (keys: string[]) => boolean

@@ -24,0 +25,0 @@ getStructures?(): {}[]

42

decode.js

@@ -257,3 +257,7 @@ let decoder

}
if (currentDecoder.int64AsNumber) {
if (majorType > 1) {
if (dataView.getUint32(position) > 0)
throw new Error('JavaScript does not support arrays, maps, or strings with length over 4294967295')
token = dataView.getUint32(position + 4)
} else if (currentDecoder.int64AsNumber) {
token = dataView.getUint32(position) * 0x100000000

@@ -438,11 +442,20 @@ token += dataView.getUint32(position + 4)

// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
if (this.objectLiteralSize === length) // we have a fast object literal reader, use it (assuming it is the right length)
return this.objectLiteral(read)
if (this.count++ == 3) { // create a fast reader
this.objectLiteralSize = length
this.objectLiteral = currentDecoder.keyMap
? new Function('r', 'return {' + this.map(k => currentDecoder.decodeKey(k)).map(k => validName.test(k) ? k + ':r()' : ('[' + JSON.stringify(k) + ']:r()')).join(',') + '}')
: new Function('r', 'return {' + this.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}')
return this.objectLiteral(read)
let compiledReader = this.compiledReader // first look to see if we have the fast compiled function
while(compiledReader) {
// we have a fast compiled object literal reader
if (compiledReader.propertyCount === length)
return compiledReader(read) // with the right length, so we use it
compiledReader = compiledReader.next // see if there is another reader with the right length
}
if (this.slowReads++ >= 3) { // create a fast compiled reader
let array = this.length == length ? this : this.slice(0, length)
compiledReader = currentDecoder.keyMap
? new Function('r', 'return {' + array.map(k => currentDecoder.decodeKey(k)).map(k => validName.test(k) ? k + ':r()' : ('[' + JSON.stringify(k) + ']:r()')).join(',') + '}')
: new Function('r', 'return {' + array.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}')
if (this.compiledReader)
compiledReader.next = this.compiledReader // if there is an existing one, we store multiple readers as a linked list because it is usually pretty rare to have multiple readers (of different length) for the same structure
compiledReader.propertyCount = length
this.compiledReader = compiledReader
return compiledReader(read)
}
let object = {}

@@ -453,3 +466,3 @@ if (currentDecoder.keyMap) for (let i = 0; i < length; i++) object[currentDecoder.decodeKey(this[i])] = read()

}
structure.count = 0
structure.slowReads = 0
return readObject

@@ -843,7 +856,12 @@ }

// the registration of the record definition extension (tag 105)
// the registration of the record definition extension
const recordDefinition = (definition) => {
let id = definition[0] - 0xe000
let structure = definition[1]
let existingStructure = currentStructures[id]
if (existingStructure && existingStructure.isShared) {
(currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure
}
currentStructures[id] = structure
structure.read = createStructureReader(structure)

@@ -992,2 +1010,4 @@ let object = {}

}
if (tag == 55799) // self-descriptive CBOR tag, just return input value
return input
})

@@ -994,0 +1014,0 @@

@@ -1,15 +0,15 @@

(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):(e=e||self,t(e.CBOR={}))})(this,function(e){'use strict';var t=Math.log,s=Math.exp;function n(){try{let e=a();if(T&&(// bundled strings to skip past
x=T.postBundlePosition),x==j)D=null,_=null,w&&(w=null);else if(x>j){// over read
(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):(e=e||self,t(e.CBOR={}))})(this,function(e){'use strict';var t=Math.log,s=Math.exp;function n(){try{let e=a();if(K&&(// bundled strings to skip past
x=K.postBundlePosition),x==V)w=null,C=null,T&&(T=null);else if(x>V){// over read
let e=new Error("Unexpected end of CBOR data");throw e.incomplete=!0,e}else if(!Q)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
return e}catch(e){throw m(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer"))&&(e.incomplete=!0),e}}function a(){let e=_[x++],t=e>>5;if(e&=31,23<e)switch(e){case 24:e=_[x++];break;case 25:if(7==t)return c();e=z.getUint16(x),x+=2;break;case 26:if(7==t){let e=z.getFloat32(x);if(2<Y.useFloat32){// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
let t=ue[(127&_[x])<<1|_[x+1]>>7];return x+=4,(t*e+(0<e?.5:-.5)>>0)/t}return x+=4,e}e=z.getUint32(x),x+=4;break;case 27:if(7==t){let e=z.getFloat64(x);return x+=8,e}Y.int64AsNumber?(e=4294967296*z.getUint32(x),e+=z.getUint32(x+4)):e=z.getBigUint64(x),x+=8;break;case 31:// indefinite length
return e}catch(e){throw b(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer"))&&(e.incomplete=!0),e}}function a(){let e=C[x++],t=e>>5;if(e&=31,23<e)switch(e){case 24:e=C[x++];break;case 25:if(7==t)return c();e=N.getUint16(x),x+=2;break;case 26:if(7==t){let e=N.getFloat32(x);if(2<z.useFloat32){// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
let t=ue[(127&C[x])<<1|C[x+1]>>7];return x+=4,(t*e+(0<e?.5:-.5)>>0)/t}return x+=4,e}e=N.getUint32(x),x+=4;break;case 27:if(7==t){let e=N.getFloat64(x);return x+=8,e}if(1<t){if(0<N.getUint32(x))throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");e=N.getUint32(x+4)}else z.int64AsNumber?(e=4294967296*N.getUint32(x),e+=N.getUint32(x+4)):e=N.getBigUint64(x);x+=8;break;case 31:// indefinite length
switch(t){case 2:// byte string
case 3:// text string
throw new Error("Indefinite length not supported for byte or text strings");case 4:// array
let e,s=[],n=0;for(;(e=a())!=F;)s[n++]=e;return 4==t?s:3==t?s.join(""):Buffer.concat(s);case 5:// map
let r;if(Y.mapsAsObjects){let e={};if(Y.keyMap)for(;(r=a())!=F;)e[Y.decodeKey(r)]=a();else for(;(r=a())!=F;)e[r]=a();return e}else{W&&(Y.mapsAsObjects=!0,W=!1);let e=new Map;if(Y.keyMap)for(;(r=a())!=F;)e.set(Y.decodeKey(r),a());else for(;(r=a())!=F;)e.set(r,a());return e}case 7:return F;default:throw new Error("Invalid major type for indefinite length "+t);}default:throw new Error("Unknown token "+e);}switch(t){case 0:// positive int
let e,s=[],n=0;for(;(e=a())!=j;)s[n++]=e;return 4==t?s:3==t?s.join(""):Buffer.concat(s);case 5:// map
let r;if(z.mapsAsObjects){let e={};if(z.keyMap)for(;(r=a())!=j;)e[z.decodeKey(r)]=a();else for(;(r=a())!=j;)e[r]=a();return e}else{W&&(z.mapsAsObjects=!0,W=!1);let e=new Map;if(z.keyMap)for(;(r=a())!=j;)e.set(z.decodeKey(r),a());else for(;(r=a())!=j;)e.set(r,a());return e}case 7:return j;default:throw new Error("Invalid major type for indefinite length "+t);}default:throw new Error("Unknown token "+e);}switch(t){case 0:// positive int
return e;case 1:// negative int
return~e;case 2:// buffer
return u(e);case 3:// string
if(G>=x)return K.slice(x-q,(x+=e)-q);if(0==G&&140>j&&32>e){// for small blocks, avoiding the overhead of the extract call is helpful
if(G>=x)return F.slice(x-q,(x+=e)-q);if(0==G&&140>V&&32>e){// for small blocks, avoiding the overhead of the extract call is helpful
let t=16>e?d(e):o(e);if(null!=t)return t}return ee(e);case 4:// array

@@ -19,24 +19,27 @@ let s=Array(e);//if (currentDecoder.keyMap) for (let i = 0; i < token; i++) array[i] = currentDecoder.decodeKey(read())

for(let t=0;t<e;t++)s[t]=a();return s;case 5:// map
if(Y.mapsAsObjects){let t={};if(Y.keyMap)for(let s=0;s<e;s++)t[Y.decodeKey(a())]=a();else for(let s=0;s<e;s++)t[a()]=a();return t}else{W&&(Y.mapsAsObjects=!0,W=!1);let t=new Map;if(Y.keyMap)for(let s=0;s<e;s++)t.set(Y.decodeKey(a()),a());else for(let s=0;s<e;s++)t.set(a(),a());return t}case 6:// extension
if(e>=L){let t=D[8191&e];// check record structures first
if(z.mapsAsObjects){let t={};if(z.keyMap)for(let s=0;s<e;s++)t[z.decodeKey(a())]=a();else for(let s=0;s<e;s++)t[a()]=a();return t}else{W&&(z.mapsAsObjects=!0,W=!1);let t=new Map;if(z.keyMap)for(let s=0;s<e;s++)t.set(z.decodeKey(a()),a());else for(let s=0;s<e;s++)t.set(a(),a());return t}case 6:// extension
if(e>=L){let t=w[8191&e];// check record structures first
// At some point we may provide an option for dynamic tag assignment with a range like token >= 8 && (token < 16 || (token > 0x80 && token < 0xc0) || (token > 0x130 && token < 0x4000))
if(t)return t.read||(t.read=r(t)),t.read();if(65536>e){if(e==P)// we do a special check for this so that we can keep the currentExtensions as densely stored array (v8 stores arrays densely under about 3000 elements)
return re(a());if(e==C){let e=h(),t=a();for(let s=2;s<e;s++)re([t++,a()]);return a()}if(e==L)return g();if(Y.getShared&&(y(),t=D[8191&e],t))return t.read||(t.read=r(t)),t.read()}}let n=$[e];if(n)return n.handlesRead?n(a):n(a());else{let t=a();for(let s,n=0;n<H.length;n++)if(s=H[n](e,t),void 0!==s)return s;return new ne(t,e)}case 7:// fixed value
if(t)return t.read||(t.read=r(t)),t.read();if(65536>e){if(e==D)// we do a special check for this so that we can keep the currentExtensions as densely stored array (v8 stores arrays densely under about 3000 elements)
return re(a());if(e==B){let e=h(),t=a();for(let s=2;s<e;s++)re([t++,a()]);return a()}if(e==L)return f();if(z.getShared&&(y(),t=w[8191&e],t))return t.read||(t.read=r(t)),t.read()}}let n=H[e];if(n)return n.handlesRead?n(a):n(a());else{let t=a();for(let s,n=0;n<J.length;n++)if(s=J[n](e,t),void 0!==s)return s;return new ne(t,e)}case 7:// fixed value
switch(e){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;// undefined
case 31:default:let t=(N||p())[e];if(void 0!==t)return t;throw new Error("Unknown token "+e);}default:// negative int
case 31:default:let t=(Y||p())[e];if(void 0!==t)return t;throw new Error("Unknown token "+e);}default:// negative int
if(isNaN(e)){let e=new Error("Unexpected end of CBOR data");throw e.incomplete=!0,e}throw new Error("Unknown CBOR token "+e);}}function r(e){function t(){// get the array size from the header
let e=_[x++];//let majorType = token >> 5
if(e&=31,23<e)switch(e){case 24:e=_[x++];break;case 25:e=z.getUint16(x),x+=2;break;case 26:e=z.getUint32(x),x+=4;break;default:throw new Error("Expected array header, but got "+_[x-1]);}// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
if(this.objectLiteralSize===e)// we have a fast object literal reader, use it (assuming it is the right length)
return this.objectLiteral(a);if(3==this.count++)return this.objectLiteralSize=e,this.objectLiteral=Y.keyMap?new Function("r","return {"+this.map(e=>Y.decodeKey(e)).map(e=>Z.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"):new Function("r","return {"+this.map(e=>Z.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"),this.objectLiteral(a);let t={};if(Y.keyMap)for(let s=0;s<e;s++)t[Y.decodeKey(this[s])]=a();else for(let s=0;s<e;s++)t[this[s]]=a();return t}return e.count=0,t}function i(e){let t;if(16>e&&(t=d(e)))return t;if(64<e&&E)return E.decode(_.subarray(x,x+=e));const s=x+e,n=[];for(t="";x<s;){const e=_[x++];if(0==(128&e))n.push(e);else if(192==(224&e)){// 2 bytes
const t=63&_[x++];n.push((31&e)<<6|t)}else if(224==(240&e)){// 3 bytes
const t=63&_[x++],s=63&_[x++];n.push((31&e)<<12|t<<6|s)}else if(240==(248&e)){// 4 bytes
const t=63&_[x++],s=63&_[x++],a=63&_[x++];let r=(7&e)<<18|t<<12|s<<6|a;65535<r&&(r-=65536,n.push(55296|1023&r>>>10),r=56320|1023&r),n.push(r)}else n.push(e);4096<=n.length&&(t+=te.apply(String,n),n.length=0)}return 0<n.length&&(t+=te.apply(String,n)),t}function o(e){let t=x,s=Array(e);for(let n=0;n<e;n++){const e=_[x++];if(0<(128&e))return void(x=t);s[n]=e}return te.apply(String,s)}function d(t){if(4>t){if(!(2>t)){let e=_[x++],s=_[x++];if(0<(128&e)||0<(128&s))return void(x-=2);if(3>t)return te(e,s);let n=_[x++];return 0<(128&n)?void(x-=3):te(e,s,n)}if(0===t)return"";else{let e=_[x++];return 1<(128&e)?void(x-=1):te(e)}}else{let s=_[x++],a=_[x++],r=_[x++],u=_[x++];if(0<(128&s)||0<(128&a)||0<(128&r)||0<(128&u))return void(x-=4);if(6>t){if(4===t)return te(s,a,r,u);else{let t=_[x++];return 0<(128&t)?void(x-=5):te(s,a,r,u,t)}}else if(8>t){let n=_[x++],e=_[x++];if(0<(128&n)||0<(128&e))return void(x-=6);if(7>t)return te(s,a,r,u,n,e);let i=_[x++];return 0<(128&i)?void(x-=7):te(s,a,r,u,n,e,i)}else{let d=_[x++],e=_[x++],c=_[x++],p=_[x++];if(0<(128&d)||0<(128&e)||0<(128&c)||0<(128&p))return void(x-=8);if(10>t){if(8===t)return te(s,a,r,u,d,e,c,p);else{let t=_[x++];return 0<(128&t)?void(x-=9):te(s,a,r,u,d,e,c,p,t)}}else if(12>t){let n=_[x++],i=_[x++];if(0<(128&n)||0<(128&i))return void(x-=10);if(11>t)return te(s,a,r,u,d,e,c,p,n,i);let o=_[x++];return 0<(128&o)?void(x-=11):te(s,a,r,u,d,e,c,p,n,i,o)}else{let f=_[x++],i=_[x++],g=_[x++],h=_[x++];if(0<(128&f)||0<(128&i)||0<(128&g)||0<(128&h))return void(x-=12);if(!(14>t)){let l=_[x++],y=_[x++];if(0<(128&l)||0<(128&y))return void(x-=14);if(15>t)return te(s,a,r,u,d,e,c,p,f,i,g,h,l,y);let n=_[x++];return 0<(128&n)?void(x-=15):te(s,a,r,u,d,e,c,p,f,i,g,h,l,y,n)}if(12===t)return te(s,a,r,u,d,e,c,p,f,i,g,h);else{let t=_[x++];return 0<(128&t)?void(x-=13):te(s,a,r,u,d,e,c,p,f,i,g,h,t)}}}}}function u(e){return Y.copyBuffers?// specifically use the copying slice (not the node one)
Uint8Array.prototype.slice.call(_,x,x+=e):_.subarray(x,x+=e)}function c(){let e,t=_[x++],n=_[x++],a=(t<<8)+n,r=31&a>>10,i=1023&a;return e=0==r?s(i,-24):31==r?0==i?1/0:NaN:s(i+1024,r-25),32768&a?-e:e}function l(e,t){return"string"==typeof e?e+t:e instanceof Array?e.concat(t):Object.assign({},e,t)}function p(){if(!N)if(Y.getShared)y();else throw new Error("No packed values available");return N}function f(e,t){$[t]=t=>{if(!e)throw new Error("Could not find typed array for code "+typeCode);// we have to always slice/copy here to get a new ArrayBuffer that is word/byte aligned
return new ae[e](Uint8Array.prototype.slice.call(t,0).buffer)}}function g(){let e=h(),t=x+a();for(let t,s=2;s<e;s++)// skip past bundles that were already read
let e=C[x++];//let majorType = token >> 5
if(e&=31,23<e)switch(e){case 24:e=C[x++];break;case 25:e=N.getUint16(x),x+=2;break;case 26:e=N.getUint32(x),x+=4;break;default:throw new Error("Expected array header, but got "+C[x-1]);}// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
let t=this.compiledReader;// first look to see if we have the fast compiled function
for(;t;){// we have a fast compiled object literal reader
if(t.propertyCount===e)return t(a);// with the right length, so we use it
t=t.next}if(3<=this.slowReads++){// create a fast compiled reader
let s=this.length==e?this:this.slice(0,e);return t=z.keyMap?new Function("r","return {"+s.map(e=>z.decodeKey(e)).map(e=>Z.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"):new Function("r","return {"+s.map(e=>Z.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}"),this.compiledReader&&(t.next=this.compiledReader),t.propertyCount=e,this.compiledReader=t,t(a)}let s={};if(z.keyMap)for(let t=0;t<e;t++)s[z.decodeKey(this[t])]=a();else for(let t=0;t<e;t++)s[this[t]]=a();return s}return e.slowReads=0,t}function i(e){let t;if(16>e&&(t=d(e)))return t;if(64<e&&A)return A.decode(C.subarray(x,x+=e));const s=x+e,n=[];for(t="";x<s;){const e=C[x++];if(0==(128&e))n.push(e);else if(192==(224&e)){// 2 bytes
const t=63&C[x++];n.push((31&e)<<6|t)}else if(224==(240&e)){// 3 bytes
const t=63&C[x++],s=63&C[x++];n.push((31&e)<<12|t<<6|s)}else if(240==(248&e)){// 4 bytes
const t=63&C[x++],s=63&C[x++],a=63&C[x++];let r=(7&e)<<18|t<<12|s<<6|a;65535<r&&(r-=65536,n.push(55296|1023&r>>>10),r=56320|1023&r),n.push(r)}else n.push(e);4096<=n.length&&(t+=te.apply(String,n),n.length=0)}return 0<n.length&&(t+=te.apply(String,n)),t}function o(e){let t=x,s=Array(e);for(let n=0;n<e;n++){const e=C[x++];if(0<(128&e))return void(x=t);s[n]=e}return te.apply(String,s)}function d(t){if(4>t){if(!(2>t)){let e=C[x++],s=C[x++];if(0<(128&e)||0<(128&s))return void(x-=2);if(3>t)return te(e,s);let n=C[x++];return 0<(128&n)?void(x-=3):te(e,s,n)}if(0===t)return"";else{let e=C[x++];return 1<(128&e)?void(x-=1):te(e)}}else{let s=C[x++],a=C[x++],r=C[x++],u=C[x++];if(0<(128&s)||0<(128&a)||0<(128&r)||0<(128&u))return void(x-=4);if(6>t){if(4===t)return te(s,a,r,u);else{let t=C[x++];return 0<(128&t)?void(x-=5):te(s,a,r,u,t)}}else if(8>t){let n=C[x++],e=C[x++];if(0<(128&n)||0<(128&e))return void(x-=6);if(7>t)return te(s,a,r,u,n,e);let i=C[x++];return 0<(128&i)?void(x-=7):te(s,a,r,u,n,e,i)}else{let d=C[x++],e=C[x++],c=C[x++],p=C[x++];if(0<(128&d)||0<(128&e)||0<(128&c)||0<(128&p))return void(x-=8);if(10>t){if(8===t)return te(s,a,r,u,d,e,c,p);else{let t=C[x++];return 0<(128&t)?void(x-=9):te(s,a,r,u,d,e,c,p,t)}}else if(12>t){let n=C[x++],i=C[x++];if(0<(128&n)||0<(128&i))return void(x-=10);if(11>t)return te(s,a,r,u,d,e,c,p,n,i);let o=C[x++];return 0<(128&o)?void(x-=11):te(s,a,r,u,d,e,c,p,n,i,o)}else{let g=C[x++],i=C[x++],f=C[x++],h=C[x++];if(0<(128&g)||0<(128&i)||0<(128&f)||0<(128&h))return void(x-=12);if(!(14>t)){let l=C[x++],y=C[x++];if(0<(128&l)||0<(128&y))return void(x-=14);if(15>t)return te(s,a,r,u,d,e,c,p,g,i,f,h,l,y);let n=C[x++];return 0<(128&n)?void(x-=15):te(s,a,r,u,d,e,c,p,g,i,f,h,l,y,n)}if(12===t)return te(s,a,r,u,d,e,c,p,g,i,f,h);else{let t=C[x++];return 0<(128&t)?void(x-=13):te(s,a,r,u,d,e,c,p,g,i,f,h,t)}}}}}function u(e){return z.copyBuffers?// specifically use the copying slice (not the node one)
Uint8Array.prototype.slice.call(C,x,x+=e):C.subarray(x,x+=e)}function c(){let e,t=C[x++],n=C[x++],a=(t<<8)+n,r=31&a>>10,i=1023&a;return e=0==r?s(i,-24):31==r?0==i?1/0:NaN:s(i+1024,r-25),32768&a?-e:e}function l(e,t){return"string"==typeof e?e+t:e instanceof Array?e.concat(t):Object.assign({},e,t)}function p(){if(!Y)if(z.getShared)y();else throw new Error("No packed values available");return Y}function g(e,t){H[t]=t=>{if(!e)throw new Error("Could not find typed array for code "+typeCode);// we have to always slice/copy here to get a new ArrayBuffer that is word/byte aligned
return new ae[e](Uint8Array.prototype.slice.call(t,0).buffer)}}function f(){let e=h(),t=x+a();for(let t,s=2;s<e;s++)// skip past bundles that were already read
// this will increment position, so must add to position afterwards
t=h(),x+=t;let s=x;return x=t,T=[i(h()),i(h())],T.position0=0,T.position1=0,T.postBundlePosition=x,x=s,a()}function h(){let e=31&_[x++];return 23<e&&(24===e?e=_[x++]:25===e?(e=z.getUint16(x),x+=2):26===e?(e=z.getUint32(x),x+=4):void 0),e}function y(){if(Y.getShared){let e=b(()=>(_=null,Y.getShared()))||{},t=e.structures||[];Y.sharedVersion=e.version,N=Y.sharedValues=e.packedValues,!0===D?Y.structures=D=t:D.splice.apply(D,[0,t.length].concat(t))}}function b(e){let t=j,s=x,n=q,a=G,r=K,i=w,o=T,d=new Uint8Array(_.slice(0,j)),u=D,c=Y,l=Q,p=e();return j=t,x=s,q=n,G=a,K=r,w=i,T=o,_=d,Q=l,D=u,Y=c,z=new DataView(_.buffer,_.byteOffset,_.byteLength),p}function m(){_=null,w=null,D=null}function k(e){$[e.tag]=e.decode}function M(e){24>e?ve[Se++]=128|e:256>e?(ve[Se++]=152,ve[Se++]=e):65536>e?(ve[Se++]=153,ve[Se++]=e>>8,ve[Se++]=255&e):(ve[Se++]=154,Ae.setUint32(Se,e),Se+=4)}function I(e,t){switch(typeof e){case"string":if(3<e.length){if(-1<t.objectMap[e]||t.values.length>=t.maxValues)return;let s=t.get(e);if(s)2==++s.count&&t.values.push(e);else if(t.set(e,{count:1}),t.samplingPackedValues){let s=t.samplingPackedValues.get(e);s?s.count++:t.samplingPackedValues.set(e,{count:1})}}break;case"object":if(e)if(e instanceof Array)for(let s=0,n=e.length;s<n;s++)I(e[s],t);else{let n=!t.encoder.useRecords;for(var s in e)e.hasOwnProperty(s)&&(n&&I(s,t),I(e[s],t))}break;case"function":console.log(e);}}function O(e){return{tag:e,encode:function(e,t){let s=e.byteLength,n=e.byteOffset||0,a=e.buffer||e;t(ke?Buffer.from(a,n,s):new Uint8Array(a,n,s))}}}function U(e,t){let s=e.byteLength;24>s?ve[Se++]=64+s:256>s?(ve[Se++]=88,ve[Se++]=s):65536>s?(ve[Se++]=89,ve[Se++]=s>>8,ve[Se++]=255&s):(ve[Se++]=90,Ae.setUint32(Se,s),Se+=4),Se+s>=ve.length&&t(Se+s),ve.set(e,Se),Se+=s}function v(e,t){// insert the ids that need to be referenced for structured clones
t=h(),x+=t;let s=x;return x=t,K=[i(h()),i(h())],K.position0=0,K.position1=0,K.postBundlePosition=x,x=s,a()}function h(){let e=31&C[x++];return 23<e&&(24===e?e=C[x++]:25===e?(e=N.getUint16(x),x+=2):26===e?(e=N.getUint32(x),x+=4):void 0),e}function y(){if(z.getShared){let e=m(()=>(C=null,z.getShared()))||{},t=e.structures||[];z.sharedVersion=e.version,Y=z.sharedValues=e.packedValues,!0===w?z.structures=w=t:w.splice.apply(w,[0,t.length].concat(t))}}function m(e){let t=V,s=x,n=q,a=G,r=F,i=T,o=K,d=new Uint8Array(C.slice(0,V)),u=w,c=z,l=Q,p=e();return V=t,x=s,q=n,G=a,F=r,T=i,K=o,C=d,Q=l,w=u,z=c,N=new DataView(C.buffer,C.byteOffset,C.byteLength),p}function b(){C=null,T=null,w=null}function k(e){H[e.tag]=e.decode}function O(e){24>e?_e[Ee++]=128|e:256>e?(_e[Ee++]=152,_e[Ee++]=e):65536>e?(_e[Ee++]=153,_e[Ee++]=e>>8,_e[Ee++]=255&e):(_e[Ee++]=154,Ie.setUint32(Ee,e),Ee+=4)}function R(e,t){switch(typeof e){case"string":if(3<e.length){if(-1<t.objectMap[e]||t.values.length>=t.maxValues)return;let s=t.get(e);if(s)2==++s.count&&t.values.push(e);else if(t.set(e,{count:1}),t.samplingPackedValues){let s=t.samplingPackedValues.get(e);s?s.count++:t.samplingPackedValues.set(e,{count:1})}}break;case"object":if(e)if(e instanceof Array)for(let s=0,n=e.length;s<n;s++)R(e[s],t);else{let n=!t.encoder.useRecords;for(var s in e)e.hasOwnProperty(s)&&(n&&R(s,t),R(e[s],t))}break;case"function":console.log(e);}}function M(e){return{tag:e,encode:function(e,t){let s=e.byteLength,n=e.byteOffset||0,a=e.buffer||e;t(ke?Buffer.from(a,n,s):new Uint8Array(a,n,s))}}}function S(e,t){let s=e.byteLength;24>s?_e[Ee++]=64+s:256>s?(_e[Ee++]=88,_e[Ee++]=s):65536>s?(_e[Ee++]=89,_e[Ee++]=s>>8,_e[Ee++]=255&s):(_e[Ee++]=90,Ie.setUint32(Ee,s),Ee+=4),Ee+s>=_e.length&&t(Ee+s),_e.set(e,Ee),Ee+=s}function _(e,t){// insert the ids that need to be referenced for structured clones
let s,n=2*t.length,a=e.length-n;t.sort((e,t)=>e.offset>t.offset?1:-1);for(let s,n=0;n<t.length;n++){s=t[n],s.id=n;for(let t of s.references)e[t++]=n>>8,e[t]=255&n}for(;s=t.pop();){let t=s.offset;e.copyWithin(t+n,t,a),n-=2;let r=t+n;// http://cbor.schmorp.de/value-sharing
e[r++]=216,e[r++]=28,a=t}return e}function A(e,t){Ae.setUint32(Ve.position+e,Se-Ve.position-e+1);// the offset to bundle
let s=Ve;Ve=null,t(s[0]),t(s[1])}function R(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");me.unshift(e.Class),be.unshift(e)}k(e)}function*S(e,t){const s=new _e(t);for(const n of e)yield s.encode(n)}async function*V(e,t){const s=new _e(t);for await(const n of e)yield s.encode(n)}/**
e[r++]=216,e[r++]=28,a=t}return e}function I(e,t){Ie.setUint32(ve.position+e,Ee-ve.position-e+1);// the offset to bundle
let s=ve;ve=null,t(s[0]),t(s[1])}function U(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");be.unshift(e.Class),me.unshift(e)}k(e)}function*E(e,t){const s=new Ce(t);for(const n of e)yield s.encode(n)}async function*v(e,t){const s=new Ce(t);for await(const n of e)yield s.encode(n)}/**
* Given an Iterable/Iterator input which yields buffers, returns an IterableIterator which yields sync decoded objects

@@ -47,3 +50,3 @@ * Or, given an Async Iterable/Iterator which yields promises resolving in buffers, returns an AsyncIterableIterator.

* @returns {IterableIterator|Promise.<AsyncIterableIterator}
*/let E;try{E=new TextDecoder}catch(e){}let _,j,x=0;const C=57342,P=57343,L=57337,B=6,F={};let D,K,T,w,N,z,W,Y={},q=0,G=0,$=[],H=[],J={useRecords:!1,mapsAsObjects:!0},Q=!1;class X{constructor(e){if(e&&((e.keyMap||e._keyMap)&&!e.useRecords&&(e.useRecords=!1,e.mapsAsObjects=!0),!1===e.useRecords&&void 0===e.mapsAsObjects&&(e.mapsAsObjects=!0),e.getStructures&&(e.getShared=e.getStructures),e.getShared&&!e.structures&&((e.structures=[]).uninitialized=!0),e.keyMap))// this is what we use to denote an uninitialized structures
*/let A;try{A=new TextDecoder}catch(e){}let C,V,x=0;const B=57342,D=57343,L=57337,P=6,j={};let w,F,K,T,Y,N,W,z={},q=0,G=0,H=[],J=[],$={useRecords:!1,mapsAsObjects:!0},Q=!1;class X{constructor(e){if(e&&((e.keyMap||e._keyMap)&&!e.useRecords&&(e.useRecords=!1,e.mapsAsObjects=!0),!1===e.useRecords&&void 0===e.mapsAsObjects&&(e.mapsAsObjects=!0),e.getStructures&&(e.getShared=e.getStructures),e.getShared&&!e.structures&&((e.structures=[]).uninitialized=!0),e.keyMap))// this is what we use to denote an uninitialized structures
{this.mapKey=new Map;for(let[t,s]of Object.entries(e.keyMap))this.mapKey.set(s,t)}Object.assign(this,e)}/*

@@ -58,17 +61,17 @@ decodeKey(key) {

switch(t.constructor.name){case"Array":return t.map(e=>this.decodeKeys(e));//case 'Map': return this.decodeKeys(res)
}return t}decode(e,t){if(_)// re-entrant execution, save the state and restore it after we do this decode
return b(()=>(m(),this?this.decode(e,t):X.prototype.decode.call(J,e,t)));j=-1<t?t:e.length,x=0,G=0,K=null,T=null,_=e;// this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
}return t}decode(e,t){if(C)// re-entrant execution, save the state and restore it after we do this decode
return m(()=>(b(),this?this.decode(e,t):X.prototype.decode.call($,e,t)));V=-1<t?t:e.length,x=0,G=0,F=null,K=null,C=e;// this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
// technique for getting data from a database where it can be copied into an existing buffer instead of creating
// new ones
try{z=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(t){if(_=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 X){if(Y=this,N=this.sharedValues&&(this.pack?Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return D=this.structures,n();(!D||0<D.length)&&(D=[])}else Y=J,(!D||0<D.length)&&(D=[]),N=null;return n()}decodeMultiple(e,t){let s,a=0;try{let r=e.length;Q=!0;let i=this?this.decode(e,r):ce.decode(e,r);if(t){if(!1===t(i))return;for(;x<r;)if(a=x,!1===t(n()))return}else{for(s=[i];x<r;)a=x,s.push(n());return s}}catch(e){throw e.lastPosition=a,e.values=s,e}finally{Q=!1,m()}}}const Z=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;let ee=i,te=String.fromCharCode,se=Array(4096);class ne{constructor(e,t){this.value=e,this.tag=t}}let ae="object"==typeof self?self:global;$[0]=e=>new Date(e),$[1]=e=>new Date(1e3*e),$[2]=e=>{// bigint extension
let t=BigInt(0);for(let s=0,n=e.byteLength;s<n;s++)t=BigInt(e[s])+t<<BigInt(8);return t},$[3]=e=>BigInt(-1)-$[2](e),$[4]=e=>+(e[1]+"e"+e[0]),$[5]=e=>e[1]*s(e[0]*t(2));// the registration of the record definition extension (tag 105)
const re=e=>{let t=e[0]-57344,s=e[1];D[t]=s,s.read=r(s);let n={};if(Y.keyMap)for(let t,a=2,r=e.length;a<r;a++)t=Y.decodeKey(s[a-2]),n[t]=e[a];else for(let t,a=2,r=e.length;a<r;a++)t=s[a-2],n[t]=e[a];return n};$[105]=re,$[14]=e=>T?T[0].slice(T.position0,T.position0+=e):new ne(e,14),$[15]=e=>T?T[1].slice(T.position1,T.position1+=e):new ne(e,15),$[27]=e=>(ae[e[0]]||Error)(e[1],e[2]);const ie=e=>{if(132!=_[x++])throw new Error("Packed values structure must be followed by a 4 element array");let t=e();// packed values
return N=N?t.concat(N.slice(t.length)):t,N.prefixes=e(),N.suffixes=e(),e();// read the rump
};ie.handlesRead=!0,$[51]=ie,$[B]=e=>{// packed reference
if(!N)if(Y.getShared)y();else return new ne(e,B);if("number"==typeof e)return N[16+(0<=e?2*e:-2*e-1)];throw new Error("No support for non-integer packed references yet")},$[25]=e=>stringRefs[e],$[256]=e=>{stringRefs=[];try{return e()}finally{stringRefs=null}},$[256].handlesRead=!0,$[28]=e=>{w||(w=new Map,w.id=0);let t,s=w.id++,n=_[x];t=4==n>>5?[]:{};let a={target:t};// a placeholder object
w.set(s,a);let r=e();// read the next value as the target object to id
try{N=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(t){if(C=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 X){if(z=this,Y=this.sharedValues&&(this.pack?Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return w=this.structures,n();(!w||0<w.length)&&(w=[])}else z=$,(!w||0<w.length)&&(w=[]),Y=null;return n()}decodeMultiple(e,t){let s,a=0;try{let r=e.length;Q=!0;let i=this?this.decode(e,r):ce.decode(e,r);if(t){if(!1===t(i))return;for(;x<r;)if(a=x,!1===t(n()))return}else{for(s=[i];x<r;)a=x,s.push(n());return s}}catch(e){throw e.lastPosition=a,e.values=s,e}finally{Q=!1,b()}}}const Z=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;let ee=i,te=String.fromCharCode,se=Array(4096);class ne{constructor(e,t){this.value=e,this.tag=t}}let ae="object"==typeof self?self:global;H[0]=e=>new Date(e),H[1]=e=>new Date(1e3*e),H[2]=e=>{// bigint extension
let t=BigInt(0);for(let s=0,n=e.byteLength;s<n;s++)t=BigInt(e[s])+t<<BigInt(8);return t},H[3]=e=>BigInt(-1)-H[2](e),H[4]=e=>+(e[1]+"e"+e[0]),H[5]=e=>e[1]*s(e[0]*t(2));// the registration of the record definition extension
const re=e=>{let t=e[0]-57344,s=e[1],n=w[t];n&&n.isShared&&((w.restoreStructures||(w.restoreStructures=[]))[t]=n),w[t]=s,s.read=r(s);let a={};if(z.keyMap)for(let t,n=2,r=e.length;n<r;n++)t=z.decodeKey(s[n-2]),a[t]=e[n];else for(let t,n=2,r=e.length;n<r;n++)t=s[n-2],a[t]=e[n];return a};H[105]=re,H[14]=e=>K?K[0].slice(K.position0,K.position0+=e):new ne(e,14),H[15]=e=>K?K[1].slice(K.position1,K.position1+=e):new ne(e,15),H[27]=e=>(ae[e[0]]||Error)(e[1],e[2]);const ie=e=>{if(132!=C[x++])throw new Error("Packed values structure must be followed by a 4 element array");let t=e();// packed values
return Y=Y?t.concat(Y.slice(t.length)):t,Y.prefixes=e(),Y.suffixes=e(),e();// read the rump
};ie.handlesRead=!0,H[51]=ie,H[P]=e=>{// packed reference
if(!Y)if(z.getShared)y();else return new ne(e,P);if("number"==typeof e)return Y[16+(0<=e?2*e:-2*e-1)];throw new Error("No support for non-integer packed references yet")},H[25]=e=>stringRefs[e],H[256]=e=>{stringRefs=[];try{return e()}finally{stringRefs=null}},H[256].handlesRead=!0,H[28]=e=>{T||(T=new Map,T.id=0);let t,s=T.id++,n=C[x];t=4==n>>5?[]:{};let a={target:t};// a placeholder object
T.set(s,a);let r=e();// read the next value as the target object to id
return a.used?Object.assign(t,r):(a.target=r,r);// no cycle, can just use the returned read object
},$[28].handlesRead=!0,$[29]=e=>{// sharedref http://cbor.schmorp.de/value-sharing (for structured clones)
let t=w.get(e);return t.used=!0,t.target},$[258]=e=>new Set(e),($[259]=e=>(Y.mapsAsObjects&&(Y.mapsAsObjects=!1,W=!0),e())).handlesRead=!0;H.push((e,t)=>225<=e&&255>=e?l(p().prefixes[e-224],t):28704<=e&&32767>=e?l(p().prefixes[e-28672],t):1879052288<=e&&2147483647>=e?l(p().prefixes[e-1879048192],t):216<=e&&223>=e?l(t,p().suffixes[e-216]):27647<=e&&28671>=e?l(t,p().suffixes[e-27639]):1811940352<=e&&1879048191>=e?l(t,p().suffixes[e-1811939328]):e==1399353956?{packedValues:N,structures:D.slice(0),version:t}:void 0);const oe=["Uint8","Uint8Clamped","Uint16","Uint32","BigUint64","Int8","Int16","Int32","BigInt64","Float32","Float64"].map(e=>e+"Array"),de=[64,68,69,70,71,72,77,78,79,81,82];for(let t=0;t<oe.length;t++)f(oe[t],de[t]);const ue=Array(147);// this is a table matching binary exponents to the multiplier to determine significant digit rounding
for(let t=0;256>t;t++)ue[t]=+("1e"+Math.floor(45.15-.30103*t));let ce=new X({useRecords:!1});const le=ce.decode,pe=ce.decodeMultiple,fe={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let ge,he=new Float32Array(1),ye=new Uint8Array(he.buffer,0,4);try{ge=new TextEncoder}catch(e){}let be,me;const ke="undefined"!=typeof Buffer,Me=ke?Buffer.allocUnsafeSlow:Uint8Array,Ie=ke?Buffer:Uint8Array,Oe=256,Ue=ke?4294967296:2144337920;let ve,Ae,Re,Se=0,Ve=null;const Ee=Symbol("record-id");class _e extends X{constructor(e){super(e),this.offset=0;let t,s,n,a,r;e=e||{};let i=Ie.prototype.utf8Write?function(e,t,s){return ve.utf8Write(e,t,s)}:!!(ge&&ge.encodeInto)&&function(e,t){return ge.encodeInto(e,ve.subarray(t)).written},o=this,d=e.maxSharedStructures||128,u=e.sequential;u&&(d=0,this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let c,p,f,g=e.sharedValues;if(g){f=Object.create(null);for(let e=0,t=g.length;e<t;e++)f[g[e]]=e}let h=[],y=0,b=0;this.mapEncode=function(e,t){// Experimental support for premapping keys using _keyMap instad of keyMap - not optiimised yet)
},H[28].handlesRead=!0,H[29]=e=>{// sharedref http://cbor.schmorp.de/value-sharing (for structured clones)
let t=T.get(e);return t.used=!0,t.target},H[258]=e=>new Set(e),(H[259]=e=>(z.mapsAsObjects&&(z.mapsAsObjects=!1,W=!0),e())).handlesRead=!0;J.push((e,t)=>225<=e&&255>=e?l(p().prefixes[e-224],t):28704<=e&&32767>=e?l(p().prefixes[e-28672],t):1879052288<=e&&2147483647>=e?l(p().prefixes[e-1879048192],t):216<=e&&223>=e?l(t,p().suffixes[e-216]):27647<=e&&28671>=e?l(t,p().suffixes[e-27639]):1811940352<=e&&1879048191>=e?l(t,p().suffixes[e-1811939328]):e==1399353956?{packedValues:Y,structures:w.slice(0),version:t}:55799==e?t:void 0);const oe=["Uint8","Uint8Clamped","Uint16","Uint32","BigUint64","Int8","Int16","Int32","BigInt64","Float32","Float64"].map(e=>e+"Array"),de=[64,68,69,70,71,72,77,78,79,81,82];for(let t=0;t<oe.length;t++)g(oe[t],de[t]);const ue=Array(147);// this is a table matching binary exponents to the multiplier to determine significant digit rounding
for(let t=0;256>t;t++)ue[t]=+("1e"+Math.floor(45.15-.30103*t));let ce=new X({useRecords:!1});const le=ce.decode,pe=ce.decodeMultiple,ge={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let fe,he=new Float32Array(1),ye=new Uint8Array(he.buffer,0,4);try{fe=new TextEncoder}catch(e){}let me,be;const ke="undefined"!=typeof Buffer,Oe=ke?Buffer.allocUnsafeSlow:Uint8Array,Re=ke?Buffer:Uint8Array,Me=256,Se=ke?4294967296:2144337920;let _e,Ie,Ue,Ee=0,ve=null;const Ae=Symbol("record-id");class Ce extends X{constructor(e){super(e),this.offset=0;let t,s,n,a,r;e=e||{};let i=Re.prototype.utf8Write?function(e,t,s){return _e.utf8Write(e,t,s)}:!!(fe&&fe.encodeInto)&&function(e,t){return fe.encodeInto(e,_e.subarray(t)).written},o=this,d=e.structures||e.saveStructures,u=e.maxSharedStructures;if(null==u&&(u=d?128:0),8190<u)throw new Error("Maximum maxSharedStructure is 8190");let c=e.sequential;c&&(u=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let l,p,g,f=e.sharedValues;if(f){g=Object.create(null);for(let e=0,t=f.length;e<t;e++)g[f[e]]=e}let h=[],y=0,m=0;this.mapEncode=function(e,t){// Experimental support for premapping keys using _keyMap instad of keyMap - not optiimised yet)
if(this._keyMap&&!this._mapped)//console.log('encoding ', value)

@@ -79,8 +82,8 @@ switch(e.constructor.name){case"Array":e=e.map(e=>this.encodeKeys(e));//case 'Map':

}//this._mapped = true
return this.encode(e,t)},this.encode=function(i,l){if(ve||(ve=new Me(8192),Ae=new DataView(ve.buffer,0,8192),Se=0),Re=ve.length-10,2048>Re-Se?(ve=new Me(ve.length),Ae=new DataView(ve.buffer,0,ve.length),Re=ve.length-10,Se=0):l===De&&(Se=2147483640&Se+7),t=Se,r=o.structuredClone?new Map:null,o.bundleStrings&&"string"!=typeof i?(Ve=[],Ve.size=1/0):Ve=null,s=o.structures,s){if(s.uninitialized){let e=o.getShared()||{};o.structures=s=e.structures||[],o.sharedVersion=e.version;let t=o.sharedValues=e.packedValues;if(t){f={};for(let e=0,s=t.length;e<s;e++)f[t[e]]=e}}let e=s.length;if(e>d&&!u&&(e=d),!s.transitions){s.transitions=Object.create(null);for(let t,n=0;n<e;n++){//console.log('shared struct keys:', keys)
if(t=s[n],!t)continue;let e,a=s.transitions;for(let s,n=0,r=t.length;n<r;n++)s=t[n],e=a[s],e||(e=a[s]=Object.create(null)),a=e;a[Ee]=n}}u||(s.nextId=e)}if(n&&(n=!1),a=s||[],p=f,e.pack){let t=new Map;if(t.values=[],t.encoder=o,t.maxValues=e.maxPrivatePackedValues||(f?16:1/0),t.objectMap=f||!1,t.samplingPackedValues=c,I(i,t),0<t.values.length){ve[Se++]=216,ve[Se++]=51,M(4);let e=t.values;m(e),M(0),M(0),p=Object.create(f||null);for(let t=0,s=e.length;t<s;t++)p[e[t]]=t}}try{// update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
if(m(i),Ve&&A(t,m),o.offset=Se,r&&r.idsToInsert){Se+=2*r.idsToInsert.length,Se>Re&&O(Se),o.offset=Se;let e=v(ve.subarray(t,Se),r.idsToInsert);return r=null,e}return l&De?(ve.start=t,ve.end=Se,ve):ve.subarray(t,Se);// position can change if we call pack again in saveShared, so we get the buffer now
}finally{if(s)if(10>b&&b++,1e4<y)s.transitions=null,b=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][Ee]=void 0;h=[]}if(n&&o.saveShared){o.structures.length>d&&(o.structures=o.structures.slice(0,d));// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
let e=ve.subarray(t,Se);return!1===o.updateSharedData()?o.encode(i):e;// re-encode if it fails
}l&Ke&&(Se=t)}},this.findCommonStringsToPack=()=>(c=new Map,f||(f=Object.create(null)),e=>{let t=e&&e.threshold||4,s=this.pack?e.maxPrivatePackedValues||16:0;g||(g=this.sharedValues=[]);for(let[a,r]of c)r.count>t&&(f[a]=s++,g.push(a),n=!0);for(;this.saveShared&&!1===this.updateSharedData(););c=null});const m=s=>{Se>Re&&(ve=O(Se));var n,a=typeof s;if("string"==a){if(p){let t=p[s];if(0<=t)return void(16>t?ve[Se++]=t+224:(ve[Se++]=198,1&t?m(15-t>>1):m(t-16>>1)));/* } else if (packedStatus.serializationId != serializationId) {
return this.encode(e,t)},this.encode=function(i,d){if(_e||(_e=new Oe(8192),Ie=new DataView(_e.buffer,0,8192),Ee=0),Ue=_e.length-10,2048>Ue-Ee?(_e=new Oe(_e.length),Ie=new DataView(_e.buffer,0,_e.length),Ue=_e.length-10,Ee=0):d===we&&(Ee=2147483640&Ee+7),t=Ee,o.useSelfDescribedHeader&&(Ie.setUint32(Ee,3654940416),Ee+=3),r=o.structuredClone?new Map:null,o.bundleStrings&&"string"!=typeof i?(ve=[],ve.size=1/0):ve=null,s=o.structures,s){if(s.uninitialized){let e=o.getShared()||{};o.structures=s=e.structures||[],o.sharedVersion=e.version;let t=o.sharedValues=e.packedValues;if(t){g={};for(let e=0,s=t.length;e<s;e++)g[t[e]]=e}}let e=s.length;if(e>u&&!c&&(e=u),!s.transitions){s.transitions=Object.create(null);for(let t,n=0;n<e;n++){//console.log('shared struct keys:', keys)
if(t=s[n],!t)continue;let e,a=s.transitions;for(let s=0,r=t.length;s<r;s++){void 0===a[Ae]&&(a[Ae]=n);let r=t[s];e=a[r],e||(e=a[r]=Object.create(null)),a=e}a[Ae]=1048576|n}}c||(s.nextId=e)}if(n&&(n=!1),a=s||[],p=g,e.pack){let t=new Map;if(t.values=[],t.encoder=o,t.maxValues=e.maxPrivatePackedValues||(g?16:1/0),t.objectMap=g||!1,t.samplingPackedValues=l,R(i,t),0<t.values.length){_e[Ee++]=216,_e[Ee++]=51,O(4);let e=t.values;b(e),O(0),O(0),p=Object.create(g||null);for(let t=0,s=e.length;t<s;t++)p[e[t]]=t}}try{// update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
if(b(i),ve&&I(t,b),o.offset=Ee,r&&r.idsToInsert){Ee+=2*r.idsToInsert.length,Ee>Ue&&M(Ee),o.offset=Ee;let e=_(_e.subarray(t,Ee),r.idsToInsert);return r=null,e}return d&we?(_e.start=t,_e.end=Ee,_e):_e.subarray(t,Ee);// position can change if we call encode again in saveShared, so we get the buffer now
}finally{if(s)if(10>m&&m++,s.length>u&&(s.length=u),1e4<y)s.transitions=null,m=0,y=0,0<h.length&&(h=[]);else if(0<h.length&&!c){for(let e=0,t=h.length;e<t;e++)h[e][Ae]=void 0;h=[]}if(n&&o.saveShared){o.structures.length>u&&(o.structures=o.structures.slice(0,u));// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
let e=_e.subarray(t,Ee);return!1===o.updateSharedData()?o.encode(i):e;// re-encode if it fails
}d&Fe&&(Ee=t)}},this.findCommonStringsToPack=()=>(l=new Map,g||(g=Object.create(null)),e=>{let t=e&&e.threshold||4,s=this.pack?e.maxPrivatePackedValues||16:0;f||(f=this.sharedValues=[]);for(let[a,r]of l)r.count>t&&(g[a]=s++,f.push(a),n=!0);for(;this.saveShared&&!1===this.updateSharedData(););l=null});const b=s=>{Ee>Ue&&(_e=M(Ee));var n,a=typeof s;if("string"==a){if(p){let t=p[s];if(0<=t)return void(16>t?_e[Ee++]=t+224:(_e[Ee++]=198,1&t?b(15-t>>1):b(t-16>>1)));/* } else if (packedStatus.serializationId != serializationId) {
packedStatus.serializationId = serializationId

@@ -98,65 +101,23 @@ packedStatus.count = 1

}
} // else any in-doc incrementation?*/if(c&&!e.pack){let e=c.get(s);e?e.count++:c.set(s,{count:1})}}let a=s.length;if(Ve&&4<=a&&1024>a){if((Ve.size+=a)>61440){let e,s=(Ve[0]?3*Ve[0].length+Ve[1].length:0)+10;Se+s>Re&&(ve=O(Se+s)),ve[Se++]=217,ve[Se++]=223,ve[Se++]=249,ve[Se++]=Ve.position?132:130,ve[Se++]=26,e=Se-t,Se+=4,Ve.position&&A(t,m),Ve=["",""],Ve.size=0,Ve.position=e}let e=/[\u0080-\uFFFF]/.test(s);return Ve[e?0:1]+=s,ve[Se++]=e?206:207,void m(a)}let r=32>a?1:256>a?2:65536>a?3:5;// first we estimate the header size, so we can write to the correct location
let o=3*a;if(Se+o>Re&&(ve=O(Se+o)),64>a||!i){let e,t,i,o=Se+r;for(e=0;e<a;e++)t=s.charCodeAt(e),128>t?ve[o++]=t:2048>t?(ve[o++]=192|t>>6,ve[o++]=128|63&t):55296==(64512&t)&&56320==(64512&(i=s.charCodeAt(e+1)))?(t=65536+((1023&t)<<10)+(1023&i),e++,ve[o++]=240|t>>18,ve[o++]=128|63&t>>12,ve[o++]=128|63&t>>6,ve[o++]=128|63&t):(ve[o++]=224|t>>12,ve[o++]=128|63&t>>6,ve[o++]=128|63&t);n=o-Se-r}else n=i(s,Se+r,o);24>n?ve[Se++]=96|n:256>n?(2>r&&ve.copyWithin(Se+2,Se+1,Se+1+n),ve[Se++]=120,ve[Se++]=n):65536>n?(3>r&&ve.copyWithin(Se+3,Se+2,Se+2+n),ve[Se++]=121,ve[Se++]=n>>8,ve[Se++]=255&n):(5>r&&ve.copyWithin(Se+5,Se+3,Se+3+n),ve[Se++]=122,Ae.setUint32(Se,n),Se+=4),Se+=n}else if("number"===a){if(s>>>0===s)24>s?ve[Se++]=s:256>s?(ve[Se++]=24,ve[Se++]=s):65536>s?(ve[Se++]=25,ve[Se++]=s>>8,ve[Se++]=255&s):(ve[Se++]=26,Ae.setUint32(Se,s),Se+=4);else if(s>>0===s)-24<=s?ve[Se++]=31-s:-256<=s?(ve[Se++]=56,ve[Se++]=~s):-65536<=s?(ve[Se++]=57,Ae.setUint16(Se,~s),Se+=2):(ve[Se++]=58,Ae.setUint32(Se,~s),Se+=4);else{let e;if(0<(e=this.useFloat32)&&4294967296>s&&-2147483648<=s){ve[Se++]=250,Ae.setFloat32(Se,s);let t;if(4>e||// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
(t=s*ue[(127&ve[Se])<<1|ve[Se+1]>>7])>>0===t)return void(Se+=4);// move back into position for writing a double
Se--}ve[Se++]=251,Ae.setFloat64(Se,s),Se+=8}}else if("object"===a){if(!s)ve[Se++]=246;else{if(r){let e=r.get(s);if(e){// 16-bit uint
if(ve[Se++]=216,ve[Se++]=29,ve[Se++]=25,!e.references){let t=r.idsToInsert||(r.idsToInsert=[]);e.references=[],t.push(e)}// TODO: also support 32-bit
return e.references.push(Se-t),void(Se+=2)}r.set(s,{offset:Se-t})}let e=s.constructor;if(e===Object)k(s,!0);else if(e===Array){n=s.length,24>n?ve[Se++]=128|n:M(n);for(let e=0;e<n;e++)m(s[e])}else if(e!==Map){for(let e,t=0,n=be.length;t<n;t++)if(e=me[t],s instanceof e){let e=be[t],n=e.tag||e.getTag&&e.getTag(s);return 24>n?ve[Se++]=192|n:256>n?(ve[Se++]=216,ve[Se++]=n):65536>n?(ve[Se++]=217,ve[Se++]=n>>8,ve[Se++]=255&n):-1<n&&(ve[Se++]=218,Ae.setUint32(Se,n),Se+=4),void e.encode.call(this,s,m,O)}if(s[Symbol.iterator]){ve[Se++]=159;// indefinite length array
for(let e of s)m(e);// stop-code
return void(ve[Se++]=255)}// no extension found, write as object
k(s,!s.hasOwnProperty)}else if((this.mapsAsObjects?!1!==this.useTag259ForMaps:this.useTag259ForMaps)&&(ve[Se++]=217,ve[Se++]=1,ve[Se++]=3),n=s.size,24>n?ve[Se++]=160|n:256>n?(ve[Se++]=184,ve[Se++]=n):65536>n?(ve[Se++]=185,ve[Se++]=n>>8,ve[Se++]=255&n):(ve[Se++]=186,Ae.setUint32(Se,n),Se+=4),o.keyMap)for(let[e,t]of s)m(o.encodeKey(e)),m(t);else for(let[e,t]of s)m(e),m(t)}}else if("boolean"===a)ve[Se++]=s?245:244;else if("bigint"===a){if(s<BigInt(1)<<BigInt(64)&&0<=s)ve[Se++]=27,Ae.setBigUint64(Se,s);else if(s>-(BigInt(1)<<BigInt(64))&&0>s)ve[Se++]=59,Ae.setBigUint64(Se,-s-BigInt(1));else// overflow
if(this.largeBigIntToFloat)ve[Se++]=251,Ae.setFloat64(Se,+s);else throw new RangeError(s+" was too large to fit in CBOR 64-bit integer format, set largeBigIntToFloat to convert to float-64");Se+=8}else if("undefined"===a)ve[Se++]=247;else throw new Error("Unknown type: "+a)},k=!1===this.useRecords?this.variableMapSize?e=>{// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
let t=Object.keys(e),s=Object.values(e),n=t.length;if(24>n?ve[Se++]=160|n:256>n?(ve[Se++]=184,ve[Se++]=n):65536>n?(ve[Se++]=185,ve[Se++]=n>>8,ve[Se++]=255&n):(ve[Se++]=186,Ae.setUint32(Se,n),Se+=4),o.keyMap)for(let e=0;e<n;e++)m(encodeKey(t[e])),m(s[e]);else for(let e=0;e<n;e++)m(t[e]),m(s[e])}:(e,s)=>{ve[Se++]=185;// always use map 16, so we can preallocate and set the length afterwards
let n=Se-t;Se+=2;let a=0;if(o.keyMap)for(let t in e)(s||e.hasOwnProperty(t))&&(m(o.encodeKey(t)),m(e[t]),a++);else for(let t in e)(s||e.hasOwnProperty(t))&&(m(t),m(e[t]),a++);ve[n++ +t]=a>>8,ve[n+t]=255&a}:/* sharedStructures ? // For highly stable structures, using for-in can a little bit faster
(object, safePrototype) => {
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null))
let objectOffset = position++ - start
let wroteKeys
for (let key in object) {
if (safePrototype || object.hasOwnProperty(key)) {
nextTransition = transition[key]
if (!nextTransition) {
nextTransition = transition[key] = Object.create(null)
nextTransition.__keys__ = (transition.__keys__ || []).concat([key])
/*let keys = Object.keys(object)
if
let size = 0
let startBranch = transition.__keys__ ? transition.__keys__.length : 0
for (let i = 0, l = keys.length; i++) {
let key = keys[i]
size += key.length << 2
if (i >= startBranch) {
nextTransition = nextTransition[key] = Object.create(null)
nextTransition.__keys__ = keys.slice(0, i + 1)
}
}
makeRoom(position + size)
nextTransition = transition[key]
target.copy(target, )
objectOffset
}
transition = nextTransition
encode(object[key])
}
}
let id = transition.id
if (!id) {
id = transition.id = structures.push(transition.__keys__) + 63
if (sharedStructures.onUpdate)
sharedStructures.onUpdate(id, transition.__keys__)
}
target[objectOffset + start] = id
}*/e=>{let t=Object.keys(e),r=Object.values(e);this.keyMap&&(t=t.map(e=>this.encodeKey(e)));let o,u=a.transitions||(a.transitions=Object.create(null)),c=0,l=t.length;//let parentRecordId
for(let s,n=0;n<l;n++)//if (!parentRecordId)
// parentRecordId = transition[RECORD_SYMBOL]
s=t[n],o=u[s],o||(o=u[s]=Object.create(null),c++),u=o;let p=u[Ee];if(void 0!==p)ve[Se++]=217,ve[Se++]=224|p>>8,ve[Se++]=255&p;else if(p=a.nextId++,p||(p=0,a.nextId=1),p>=Oe&&(a.nextId=(p=d)+1),u[Ee]=p,a[p]=t,s&&s.length<=d)ve[Se++]=217,ve[Se++]=224|p>>8,ve[Se++]=255&p,n=!0;else{Ae.setUint32(Se,3655335680),Se+=3,c&&(y+=b*c),h.length>=Oe-d&&(h.shift()[Ee]=void 0),h.push(u),M(l+2),m(57344+p),m(t);for(let t of Object.values(e))m(t);return}24>l?ve[Se++]=128|l:M(l);for(let t=0;t<l;t++)m(r[t])},O=e=>{var s=Math.min,n=Math.round,a=Math.max;let r;if(16777216<e){// special handling for really large buffers
if(e-t>Ue)throw new Error("Encoded buffer would be larger than maximum buffer size");r=s(Ue,4096*n(a((e-t)*(67108864<e?1.25:2),4194304)/4096))}else// faster handling for smaller buffers
r=(a(e-t<<2,ve.length-1)>>12)+1<<12;let i=new Me(r);return Ae=new DataView(i.buffer,0,r),ve.copy?ve.copy(i,0,t,e):i.set(ve.slice(t,e)),Se-=t,t=0,Re=i.length-10,ve=i}}useBuffer(e){// this means we are finished using our own buffer and we can write over it safely
ve=e,Ae=new DataView(ve.buffer,ve.byteOffset,ve.byteLength),Se=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let e=this.sharedVersion||0;this.sharedVersion=e+1;let t=this.saveShared(new je(this.structures,this.sharedValues,this.sharedVersion),t=>(t&&t.version||0)==e);if(!1===t){// get updated structures and try again if the update failed
let e=this.getShared()||{};this.structures=e.structures||[],this.sharedValues=e.packedValues,this.sharedVersion=e.version}return t}}class je{constructor(e,t,s){this.structures=e,this.packedValues=t,this.version=s}}me=[Date,Set,Error,RegExp,ne,ArrayBuffer,Ie,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,"undefined"==typeof BigUint64Array?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,"undefined"==typeof BigInt64Array?function(){}:BigInt64Array,Float32Array,Float64Array,je],be=[{tag:1,encode(e){let t=e.getTime()/1e3;(this.useTimestamp32||0===e.getMilliseconds())&&0<=t&&4294967296>t?(ve[Se++]=26,Ae.setUint32(Se,t),Se+=4):(ve[Se++]=251,Ae.setFloat64(Se,t),Se+=8)}},{tag:258,// https://github.com/input-output-hk/cbor-sets-spec/blob/master/CBOR_SETS.md
} // else any in-doc incrementation?*/if(l&&!e.pack){let e=l.get(s);e?e.count++:l.set(s,{count:1})}}let a=s.length;if(ve&&4<=a&&1024>a){if((ve.size+=a)>61440){let e,s=(ve[0]?3*ve[0].length+ve[1].length:0)+10;Ee+s>Ue&&(_e=M(Ee+s)),_e[Ee++]=217,_e[Ee++]=223,_e[Ee++]=249,_e[Ee++]=ve.position?132:130,_e[Ee++]=26,e=Ee-t,Ee+=4,ve.position&&I(t,b),ve=["",""],ve.size=0,ve.position=e}let e=/[\u0080-\uFFFF]/.test(s);return ve[e?0:1]+=s,_e[Ee++]=e?206:207,void b(a)}let r=32>a?1:256>a?2:65536>a?3:5;// first we estimate the header size, so we can write to the correct location
let o=3*a;if(Ee+o>Ue&&(_e=M(Ee+o)),64>a||!i){let e,t,i,o=Ee+r;for(e=0;e<a;e++)t=s.charCodeAt(e),128>t?_e[o++]=t:2048>t?(_e[o++]=192|t>>6,_e[o++]=128|63&t):55296==(64512&t)&&56320==(64512&(i=s.charCodeAt(e+1)))?(t=65536+((1023&t)<<10)+(1023&i),e++,_e[o++]=240|t>>18,_e[o++]=128|63&t>>12,_e[o++]=128|63&t>>6,_e[o++]=128|63&t):(_e[o++]=224|t>>12,_e[o++]=128|63&t>>6,_e[o++]=128|63&t);n=o-Ee-r}else n=i(s,Ee+r,o);24>n?_e[Ee++]=96|n:256>n?(2>r&&_e.copyWithin(Ee+2,Ee+1,Ee+1+n),_e[Ee++]=120,_e[Ee++]=n):65536>n?(3>r&&_e.copyWithin(Ee+3,Ee+2,Ee+2+n),_e[Ee++]=121,_e[Ee++]=n>>8,_e[Ee++]=255&n):(5>r&&_e.copyWithin(Ee+5,Ee+3,Ee+3+n),_e[Ee++]=122,Ie.setUint32(Ee,n),Ee+=4),Ee+=n}else if("number"===a){if(s>>>0===s)24>s?_e[Ee++]=s:256>s?(_e[Ee++]=24,_e[Ee++]=s):65536>s?(_e[Ee++]=25,_e[Ee++]=s>>8,_e[Ee++]=255&s):(_e[Ee++]=26,Ie.setUint32(Ee,s),Ee+=4);else if(s>>0===s)-24<=s?_e[Ee++]=31-s:-256<=s?(_e[Ee++]=56,_e[Ee++]=~s):-65536<=s?(_e[Ee++]=57,Ie.setUint16(Ee,~s),Ee+=2):(_e[Ee++]=58,Ie.setUint32(Ee,~s),Ee+=4);else{let e;if(0<(e=this.useFloat32)&&4294967296>s&&-2147483648<=s){_e[Ee++]=250,Ie.setFloat32(Ee,s);let t;if(4>e||// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
(t=s*ue[(127&_e[Ee])<<1|_e[Ee+1]>>7])>>0===t)return void(Ee+=4);// move back into position for writing a double
Ee--}_e[Ee++]=251,Ie.setFloat64(Ee,s),Ee+=8}}else if("object"===a){if(!s)_e[Ee++]=246;else{if(r){let e=r.get(s);if(e){// 16-bit uint
if(_e[Ee++]=216,_e[Ee++]=29,_e[Ee++]=25,!e.references){let t=r.idsToInsert||(r.idsToInsert=[]);e.references=[],t.push(e)}// TODO: also support 32-bit
return e.references.push(Ee-t),void(Ee+=2)}r.set(s,{offset:Ee-t})}let e=s.constructor;if(e===Object)k(s,!0);else if(e===Array){n=s.length,24>n?_e[Ee++]=128|n:O(n);for(let e=0;e<n;e++)b(s[e])}else if(e!==Map){for(let e,t=0,n=me.length;t<n;t++)if(e=be[t],s instanceof e){let e=me[t],n=e.tag||e.getTag&&e.getTag(s);return 24>n?_e[Ee++]=192|n:256>n?(_e[Ee++]=216,_e[Ee++]=n):65536>n?(_e[Ee++]=217,_e[Ee++]=n>>8,_e[Ee++]=255&n):-1<n&&(_e[Ee++]=218,Ie.setUint32(Ee,n),Ee+=4),void e.encode.call(this,s,b,M)}if(s[Symbol.iterator]){_e[Ee++]=159;// indefinite length array
for(let e of s)b(e);// stop-code
return void(_e[Ee++]=255)}// no extension found, write as object
k(s,!s.hasOwnProperty)}else if((this.mapsAsObjects?!1!==this.useTag259ForMaps:this.useTag259ForMaps)&&(_e[Ee++]=217,_e[Ee++]=1,_e[Ee++]=3),n=s.size,24>n?_e[Ee++]=160|n:256>n?(_e[Ee++]=184,_e[Ee++]=n):65536>n?(_e[Ee++]=185,_e[Ee++]=n>>8,_e[Ee++]=255&n):(_e[Ee++]=186,Ie.setUint32(Ee,n),Ee+=4),o.keyMap)for(let[e,t]of s)b(o.encodeKey(e)),b(t);else for(let[e,t]of s)b(e),b(t)}}else if("boolean"===a)_e[Ee++]=s?245:244;else if("bigint"===a){if(s<BigInt(1)<<BigInt(64)&&0<=s)_e[Ee++]=27,Ie.setBigUint64(Ee,s);else if(s>-(BigInt(1)<<BigInt(64))&&0>s)_e[Ee++]=59,Ie.setBigUint64(Ee,-s-BigInt(1));else// overflow
if(this.largeBigIntToFloat)_e[Ee++]=251,Ie.setFloat64(Ee,+s);else throw new RangeError(s+" was too large to fit in CBOR 64-bit integer format, set largeBigIntToFloat to convert to float-64");Ee+=8}else if("undefined"===a)_e[Ee++]=247;else throw new Error("Unknown type: "+a)},k=!1===this.useRecords?this.variableMapSize?e=>{// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
let t=Object.keys(e),s=Object.values(e),n=t.length;if(24>n?_e[Ee++]=160|n:256>n?(_e[Ee++]=184,_e[Ee++]=n):65536>n?(_e[Ee++]=185,_e[Ee++]=n>>8,_e[Ee++]=255&n):(_e[Ee++]=186,Ie.setUint32(Ee,n),Ee+=4),o.keyMap)for(let e=0;e<n;e++)b(encodeKey(t[e])),b(s[e]);else for(let e=0;e<n;e++)b(t[e]),b(s[e])}:(e,s)=>{_e[Ee++]=185;// always use map 16, so we can preallocate and set the length afterwards
let n=Ee-t;Ee+=2;let a=0;if(o.keyMap)for(let t in e)(s||e.hasOwnProperty(t))&&(b(o.encodeKey(t)),b(e[t]),a++);else for(let t in e)(s||e.hasOwnProperty(t))&&(b(t),b(e[t]),a++);_e[n++ +t]=a>>8,_e[n+t]=255&a}:(e,t)=>{let s,r,o,d=a.transitions||(a.transitions=Object.create(null)),c=0,l=0;if(this.keyMap){o=Object.keys(e).map(e=>this.encodeKey(e)),l=o.length;for(let e,t=0;t<l;t++)e=o[t],s=d[e],s||(s=d[e]=Object.create(null),c++),d=s}else for(let n in e)(t||e.hasOwnProperty(n))&&(s=d[n],s||(1048576&d[Ae]&&(r=65535&d[Ae]),s=d[n]=Object.create(null),c++),d=s,l++);let p=d[Ae];if(void 0!==p)p&=65535,_e[Ee++]=217,_e[Ee++]=224|p>>8,_e[Ee++]=255&p;else if(o||(o=d.__keys__||(d.__keys__=Object.keys(e))),void 0===r?(p=a.nextId++,!p&&(p=0,a.nextId=1),p>=Me&&(a.nextId=(p=u)+1)):p=r,a[p]=o,p<u){_e[Ee++]=217,_e[Ee++]=224|p>>8,_e[Ee++]=255&p,d=a.transitions;for(let e=0;e<l;e++)(void 0===d[Ae]||1048576&d[Ae])&&(d[Ae]=p),d=d[o[e]];d[Ae]=1048576|p,n=!0}else{d[Ae]=p,Ie.setUint32(Ee,3655335680),Ee+=3,c&&(y+=m*c),h.length>=Me-u&&(h.shift()[Ae]=void 0),h.push(d),O(l+2),b(57344+p),b(o);for(let t of Object.values(e))b(t);return}for(let s in 24>l?_e[Ee++]=128|l:O(l),e)(t||e.hasOwnProperty(s))&&b(e[s])},M=e=>{var s=Math.min,n=Math.round,a=Math.max;let r;if(16777216<e){// special handling for really large buffers
if(e-t>Se)throw new Error("Encoded buffer would be larger than maximum buffer size");r=s(Se,4096*n(a((e-t)*(67108864<e?1.25:2),4194304)/4096))}else// faster handling for smaller buffers
r=(a(e-t<<2,_e.length-1)>>12)+1<<12;let i=new Oe(r);return Ie=new DataView(i.buffer,0,r),_e.copy?_e.copy(i,0,t,e):i.set(_e.slice(t,e)),Ee-=t,t=0,Ue=i.length-10,_e=i}}useBuffer(e){// this means we are finished using our own buffer and we can write over it safely
_e=e,Ie=new DataView(_e.buffer,_e.byteOffset,_e.byteLength),Ee=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let e=this.sharedVersion||0;this.sharedVersion=e+1;let t=this.structures.slice(0),s=new Ve(t,this.sharedValues,this.sharedVersion),n=this.saveShared(s,t=>(t&&t.version||0)==e);// saveShared may fail to write and reload, or may have reloaded to check compatibility and overwrite saved data, either way load the correct shared data
return!1===n?(s=this.getShared()||{},this.structures=s.structures||[],this.sharedValues=s.packedValues,this.sharedVersion=s.version,this.structures.nextId=this.structures.length):t.forEach((e,t)=>this.structures[t]=e),n}}class Ve{constructor(e,t,s){this.structures=e,this.packedValues=t,this.version=s}}be=[Date,Set,Error,RegExp,ne,ArrayBuffer,Re,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,"undefined"==typeof BigUint64Array?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,"undefined"==typeof BigInt64Array?function(){}:BigInt64Array,Float32Array,Float64Array,Ve],me=[{tag:1,encode(e){let t=e.getTime()/1e3;(this.useTimestamp32||0===e.getMilliseconds())&&0<=t&&4294967296>t?(_e[Ee++]=26,Ie.setUint32(Ee,t),Ee+=4):(_e[Ee++]=251,Ie.setFloat64(Ee,t),Ee+=8)}},{tag:258,// https://github.com/input-output-hk/cbor-sets-spec/blob/master/CBOR_SETS.md
encode(e,t){let s=Array.from(e);t(s)}},{tag:27,// http://cbor.schmorp.de/generic-object
encode(e,t){t([e.name,e.message])}},{tag:27,// http://cbor.schmorp.de/generic-object
encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,s){U(e,s)}},{encode(e,t,s){U(e,s)}},O(64),O(68),O(69),O(70),O(71),O(72),O(77),O(78),O(79),O(81),O(82),{encode(e,t){// write SharedData
let s=e.packedValues||[],n=e.structures||[];if(0<s.values.length){ve[Se++]=216,ve[Se++]=51,M(4);let e=s.values;t(e),M(0),M(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let t=0,s=e.length;t<s;t++)packedObjectMap[e[t]]=t}if(n){Ae.setUint32(Se,3655335424),Se+=3;let s=n.slice(0);s.unshift(57344),s.push(new ne(e.version,1399353956)),t(s)}else t(new ne(e.version,1399353956))}}];let xe=new _e({useRecords:!1});const Ce=xe.encode,{NEVER:Pe,ALWAYS:Le,DECIMAL_ROUND:Be,DECIMAL_FIT:Fe}=fe,De=512,Ke=1024;e.ALWAYS=Le,e.DECIMAL_FIT=Fe,e.DECIMAL_ROUND=Be,e.Decoder=X,e.Encoder=_e,e.FLOAT32_OPTIONS=fe,e.NEVER=Pe,e.REUSE_BUFFER_MODE=De,e.Tag=ne,e.addExtension=R,e.clearSource=m,e.decode=le,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 s=new X(t);let n;const a=e=>{let t;// if there's incomplete data from previous chunk, concatinate and try again
n&&(e=Buffer.concat([n,e]),n=void 0);try{t=s.decodeMultiple(e)}catch(s){if(s.incomplete)n=e.slice(s.lastPosition),t=s.values;else throw s}return t};if("function"==typeof e[Symbol.iterator])return function*(){for(const t of e)yield*a(t)}();return"function"==typeof e[Symbol.asyncIterator]?async function*(){for await(const t of e)yield*a(t)}():void 0},e.decodeMultiple=pe,e.encode=Ce,e.encodeIter=/**
encode(e,t){t(["RegExp",e.source,e.flags])}},{getTag(e){return e.tag},encode(e,t){t(e.value)}},{encode(e,t,s){S(e,s)}},{encode(e,t,s){S(e,s)}},M(64),M(68),M(69),M(70),M(71),M(72),M(77),M(78),M(79),M(81),M(82),{encode(e,t){// write SharedData
let s=e.packedValues||[],n=e.structures||[];if(0<s.values.length){_e[Ee++]=216,_e[Ee++]=51,O(4);let e=s.values;t(e),O(0),O(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let t=0,s=e.length;t<s;t++)packedObjectMap[e[t]]=t}if(n){Ie.setUint32(Ee,3655335424),Ee+=3;let s=n.slice(0);s.unshift(57344),s.push(new ne(e.version,1399353956)),t(s)}else t(new ne(e.version,1399353956))}}];let xe=new Ce({useRecords:!1});const Be=xe.encode,{NEVER:De,ALWAYS:Le,DECIMAL_ROUND:Pe,DECIMAL_FIT:je}=ge,we=512,Fe=1024;e.ALWAYS=Le,e.DECIMAL_FIT=je,e.DECIMAL_ROUND=Pe,e.Decoder=X,e.Encoder=Ce,e.FLOAT32_OPTIONS=ge,e.NEVER=De,e.REUSE_BUFFER_MODE=we,e.Tag=ne,e.addExtension=U,e.clearSource=b,e.decode=le,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 s=new X(t);let n;const a=e=>{let t;// if there's incomplete data from previous chunk, concatinate and try again
n&&(e=Buffer.concat([n,e]),n=void 0);try{t=s.decodeMultiple(e)}catch(s){if(s.incomplete)n=e.slice(s.lastPosition),t=s.values;else throw s}return t};if("function"==typeof e[Symbol.iterator])return function*(){for(const t of e)yield*a(t)}();return"function"==typeof e[Symbol.asyncIterator]?async function*(){for await(const t of e)yield*a(t)}():void 0},e.decodeMultiple=pe,e.encode=Be,e.encodeIter=/**
* Given an Iterable first argument, returns an Iterable where each value is encoded as a Buffer

@@ -167,2 +128,2 @@ * If the argument is only Async Iterable, the return value will be an Async Iterable.

* @returns {IterableIterator|Promise.<AsyncIterableIterator>}
*/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 S(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return V(e,t);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}},e.isNativeAccelerationEnabled=!1,e.roundFloat32=function(e){he[0]=e;let t=ue[(127&ye[3])<<1|ye[2]>>7];return(t*e+(0<e?.5:-.5)>>0)/t},Object.defineProperty(e,"__esModule",{value:!0})});
*/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 E(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return v(e,t);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}},e.isNativeAccelerationEnabled=!1,e.roundFloat32=function(e){he[0]=e;let t=ue[(127&ye[3])<<1|ye[2]>>7];return(t*e+(0<e?.5:-.5)>>0)/t},Object.defineProperty(e,"__esModule",{value:!0})});

@@ -595,3 +595,2 @@ (function (CBOR, chai) {

//import inspector from 'inspector'; inspector.open(9229, null, true); debugger

@@ -670,2 +669,3 @@ function tryRequire(module) {

var serialized = encoder.encode(data);
serialized = encoder.encode(data);
var deserialized = encoder.decode(serialized);

@@ -675,2 +675,33 @@ assert.deepEqual(deserialized, data);

test('mixed structures, shared', function(){
let data1 = { a: 1, b: 2, c: 3 };
let data2 = { a: 1, b: 2, d: 4 };
let data3 = { a: 1, b: 2, e: 5 };
let structures = [];
let encoder = new Encoder({ structures });
var serialized = encoder.encode(data1);
var deserialized = encoder.decode(serialized);
assert.deepEqual(deserialized, data1);
var serialized = encoder.encode(data2);
var deserialized = encoder.decode(serialized);
assert.deepEqual(deserialized, data2);
var serialized = encoder.encode(data3);
var deserialized = encoder.decode(serialized);
assert.deepEqual(deserialized, data3);
});
test('mixed structures, unshared', function(){
let data = [];
let encoder = new Encoder({ });
for (let i = 0; i< 1000; i++) {
data.push({a: 1, ['test' + i]: i});
}
var serialized = encoder.encode(data);
var deserialized = encoder.decode(serialized);
assert.deepEqual(deserialized, data);
serialized = encoder.encode(data);
deserialized = encoder.decode(serialized);
assert.deepEqual(deserialized, data);
});
test('mixed array', function(){

@@ -778,2 +809,12 @@ var data = [

});
test('pack/unpack sample data with self-descriptive header', function(){
var data = sampleData;
let encoder = new Encoder({ useSelfDescribedHeader: true });
var serialized = encoder.encode(data);
var deserialized = encoder.decode(serialized);
assert.deepEqual(deserialized, data);
assert.equal(serialized[0], 0xd9);
assert.equal(serialized[1], 0xd9);
assert.equal(serialized[2], 0xf7);
});
if (typeof Buffer != 'undefined')

@@ -1169,3 +1210,6 @@ test('replace data', function(){

});
test('bad input', function() {
let badInput = Buffer.from('7b2273657269616c6e6f223a2265343a30222c226970223a223139322e3136382e312e3335222c226b6579223a226770735f736563726574227d', 'hex');
assert.throws(function(){ decode(badInput); }); // should throw, not crash
});
});

@@ -1172,0 +1216,0 @@ suite('CBOR performance tests', function(){

@@ -41,8 +41,14 @@ import { Decoder, mult10, Tag, typedArrays, addExtension as decodeAddExtension } from './decode.js'

let encoder = this
let maxSharedStructures = options.maxSharedStructures || 128
let hasSharedStructures = options.structures || options.saveStructures
let maxSharedStructures = options.maxSharedStructures
if (maxSharedStructures == null)
maxSharedStructures = hasSharedStructures ? 128 : 0
if (maxSharedStructures > 8190)
throw new Error('Maximum maxSharedStructure is 8190')
let isSequential = options.sequential
if (isSequential) {
maxSharedStructures = 0
}
if (!this.structures)
this.structures = []
}
if (this.saveStructures)

@@ -95,2 +101,6 @@ this.saveShared = this.saveStructures

start = position
if (encoder.useSelfDescribedHeader) {
targetView.setUint32(position, 0xd9d9f700) // tag two byte, then self-descriptive tag
position += 3
}
referenceMap = encoder.structuredClone ? new Map() : null

@@ -129,2 +139,4 @@ if (encoder.bundleStrings && typeof value !== 'string') {

for (let j = 0, l = keys.length; j < l; j++) {
if (transition[RECORD_SYMBOL] === undefined)
transition[RECORD_SYMBOL] = i
let key = keys[j]

@@ -137,3 +149,3 @@ nextTransition = transition[key]

}
transition[RECORD_SYMBOL] = i
transition[RECORD_SYMBOL] = i | 0x100000
}

@@ -190,3 +202,3 @@ }

}
return target.subarray(start, position) // position can change if we call pack again in saveShared, so we get the buffer now
return target.subarray(start, position) // position can change if we call encode again in saveShared, so we get the buffer now
} finally {

@@ -196,2 +208,4 @@ if (sharedStructures) {

serializationsSinceTransitionRebuild++
if (sharedStructures.length > maxSharedStructures)
sharedStructures.length = maxSharedStructures
if (transitionsCount > 10000) {

@@ -209,2 +223,3 @@ // force a rebuild occasionally after a lot of transitions so it can get cleaned up

recordIdsToRemove = []
//sharedStructures.nextId = maxSharedStructures
}

@@ -621,64 +636,37 @@ }

} :
/* sharedStructures ? // For highly stable structures, using for-in can a little bit faster
(object, safePrototype) => {
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null))
let objectOffset = position++ - start
let wroteKeys
for (let key in object) {
if (safePrototype || object.hasOwnProperty(key)) {
let newTransitions = 0
let length = 0
let parentRecordId
let keys
if (this.keyMap) {
keys = Object.keys(object).map(k => this.encodeKey(k))
length = keys.length
for (let i = 0; i < length; i++) {
let key = keys[i]
nextTransition = transition[key]
if (!nextTransition) {
nextTransition = transition[key] = Object.create(null)
nextTransition.__keys__ = (transition.__keys__ || []).concat([key])
/*let keys = Object.keys(object)
if
let size = 0
let startBranch = transition.__keys__ ? transition.__keys__.length : 0
for (let i = 0, l = keys.length; i++) {
let key = keys[i]
size += key.length << 2
if (i >= startBranch) {
nextTransition = nextTransition[key] = Object.create(null)
nextTransition.__keys__ = keys.slice(0, i + 1)
}
newTransitions++
}
transition = nextTransition
}
} else {
for (let key in object) if (safePrototype || object.hasOwnProperty(key)) {
nextTransition = transition[key]
if (!nextTransition) {
if (transition[RECORD_SYMBOL] & 0x100000) {// this indicates it is a brancheable/extendable terminal node, so we will use this record id and extend it
parentRecordId = transition[RECORD_SYMBOL] & 0xffff
}
makeRoom(position + size)
nextTransition = transition[key]
target.copy(target, )
objectOffset
nextTransition = transition[key] = Object.create(null)
newTransitions++
}
transition = nextTransition
encode(object[key])
length++
}
}
let id = transition.id
if (!id) {
id = transition.id = structures.push(transition.__keys__) + 63
if (sharedStructures.onUpdate)
sharedStructures.onUpdate(id, transition.__keys__)
}
target[objectOffset + start] = id
}*/
(object) => {
let keys = Object.keys(object)
let vals = Object.values(object)
if (this.keyMap) keys = keys.map(k => this.encodeKey(k))
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null))
let newTransitions = 0
let length = keys.length
//let parentRecordId
for (let i = 0; i < length; i++) {
//if (!parentRecordId)
let key = keys[i]
// parentRecordId = transition[RECORD_SYMBOL]
nextTransition = transition[key]
if (!nextTransition) {
nextTransition = transition[key] = Object.create(null)
newTransitions++
}
transition = nextTransition
}
let recordId = transition[RECORD_SYMBOL]
if (recordId !== undefined) {
recordId &= 0xffff
target[position++] = 0xd9

@@ -688,18 +676,31 @@ target[position++] = (recordId >> 8) | 0xe0

} else {
recordId = structures.nextId++
if (!recordId) {
recordId = 0
structures.nextId = 1
if (!keys)
keys = transition.__keys__ || (transition.__keys__ = Object.keys(object))
if (parentRecordId === undefined) {
recordId = structures.nextId++
if (!recordId) {
recordId = 0
structures.nextId = 1
}
if (recordId >= MAX_STRUCTURES) {// cycle back around
structures.nextId = (recordId = maxSharedStructures) + 1
}
} else {
recordId = parentRecordId
}
if (recordId >= MAX_STRUCTURES) {// cycle back around
structures.nextId = (recordId = maxSharedStructures) + 1
}
transition[RECORD_SYMBOL] = recordId
structures[recordId] = keys
if (sharedStructures && sharedStructures.length <= maxSharedStructures) {
if (recordId < maxSharedStructures) {
target[position++] = 0xd9
target[position++] = (recordId >> 8) | 0xe0
target[position++] = recordId & 0xff
transition = structures.transitions
for (let i = 0; i < length; i++) {
if (transition[RECORD_SYMBOL] === undefined || (transition[RECORD_SYMBOL] & 0x100000))
transition[RECORD_SYMBOL] = recordId
transition = transition[keys[i]]
}
transition[RECORD_SYMBOL] = recordId | 0x100000 // indicates it is a extendable terminal
hasSharedUpdate = true
} else {
transition[RECORD_SYMBOL] = recordId
targetView.setUint32(position, 0xd9dfff00) // tag two byte, then record definition id

@@ -725,3 +726,5 @@ position += 3

}
for (let i =0; i < length; i++) encode(vals[i])
for (let key in object)
if (safePrototype || object.hasOwnProperty(key))
encode(object[key])
}

@@ -765,11 +768,18 @@ const makeRoom = (end) => {

this.sharedVersion = lastVersion + 1
let saveResults = this.saveShared(new SharedData(this.structures, this.sharedValues, this.sharedVersion),
let structuresCopy = this.structures.slice(0)
let sharedData = new SharedData(structuresCopy, this.sharedValues, this.sharedVersion)
let saveResults = this.saveShared(sharedData,
existingShared => (existingShared && existingShared.version || 0) == lastVersion)
if (saveResults === false) {
// get updated structures and try again if the update failed
let sharedData = this.getShared() || {}
sharedData = this.getShared() || {}
this.structures = sharedData.structures || []
this.sharedValues = sharedData.packedValues
this.sharedVersion = sharedData.version
this.structures.nextId = this.structures.length
} else {
// restore structures
structuresCopy.forEach((structure, i) => this.structures[i] = structure)
}
// saveShared may fail to write and reload, or may have reloaded to check compatibility and overwrite saved data, either way load the correct shared data
return saveResults

@@ -776,0 +786,0 @@ }

{
"name": "cbor-x",
"author": "Kris Zyp",
"version": "1.0.0",
"version": "1.1.0",
"description": "Ultra-fast and conformant CBOR (RFC 8949) implementation with support for numerous tag extensions including records and structured cloning",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -10,7 +10,6 @@ # cbor-x

<img align="right" src="./assets/performance.png" width="380"/>
The cbor-x package is an extremely fast and conformant CBOR NodeJS/JavaScript implementation. Currently, it is over 3-10x faster than any other CBOR JS implementation (including cbor-js and cborg) and faster than most MessagePack encoders, Avro, and generally faster than native V8 JSON.stringify/parse, on NodeJS. It implements the CBOR format as specificed in [RFC-8949](https://www.rfc-editor.org/rfc/rfc8949.html), [RFC-8746](https://tools.ietf.org/html/rfc8746), [RFC-8742](https://datatracker.ietf.org/doc/html/rfc8742), [Packed CBOR](https://www.ietf.org/id/draft-ietf-cbor-packed-03.html), numerous [registered IANA tag extensions](https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml) (the `x` in cbor-x), and proposed optional [record extension](https://github.com/kriszyp/cbor-records), for defining record structures that makes CBOR even faster and more compact, often over twice as fast as even native JSON functions, and 15-50% more compact. See the performance section for more details. Structured cloning (with support for cyclical references) is supported through these tag extensions.
<img align="right" src="./assets/performance.png" width="380"/>
## Basic Usage

@@ -17,0 +16,0 @@ Install on NodeJS with:

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc