Comparing version 4.3.1 to 4.4.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [4.4.0](https://github.com/aristanetworks/cloudvision/compare/v4.3.1...v4.4.0) (2020-07-14) | ||
### Features | ||
* **a-msgpack:** add Wildcard support ([#124](https://github.com/aristanetworks/cloudvision/issues/124)) ([09d75d7](https://github.com/aristanetworks/cloudvision/commit/09d75d7d80faab8fe70f707e82529f8d5c213d42)) | ||
## [4.3.1](https://github.com/aristanetworks/cloudvision/compare/v4.3.0...v4.3.1) (2020-07-07) | ||
@@ -8,0 +19,0 @@ |
@@ -27,18 +27,23 @@ (function (global, factory) { | ||
this.decoders = []; | ||
this.identifiers = []; | ||
} | ||
register({ type, encode, decode, }) { | ||
register({ type, identifier, encode, decode, }) { | ||
this.encoders[type] = encode; | ||
this.decoders[type] = decode; | ||
this.identifiers.push(identifier); | ||
} | ||
tryToEncode(object) { | ||
// custom extensions | ||
for (let i = 0; i < this.encoders.length; i++) { | ||
const encoder = this.encoders[i]; | ||
const data = encoder(object); | ||
if (data != null) { | ||
const type = i; | ||
return new ExtData(type, data); | ||
encode(object) { | ||
let type = null; | ||
for (let i = 0; i < this.identifiers.length; i++) { | ||
const id = this.identifiers[i]; | ||
if (id(object)) { | ||
type = i; | ||
} | ||
} | ||
return null; | ||
if (type === null) { | ||
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`); | ||
} | ||
const encoder = this.encoders[type]; | ||
const data = encoder(object); | ||
return new ExtData(type, data); | ||
} | ||
@@ -59,2 +64,12 @@ decode(data, type) { | ||
} | ||
function isPlainObject(object) { | ||
if (Object.getPrototypeOf(object) === null) { | ||
return true; | ||
} | ||
let proto = object; | ||
while (Object.getPrototypeOf(proto) !== null) { | ||
proto = Object.getPrototypeOf(proto); | ||
} | ||
return Object.getPrototypeOf(object) === proto; | ||
} | ||
@@ -224,5 +239,19 @@ // Copyright (c) 2018, Arista Networks, Inc. | ||
Pointer.type = 'ptr'; | ||
class Wildcard { | ||
/** | ||
* A class to represent a Wildcard type. | ||
* A Wildcard is a type that matches 1 or more path elements | ||
*/ | ||
constructor() { | ||
this.type = Wildcard.type; | ||
this.value = null; | ||
} | ||
toString() { | ||
return '*'; | ||
} | ||
} | ||
Wildcard.type = '*'; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
function isNeatType(value) { | ||
function isBaseNeatType(value) { | ||
if (typeof value === 'object' && value !== null) { | ||
@@ -233,2 +262,10 @@ if (Object.keys(value).length === 2 && 'type' in value && 'value' in value) { | ||
} | ||
} | ||
return false; | ||
} | ||
function isNeatType(value) { | ||
if (typeof value === 'object' && value !== null) { | ||
if (isBaseNeatType(value)) { | ||
return true; | ||
} | ||
if (Object.keys(value).length === 3 && | ||
@@ -720,8 +757,3 @@ 'type' in value && | ||
encodeObject(object, depth) { | ||
// try to encode objects with custom codec first of non-primitives | ||
const ext = this.extensionCodec.tryToEncode(object); | ||
if (ext != null) { | ||
this.encodeExtension(ext); | ||
} | ||
else if (Array.isArray(object)) { | ||
if (Array.isArray(object)) { | ||
if (isJsbi(object)) { | ||
@@ -744,8 +776,13 @@ this.encodeJSBI(object); | ||
else if (typeof object === 'object') { | ||
if (isNeatType(object)) { | ||
if (isBaseNeatType(object)) { | ||
this.encodeNeatClass(object); | ||
} | ||
else { | ||
else if (isPlainObject(object)) { | ||
// Find out if it is a plain object | ||
this.encodePlainObject(object, depth); | ||
} | ||
else { | ||
// Otherwise try to encode objects with custom codec of non-primitives | ||
this.encodeExtension(this.extensionCodec.encode(object)); | ||
} | ||
} | ||
@@ -1527,6 +1564,3 @@ else if (typeof object === 'function') { | ||
return (data) => { | ||
if (data instanceof Pointer) { | ||
return encode(data.value, { extensionCodec: codec }); | ||
} | ||
return null; | ||
return encode(data.value, { extensionCodec: codec }); | ||
}; | ||
@@ -1543,5 +1577,16 @@ } | ||
} | ||
function encodeWildcard() { | ||
return () => { | ||
return new Uint8Array(); | ||
}; | ||
} | ||
function decodeWildcard() { | ||
return () => { | ||
return new Wildcard(); | ||
}; | ||
} | ||
// Copyright (c) 2018, Arista Networks, Inc. | ||
const POINTER_TYPE = 0; | ||
const WILDCARD_TYPE = 1; | ||
const NeatTypes = { | ||
@@ -1555,2 +1600,3 @@ Bool, | ||
Str, | ||
Wildcard, | ||
}; | ||
@@ -1560,5 +1606,12 @@ const Codec = new ExtensionCodec(); | ||
type: POINTER_TYPE, | ||
identifier: (data) => data instanceof Pointer, | ||
encode: encodePointer(Codec), | ||
decode: decodePointer(Codec), | ||
}); | ||
Codec.register({ | ||
type: WILDCARD_TYPE, | ||
identifier: (data) => data instanceof Wildcard, | ||
encode: encodeWildcard(), | ||
decode: decodeWildcard(), | ||
}); | ||
@@ -1565,0 +1618,0 @@ exports.Bool = Bool; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("jsbi"),require("base64-js")):"function"==typeof define&&define.amd?define(["exports","jsbi","base64-js"],e):e((t=t||self)["a-msgpack"]={},t.jsbi,t.base64Js)}(this,(function(t,e,i){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;class s{constructor(t,e){this.type=t,this.data=e,this.type=t,this.data=e}}class n{constructor(){this.encoders=[],this.decoders=[]}register({type:t,encode:e,decode:i}){this.encoders[t]=e,this.decoders[t]=i}tryToEncode(t){for(let e=0;e<this.encoders.length;e++){const i=(0,this.encoders[e])(t);if(null!=i){return new s(e,i)}}return null}decode(t,e){return(0,this.decoders[e])(t,e)}}function r(t){return Array.isArray(t)&&"__clzmsd"in t}n.defaultCodec=new n;class o{constructor(t){this.type=o.type,this.value=t?parseFloat(String(t)):0}toString(){const t=this.value.toString();return t.includes(".")?t:this.value.toFixed(1)}}o.type="float32";class h{constructor(t){this.type=h.type,this.value=t?parseFloat(String(t)):0}toString(){const t=this.value.toString();return t.includes(".")?t:this.value.toFixed(1)}}h.type="float64";class a{constructor(t,i=!1){if(this.type=a.type,"string"==typeof t){let s;s="undefined"==typeof BigInt||i?e.BigInt:BigInt,this.value=parseInt(t,10)>Number.MAX_SAFE_INTEGER||parseInt(t,10)<-1*Number.MAX_SAFE_INTEGER?s(t):parseInt(t,10)}else"bigint"==typeof t||r(t)?this.value=t:this.value=parseInt(String(t),10)}toString(){return this.value.toString()}}a.type="int";class c{constructor(t){this.type=c.type,this.value=!!t}toString(){return this.value?"true":"false"}}c.type="bool";class u{constructor(){this.type=u.type,this.value=null}toString(){return"null"}}u.type="nil";class f{constructor(t){switch(this.type=f.type,typeof t){case"string":this.value=t;break;case"bigint":this.value=t.toString();break;case"undefined":this.value="";break;default:this.value=JSON.stringify(t)}r(t)&&(this.value=t.toString())}toString(){return this.value}}f.type="str";class l{constructor(t=[]){let e;if(this.delimiter="/",this.type=l.type,Array.isArray(t))this.value=t;else{e="string"!=typeof t?JSON.stringify(t):t;const i=e.split(this.delimiter);for(;""===i[0];)i.shift();this.value=i.map(t=>{try{return JSON.parse(t)}catch(t){}return t})}}toString(){return this.value.map(t=>"string"==typeof t?t:JSON.stringify(t)).join(this.delimiter)}}function d(t){if("object"==typeof t&&null!==t){if(2===Object.keys(t).length&&"type"in t&&"value"in t){const e=t;return[c.type,o.type,h.type,a.type,u.type,f.type].includes(e.type)}if(3===Object.keys(t).length&&"type"in t&&"value"in t&&"delimiter"in t){return t.type===l.type}}return!1}function p(t,e){return function(t,e){const i=Math.min(t.length,e.length);if(t===e)return 0;for(let s=0;s<i;s+=1)if(t[s]!==e[s])return t[s]-e[s];return t.length-e.length}(t[0],e[0])}l.type="ptr";class y{static serialize(t){return{__neatTypeClass:t.type,value:t.value}}static deserialize(t){return new y.NEAT_TYPE_MAP[t.__neatTypeClass](t.value)}}function g(t,e,i){let s=t,n=e;const r=!i&&2147483648&t;r&&(s=~t,n=4294967296-e);let o="";for(;;){const t=s%10*4294967296+n;if(s=Math.floor(s/10),n=Math.floor(t/10),o=(t%10).toString(10)+o,!s&&!n)break}return r&&(o="-"+o),o}function w(t,e,i){let s=0;const n=i.length;let r=0,o=0;"-"===i[0]&&s++;const h=s;for(;s<n;){const t=parseInt(i[s++],10);if(Number.isNaN(t)||t<0)break;o=10*o+t,r=10*r+Math.floor(o/4294967296),o%=4294967296}h&&(r=~r,o?o=4294967296-o:r++),t.setUint32(e,r),t.setUint32(e+4,o)}function U(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t instanceof ArrayBuffer?new Uint8Array(t):Uint8Array.from(t)}y.NEAT_TYPE_MAP={float32:o,float64:h,int:a,ptr:l,str:f,nil:u,bool:c};const b="never"!==process.env.TEXT_ENCODING&&"undefined"!=typeof TextEncoder&&"undefined"!=typeof TextDecoder;function S(t){const e=t.length;let i=0,s=0;for(;s<e;){let n=t.charCodeAt(s++);if(0!=(4294967168&n))if(0==(4294965248&n))i+=2;else{if(n>=55296&&n<=56319&&s<e){const e=t.charCodeAt(s);56320==(64512&e)&&(++s,n=((1023&n)<<10)+(1023&e)+65536)}i+=0==(4294901760&n)?3:4}else i++}return i}const x=b?new TextEncoder:void 0,v="force"!==process.env.TEXT_ENCODING?200:0;const B=(null==x?void 0:x.encodeInto)?function(t,e,i){x.encodeInto(t,e.subarray(i))}:function(t,e,i){e.set(x.encode(t),i)};function m(t,e,i){let s=e;const n=s+i,r=[];let o="";for(;s<n;){const e=t[s++];if(0==(128&e))r.push(e);else if(192==(224&e)){const i=63&t[s++];r.push((31&e)<<6|i)}else if(224==(240&e)){const i=63&t[s++],n=63&t[s++];r.push((31&e)<<12|i<<6|n)}else if(240==(248&e)){let i=(7&e)<<18|(63&t[s++])<<12|(63&t[s++])<<6|63&t[s++];i>65535&&(i-=65536,r.push(i>>>10&1023|55296),i=56320|1023&i),r.push(i)}else r.push(e);r.length>=4096&&(o+=String.fromCharCode(...r),r.length=0)}return r.length>0&&(o+=String.fromCharCode(...r)),o}const I=b?new TextDecoder:null,E="force"!==process.env.TEXT_DECODER?200:0;class A{constructor(t=n.defaultCodec,e=100,i=2048){this.pos=0,this.extensionCodec=t,this.maxDepth=e,this.initialBufferSize=i,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}keyEncoder(t,e){const i=new A(this.extensionCodec,this.maxDepth,this.initialBufferSize);return i.encode(t,e),i.getUint8Array()}encode(t,e){if(e>this.maxDepth)throw new Error("Too deep objects in depth "+e);null==t?this.encodeNil():"boolean"==typeof t?this.encodeBoolean(t):"number"==typeof t?this.encodeNumber(t):"string"==typeof t?this.encodeString(t):this.encodeObject(t,e)}getUint8Array(){return this.bytes.subarray(0,this.pos)}ensureBufferSizeToWrite(t){const e=this.pos+t;this.view.byteLength<e&&this.resizeBuffer(2*e)}resizeBuffer(t){const e=new ArrayBuffer(t),i=new Uint8Array(e),s=new DataView(e);i.set(this.bytes),this.view=s,this.bytes=i}encodeNil(){this.writeU8(192)}encodeBoolean(t){!1===t?this.writeU8(194):this.writeU8(195)}encodeNumber(t){Number.isSafeInteger(t)?t>=0?t<128?this.writeU8(t):t<256?(this.writeU8(204),this.writeU8(t)):t<65536?(this.writeU8(205),this.writeU16(t)):t<4294967296?(this.writeU8(206),this.writeU32(t)):(this.writeU8(207),this.writeU64(t)):t>=-32?this.writeU8(224|t+32):t>=-128?(this.writeU8(208),this.writeI8(t)):t>=-32768?(this.writeU8(209),this.writeI16(t)):t>=-2147483648?(this.writeU8(210),this.writeI32(t)):(this.writeU8(211),this.writeI64(t)):(this.writeU8(203),this.writeF64(t))}writeStringHeader(t){t<256?(this.writeU8(196),this.writeU8(t)):t<65536?(this.writeU8(197),this.writeU16(t)):(this.writeU8(198),this.writeU32(t))}encodeString(t){const e=t.length;if(b&&e>v){const e=S(t);this.ensureBufferSizeToWrite(5+e),this.writeStringHeader(e),B(t,this.bytes,this.pos),this.pos+=e}else{const e=S(t);this.ensureBufferSizeToWrite(5+e),this.writeStringHeader(e),function(t,e,i){const s=t.length;let n=i,r=0;for(;r<s;){let i=t.charCodeAt(r++);if(0!=(4294967168&i)){if(0==(4294965248&i))e[n++]=i>>6&31|192;else{if(i>=55296&&i<=56319&&r<s){const e=t.charCodeAt(r);56320==(64512&e)&&(++r,i=((1023&i)<<10)+(1023&e)+65536)}0==(4294901760&i)?(e[n++]=i>>12&15|224,e[n++]=i>>6&63|128):(e[n++]=i>>18&7|240,e[n++]=i>>12&63|128,e[n++]=i>>6&63|128)}e[n++]=63&i|128}else e[n++]=i}}(t,this.bytes,this.pos),this.pos+=e}}encodeObject(t,e){const i=this.extensionCodec.tryToEncode(t);if(null!=i)this.encodeExtension(i);else if(Array.isArray(t))r(t)?this.encodeJSBI(t):this.encodeArray(t,e);else if(ArrayBuffer.isView(t))this.encodeBinary(t);else if("bigint"==typeof t)this.encodeBigInt(t);else if(t instanceof Map)this.encodeMap(t,e);else if("object"==typeof t)d(t)?this.encodeNeatClass(t):this.encodePlainObject(t,e);else{if("function"!=typeof t)throw new Error("Unrecognized object: "+Object.prototype.toString.apply(t));this.encodeNil()}}encodeNeatClass(t){t instanceof o?(this.writeU8(202),this.writeF32(t.value)):t instanceof h?(this.writeU8(203),this.writeF64(t.value)):t instanceof a?"bigint"==typeof t.value?this.encodeBigInt(t.value):r(t.value)?this.encodeJSBI(t.value):this.encodeNumber(t.value):t instanceof f?this.encodeString(t.value):t instanceof c?this.encodeBoolean(t.value):this.encodeNil()}encodeBigInt(t){t===BigInt(0)||BigInt.asIntN(32,t)>0||t<0&&BigInt.asUintN(32,t)===t*BigInt(-1)?this.encodeNumber(Number(t)):t<0?(this.writeU8(211),this.writeI64(t)):(this.writeU8(207),this.writeU64(t))}encodeJSBI(t){const i=t.toString();"0"===i||e.LE(t,2147483647)&&e.GE(t,-4294967295)||i<"0"&&e.GE(t,-4294967295)?this.encodeNumber(Number(t)):i<"0"?(this.writeU8(211),this.writeI64(i)):(this.writeU8(207),this.writeU64(i))}encodeBinary(t){const e=t.byteLength;e<256?(this.writeU8(196),this.writeU8(e)):e<65536?(this.writeU8(197),this.writeU16(e)):(this.writeU8(198),this.writeU32(e));const i=U(t);this.writeU8a(i)}encodeArray(t,e){const i=t.length;i<16?this.writeU8(144+i):i<65536?(this.writeU8(220),this.writeU16(i)):(this.writeU8(221),this.writeU32(i));for(const i of t)this.encode(i,e+1)}encodeMap(t,e){const i=t.size,s=[];i<16?this.writeU8(128+i):i<65536?(this.writeU8(222),this.writeU16(i)):(this.writeU8(223),this.writeU32(i)),t.forEach((t,i)=>{const n=this.keyEncoder(i,e+1);s.push([n,t])}),s.sort(p),s.forEach(t=>{this.writeU8a(t[0]),this.encode(t[1],e+1)})}encodePlainObject(t,e){this.encodeMap(new Map(Object.entries(t)),e)}encodeExtension(t){const e=t.data.length;1===e?this.writeU8(212):2===e?this.writeU8(213):4===e?this.writeU8(214):8===e?this.writeU8(215):16===e?this.writeU8(216):e<256?(this.writeU8(199),this.writeU8(e)):e<65536?(this.writeU8(200),this.writeU16(e)):(this.writeU8(201),this.writeU32(e)),this.writeI8(t.type),this.writeU8a(t.data)}writeU8(t){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,t),this.pos++}writeU8a(t){const e=t.length;this.ensureBufferSizeToWrite(e),this.bytes.set(t,this.pos),this.pos+=e}writeI8(t){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,t),this.pos++}writeU16(t){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,t),this.pos+=2}writeI16(t){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,t),this.pos+=2}writeU32(t){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,t),this.pos+=4}writeI32(t){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,t),this.pos+=4}writeF32(t){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,t),this.pos+=4}writeF64(t){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,t),this.pos+=8}writeU64(t){this.ensureBufferSizeToWrite(8),function(t,e,i){if("number"==typeof i){const s=i/4294967296,n=i;t.setUint32(e,s),t.setUint32(e+4,n)}else"bigint"==typeof i?t.setBigUint64(e,i):"string"==typeof i&&w(t,e,i)}(this.view,this.pos,t),this.pos+=8}writeI64(t){this.ensureBufferSizeToWrite(8),function(t,e,i){if("number"==typeof i){const s=Math.floor(i/4294967296),n=i;t.setUint32(e,s),t.setUint32(e+4,n)}else"bigint"==typeof i?t.setBigInt64(e,i):"string"==typeof i&&w(t,e,i)}(this.view,this.pos,t),this.pos+=8}}const N={};function T(t,e=N){const i=new A(e.extensionCodec,e.maxDepth,e.initialBufferSize);return i.encode(t,1),i.getUint8Array()}const L=t=>"string"===typeof t,k=new DataView(new ArrayBuffer(0)),z=new Uint8Array(k.buffer),C=new class{constructor(t=16,e=16){this.maxKeyLength=t,this.maxLengthPerKey=e,this.caches=[];for(let t=0;t<this.maxKeyLength;t++)this.caches.push([])}canBeCached(t){return t>0&&t<=this.maxKeyLength}get(t,e,i){const s=this.caches[i-1],n=s.length;t:for(let r=0;r<n;r++){const n=s[r],o=n.bytes;for(let s=0;s<i;s++)if(o[s]!==t[e+s])continue t;return n.value}return null}store(t,e){const i=this.caches[t.length-1],s={bytes:t,value:e};i.length>=this.maxLengthPerKey?i[Math.random()*i.length|0]=s:i.push(s)}decode(t,e,i){const s=this.get(t,e,i);if(s)return s;const n=m(t,e,i),r=Uint8Array.prototype.slice.call(t,e,e+i);return this.store(r,n),n}};class M{constructor(t=n.defaultCodec,e=!1,i=4294967295,s=4294967295,r=4294967295,o=4294967295,h=4294967295,a=C){this.totalPos=0,this.pos=0,this.view=k,this.bytes=z,this.stack=[],this.extensionCodec=t,this.cachedKeyDecoder=a,this.useJSBI=e,this.maxStrLength=i,this.maxBinLength=s,this.maxArrayLength=r,this.maxMapLength=o,this.maxExtLength=h}setBuffer(t){this.bytes=U(t),this.view=function(t){if(t instanceof ArrayBuffer)return new DataView(t);const e=U(t);return new DataView(e.buffer,e.byteOffset,e.byteLength)}(this.bytes),this.pos=0}hasRemaining(t=1){return this.view.byteLength-this.pos>=t}createNoExtraBytesError(t){const{view:e,pos:i}=this;return new RangeError(`Extra ${e.byteLength-i} byte(s) found at buffer[${t}]`)}decodeSingleSync(){const t=this.decodeSync();if(this.hasRemaining())throw this.createNoExtraBytesError(this.pos);return t}decodeSync(){t:for(;;){const e=this.readU8();let s;if(e>=224)s=e-256;else if(e<192)if(e<128)s=e;else if(e<144){const t=e-128;if(0!==t){this.pushMapState(t);continue t}s={}}else{const t=e-144;if(0!==t){this.pushArrayState(t);continue t}s=[]}else if(192===e)s=null;else if(194===e)s=!1;else if(195===e)s=!0;else if(202===e)s=this.readF32();else if(203===e)s=this.readF64();else if(204===e)s=this.readU8();else if(205===e)s=this.readU16();else if(206===e)s=this.readU32();else if(207===e)s=this.readU64();else if(208===e)s=this.readI8();else if(209===e)s=this.readI16();else if(210===e)s=this.readI32();else if(211===e)s=this.readI64();else{if(220===e){const t=this.readU16();this.pushArrayState(t);continue t}if(221===e){const t=this.readU32();this.pushArrayState(t);continue t}if(222===e){const t=this.readU16();this.pushMapState(t);continue t}if(223===e){const t=this.readU32();this.pushMapState(t);continue t}if(196===e){const t=this.lookU8();s=this.decodeUtf8String(t,1)}else if(197===e){const t=this.lookU16();s=this.decodeUtf8String(t,2)}else if(198===e){const t=this.lookU32();s=this.decodeUtf8String(t,4)}else if(212===e)s=this.decodeExtension(1,0);else if(213===e)s=this.decodeExtension(2,0);else if(214===e)s=this.decodeExtension(4,0);else if(215===e)s=this.decodeExtension(8,0);else if(216===e)s=this.decodeExtension(16,0);else if(199===e){const t=this.lookU8();s=this.decodeExtension(t,1)}else if(200===e){const t=this.lookU16();s=this.decodeExtension(t,2)}else{if(201!==e)throw new Error("Unrecognized type byte: "+`${(t=e)<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`);{const t=this.lookU32();s=this.decodeExtension(t,4)}}}const n=this.stack;for(;n.length>0;){const t=n[n.length-1];if(0===t.type){if(t.array[t.position]=s,t.position++,t.position!==t.size)continue t;n.pop(),s=t.array}else{if(1===t.type){L(s)||(t.serializedKey=i.fromByteArray(this.bytes.slice(t.keyStart,this.pos))),t.key=s,t.type=2;continue t}if(L(t.key)?t.map[t.key]=s:t.map[t.serializedKey]={_key:t.key,_value:s},t.readCount++,t.readCount!==t.size){t.key=null,t.type=1,n[n.length-1].keyStart=this.pos;continue t}n.pop(),s=t.map}}return s}var t}pushMapState(t){if(t>this.maxMapLength)throw new Error(`Max length exceeded: map length (${t}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.push({type:1,size:t,keyStart:1,key:null,serializedKey:null,readCount:0,map:{}})}pushArrayState(t){if(t>this.maxArrayLength)throw new Error(`Max length exceeded: array length (${t}) > maxArrayLength (${this.maxArrayLength})`);this.stack.push({type:0,size:t,keyStart:1,array:new Array(t),position:0})}decodeUtf8String(t,e){var i;if(t>this.maxStrLength)throw new Error(`Max length exceeded: UTF-8 byte length (${t}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+e+t)throw new RangeError("Insufficient data");const s=this.pos+e;let n;return n=this.stateIsMapKey()&&(null===(i=this.cachedKeyDecoder)||void 0===i?void 0:i.canBeCached(t))?this.cachedKeyDecoder.decode(this.bytes,s,t):b&&t>E?function(t,e,i){const s=t.subarray(e,e+i);return I.decode(s)}(this.bytes,s,t):m(this.bytes,s,t),this.pos+=e+t,n}stateIsMapKey(){if(this.stack.length>0){return 1===this.stack[this.stack.length-1].type}return!1}decodeBinary(t,e){if(t>this.maxBinLength)throw new Error(`Max length exceeded: bin length (${t}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(t+e))throw new RangeError("Insufficient data");const i=this.pos+e,s=this.bytes.subarray(i,i+t);return this.pos+=e+t,s}decodeExtension(t,e){if(t>this.maxExtLength)throw new Error(`Max length exceeded: ext length (${t}) > maxExtLength (${this.maxExtLength})`);const i=this.view.getInt8(this.pos+e),s=this.decodeBinary(t,e+1);return this.extensionCodec.decode(s,i)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const t=this.view.getUint8(this.pos);return this.pos++,t}readI8(){const t=this.view.getInt8(this.pos);return this.pos++,t}readU16(){const t=this.view.getUint16(this.pos);return this.pos+=2,t}readI16(){const t=this.view.getInt16(this.pos);return this.pos+=2,t}readU32(){const t=this.view.getUint32(this.pos);return this.pos+=4,t}readI32(){const t=this.view.getInt32(this.pos);return this.pos+=4,t}readU64(){const t=function(t,i,s){if(!t.getBigUint64||s){const s=t.getUint32(i),n=t.getUint32(i+4);return e.BigInt(g(s,n,!0))}return t.getBigUint64(i)}(this.view,this.pos,this.useJSBI);return this.pos+=8,t}readI64(){const t=function(t,i,s){if(!t.getBigInt64||s){const s=t.getInt32(i),n=t.getUint32(i+4);return e.BigInt(g(s,n,!1))}return t.getBigInt64(i)}(this.view,this.pos,this.useJSBI);return this.pos+=8,t}readF32(){const t=this.view.getFloat32(this.pos);return this.pos+=4,t}readF64(){const t=this.view.getFloat64(this.pos);return this.pos+=8,t}}const O={};function j(t,e=O){const i=new M(e.extensionCodec,e.useJSBI,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength,e.cachedKeyDecoder);return i.setBuffer(t),i.decodeSingleSync()}function F(t){const e=typeof t;if("number"===e){return String(t).split(".").length>1?new h(t):new a(t)}if("boolean"===e)return new c(t);if("string"===e)return new f(t);if(null!==t&&"object"===e){let e=t;for(;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);if(Object.getPrototypeOf(t)===e)return function(t){const e=new Map,i=Object.keys(t);for(let s=0;s<i.length;s+=1){const n=i[s],r=t[n],o=F(n),h=F(r);e.set(o,h)}return e}(t)}return new u}const _={Bool:c,Float32:o,Float64:h,Int:a,Nil:u,Pointer:l,Str:f},D=new n;var P;D.register({type:0,encode:(P=D,t=>t instanceof l?T(t.value,{extensionCodec:P}):null),decode:function(t){return e=>{const i=j(e,{extensionCodec:t});return Array.isArray(i)?new l(i):new l}}(D)}),t.Bool=c,t.Codec=D,t.ExtData=s,t.ExtensionCodec=n,t.Float32=o,t.Float64=h,t.Int=a,t.NeatTypeSerializer=y,t.NeatTypes=_,t.Nil=u,t.Pointer=l,t.Str=f,t.createBaseType=F,t.decode=j,t.encode=T,t.isJsbi=r,t.isNeatType=d,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("jsbi"),require("base64-js")):"function"==typeof define&&define.amd?define(["exports","jsbi","base64-js"],e):e((t=t||self)["a-msgpack"]={},t.jsbi,t.base64Js)}(this,(function(t,e,i){"use strict";e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;class s{constructor(t,e){this.type=t,this.data=e,this.type=t,this.data=e}}class n{constructor(){this.encoders=[],this.decoders=[],this.identifiers=[]}register({type:t,identifier:e,encode:i,decode:s}){this.encoders[t]=i,this.decoders[t]=s,this.identifiers.push(e)}encode(t){let e=null;for(let i=0;i<this.identifiers.length;i++){(0,this.identifiers[i])(t)&&(e=i)}if(null===e)throw new Error("Unrecognized object: "+Object.prototype.toString.apply(t));const i=(0,this.encoders[e])(t);return new s(e,i)}decode(t,e){return(0,this.decoders[e])(t,e)}}function r(t){return Array.isArray(t)&&"__clzmsd"in t}n.defaultCodec=new n;class o{constructor(t){this.type=o.type,this.value=t?parseFloat(String(t)):0}toString(){const t=this.value.toString();return t.includes(".")?t:this.value.toFixed(1)}}o.type="float32";class h{constructor(t){this.type=h.type,this.value=t?parseFloat(String(t)):0}toString(){const t=this.value.toString();return t.includes(".")?t:this.value.toFixed(1)}}h.type="float64";class a{constructor(t,i=!1){if(this.type=a.type,"string"==typeof t){let s;s="undefined"==typeof BigInt||i?e.BigInt:BigInt,this.value=parseInt(t,10)>Number.MAX_SAFE_INTEGER||parseInt(t,10)<-1*Number.MAX_SAFE_INTEGER?s(t):parseInt(t,10)}else"bigint"==typeof t||r(t)?this.value=t:this.value=parseInt(String(t),10)}toString(){return this.value.toString()}}a.type="int";class c{constructor(t){this.type=c.type,this.value=!!t}toString(){return this.value?"true":"false"}}c.type="bool";class f{constructor(){this.type=f.type,this.value=null}toString(){return"null"}}f.type="nil";class u{constructor(t){switch(this.type=u.type,typeof t){case"string":this.value=t;break;case"bigint":this.value=t.toString();break;case"undefined":this.value="";break;default:this.value=JSON.stringify(t)}r(t)&&(this.value=t.toString())}toString(){return this.value}}u.type="str";class l{constructor(t=[]){let e;if(this.delimiter="/",this.type=l.type,Array.isArray(t))this.value=t;else{e="string"!=typeof t?JSON.stringify(t):t;const i=e.split(this.delimiter);for(;""===i[0];)i.shift();this.value=i.map(t=>{try{return JSON.parse(t)}catch(t){}return t})}}toString(){return this.value.map(t=>"string"==typeof t?t:JSON.stringify(t)).join(this.delimiter)}}l.type="ptr";class d{constructor(){this.type=d.type,this.value=null}toString(){return"*"}}function p(t){if("object"==typeof t&&null!==t&&2===Object.keys(t).length&&"type"in t&&"value"in t){const e=t;return[c.type,o.type,h.type,a.type,f.type,u.type].includes(e.type)}return!1}function y(t,e){return function(t,e){const i=Math.min(t.length,e.length);if(t===e)return 0;for(let s=0;s<i;s+=1)if(t[s]!==e[s])return t[s]-e[s];return t.length-e.length}(t[0],e[0])}d.type="*";class g{static serialize(t){return{__neatTypeClass:t.type,value:t.value}}static deserialize(t){return new g.NEAT_TYPE_MAP[t.__neatTypeClass](t.value)}}function w(t,e,i){let s=t,n=e;const r=!i&&2147483648&t;r&&(s=~t,n=4294967296-e);let o="";for(;;){const t=s%10*4294967296+n;if(s=Math.floor(s/10),n=Math.floor(t/10),o=(t%10).toString(10)+o,!s&&!n)break}return r&&(o="-"+o),o}function U(t,e,i){let s=0;const n=i.length;let r=0,o=0;"-"===i[0]&&s++;const h=s;for(;s<n;){const t=parseInt(i[s++],10);if(Number.isNaN(t)||t<0)break;o=10*o+t,r=10*r+Math.floor(o/4294967296),o%=4294967296}h&&(r=~r,o?o=4294967296-o:r++),t.setUint32(e,r),t.setUint32(e+4,o)}function b(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t instanceof ArrayBuffer?new Uint8Array(t):Uint8Array.from(t)}g.NEAT_TYPE_MAP={float32:o,float64:h,int:a,ptr:l,str:u,nil:f,bool:c};const S="never"!==process.env.TEXT_ENCODING&&"undefined"!=typeof TextEncoder&&"undefined"!=typeof TextDecoder;function v(t){const e=t.length;let i=0,s=0;for(;s<e;){let n=t.charCodeAt(s++);if(0!=(4294967168&n))if(0==(4294965248&n))i+=2;else{if(n>=55296&&n<=56319&&s<e){const e=t.charCodeAt(s);56320==(64512&e)&&(++s,n=((1023&n)<<10)+(1023&e)+65536)}i+=0==(4294901760&n)?3:4}else i++}return i}const x=S?new TextEncoder:void 0,B="force"!==process.env.TEXT_ENCODING?200:0;const m=(null==x?void 0:x.encodeInto)?function(t,e,i){x.encodeInto(t,e.subarray(i))}:function(t,e,i){e.set(x.encode(t),i)};function I(t,e,i){let s=e;const n=s+i,r=[];let o="";for(;s<n;){const e=t[s++];if(0==(128&e))r.push(e);else if(192==(224&e)){const i=63&t[s++];r.push((31&e)<<6|i)}else if(224==(240&e)){const i=63&t[s++],n=63&t[s++];r.push((31&e)<<12|i<<6|n)}else if(240==(248&e)){let i=(7&e)<<18|(63&t[s++])<<12|(63&t[s++])<<6|63&t[s++];i>65535&&(i-=65536,r.push(i>>>10&1023|55296),i=56320|1023&i),r.push(i)}else r.push(e);r.length>=4096&&(o+=String.fromCharCode(...r),r.length=0)}return r.length>0&&(o+=String.fromCharCode(...r)),o}const E=S?new TextDecoder:null,A="force"!==process.env.TEXT_DECODER?200:0;class N{constructor(t=n.defaultCodec,e=100,i=2048){this.pos=0,this.extensionCodec=t,this.maxDepth=e,this.initialBufferSize=i,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}keyEncoder(t,e){const i=new N(this.extensionCodec,this.maxDepth,this.initialBufferSize);return i.encode(t,e),i.getUint8Array()}encode(t,e){if(e>this.maxDepth)throw new Error("Too deep objects in depth "+e);null==t?this.encodeNil():"boolean"==typeof t?this.encodeBoolean(t):"number"==typeof t?this.encodeNumber(t):"string"==typeof t?this.encodeString(t):this.encodeObject(t,e)}getUint8Array(){return this.bytes.subarray(0,this.pos)}ensureBufferSizeToWrite(t){const e=this.pos+t;this.view.byteLength<e&&this.resizeBuffer(2*e)}resizeBuffer(t){const e=new ArrayBuffer(t),i=new Uint8Array(e),s=new DataView(e);i.set(this.bytes),this.view=s,this.bytes=i}encodeNil(){this.writeU8(192)}encodeBoolean(t){!1===t?this.writeU8(194):this.writeU8(195)}encodeNumber(t){Number.isSafeInteger(t)?t>=0?t<128?this.writeU8(t):t<256?(this.writeU8(204),this.writeU8(t)):t<65536?(this.writeU8(205),this.writeU16(t)):t<4294967296?(this.writeU8(206),this.writeU32(t)):(this.writeU8(207),this.writeU64(t)):t>=-32?this.writeU8(224|t+32):t>=-128?(this.writeU8(208),this.writeI8(t)):t>=-32768?(this.writeU8(209),this.writeI16(t)):t>=-2147483648?(this.writeU8(210),this.writeI32(t)):(this.writeU8(211),this.writeI64(t)):(this.writeU8(203),this.writeF64(t))}writeStringHeader(t){t<256?(this.writeU8(196),this.writeU8(t)):t<65536?(this.writeU8(197),this.writeU16(t)):(this.writeU8(198),this.writeU32(t))}encodeString(t){const e=t.length;if(S&&e>B){const e=v(t);this.ensureBufferSizeToWrite(5+e),this.writeStringHeader(e),m(t,this.bytes,this.pos),this.pos+=e}else{const e=v(t);this.ensureBufferSizeToWrite(5+e),this.writeStringHeader(e),function(t,e,i){const s=t.length;let n=i,r=0;for(;r<s;){let i=t.charCodeAt(r++);if(0!=(4294967168&i)){if(0==(4294965248&i))e[n++]=i>>6&31|192;else{if(i>=55296&&i<=56319&&r<s){const e=t.charCodeAt(r);56320==(64512&e)&&(++r,i=((1023&i)<<10)+(1023&e)+65536)}0==(4294901760&i)?(e[n++]=i>>12&15|224,e[n++]=i>>6&63|128):(e[n++]=i>>18&7|240,e[n++]=i>>12&63|128,e[n++]=i>>6&63|128)}e[n++]=63&i|128}else e[n++]=i}}(t,this.bytes,this.pos),this.pos+=e}}encodeObject(t,e){if(Array.isArray(t))r(t)?this.encodeJSBI(t):this.encodeArray(t,e);else if(ArrayBuffer.isView(t))this.encodeBinary(t);else if("bigint"==typeof t)this.encodeBigInt(t);else if(t instanceof Map)this.encodeMap(t,e);else if("object"==typeof t)p(t)?this.encodeNeatClass(t):!function(t){if(null===Object.getPrototypeOf(t))return!0;let e=t;for(;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}(t)?this.encodeExtension(this.extensionCodec.encode(t)):this.encodePlainObject(t,e);else{if("function"!=typeof t)throw new Error("Unrecognized object: "+Object.prototype.toString.apply(t));this.encodeNil()}}encodeNeatClass(t){t instanceof o?(this.writeU8(202),this.writeF32(t.value)):t instanceof h?(this.writeU8(203),this.writeF64(t.value)):t instanceof a?"bigint"==typeof t.value?this.encodeBigInt(t.value):r(t.value)?this.encodeJSBI(t.value):this.encodeNumber(t.value):t instanceof u?this.encodeString(t.value):t instanceof c?this.encodeBoolean(t.value):this.encodeNil()}encodeBigInt(t){t===BigInt(0)||BigInt.asIntN(32,t)>0||t<0&&BigInt.asUintN(32,t)===t*BigInt(-1)?this.encodeNumber(Number(t)):t<0?(this.writeU8(211),this.writeI64(t)):(this.writeU8(207),this.writeU64(t))}encodeJSBI(t){const i=t.toString();"0"===i||e.LE(t,2147483647)&&e.GE(t,-4294967295)||i<"0"&&e.GE(t,-4294967295)?this.encodeNumber(Number(t)):i<"0"?(this.writeU8(211),this.writeI64(i)):(this.writeU8(207),this.writeU64(i))}encodeBinary(t){const e=t.byteLength;e<256?(this.writeU8(196),this.writeU8(e)):e<65536?(this.writeU8(197),this.writeU16(e)):(this.writeU8(198),this.writeU32(e));const i=b(t);this.writeU8a(i)}encodeArray(t,e){const i=t.length;i<16?this.writeU8(144+i):i<65536?(this.writeU8(220),this.writeU16(i)):(this.writeU8(221),this.writeU32(i));for(const i of t)this.encode(i,e+1)}encodeMap(t,e){const i=t.size,s=[];i<16?this.writeU8(128+i):i<65536?(this.writeU8(222),this.writeU16(i)):(this.writeU8(223),this.writeU32(i)),t.forEach((t,i)=>{const n=this.keyEncoder(i,e+1);s.push([n,t])}),s.sort(y),s.forEach(t=>{this.writeU8a(t[0]),this.encode(t[1],e+1)})}encodePlainObject(t,e){this.encodeMap(new Map(Object.entries(t)),e)}encodeExtension(t){const e=t.data.length;1===e?this.writeU8(212):2===e?this.writeU8(213):4===e?this.writeU8(214):8===e?this.writeU8(215):16===e?this.writeU8(216):e<256?(this.writeU8(199),this.writeU8(e)):e<65536?(this.writeU8(200),this.writeU16(e)):(this.writeU8(201),this.writeU32(e)),this.writeI8(t.type),this.writeU8a(t.data)}writeU8(t){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,t),this.pos++}writeU8a(t){const e=t.length;this.ensureBufferSizeToWrite(e),this.bytes.set(t,this.pos),this.pos+=e}writeI8(t){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,t),this.pos++}writeU16(t){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,t),this.pos+=2}writeI16(t){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,t),this.pos+=2}writeU32(t){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,t),this.pos+=4}writeI32(t){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,t),this.pos+=4}writeF32(t){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,t),this.pos+=4}writeF64(t){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,t),this.pos+=8}writeU64(t){this.ensureBufferSizeToWrite(8),function(t,e,i){if("number"==typeof i){const s=i/4294967296,n=i;t.setUint32(e,s),t.setUint32(e+4,n)}else"bigint"==typeof i?t.setBigUint64(e,i):"string"==typeof i&&U(t,e,i)}(this.view,this.pos,t),this.pos+=8}writeI64(t){this.ensureBufferSizeToWrite(8),function(t,e,i){if("number"==typeof i){const s=Math.floor(i/4294967296),n=i;t.setUint32(e,s),t.setUint32(e+4,n)}else"bigint"==typeof i?t.setBigInt64(e,i):"string"==typeof i&&U(t,e,i)}(this.view,this.pos,t),this.pos+=8}}const L={};function k(t,e=L){const i=new N(e.extensionCodec,e.maxDepth,e.initialBufferSize);return i.encode(t,1),i.getUint8Array()}const T=t=>"string"===typeof t,O=new DataView(new ArrayBuffer(0)),z=new Uint8Array(O.buffer),C=new class{constructor(t=16,e=16){this.maxKeyLength=t,this.maxLengthPerKey=e,this.caches=[];for(let t=0;t<this.maxKeyLength;t++)this.caches.push([])}canBeCached(t){return t>0&&t<=this.maxKeyLength}get(t,e,i){const s=this.caches[i-1],n=s.length;t:for(let r=0;r<n;r++){const n=s[r],o=n.bytes;for(let s=0;s<i;s++)if(o[s]!==t[e+s])continue t;return n.value}return null}store(t,e){const i=this.caches[t.length-1],s={bytes:t,value:e};i.length>=this.maxLengthPerKey?i[Math.random()*i.length|0]=s:i.push(s)}decode(t,e,i){const s=this.get(t,e,i);if(s)return s;const n=I(t,e,i),r=Uint8Array.prototype.slice.call(t,e,e+i);return this.store(r,n),n}};class M{constructor(t=n.defaultCodec,e=!1,i=4294967295,s=4294967295,r=4294967295,o=4294967295,h=4294967295,a=C){this.totalPos=0,this.pos=0,this.view=O,this.bytes=z,this.stack=[],this.extensionCodec=t,this.cachedKeyDecoder=a,this.useJSBI=e,this.maxStrLength=i,this.maxBinLength=s,this.maxArrayLength=r,this.maxMapLength=o,this.maxExtLength=h}setBuffer(t){this.bytes=b(t),this.view=function(t){if(t instanceof ArrayBuffer)return new DataView(t);const e=b(t);return new DataView(e.buffer,e.byteOffset,e.byteLength)}(this.bytes),this.pos=0}hasRemaining(t=1){return this.view.byteLength-this.pos>=t}createNoExtraBytesError(t){const{view:e,pos:i}=this;return new RangeError(`Extra ${e.byteLength-i} byte(s) found at buffer[${t}]`)}decodeSingleSync(){const t=this.decodeSync();if(this.hasRemaining())throw this.createNoExtraBytesError(this.pos);return t}decodeSync(){t:for(;;){const e=this.readU8();let s;if(e>=224)s=e-256;else if(e<192)if(e<128)s=e;else if(e<144){const t=e-128;if(0!==t){this.pushMapState(t);continue t}s={}}else{const t=e-144;if(0!==t){this.pushArrayState(t);continue t}s=[]}else if(192===e)s=null;else if(194===e)s=!1;else if(195===e)s=!0;else if(202===e)s=this.readF32();else if(203===e)s=this.readF64();else if(204===e)s=this.readU8();else if(205===e)s=this.readU16();else if(206===e)s=this.readU32();else if(207===e)s=this.readU64();else if(208===e)s=this.readI8();else if(209===e)s=this.readI16();else if(210===e)s=this.readI32();else if(211===e)s=this.readI64();else{if(220===e){const t=this.readU16();this.pushArrayState(t);continue t}if(221===e){const t=this.readU32();this.pushArrayState(t);continue t}if(222===e){const t=this.readU16();this.pushMapState(t);continue t}if(223===e){const t=this.readU32();this.pushMapState(t);continue t}if(196===e){const t=this.lookU8();s=this.decodeUtf8String(t,1)}else if(197===e){const t=this.lookU16();s=this.decodeUtf8String(t,2)}else if(198===e){const t=this.lookU32();s=this.decodeUtf8String(t,4)}else if(212===e)s=this.decodeExtension(1,0);else if(213===e)s=this.decodeExtension(2,0);else if(214===e)s=this.decodeExtension(4,0);else if(215===e)s=this.decodeExtension(8,0);else if(216===e)s=this.decodeExtension(16,0);else if(199===e){const t=this.lookU8();s=this.decodeExtension(t,1)}else if(200===e){const t=this.lookU16();s=this.decodeExtension(t,2)}else{if(201!==e)throw new Error("Unrecognized type byte: "+`${(t=e)<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`);{const t=this.lookU32();s=this.decodeExtension(t,4)}}}const n=this.stack;for(;n.length>0;){const t=n[n.length-1];if(0===t.type){if(t.array[t.position]=s,t.position++,t.position!==t.size)continue t;n.pop(),s=t.array}else{if(1===t.type){T(s)||(t.serializedKey=i.fromByteArray(this.bytes.slice(t.keyStart,this.pos))),t.key=s,t.type=2;continue t}if(T(t.key)?t.map[t.key]=s:t.map[t.serializedKey]={_key:t.key,_value:s},t.readCount++,t.readCount!==t.size){t.key=null,t.type=1,n[n.length-1].keyStart=this.pos;continue t}n.pop(),s=t.map}}return s}var t}pushMapState(t){if(t>this.maxMapLength)throw new Error(`Max length exceeded: map length (${t}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.push({type:1,size:t,keyStart:1,key:null,serializedKey:null,readCount:0,map:{}})}pushArrayState(t){if(t>this.maxArrayLength)throw new Error(`Max length exceeded: array length (${t}) > maxArrayLength (${this.maxArrayLength})`);this.stack.push({type:0,size:t,keyStart:1,array:new Array(t),position:0})}decodeUtf8String(t,e){var i;if(t>this.maxStrLength)throw new Error(`Max length exceeded: UTF-8 byte length (${t}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+e+t)throw new RangeError("Insufficient data");const s=this.pos+e;let n;return n=this.stateIsMapKey()&&(null===(i=this.cachedKeyDecoder)||void 0===i?void 0:i.canBeCached(t))?this.cachedKeyDecoder.decode(this.bytes,s,t):S&&t>A?function(t,e,i){const s=t.subarray(e,e+i);return E.decode(s)}(this.bytes,s,t):I(this.bytes,s,t),this.pos+=e+t,n}stateIsMapKey(){if(this.stack.length>0){return 1===this.stack[this.stack.length-1].type}return!1}decodeBinary(t,e){if(t>this.maxBinLength)throw new Error(`Max length exceeded: bin length (${t}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(t+e))throw new RangeError("Insufficient data");const i=this.pos+e,s=this.bytes.subarray(i,i+t);return this.pos+=e+t,s}decodeExtension(t,e){if(t>this.maxExtLength)throw new Error(`Max length exceeded: ext length (${t}) > maxExtLength (${this.maxExtLength})`);const i=this.view.getInt8(this.pos+e),s=this.decodeBinary(t,e+1);return this.extensionCodec.decode(s,i)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const t=this.view.getUint8(this.pos);return this.pos++,t}readI8(){const t=this.view.getInt8(this.pos);return this.pos++,t}readU16(){const t=this.view.getUint16(this.pos);return this.pos+=2,t}readI16(){const t=this.view.getInt16(this.pos);return this.pos+=2,t}readU32(){const t=this.view.getUint32(this.pos);return this.pos+=4,t}readI32(){const t=this.view.getInt32(this.pos);return this.pos+=4,t}readU64(){const t=function(t,i,s){if(!t.getBigUint64||s){const s=t.getUint32(i),n=t.getUint32(i+4);return e.BigInt(w(s,n,!0))}return t.getBigUint64(i)}(this.view,this.pos,this.useJSBI);return this.pos+=8,t}readI64(){const t=function(t,i,s){if(!t.getBigInt64||s){const s=t.getInt32(i),n=t.getUint32(i+4);return e.BigInt(w(s,n,!1))}return t.getBigInt64(i)}(this.view,this.pos,this.useJSBI);return this.pos+=8,t}readF32(){const t=this.view.getFloat32(this.pos);return this.pos+=4,t}readF64(){const t=this.view.getFloat64(this.pos);return this.pos+=8,t}}const j={};function F(t,e=j){const i=new M(e.extensionCodec,e.useJSBI,e.maxStrLength,e.maxBinLength,e.maxArrayLength,e.maxMapLength,e.maxExtLength,e.cachedKeyDecoder);return i.setBuffer(t),i.decodeSingleSync()}function _(t){const e=typeof t;if("number"===e){return String(t).split(".").length>1?new h(t):new a(t)}if("boolean"===e)return new c(t);if("string"===e)return new u(t);if(null!==t&&"object"===e){let e=t;for(;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);if(Object.getPrototypeOf(t)===e)return function(t){const e=new Map,i=Object.keys(t);for(let s=0;s<i.length;s+=1){const n=i[s],r=t[n],o=_(n),h=_(r);e.set(o,h)}return e}(t)}return new f}const D={Bool:c,Float32:o,Float64:h,Int:a,Nil:f,Pointer:l,Str:u,Wildcard:d},P=new n;var W;P.register({type:0,identifier:t=>t instanceof l,encode:(W=P,t=>k(t.value,{extensionCodec:W})),decode:function(t){return e=>{const i=F(e,{extensionCodec:t});return Array.isArray(i)?new l(i):new l}}(P)}),P.register({type:1,identifier:t=>t instanceof d,encode:()=>new Uint8Array,decode:()=>new d}),t.Bool=c,t.Codec=P,t.ExtData=s,t.ExtensionCodec=n,t.Float32=o,t.Float64=h,t.Int=a,t.NeatTypeSerializer=g,t.NeatTypes=D,t.Nil=f,t.Pointer=l,t.Str=u,t.createBaseType=_,t.decode=F,t.encode=k,t.isJsbi=r,t.isNeatType=function(t){if("object"==typeof t&&null!==t){if(p(t))return!0;if(3===Object.keys(t).length&&"type"in t&&"value"in t&&"delimiter"in t){return t.type===l.type}}return!1},Object.defineProperty(t,"__esModule",{value:!0})})); |
@@ -22,18 +22,23 @@ import JSBI from 'jsbi'; | ||
this.decoders = []; | ||
this.identifiers = []; | ||
} | ||
register({ type, encode, decode, }) { | ||
register({ type, identifier, encode, decode, }) { | ||
this.encoders[type] = encode; | ||
this.decoders[type] = decode; | ||
this.identifiers.push(identifier); | ||
} | ||
tryToEncode(object) { | ||
// custom extensions | ||
for (let i = 0; i < this.encoders.length; i++) { | ||
const encoder = this.encoders[i]; | ||
const data = encoder(object); | ||
if (data != null) { | ||
const type = i; | ||
return new ExtData(type, data); | ||
encode(object) { | ||
let type = null; | ||
for (let i = 0; i < this.identifiers.length; i++) { | ||
const id = this.identifiers[i]; | ||
if (id(object)) { | ||
type = i; | ||
} | ||
} | ||
return null; | ||
if (type === null) { | ||
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`); | ||
} | ||
const encoder = this.encoders[type]; | ||
const data = encoder(object); | ||
return new ExtData(type, data); | ||
} | ||
@@ -54,2 +59,12 @@ decode(data, type) { | ||
} | ||
function isPlainObject(object) { | ||
if (Object.getPrototypeOf(object) === null) { | ||
return true; | ||
} | ||
let proto = object; | ||
while (Object.getPrototypeOf(proto) !== null) { | ||
proto = Object.getPrototypeOf(proto); | ||
} | ||
return Object.getPrototypeOf(object) === proto; | ||
} | ||
@@ -219,5 +234,19 @@ // Copyright (c) 2018, Arista Networks, Inc. | ||
Pointer.type = 'ptr'; | ||
class Wildcard { | ||
/** | ||
* A class to represent a Wildcard type. | ||
* A Wildcard is a type that matches 1 or more path elements | ||
*/ | ||
constructor() { | ||
this.type = Wildcard.type; | ||
this.value = null; | ||
} | ||
toString() { | ||
return '*'; | ||
} | ||
} | ||
Wildcard.type = '*'; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
function isNeatType(value) { | ||
function isBaseNeatType(value) { | ||
if (typeof value === 'object' && value !== null) { | ||
@@ -228,2 +257,10 @@ if (Object.keys(value).length === 2 && 'type' in value && 'value' in value) { | ||
} | ||
} | ||
return false; | ||
} | ||
function isNeatType(value) { | ||
if (typeof value === 'object' && value !== null) { | ||
if (isBaseNeatType(value)) { | ||
return true; | ||
} | ||
if (Object.keys(value).length === 3 && | ||
@@ -715,8 +752,3 @@ 'type' in value && | ||
encodeObject(object, depth) { | ||
// try to encode objects with custom codec first of non-primitives | ||
const ext = this.extensionCodec.tryToEncode(object); | ||
if (ext != null) { | ||
this.encodeExtension(ext); | ||
} | ||
else if (Array.isArray(object)) { | ||
if (Array.isArray(object)) { | ||
if (isJsbi(object)) { | ||
@@ -739,8 +771,13 @@ this.encodeJSBI(object); | ||
else if (typeof object === 'object') { | ||
if (isNeatType(object)) { | ||
if (isBaseNeatType(object)) { | ||
this.encodeNeatClass(object); | ||
} | ||
else { | ||
else if (isPlainObject(object)) { | ||
// Find out if it is a plain object | ||
this.encodePlainObject(object, depth); | ||
} | ||
else { | ||
// Otherwise try to encode objects with custom codec of non-primitives | ||
this.encodeExtension(this.extensionCodec.encode(object)); | ||
} | ||
} | ||
@@ -1522,6 +1559,3 @@ else if (typeof object === 'function') { | ||
return (data) => { | ||
if (data instanceof Pointer) { | ||
return encode(data.value, { extensionCodec: codec }); | ||
} | ||
return null; | ||
return encode(data.value, { extensionCodec: codec }); | ||
}; | ||
@@ -1538,5 +1572,16 @@ } | ||
} | ||
function encodeWildcard() { | ||
return () => { | ||
return new Uint8Array(); | ||
}; | ||
} | ||
function decodeWildcard() { | ||
return () => { | ||
return new Wildcard(); | ||
}; | ||
} | ||
// Copyright (c) 2018, Arista Networks, Inc. | ||
const POINTER_TYPE = 0; | ||
const WILDCARD_TYPE = 1; | ||
const NeatTypes = { | ||
@@ -1550,2 +1595,3 @@ Bool, | ||
Str, | ||
Wildcard, | ||
}; | ||
@@ -1555,6 +1601,13 @@ const Codec = new ExtensionCodec(); | ||
type: POINTER_TYPE, | ||
identifier: (data) => data instanceof Pointer, | ||
encode: encodePointer(Codec), | ||
decode: decodePointer(Codec), | ||
}); | ||
Codec.register({ | ||
type: WILDCARD_TYPE, | ||
identifier: (data) => data instanceof Wildcard, | ||
encode: encodeWildcard(), | ||
decode: decodeWildcard(), | ||
}); | ||
export { Bool, Codec, ExtData, ExtensionCodec, Float32, Float64, Int, NeatTypeSerializer, NeatTypes, Nil, Pointer, Str, createBaseType, decode, encode, isJsbi, isNeatType }; |
@@ -28,18 +28,23 @@ 'use strict'; | ||
this.decoders = []; | ||
this.identifiers = []; | ||
} | ||
register({ type, encode, decode, }) { | ||
register({ type, identifier, encode, decode, }) { | ||
this.encoders[type] = encode; | ||
this.decoders[type] = decode; | ||
this.identifiers.push(identifier); | ||
} | ||
tryToEncode(object) { | ||
// custom extensions | ||
for (let i = 0; i < this.encoders.length; i++) { | ||
const encoder = this.encoders[i]; | ||
const data = encoder(object); | ||
if (data != null) { | ||
const type = i; | ||
return new ExtData(type, data); | ||
encode(object) { | ||
let type = null; | ||
for (let i = 0; i < this.identifiers.length; i++) { | ||
const id = this.identifiers[i]; | ||
if (id(object)) { | ||
type = i; | ||
} | ||
} | ||
return null; | ||
if (type === null) { | ||
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`); | ||
} | ||
const encoder = this.encoders[type]; | ||
const data = encoder(object); | ||
return new ExtData(type, data); | ||
} | ||
@@ -60,2 +65,12 @@ decode(data, type) { | ||
} | ||
function isPlainObject(object) { | ||
if (Object.getPrototypeOf(object) === null) { | ||
return true; | ||
} | ||
let proto = object; | ||
while (Object.getPrototypeOf(proto) !== null) { | ||
proto = Object.getPrototypeOf(proto); | ||
} | ||
return Object.getPrototypeOf(object) === proto; | ||
} | ||
@@ -225,5 +240,19 @@ // Copyright (c) 2018, Arista Networks, Inc. | ||
Pointer.type = 'ptr'; | ||
class Wildcard { | ||
/** | ||
* A class to represent a Wildcard type. | ||
* A Wildcard is a type that matches 1 or more path elements | ||
*/ | ||
constructor() { | ||
this.type = Wildcard.type; | ||
this.value = null; | ||
} | ||
toString() { | ||
return '*'; | ||
} | ||
} | ||
Wildcard.type = '*'; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
function isNeatType(value) { | ||
function isBaseNeatType(value) { | ||
if (typeof value === 'object' && value !== null) { | ||
@@ -234,2 +263,10 @@ if (Object.keys(value).length === 2 && 'type' in value && 'value' in value) { | ||
} | ||
} | ||
return false; | ||
} | ||
function isNeatType(value) { | ||
if (typeof value === 'object' && value !== null) { | ||
if (isBaseNeatType(value)) { | ||
return true; | ||
} | ||
if (Object.keys(value).length === 3 && | ||
@@ -721,8 +758,3 @@ 'type' in value && | ||
encodeObject(object, depth) { | ||
// try to encode objects with custom codec first of non-primitives | ||
const ext = this.extensionCodec.tryToEncode(object); | ||
if (ext != null) { | ||
this.encodeExtension(ext); | ||
} | ||
else if (Array.isArray(object)) { | ||
if (Array.isArray(object)) { | ||
if (isJsbi(object)) { | ||
@@ -745,8 +777,13 @@ this.encodeJSBI(object); | ||
else if (typeof object === 'object') { | ||
if (isNeatType(object)) { | ||
if (isBaseNeatType(object)) { | ||
this.encodeNeatClass(object); | ||
} | ||
else { | ||
else if (isPlainObject(object)) { | ||
// Find out if it is a plain object | ||
this.encodePlainObject(object, depth); | ||
} | ||
else { | ||
// Otherwise try to encode objects with custom codec of non-primitives | ||
this.encodeExtension(this.extensionCodec.encode(object)); | ||
} | ||
} | ||
@@ -1528,6 +1565,3 @@ else if (typeof object === 'function') { | ||
return (data) => { | ||
if (data instanceof Pointer) { | ||
return encode(data.value, { extensionCodec: codec }); | ||
} | ||
return null; | ||
return encode(data.value, { extensionCodec: codec }); | ||
}; | ||
@@ -1544,5 +1578,16 @@ } | ||
} | ||
function encodeWildcard() { | ||
return () => { | ||
return new Uint8Array(); | ||
}; | ||
} | ||
function decodeWildcard() { | ||
return () => { | ||
return new Wildcard(); | ||
}; | ||
} | ||
// Copyright (c) 2018, Arista Networks, Inc. | ||
const POINTER_TYPE = 0; | ||
const WILDCARD_TYPE = 1; | ||
const NeatTypes = { | ||
@@ -1556,2 +1601,3 @@ Bool, | ||
Str, | ||
Wildcard, | ||
}; | ||
@@ -1561,5 +1607,12 @@ const Codec = new ExtensionCodec(); | ||
type: POINTER_TYPE, | ||
identifier: (data) => data instanceof Pointer, | ||
encode: encodePointer(Codec), | ||
decode: decodePointer(Codec), | ||
}); | ||
Codec.register({ | ||
type: WILDCARD_TYPE, | ||
identifier: (data) => data instanceof Wildcard, | ||
encode: encodeWildcard(), | ||
decode: decodeWildcard(), | ||
}); | ||
@@ -1566,0 +1619,0 @@ exports.Bool = Bool; |
{ | ||
"name": "a-msgpack", | ||
"version": "4.3.1", | ||
"version": "4.4.0", | ||
"description": "A minimalistic NEAT (MessagePack based) encoder and decoder for JavaScript.", | ||
@@ -59,4 +59,4 @@ "author": "Stephane Rufer <stephane@arista.com>", | ||
"@arista/prettier-config": "1.1.3", | ||
"@rollup/plugin-commonjs": "12.0.0", | ||
"@rollup/plugin-node-resolve": "8.0.0", | ||
"@rollup/plugin-commonjs": "14.0.0", | ||
"@rollup/plugin-node-resolve": "8.4.0", | ||
"@rollup/plugin-typescript": "4.1.2", | ||
@@ -71,3 +71,3 @@ "@types/base64-js": "1.2.5", | ||
"eslint-config-arista-ts": "1.1.21", | ||
"eslint-plugin-arista": "0.1.32", | ||
"eslint-plugin-arista": "0.1.35", | ||
"eslint-plugin-import": "2.22.0", | ||
@@ -78,12 +78,12 @@ "jest": "26.0.1", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.20.0", | ||
"rollup": "2.21.0", | ||
"rollup-plugin-terser": "5.3.0", | ||
"ts-jest": "26.0.0", | ||
"ts-jest": "26.1.2", | ||
"tslib": "2.0.0", | ||
"typedoc": "0.17.8", | ||
"typedoc-neo-theme": "1.0.8", | ||
"typedoc-neo-theme": "1.0.9", | ||
"typedoc-plugin-markdown": "2.2.17", | ||
"typescript": "3.9.6" | ||
}, | ||
"gitHead": "d90c25f7f7ba17f90f6f1e846435fcb956db35de" | ||
"gitHead": "f234605a98f4df8bfa7ffd6de950d440b6351bdf" | ||
} |
@@ -8,4 +8,4 @@ import JSBI from 'jsbi'; | ||
import { Bool, Float32, Float64, Int, Str } from './neat/NeatTypes'; | ||
import { isNeatType, sortMapByKey } from './neat/utils'; | ||
import { isJsbi } from './utils/data'; | ||
import { isBaseNeatType, sortMapByKey } from './neat/utils'; | ||
import { isJsbi, isPlainObject } from './utils/data'; | ||
import { setInt64, setUint64 } from './utils/int'; | ||
@@ -196,7 +196,3 @@ import { ensureUint8Array } from './utils/typedArrays'; | ||
encodeObject(object: unknown, depth: number): void { | ||
// try to encode objects with custom codec first of non-primitives | ||
const ext = this.extensionCodec.tryToEncode(object); | ||
if (ext != null) { | ||
this.encodeExtension(ext); | ||
} else if (Array.isArray(object)) { | ||
if (Array.isArray(object)) { | ||
if (isJsbi(object)) { | ||
@@ -214,6 +210,10 @@ this.encodeJSBI(object as JSBI); | ||
} else if (typeof object === 'object') { | ||
if (isNeatType(object)) { | ||
if (isBaseNeatType(object)) { | ||
this.encodeNeatClass(object as NeatType); | ||
} else if (isPlainObject(object as object)) { | ||
// Find out if it is a plain object | ||
this.encodePlainObject(object as Record<string, unknown>, depth); | ||
} else { | ||
this.encodePlainObject(object as Record<string, unknown>, depth); | ||
// Otherwise try to encode objects with custom codec of non-primitives | ||
this.encodeExtension(this.extensionCodec.encode(object)); | ||
} | ||
@@ -220,0 +220,0 @@ } else if (typeof object === 'function') { |
@@ -6,7 +6,7 @@ // ExtensionCodec to handle MessagePack extensions | ||
export type ExtensionDecoderType = (data: Uint8Array, extensionType: number) => unknown; | ||
export type ExtensionEncoderType<T> = (input: T) => Uint8Array; | ||
export type ExtensionIdentifier = (ext: unknown) => boolean; | ||
export type ExtensionEncoderType = (input: unknown) => Uint8Array | null; | ||
export interface ExtensionCodecType { | ||
tryToEncode(object: unknown): ExtData | null; | ||
encode(object: unknown): ExtData; | ||
decode(data: Uint8Array, extType: number): unknown; | ||
@@ -19,8 +19,11 @@ } | ||
// custom extensions | ||
private readonly encoders: ExtensionEncoderType[] = []; | ||
private readonly encoders: ExtensionEncoderType<any>[] = []; | ||
private readonly decoders: ExtensionDecoderType[] = []; | ||
public register({ | ||
private readonly identifiers: ExtensionIdentifier[] = []; | ||
public register<EncodeType>({ | ||
type, | ||
identifier, | ||
encode, | ||
@@ -30,3 +33,4 @@ decode, | ||
type: number; | ||
encode: ExtensionEncoderType; | ||
identifier: ExtensionIdentifier; | ||
encode: ExtensionEncoderType<EncodeType>; | ||
decode: ExtensionDecoderType; | ||
@@ -36,15 +40,19 @@ }): void { | ||
this.decoders[type] = decode; | ||
this.identifiers.push(identifier); | ||
} | ||
public tryToEncode(object: unknown): ExtData | null { | ||
// custom extensions | ||
for (let i = 0; i < this.encoders.length; i++) { | ||
const encoder = this.encoders[i]; | ||
const data = encoder(object); | ||
if (data != null) { | ||
const type = i; | ||
return new ExtData(type, data); | ||
public encode(object: unknown): ExtData { | ||
let type = null; | ||
for (let i = 0; i < this.identifiers.length; i++) { | ||
const id = this.identifiers[i]; | ||
if (id(object)) { | ||
type = i; | ||
} | ||
} | ||
return null; | ||
if (type === null) { | ||
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`); | ||
} | ||
const encoder = this.encoders[type]; | ||
const data = encoder(object); | ||
return new ExtData(type, data); | ||
} | ||
@@ -51,0 +59,0 @@ |
@@ -22,13 +22,12 @@ // Copyright (c) 2018, Arista Networks, Inc. | ||
import { Pointer } from './NeatTypes'; | ||
import { Pointer, Wildcard } from './NeatTypes'; | ||
type PointerEncoder = (data: unknown) => Uint8Array | null; | ||
type PointerEncoder = (data: Pointer) => Uint8Array; | ||
type PointerDecoder = (buffer: Uint8Array) => Pointer; | ||
type WildcardEncoder = () => Uint8Array; | ||
type WildcardDecoder = () => Wildcard; | ||
export function encodePointer(codec: ExtensionCodec): PointerEncoder { | ||
return (data: unknown): Uint8Array | null => { | ||
if (data instanceof Pointer) { | ||
return encode(data.value, { extensionCodec: codec }); | ||
} | ||
return null; | ||
return (data: Pointer): Uint8Array => { | ||
return encode(data.value, { extensionCodec: codec }); | ||
}; | ||
@@ -46,1 +45,13 @@ } | ||
} | ||
export function encodeWildcard(): WildcardEncoder { | ||
return (): Uint8Array => { | ||
return new Uint8Array(); | ||
}; | ||
} | ||
export function decodeWildcard(): WildcardDecoder { | ||
return (): Wildcard => { | ||
return new Wildcard(); | ||
}; | ||
} |
@@ -20,6 +20,7 @@ // Copyright (c) 2018, Arista Networks, Inc. | ||
import { Bool, Float32, Float64, Int, Nil, Pointer, Str } from './NeatTypes'; | ||
import { decodePointer, encodePointer } from './extensions'; | ||
import { Bool, Float32, Float64, Int, Nil, Pointer, Str, Wildcard } from './NeatTypes'; | ||
import { decodePointer, decodeWildcard, encodePointer, encodeWildcard } from './extensions'; | ||
export const POINTER_TYPE = 0; | ||
export const WILDCARD_TYPE = 1; | ||
@@ -34,2 +35,3 @@ export const NeatTypes = { | ||
Str, | ||
Wildcard, | ||
}; | ||
@@ -41,4 +43,12 @@ | ||
type: POINTER_TYPE, | ||
identifier: (data: unknown) => data instanceof Pointer, | ||
encode: encodePointer(Codec), | ||
decode: decodePointer(Codec), | ||
}); | ||
Codec.register({ | ||
type: WILDCARD_TYPE, | ||
identifier: (data: unknown) => data instanceof Wildcard, | ||
encode: encodeWildcard(), | ||
decode: decodeWildcard(), | ||
}); |
@@ -237,1 +237,22 @@ // Copyright (c) 2018, Arista Networks, Inc. | ||
} | ||
export class Wildcard { | ||
public static type: '*' = '*'; | ||
public value: null; | ||
public type: '*'; | ||
/** | ||
* A class to represent a Wildcard type. | ||
* A Wildcard is a type that matches 1 or more path elements | ||
*/ | ||
public constructor() { | ||
this.type = Wildcard.type; | ||
this.value = null; | ||
} | ||
public toString(): string { | ||
return '*'; | ||
} | ||
} |
@@ -23,3 +23,3 @@ /* eslint-disable @typescript-eslint/naming-convention */ | ||
export function isNeatType(value: unknown): boolean { | ||
export function isBaseNeatType(value: unknown): boolean { | ||
if (typeof value === 'object' && value !== null) { | ||
@@ -32,2 +32,11 @@ if (Object.keys(value).length === 2 && 'type' in value && 'value' in value) { | ||
} | ||
} | ||
return false; | ||
} | ||
export function isNeatType(value: unknown): boolean { | ||
if (typeof value === 'object' && value !== null) { | ||
if (isBaseNeatType(value)) { | ||
return true; | ||
} | ||
if ( | ||
@@ -34,0 +43,0 @@ Object.keys(value).length === 3 && |
@@ -10,1 +10,12 @@ import JSBI from 'jsbi'; | ||
} | ||
export function isPlainObject(object: {}): boolean { | ||
if (Object.getPrototypeOf(object) === null) { | ||
return true; | ||
} | ||
let proto = object; | ||
while (Object.getPrototypeOf(proto) !== null) { | ||
proto = Object.getPrototypeOf(proto); | ||
} | ||
return Object.getPrototypeOf(object) === proto; | ||
} |
import { ExtData } from './ExtData'; | ||
export declare type ExtensionDecoderType = (data: Uint8Array, extensionType: number) => unknown; | ||
export declare type ExtensionEncoderType = (input: unknown) => Uint8Array | null; | ||
export declare type ExtensionEncoderType<T> = (input: T) => Uint8Array; | ||
export declare type ExtensionIdentifier = (ext: unknown) => boolean; | ||
export interface ExtensionCodecType { | ||
tryToEncode(object: unknown): ExtData | null; | ||
encode(object: unknown): ExtData; | ||
decode(data: Uint8Array, extType: number): unknown; | ||
@@ -12,9 +13,11 @@ } | ||
private readonly decoders; | ||
register({ type, encode, decode, }: { | ||
private readonly identifiers; | ||
register<EncodeType>({ type, identifier, encode, decode, }: { | ||
type: number; | ||
encode: ExtensionEncoderType; | ||
identifier: ExtensionIdentifier; | ||
encode: ExtensionEncoderType<EncodeType>; | ||
decode: ExtensionDecoderType; | ||
}): void; | ||
tryToEncode(object: unknown): ExtData | null; | ||
encode(object: unknown): ExtData; | ||
decode(data: Uint8Array, type: number): unknown; | ||
} |
import { ExtensionCodec } from '../ExtensionCodec'; | ||
import { Pointer } from './NeatTypes'; | ||
declare type PointerEncoder = (data: unknown) => Uint8Array | null; | ||
import { Pointer, Wildcard } from './NeatTypes'; | ||
declare type PointerEncoder = (data: Pointer) => Uint8Array; | ||
declare type PointerDecoder = (buffer: Uint8Array) => Pointer; | ||
declare type WildcardEncoder = () => Uint8Array; | ||
declare type WildcardDecoder = () => Wildcard; | ||
export declare function encodePointer(codec: ExtensionCodec): PointerEncoder; | ||
export declare function decodePointer(codec: ExtensionCodec): PointerDecoder; | ||
export declare function encodeWildcard(): WildcardEncoder; | ||
export declare function decodeWildcard(): WildcardDecoder; | ||
export {}; |
import { ExtensionCodec } from '../ExtensionCodec'; | ||
import { Bool, Float32, Float64, Int, Nil, Pointer, Str } from './NeatTypes'; | ||
import { Bool, Float32, Float64, Int, Nil, Pointer, Str, Wildcard } from './NeatTypes'; | ||
export declare const POINTER_TYPE = 0; | ||
export declare const WILDCARD_TYPE = 1; | ||
export declare const NeatTypes: { | ||
@@ -12,3 +13,4 @@ Bool: typeof Bool; | ||
Str: typeof Str; | ||
Wildcard: typeof Wildcard; | ||
}; | ||
export declare const Codec: ExtensionCodec; |
@@ -75,1 +75,12 @@ import JSBI from 'jsbi'; | ||
} | ||
export declare class Wildcard { | ||
static type: '*'; | ||
value: null; | ||
type: '*'; | ||
/** | ||
* A class to represent a Wildcard type. | ||
* A Wildcard is a type that matches 1 or more path elements | ||
*/ | ||
constructor(); | ||
toString(): string; | ||
} |
@@ -16,2 +16,3 @@ import { PathElements } from '../../types/neat'; | ||
} | ||
export declare function isBaseNeatType(value: unknown): boolean; | ||
export declare function isNeatType(value: unknown): boolean; | ||
@@ -18,0 +19,0 @@ export declare function sortMapByKey(a: [Uint8Array, unknown], b: [Uint8Array, unknown]): number; |
@@ -6,1 +6,2 @@ import JSBI from 'jsbi'; | ||
export declare function isJsbi(value: unknown): value is JSBI; | ||
export declare function isPlainObject(object: {}): boolean; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
267948
7106