Comparing version 1.3.0 to 1.3.1
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("k8w-extend-native");var LengthType,tsbufferValidator=require("tsbuffer-validator"),Config={interface:{maxExtendsNum:9}},Varint64=function(){function s(e,t,r){this.uint32s=new Uint32Array([e,t]),void 0!==r&&(this._byteLength=r)}return s.from=function(e){if(0===e)return this.Zero;var t=e<0;t&&(e=-e);var r=e>>>0,i=(e-r)/4294967296>>>0;return t&&(i=~i>>>0,r=~r>>>0,4294967295<++r&&(r=0,4294967295<++i&&(i=0))),new s(i,r)},s.prototype.toNumber=function(e){if(!e&&this.uint32s[0]>>>31){var t=1+~this.uint32s[1]>>>0,r=~this.uint32s[0]>>>0;return t||(r=r+1>>>0),-(t+4294967296*r)}return this.uint32s[1]+4294967296*this.uint32s[0]},s.prototype.zzEncode=function(){var e=this.uint32s[0]>>31;return this.uint32s[0]=((this.uint32s[0]<<1|this.uint32s[1]>>>31)^e)>>>0,this.uint32s[1]=(this.uint32s[1]<<1^e)>>>0,this},s.prototype.zzDecode=function(){var e=-(1&this.uint32s[1]);return this.uint32s[1]=((this.uint32s[1]>>>1|this.uint32s[0]<<31)^e)>>>0,this.uint32s[0]=(this.uint32s[0]>>>1^e)>>>0,this},Object.defineProperty(s.prototype,"byteLength",{get:function(){if(void 0===this._byteLength){var e=this.uint32s[1],t=(this.uint32s[1]>>>28|this.uint32s[0]<<4)>>>0,r=this.uint32s[0]>>>24;this._byteLength=0==r?0==t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10}return this._byteLength},enumerable:!0,configurable:!0}),s.prototype.writeToBuffer=function(e,t){for(;this.uint32s[0];)e[t++]=127&this.uint32s[1]|128,this.uint32s[1]=(this.uint32s[1]>>>7|this.uint32s[0]<<25)>>>0,this.uint32s[0]>>>=7;for(;127<this.uint32s[1];)e[t++]=127&this.uint32s[1]|128,this.uint32s[1]=this.uint32s[1]>>>7;return e[t++]=this.uint32s[1],t},s.readFromBuffer=function(e,t){var r=t,i=0,n=0,a=0;if(!(4<e.byteLength-t)){for(;a<3;++a){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(n=(n|(127&e[t])<<7*a)>>>0,e[t++]<128)return new s(i,n,t-r)}return new s(i,n=(n|(127&e[t++])<<7*a)>>>0,t-r)}for(;a<4;++a)if(n=(n|(127&e[t])<<7*a)>>>0,e[t++]<128)return new s(i,n,t-r);if(n=(n|(127&e[t])<<28)>>>0,i=(i|(127&e[t])>>4)>>>0,e[t++]<128)return new s(i,n,t-r);if(a=0,4<e.byteLength-t){for(;a<5;++a)if(i=(i|(127&e[t])<<7*a+3)>>>0,e[t++]<128)return new s(i,n,t-r)}else for(;a<5;++a){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(i=(i|(127&e[t])<<7*a+3)>>>0,e[t++]<128)return new s(i,n,t-r)}throw Error("invalid varint encoding")},s.Zero=new s(0,0),s}(),TypedArrays={Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array},IdBlockUtil=function(){function e(){}return e.getPayloadLengthInfo=function(e){switch(e.type){case"Boolean":case"Enum":return{lengthType:LengthType.Varint};case"Number":return!e.scalarType||e.scalarType.includes("64")||"double"===e.scalarType?{lengthType:LengthType.Bit64}:e.scalarType&&e.scalarType.startsWith("big")?{lengthType:LengthType.LengthDelimited}:{lengthType:LengthType.Varint};case"Buffer":case"String":case"Any":case"NonPrimitive":return{lengthType:LengthType.LengthDelimited};case"Interface":case"Pick":case"Partial":case"Omit":case"Union":case"Intersection":return{lengthType:LengthType.IdBlock};case"Array":case"Overwrite":case"Tuple":return{lengthType:LengthType.LengthDelimited,needLengthPrefix:!0};case"Literal":return{lengthType:LengthType.LengthDelimited,needLengthPrefix:!1};default:throw new Error("Unrecognized schema type: "+e.type)}},e}();!function(e){e[e.LengthDelimited=0]="LengthDelimited",e[e.Varint=1]="Varint",e[e.Bit64=2]="Bit64",e[e.IdBlock=3]="IdBlock"}(LengthType=LengthType||{});var __assign=function(){return(__assign=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},BufferWriter=function(){function e(e){this._ops=[],this._utf8=e}return Object.defineProperty(e.prototype,"ops",{get:function(){return this._ops},enumerable:!0,configurable:!0}),e.prototype.clear=function(){this._ops=[]},e.prototype.push=function(e){return this._ops.push(this.req2op(e)),this},e.prototype.req2op=function(e){if("string"===e.type||"buffer"===e.type){var t=this.measureLength(e);return this.push({type:"varint",value:Varint64.from(t)}),__assign(__assign({},e),{length:t})}var r=this.measureLength(e);return __assign(__assign({},e),{length:r})},e.prototype.measureLength=function(e){switch(e.type){case"varint":return e.value.byteLength;case"string":return this._utf8.measureLength(e.value);case"buffer":return e.value.byteLength;case"double":return 8;case"boolean":return 1;default:return NaN}},e.prototype.finish=function(){for(var e=this._ops.sum(function(e){return e.length}),t=0,r=new Uint8Array(e),i=new DataView(r.buffer),n=0,a=this._ops;n<a.length;n++){var s=a[n];switch(s.type){case"varint":var o=s.value.writeToBuffer(r,t);if(o!==t+s.length)throw new Error("Error varint measuredLength "+s.length+", actual is "+(o-t)+", value is "+s.value.toNumber());break;case"double":i.setFloat64(r.byteOffset+t,s.value);break;case"string":var h=this._utf8.write(s.value,r,t);if(h!==s.length)throw new Error("Expect "+s.length+" bytes but encoded "+h+" bytes");break;case"buffer":r.subarray(t,t+s.length).set(s.value);break;case"boolean":i.setUint8(r.byteOffset+t,s.value?255:0)}t+=s.length}return r},e}(),Encoder=function(){function e(e,t){this._writer=new BufferWriter(t),this._validator=e}return e.prototype.encode=function(e,t){return this._writer.clear(),this._write(e,t),this._writer.finish()},e.prototype._write=function(t,e,r){switch(e.type){case"Boolean":this._writer.push({type:"boolean",value:t});break;case"Number":this._writeNumber(t,e);break;case"String":this._writer.push({type:"string",value:t});break;case"Array":var i=t;this._writer.push({type:"varint",value:Varint64.from(i.length)});for(var n=0;n<i.length;++n)this._write(i[n],e.elementType);break;case"Tuple":if(64<e.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+e.elementTypes.length);i=t;var a=[];for(n=0;n<i.length;++n)void 0!==i[n]&&a.push(n);for(var s=0,o=0,h=0,p=a;h<p.length;h++){var u=p[h];u<32?s|=1<<u:o|=1<<u-32}this._writer.push({type:"varint",value:new Varint64(o,s)});for(var f=0,c=a;f<c.length;f++){n=c[f];this._write(i[n],e.elementTypes[n])}break;case"Enum":var l=e.members.find(function(e){return e.value===t});if(!l)throw new Error("Unexpect enum value: "+t);this._writer.push({type:"varint",value:Varint64.from(l.id)});break;case"Any":void 0===t?this._writer.push({type:"string",value:"undefined"}):this._writer.push({type:"string",value:JSON.stringify(t)});break;case"NonPrimitive":this._writer.push({type:"string",value:JSON.stringify(t)});break;case"Literal":break;case"Interface":this._writeInterface(t,e,r);break;case"Buffer":this._writeBuffer(t,e);break;case"IndexedAccess":case"Reference":this._write(t,this._validator.protoHelper.parseReference(e),r);break;case"Pick":case"Partial":case"Omit":this._writeInterface(t,e.target,r);break;case"Overwrite":this._writeOverwrite(t,e,r);break;case"Union":this._writeUnion(t,e,r);break;case"Intersection":this._writeIntersection(t,e,r);break;default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._writeNumber=function(e,t){var r=t.scalarType||"double";switch(r){case"double":this._writer.push({type:r,value:e});break;case"int":this._writer.push({type:"varint",value:Varint64.from(e).zzEncode()});break;case"uint":this._writer.push({type:"varint",value:Varint64.from(e)});break;default:throw new Error("Scalar type not support : "+r)}},e.prototype._writeInterface=function(e,t,r,i){void 0===r&&(r={});var n=this._writer.ops.length,a=0,s=this._validator.protoHelper.parseReference(t);switch(s.type){case"Overwrite":return void this._writeOverwrite(e,s,r);case"Pick":case"Omit":case"Partial":return void this._writeInterface(e,s.target,r)}if(s.extends){if(s.extends.length>Config.interface.maxExtendsNum)throw new Error("Max support "+Config.interface.maxExtendsNum+" extends, actual: "+s.extends.length);for(var o=0,h=s.extends;o<h.length;o++){var p=h[o],u=p.id+1;this._writer.push({type:"varint",value:Varint64.from(u)});var f=this._writer.ops.length-1,c=this._writer.ops.length;this._writeInterface(e,p.type,r,!!s.indexSignature||i),this._writer.ops.length===c+1?this._writer.ops.splice(this._writer.ops.length-2,2):(++a,this._processIdWithLengthType(f,p.type))}}if(s.properties)for(var l=0,d=s.properties;l<d.length;l++){var y=d[l],v=this._validator.protoHelper.parseReference(y.type);if("Literal"!==v.type){if(void 0!==e[y.name]&&!r[y.name]){r[y.name]=1;u=y.id+Config.interface.maxExtendsNum+1;this._writer.push({type:"varint",value:Varint64.from(u)});f=this._writer.ops.length-1;this._write(e[y.name],v),++a,this._processIdWithLengthType(f,v)}}else r[y.name]=1}if(!i){var _=this._validator.protoHelper.getFlatInterfaceSchema(s);if(_.indexSignature)for(var g in e)if(void 0!==e[g]&&!r[g]){r[g]=1,this._writer.push({type:"varint",value:Varint64.from(0)});f=this._writer.ops.length-1;this._writer.push({type:"string",value:g});var w=this._writer.ops.length;this._write(e[g],_.indexSignature.type),++a,this._processIdWithLengthType(f,_.indexSignature.type,w)}}this._writer.ops.splice(n,0,this._writer.req2op({type:"varint",value:Varint64.from(a)}))},e.prototype._writeOverwrite=function(e,t,r){void 0===r&&(r={});var i,n,a=this._validator.protoHelper.parseReference(t.target),s=this._validator.protoHelper.parseReference(t.overwrite),o=this._validator.protoHelper.getFlatInterfaceSchema(a),h=this._validator.protoHelper.getFlatInterfaceSchema(s),p={},u={};if(h.properties)for(var f=0,c=h.properties;f<c.length;f++){void 0===e[(y=c[f]).name]||r[y.name]||(p[y.name]=e[y.name],r[y.name]=1)}if(o.properties)for(var l=0,d=o.properties;l<d.length;l++){var y;void 0===e[(y=d[l]).name]||r[y.name]||(u[y.name]=e[y.name],r[y.name]=1)}if(h.indexSignature?(n=h.indexSignature,i=p):o.indexSignature&&(n=o.indexSignature,i=u),n)for(var v in e)r[v]||(i[v]=e[v],r[v]=1);this._writeInterface(p,s),this._writeInterface(u,a)},e.prototype._writeUnion=function(e,t,r,i){void 0===r&&(r={}),i=i||(r?Object.keys(r):[]),this._validator.protoHelper.extendsUnionFields(i,t.members.map(function(e){return e.type}));for(var n=this._writer.ops.length,a=0,s=0,o=t.members;s<o.length;s++){var h=o[s];if((this._validator.protoHelper.isInterface(h.type)?this._validator.validateInterfaceReference(e,h.type,i):"Union"===h.type.type?this._validator.validateUnionType(e,h.type,i):"Intersection"===h.type.type?this._validator.validateIntersectionType(e,h.type,i):this._validator.validateBySchema(e,h.type)).isSucc){this._writer.push({type:"varint",value:Varint64.from(h.id)});var p=this._writer.ops.length-1;if("Union"===h.type.type?this._writeUnion(e,h.type,r,i):this._write(e,h.type,r),a++,this._processIdWithLengthType(p,h.type),"object"!=typeof e)break}}if(!(0<a))throw new Error("Non member is satisfied for union type");this._writer.ops.splice(n,0,this._writer.req2op({type:"varint",value:Varint64.from(a)}))},e.prototype._writeIntersection=function(e,t,r){void 0===r&&(r={}),this._writer.push({type:"varint",value:Varint64.from(t.members.length)});for(var i=0,n=t.members;i<n.length;i++){var a=n[i];this._writer.push({type:"varint",value:Varint64.from(a.id)});var s=this._writer.ops.length-1;this._write(e,a.type,r),this._processIdWithLengthType(s,a.type)}},e.prototype._writeBuffer=function(e,t){if(e instanceof ArrayBuffer)this._writer.push({type:"buffer",value:new Uint8Array(e)});else if(e instanceof Uint8Array)this._writer.push({type:"buffer",value:e});else{var r=e.constructor.name,i=TypedArrays[r],n=new Uint8Array(e.buffer,e.byteOffset,e.length*i.BYTES_PER_ELEMENT);this._writer.push({type:"buffer",value:n})}},e.prototype._processIdWithLengthType=function(r,e,t){var i=this._writer.ops[r];if("varint"!==i.type)throw new Error("Error idPos: "+r);var n=this._validator.protoHelper.parseReference(e),a=IdBlockUtil.getPayloadLengthInfo(n),s=(i.value.toNumber()<<2)+a.lengthType;if(this._writer.ops[r]=this._writer.req2op({type:"varint",value:Varint64.from(s)}),a.needLengthPrefix){var o=this._writer.ops.filter(function(e,t){return r<t}).sum(function(e){return e.length});this._writer.ops.splice(null==t?r+1:t,0,this._writer.req2op({type:"varint",value:Varint64.from(o)}))}},e}(),BufferReader=function(){function e(e){this._pos=0,this._utf8=e}return e.prototype.load=function(e,t){void 0===t&&(t=0),this._buf=e,this._pos=t,this._view=new DataView(e.buffer)},e.prototype.readVarint=function(){var e=Varint64.readFromBuffer(this._buf,this._pos);return this._pos+=e.byteLength,e},e.prototype.readUint=function(){return this.readVarint().toNumber(!0)},e.prototype.readInt=function(){return this.readVarint().zzDecode().toNumber()},e.prototype.readDouble=function(){var e=this._pos;return this._pos+=8,this._view.getFloat64(this._buf.byteOffset+e)},e.prototype.readString=function(){var e=this.readUint(),t=this._utf8.read(this._buf,this._pos,e);return this._pos+=e,t},e.prototype.readBuffer=function(){var e=this.readUint(),t=this._buf.subarray(this._pos,this._pos+e);return this._pos+=e,t},e.prototype.skip=function(e){this._pos+=e},e.prototype.skipByLengthType=function(e){if(e===LengthType.Bit64)this._pos+=8;else if(e===LengthType.Varint)this.readVarint();else if(e===LengthType.LengthDelimited){var t=this.readUint();this._pos+=t}else{if(e!==LengthType.IdBlock)throw new Error("Unknown lengthType: "+e);this.skipIdBlock()}},e.prototype.skipIdBlock=function(){for(var e=this.readUint(),t=0;t<e;++t){var r=3&this.readUint();this.skipByLengthType(r)}},e.prototype.readBoolean=function(){var e=this._view.getUint8(this._buf.byteOffset+this._pos++);if(255===e)return!0;if(0===e)return!1;throw new Error("Invalid boolean encoding ["+e+"] at pos "+(this._pos-1))},Object.defineProperty(e.prototype,"unreadByteLength",{get:function(){return this._buf.byteLength-this._pos},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){this._buf=this._view=void 0},e}(),Decoder=function(){function e(e,t){this._reader=new BufferReader(t),this._validator=e}return e.prototype.decode=function(e,t){return this._reader.load(e),this._read(t)},e.prototype._read=function(e){switch(e.type){case"Boolean":return this._reader.readBoolean();case"Number":return this._readNumber(e);case"String":return this._reader.readString();case"Array":for(var t=[],r=this._reader.readUint(),i=0;i<r;++i){var n=this._read(e.elementType);t.push(n)}return t;case"Tuple":if(64<e.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+e.elementTypes.length);t=[];var a=this._reader.readVarint(),s=[];for(i=0;i<32;++i)a.uint32s[1]&1<<i&&s.push(i);for(i=0;i<32;++i)a.uint32s[0]&1<<i&&s.push(i+32);if(!s.length)return[];for(var o=s.last(),h=(i=0,0),p=s[0];i<=o;++i)i===p?(t[i]=this._read(e.elementTypes[i]),p=s[++h]):t[i]=void 0;return t;case"Enum":var u=this._reader.readVarint().toNumber(),f=e.members.find(function(e){return e.id===u});if(!f)throw new Error("Invalid enum encoding: unexpected id "+u);return f.value;case"Any":case"NonPrimitive":var c=this._reader.readString();if("undefined"===c)return;return JSON.parse(c);case"Literal":return e.literal;case"Interface":return this._readInterface(e);case"Buffer":var l=this._reader.readBuffer();if(e.arrayType){if("BigInt64Array"===e.arrayType||"BigUint64Array"===e.arrayType)throw new Error("Unsupported arrayType: "+e.arrayType);if("Uint8Array"===e.arrayType)return l;var d=TypedArrays[e.arrayType];return l.byteOffset%d.BYTES_PER_ELEMENT==0?new d(l.buffer,l.byteOffset,l.byteLength/d.BYTES_PER_ELEMENT):new d(l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength))}return l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength);case"IndexedAccess":case"Reference":return this._read(this._validator.protoHelper.parseReference(e));case"Pick":case"Partial":case"Omit":return this._read(e.target);case"Overwrite":return this._readOverwrite(e);case"Union":case"Intersection":return this._readUnionOrIntersection(e);default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._readNumber=function(e){var t=e.scalarType||"double";switch(t){case"double":return this._reader.readDouble();case"int":return this._reader.readInt();case"uint":return this._reader.readUint();default:throw new Error("Scalar type not support : "+t)}},e.prototype._readInterface=function(f){for(var c={},l=this._validator.protoHelper.getFlatInterfaceSchema(f),e=this._reader.readUint(),t=function(e){var t=d._reader.readUint(),r=3&t,i=t>>2;if(0==i)if(l.indexSignature){var n=l.indexSignature.type,a=d._reader.readString();d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(n)),c[a]=d._read(n)}else d._reader.skipByLengthType(LengthType.LengthDelimited),d._reader.skipByLengthType(r);else if(i<=9){var s=i-1,o=f.extends&&f.extends.find(function(e){return e.id===s});if(o){d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(o.type));var h=d._read(o.type);Object.assign(c,h)}else d._reader.skipByLengthType(r)}else{var p=i-10,u=f.properties&&f.properties.find(function(e){return e.id===p});u?(d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(u.type)),c[u.name]=d._read(u.type)):d._reader.skipByLengthType(r)}},d=this,r=0;r<e;++r)t();for(var i=0,n=l.properties;i<n.length;i++){var a=n[i];if(!c.hasOwnProperty(a.name)){var s=this._validator.protoHelper.parseReference(a.type);"Literal"===s.type&&(c[a.name]=s.literal)}}return c},e.prototype._skipIdLengthPrefix=function(e){IdBlockUtil.getPayloadLengthInfo(e).needLengthPrefix&&this._reader.skipByLengthType(LengthType.Varint)},e.prototype._readOverwrite=function(e){var t=this._read(e.overwrite),r=this._read(e.target);return Object.assign({},r,t)},e.prototype._readUnionOrIntersection=function(s){for(var o,e=this._reader.readUint(),t=function(e){var t=h._reader.readUint(),r=3&t,i=t>>2,n=s.members.find(function(e){return e.id===i});if(!n)return h._reader.skipByLengthType(r),"continue";h._skipIdLengthPrefix(h._validator.protoHelper.parseReference(n.type));var a=h._read(n.type);h._isObject(o)&&h._isObject(a)?Object.assign(o,a):o=a},h=this,r=0;r<e;++r)t();return o},e.prototype._isObject=function(e){return"object"==typeof e&&null!==e},e}(),Utf8Util=function(){function e(){}return e.measureLength=function(e){for(var t=0,r=0,i=0;i<e.length;++i)(r=e.charCodeAt(i))<128?t+=1:r<2048?t+=2:55296==(64512&r)&&56320==(64512&e.charCodeAt(i+1))?(++i,t+=4):t+=3;return t},e.write=function(e,t,r){for(var i,n,a=r,s=0;s<e.length;++s)(i=e.charCodeAt(s))<128?t[r++]=i:(i<2048?t[r++]=i>>6|192:(55296==(64512&i)&&56320==(64512&(n=e.charCodeAt(s+1)))?(i=65536+((1023&i)<<10)+(1023&n),++s,t[r++]=i>>18|240,t[r++]=i>>12&63|128):t[r++]=i>>12|224,t[r++]=i>>6&63|128),t[r++]=63&i|128);return r-a},e.read=function(e,t,r){if(r<1)return"";for(var i,n=void 0,a=[],s=0,o=t+r;t<o;)(i=e[t++])<128?a[s++]=i:191<i&&i<224?a[s++]=(31&i)<<6|63&e[t++]:239<i&&i<365?(i=((7&i)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,a[s++]=55296+(i>>10),a[s++]=56320+(1023&i)):a[s++]=(15&i)<<12|(63&e[t++])<<6|63&e[t++],8191<s&&((n=n||[]).push(String.fromCharCode.apply(String,a)),s=0);return n?(s&&n.push(String.fromCharCode.apply(String,a.slice(0,s))),n.join("")):String.fromCharCode.apply(String,a.slice(0,s))},e}(),TSBuffer=function(){function e(e,t){this.options={strictExcessCheck:!1,utf8:Utf8Util},Object.assign(this.options,t),this._proto=e,this._validator=new tsbufferValidator.TSBufferValidator(e,{skipExcessCheck:!this.options.strictExcessCheck}),this._encoder=new Encoder(this._validator,this.options.utf8),this._decoder=new Decoder(this._validator,this.options.utf8)}return e.prototype.encode=function(e,t,r){var i;if("string"==typeof t){if(!(i=this._proto[t]))throw new Error("Cannot find schema: "+t)}else i=t;if(!r||!r.skipValidate){var n=this._validator.validateBySchema(e,i);if(!n.isSucc)throw new Error(n.originalError.message)}return this._encoder.encode(e,i)},e.prototype.decode=function(e,t,r){var i,n;if("string"==typeof t){if(!(i=this._proto[t]))throw new Error("Cannot find schema: "+t)}else i=t;try{n=this._decoder.decode(e,i)}catch(e){var a=new Error("Invalid buffer encoding");throw a.encodingError=e,a}if(!r||!r.skipValidate){var s=this._validator.validateBySchema(n,i);if(!s.isSucc)throw new Error(s.originalError.message)}return n},e.prototype.validate=function(e,t){var r;if("string"==typeof t){if(!(r=this._proto[t]))throw new Error("Cannot find schema: "+t)}else r=t;return this._validator.validateBySchema(e,r)},e}();exports.TSBuffer=TSBuffer; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("k8w-extend-native");var LengthType,tsbufferValidator=require("tsbuffer-validator"),Config={interface:{maxExtendsNum:9}},Varint64=function(){function s(e,t,r){this.uint32s=new Uint32Array([e,t]),void 0!==r&&(this._byteLength=r)}return s.from=function(e){if(0===e)return this.Zero;var t=e<0;t&&(e=-e);var r=e>>>0,i=(e-r)/4294967296>>>0;return t&&(i=~i>>>0,r=~r>>>0,4294967295<++r&&(r=0,4294967295<++i&&(i=0))),new s(i,r)},s.prototype.toNumber=function(e){if(!e&&this.uint32s[0]>>>31){var t=1+~this.uint32s[1]>>>0,r=~this.uint32s[0]>>>0;return t||(r=r+1>>>0),-(t+4294967296*r)}return this.uint32s[1]+4294967296*this.uint32s[0]},s.prototype.zzEncode=function(){var e=this.uint32s[0]>>31;return this.uint32s[0]=((this.uint32s[0]<<1|this.uint32s[1]>>>31)^e)>>>0,this.uint32s[1]=(this.uint32s[1]<<1^e)>>>0,this},s.prototype.zzDecode=function(){var e=-(1&this.uint32s[1]);return this.uint32s[1]=((this.uint32s[1]>>>1|this.uint32s[0]<<31)^e)>>>0,this.uint32s[0]=(this.uint32s[0]>>>1^e)>>>0,this},Object.defineProperty(s.prototype,"byteLength",{get:function(){var e,t,r;return void 0===this._byteLength&&(e=this.uint32s[1],t=(this.uint32s[1]>>>28|this.uint32s[0]<<4)>>>0,r=this.uint32s[0]>>>24,this._byteLength=0==r?0==t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10),this._byteLength},enumerable:!0,configurable:!0}),s.prototype.writeToBuffer=function(e,t){for(;this.uint32s[0];)e[t++]=127&this.uint32s[1]|128,this.uint32s[1]=(this.uint32s[1]>>>7|this.uint32s[0]<<25)>>>0,this.uint32s[0]>>>=7;for(;127<this.uint32s[1];)e[t++]=127&this.uint32s[1]|128,this.uint32s[1]=this.uint32s[1]>>>7;return e[t++]=this.uint32s[1],t},s.readFromBuffer=function(e,t){var r=t,i=0,n=0,a=0;if(!(4<e.byteLength-t)){for(;a<3;++a){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(n=(n|(127&e[t])<<7*a)>>>0,e[t++]<128)return new s(i,n,t-r)}return new s(i,n=(n|(127&e[t++])<<7*a)>>>0,t-r)}for(;a<4;++a)if(n=(n|(127&e[t])<<7*a)>>>0,e[t++]<128)return new s(i,n,t-r);if(n=(n|(127&e[t])<<28)>>>0,i=(i|(127&e[t])>>4)>>>0,e[t++]<128)return new s(i,n,t-r);if(a=0,4<e.byteLength-t){for(;a<5;++a)if(i=(i|(127&e[t])<<7*a+3)>>>0,e[t++]<128)return new s(i,n,t-r)}else for(;a<5;++a){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(i=(i|(127&e[t])<<7*a+3)>>>0,e[t++]<128)return new s(i,n,t-r)}throw Error("invalid varint encoding")},s.Zero=new s(0,0),s}(),TypedArrays={Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array},IdBlockUtil=function(){function e(){}return e.getPayloadLengthInfo=function(e){switch(e.type){case"Boolean":case"Enum":return{lengthType:LengthType.Varint};case"Number":return!e.scalarType||e.scalarType.includes("64")||"double"===e.scalarType?{lengthType:LengthType.Bit64}:e.scalarType&&e.scalarType.startsWith("big")?{lengthType:LengthType.LengthDelimited}:{lengthType:LengthType.Varint};case"Buffer":case"String":case"Any":case"NonPrimitive":return{lengthType:LengthType.LengthDelimited};case"Interface":case"Pick":case"Partial":case"Omit":case"Union":case"Intersection":return{lengthType:LengthType.IdBlock};case"Array":case"Overwrite":case"Tuple":return{lengthType:LengthType.LengthDelimited,needLengthPrefix:!0};case"Literal":return{lengthType:LengthType.LengthDelimited,needLengthPrefix:!1};default:throw new Error("Unrecognized schema type: "+e.type)}},e}();!function(e){e[e.LengthDelimited=0]="LengthDelimited",e[e.Varint=1]="Varint",e[e.Bit64=2]="Bit64",e[e.IdBlock=3]="IdBlock"}(LengthType=LengthType||{});var __assign=function(){return(__assign=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},BufferWriter=function(){function e(e){this._ops=[],this._utf8=e}return Object.defineProperty(e.prototype,"ops",{get:function(){return this._ops},enumerable:!0,configurable:!0}),e.prototype.clear=function(){this._ops=[]},e.prototype.push=function(e){return this._ops.push(this.req2op(e)),this},e.prototype.req2op=function(e){if("string"===e.type||"buffer"===e.type){var t=this.measureLength(e);return this.push({type:"varint",value:Varint64.from(t)}),__assign(__assign({},e),{length:t})}var r=this.measureLength(e);return __assign(__assign({},e),{length:r})},e.prototype.measureLength=function(e){switch(e.type){case"varint":return e.value.byteLength;case"string":return this._utf8.measureLength(e.value);case"buffer":return e.value.byteLength;case"double":return 8;case"boolean":return 1;default:return NaN}},e.prototype.finish=function(){for(var e=this._ops.sum(function(e){return e.length}),t=0,r=new Uint8Array(e),i=new DataView(r.buffer),n=0,a=this._ops;n<a.length;n++){var s=a[n];switch(s.type){case"varint":var o=s.value.writeToBuffer(r,t);if(o!==t+s.length)throw new Error("Error varint measuredLength "+s.length+", actual is "+(o-t)+", value is "+s.value.toNumber());break;case"double":i.setFloat64(r.byteOffset+t,s.value);break;case"string":var h=this._utf8.write(s.value,r,t);if(h!==s.length)throw new Error("Expect "+s.length+" bytes but encoded "+h+" bytes");break;case"buffer":r.subarray(t,t+s.length).set(s.value);break;case"boolean":i.setUint8(r.byteOffset+t,s.value?255:0)}t+=s.length}return r},e}(),Encoder=function(){function e(e,t){this._writer=new BufferWriter(t),this._validator=e}return e.prototype.encode=function(e,t){return this._writer.clear(),this._write(e,t),this._writer.finish()},e.prototype._write=function(t,e,r){switch(e.type){case"Boolean":this._writer.push({type:"boolean",value:t});break;case"Number":this._writeNumber(t,e);break;case"String":this._writer.push({type:"string",value:t});break;case"Array":var i=t;this._writer.push({type:"varint",value:Varint64.from(i.length)});for(var n=0;n<i.length;++n)this._write(i[n],e.elementType);break;case"Tuple":if(64<e.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+e.elementTypes.length);for(var i=t,a=[],n=0;n<i.length;++n)void 0!==i[n]&&a.push(n);for(var s=0,o=0,h=0,p=a;h<p.length;h++){var u=p[h];u<32?s|=1<<u:o|=1<<u-32}this._writer.push({type:"varint",value:new Varint64(o,s)});for(var f=0,c=a;f<c.length;f++){n=c[f];this._write(i[n],e.elementTypes[n])}break;case"Enum":var d=e.members.find(function(e){return e.value===t});if(!d)throw new Error("Unexpect enum value: "+t);this._writer.push({type:"varint",value:Varint64.from(d.id)});break;case"Any":void 0===t?this._writer.push({type:"string",value:"undefined"}):this._writer.push({type:"string",value:JSON.stringify(t)});break;case"NonPrimitive":this._writer.push({type:"string",value:JSON.stringify(t)});break;case"Literal":break;case"Interface":this._writeInterface(t,e,r);break;case"Buffer":this._writeBuffer(t,e);break;case"IndexedAccess":case"Reference":this._write(t,this._validator.protoHelper.parseReference(e),r);break;case"Pick":case"Partial":case"Omit":this._writeInterface(t,e.target,r);break;case"Overwrite":this._writeOverwrite(t,e,r);break;case"Union":this._writeUnion(t,e,r);break;case"Intersection":this._writeIntersection(t,e,r);break;default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._writeNumber=function(e,t){var r=t.scalarType||"double";switch(r){case"double":this._writer.push({type:r,value:e});break;case"int":this._writer.push({type:"varint",value:Varint64.from(e).zzEncode()});break;case"uint":this._writer.push({type:"varint",value:Varint64.from(e)});break;default:throw new Error("Scalar type not support : "+r)}},e.prototype._writeInterface=function(e,t,r,i){void 0===r&&(r={});var n=this._writer.ops.length,a=0,s=this._validator.protoHelper.parseReference(t);switch(s.type){case"Overwrite":return void this._writeOverwrite(e,s,r);case"Pick":case"Omit":case"Partial":return void this._writeInterface(e,s.target,r)}if(s.extends){if(s.extends.length>Config.interface.maxExtendsNum)throw new Error("Max support "+Config.interface.maxExtendsNum+" extends, actual: "+s.extends.length);for(var o=0,h=s.extends;o<h.length;o++){var p=h[o],u=p.id+1;this._writer.push({type:"varint",value:Varint64.from(u)});var f=this._writer.ops.length-1,c=this._writer.ops.length;this._writeInterface(e,p.type,r,!!s.indexSignature||i),this._writer.ops.length===c+1?this._writer.ops.splice(this._writer.ops.length-2,2):(++a,this._processIdWithLengthType(f,p.type))}}if(s.properties)for(var d=0,l=s.properties;d<l.length;d++){var y=l[d],_=this._validator.protoHelper.parseReference(y.type);"Literal"!==_.type?void 0!==e[y.name]&&(r[y.name]||(r[y.name]=1,u=y.id+Config.interface.maxExtendsNum+1,this._writer.push({type:"varint",value:Varint64.from(u)}),f=this._writer.ops.length-1,this._write(e[y.name],_),++a,this._processIdWithLengthType(f,_))):r[y.name]=1}if(!i){var v,g=this._validator.protoHelper.getFlatInterfaceSchema(s);if(g.indexSignature)for(var w in e){void 0!==e[w]&&(r[w]||(r[w]=1,this._writer.push({type:"varint",value:Varint64.from(0)}),f=this._writer.ops.length-1,this._writer.push({type:"string",value:w}),v=this._writer.ops.length,this._write(e[w],g.indexSignature.type),++a,this._processIdWithLengthType(f,g.indexSignature.type,v)))}}this._writer.ops.splice(n,0,this._writer.req2op({type:"varint",value:Varint64.from(a)}))},e.prototype._writeOverwrite=function(e,t,r){void 0===r&&(r={});var i,n,a=this._validator.protoHelper.parseReference(t.target),s=this._validator.protoHelper.parseReference(t.overwrite),o=this._validator.protoHelper.getFlatInterfaceSchema(a),h=this._validator.protoHelper.getFlatInterfaceSchema(s),p={},u={};if(h.properties)for(var f=0,c=h.properties;f<c.length;f++){void 0===e[(d=c[f]).name]||r[d.name]||(p[d.name]=e[d.name],r[d.name]=1)}if(o.properties)for(var d,l=0,y=o.properties;l<y.length;l++){void 0===e[(d=y[l]).name]||r[d.name]||(u[d.name]=e[d.name],r[d.name]=1)}if(h.indexSignature?(n=h.indexSignature,i=p):o.indexSignature&&(n=o.indexSignature,i=u),n)for(var _ in e)r[_]||(i[_]=e[_],r[_]=1);this._writeInterface(p,s),this._writeInterface(u,a)},e.prototype._writeUnion=function(e,t,r,i){void 0===r&&(r={}),i=i||(r?Object.keys(r):[]),this._validator.protoHelper.extendsUnionFields(i,t.members.map(function(e){return e.type}));for(var n=this._writer.ops.length,a=0,s=0,o=t.members;s<o.length;s++){var h=o[s];if((this._validator.protoHelper.isInterface(h.type)?this._validator.validateInterfaceReference(e,h.type,i):"Union"===h.type.type?this._validator.validateUnionType(e,h.type,i):"Intersection"===h.type.type?this._validator.validateIntersectionType(e,h.type,i):this._validator.validateBySchema(e,h.type)).isSucc){this._writer.push({type:"varint",value:Varint64.from(h.id)});var p=this._writer.ops.length-1;if("Union"===h.type.type?this._writeUnion(e,h.type,r,i):this._write(e,h.type,r),a++,this._processIdWithLengthType(p,h.type),"object"!=typeof e)break}}if(!(0<a))throw new Error("Non member is satisfied for union type");this._writer.ops.splice(n,0,this._writer.req2op({type:"varint",value:Varint64.from(a)}))},e.prototype._writeIntersection=function(e,t,r){void 0===r&&(r={}),this._writer.push({type:"varint",value:Varint64.from(t.members.length)});for(var i=0,n=t.members;i<n.length;i++){var a=n[i];this._writer.push({type:"varint",value:Varint64.from(a.id)});var s=this._writer.ops.length-1;this._write(e,a.type,r),this._processIdWithLengthType(s,a.type)}},e.prototype._writeBuffer=function(e,t){var r,i,n;e instanceof ArrayBuffer?this._writer.push({type:"buffer",value:new Uint8Array(e)}):e instanceof Uint8Array?this._writer.push({type:"buffer",value:e}):(r=e.constructor.name,i=TypedArrays[r],n=new Uint8Array(e.buffer,e.byteOffset,e.length*i.BYTES_PER_ELEMENT),this._writer.push({type:"buffer",value:n}))},e.prototype._processIdWithLengthType=function(r,e,t){var i=this._writer.ops[r];if("varint"!==i.type)throw new Error("Error idPos: "+r);var n,a=this._validator.protoHelper.parseReference(e),s=IdBlockUtil.getPayloadLengthInfo(a),o=(i.value.toNumber()<<2)+s.lengthType;this._writer.ops[r]=this._writer.req2op({type:"varint",value:Varint64.from(o)}),s.needLengthPrefix&&(n=this._writer.ops.filter(function(e,t){return r<t}).sum(function(e){return e.length}),this._writer.ops.splice(null==t?r+1:t,0,this._writer.req2op({type:"varint",value:Varint64.from(n)})))},e}(),BufferReader=function(){function e(e){this._pos=0,this._utf8=e}return e.prototype.load=function(e,t){void 0===t&&(t=0),this._buf=e,this._pos=t,this._view=new DataView(e.buffer)},e.prototype.readVarint=function(){var e=Varint64.readFromBuffer(this._buf,this._pos);return this._pos+=e.byteLength,e},e.prototype.readUint=function(){return this.readVarint().toNumber(!0)},e.prototype.readInt=function(){return this.readVarint().zzDecode().toNumber()},e.prototype.readDouble=function(){var e=this._pos;return this._pos+=8,this._view.getFloat64(this._buf.byteOffset+e)},e.prototype.readString=function(){var e=this.readUint(),t=this._utf8.read(this._buf,this._pos,e);return this._pos+=e,t},e.prototype.readBuffer=function(){var e=this.readUint(),t=this._buf.subarray(this._pos,this._pos+e);return this._pos+=e,t},e.prototype.skip=function(e){this._pos+=e},e.prototype.skipByLengthType=function(e){if(e===LengthType.Bit64)this._pos+=8;else if(e===LengthType.Varint)this.readVarint();else if(e===LengthType.LengthDelimited){var t=this.readUint();this._pos+=t}else{if(e!==LengthType.IdBlock)throw new Error("Unknown lengthType: "+e);this.skipIdBlock()}},e.prototype.skipIdBlock=function(){for(var e=this.readUint(),t=0;t<e;++t){var r=3&this.readUint();this.skipByLengthType(r)}},e.prototype.readBoolean=function(){var e=this._view.getUint8(this._buf.byteOffset+this._pos++);if(255===e)return!0;if(0===e)return!1;throw new Error("Invalid boolean encoding ["+e+"] at pos "+(this._pos-1))},Object.defineProperty(e.prototype,"unreadByteLength",{get:function(){return this._buf.byteLength-this._pos},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){this._buf=this._view=void 0},e}(),Decoder=function(){function e(e,t){this._reader=new BufferReader(t),this._validator=e}return e.prototype.decode=function(e,t){return this._reader.load(e),this._read(t)},e.prototype._read=function(e){switch(e.type){case"Boolean":return this._reader.readBoolean();case"Number":return this._readNumber(e);case"String":return this._reader.readString();case"Array":for(var t=[],r=this._reader.readUint(),i=0;i<r;++i){var n=this._read(e.elementType);t.push(n)}return t;case"Tuple":if(64<e.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+e.elementTypes.length);for(var t=[],a=this._reader.readVarint(),s=[],i=0;i<32;++i)a.uint32s[1]&1<<i&&s.push(i);for(i=0;i<32;++i)a.uint32s[0]&1<<i&&s.push(i+32);if(!s.length)return[];for(var o=s.last(),i=0,h=0,p=s[0];i<=o;++i)i===p?(t[i]=this._read(e.elementTypes[i]),p=s[++h]):t[i]=void 0;return t;case"Enum":var u=this._reader.readVarint().toNumber(),f=e.members.find(function(e){return e.id===u});if(!f)throw new Error("Invalid enum encoding: unexpected id "+u);return f.value;case"Any":case"NonPrimitive":var c=this._reader.readString();if("undefined"===c)return;return JSON.parse(c);case"Literal":return e.literal;case"Interface":return this._readInterface(e);case"Buffer":var d=this._reader.readBuffer();if(e.arrayType){if("BigInt64Array"===e.arrayType||"BigUint64Array"===e.arrayType)throw new Error("Unsupported arrayType: "+e.arrayType);if("Uint8Array"===e.arrayType)return d;var l=TypedArrays[e.arrayType];return d.byteOffset%l.BYTES_PER_ELEMENT==0?new l(d.buffer,d.byteOffset,d.byteLength/l.BYTES_PER_ELEMENT):new l(d.buffer.slice(d.byteOffset,d.byteOffset+d.byteLength))}return d.buffer.slice(d.byteOffset,d.byteOffset+d.byteLength);case"IndexedAccess":case"Reference":return this._read(this._validator.protoHelper.parseReference(e));case"Pick":case"Partial":case"Omit":return this._read(e.target);case"Overwrite":return this._readOverwrite(e);case"Union":case"Intersection":return this._readUnionOrIntersection(e);default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._readNumber=function(e){var t=e.scalarType||"double";switch(t){case"double":return this._reader.readDouble();case"int":return this._reader.readInt();case"uint":return this._reader.readUint();default:throw new Error("Scalar type not support : "+t)}},e.prototype._readInterface=function(f){for(var c={},d=this._validator.protoHelper.getFlatInterfaceSchema(f),e=this._reader.readUint(),t=function(e){var t,r,i,n,a,s,o,h=l._reader.readUint(),p=3&h,u=h>>2;0==u?d.indexSignature?(t=d.indexSignature.type,r=l._reader.readString(),l._skipIdLengthPrefix(l._validator.protoHelper.parseReference(t)),c[r]=l._read(t)):(l._reader.skipByLengthType(LengthType.LengthDelimited),l._reader.skipByLengthType(p)):u<=9?(i=u-1,(n=f.extends&&f.extends.find(function(e){return e.id===i}))?(l._skipIdLengthPrefix(l._validator.protoHelper.parseReference(n.type)),a=l._read(n.type),Object.assign(c,a)):l._reader.skipByLengthType(p)):(s=u-10,(o=f.properties&&f.properties.find(function(e){return e.id===s}))?(l._skipIdLengthPrefix(l._validator.protoHelper.parseReference(o.type)),c[o.name]=l._read(o.type)):l._reader.skipByLengthType(p))},l=this,r=0;r<e;++r)t();for(var i=0,n=d.properties;i<n.length;i++){var a,s=n[i];c.hasOwnProperty(s.name)||"Literal"===(a=this._validator.protoHelper.parseReference(s.type)).type&&(c[s.name]=a.literal)}return c},e.prototype._skipIdLengthPrefix=function(e){IdBlockUtil.getPayloadLengthInfo(e).needLengthPrefix&&this._reader.skipByLengthType(LengthType.Varint)},e.prototype._readOverwrite=function(e){var t=this._read(e.overwrite),r=this._read(e.target);return Object.assign({},r,t)},e.prototype._readUnionOrIntersection=function(s){for(var o,e=this._reader.readUint(),t=function(e){var t=h._reader.readUint(),r=3&t,i=t>>2,n=s.members.find(function(e){return e.id===i});if(!n)return h._reader.skipByLengthType(r),"continue";h._skipIdLengthPrefix(h._validator.protoHelper.parseReference(n.type));var a=h._read(n.type);h._isObject(o)&&h._isObject(a)?Object.assign(o,a):o=a},h=this,r=0;r<e;++r)t();return o},e.prototype._isObject=function(e){return"object"==typeof e&&null!==e},e}(),Utf8Util=function(){function e(){}return e.measureLength=function(e){for(var t=0,r=0,i=0;i<e.length;++i)(r=e.charCodeAt(i))<128?t+=1:r<2048?t+=2:55296==(64512&r)&&56320==(64512&e.charCodeAt(i+1))?(++i,t+=4):t+=3;return t},e.write=function(e,t,r){for(var i,n,a=r,s=0;s<e.length;++s)(i=e.charCodeAt(s))<128?t[r++]=i:(i<2048?t[r++]=i>>6|192:(55296==(64512&i)&&56320==(64512&(n=e.charCodeAt(s+1)))?(i=65536+((1023&i)<<10)+(1023&n),++s,t[r++]=i>>18|240,t[r++]=i>>12&63|128):t[r++]=i>>12|224,t[r++]=i>>6&63|128),t[r++]=63&i|128);return r-a},e.read=function(e,t,r){if(r<1)return"";for(var i,n=void 0,a=[],s=0,o=t+r;t<o;)(i=e[t++])<128?a[s++]=i:191<i&&i<224?a[s++]=(31&i)<<6|63&e[t++]:239<i&&i<365?(i=((7&i)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,a[s++]=55296+(i>>10),a[s++]=56320+(1023&i)):a[s++]=(15&i)<<12|(63&e[t++])<<6|63&e[t++],8191<s&&((n=n||[]).push(String.fromCharCode.apply(String,a)),s=0);return n?(s&&n.push(String.fromCharCode.apply(String,a.slice(0,s))),n.join("")):String.fromCharCode.apply(String,a.slice(0,s))},e}(),TSBuffer=function(){function e(e,t){this.options={strictExcessCheck:!1,utf8:Utf8Util},Object.assign(this.options,t),this._proto=e,this._validator=new tsbufferValidator.TSBufferValidator(e,{skipExcessCheck:!this.options.strictExcessCheck}),this._encoder=new Encoder(this._validator,this.options.utf8),this._decoder=new Decoder(this._validator,this.options.utf8)}return e.prototype.encode=function(e,t,r){var i;if("string"==typeof t){if(!(i=this._proto[t]))throw new Error("Cannot find schema: "+t)}else i=t;if(!r||!r.skipValidate){var n=this._validator.validateBySchema(e,i);if(!n.isSucc)throw new Error(n.originalError.message)}return this._encoder.encode(e,i)},e.prototype.decode=function(e,t,r){var i,n;if("string"==typeof t){if(!(i=this._proto[t]))throw new Error("Cannot find schema: "+t)}else i=t;try{n=this._decoder.decode(e,i)}catch(e){var a=new Error("Invalid buffer encoding");throw a.encodingError=e,a}if(!r||!r.skipValidate){var s=this._validator.validateBySchema(n,i);if(!s.isSucc)throw new Error(s.originalError.message)}return n},e.prototype.validate=function(e,t){var r;if("string"==typeof t){if(!(r=this._proto[t]))throw new Error("Cannot find schema: "+t)}else r=t;return this._validator.validateBySchema(e,r)},e}();exports.TSBuffer=TSBuffer; |
{ | ||
"name": "tsbuffer", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"k8w-extend-native": "^1.4.0", | ||
"tsbuffer-validator": "^1.0.0" | ||
"tsbuffer-validator": "*" | ||
}, | ||
@@ -17,3 +17,3 @@ "devDependencies": { | ||
"rollup-plugin-typescript2": "^0.21.2", | ||
"rollup-plugin-uglify": "^6.0.2", | ||
"rollup-plugin-uglify": "^6.0.4", | ||
"typescript": "^3.7.2" | ||
@@ -20,0 +20,0 @@ }, |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
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
41602
1
+ Addedtsbuffer-schema@2.2.0(transitive)
+ Addedtsbuffer-validator@2.1.2(transitive)
+ Addedtslib@2.8.1(transitive)
- Removedtsbuffer-schema@1.6.1(transitive)
- Removedtsbuffer-validator@1.1.13(transitive)
Updatedtsbuffer-validator@*