Comparing version 2.2.0 to 2.2.1
@@ -48,6 +48,7 @@ /// <reference types="node" /> | ||
export declare class Channel implements IChannel { | ||
private callback?; | ||
agent: IAgent; | ||
constructor(url: string, callback?: ((req: any, res?: any, err?: any) => void) | undefined); | ||
reset(url?: string): void; | ||
callback?: (req: any, res?: any, err?: any) => void; | ||
constructor(url: string, options?: IOptions); | ||
onCall(callback: (req: any, res?: any, err?: any) => void): void; | ||
reset(url: string, options?: IOptions): void; | ||
rpcUnaryUnary(service: string, method: string, requestSerializer: ISerializer, responseDeserializeBinary: IDeserializer, request: any): Promise<any>; | ||
@@ -88,2 +89,7 @@ rpcUnaryStream(service: string, method: string, requestSerializer: ISerializer, responseDeserializeBinary: IDeserializer, request: any): Promise<IStream<any>>; | ||
declare interface IOptions { | ||
contentType?: "grpc" | "grpc-web" | "grpc-web+proto" | "json"; | ||
authorizationToken?: string; | ||
} | ||
declare type IRpc<T> = (service: string, method: string, requestSerializer: ISerializer, responseDeserialize: IDeserializer, request: any) => Promise<T>; | ||
@@ -90,0 +96,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.wsgrpc=t():e.wsgrpc=t()}(global,(function(){return(()=>{"use strict";var __webpack_modules__={537:e=>{e.exports=function(e,t){for(var r=new Array(arguments.length-1),s=0,n=2,a=!0;n<arguments.length;)r[s++]=arguments[n++];return new Promise((function(n,i){r[s]=function(e){if(a)if(a=!1,e)i(e);else{for(var t=new Array(arguments.length-1),r=0;r<t.length;)t[r++]=arguments[r];n.apply(null,t)}};try{e.apply(t||null,r)}catch(e){a&&(a=!1,i(e))}}))}},419:(e,t)=>{var r=t;r.length=function(e){var t=e.length;if(!t)return 0;for(var r=0;--t%4>1&&"="===e.charAt(t);)++r;return Math.ceil(3*e.length)/4-r};for(var s=new Array(64),n=new Array(123),a=0;a<64;)n[s[a]=a<26?a+65:a<52?a+71:a<62?a-4:a-59|43]=a++;r.encode=function(e,t,r){for(var n,a=null,i=[],o=0,l=0;t<r;){var u=e[t++];switch(l){case 0:i[o++]=s[u>>2],n=(3&u)<<4,l=1;break;case 1:i[o++]=s[n|u>>4],n=(15&u)<<2,l=2;break;case 2:i[o++]=s[n|u>>6],i[o++]=s[63&u],l=0}o>8191&&((a||(a=[])).push(String.fromCharCode.apply(String,i)),o=0)}return l&&(i[o++]=s[n],i[o++]=61,1===l&&(i[o++]=61)),a?(o&&a.push(String.fromCharCode.apply(String,i.slice(0,o))),a.join("")):String.fromCharCode.apply(String,i.slice(0,o))};var i="invalid encoding";r.decode=function(e,t,r){for(var s,a=r,o=0,l=0;l<e.length;){var u=e.charCodeAt(l++);if(61===u&&o>1)break;if(void 0===(u=n[u]))throw Error(i);switch(o){case 0:s=u,o=1;break;case 1:t[r++]=s<<2|(48&u)>>4,s=u,o=2;break;case 2:t[r++]=(15&s)<<4|(60&u)>>2,s=u,o=3;break;case 3:t[r++]=(3&s)<<6|u,o=0}}if(1===o)throw Error(i);return r-a},r.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}},211:e=>{function t(){this._listeners={}}e.exports=t,t.prototype.on=function(e,t,r){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:r||this}),this},t.prototype.off=function(e,t){if(void 0===e)this._listeners={};else if(void 0===t)this._listeners[e]=[];else for(var r=this._listeners[e],s=0;s<r.length;)r[s].fn===t?r.splice(s,1):++s;return this},t.prototype.emit=function(e){var t=this._listeners[e];if(t){for(var r=[],s=1;s<arguments.length;)r.push(arguments[s++]);for(s=0;s<t.length;)t[s].fn.apply(t[s++].ctx,r)}return this}},945:e=>{function t(e){return"undefined"!=typeof Float32Array?function(){var t=new Float32Array([-0]),r=new Uint8Array(t.buffer),s=128===r[3];function n(e,s,n){t[0]=e,s[n]=r[0],s[n+1]=r[1],s[n+2]=r[2],s[n+3]=r[3]}function a(e,s,n){t[0]=e,s[n]=r[3],s[n+1]=r[2],s[n+2]=r[1],s[n+3]=r[0]}function i(e,s){return r[0]=e[s],r[1]=e[s+1],r[2]=e[s+2],r[3]=e[s+3],t[0]}function o(e,s){return r[3]=e[s],r[2]=e[s+1],r[1]=e[s+2],r[0]=e[s+3],t[0]}e.writeFloatLE=s?n:a,e.writeFloatBE=s?a:n,e.readFloatLE=s?i:o,e.readFloatBE=s?o:i}():function(){function t(e,t,r,s){var n=t<0?1:0;if(n&&(t=-t),0===t)e(1/t>0?0:2147483648,r,s);else if(isNaN(t))e(2143289344,r,s);else if(t>34028234663852886e22)e((n<<31|2139095040)>>>0,r,s);else if(t<11754943508222875e-54)e((n<<31|Math.round(t/1401298464324817e-60))>>>0,r,s);else{var a=Math.floor(Math.log(t)/Math.LN2);e((n<<31|a+127<<23|8388607&Math.round(t*Math.pow(2,-a)*8388608))>>>0,r,s)}}function i(e,t,r){var s=e(t,r),n=2*(s>>31)+1,a=s>>>23&255,i=8388607&s;return 255===a?i?NaN:n*(1/0):0===a?1401298464324817e-60*n*i:n*Math.pow(2,a-150)*(i+8388608)}e.writeFloatLE=t.bind(null,r),e.writeFloatBE=t.bind(null,s),e.readFloatLE=i.bind(null,n),e.readFloatBE=i.bind(null,a)}(),"undefined"!=typeof Float64Array?function(){var t=new Float64Array([-0]),r=new Uint8Array(t.buffer),s=128===r[7];function n(e,s,n){t[0]=e,s[n]=r[0],s[n+1]=r[1],s[n+2]=r[2],s[n+3]=r[3],s[n+4]=r[4],s[n+5]=r[5],s[n+6]=r[6],s[n+7]=r[7]}function a(e,s,n){t[0]=e,s[n]=r[7],s[n+1]=r[6],s[n+2]=r[5],s[n+3]=r[4],s[n+4]=r[3],s[n+5]=r[2],s[n+6]=r[1],s[n+7]=r[0]}function i(e,s){return r[0]=e[s],r[1]=e[s+1],r[2]=e[s+2],r[3]=e[s+3],r[4]=e[s+4],r[5]=e[s+5],r[6]=e[s+6],r[7]=e[s+7],t[0]}function o(e,s){return r[7]=e[s],r[6]=e[s+1],r[5]=e[s+2],r[4]=e[s+3],r[3]=e[s+4],r[2]=e[s+5],r[1]=e[s+6],r[0]=e[s+7],t[0]}e.writeDoubleLE=s?n:a,e.writeDoubleBE=s?a:n,e.readDoubleLE=s?i:o,e.readDoubleBE=s?o:i}():function(){function t(e,t,r,s,n,a){var i=s<0?1:0;if(i&&(s=-s),0===s)e(0,n,a+t),e(1/s>0?0:2147483648,n,a+r);else if(isNaN(s))e(0,n,a+t),e(2146959360,n,a+r);else if(s>17976931348623157e292)e(0,n,a+t),e((i<<31|2146435072)>>>0,n,a+r);else{var o;if(s<22250738585072014e-324)e((o=s/5e-324)>>>0,n,a+t),e((i<<31|o/4294967296)>>>0,n,a+r);else{var l=Math.floor(Math.log(s)/Math.LN2);1024===l&&(l=1023),e(4503599627370496*(o=s*Math.pow(2,-l))>>>0,n,a+t),e((i<<31|l+1023<<20|1048576*o&1048575)>>>0,n,a+r)}}}function i(e,t,r,s,n){var a=e(s,n+t),i=e(s,n+r),o=2*(i>>31)+1,l=i>>>20&2047,u=4294967296*(1048575&i)+a;return 2047===l?u?NaN:o*(1/0):0===l?5e-324*o*u:o*Math.pow(2,l-1075)*(u+4503599627370496)}e.writeDoubleLE=t.bind(null,r,0,4),e.writeDoubleBE=t.bind(null,s,4,0),e.readDoubleLE=i.bind(null,n,0,4),e.readDoubleBE=i.bind(null,a,4,0)}(),e}function r(e,t,r){t[r]=255&e,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function s(e,t,r){t[r]=e>>>24,t[r+1]=e>>>16&255,t[r+2]=e>>>8&255,t[r+3]=255&e}function n(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function a(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}e.exports=t(t)},199:module=>{function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(e){}return null}module.exports=inquire},662:e=>{e.exports=function(e,t,r){var s=r||8192,n=s>>>1,a=null,i=s;return function(r){if(r<1||r>n)return e(r);i+r>s&&(a=e(s),i=0);var o=t.call(a,i,i+=r);return 7&i&&(i=1+(7|i)),o}}},997:(e,t)=>{var r=t;r.length=function(e){for(var t=0,r=0,s=0;s<e.length;++s)(r=e.charCodeAt(s))<128?t+=1:r<2048?t+=2:55296==(64512&r)&&56320==(64512&e.charCodeAt(s+1))?(++s,t+=4):t+=3;return t},r.read=function(e,t,r){if(r-t<1)return"";for(var s,n=null,a=[],i=0;t<r;)(s=e[t++])<128?a[i++]=s:s>191&&s<224?a[i++]=(31&s)<<6|63&e[t++]:s>239&&s<365?(s=((7&s)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,a[i++]=55296+(s>>10),a[i++]=56320+(1023&s)):a[i++]=(15&s)<<12|(63&e[t++])<<6|63&e[t++],i>8191&&((n||(n=[])).push(String.fromCharCode.apply(String,a)),i=0);return n?(i&&n.push(String.fromCharCode.apply(String,a.slice(0,i))),n.join("")):String.fromCharCode.apply(String,a.slice(0,i))},r.write=function(e,t,r){for(var s,n,a=r,i=0;i<e.length;++i)(s=e.charCodeAt(i))<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=63&s|128):55296==(64512&s)&&56320==(64512&(n=e.charCodeAt(i+1)))?(s=65536+((1023&s)<<10)+(1023&n),++i,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=63&s|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=63&s|128);return r-a}},100:(e,t,r)=>{e.exports=r(482)},482:(e,t,r)=>{var s=t;function n(){s.util._configure(),s.Writer._configure(s.BufferWriter),s.Reader._configure(s.BufferReader)}s.build="minimal",s.Writer=r(173),s.BufferWriter=r(155),s.Reader=r(408),s.BufferReader=r(593),s.util=r(693),s.rpc=r(994),s.roots=r(54),s.configure=n,n()},408:(e,t,r)=>{e.exports=l;var s,n=r(693),a=n.LongBits,i=n.utf8;function o(e,t){return RangeError("index out of range: "+e.pos+" + "+(t||1)+" > "+e.len)}function l(e){this.buf=e,this.pos=0,this.len=e.length}var u,c="undefined"!=typeof Uint8Array?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new l(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new l(e);throw Error("illegal buffer")},h=function(){return n.Buffer?function(e){return(l.create=function(e){return n.Buffer.isBuffer(e)?new s(e):c(e)})(e)}:c};function f(){var e=new a(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw o(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw o(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}function d(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}function p(){if(this.pos+8>this.len)throw o(this,8);return new a(d(this.buf,this.pos+=4),d(this.buf,this.pos+=4))}l.create=h(),l.prototype._slice=n.Array.prototype.subarray||n.Array.prototype.slice,l.prototype.uint32=(u=4294967295,function(){if(u=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return u;if(u=(u|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return u;if(u=(u|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return u;if(u=(u|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return u;if(u=(u|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return u;if((this.pos+=5)>this.len)throw this.pos=this.len,o(this,10);return u}),l.prototype.int32=function(){return 0|this.uint32()},l.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(1&e)|0},l.prototype.bool=function(){return 0!==this.uint32()},l.prototype.fixed32=function(){if(this.pos+4>this.len)throw o(this,4);return d(this.buf,this.pos+=4)},l.prototype.sfixed32=function(){if(this.pos+4>this.len)throw o(this,4);return 0|d(this.buf,this.pos+=4)},l.prototype.float=function(){if(this.pos+4>this.len)throw o(this,4);var e=n.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e},l.prototype.double=function(){if(this.pos+8>this.len)throw o(this,4);var e=n.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e},l.prototype.bytes=function(){var e=this.uint32(),t=this.pos,r=this.pos+e;if(r>this.len)throw o(this,e);return this.pos+=e,Array.isArray(this.buf)?this.buf.slice(t,r):t===r?new this.buf.constructor(0):this._slice.call(this.buf,t,r)},l.prototype.string=function(){var e=this.bytes();return i.read(e,0,e.length)},l.prototype.skip=function(e){if("number"==typeof e){if(this.pos+e>this.len)throw o(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw o(this)}while(128&this.buf[this.pos++]);return this},l.prototype.skipType=function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+e+" at offset "+this.pos)}return this},l._configure=function(e){s=e,l.create=h(),s._configure();var t=n.Long?"toLong":"toNumber";n.merge(l.prototype,{int64:function(){return f.call(this)[t](!1)},uint64:function(){return f.call(this)[t](!0)},sint64:function(){return f.call(this).zzDecode()[t](!1)},fixed64:function(){return p.call(this)[t](!0)},sfixed64:function(){return p.call(this)[t](!1)}})}},593:(e,t,r)=>{e.exports=a;var s=r(408);(a.prototype=Object.create(s.prototype)).constructor=a;var n=r(693);function a(e){s.call(this,e)}a._configure=function(){n.Buffer&&(a.prototype._slice=n.Buffer.prototype.slice)},a.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+e,this.len))},a._configure()},54:e=>{e.exports={}},994:(e,t,r)=>{t.Service=r(948)},948:(e,t,r)=>{e.exports=n;var s=r(693);function n(e,t,r){if("function"!=typeof e)throw TypeError("rpcImpl must be a function");s.EventEmitter.call(this),this.rpcImpl=e,this.requestDelimited=Boolean(t),this.responseDelimited=Boolean(r)}(n.prototype=Object.create(s.EventEmitter.prototype)).constructor=n,n.prototype.rpcCall=function e(t,r,n,a,i){if(!a)throw TypeError("request must be specified");var o=this;if(!i)return s.asPromise(e,o,t,r,n,a);if(o.rpcImpl)try{return o.rpcImpl(t,r[o.requestDelimited?"encodeDelimited":"encode"](a).finish(),(function(e,r){if(e)return o.emit("error",e,t),i(e);if(null!==r){if(!(r instanceof n))try{r=n[o.responseDelimited?"decodeDelimited":"decode"](r)}catch(e){return o.emit("error",e,t),i(e)}return o.emit("data",r,t),i(null,r)}o.end(!0)}))}catch(e){return o.emit("error",e,t),void setTimeout((function(){i(e)}),0)}else setTimeout((function(){i(Error("already ended"))}),0)},n.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},630:(e,t,r)=>{e.exports=n;var s=r(693);function n(e,t){this.lo=e>>>0,this.hi=t>>>0}var a=n.zero=new n(0,0);a.toNumber=function(){return 0},a.zzEncode=a.zzDecode=function(){return this},a.length=function(){return 1};var i=n.zeroHash="\0\0\0\0\0\0\0\0";n.fromNumber=function(e){if(0===e)return a;var t=e<0;t&&(e=-e);var r=e>>>0,s=(e-r)/4294967296>>>0;return t&&(s=~s>>>0,r=~r>>>0,++r>4294967295&&(r=0,++s>4294967295&&(s=0))),new n(r,s)},n.from=function(e){if("number"==typeof e)return n.fromNumber(e);if(s.isString(e)){if(!s.Long)return n.fromNumber(parseInt(e,10));e=s.Long.fromString(e)}return e.low||e.high?new n(e.low>>>0,e.high>>>0):a},n.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var t=1+~this.lo>>>0,r=~this.hi>>>0;return t||(r=r+1>>>0),-(t+4294967296*r)}return this.lo+4294967296*this.hi},n.prototype.toLong=function(e){return s.Long?new s.Long(0|this.lo,0|this.hi,Boolean(e)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(e)}};var o=String.prototype.charCodeAt;n.fromHash=function(e){return e===i?a:new n((o.call(e,0)|o.call(e,1)<<8|o.call(e,2)<<16|o.call(e,3)<<24)>>>0,(o.call(e,4)|o.call(e,5)<<8|o.call(e,6)<<16|o.call(e,7)<<24)>>>0)},n.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},n.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this},n.prototype.zzDecode=function(){var e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this},n.prototype.length=function(){var e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,r=this.hi>>>24;return 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}},693:function(e,t,r){var s=t;function n(e,t,r){for(var s=Object.keys(t),n=0;n<s.length;++n)void 0!==e[s[n]]&&r||(e[s[n]]=t[s[n]]);return e}function a(e){function t(e,r){if(!(this instanceof t))return new t(e,r);Object.defineProperty(this,"message",{get:function(){return e}}),Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:(new Error).stack||""}),r&&n(this,r)}return(t.prototype=Object.create(Error.prototype)).constructor=t,Object.defineProperty(t.prototype,"name",{get:function(){return e}}),t.prototype.toString=function(){return this.name+": "+this.message},t}s.asPromise=r(537),s.base64=r(419),s.EventEmitter=r(211),s.float=r(945),s.inquire=r(199),s.utf8=r(997),s.pool=r(662),s.LongBits=r(630),s.isNode=Boolean("undefined"!=typeof global&&global&&global.process&&global.process.versions&&global.process.versions.node),s.global=s.isNode&&global||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||this,s.emptyArray=Object.freeze?Object.freeze([]):[],s.emptyObject=Object.freeze?Object.freeze({}):{},s.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},s.isString=function(e){return"string"==typeof e||e instanceof String},s.isObject=function(e){return e&&"object"==typeof e},s.isset=s.isSet=function(e,t){var r=e[t];return!(null==r||!e.hasOwnProperty(t))&&("object"!=typeof r||(Array.isArray(r)?r.length:Object.keys(r).length)>0)},s.Buffer=function(){try{var e=s.inquire("buffer").Buffer;return e.prototype.utf8Write?e:null}catch(e){return null}}(),s._Buffer_from=null,s._Buffer_allocUnsafe=null,s.newBuffer=function(e){return"number"==typeof e?s.Buffer?s._Buffer_allocUnsafe(e):new s.Array(e):s.Buffer?s._Buffer_from(e):"undefined"==typeof Uint8Array?e:new Uint8Array(e)},s.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,s.Long=s.global.dcodeIO&&s.global.dcodeIO.Long||s.global.Long||s.inquire("long"),s.key2Re=/^true|false|0|1$/,s.key32Re=/^-?(?:0|[1-9][0-9]*)$/,s.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,s.longToHash=function(e){return e?s.LongBits.from(e).toHash():s.LongBits.zeroHash},s.longFromHash=function(e,t){var r=s.LongBits.fromHash(e);return s.Long?s.Long.fromBits(r.lo,r.hi,t):r.toNumber(Boolean(t))},s.merge=n,s.lcFirst=function(e){return e.charAt(0).toLowerCase()+e.substring(1)},s.newError=a,s.ProtocolError=a("ProtocolError"),s.oneOfGetter=function(e){for(var t={},r=0;r<e.length;++r)t[e[r]]=1;return function(){for(var e=Object.keys(this),r=e.length-1;r>-1;--r)if(1===t[e[r]]&&void 0!==this[e[r]]&&null!==this[e[r]])return e[r]}},s.oneOfSetter=function(e){return function(t){for(var r=0;r<e.length;++r)e[r]!==t&&delete this[e[r]]}},s.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},s._configure=function(){var e=s.Buffer;e?(s._Buffer_from=e.from!==Uint8Array.from&&e.from||function(t,r){return new e(t,r)},s._Buffer_allocUnsafe=e.allocUnsafe||function(t){return new e(t)}):s._Buffer_from=s._Buffer_allocUnsafe=null}},173:(e,t,r)=>{e.exports=h;var s,n=r(693),a=n.LongBits,i=n.base64,o=n.utf8;function l(e,t,r){this.fn=e,this.len=t,this.next=void 0,this.val=r}function u(){}function c(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}function h(){this.len=0,this.head=new l(u,0,0),this.tail=this.head,this.states=null}var f=function(){return n.Buffer?function(){return(h.create=function(){return new s})()}:function(){return new h}};function d(e,t,r){t[r]=255&e}function p(e,t){this.len=e,this.next=void 0,this.val=t}function y(e,t,r){for(;e.hi;)t[r++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=127&e.lo|128,e.lo=e.lo>>>7;t[r++]=e.lo}function m(e,t,r){t[r]=255&e,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}h.create=f(),h.alloc=function(e){return new n.Array(e)},n.Array!==Array&&(h.alloc=n.pool(h.alloc,n.Array.prototype.subarray)),h.prototype._push=function(e,t,r){return this.tail=this.tail.next=new l(e,t,r),this.len+=t,this},p.prototype=Object.create(l.prototype),p.prototype.fn=function(e,t,r){for(;e>127;)t[r++]=127&e|128,e>>>=7;t[r]=e},h.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new p((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this},h.prototype.int32=function(e){return e<0?this._push(y,10,a.fromNumber(e)):this.uint32(e)},h.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)},h.prototype.uint64=function(e){var t=a.from(e);return this._push(y,t.length(),t)},h.prototype.int64=h.prototype.uint64,h.prototype.sint64=function(e){var t=a.from(e).zzEncode();return this._push(y,t.length(),t)},h.prototype.bool=function(e){return this._push(d,1,e?1:0)},h.prototype.fixed32=function(e){return this._push(m,4,e>>>0)},h.prototype.sfixed32=h.prototype.fixed32,h.prototype.fixed64=function(e){var t=a.from(e);return this._push(m,4,t.lo)._push(m,4,t.hi)},h.prototype.sfixed64=h.prototype.fixed64,h.prototype.float=function(e){return this._push(n.float.writeFloatLE,4,e)},h.prototype.double=function(e){return this._push(n.float.writeDoubleLE,8,e)};var g=n.Array.prototype.set?function(e,t,r){t.set(e,r)}:function(e,t,r){for(var s=0;s<e.length;++s)t[r+s]=e[s]};h.prototype.bytes=function(e){var t=e.length>>>0;if(!t)return this._push(d,1,0);if(n.isString(e)){var r=h.alloc(t=i.length(e));i.decode(e,r,0),e=r}return this.uint32(t)._push(g,t,e)},h.prototype.string=function(e){var t=o.length(e);return t?this.uint32(t)._push(o.write,t,e):this._push(d,1,0)},h.prototype.fork=function(){return this.states=new c(this),this.head=this.tail=new l(u,0,0),this.len=0,this},h.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new l(u,0,0),this.len=0),this},h.prototype.ldelim=function(){var e=this.head,t=this.tail,r=this.len;return this.reset().uint32(r),r&&(this.tail.next=e.next,this.tail=t,this.len+=r),this},h.prototype.finish=function(){for(var e=this.head.next,t=this.constructor.alloc(this.len),r=0;e;)e.fn(e.val,t,r),r+=e.len,e=e.next;return t},h._configure=function(e){s=e,h.create=f(),s._configure()}},155:(e,t,r)=>{e.exports=a;var s=r(173);(a.prototype=Object.create(s.prototype)).constructor=a;var n=r(693);function a(){s.call(this)}function i(e,t,r){e.length<40?n.utf8.write(e,t,r):t.utf8Write?t.utf8Write(e,r):t.write(e,r)}a._configure=function(){a.alloc=n._Buffer_allocUnsafe,a.writeBytesBuffer=n.Buffer&&n.Buffer.prototype instanceof Uint8Array&&"set"===n.Buffer.prototype.set.name?function(e,t,r){t.set(e,r)}:function(e,t,r){if(e.copy)e.copy(t,r,0,e.length);else for(var s=0;s<e.length;)t[r++]=e[s++]}},a.prototype.bytes=function(e){n.isString(e)&&(e=n._Buffer_from(e,"base64"));var t=e.length>>>0;return this.uint32(t),t&&this._push(a.writeBytesBuffer,t,e),this},a.prototype.string=function(e){var t=n.Buffer.byteLength(e);return this.uint32(t),t&&this._push(i,t,e),this},a._configure()},110:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Channel=void 0;const s=r(212),n=r(303);t.Channel=class{constructor(e,t){if(this.callback=t,!e)throw new Error("no url provided.");this.reset(e)}reset(e){var t;if(null===(t=this.agent)||void 0===t||t.reset(),e)if(e.startsWith("http:")||e.startsWith("https:"))this.agent=new n.GrpcWebAgent(e);else{if(!e.startsWith("ws:")&&!e.startsWith("wss:"))throw new Error("channel url not supported: "+e);this.agent=new s.WebSocketAgent(e)}}async rpcUnaryUnary(e,t,r,s,n){const a=await this.agent.getConnection();return await a.rpcUnaryUnary(e,t,r,s,n).then((e=>(this.callback&&this.callback(n,e),e)),(e=>{throw this.callback&&this.callback(n,null,e),e}))}async rpcUnaryStream(e,t,r,s,n){const a=await this.agent.getConnection();return await a.rpcUnaryStream(e,t,r,s,n)}async rpcStreamStream(e,t,r,s,n){const a=await this.agent.getConnection();return await a.rpcStreamStream(e,t,r,s,n)}async rpcStreamUnary(e,t,r,s,n){const a=await this.agent.getConnection();return await a.rpcStreamUnary(e,t,r,s,n).then((e=>(this.callback&&this.callback(n,e),e)),(e=>{throw this.callback&&this.callback(n,null,e),e}))}}},303:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GrpcWebAgent=void 0,t.GrpcWebAgent=class{constructor(e,t="grpc-web"){this.type=t,this.url=e+(e.endsWith("/")?"":"/")}getConnection(){return this}reset(){}async rpcUnaryUnary(e,t,i,o,l){var u,c;const h=`application/${this.type}`;let f;if("grpc-web"==this.type||"grpc-web+proto"==this.type)f=function(e){for(var t=e.length,r=[0,0,0,0],s=new Uint8Array(5+t),n=3;n>=0;n--)r[n]=t%256,t>>>=8;return s.set(new Uint8Array(r),1),s.set(e,5),s}(i(l));else if("grpc"==this.type)f=i(l);else{if("json"!=this.type)throw new Error(`Unknown Content-type to use. ${h}`);f=JSON.stringify(l)}console.log("req:",{body:f,headers:{"Content-Type":h,Accept:h}});const d=this.url+e+"/"+t,p=await fetch(d,{method:"POST",body:f,headers:{"Content-Type":h,Accept:h}}),y=p.headers.get("Content-Type");if("application/grpc-web+proto"===y||"application/grpc-web"===y){const e=function(e){const t={messages:[],trailer:null};let i=new Uint8Array(e);for(;i.length;){const e=i[0],o=i[1]<<24|i[2]<<16|i[3]<<8|i[4],l=i.slice(5,5+o);if(i=i.subarray(5+o),e==n)t.messages.push(l);else if(e==a){const e={code:0,message:"",metadata:{}};new TextDecoder("utf-8").decode(l).trim().split("\r\n").map((e=>e.split(": ",2))).map((([e,t])=>[e.toLowerCase(),t])).forEach((([t,n])=>{t==r?e.code=Number(n):t==s?e.message=n:e.metadata[t]=n})),t.trailer=e}}return t}(await p.arrayBuffer()),t=null===(u=e.trailer)||void 0===u?void 0:u.code,i=null===(c=e.trailer)||void 0===c?void 0:c.metadata;if(0!=t)throw new Error(i);return o(e.messages[0])}if("application/grpc"===y){const e=await p.arrayBuffer(),t=Number(p.headers.get(r)),n=p.headers.get(s);if(0!=t)throw new Error(n);return o(new Uint8Array(e))}if("application/json"===y){const e=Number(p.headers.get(r)),t=p.headers.get(s);if(0!=e)throw new Error(t);return await p.json()}throw new Error(`Unknown Content-type received. ${y}`)}rpcUnaryStream(e,t,r,s,n){throw new Error("method not supported")}rpcStreamStream(e,t,r,s,n){throw new Error("method not supported")}rpcStreamUnary(e,t,r,s,n){throw new Error("method not supported")}};const r="grpc-status",s="grpc-message",n=0,a=128},212:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketAgent=void 0;const s=r(87),n=r(795);t.WebSocketAgent=class{constructor(e){this.url=e,this.connectionFuture=null}async getConnection(){var e;if((null===(e=this.connectionFuture)||void 0===e?void 0:e.resolved)&&(this.connectionFuture.result?1!=this.connectionFuture.result.ws.readyState&&(this.connectionFuture=null):this.connectionFuture=null),!this.connectionFuture){const e=new s.Future,t=new WebSocket(this.url);t.binaryType="arraybuffer",t.onopen=()=>{e.resolve(new a(t))},t.onclose=t=>{e.reject(t)},this.connectionFuture=e}return await this.connectionFuture.promise}reset(){var e;(null===(e=this.connectionFuture)||void 0===e?void 0:e.result)&&1==this.connectionFuture.result.ws.readyState&&this.connectionFuture.result.ws.close(),this.connectionFuture=null}};class a{constructor(e){this.ws=e,this._nextCallID=1,this._calls=new Map,e.onmessage=e=>{let t=n.data.DataFrame.decode(new Uint8Array(e.data)),r=this._calls.get(t.callID);r&&r(t)},e.onclose=()=>{e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null,console.log("calls:",this._calls),this._calls.forEach((e=>e(null))),this._calls.clear()}}registerCall(e){const t=this._nextCallID;return this._calls.set(t,e),this._nextCallID+=2,t}sendMessage(e){if(1!=this.ws.readyState)return;const t=n.data.DataFrame.encode(e);"undefined"!=typeof window&&window.wx?this.ws.send(t.buffer.slice(t.byteOffset,t.byteOffset+t.length)):this.ws.send(t)}rpcUnaryUnary(e,t,r,a,i){const o=new s.Future,l=this.registerCall((e=>{if(e)if(this._calls.delete(l),e.body){const t=a(e.body);o.resolve(t)}else e.trailer&&e.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&o.reject(new Error(e.trailer.message));else o.reject(new Error("lost connection"))})),u=r(i);return this.sendMessage({callID:l,header:{service:e,method:t},body:u}),o.promise}async rpcUnaryStream(e,t,r,a,i){const o=new s.Stream((e=>{this.sendMessage({callID:l,trailer:{status:n.data.DataFrame.Trailer.Status.ABORT,message:null==e?void 0:e.toString()}})})),l=this.registerCall((e=>{if(e){if(e.body){const t=a(e.body);o.write(t)}e.trailer&&(this._calls.delete(l),e.trailer.status==n.data.DataFrame.Trailer.Status.OK?o.end():e.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&o.error(new Error(e.trailer.message)))}else o.error(new Error("lost connection"))})),u=r(i);return this.sendMessage({callID:l,header:{service:e,method:t},body:u}),o}async rpcStreamStream(e,t,r,a,i){const o=new s.Stream((e=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.ABORT,message:null==e?void 0:e.toString()}})})),l=()=>{o.closed&&i.closed&&this._calls.delete(u)},u=this.registerCall((e=>{if(!e)return o.error(new Error("lost connection")),void i.abort(new Error("lost connection"));if(e.body){const t=a(e.body);o.write(t)}e.trailer&&(e.trailer.status==n.data.DataFrame.Trailer.Status.OK?o.end():e.trailer.status==n.data.DataFrame.Trailer.Status.ABORT?i.abort(new Error(e.trailer.message)):e.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&o.error(new Error(e.trailer.message)),l())}));return this.sendMessage({callID:u,header:{service:e,method:t}}),i.read((e=>{const t=r(e);this.sendMessage({callID:u,body:t})})).then((()=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})})).catch((e=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:e.toString()}})})).finally(l),o}rpcStreamUnary(e,t,r,a,i){const o=new s.Future,l=()=>{o.resolved&&i.closed&&this._calls.delete(u)},u=this.registerCall((e=>{if(!e)return o.reject(new Error("lost connection")),void i.abort(new Error("lost connection"));if(e.body){const t=a(e.body);o.resolve(t)}e.trailer&&(e.trailer.status==n.data.DataFrame.Trailer.Status.ABORT?i.abort(new Error(e.trailer.message)):e.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&o.reject(new Error(e.trailer.message))),l()}));return this.sendMessage({callID:u,header:{service:e,method:t}}),i.read((e=>{const t=r(e);this.sendMessage({callID:u,body:t})})).then((()=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})})).catch((e=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:e.toString()}})})).finally(l),o.promise}}},795:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.data=void 0;const s=r(100);!function(e){let t;!function(e){let t,r;!function(e){e.encode=function(e,t){const r=!t;return t||(t=s.Writer.create()),null!=e.service&&null!=e.service&&t.uint32(10).string(e.service),null!=e.method&&null!=e.method&&t.uint32(18).string(e.method),r?t.finish():t},e.decode=function(e,t){e instanceof s.Reader||(e=s.Reader.create(e));let r=void 0===t?e.len:e.pos+t;const n={};for(;e.pos<r;){let t=e.uint32();switch(t>>>3){case 1:n.service=e.string();break;case 2:n.method=e.string();break;default:e.skipType(7&t)}}return n}}(t=e.Header||(e.Header={})),function(e){e.Status={OK:0,ERROR:1,ABORT:2,UNKNOWN:3},e.encode=function(e,t){const r=!t;return t||(t=s.Writer.create()),null!=e.status&&null!=e.status&&t.uint32(8).int32(e.status),null!=e.message&&null!=e.message&&t.uint32(18).string(e.message),r?t.finish():t},e.decode=function(e,t){e instanceof s.Reader||(e=s.Reader.create(e));let r=void 0===t?e.len:e.pos+t;const n={};for(;e.pos<r;){let t=e.uint32();switch(t>>>3){case 1:n.status=e.int32();break;case 2:n.message=e.string();break;default:e.skipType(7&t)}}return n}}(r=e.Trailer||(e.Trailer={})),e.encode=function(e,n){const a=!n;return n||(n=s.Writer.create()),null!=e.callID&&null!=e.callID&&n.uint32(8).int32(e.callID),null!=e.header&&null!=e.header&&t.encode(e.header,n.uint32(58).fork()).ldelim(),null!=e.trailer&&null!=e.trailer&&r.encode(e.trailer,n.uint32(66).fork()).ldelim(),null!=e.body&&null!=e.body&&n.uint32(74).bytes(e.body),a?n.finish():n},e.decode=function(e,n){e instanceof s.Reader||(e=s.Reader.create(e));let a=void 0===n?e.len:e.pos+n;const i={};for(;e.pos<a;){let s=e.uint32();switch(s>>>3){case 1:i.callID=e.int32();break;case 7:i.header=t.decode(e,e.uint32());break;case 8:i.trailer=r.decode(e,e.uint32());break;case 9:i.body=e.bytes();break;default:e.skipType(7&s)}}return i}}(t=e.DataFrame||(e.DataFrame={}))}(t.data||(t.data={}))},728:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Server=void 0;const s=r(87),n=r(795),a=r(615);t.Server=class{constructor(){this.services={},this.fallbacks={}}addService(e,t,r){this.services[e]={rpcs:t,factory:r}}listenHttpServerRequest(e,t){e.on("request",((e,r)=>{var s,n;(null===(s=e.url)||void 0===s?void 0:s.startsWith(t))?new o(t,this.services).handle(e,r):(null===(n=this.fallbacks)||void 0===n?void 0:n.onrequest)?this.fallbacks.onrequest(e,r):(r.statusCode=404,r.end())}))}listenHttpServerUpgrade(e,t){const r=new WebSocket.Server({noServer:!0});e.on("upgrade",((e,s,n)=>{var a;new URL(e.url,`http://${e.headers.host}`).pathname==t?r.handleUpgrade(e,s,n,((e,t)=>new l(e,t,this.services))):(null===(a=this.fallbacks)||void 0===a?void 0:a.onupgrade)?this.fallbacks.onupgrade(e,s,n):(s.write("HTTP/1.1 404 Not Found\r\n\r\n"),s.destroy())}))}fallback(e,t){this.fallbacks={onrequest:e,onupgrade:t}}};class i{constructor(e){this.serviceDirectory=e,this.services={}}async getRpc(e,t,r){const n=this.serviceDirectory[t];if(!n)throw new Error(`service not found: ${t}.${r}`);if(!((r=s.lcFirst(r))in n.rpcs))throw new Error(`method not found: ${t}.${r}`);let a=this.services[t];if(!a){if(a=n.factory(e),!a)throw new Error(`create service error: ${t}.${r}`);this.services[t]=a}const i=await a,o=i[r];if(!o)throw new Error(`method not implemented: ${t}.${r}`);const[l,u,c,h]=n.rpcs[r];return{requestDecode:l,responseEncode:u,requestStream:c,responseStream:h,exec:o.bind(i)}}}class o{constructor(e,t){e.endsWith("/")||(e+="/"),this.pathPrefix=e,this.caller=new i(t)}async handle(e,t){if("OPTIONS"==e.method)return void this._corsOptions(e,t);if("POST"!=e.method)throw new Error("http method not supported");const[r,s]=e.url.substr(this.pathPrefix.length).split("/");try{const n=await this.caller.getRpc(e,r,s);n.requestStream||n.responseStream?(t.statusCode=501,t.end()):await this.rpcUnaryUnary(e,t,n)}catch(e){t.statusCode=500,t.end(e.toString())}}_corsOptions(e,t){const r=e.headers.origin;if(!r)return t.writeHead(400),void t.end("no header: Origin");if(!e.headers["access-control-request-method"])return t.writeHead(400),void t.end("no header: Access-Control-Request-Method");let s=e.headers["access-control-request-headers"];s||(s="Authentication"),t.writeHead(204,{"Access-Control-Allow-Origin":r,"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Methods":"POST","Access-Control-Allow-Headers":s}),t.end()}_readRequestText(e){return new Promise(((t,r)=>{let s=[];e.on("error",(e=>{r(e)})).on("data",(e=>{s.push(e)})).on("end",(()=>{const e=Buffer.concat(s).toString();t(e)}))}))}async rpcUnaryUnary(e,t,r){if("application/json"!=e.headers["content-type"])throw new Error("codec not supported");const s=JSON.parse(await this._readRequestText(e)),n=await r.exec(s);t.setHeader("content-type","application/json"),t.end(JSON.stringify(n))}}class l{constructor(e,t,r){this.ws=e,this._calls=new Map,this._v="";const s=new i(r);e.onmessage=async e=>{let r=n.data.DataFrame.decode(new Uint8Array(e.data));if(!r.callID)return;if(!r.header&&!r.trailer&&!r.body){if(r=a.v1to2.tryDecodeDataFrame(new Uint8Array(e.data)),!r)return;if(this._v="v1",r.header){const e=r.callID,{service:i,method:o}=r.header;return this.ws.send(a.v1to2.encodeRequestOKResponse(e)),void this._calls.set(e,(async r=>{if(r&&r.body)try{const a=await s.getRpc(t,i,o);if(a.requestStream||a.responseStream)throw new Error("stream not implemented for v1 compatibility");await this.rpcUnaryUnary(r,a),this.sendMessage({callID:e,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})}catch(e){this.sendMessage({callID:r.callID,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:e.toString()}})}finally{this._calls.delete(e)}}))}}let i=this._calls.get(r.callID);if(i)i(r);else if(r.header){const{service:e,method:a}=r.header;try{const n=await s.getRpc(t,e,a);n.requestStream||n.responseStream?!n.requestStream&&n.responseStream?await this.rpcUnaryStream(r,n):n.requestStream&&!n.responseStream?await this.rpcStreamUnary(r,n):n.requestStream&&n.responseStream&&await this.rpcStreamStream(r,n):await this.rpcUnaryUnary(r,n)}catch(e){this.sendMessage({callID:r.callID,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:e.toString()}})}}else console.log("frame without header and callback:",r),console.log("this is a bug of client stream request")},e.onclose=()=>{this._calls.forEach((e=>e(null))),this._calls.clear()}}sendMessage(e){if(this.ws.readyState!=WebSocket.OPEN)return;if("v1"==this._v){const t=a.v1to2.encodeDataFrame(e);for(const e of t)this.ws.send(e);return}const t=n.data.DataFrame.encode(e);this.ws.send(t)}registerCall(e,t){this._calls.set(e,t)}async rpcUnaryUnary({callID:e,body:t},r){const s=r.requestDecode(t),a=await r.exec(s);this.sendMessage({callID:e,body:r.responseEncode(a),trailer:{status:n.data.DataFrame.Trailer.Status.OK}})}async rpcUnaryStream({callID:e,body:t},r){const a=r.requestDecode(t),i=new s.StreamDelegate;this.registerCall(e,(e=>{e?e.trailer&&e.trailer.status==n.data.DataFrame.Trailer.Status.ABORT&&i.abort(new Error(e.trailer.message)):i.abort(new Error("lost connection"))}));const o=await r.exec(a);i.bind(o),o.read((t=>{this.sendMessage({callID:e,body:r.responseEncode(t)})})).then((()=>{this.sendMessage({callID:e,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})})).catch((t=>{this.sendMessage({callID:e,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:t.toString()}})})).finally((()=>{this._calls.delete(e)}))}async rpcStreamStream({callID:e},t){const r=new s.Stream((t=>{this.sendMessage({callID:e,trailer:{status:n.data.DataFrame.Trailer.Status.ABORT,message:null==t?void 0:t.toString()}})})),a=new s.StreamDelegate,i=()=>{r.closed&&a.closed&&this._calls.delete(e)};this.registerCall(e,(e=>{if(e){if(e.body){const s=t.requestDecode(e.body);r.write(s)}e.trailer&&(e.trailer.status==n.data.DataFrame.Trailer.Status.OK?r.end():e.trailer.status==n.data.DataFrame.Trailer.Status.ERROR?r.error(new Error(e.trailer.message)):e.trailer.status==n.data.DataFrame.Trailer.Status.ABORT&&a.abort(new Error(e.trailer.message)),i())}else a.abort(new Error("lost connection"))}));const o=await t.exec(r);a.bind(o),o.read((r=>{this.sendMessage({callID:e,body:t.responseEncode(r)})})).then((()=>{this.sendMessage({callID:e,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})})).catch((t=>{this.sendMessage({callID:e,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:t.toString()}})})).finally(i)}async rpcStreamUnary({callID:e},t){const r=new s.Stream((t=>{this.sendMessage({callID:e,trailer:{status:n.data.DataFrame.Trailer.Status.ABORT,message:null==t?void 0:t.toString()}})}));this.registerCall(e,(s=>{if(console.log("request:",s),s){if(s.body){const e=t.requestDecode(s.body);r.write(e)}s.trailer&&(s.trailer.status==n.data.DataFrame.Trailer.Status.OK?r.end():s.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&r.error(new Error(s.trailer.message)),this._calls.delete(e))}}));const a=await t.exec(r);this.sendMessage({callID:e,body:t.responseEncode(a),trailer:{status:n.data.DataFrame.Trailer.Status.OK}})}}},87:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamDelegate=t.Stream=t.Future=t.lcFirst=void 0,t.lcFirst=function(e){return e[0].toLowerCase()+e.substr(1)};class r{constructor(){this._resolved=!1,this.promise=new Promise(((e,t)=>{this._resovle=e,this._reject=t}))}resolve(e){this._resolved=!0,this.result=e,this._resovle(e)}reject(e){this._resolved=!0,this.error=e,this._reject(e)}get resolved(){return this._resolved}}t.Future=r,t.Stream=class{constructor(e){this._onabort=e,this._readers=[],this._closed=!1,this._cache=[]}write(e){if(0==this._readers.length)return this._cache.push(e),void console.log("cache stream input");this._readers.forEach((t=>{t.onMessage(e)}))}error(e){this._closed=!0,0!=this._readers.length?(this._readers.forEach((t=>{t.future.reject(e)})),this._readers=[]):this._error=e}end(){this._closed=!0,this._readers.forEach((e=>{e.future.resolve()})),this._readers=[]}get closed(){return this._closed}abort(e){this._closed=!0,this._onabort&&this._onabort(e),this._readers.forEach((e=>{e.future.resolve()})),this._readers=[]}read(e){for(;this._cache.length>0;)e(this._cache.shift());if(this._closed)return this._error?Promise.reject(this._error):Promise.resolve();const t=new r,s={future:t,onMessage:e};return this._readers.push(s),t.promise}async*readToItorator(){const e=[];let t=new r;for(this.read((s=>{e.push(s),t.resolve(!1),t=new r})).then((()=>t.resolve(!0))).catch((e=>t.reject(e)));;){const r=e.shift();if(r)yield r;else if(await t.promise)return}}async writeFromIterator(e){try{for await(const t of e()){if(this._closed)return;this.write(t)}this.end()}catch(e){this.error(e)}}},t.StreamDelegate=class{bind(e){this.stream=e,this.abortReason&&this.stream.abort(this.abortReason)}abort(e){this.abortReason=e,this.stream&&this.stream.abort(this.abortReason)}get closed(){var e;return this.abortReason||(null===(e=this.stream)||void 0===e?void 0:e.closed)}}},836:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.data=void 0;const s=r(100);!function(e){let t;!function(e){let t,r;!function(e){e.encode=function(e,t){const r=!t;return t||(t=s.Writer.create()),null!=e.path&&null!=e.path&&t.uint32(10).string(e.path),null!=e.status&&null!=e.status&&t.uint32(18).string(e.status),null!=e.rpcStatus&&null!=e.rpcStatus&&t.uint32(26).string(e.rpcStatus),null!=e.rpcMessage&&null!=e.rpcMessage&&t.uint32(34).string(e.rpcMessage),r?t.finish():t},e.decode=function(e,t){e instanceof s.Reader||(e=s.Reader.create(e));let r=void 0===t?e.len:e.pos+t;const n={};for(;e.pos<r;){let t=e.uint32();switch(t>>>3){case 1:n.path=e.string();break;case 2:n.status=e.string();break;case 3:n.rpcStatus=e.string();break;case 4:n.rpcMessage=e.string();break;default:e.skipType(7&t)}}return n}}(t=e.Headers||(e.Headers={})),function(e){e.encode=function(e,t){const r=!t;return t||(t=s.Writer.create()),null!=e.path&&null!=e.path&&t.uint32(10).string(e.path),null!=e.status&&null!=e.status&&t.uint32(18).string(e.status),null!=e.rpcStatus&&null!=e.rpcStatus&&t.uint32(26).string(e.rpcStatus),null!=e.rpcMessage&&null!=e.rpcMessage&&t.uint32(34).string(e.rpcMessage),r?t.finish():t},e.decode=function(e,t){e instanceof s.Reader||(e=s.Reader.create(e));let r=void 0===t?e.len:e.pos+t;const n={};for(;e.pos<r;){let t=e.uint32();switch(t>>>3){case 1:n.path=e.string();break;case 2:n.status=e.string();break;case 3:n.rpcStatus=e.string();break;case 4:n.rpcMessage=e.string();break;default:e.skipType(7&t)}}return n}}(r=e.Trailers||(e.Trailers={})),e.Types={HEADERS:1,TRAILERS:2,MESSAGE:3},e.encode=function(e,n){const a=!n;return n||(n=s.Writer.create()),null!=e.streamId&&null!=e.streamId&&n.uint32(8).int32(e.streamId),null!=e.endStream&&null!=e.endStream&&n.uint32(16).bool(e.endStream),null!=e.type&&null!=e.type&&n.uint32(24).int32(e.type),null!=e.headers&&null!=e.headers&&t.encode(e.headers,n.uint32(34).fork()).ldelim(),null!=e.trailers&&null!=e.trailers&&r.encode(e.trailers,n.uint32(42).fork()).ldelim(),null!=e.message&&null!=e.message&&n.uint32(50).bytes(e.message),a?n.finish():n},e.decode=function(e,n){e instanceof s.Reader||(e=s.Reader.create(e));let a=void 0===n?e.len:e.pos+n;const i={};for(;e.pos<a;){let s=e.uint32();switch(s>>>3){case 1:i.streamId=e.int32();break;case 2:i.endStream=e.bool();break;case 3:i.type=e.int32();break;case 4:i.headers=t.decode(e,e.uint32());break;case 5:i.trailers=r.decode(e,e.uint32());break;case 6:i.message=e.bytes();break;default:e.skipType(7&s)}}return i}}(t=e.DataFrame||(e.DataFrame={}))}(t.data||(t.data={}))},615:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.v1to2=void 0;const s=r(795),n=r(836);t.v1to2={tryDecodeDataFrame:function(e){var t;const r=n.data.DataFrame.decode(e);if(r.type==n.data.DataFrame.Types.HEADERS&&r.headers){if(r.endStream)return{callID:r.streamId,body:r.message,trailer:{status:"0"==r.headers.rpcStatus?s.data.DataFrame.Trailer.Status.OK:s.data.DataFrame.Trailer.Status.ERROR,message:r.headers.rpcMessage}};{const[e,s]=null===(t=r.headers.path)||void 0===t?void 0:t.substr(1).split("/");return{callID:r.streamId,body:r.message,header:{service:e,method:s}}}}return r.type==n.data.DataFrame.Types.TRAILERS?null:r.type==n.data.DataFrame.Types.MESSAGE&&r.message?{callID:r.streamId,body:r.message}:null},encodeDataFrame:function(e){var t;const r=[];return e.header&&r.push({streamId:e.callID,type:n.data.DataFrame.Types.HEADERS,endStream:!1,headers:{path:`.${e.header.service}/${e.header.method}`}}),e.body&&r.push({streamId:e.callID,type:n.data.DataFrame.Types.MESSAGE,endStream:!1,message:e.body}),e.trailer&&(e.trailer.status==s.data.DataFrame.Trailer.Status.OK?r.push({streamId:e.callID,type:n.data.DataFrame.Types.HEADERS,endStream:!0,headers:{status:"200",rpcStatus:"0",rpcMessage:"Finish"}}):r.push({streamId:e.callID,type:n.data.DataFrame.Types.HEADERS,endStream:!0,headers:{status:"400",rpcStatus:null===(t=e.trailer.status)||void 0===t?void 0:t.toString(),rpcMessage:e.trailer.message}})),r.map((e=>n.data.DataFrame.encode(e)))},encodeRequestOKResponse:function(e){return n.data.DataFrame.encode({streamId:e,type:n.data.DataFrame.Types.HEADERS,endStream:!1,headers:{status:"200"}})}}}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e].call(r.exports,r,r.exports,__webpack_require__),r.exports}var __webpack_exports__={};return(()=>{var e=__webpack_exports__;Object.defineProperty(e,"__esModule",{value:!0}),e.Server=e.Channel=e.Future=e.Stream=e.Reader=e.Writer=void 0,__webpack_require__(693).Long=null;var t=__webpack_require__(100);Object.defineProperty(e,"Writer",{enumerable:!0,get:function(){return t.Writer}}),Object.defineProperty(e,"Reader",{enumerable:!0,get:function(){return t.Reader}});var r=__webpack_require__(87);Object.defineProperty(e,"Stream",{enumerable:!0,get:function(){return r.Stream}}),Object.defineProperty(e,"Future",{enumerable:!0,get:function(){return r.Future}});var s=__webpack_require__(110);Object.defineProperty(e,"Channel",{enumerable:!0,get:function(){return s.Channel}});var n=__webpack_require__(728);Object.defineProperty(e,"Server",{enumerable:!0,get:function(){return n.Server}})})(),__webpack_exports__})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.wsgrpc=e():t.wsgrpc=e()}(global,(function(){return(()=>{"use strict";var __webpack_modules__={537:t=>{t.exports=function(t,e){for(var r=new Array(arguments.length-1),s=0,n=2,a=!0;n<arguments.length;)r[s++]=arguments[n++];return new Promise((function(n,i){r[s]=function(t){if(a)if(a=!1,t)i(t);else{for(var e=new Array(arguments.length-1),r=0;r<e.length;)e[r++]=arguments[r];n.apply(null,e)}};try{t.apply(e||null,r)}catch(t){a&&(a=!1,i(t))}}))}},419:(t,e)=>{var r=e;r.length=function(t){var e=t.length;if(!e)return 0;for(var r=0;--e%4>1&&"="===t.charAt(e);)++r;return Math.ceil(3*t.length)/4-r};for(var s=new Array(64),n=new Array(123),a=0;a<64;)n[s[a]=a<26?a+65:a<52?a+71:a<62?a-4:a-59|43]=a++;r.encode=function(t,e,r){for(var n,a=null,i=[],o=0,l=0;e<r;){var u=t[e++];switch(l){case 0:i[o++]=s[u>>2],n=(3&u)<<4,l=1;break;case 1:i[o++]=s[n|u>>4],n=(15&u)<<2,l=2;break;case 2:i[o++]=s[n|u>>6],i[o++]=s[63&u],l=0}o>8191&&((a||(a=[])).push(String.fromCharCode.apply(String,i)),o=0)}return l&&(i[o++]=s[n],i[o++]=61,1===l&&(i[o++]=61)),a?(o&&a.push(String.fromCharCode.apply(String,i.slice(0,o))),a.join("")):String.fromCharCode.apply(String,i.slice(0,o))};var i="invalid encoding";r.decode=function(t,e,r){for(var s,a=r,o=0,l=0;l<t.length;){var u=t.charCodeAt(l++);if(61===u&&o>1)break;if(void 0===(u=n[u]))throw Error(i);switch(o){case 0:s=u,o=1;break;case 1:e[r++]=s<<2|(48&u)>>4,s=u,o=2;break;case 2:e[r++]=(15&s)<<4|(60&u)>>2,s=u,o=3;break;case 3:e[r++]=(3&s)<<6|u,o=0}}if(1===o)throw Error(i);return r-a},r.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}},211:t=>{function e(){this._listeners={}}t.exports=e,e.prototype.on=function(t,e,r){return(this._listeners[t]||(this._listeners[t]=[])).push({fn:e,ctx:r||this}),this},e.prototype.off=function(t,e){if(void 0===t)this._listeners={};else if(void 0===e)this._listeners[t]=[];else for(var r=this._listeners[t],s=0;s<r.length;)r[s].fn===e?r.splice(s,1):++s;return this},e.prototype.emit=function(t){var e=this._listeners[t];if(e){for(var r=[],s=1;s<arguments.length;)r.push(arguments[s++]);for(s=0;s<e.length;)e[s].fn.apply(e[s++].ctx,r)}return this}},945:t=>{function e(t){return"undefined"!=typeof Float32Array?function(){var e=new Float32Array([-0]),r=new Uint8Array(e.buffer),s=128===r[3];function n(t,s,n){e[0]=t,s[n]=r[0],s[n+1]=r[1],s[n+2]=r[2],s[n+3]=r[3]}function a(t,s,n){e[0]=t,s[n]=r[3],s[n+1]=r[2],s[n+2]=r[1],s[n+3]=r[0]}function i(t,s){return r[0]=t[s],r[1]=t[s+1],r[2]=t[s+2],r[3]=t[s+3],e[0]}function o(t,s){return r[3]=t[s],r[2]=t[s+1],r[1]=t[s+2],r[0]=t[s+3],e[0]}t.writeFloatLE=s?n:a,t.writeFloatBE=s?a:n,t.readFloatLE=s?i:o,t.readFloatBE=s?o:i}():function(){function e(t,e,r,s){var n=e<0?1:0;if(n&&(e=-e),0===e)t(1/e>0?0:2147483648,r,s);else if(isNaN(e))t(2143289344,r,s);else if(e>34028234663852886e22)t((n<<31|2139095040)>>>0,r,s);else if(e<11754943508222875e-54)t((n<<31|Math.round(e/1401298464324817e-60))>>>0,r,s);else{var a=Math.floor(Math.log(e)/Math.LN2);t((n<<31|a+127<<23|8388607&Math.round(e*Math.pow(2,-a)*8388608))>>>0,r,s)}}function i(t,e,r){var s=t(e,r),n=2*(s>>31)+1,a=s>>>23&255,i=8388607&s;return 255===a?i?NaN:n*(1/0):0===a?1401298464324817e-60*n*i:n*Math.pow(2,a-150)*(i+8388608)}t.writeFloatLE=e.bind(null,r),t.writeFloatBE=e.bind(null,s),t.readFloatLE=i.bind(null,n),t.readFloatBE=i.bind(null,a)}(),"undefined"!=typeof Float64Array?function(){var e=new Float64Array([-0]),r=new Uint8Array(e.buffer),s=128===r[7];function n(t,s,n){e[0]=t,s[n]=r[0],s[n+1]=r[1],s[n+2]=r[2],s[n+3]=r[3],s[n+4]=r[4],s[n+5]=r[5],s[n+6]=r[6],s[n+7]=r[7]}function a(t,s,n){e[0]=t,s[n]=r[7],s[n+1]=r[6],s[n+2]=r[5],s[n+3]=r[4],s[n+4]=r[3],s[n+5]=r[2],s[n+6]=r[1],s[n+7]=r[0]}function i(t,s){return r[0]=t[s],r[1]=t[s+1],r[2]=t[s+2],r[3]=t[s+3],r[4]=t[s+4],r[5]=t[s+5],r[6]=t[s+6],r[7]=t[s+7],e[0]}function o(t,s){return r[7]=t[s],r[6]=t[s+1],r[5]=t[s+2],r[4]=t[s+3],r[3]=t[s+4],r[2]=t[s+5],r[1]=t[s+6],r[0]=t[s+7],e[0]}t.writeDoubleLE=s?n:a,t.writeDoubleBE=s?a:n,t.readDoubleLE=s?i:o,t.readDoubleBE=s?o:i}():function(){function e(t,e,r,s,n,a){var i=s<0?1:0;if(i&&(s=-s),0===s)t(0,n,a+e),t(1/s>0?0:2147483648,n,a+r);else if(isNaN(s))t(0,n,a+e),t(2146959360,n,a+r);else if(s>17976931348623157e292)t(0,n,a+e),t((i<<31|2146435072)>>>0,n,a+r);else{var o;if(s<22250738585072014e-324)t((o=s/5e-324)>>>0,n,a+e),t((i<<31|o/4294967296)>>>0,n,a+r);else{var l=Math.floor(Math.log(s)/Math.LN2);1024===l&&(l=1023),t(4503599627370496*(o=s*Math.pow(2,-l))>>>0,n,a+e),t((i<<31|l+1023<<20|1048576*o&1048575)>>>0,n,a+r)}}}function i(t,e,r,s,n){var a=t(s,n+e),i=t(s,n+r),o=2*(i>>31)+1,l=i>>>20&2047,u=4294967296*(1048575&i)+a;return 2047===l?u?NaN:o*(1/0):0===l?5e-324*o*u:o*Math.pow(2,l-1075)*(u+4503599627370496)}t.writeDoubleLE=e.bind(null,r,0,4),t.writeDoubleBE=e.bind(null,s,4,0),t.readDoubleLE=i.bind(null,n,0,4),t.readDoubleBE=i.bind(null,a,4,0)}(),t}function r(t,e,r){e[r]=255&t,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function s(t,e,r){e[r]=t>>>24,e[r+1]=t>>>16&255,e[r+2]=t>>>8&255,e[r+3]=255&t}function n(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0}function a(t,e){return(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}t.exports=e(e)},199:module=>{function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(t){}return null}module.exports=inquire},662:t=>{t.exports=function(t,e,r){var s=r||8192,n=s>>>1,a=null,i=s;return function(r){if(r<1||r>n)return t(r);i+r>s&&(a=t(s),i=0);var o=e.call(a,i,i+=r);return 7&i&&(i=1+(7|i)),o}}},997:(t,e)=>{var r=e;r.length=function(t){for(var e=0,r=0,s=0;s<t.length;++s)(r=t.charCodeAt(s))<128?e+=1:r<2048?e+=2:55296==(64512&r)&&56320==(64512&t.charCodeAt(s+1))?(++s,e+=4):e+=3;return e},r.read=function(t,e,r){if(r-e<1)return"";for(var s,n=null,a=[],i=0;e<r;)(s=t[e++])<128?a[i++]=s:s>191&&s<224?a[i++]=(31&s)<<6|63&t[e++]:s>239&&s<365?(s=((7&s)<<18|(63&t[e++])<<12|(63&t[e++])<<6|63&t[e++])-65536,a[i++]=55296+(s>>10),a[i++]=56320+(1023&s)):a[i++]=(15&s)<<12|(63&t[e++])<<6|63&t[e++],i>8191&&((n||(n=[])).push(String.fromCharCode.apply(String,a)),i=0);return n?(i&&n.push(String.fromCharCode.apply(String,a.slice(0,i))),n.join("")):String.fromCharCode.apply(String,a.slice(0,i))},r.write=function(t,e,r){for(var s,n,a=r,i=0;i<t.length;++i)(s=t.charCodeAt(i))<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=63&s|128):55296==(64512&s)&&56320==(64512&(n=t.charCodeAt(i+1)))?(s=65536+((1023&s)<<10)+(1023&n),++i,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=63&s|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=63&s|128);return r-a}},100:(t,e,r)=>{t.exports=r(482)},482:(t,e,r)=>{var s=e;function n(){s.util._configure(),s.Writer._configure(s.BufferWriter),s.Reader._configure(s.BufferReader)}s.build="minimal",s.Writer=r(173),s.BufferWriter=r(155),s.Reader=r(408),s.BufferReader=r(593),s.util=r(693),s.rpc=r(994),s.roots=r(54),s.configure=n,n()},408:(t,e,r)=>{t.exports=l;var s,n=r(693),a=n.LongBits,i=n.utf8;function o(t,e){return RangeError("index out of range: "+t.pos+" + "+(e||1)+" > "+t.len)}function l(t){this.buf=t,this.pos=0,this.len=t.length}var u,c="undefined"!=typeof Uint8Array?function(t){if(t instanceof Uint8Array||Array.isArray(t))return new l(t);throw Error("illegal buffer")}:function(t){if(Array.isArray(t))return new l(t);throw Error("illegal buffer")},h=function(){return n.Buffer?function(t){return(l.create=function(t){return n.Buffer.isBuffer(t)?new s(t):c(t)})(t)}:c};function f(){var t=new a(0,0),e=0;if(!(this.len-this.pos>4)){for(;e<3;++e){if(this.pos>=this.len)throw o(this);if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*e)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(127&this.buf[this.pos++])<<7*e)>>>0,t}for(;e<4;++e)if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*e)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(127&this.buf[this.pos])<<28)>>>0,t.hi=(t.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return t;if(e=0,this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*e+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw o(this);if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*e+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}function d(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}function p(){if(this.pos+8>this.len)throw o(this,8);return new a(d(this.buf,this.pos+=4),d(this.buf,this.pos+=4))}l.create=h(),l.prototype._slice=n.Array.prototype.subarray||n.Array.prototype.slice,l.prototype.uint32=(u=4294967295,function(){if(u=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return u;if(u=(u|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return u;if(u=(u|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return u;if(u=(u|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return u;if(u=(u|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return u;if((this.pos+=5)>this.len)throw this.pos=this.len,o(this,10);return u}),l.prototype.int32=function(){return 0|this.uint32()},l.prototype.sint32=function(){var t=this.uint32();return t>>>1^-(1&t)|0},l.prototype.bool=function(){return 0!==this.uint32()},l.prototype.fixed32=function(){if(this.pos+4>this.len)throw o(this,4);return d(this.buf,this.pos+=4)},l.prototype.sfixed32=function(){if(this.pos+4>this.len)throw o(this,4);return 0|d(this.buf,this.pos+=4)},l.prototype.float=function(){if(this.pos+4>this.len)throw o(this,4);var t=n.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t},l.prototype.double=function(){if(this.pos+8>this.len)throw o(this,4);var t=n.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t},l.prototype.bytes=function(){var t=this.uint32(),e=this.pos,r=this.pos+t;if(r>this.len)throw o(this,t);return this.pos+=t,Array.isArray(this.buf)?this.buf.slice(e,r):e===r?new this.buf.constructor(0):this._slice.call(this.buf,e,r)},l.prototype.string=function(){var t=this.bytes();return i.read(t,0,t.length)},l.prototype.skip=function(t){if("number"==typeof t){if(this.pos+t>this.len)throw o(this,t);this.pos+=t}else do{if(this.pos>=this.len)throw o(this)}while(128&this.buf[this.pos++]);return this},l.prototype.skipType=function(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(t=7&this.uint32());)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+t+" at offset "+this.pos)}return this},l._configure=function(t){s=t,l.create=h(),s._configure();var e=n.Long?"toLong":"toNumber";n.merge(l.prototype,{int64:function(){return f.call(this)[e](!1)},uint64:function(){return f.call(this)[e](!0)},sint64:function(){return f.call(this).zzDecode()[e](!1)},fixed64:function(){return p.call(this)[e](!0)},sfixed64:function(){return p.call(this)[e](!1)}})}},593:(t,e,r)=>{t.exports=a;var s=r(408);(a.prototype=Object.create(s.prototype)).constructor=a;var n=r(693);function a(t){s.call(this,t)}a._configure=function(){n.Buffer&&(a.prototype._slice=n.Buffer.prototype.slice)},a.prototype.string=function(){var t=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+t,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+t,this.len))},a._configure()},54:t=>{t.exports={}},994:(t,e,r)=>{e.Service=r(948)},948:(t,e,r)=>{t.exports=n;var s=r(693);function n(t,e,r){if("function"!=typeof t)throw TypeError("rpcImpl must be a function");s.EventEmitter.call(this),this.rpcImpl=t,this.requestDelimited=Boolean(e),this.responseDelimited=Boolean(r)}(n.prototype=Object.create(s.EventEmitter.prototype)).constructor=n,n.prototype.rpcCall=function t(e,r,n,a,i){if(!a)throw TypeError("request must be specified");var o=this;if(!i)return s.asPromise(t,o,e,r,n,a);if(o.rpcImpl)try{return o.rpcImpl(e,r[o.requestDelimited?"encodeDelimited":"encode"](a).finish(),(function(t,r){if(t)return o.emit("error",t,e),i(t);if(null!==r){if(!(r instanceof n))try{r=n[o.responseDelimited?"decodeDelimited":"decode"](r)}catch(t){return o.emit("error",t,e),i(t)}return o.emit("data",r,e),i(null,r)}o.end(!0)}))}catch(t){return o.emit("error",t,e),void setTimeout((function(){i(t)}),0)}else setTimeout((function(){i(Error("already ended"))}),0)},n.prototype.end=function(t){return this.rpcImpl&&(t||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},630:(t,e,r)=>{t.exports=n;var s=r(693);function n(t,e){this.lo=t>>>0,this.hi=e>>>0}var a=n.zero=new n(0,0);a.toNumber=function(){return 0},a.zzEncode=a.zzDecode=function(){return this},a.length=function(){return 1};var i=n.zeroHash="\0\0\0\0\0\0\0\0";n.fromNumber=function(t){if(0===t)return a;var e=t<0;e&&(t=-t);var r=t>>>0,s=(t-r)/4294967296>>>0;return e&&(s=~s>>>0,r=~r>>>0,++r>4294967295&&(r=0,++s>4294967295&&(s=0))),new n(r,s)},n.from=function(t){if("number"==typeof t)return n.fromNumber(t);if(s.isString(t)){if(!s.Long)return n.fromNumber(parseInt(t,10));t=s.Long.fromString(t)}return t.low||t.high?new n(t.low>>>0,t.high>>>0):a},n.prototype.toNumber=function(t){if(!t&&this.hi>>>31){var e=1+~this.lo>>>0,r=~this.hi>>>0;return e||(r=r+1>>>0),-(e+4294967296*r)}return this.lo+4294967296*this.hi},n.prototype.toLong=function(t){return s.Long?new s.Long(0|this.lo,0|this.hi,Boolean(t)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(t)}};var o=String.prototype.charCodeAt;n.fromHash=function(t){return t===i?a:new n((o.call(t,0)|o.call(t,1)<<8|o.call(t,2)<<16|o.call(t,3)<<24)>>>0,(o.call(t,4)|o.call(t,5)<<8|o.call(t,6)<<16|o.call(t,7)<<24)>>>0)},n.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},n.prototype.zzEncode=function(){var t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this},n.prototype.zzDecode=function(){var t=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this},n.prototype.length=function(){var t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,r=this.hi>>>24;return 0===r?0===e?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:r<128?9:10}},693:function(t,e,r){var s=e;function n(t,e,r){for(var s=Object.keys(e),n=0;n<s.length;++n)void 0!==t[s[n]]&&r||(t[s[n]]=e[s[n]]);return t}function a(t){function e(t,r){if(!(this instanceof e))return new e(t,r);Object.defineProperty(this,"message",{get:function(){return t}}),Error.captureStackTrace?Error.captureStackTrace(this,e):Object.defineProperty(this,"stack",{value:(new Error).stack||""}),r&&n(this,r)}return(e.prototype=Object.create(Error.prototype)).constructor=e,Object.defineProperty(e.prototype,"name",{get:function(){return t}}),e.prototype.toString=function(){return this.name+": "+this.message},e}s.asPromise=r(537),s.base64=r(419),s.EventEmitter=r(211),s.float=r(945),s.inquire=r(199),s.utf8=r(997),s.pool=r(662),s.LongBits=r(630),s.isNode=Boolean("undefined"!=typeof global&&global&&global.process&&global.process.versions&&global.process.versions.node),s.global=s.isNode&&global||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||this,s.emptyArray=Object.freeze?Object.freeze([]):[],s.emptyObject=Object.freeze?Object.freeze({}):{},s.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},s.isString=function(t){return"string"==typeof t||t instanceof String},s.isObject=function(t){return t&&"object"==typeof t},s.isset=s.isSet=function(t,e){var r=t[e];return!(null==r||!t.hasOwnProperty(e))&&("object"!=typeof r||(Array.isArray(r)?r.length:Object.keys(r).length)>0)},s.Buffer=function(){try{var t=s.inquire("buffer").Buffer;return t.prototype.utf8Write?t:null}catch(t){return null}}(),s._Buffer_from=null,s._Buffer_allocUnsafe=null,s.newBuffer=function(t){return"number"==typeof t?s.Buffer?s._Buffer_allocUnsafe(t):new s.Array(t):s.Buffer?s._Buffer_from(t):"undefined"==typeof Uint8Array?t:new Uint8Array(t)},s.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,s.Long=s.global.dcodeIO&&s.global.dcodeIO.Long||s.global.Long||s.inquire("long"),s.key2Re=/^true|false|0|1$/,s.key32Re=/^-?(?:0|[1-9][0-9]*)$/,s.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,s.longToHash=function(t){return t?s.LongBits.from(t).toHash():s.LongBits.zeroHash},s.longFromHash=function(t,e){var r=s.LongBits.fromHash(t);return s.Long?s.Long.fromBits(r.lo,r.hi,e):r.toNumber(Boolean(e))},s.merge=n,s.lcFirst=function(t){return t.charAt(0).toLowerCase()+t.substring(1)},s.newError=a,s.ProtocolError=a("ProtocolError"),s.oneOfGetter=function(t){for(var e={},r=0;r<t.length;++r)e[t[r]]=1;return function(){for(var t=Object.keys(this),r=t.length-1;r>-1;--r)if(1===e[t[r]]&&void 0!==this[t[r]]&&null!==this[t[r]])return t[r]}},s.oneOfSetter=function(t){return function(e){for(var r=0;r<t.length;++r)t[r]!==e&&delete this[t[r]]}},s.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},s._configure=function(){var t=s.Buffer;t?(s._Buffer_from=t.from!==Uint8Array.from&&t.from||function(e,r){return new t(e,r)},s._Buffer_allocUnsafe=t.allocUnsafe||function(e){return new t(e)}):s._Buffer_from=s._Buffer_allocUnsafe=null}},173:(t,e,r)=>{t.exports=h;var s,n=r(693),a=n.LongBits,i=n.base64,o=n.utf8;function l(t,e,r){this.fn=t,this.len=e,this.next=void 0,this.val=r}function u(){}function c(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}function h(){this.len=0,this.head=new l(u,0,0),this.tail=this.head,this.states=null}var f=function(){return n.Buffer?function(){return(h.create=function(){return new s})()}:function(){return new h}};function d(t,e,r){e[r]=255&t}function p(t,e){this.len=t,this.next=void 0,this.val=e}function y(t,e,r){for(;t.hi;)e[r++]=127&t.lo|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=127&t.lo|128,t.lo=t.lo>>>7;e[r++]=t.lo}function m(t,e,r){e[r]=255&t,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}h.create=f(),h.alloc=function(t){return new n.Array(t)},n.Array!==Array&&(h.alloc=n.pool(h.alloc,n.Array.prototype.subarray)),h.prototype._push=function(t,e,r){return this.tail=this.tail.next=new l(t,e,r),this.len+=e,this},p.prototype=Object.create(l.prototype),p.prototype.fn=function(t,e,r){for(;t>127;)e[r++]=127&t|128,t>>>=7;e[r]=t},h.prototype.uint32=function(t){return this.len+=(this.tail=this.tail.next=new p((t>>>=0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this},h.prototype.int32=function(t){return t<0?this._push(y,10,a.fromNumber(t)):this.uint32(t)},h.prototype.sint32=function(t){return this.uint32((t<<1^t>>31)>>>0)},h.prototype.uint64=function(t){var e=a.from(t);return this._push(y,e.length(),e)},h.prototype.int64=h.prototype.uint64,h.prototype.sint64=function(t){var e=a.from(t).zzEncode();return this._push(y,e.length(),e)},h.prototype.bool=function(t){return this._push(d,1,t?1:0)},h.prototype.fixed32=function(t){return this._push(m,4,t>>>0)},h.prototype.sfixed32=h.prototype.fixed32,h.prototype.fixed64=function(t){var e=a.from(t);return this._push(m,4,e.lo)._push(m,4,e.hi)},h.prototype.sfixed64=h.prototype.fixed64,h.prototype.float=function(t){return this._push(n.float.writeFloatLE,4,t)},h.prototype.double=function(t){return this._push(n.float.writeDoubleLE,8,t)};var g=n.Array.prototype.set?function(t,e,r){e.set(t,r)}:function(t,e,r){for(var s=0;s<t.length;++s)e[r+s]=t[s]};h.prototype.bytes=function(t){var e=t.length>>>0;if(!e)return this._push(d,1,0);if(n.isString(t)){var r=h.alloc(e=i.length(t));i.decode(t,r,0),t=r}return this.uint32(e)._push(g,e,t)},h.prototype.string=function(t){var e=o.length(t);return e?this.uint32(e)._push(o.write,e,t):this._push(d,1,0)},h.prototype.fork=function(){return this.states=new c(this),this.head=this.tail=new l(u,0,0),this.len=0,this},h.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new l(u,0,0),this.len=0),this},h.prototype.ldelim=function(){var t=this.head,e=this.tail,r=this.len;return this.reset().uint32(r),r&&(this.tail.next=t.next,this.tail=e,this.len+=r),this},h.prototype.finish=function(){for(var t=this.head.next,e=this.constructor.alloc(this.len),r=0;t;)t.fn(t.val,e,r),r+=t.len,t=t.next;return e},h._configure=function(t){s=t,h.create=f(),s._configure()}},155:(t,e,r)=>{t.exports=a;var s=r(173);(a.prototype=Object.create(s.prototype)).constructor=a;var n=r(693);function a(){s.call(this)}function i(t,e,r){t.length<40?n.utf8.write(t,e,r):e.utf8Write?e.utf8Write(t,r):e.write(t,r)}a._configure=function(){a.alloc=n._Buffer_allocUnsafe,a.writeBytesBuffer=n.Buffer&&n.Buffer.prototype instanceof Uint8Array&&"set"===n.Buffer.prototype.set.name?function(t,e,r){e.set(t,r)}:function(t,e,r){if(t.copy)t.copy(e,r,0,t.length);else for(var s=0;s<t.length;)e[r++]=t[s++]}},a.prototype.bytes=function(t){n.isString(t)&&(t=n._Buffer_from(t,"base64"));var e=t.length>>>0;return this.uint32(e),e&&this._push(a.writeBytesBuffer,e,t),this},a.prototype.string=function(t){var e=n.Buffer.byteLength(t);return this.uint32(e),e&&this._push(i,e,t),this},a._configure()},110:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Channel=void 0;const s=r(212),n=r(195);e.Channel=class{constructor(t,e){this.reset(t,e)}onCall(t){this.callback=t}reset(t,e){var r;if(null===(r=this.agent)||void 0===r||r.reset(),t.startsWith("http:")||t.startsWith("https:")){const r=function({contentType:t,authorizationToken:e}){let r={};return t&&(r["Content-Type"]=`application/${t}`),e&&(r.Authorization=`Bearer ${e}`),r}(e||{});this.agent=new n.HttpAgent(t,r)}else{if(!t.startsWith("ws:")&&!t.startsWith("wss:"))throw new Error("channel url not supported: "+t);this.agent=new s.WebSocketAgent(t)}}async rpcUnaryUnary(t,e,r,s,n){const a=await this.agent.getConnection();return await a.rpcUnaryUnary(t,e,r,s,n).then((t=>(this.callback&&this.callback(n,t),t)),(t=>{throw this.callback&&this.callback(n,null,t),t}))}async rpcUnaryStream(t,e,r,s,n){const a=await this.agent.getConnection();return await a.rpcUnaryStream(t,e,r,s,n)}async rpcStreamStream(t,e,r,s,n){const a=await this.agent.getConnection();return await a.rpcStreamStream(t,e,r,s,n)}async rpcStreamUnary(t,e,r,s,n){const a=await this.agent.getConnection();return await a.rpcStreamUnary(t,e,r,s,n).then((t=>(this.callback&&this.callback(n,t),t)),(t=>{throw this.callback&&this.callback(n,null,t),t}))}}},195:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.HttpAgent=void 0,e.HttpAgent=class{constructor(t,e){this.url=t+(t.endsWith("/")?"":"/"),e||(e={}),e["Content-Type"]||(e["Content-Type"]="application/grpc-web"),this.metadata=e}getConnection(){return this}reset(){}async rpcUnaryUnary(t,e,i,o,l){var u,c;const h=this.metadata["Content-Type"];let f;if("application/grpc-web"==h||"application/grpc-web+proto"==h)f=function(t){for(var e=t.length,r=[0,0,0,0],s=new Uint8Array(5+e),n=3;n>=0;n--)r[n]=e%256,e>>>=8;return s.set(new Uint8Array(r),1),s.set(t,5),s}(i(l));else if("application/grpc"==h)f=i(l);else{if("application/json"!=h)throw new Error(`Unknown Content-type to use. ${h}`);f=JSON.stringify(l)}const d=this.url+t+"/"+e,p=await fetch(d,{method:"POST",body:f,headers:this.metadata}),y=p.headers.get("Content-Type");if("application/grpc-web+proto"===y||"application/grpc-web"===y){const t=function(t){const e={messages:[],trailer:null};let i=new Uint8Array(t);for(;i.length;){const t=i[0],o=i[1]<<24|i[2]<<16|i[3]<<8|i[4],l=i.slice(5,5+o);if(i=i.subarray(5+o),t==n)e.messages.push(l);else if(t==a){const t={code:0,message:"",metadata:{}};new TextDecoder("utf-8").decode(l).trim().split("\r\n").map((t=>t.split(": ",2))).map((([t,e])=>[t.toLowerCase(),e])).forEach((([e,n])=>{e==r?t.code=Number(n):e==s?t.message=n:t.metadata[e]=n})),e.trailer=t}}return e}(await p.arrayBuffer()),e=null===(u=t.trailer)||void 0===u?void 0:u.code,i=null===(c=t.trailer)||void 0===c?void 0:c.metadata;if(0!=e)throw new Error(i);return o(t.messages[0])}if("application/grpc"===y){const t=await p.arrayBuffer(),e=Number(p.headers.get(r)),n=p.headers.get(s);if(0!=e)throw new Error(n);return o(new Uint8Array(t))}if("application/json"===y){const t=Number(p.headers.get(r)),e=p.headers.get(s);if(0!=t)throw new Error(e);return await p.json()}throw new Error(`Unknown Content-type received. ${y}`)}rpcUnaryStream(t,e,r,s,n){throw new Error("method not supported")}rpcStreamStream(t,e,r,s,n){throw new Error("method not supported")}rpcStreamUnary(t,e,r,s,n){throw new Error("method not supported")}};const r="grpc-status",s="grpc-message",n=0,a=128},212:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.WebSocketAgent=void 0;const s=r(87),n=r(795);e.WebSocketAgent=class{constructor(t){this.url=t,this.connectionFuture=null}async getConnection(){var t;if((null===(t=this.connectionFuture)||void 0===t?void 0:t.resolved)&&(this.connectionFuture.result?1!=this.connectionFuture.result.ws.readyState&&(this.connectionFuture=null):this.connectionFuture=null),!this.connectionFuture){const t=new s.Future,e=new WebSocket(this.url);e.binaryType="arraybuffer",e.onopen=()=>{t.resolve(new a(e))},e.onclose=e=>{t.reject(e)},this.connectionFuture=t}return await this.connectionFuture.promise}reset(){var t;(null===(t=this.connectionFuture)||void 0===t?void 0:t.result)&&1==this.connectionFuture.result.ws.readyState&&this.connectionFuture.result.ws.close(),this.connectionFuture=null}};class a{constructor(t){this.ws=t,this._nextCallID=1,this._calls=new Map,t.onmessage=t=>{let e=n.data.DataFrame.decode(new Uint8Array(t.data)),r=this._calls.get(e.callID);r&&r(e)},t.onclose=()=>{t.onopen=null,t.onmessage=null,t.onerror=null,t.onclose=null,console.log("calls:",this._calls),this._calls.forEach((t=>t(null))),this._calls.clear()}}registerCall(t){const e=this._nextCallID;return this._calls.set(e,t),this._nextCallID+=2,e}sendMessage(t){if(1!=this.ws.readyState)return;const e=n.data.DataFrame.encode(t);"undefined"!=typeof window&&window.wx?this.ws.send(e.buffer.slice(e.byteOffset,e.byteOffset+e.length)):this.ws.send(e)}rpcUnaryUnary(t,e,r,a,i){const o=new s.Future,l=this.registerCall((t=>{if(t)if(this._calls.delete(l),t.body){const e=a(t.body);o.resolve(e)}else t.trailer&&t.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&o.reject(new Error(t.trailer.message));else o.reject(new Error("lost connection"))})),u=r(i);return this.sendMessage({callID:l,header:{service:t,method:e},body:u}),o.promise}async rpcUnaryStream(t,e,r,a,i){const o=new s.Stream((t=>{this.sendMessage({callID:l,trailer:{status:n.data.DataFrame.Trailer.Status.ABORT,message:null==t?void 0:t.toString()}})})),l=this.registerCall((t=>{if(t){if(t.body){const e=a(t.body);o.write(e)}t.trailer&&(this._calls.delete(l),t.trailer.status==n.data.DataFrame.Trailer.Status.OK?o.end():t.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&o.error(new Error(t.trailer.message)))}else o.error(new Error("lost connection"))})),u=r(i);return this.sendMessage({callID:l,header:{service:t,method:e},body:u}),o}async rpcStreamStream(t,e,r,a,i){const o=new s.Stream((t=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.ABORT,message:null==t?void 0:t.toString()}})})),l=()=>{o.closed&&i.closed&&this._calls.delete(u)},u=this.registerCall((t=>{if(!t)return o.error(new Error("lost connection")),void i.abort(new Error("lost connection"));if(t.body){const e=a(t.body);o.write(e)}t.trailer&&(t.trailer.status==n.data.DataFrame.Trailer.Status.OK?o.end():t.trailer.status==n.data.DataFrame.Trailer.Status.ABORT?i.abort(new Error(t.trailer.message)):t.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&o.error(new Error(t.trailer.message)),l())}));return this.sendMessage({callID:u,header:{service:t,method:e}}),i.read((t=>{const e=r(t);this.sendMessage({callID:u,body:e})})).then((()=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})})).catch((t=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:t.toString()}})})).finally(l),o}rpcStreamUnary(t,e,r,a,i){const o=new s.Future,l=()=>{o.resolved&&i.closed&&this._calls.delete(u)},u=this.registerCall((t=>{if(!t)return o.reject(new Error("lost connection")),void i.abort(new Error("lost connection"));if(t.body){const e=a(t.body);o.resolve(e)}t.trailer&&(t.trailer.status==n.data.DataFrame.Trailer.Status.ABORT?i.abort(new Error(t.trailer.message)):t.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&o.reject(new Error(t.trailer.message))),l()}));return this.sendMessage({callID:u,header:{service:t,method:e}}),i.read((t=>{const e=r(t);this.sendMessage({callID:u,body:e})})).then((()=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})})).catch((t=>{this.sendMessage({callID:u,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:t.toString()}})})).finally(l),o.promise}}},795:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.data=void 0;const s=r(100);!function(t){let e;!function(t){let e,r;!function(t){t.encode=function(t,e){const r=!e;return e||(e=s.Writer.create()),null!=t.service&&null!=t.service&&e.uint32(10).string(t.service),null!=t.method&&null!=t.method&&e.uint32(18).string(t.method),r?e.finish():e},t.decode=function(t,e){t instanceof s.Reader||(t=s.Reader.create(t));let r=void 0===e?t.len:t.pos+e;const n={};for(;t.pos<r;){let e=t.uint32();switch(e>>>3){case 1:n.service=t.string();break;case 2:n.method=t.string();break;default:t.skipType(7&e)}}return n}}(e=t.Header||(t.Header={})),function(t){t.Status={OK:0,ERROR:1,ABORT:2,UNKNOWN:3},t.encode=function(t,e){const r=!e;return e||(e=s.Writer.create()),null!=t.status&&null!=t.status&&e.uint32(8).int32(t.status),null!=t.message&&null!=t.message&&e.uint32(18).string(t.message),r?e.finish():e},t.decode=function(t,e){t instanceof s.Reader||(t=s.Reader.create(t));let r=void 0===e?t.len:t.pos+e;const n={};for(;t.pos<r;){let e=t.uint32();switch(e>>>3){case 1:n.status=t.int32();break;case 2:n.message=t.string();break;default:t.skipType(7&e)}}return n}}(r=t.Trailer||(t.Trailer={})),t.encode=function(t,n){const a=!n;return n||(n=s.Writer.create()),null!=t.callID&&null!=t.callID&&n.uint32(8).int32(t.callID),null!=t.header&&null!=t.header&&e.encode(t.header,n.uint32(58).fork()).ldelim(),null!=t.trailer&&null!=t.trailer&&r.encode(t.trailer,n.uint32(66).fork()).ldelim(),null!=t.body&&null!=t.body&&n.uint32(74).bytes(t.body),a?n.finish():n},t.decode=function(t,n){t instanceof s.Reader||(t=s.Reader.create(t));let a=void 0===n?t.len:t.pos+n;const i={};for(;t.pos<a;){let s=t.uint32();switch(s>>>3){case 1:i.callID=t.int32();break;case 7:i.header=e.decode(t,t.uint32());break;case 8:i.trailer=r.decode(t,t.uint32());break;case 9:i.body=t.bytes();break;default:t.skipType(7&s)}}return i}}(e=t.DataFrame||(t.DataFrame={}))}(e.data||(e.data={}))},728:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Server=void 0;const s=r(87),n=r(795),a=r(615);e.Server=class{constructor(){this.services={},this.fallbacks={}}addService(t,e,r){this.services[t]={rpcs:e,factory:r}}listenHttpServerRequest(t,e){t.on("request",((t,r)=>{var s,n;(null===(s=t.url)||void 0===s?void 0:s.startsWith(e))?new o(e,this.services).handle(t,r):(null===(n=this.fallbacks)||void 0===n?void 0:n.onrequest)?this.fallbacks.onrequest(t,r):(r.statusCode=404,r.end())}))}listenHttpServerUpgrade(t,e){const r=new WebSocket.Server({noServer:!0});t.on("upgrade",((t,s,n)=>{var a;new URL(t.url,`http://${t.headers.host}`).pathname==e?r.handleUpgrade(t,s,n,((t,e)=>new l(t,e,this.services))):(null===(a=this.fallbacks)||void 0===a?void 0:a.onupgrade)?this.fallbacks.onupgrade(t,s,n):(s.write("HTTP/1.1 404 Not Found\r\n\r\n"),s.destroy())}))}fallback(t,e){this.fallbacks={onrequest:t,onupgrade:e}}};class i{constructor(t){this.serviceDirectory=t,this.services={}}async getRpc(t,e,r){const n=this.serviceDirectory[e];if(!n)throw new Error(`service not found: ${e}.${r}`);if(!((r=s.lcFirst(r))in n.rpcs))throw new Error(`method not found: ${e}.${r}`);let a=this.services[e];if(!a){if(a=n.factory(t),!a)throw new Error(`create service error: ${e}.${r}`);this.services[e]=a}const i=await a,o=i[r];if(!o)throw new Error(`method not implemented: ${e}.${r}`);const[l,u,c,h]=n.rpcs[r];return{requestDecode:l,responseEncode:u,requestStream:c,responseStream:h,exec:o.bind(i)}}}class o{constructor(t,e){t.endsWith("/")||(t+="/"),this.pathPrefix=t,this.caller=new i(e)}async handle(t,e){if("OPTIONS"==t.method)return void this._corsOptions(t,e);if("POST"!=t.method)throw new Error("http method not supported");const[r,s]=t.url.substr(this.pathPrefix.length).split("/");try{const n=await this.caller.getRpc(t,r,s);n.requestStream||n.responseStream?(e.statusCode=501,e.end()):await this.rpcUnaryUnary(t,e,n)}catch(t){e.statusCode=500,e.end(t.toString())}}_corsOptions(t,e){const r=t.headers.origin;if(!r)return e.writeHead(400),void e.end("no header: Origin");if(!t.headers["access-control-request-method"])return e.writeHead(400),void e.end("no header: Access-Control-Request-Method");let s=t.headers["access-control-request-headers"];s||(s="Authentication"),e.writeHead(204,{"Access-Control-Allow-Origin":r,"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Methods":"POST","Access-Control-Allow-Headers":s}),e.end()}_readRequestText(t){return new Promise(((e,r)=>{let s=[];t.on("error",(t=>{r(t)})).on("data",(t=>{s.push(t)})).on("end",(()=>{const t=Buffer.concat(s).toString();e(t)}))}))}async rpcUnaryUnary(t,e,r){if("application/json"!=t.headers["content-type"])throw new Error("codec not supported");const s=JSON.parse(await this._readRequestText(t)),n=await r.exec(s);e.setHeader("content-type","application/json"),e.end(JSON.stringify(n))}}class l{constructor(t,e,r){this.ws=t,this._calls=new Map,this._v="";const s=new i(r);t.onmessage=async t=>{let r=n.data.DataFrame.decode(new Uint8Array(t.data));if(!r.callID)return;if(!r.header&&!r.trailer&&!r.body){if(r=a.v1to2.tryDecodeDataFrame(new Uint8Array(t.data)),!r)return;if(this._v="v1",r.header){const t=r.callID,{service:i,method:o}=r.header;return this.ws.send(a.v1to2.encodeRequestOKResponse(t)),void this._calls.set(t,(async r=>{if(r&&r.body)try{const a=await s.getRpc(e,i,o);if(a.requestStream||a.responseStream)throw new Error("stream not implemented for v1 compatibility");await this.rpcUnaryUnary(r,a),this.sendMessage({callID:t,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})}catch(t){this.sendMessage({callID:r.callID,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:t.toString()}})}finally{this._calls.delete(t)}}))}}let i=this._calls.get(r.callID);if(i)i(r);else if(r.header){const{service:t,method:a}=r.header;try{const n=await s.getRpc(e,t,a);n.requestStream||n.responseStream?!n.requestStream&&n.responseStream?await this.rpcUnaryStream(r,n):n.requestStream&&!n.responseStream?await this.rpcStreamUnary(r,n):n.requestStream&&n.responseStream&&await this.rpcStreamStream(r,n):await this.rpcUnaryUnary(r,n)}catch(t){this.sendMessage({callID:r.callID,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:t.toString()}})}}else console.log("frame without header and callback:",r),console.log("this is a bug of client stream request")},t.onclose=()=>{this._calls.forEach((t=>t(null))),this._calls.clear()}}sendMessage(t){if(this.ws.readyState!=WebSocket.OPEN)return;if("v1"==this._v){const e=a.v1to2.encodeDataFrame(t);for(const t of e)this.ws.send(t);return}const e=n.data.DataFrame.encode(t);this.ws.send(e)}registerCall(t,e){this._calls.set(t,e)}async rpcUnaryUnary({callID:t,body:e},r){const s=r.requestDecode(e),a=await r.exec(s);this.sendMessage({callID:t,body:r.responseEncode(a),trailer:{status:n.data.DataFrame.Trailer.Status.OK}})}async rpcUnaryStream({callID:t,body:e},r){const a=r.requestDecode(e),i=new s.StreamDelegate;this.registerCall(t,(t=>{t?t.trailer&&t.trailer.status==n.data.DataFrame.Trailer.Status.ABORT&&i.abort(new Error(t.trailer.message)):i.abort(new Error("lost connection"))}));const o=await r.exec(a);i.bind(o),o.read((e=>{this.sendMessage({callID:t,body:r.responseEncode(e)})})).then((()=>{this.sendMessage({callID:t,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})})).catch((e=>{this.sendMessage({callID:t,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:e.toString()}})})).finally((()=>{this._calls.delete(t)}))}async rpcStreamStream({callID:t},e){const r=new s.Stream((e=>{this.sendMessage({callID:t,trailer:{status:n.data.DataFrame.Trailer.Status.ABORT,message:null==e?void 0:e.toString()}})})),a=new s.StreamDelegate,i=()=>{r.closed&&a.closed&&this._calls.delete(t)};this.registerCall(t,(t=>{if(t){if(t.body){const s=e.requestDecode(t.body);r.write(s)}t.trailer&&(t.trailer.status==n.data.DataFrame.Trailer.Status.OK?r.end():t.trailer.status==n.data.DataFrame.Trailer.Status.ERROR?r.error(new Error(t.trailer.message)):t.trailer.status==n.data.DataFrame.Trailer.Status.ABORT&&a.abort(new Error(t.trailer.message)),i())}else a.abort(new Error("lost connection"))}));const o=await e.exec(r);a.bind(o),o.read((r=>{this.sendMessage({callID:t,body:e.responseEncode(r)})})).then((()=>{this.sendMessage({callID:t,trailer:{status:n.data.DataFrame.Trailer.Status.OK}})})).catch((e=>{this.sendMessage({callID:t,trailer:{status:n.data.DataFrame.Trailer.Status.ERROR,message:e.toString()}})})).finally(i)}async rpcStreamUnary({callID:t},e){const r=new s.Stream((e=>{this.sendMessage({callID:t,trailer:{status:n.data.DataFrame.Trailer.Status.ABORT,message:null==e?void 0:e.toString()}})}));this.registerCall(t,(s=>{if(console.log("request:",s),s){if(s.body){const t=e.requestDecode(s.body);r.write(t)}s.trailer&&(s.trailer.status==n.data.DataFrame.Trailer.Status.OK?r.end():s.trailer.status==n.data.DataFrame.Trailer.Status.ERROR&&r.error(new Error(s.trailer.message)),this._calls.delete(t))}}));const a=await e.exec(r);this.sendMessage({callID:t,body:e.responseEncode(a),trailer:{status:n.data.DataFrame.Trailer.Status.OK}})}}},87:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.StreamDelegate=e.Stream=e.Future=e.lcFirst=void 0,e.lcFirst=function(t){return t[0].toLowerCase()+t.substr(1)};class r{constructor(){this._resolved=!1,this.promise=new Promise(((t,e)=>{this._resovle=t,this._reject=e}))}resolve(t){this._resolved=!0,this.result=t,this._resovle(t)}reject(t){this._resolved=!0,this.error=t,this._reject(t)}get resolved(){return this._resolved}}e.Future=r,e.Stream=class{constructor(t){this._onabort=t,this._readers=[],this._closed=!1,this._cache=[]}write(t){if(0==this._readers.length)return this._cache.push(t),void console.log("cache stream input");this._readers.forEach((e=>{e.onMessage(t)}))}error(t){this._closed=!0,0!=this._readers.length?(this._readers.forEach((e=>{e.future.reject(t)})),this._readers=[]):this._error=t}end(){this._closed=!0,this._readers.forEach((t=>{t.future.resolve()})),this._readers=[]}get closed(){return this._closed}abort(t){this._closed=!0,this._onabort&&this._onabort(t),this._readers.forEach((t=>{t.future.resolve()})),this._readers=[]}read(t){for(;this._cache.length>0;)t(this._cache.shift());if(this._closed)return this._error?Promise.reject(this._error):Promise.resolve();const e=new r,s={future:e,onMessage:t};return this._readers.push(s),e.promise}async*readToItorator(){const t=[];let e=new r;for(this.read((s=>{t.push(s),e.resolve(!1),e=new r})).then((()=>e.resolve(!0))).catch((t=>e.reject(t)));;){const r=t.shift();if(r)yield r;else if(await e.promise)return}}async writeFromIterator(t){try{for await(const e of t()){if(this._closed)return;this.write(e)}this.end()}catch(t){this.error(t)}}},e.StreamDelegate=class{bind(t){this.stream=t,this.abortReason&&this.stream.abort(this.abortReason)}abort(t){this.abortReason=t,this.stream&&this.stream.abort(this.abortReason)}get closed(){var t;return this.abortReason||(null===(t=this.stream)||void 0===t?void 0:t.closed)}}},836:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.data=void 0;const s=r(100);!function(t){let e;!function(t){let e,r;!function(t){t.encode=function(t,e){const r=!e;return e||(e=s.Writer.create()),null!=t.path&&null!=t.path&&e.uint32(10).string(t.path),null!=t.status&&null!=t.status&&e.uint32(18).string(t.status),null!=t.rpcStatus&&null!=t.rpcStatus&&e.uint32(26).string(t.rpcStatus),null!=t.rpcMessage&&null!=t.rpcMessage&&e.uint32(34).string(t.rpcMessage),r?e.finish():e},t.decode=function(t,e){t instanceof s.Reader||(t=s.Reader.create(t));let r=void 0===e?t.len:t.pos+e;const n={};for(;t.pos<r;){let e=t.uint32();switch(e>>>3){case 1:n.path=t.string();break;case 2:n.status=t.string();break;case 3:n.rpcStatus=t.string();break;case 4:n.rpcMessage=t.string();break;default:t.skipType(7&e)}}return n}}(e=t.Headers||(t.Headers={})),function(t){t.encode=function(t,e){const r=!e;return e||(e=s.Writer.create()),null!=t.path&&null!=t.path&&e.uint32(10).string(t.path),null!=t.status&&null!=t.status&&e.uint32(18).string(t.status),null!=t.rpcStatus&&null!=t.rpcStatus&&e.uint32(26).string(t.rpcStatus),null!=t.rpcMessage&&null!=t.rpcMessage&&e.uint32(34).string(t.rpcMessage),r?e.finish():e},t.decode=function(t,e){t instanceof s.Reader||(t=s.Reader.create(t));let r=void 0===e?t.len:t.pos+e;const n={};for(;t.pos<r;){let e=t.uint32();switch(e>>>3){case 1:n.path=t.string();break;case 2:n.status=t.string();break;case 3:n.rpcStatus=t.string();break;case 4:n.rpcMessage=t.string();break;default:t.skipType(7&e)}}return n}}(r=t.Trailers||(t.Trailers={})),t.Types={HEADERS:1,TRAILERS:2,MESSAGE:3},t.encode=function(t,n){const a=!n;return n||(n=s.Writer.create()),null!=t.streamId&&null!=t.streamId&&n.uint32(8).int32(t.streamId),null!=t.endStream&&null!=t.endStream&&n.uint32(16).bool(t.endStream),null!=t.type&&null!=t.type&&n.uint32(24).int32(t.type),null!=t.headers&&null!=t.headers&&e.encode(t.headers,n.uint32(34).fork()).ldelim(),null!=t.trailers&&null!=t.trailers&&r.encode(t.trailers,n.uint32(42).fork()).ldelim(),null!=t.message&&null!=t.message&&n.uint32(50).bytes(t.message),a?n.finish():n},t.decode=function(t,n){t instanceof s.Reader||(t=s.Reader.create(t));let a=void 0===n?t.len:t.pos+n;const i={};for(;t.pos<a;){let s=t.uint32();switch(s>>>3){case 1:i.streamId=t.int32();break;case 2:i.endStream=t.bool();break;case 3:i.type=t.int32();break;case 4:i.headers=e.decode(t,t.uint32());break;case 5:i.trailers=r.decode(t,t.uint32());break;case 6:i.message=t.bytes();break;default:t.skipType(7&s)}}return i}}(e=t.DataFrame||(t.DataFrame={}))}(e.data||(e.data={}))},615:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.v1to2=void 0;const s=r(795),n=r(836);e.v1to2={tryDecodeDataFrame:function(t){var e;const r=n.data.DataFrame.decode(t);if(r.type==n.data.DataFrame.Types.HEADERS&&r.headers){if(r.endStream)return{callID:r.streamId,body:r.message,trailer:{status:"0"==r.headers.rpcStatus?s.data.DataFrame.Trailer.Status.OK:s.data.DataFrame.Trailer.Status.ERROR,message:r.headers.rpcMessage}};{const[t,s]=null===(e=r.headers.path)||void 0===e?void 0:e.substr(1).split("/");return{callID:r.streamId,body:r.message,header:{service:t,method:s}}}}return r.type==n.data.DataFrame.Types.TRAILERS?null:r.type==n.data.DataFrame.Types.MESSAGE&&r.message?{callID:r.streamId,body:r.message}:null},encodeDataFrame:function(t){var e;const r=[];return t.header&&r.push({streamId:t.callID,type:n.data.DataFrame.Types.HEADERS,endStream:!1,headers:{path:`.${t.header.service}/${t.header.method}`}}),t.body&&r.push({streamId:t.callID,type:n.data.DataFrame.Types.MESSAGE,endStream:!1,message:t.body}),t.trailer&&(t.trailer.status==s.data.DataFrame.Trailer.Status.OK?r.push({streamId:t.callID,type:n.data.DataFrame.Types.HEADERS,endStream:!0,headers:{status:"200",rpcStatus:"0",rpcMessage:"Finish"}}):r.push({streamId:t.callID,type:n.data.DataFrame.Types.HEADERS,endStream:!0,headers:{status:"400",rpcStatus:null===(e=t.trailer.status)||void 0===e?void 0:e.toString(),rpcMessage:t.trailer.message}})),r.map((t=>n.data.DataFrame.encode(t)))},encodeRequestOKResponse:function(t){return n.data.DataFrame.encode({streamId:t,type:n.data.DataFrame.Types.HEADERS,endStream:!1,headers:{status:"200"}})}}}},__webpack_module_cache__={};function __webpack_require__(t){var e=__webpack_module_cache__[t];if(void 0!==e)return e.exports;var r=__webpack_module_cache__[t]={exports:{}};return __webpack_modules__[t].call(r.exports,r,r.exports,__webpack_require__),r.exports}var __webpack_exports__={};return(()=>{var t=__webpack_exports__;Object.defineProperty(t,"__esModule",{value:!0}),t.Server=t.Channel=t.Future=t.Stream=t.Reader=t.Writer=void 0,__webpack_require__(693).Long=null;var e=__webpack_require__(100);Object.defineProperty(t,"Writer",{enumerable:!0,get:function(){return e.Writer}}),Object.defineProperty(t,"Reader",{enumerable:!0,get:function(){return e.Reader}});var r=__webpack_require__(87);Object.defineProperty(t,"Stream",{enumerable:!0,get:function(){return r.Stream}}),Object.defineProperty(t,"Future",{enumerable:!0,get:function(){return r.Future}});var s=__webpack_require__(110);Object.defineProperty(t,"Channel",{enumerable:!0,get:function(){return s.Channel}});var n=__webpack_require__(728);Object.defineProperty(t,"Server",{enumerable:!0,get:function(){return n.Server}})})(),__webpack_exports__})()})); |
{ | ||
"name": "wsgrpc", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main-ts": "src/index.ts", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
144333
830
4