Comparing version 1.3.2 to 1.3.3
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("k8w-extend-native");var LengthType,tsbufferValidator=require("tsbuffer-validator"),__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)},Config={interface:{maxExtendsNum:9}},Varint64=function(){function a(e,t,r){this.uint32s=new Uint32Array([e,t]),void 0!==r&&(this._byteLength=r)}return a.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 a(i,r)},a.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]},a.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},a.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(a.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:!1,configurable:!0}),a.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},a.readFromBuffer=function(e,t){var r=t,i=0,n=0,s=0;if(!(4<e.byteLength-t)){for(;s<3;++s){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(n=(n|(127&e[t])<<7*s)>>>0,e[t++]<128)return new a(i,n,t-r)}return new a(i,n=(n|(127&e[t++])<<7*s)>>>0,t-r)}for(;s<4;++s)if(n=(n|(127&e[t])<<7*s)>>>0,e[t++]<128)return new a(i,n,t-r);if(n=(n|(127&e[t])<<28)>>>0,i=(i|(127&e[t])>>4)>>>0,e[t++]<128)return new a(i,n,t-r);if(s=0,4<e.byteLength-t){for(;s<5;++s)if(i=(i|(127&e[t])<<7*s+3)>>>0,e[t++]<128)return new a(i,n,t-r)}else for(;s<5;++s){if(t>=e.byteLength)throw new Error("Read varint error: index out of range");if(i=(i|(127&e[t])<<7*s+3)>>>0,e[t++]<128)return new a(i,n,t-r)}throw Error("invalid varint encoding")},a.Zero=new a(0,0),a}(),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 BufferWriter=function(){function e(e){this._ops=[],this._utf8=e}return Object.defineProperty(e.prototype,"ops",{get:function(){return this._ops},enumerable:!1,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,s=this._ops;n<s.length;n++){var a=s[n];switch(a.type){case"varint":var o=a.value.writeToBuffer(r,t);if(o!==t+a.length)throw new Error("Error varint measuredLength "+a.length+", actual is "+(o-t)+", value is "+a.value.toNumber());break;case"double":i.setFloat64(r.byteOffset+t,a.value);break;case"string":var p=this._utf8.write(a.value,r,t);if(p!==a.length)throw new Error("Expect "+a.length+" bytes but encoded "+p+" bytes");break;case"buffer":r.subarray(t,t+a.length).set(a.value);break;case"boolean":i.setUint8(r.byteOffset+t,a.value?255:0)}t+=a.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,s=[],n=0;n<i.length;++n)void 0!==i[n]&&s.push(n);for(var a=0,o=0,p=0,h=s;p<h.length;p++){(_=h[p])<32?a|=1<<_:o|=1<<_-32}this._writer.push({type:"varint",value:new Varint64(o,a)});for(var u=0,f=s;u<f.length;u++){n=f[u];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"Partial":this._writeInterface(t,e.target,r);break;case"Pick":if(null!=r&&r.pickFields){for(var c={},d=0,y=e.keys;d<y.length;d++){var _=y[d];r.pickFields[_]&&(c[_]=1)}r.pickFields=c}else{(r=r||{}).pickFields={};for(var g=0,v=e.keys;g<v.length;g++){_=v[g];r.pickFields[_]=1}}this._writeInterface(t,e.target,r);break;case"Omit":null!=r&&r.skipFields||((r=r||{}).skipFields={});for(var w=0,m=e.keys;w<m.length;w++){_=m[w];r.skipFields[_]=1}this._writeInterface(t,e.target,r);break;case"Overwrite":this._writeOverwrite(t,e,r);break;case"Union":this._writeUnion(t,e,null==r?void 0:r.skipFields);break;case"Intersection":this._writeIntersection(t,e,null==r?void 0:r.skipFields);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){(r=r||{}).skipFields||(r.skipFields={});var i=this._writer.ops.length,n=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._write(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 a=0,o=s.extends;a<o.length;a++){var p=o[a],h=p.id+1;this._writer.push({type:"varint",value:Varint64.from(h)});var u=this._writer.ops.length-1,f=this._writer.ops.length;this._writeInterface(e,p.type,__assign(__assign({},r),{skipIndexSignature:!!s.indexSignature||r.skipIndexSignature})),this._writer.ops.length===f+1?this._writer.ops.splice(this._writer.ops.length-2,2):(++n,this._processIdWithLengthType(u,p.type))}}if(s.properties)for(var l=0,c=s.properties;l<c.length;l++){var d=c[l],y=this._validator.protoHelper.parseReference(d.type);r.pickFields&&!r.pickFields[d.name]||("Literal"!==y.type?void 0!==e[d.name]&&(r.skipFields[d.name]||(r.skipFields[d.name]=1,h=d.id+Config.interface.maxExtendsNum+1,this._writer.push({type:"varint",value:Varint64.from(h)}),u=this._writer.ops.length-1,this._write(e[d.name],y),++n,this._processIdWithLengthType(u,y))):r.skipFields[d.name]=1)}if(!r.skipIndexSignature){var _,g=this._validator.protoHelper.getFlatInterfaceSchema(s);if(g.indexSignature)for(var v in e){void 0!==e[v]&&(r.pickFields&&!r.pickFields[v]||r.skipFields[v]||(r.skipFields[v]=1,this._writer.push({type:"varint",value:Varint64.from(0)}),u=this._writer.ops.length-1,this._writer.push({type:"string",value:v}),_=this._writer.ops.length,this._write(e[v],g.indexSignature.type),++n,this._processIdWithLengthType(u,g.indexSignature.type,_)))}}this._writer.ops.splice(i,0,this._writer.req2op({type:"varint",value:Varint64.from(n)}))},e.prototype._writeOverwrite=function(e,t,r){(r=r||{}).skipFields||(r.skipFields={});var i,n,s=this._validator.protoHelper.parseReference(t.target),a=this._validator.protoHelper.parseReference(t.overwrite),o=this._validator.protoHelper.getFlatInterfaceSchema(s),p=this._validator.protoHelper.getFlatInterfaceSchema(a),h={},u={};if(p.properties)for(var f=0,l=p.properties;f<l.length;f++){void 0===e[(c=l[f]).name]||r.skipFields[c.name]||(h[c.name]=e[c.name],r.skipFields[c.name]=1)}if(o.properties)for(var c,d=0,y=o.properties;d<y.length;d++){void 0===e[(c=y[d]).name]||r.skipFields[c.name]||(u[c.name]=e[c.name],r.skipFields[c.name]=1)}if(p.indexSignature?(n=p.indexSignature,i=h):o.indexSignature&&(n=o.indexSignature,i=u),n)for(var _ in e)r.skipFields[_]||(i[_]=e[_],r.skipFields[_]=1);this._writeInterface(h,a,__assign(__assign({},r),{skipFields:{}})),this._writeInterface(u,s,__assign(__assign({},r),{skipFields:{}}))},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,s=0,a=0,o=t.members;a<o.length;a++){var p=o[a];if((this._validator.protoHelper.isInterface(p.type)?this._validator.validateInterfaceReference(e,p.type,i):"Union"===p.type.type?this._validator.validateUnionType(e,p.type,i):"Intersection"===p.type.type?this._validator.validateIntersectionType(e,p.type,i):this._validator.validateBySchema(e,p.type)).isSucc){this._writer.push({type:"varint",value:Varint64.from(p.id)});var h=this._writer.ops.length-1;if("Union"===p.type.type?this._writeUnion(e,p.type,r,i):this._write(e,p.type,r),s++,this._processIdWithLengthType(h,p.type),"object"!=typeof e)break}}if(!(0<s))throw new Error("Non member is satisfied for union type");this._writer.ops.splice(n,0,this._writer.req2op({type:"varint",value:Varint64.from(s)}))},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 s=n[i];this._writer.push({type:"varint",value:Varint64.from(s.id)});var a=this._writer.ops.length-1;this._write(e,s.type,r),this._processIdWithLengthType(a,s.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,s=this._validator.protoHelper.parseReference(e),a=IdBlockUtil.getPayloadLengthInfo(s),o=(i.value.toNumber()<<2)+a.lengthType;this._writer.ops[r]=this._writer.req2op({type:"varint",value:Varint64.from(o)}),a.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:!1,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(t,e){switch(t.type){case"Boolean":return this._reader.readBoolean();case"Number":return this._readNumber(t);case"String":return this._reader.readString();case"Array":for(var r=[],i=this._reader.readUint(),n=0;n<i;++n){var s=this._read(t.elementType);r.push(s)}return r;case"Tuple":if(64<t.elementTypes.length)throw new Error("Elements oversized, maximum supported tuple elements is 64, now get "+t.elementTypes.length);for(var r=[],a=this._reader.readVarint(),o=[],n=0;n<32;++n)a.uint32s[1]&1<<n&&o.push(n);for(n=0;n<32;++n)a.uint32s[0]&1<<n&&o.push(n+32);if(!o.length)return[];for(var p=o.last(),n=0,h=0,u=o[0];n<=p;++n)n===u?(r[n]=this._read(t.elementTypes[n]),u=o[++h]):r[n]=void 0;return r;case"Enum":var f=this._reader.readVarint().toNumber(),l=t.members.find(function(e){return e.id===f});if(!l)throw new Error("Invalid enum encoding: unexpected id "+f);return l.value;case"Any":case"NonPrimitive":var c=this._reader.readString();if("undefined"===c)return;return JSON.parse(c);case"Literal":return t.literal;case"Interface":return this._readInterface(t,e);case"Buffer":var d=this._reader.readBuffer();if(t.arrayType){if("BigInt64Array"===t.arrayType||"BigUint64Array"===t.arrayType)throw new Error("Unsupported arrayType: "+t.arrayType);if("Uint8Array"===t.arrayType)return d;var y=TypedArrays[t.arrayType];return d.byteOffset%y.BYTES_PER_ELEMENT==0?new y(d.buffer,d.byteOffset,d.byteLength/y.BYTES_PER_ELEMENT):new y(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(t),e);case"Partial":return this._read(t.target,e);case"Pick":return(e=e||{}).pickFields?e.pickFields=e.pickFields.filter(function(e){return-1<t.keys.indexOf(e)}):e.pickFields=t.keys.slice(),this._read(t.target,e);case"Omit":return(e=e||{}).omitFields?e.omitFields=e.omitFields.concat(t.keys).distinct():e.omitFields=t.keys.slice(),this._read(t.target,e);case"Overwrite":return this._readOverwrite(t);case"Union":case"Intersection":return this._readUnionOrIntersection(t);default:throw new Error("Unrecognized schema type: "+t.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,e){for(var l={},c=this._validator.protoHelper.getFlatInterfaceSchema(f),t=this._reader.readUint(),r=function(e){var t,r,i,n,s,a,o,p=d._reader.readUint(),h=3&p,u=p>>2;0==u?c.indexSignature?(t=c.indexSignature.type,r=d._reader.readString(),d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(t)),l[r]=d._read(t)):(d._reader.skipByLengthType(LengthType.LengthDelimited),d._reader.skipByLengthType(h)):u<=9?(i=u-1,(n=f.extends&&f.extends.find(function(e){return e.id===i}))?(d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(n.type)),s=d._read(n.type),Object.assign(l,s)):d._reader.skipByLengthType(h)):(a=u-10,(o=f.properties&&f.properties.find(function(e){return e.id===a}))?(d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(o.type)),l[o.name]=d._read(o.type)):d._reader.skipByLengthType(h))},d=this,i=0;i<t;++i)r();for(var n=0,s=c.properties;n<s.length;n++){var a,o=s[n];l.hasOwnProperty(o.name)||"Literal"===(a=this._validator.protoHelper.parseReference(o.type)).type&&(l[o.name]=a.literal)}if(null!=e&&e.pickFields){for(var p={},h=0,u=e.pickFields;h<u.length;h++){var y=u[h];void 0!==l[y]&&(p[y]=l[y])}l=p}if(null!=e&&e.omitFields)for(var _=0,g=e.omitFields;_<g.length;_++){y=g[_];void 0!==l[y]&&delete l[y]}return l},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(a){for(var o,e=this._reader.readUint(),t=function(e){var t=p._reader.readUint(),r=3&t,i=t>>2,n=a.members.find(function(e){return e.id===i});if(!n)return p._reader.skipByLengthType(r),"continue";p._skipIdLengthPrefix(p._validator.protoHelper.parseReference(n.type));var s=p._read(n.type);p._isObject(o)&&p._isObject(s)?Object.assign(o,s):o=s},p=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,s=r,a=0;a<e.length;++a)(i=e.charCodeAt(a))<128?t[r++]=i:(i<2048?t[r++]=i>>6|192:(55296==(64512&i)&&56320==(64512&(n=e.charCodeAt(a+1)))?(i=65536+((1023&i)<<10)+(1023&n),++a,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-s},e.read=function(e,t,r){if(r<1)return"";for(var i,n=void 0,s=[],a=0,o=t+r;t<o;)(i=e[t++])<128?s[a++]=i:191<i&&i<224?s[a++]=(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,s[a++]=55296+(i>>10),s[a++]=56320+(1023&i)):s[a++]=(15&i)<<12|(63&e[t++])<<6|63&e[t++],8191<a&&((n=n||[]).push(String.fromCharCode.apply(String,s)),a=0);return n?(a&&n.push(String.fromCharCode.apply(String,s.slice(0,a))),n.join("")):String.fromCharCode.apply(String,s.slice(0,a))},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 s=new Error("Invalid buffer encoding");throw s.encodingError=e,s}if(!r||!r.skipValidate){var a=this._validator.validateBySchema(n,i);if(!a.isSucc)throw new Error(a.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"),__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)},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:!1,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 BufferWriter=function(){function e(e){this._ops=[],this._utf8=e}return Object.defineProperty(e.prototype,"ops",{get:function(){return this._ops},enumerable:!1,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 p=this._utf8.write(s.value,r,t);if(p!==s.length)throw new Error("Expect "+s.length+" bytes but encoded "+p+" 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,p=0,h=a;p<h.length;p++){var u=h[p];u<32?s|=1<<u:o|=1<<u-32}this._writer.push({type:"varint",value:new Varint64(o,s)});for(var f=0,l=a;f<l.length;f++){n=l[f];this._write(i[n],e.elementTypes[n])}break;case"Enum":var c=e.members.find(function(e){return e.value===t});if(!c)throw new Error("Unexpect enum value: "+t);this._writer.push({type:"varint",value:Varint64.from(c.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"Partial":case"Pick":case"Omit":case"Overwrite":var d=this._validator.protoHelper.parseMappedType(e);"Interface"===d.type?this._writePureMappedType(t,e,r):this._writeUnion(t,d,null==r?void 0:r.skipFields);break;case"Union":this._writeUnion(t,e,null==r?void 0:r.skipFields);break;case"Intersection":this._writeIntersection(t,e,null==r?void 0:r.skipFields);break;default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._writePureMappedType=function(e,t,r){if(r=r||{},"Pick"===t.type)if(r.pickFields){for(var i={},n=0,a=t.keys;n<a.length;n++){var s=a[n];r.pickFields[s]&&(i[s]=1)}r.pickFields=i}else{r.pickFields={};for(var o=0,p=t.keys;o<p.length;o++){s=p[o];r.pickFields[s]=1}}else if("Omit"===t.type){null!=r&&r.skipFields||((r=r||{}).skipFields={});for(var h=0,u=t.keys;h<u.length;h++){s=u[h];r.skipFields[s]=1}}else if("Overwrite"===t.type){var f=this._parseOverwrite(e,t);this._write(f.overwriteValue,f.overwrite,r)}else if("Partial"!==t.type)throw new Error("Invalid PureMappedType child: "+t.type);var l=this._validator.protoHelper.parseReference(t.target);"Interface"===l.type?this._writeInterface(e,l,r):this._writePureMappedType(e,l,r)},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){(r=r||{}).skipFields||(r.skipFields={});var i=this._writer.ops.length,n=0;if(t.extends){if(t.extends.length>Config.interface.maxExtendsNum)throw new Error("Max support "+Config.interface.maxExtendsNum+" extends, actual: "+t.extends.length);for(var a=0,s=t.extends;a<s.length;a++){var o=s[a],p=o.id+1;this._writer.push({type:"varint",value:Varint64.from(p)});var h=this._writer.ops.length-1,u=this._writer.ops.length,f=this._validator.protoHelper.parseReference(o.type);this._writeInterface(e,f,__assign(__assign({},r),{skipIndexSignature:!!t.indexSignature||r.skipIndexSignature})),this._writer.ops.length===u+1?this._writer.ops.splice(this._writer.ops.length-2,2):(++n,this._processIdWithLengthType(h,o.type))}}if(t.properties)for(var l=0,c=t.properties;l<c.length;l++){var d=c[l],y=this._validator.protoHelper.parseReference(d.type);r.pickFields&&!r.pickFields[d.name]||("Literal"!==y.type?void 0!==e[d.name]&&(r.skipFields[d.name]||(r.skipFields[d.name]=1,p=d.id+Config.interface.maxExtendsNum+1,this._writer.push({type:"varint",value:Varint64.from(p)}),h=this._writer.ops.length-1,this._write(e[d.name],y),++n,this._processIdWithLengthType(h,y))):r.skipFields[d.name]=1)}if(!r.skipIndexSignature){var v,_=this._validator.protoHelper.getFlatInterfaceSchema(t);if(_.indexSignature)for(var g in e){void 0!==e[g]&&(r.pickFields&&!r.pickFields[g]||r.skipFields[g]||(r.skipFields[g]=1,this._writer.push({type:"varint",value:Varint64.from(0)}),h=this._writer.ops.length-1,this._writer.push({type:"string",value:g}),v=this._writer.ops.length,this._write(e[g],_.indexSignature.type),++n,this._processIdWithLengthType(h,_.indexSignature.type,v)))}}this._writer.ops.splice(i,0,this._writer.req2op({type:"varint",value:Varint64.from(n)}))},e.prototype._parseOverwrite=function(e,t){var r,i,n={},a=this._validator.protoHelper.parseReference(t.target),s=this._validator.protoHelper.parseReference(t.overwrite),o=this._validator.protoHelper.getFlatInterfaceSchema(a),p=this._validator.protoHelper.getFlatInterfaceSchema(s),h={},u={};if(p.properties)for(var f=0,l=p.properties;f<l.length;f++){void 0===e[(c=l[f]).name]||n[c.name]||(h[c.name]=e[c.name],n[c.name]=1)}if(o.properties)for(var c,d=0,y=o.properties;d<y.length;d++){void 0===e[(c=y[d]).name]||n[c.name]||(u[c.name]=e[c.name],n[c.name]=1)}if(p.indexSignature?(i=p.indexSignature,r=h):o.indexSignature&&(i=o.indexSignature,r=u),i)for(var v in e)n[v]||(r[v]=e[v],n[v]=1);return{target:a,targetValue:u,overwrite:s,overwriteValue:h}},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 p=o[s];if((this._validator.protoHelper.isInterface(p.type)?this._validator.validateInterfaceReference(e,p.type,i):"Union"===p.type.type?this._validator.validateUnionType(e,p.type,i):"Intersection"===p.type.type?this._validator.validateIntersectionType(e,p.type,i):this._validator.validateBySchema(e,p.type)).isSucc){this._writer.push({type:"varint",value:Varint64.from(p.id)});var h=this._writer.ops.length-1;if("Union"===p.type.type?this._writeUnion(e,p.type,r,i):this._write(e,p.type,r),a++,this._processIdWithLengthType(h,p.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:!1,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,p=0,h=s[0];i<=o;++i)i===h?(t[i]=this._read(e.elementTypes[i]),h=s[++p]):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 l=this._reader.readString();if("undefined"===l)return;return JSON.parse(l);case"Literal":return e.literal;case"Interface":return this._readInterface(e);case"Buffer":var c=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 c;var d=TypedArrays[e.arrayType];return c.byteOffset%d.BYTES_PER_ELEMENT==0?new d(c.buffer,c.byteOffset,c.byteLength/d.BYTES_PER_ELEMENT):new d(c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength))}return c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength);case"IndexedAccess":case"Reference":return this._read(this._validator.protoHelper.parseReference(e));case"Partial":case"Pick":case"Omit":case"Overwrite":var y=this._validator.protoHelper.parseMappedType(e);if("Interface"===y.type)return this._readPureMappedType(e);if("Union"===y.type)return this._readUnionOrIntersection(y);break;case"Union":case"Intersection":return this._readUnionOrIntersection(e);default:throw new Error("Unrecognized schema type: "+e.type)}},e.prototype._readPureMappedType=function(e){var t,r;"Overwrite"===e.type&&(r=this._read(e.overwrite));var i=this._validator.protoHelper.parseReference(e.target);if("Interface"===i.type)t=this._readInterface(i);else{if("Pick"!==i.type&&"Omit"!==i.type&&"Partial"!==i.type&&"Overwrite"!==i.type)throw new Error("Invalid PureMappedType child: "+e.type);t=this._readPureMappedType(i)}if("Pick"===e.type)for(var n in t)-1===e.keys.indexOf(n)&&delete t[n];else if("Omit"===e.type)for(var n in t)-1<e.keys.indexOf(n)&&delete t[n];else"Overwrite"===e.type&&Object.assign(t,r);return t},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 l={},c=this._validator.protoHelper.getFlatInterfaceSchema(f),e=this._reader.readUint(),t=function(e){var t,r,i,n,a,s,o,p=d._reader.readUint(),h=3&p,u=p>>2;0==u?c.indexSignature?(t=c.indexSignature.type,r=d._reader.readString(),d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(t)),l[r]=d._read(t)):(d._reader.skipByLengthType(LengthType.LengthDelimited),d._reader.skipByLengthType(h)):u<=9?(i=u-1,(n=f.extends&&f.extends.find(function(e){return e.id===i}))?(d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(n.type)),a=d._read(n.type),Object.assign(l,a)):d._reader.skipByLengthType(h)):(s=u-10,(o=f.properties&&f.properties.find(function(e){return e.id===s}))?(d._skipIdLengthPrefix(d._validator.protoHelper.parseReference(o.type)),l[o.name]=d._read(o.type)):d._reader.skipByLengthType(h))},d=this,r=0;r<e;++r)t();for(var i=0,n=c.properties;i<n.length;i++){var a,s=n[i];l.hasOwnProperty(s.name)||"Literal"===(a=this._validator.protoHelper.parseReference(s.type)).type&&(l[s.name]=a.literal)}return l},e.prototype._skipIdLengthPrefix=function(e){IdBlockUtil.getPayloadLengthInfo(e).needLengthPrefix&&this._reader.skipByLengthType(LengthType.Varint)},e.prototype._readUnionOrIntersection=function(s){for(var o,e=this._reader.readUint(),t=function(e){var t=p._reader.readUint(),r=3&t,i=t>>2,n=s.members.find(function(e){return e.id===i});if(!n)return p._reader.skipByLengthType(r),"continue";p._skipIdLengthPrefix(p._validator.protoHelper.parseReference(n.type));var a=p._read(n.type);p._isObject(o)&&p._isObject(a)?Object.assign(o,a):o=a},p=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.2", | ||
"version": "1.3.3", | ||
"description": "", | ||
@@ -11,2 +11,3 @@ "main": "index.js", | ||
"k8w-extend-native": "*", | ||
"tsbuffer-schema": "*", | ||
"tsbuffer-validator": "*" | ||
@@ -36,2 +37,2 @@ }, | ||
"homepage": "https://github.com/k8w/tsbuffer#readme" | ||
} | ||
} |
@@ -10,8 +10,11 @@ import { TSBufferSchema } from "tsbuffer-schema"; | ||
private _read; | ||
/** | ||
* PureMappedType 每一层的target 都是MappedType或Interface(最终层) | ||
*/ | ||
private _readPureMappedType; | ||
private _readNumber; | ||
private _readInterface; | ||
private _skipIdLengthPrefix; | ||
private _readOverwrite; | ||
private _readUnionOrIntersection; | ||
private _isObject; | ||
} |
import { TSBufferSchema } from 'tsbuffer-schema'; | ||
import { TSBufferValidator } from 'tsbuffer-validator'; | ||
import { OverwriteTypeSchema } from 'tsbuffer-schema/src/schemas/OverwriteTypeSchema'; | ||
import { BufferWriter } from './BufferWriter'; | ||
import { TSBufferOptions } from '../TSBuffer'; | ||
import { OmitTypeSchema } from 'tsbuffer-schema/src/schemas/OmitTypeSchema'; | ||
import { PartialTypeSchema } from 'tsbuffer-schema/src/schemas/PartialTypeSchema'; | ||
import { PickTypeSchema } from 'tsbuffer-schema/src/schemas/PickTypeSchema'; | ||
export declare class Encoder { | ||
@@ -11,5 +15,6 @@ protected _writer: BufferWriter; | ||
private _write; | ||
private _writePureMappedType; | ||
private _writeNumber; | ||
private _writeInterface; | ||
private _writeOverwrite; | ||
private _parseOverwrite; | ||
private _writeUnion; | ||
@@ -29,1 +34,2 @@ private _writeIntersection; | ||
} | ||
export declare type MappedTypeSchema = PickTypeSchema | OmitTypeSchema | PartialTypeSchema | OverwriteTypeSchema; |
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
44290
17
347
3
3
+ Addedtsbuffer-schema@*