var e,t={},r={};var n,s,o={}; /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */function a(){return n||(n=1,o.read=function(e,t,r,n,s){var o,a,i=8*s-n-1,u=(1<>1,c=-7,d=r?s-1:0,f=r?-1:1,h=e[t+d];for(d+=f,o=h&(1<<-c)-1,h>>=-c,c+=i;c>0;o=256*o+e[t+d],d+=f,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=n;c>0;a=256*a+e[t+d],d+=f,c-=8);if(0===o)o=1-l;else{if(o===u)return a?NaN:1/0*(h?-1:1);a+=Math.pow(2,n),o-=l}return(h?-1:1)*a*Math.pow(2,o-n)},o.write=function(e,t,r,n,s,o){var a,i,u,l=8*o-s-1,c=(1<>1,f=23===s?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:o-1,p=n?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(i=isNaN(t)?1:0,a=c):(a=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-a))<1&&(a--,u*=2),(t+=a+d>=1?f/u:f*Math.pow(2,1-d))*u>=2&&(a++,u/=2),a+d>=c?(i=0,a=c):a+d>=1?(i=(t*u-1)*Math.pow(2,s),a+=d):(i=t*Math.pow(2,d-1)*Math.pow(2,s),a=0));s>=8;e[r+h]=255&i,h+=p,i/=256,s-=8);for(a=a<0;e[r+h]=255&a,h+=p,a/=256,l-=8);e[r+h-p]|=128*m}),o} /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */var i=(s||(s=1,function(t){const n=function(){if(e)return r;e=1,r.byteLength=function(e){var t=i(e),r=t[0],n=t[1];return 3*(r+n)/4-n},r.toByteArray=function(e){var t,r,o=i(e),a=o[0],u=o[1],l=new s(function(e,t,r){return 3*(t+r)/4-r}(0,a,u)),c=0,d=u>0?a-4:a;for(r=0;r>16&255,l[c++]=t>>8&255,l[c++]=255&t;return 2===u&&(t=n[e.charCodeAt(r)]<<2|n[e.charCodeAt(r+1)]>>4,l[c++]=255&t),1===u&&(t=n[e.charCodeAt(r)]<<10|n[e.charCodeAt(r+1)]<<4|n[e.charCodeAt(r+2)]>>2,l[c++]=t>>8&255,l[c++]=255&t),l},r.fromByteArray=function(e){for(var r,n=e.length,s=n%3,o=[],a=16383,i=0,u=n-s;iu?u:i+a));return 1===s?(r=e[n-1],o.push(t[r>>2]+t[r<<4&63]+"==")):2===s&&(r=(e[n-2]<<8)+e[n-1],o.push(t[r>>10]+t[r>>4&63]+t[r<<2&63]+"=")),o.join("")};for(var t=[],n=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0;a<64;++a)t[a]=o[a],n[o.charCodeAt(a)]=a;function i(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function u(e){return t[e>>18&63]+t[e>>12&63]+t[e>>6&63]+t[63&e]}function l(e,t,r){for(var n,s=[],o=t;oi)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,l.prototype),t}function l(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return c(e,t,r)}function c(e,t,r){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!l.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|y(e,t);let n=u(r);const s=n.write(e,t);return s!==r&&(n=n.slice(0,s)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(W(e,Uint8Array)){const t=new Uint8Array(e);return p(t.buffer,t.byteOffset,t.byteLength)}return h(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(W(e,ArrayBuffer)||e&&W(e.buffer,ArrayBuffer))return p(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(W(e,SharedArrayBuffer)||e&&W(e.buffer,SharedArrayBuffer)))return p(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return l.from(n,t,r);const s=function(e){if(l.isBuffer(e)){const t=0|m(e.length),r=u(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||$(e.length)?u(0):h(e):"Buffer"===e.type&&Array.isArray(e.data)?h(e.data):void 0}(e);if(s)return s;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return l.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function d(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return d(e),u(e<0?0:0|m(e))}function h(e){const t=e.length<0?0:0|m(e.length),r=u(t);for(let n=0;n=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function y(e,t){if(l.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||W(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let s=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return V(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(e).length;default:if(s)return n?-1:V(e).length;t=(""+t).toLowerCase(),s=!0}}function E(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,r);case"utf8":case"utf-8":return O(this,t,r);case"ascii":return N(this,t,r);case"latin1":case"binary":return _(this,t,r);case"base64":return w(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function v(e,t,r,n,s){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),$(r=+r)&&(r=s?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(s)return-1;r=e.length-1}else if(r<0){if(!s)return-1;r=0}if("string"==typeof t&&(t=l.from(t,n)),l.isBuffer(t))return 0===t.length?-1:T(e,t,r,n,s);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?s?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):T(e,[t],r,n,s);throw new TypeError("val must be string, number or Buffer")}function T(e,t,r,n,s){let o,a=1,i=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;a=2,i/=2,u/=2,r/=2}function l(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(s){let n=-1;for(o=r;oi&&(r=i-u),o=r;o>=0;o--){let r=!0;for(let n=0;ns&&(n=s):n=s;const o=t.length;let a;for(n>o/2&&(n=o/2),a=0;a>8,s=r%256,o.push(s),o.push(n);return o}(t,e.length-r),e,r,n)}function w(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function O(e,t,r){r=Math.min(e.length,r);const n=[];let s=t;for(;s239?4:t>223?3:t>191?2:1;if(s+a<=r){let r,n,i,u;switch(a){case 1:t<128&&(o=t);break;case 2:r=e[s+1],128==(192&r)&&(u=(31&t)<<6|63&r,u>127&&(o=u));break;case 3:r=e[s+1],n=e[s+2],128==(192&r)&&128==(192&n)&&(u=(15&t)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:r=e[s+1],n=e[s+2],i=e[s+3],128==(192&r)&&128==(192&n)&&128==(192&i)&&(u=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&i,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,a=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),s+=a}return function(e){const t=e.length;if(t<=I)return String.fromCharCode.apply(String,e);let r="",n=0;for(;nn.length?(l.isBuffer(t)||(t=l.from(t)),t.copy(n,s)):Uint8Array.prototype.set.call(n,t,s);else{if(!l.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,s)}s+=t.length}return n},l.byteLength=y,l.prototype._isBuffer=!0,l.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;tr&&(e+=" ... "),""},o&&(l.prototype[o]=l.prototype.inspect),l.prototype.compare=function(e,t,r,n,s){if(W(e,Uint8Array)&&(e=l.from(e,e.offset,e.byteLength)),!l.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===s&&(s=this.length),t<0||r>e.length||n<0||s>this.length)throw new RangeError("out of range index");if(n>=s&&t>=r)return 0;if(n>=s)return-1;if(t>=r)return 1;if(this===e)return 0;let o=(s>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const i=Math.min(o,a),u=this.slice(n,s),c=e.slice(t,r);for(let e=0;e>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const s=this.length-t;if((void 0===r||r>s)&&(r=s),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return b(this,e,t,r);case"utf8":case"utf-8":return R(this,e,t,r);case"ascii":case"latin1":case"binary":return F(this,e,t,r);case"base64":return S(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},l.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const I=4096;function N(e,t,r){let n="";r=Math.min(e.length,r);for(let s=t;sn)&&(r=n);let s="";for(let n=t;nr)throw new RangeError("Trying to access beyond buffer length")}function D(e,t,r,n,s,o){if(!l.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>s||te.length)throw new RangeError("Index out of range")}function M(e,t,r,n,s){Q(t,n,s,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o;let a=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=a,a>>=8,e[r++]=a,a>>=8,e[r++]=a,a>>=8,e[r++]=a,r}function x(e,t,r,n,s){Q(t,n,s,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o>>=8,e[r+6]=o,o>>=8,e[r+5]=o,o>>=8,e[r+4]=o;let a=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=a,a>>=8,e[r+2]=a,a>>=8,e[r+1]=a,a>>=8,e[r]=a,r+8}function P(e,t,r,n,s,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function B(e,t,r,n,o){return t=+t,r>>>=0,o||P(e,0,r,4),s.write(e,t,r,n,23,4),r+4}function k(e,t,r,n,o){return t=+t,r>>>=0,o||P(e,0,r,8),s.write(e,t,r,n,52,8),r+8}l.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t>>=0,t>>>=0,r||U(e,t,this.length);let n=this[e],s=1,o=0;for(;++o>>=0,t>>>=0,r||U(e,t,this.length);let n=this[e+--t],s=1;for(;t>0&&(s*=256);)n+=this[e+--t]*s;return n},l.prototype.readUint8=l.prototype.readUInt8=function(e,t){return e>>>=0,t||U(e,1,this.length),this[e]},l.prototype.readUint16LE=l.prototype.readUInt16LE=function(e,t){return e>>>=0,t||U(e,2,this.length),this[e]|this[e+1]<<8},l.prototype.readUint16BE=l.prototype.readUInt16BE=function(e,t){return e>>>=0,t||U(e,2,this.length),this[e]<<8|this[e+1]},l.prototype.readUint32LE=l.prototype.readUInt32LE=function(e,t){return e>>>=0,t||U(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},l.prototype.readUint32BE=l.prototype.readUInt32BE=function(e,t){return e>>>=0,t||U(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},l.prototype.readBigUInt64LE=Z(function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||X(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,s=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(s)<>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||X(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],s=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<>>=0,t>>>=0,r||U(e,t,this.length);let n=this[e],s=1,o=0;for(;++o=s&&(n-=Math.pow(2,8*t)),n},l.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||U(e,t,this.length);let n=t,s=1,o=this[e+--n];for(;n>0&&(s*=256);)o+=this[e+--n]*s;return s*=128,o>=s&&(o-=Math.pow(2,8*t)),o},l.prototype.readInt8=function(e,t){return e>>>=0,t||U(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},l.prototype.readInt16LE=function(e,t){e>>>=0,t||U(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},l.prototype.readInt16BE=function(e,t){e>>>=0,t||U(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},l.prototype.readInt32LE=function(e,t){return e>>>=0,t||U(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},l.prototype.readInt32BE=function(e,t){return e>>>=0,t||U(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},l.prototype.readBigInt64LE=Z(function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||X(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||X(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<>>=0,t||U(e,4,this.length),s.read(this,e,!0,23,4)},l.prototype.readFloatBE=function(e,t){return e>>>=0,t||U(e,4,this.length),s.read(this,e,!1,23,4)},l.prototype.readDoubleLE=function(e,t){return e>>>=0,t||U(e,8,this.length),s.read(this,e,!0,52,8)},l.prototype.readDoubleBE=function(e,t){return e>>>=0,t||U(e,8,this.length),s.read(this,e,!1,52,8)},l.prototype.writeUintLE=l.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||D(this,e,t,r,Math.pow(2,8*r)-1,0);let s=1,o=0;for(this[t]=255&e;++o>>=0,r>>>=0,n||D(this,e,t,r,Math.pow(2,8*r)-1,0);let s=r-1,o=1;for(this[t+s]=255&e;--s>=0&&(o*=256);)this[t+s]=e/o&255;return t+r},l.prototype.writeUint8=l.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,1,255,0),this[t]=255&e,t+1},l.prototype.writeUint16LE=l.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},l.prototype.writeUint16BE=l.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},l.prototype.writeUint32LE=l.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},l.prototype.writeUint32BE=l.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},l.prototype.writeBigUInt64LE=Z(function(e,t=0){return M(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),l.prototype.writeBigUInt64BE=Z(function(e,t=0){return x(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),l.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);D(this,e,t,r,n-1,-n)}let s=0,o=1,a=0;for(this[t]=255&e;++s>>=0,!n){const n=Math.pow(2,8*r-1);D(this,e,t,r,n-1,-n)}let s=r-1,o=1,a=0;for(this[t+s]=255&e;--s>=0&&(o*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/o|0)-a&255;return t+r},l.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},l.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},l.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},l.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},l.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||D(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},l.prototype.writeBigInt64LE=Z(function(e,t=0){return M(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),l.prototype.writeBigInt64BE=Z(function(e,t=0){return x(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),l.prototype.writeFloatLE=function(e,t,r){return B(this,e,t,!0,r)},l.prototype.writeFloatBE=function(e,t,r){return B(this,e,t,!1,r)},l.prototype.writeDoubleLE=function(e,t,r){return k(this,e,t,!0,r)},l.prototype.writeDoubleBE=function(e,t,r){return k(this,e,t,!1,r)},l.prototype.copy=function(e,t,r,n){if(!l.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(s=t;s=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function Q(e,t,r,n,s,o){if(e>r||e= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`,new q.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,r){H(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||X(t,e.length-(r+1))}(n,s,o)}function H(e,t){if("number"!=typeof e)throw new q.ERR_INVALID_ARG_TYPE(t,"number",e)}function X(e,t,r){if(Math.floor(e)!==e)throw H(e,r),new q.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new q.ERR_BUFFER_OUT_OF_BOUNDS;throw new q.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}j("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),j("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),j("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,s=r;return Number.isInteger(r)&&Math.abs(r)>2**32?s=z(String(r)):"bigint"==typeof r&&(s=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(s=z(s)),s+="n"),n+=` It must be ${t}. Received ${s}`,n},RangeError);const Y=/[^+/0-9A-Za-z-_]/g;function V(e,t){let r;t=t||1/0;const n=e.length;let s=null;const o=[];for(let a=0;a55295&&r<57344){if(!s){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(a+1===n){(t-=3)>-1&&o.push(239,191,189);continue}s=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),s=r;continue}r=65536+(s-55296<<10|r-56320)}else s&&(t-=3)>-1&&o.push(239,191,189);if(s=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function G(e){return n.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(Y,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function K(e,t,r,n){let s;for(s=0;s=t.length||s>=e.length);++s)t[s+r]=e[s];return s}function W(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function $(e){return e!=e}const J=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let s=0;s<16;++s)t[n+s]=e[r]+e[s]}return t}();function Z(e){return"undefined"==typeof BigInt?ee:e}function ee(){throw new Error("BigInt not supported")}}(t)),t);const u={done:!0,value:void 0};var l,c,d={},f={},h={};function p(){return l||(l=1,e=h,Object.defineProperty(e,"__esModule",{value:!0}),e.Frame=e.Lengths=e.Flags=e.FrameTypes=void 0,function(e){e[e.RESERVED=0]="RESERVED",e[e.SETUP=1]="SETUP",e[e.LEASE=2]="LEASE",e[e.KEEPALIVE=3]="KEEPALIVE",e[e.REQUEST_RESPONSE=4]="REQUEST_RESPONSE",e[e.REQUEST_FNF=5]="REQUEST_FNF",e[e.REQUEST_STREAM=6]="REQUEST_STREAM",e[e.REQUEST_CHANNEL=7]="REQUEST_CHANNEL",e[e.REQUEST_N=8]="REQUEST_N",e[e.CANCEL=9]="CANCEL",e[e.PAYLOAD=10]="PAYLOAD",e[e.ERROR=11]="ERROR",e[e.METADATA_PUSH=12]="METADATA_PUSH",e[e.RESUME=13]="RESUME",e[e.RESUME_OK=14]="RESUME_OK",e[e.EXT=63]="EXT"}(t=e.FrameTypes||(e.FrameTypes={})),(r=e.Flags||(e.Flags={}))[r.NONE=0]="NONE",r[r.COMPLETE=64]="COMPLETE",r[r.FOLLOWS=128]="FOLLOWS",r[r.IGNORE=512]="IGNORE",r[r.LEASE=64]="LEASE",r[r.METADATA=256]="METADATA",r[r.NEXT=32]="NEXT",r[r.RESPOND=128]="RESPOND",r[r.RESUME_ENABLE=128]="RESUME_ENABLE",function(e){e.hasMetadata=function(t){return(t&e.METADATA)===e.METADATA},e.hasComplete=function(t){return(t&e.COMPLETE)===e.COMPLETE},e.hasNext=function(t){return(t&e.NEXT)===e.NEXT},e.hasFollows=function(t){return(t&e.FOLLOWS)===e.FOLLOWS},e.hasIgnore=function(t){return(t&e.IGNORE)===e.IGNORE},e.hasRespond=function(t){return(t&e.RESPOND)===e.RESPOND},e.hasLease=function(t){return(t&e.LEASE)===e.LEASE},e.hasResume=function(t){return(t&e.RESUME_ENABLE)===e.RESUME_ENABLE}}(e.Flags||(e.Flags={})),(n=e.Lengths||(e.Lengths={}))[n.FRAME=3]="FRAME",n[n.HEADER=6]="HEADER",n[n.METADATA=3]="METADATA",n[n.REQUEST=3]="REQUEST",(s=e.Frame||(e.Frame={})).isConnection=function(e){return 0===e.streamId},s.isRequest=function(e){return t.REQUEST_RESPONSE<=e.type&&e.type<=t.REQUEST_CHANNEL}),h;var e,t,r,n,s}function m(){return c||(c=1,function(e){var t=f&&f.__generator||function(e,t){var r,n,s,o,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(s=2&o[0]?n.return:o[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,o[1])).done)return s;switch(n=0,s&&(o=[2&o[0],s.value]),o[0]){case 0:case 1:s=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(s=a.trys,(s=s.length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]>>16,r),r=e.writeUInt8(t>>>8&255,r),e.writeUInt8(255&t,r)}function a(e,t){var r=e.readUInt32BE(t),s=e.readUInt32BE(t+4);return r*n+s}function u(e,t,r){var s=t/n|0,o=t%n;return r=e.writeUInt32BE(s,r),e.writeUInt32BE(o,r)}e.readUInt24BE=s,e.writeUInt24BE=o,e.readUInt64BE=a,e.writeUInt64BE=u;function l(e){var t=s(e,0);return d(e.slice(3,3+t))}function c(e){var r,n,o,a,i;return t(this,function(t){switch(t.label){case 0:r=0,t.label=1;case 1:return r+3e.length?[3,3]:(i=e.slice(o,a),[4,[d(i),r=a]])):[3,3];case 2:return t.sent(),[3,1];case 3:return[2]}})}function d(t){var n=0,s=t.readInt32BE(n);n+=4;var o=t.readUInt16BE(n);n+=2;var i=o>>>e.FRAME_TYPE_OFFFSET,u=o&e.FLAGS_MASK;switch(i){case r.FrameTypes.SETUP:return function(e,t,n){e.length;var s=6,o=e.readUInt16BE(s);s+=2;var a=e.readUInt16BE(s);s+=2;var i=e.readInt32BE(s);s+=4;var u=e.readInt32BE(s);s+=4;var l=null;if(n&r.Flags.RESUME_ENABLE){var c=e.readInt16BE(s);s+=2,l=e.slice(s,s+c),s+=c}var d=e.readUInt8(s);s+=1;var f=e.toString("ascii",s,s+d);s+=d;var h=e.readUInt8(s);s+=1;var p=e.toString("ascii",s,s+h);s+=h;var m={data:null,dataMimeType:p,flags:n,keepAlive:i,lifetime:u,majorVersion:o,metadata:null,metadataMimeType:f,minorVersion:a,resumeToken:l,streamId:0,type:r.FrameTypes.SETUP};return O(e,m,s),m}(t,0,u);case r.FrameTypes.PAYLOAD:return function(e,t,n){e.length;var s={data:null,flags:n,metadata:null,streamId:t,type:r.FrameTypes.PAYLOAD};return O(e,s,6),s}(t,s,u);case r.FrameTypes.ERROR:return function(e,t,n){e.length;var s=6,o=e.readInt32BE(s);s+=4;var a=e.length-s,i="";a>0&&(i=e.toString("utf8",s,s+a),s+=a);return{code:o,flags:n,message:i,streamId:t,type:r.FrameTypes.ERROR}}(t,s,u);case r.FrameTypes.KEEPALIVE:return function(e,t,n){e.length;var s=6,o=a(e,s);s+=8;var i=null;s0&&(t.metadata=e.slice(n,n+o),n+=o)}n=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(v,"__esModule",{value:!0}),v.Deferred=void 0;var t=function(){function t(){this._done=!1,this.onCloseCallbacks=[]}return Object.defineProperty(t.prototype,"done",{get:function(){return this._done},enumerable:!1,configurable:!0}),t.prototype.close=function(t){var r,n,s,o;if(this.done)console.warn("Trying to close for the second time. ".concat(t?"Dropping error [".concat(t,"]."):""));else if(this._done=!0,this._error=t,t)try{for(var a=e(this.onCloseCallbacks),i=a.next();!i.done;i=a.next()){(0,i.value)(t)}}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}else try{for(var u=e(this.onCloseCallbacks),l=u.next();!l.done;l=u.next()){(0,l.value)()}}catch(e){s={error:e}}finally{try{l&&!l.done&&(o=u.return)&&o.call(u)}finally{if(s)throw s.error}}},t.prototype.onClose=function(e){this._done?e(this._error):this.onCloseCallbacks.push(e)},t}();return v.Deferred=t,v}var b,R={};function F(){return b||(b=1,function(e){var t,r=R&&R.__extends||(t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},t(e,r)},function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0}),e.ErrorCodes=e.RSocketError=void 0;var n,s=function(e){function t(t,r){var n=e.call(this,r)||this;return n.code=t,n}return r(t,e),t}(Error);e.RSocketError=s,(n=e.ErrorCodes||(e.ErrorCodes={}))[n.RESERVED=0]="RESERVED",n[n.INVALID_SETUP=1]="INVALID_SETUP",n[n.UNSUPPORTED_SETUP=2]="UNSUPPORTED_SETUP",n[n.REJECTED_SETUP=3]="REJECTED_SETUP",n[n.REJECTED_RESUME=4]="REJECTED_RESUME",n[n.CONNECTION_CLOSE=258]="CONNECTION_CLOSE",n[n.CONNECTION_ERROR=257]="CONNECTION_ERROR",n[n.APPLICATION_ERROR=513]="APPLICATION_ERROR",n[n.REJECTED=514]="REJECTED",n[n.CANCELED=515]="CANCELED",n[n.INVALID=516]="INVALID",n[n.RESERVED_EXTENSION=4294967295]="RESERVED_EXTENSION"}(R)),R}var S,A={};var w,O={},I={};function N(){return w||(w=1,function(e){var t,r=I&&I.__extends||(t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},t(e,r)},function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}),n=I&&I.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(s,o){function a(e){try{u(n.next(e))}catch(e){o(e)}}function i(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(a,i)}u((n=n.apply(e,t||[])).next())})},s=I&&I.__generator||function(e,t){var r,n,s,o,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(s=2&o[0]?n.return:o[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,o[1])).done)return s;switch(n=0,s&&(o=[2&o[0],s.value]),o[0]){case 0:case 1:s=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(s=a.trys,(s=s.length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]0&&s[s.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]r},U.fragment=function(r,n,s,o,a){var u,l,c,d,f,h,p,m,y,E,g,v;return void 0===a&&(a=!1),e(this,function(e){switch(e.label){case 0:return u=null!==(v=null===(g=n.data)||void 0===g?void 0:g.byteLength)&&void 0!==v?v:0,l=o!==t.FrameTypes.PAYLOAD,c=s,n.metadata?0!==(f=n.metadata.byteLength)?[3,1]:(c-=t.Lengths.METADATA,d=i.Buffer.allocUnsafe(0),[3,6]):[3,6];case 1:return h=0,l?(c-=t.Lengths.METADATA,p=Math.min(f,h+c),d=n.metadata.slice(h,p),c-=d.byteLength,h=p,0!==c?[3,3]:(l=!1,[4,{type:o,flags:t.Flags.FOLLOWS|t.Flags.METADATA,data:void 0,metadata:d,streamId:r}])):[3,3];case 2:e.sent(),d=void 0,c=s,e.label=3;case 3:return h=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(L,"__esModule",{value:!0}),L.RequestChannelResponderStream=L.RequestChannelRequesterStream=void 0;var s=F(),o=D(),a=p(),i=r(B()),u=function(){function e(e,t,r,n,s,o){this.payload=e,this.isComplete=t,this.receiver=r,this.fragmentSize=n,this.initialRequestN=s,this.leaseManager=o,this.streamType=a.FrameTypes.REQUEST_CHANNEL}return e.prototype.handleReady=function(e,t){var r,s;if(this.outboundDone)return!1;this.streamId=e,this.stream=t,t.connect(this);var i=this.isComplete;if(i&&(this.outboundDone=i),(0,o.isFragmentable)(this.payload,this.fragmentSize,a.FrameTypes.REQUEST_CHANNEL))try{for(var u=n((0,o.fragmentWithRequestN)(e,this.payload,this.fragmentSize,a.FrameTypes.REQUEST_CHANNEL,this.initialRequestN,i)),l=u.next();!l.done;l=u.next()){var c=l.value;this.stream.send(c)}}catch(e){r={error:e}}finally{try{l&&!l.done&&(s=u.return)&&s.call(u)}finally{if(r)throw r.error}}else this.stream.send({type:a.FrameTypes.REQUEST_CHANNEL,data:this.payload.data,metadata:this.payload.metadata,requestN:this.initialRequestN,flags:(void 0!==this.payload.metadata?a.Flags.METADATA:a.Flags.NONE)|(i?a.Flags.COMPLETE:a.Flags.NONE),streamId:e});return this.hasExtension&&this.stream.send({type:a.FrameTypes.EXT,streamId:e,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},e.prototype.handleReject=function(e){this.inboundDone||(this.inboundDone=!0,this.outboundDone=!0,this.receiver.onError(e))},e.prototype.handle=function(e){var t,r=e.type;switch(r){case a.FrameTypes.PAYLOAD:var n=a.Flags.hasComplete(e.flags),o=a.Flags.hasNext(e.flags);if(n||!a.Flags.hasFollows(e.flags)){if(n&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this),!o))return void this.receiver.onComplete();var u=this.hasFragments?i.reassemble(this,e.data,e.metadata):{data:e.data,metadata:e.metadata};return void this.receiver.onNext(u,n)}if(i.add(this,e.data,e.metadata))return;t="Unexpected frame size";break;case a.FrameTypes.CANCEL:if(this.outboundDone)return;return this.outboundDone=!0,this.inboundDone&&this.stream.disconnect(this),void this.receiver.cancel();case a.FrameTypes.REQUEST_N:if(this.outboundDone)return;if(this.hasFragments){t="Unexpected frame type [".concat(r,"] during reassembly");break}return void this.receiver.request(e.requestN);case a.FrameTypes.ERROR:var l=this.outboundDone;return this.inboundDone=!0,this.outboundDone=!0,this.stream.disconnect(this),i.cancel(this),l||this.receiver.cancel(),void this.receiver.onError(new s.RSocketError(e.code,e.message));case a.FrameTypes.EXT:return void this.receiver.onExtension(e.extendedType,e.extendedContent,a.Flags.hasIgnore(e.flags));default:t="Unexpected frame type [".concat(r,"]")}this.close(new s.RSocketError(s.ErrorCodes.CANCELED,t)),this.stream.send({type:a.FrameTypes.CANCEL,streamId:this.streamId,flags:a.Flags.NONE}),this.stream.disconnect(this)},e.prototype.request=function(e){this.inboundDone||(this.streamId?this.stream.send({type:a.FrameTypes.REQUEST_N,flags:a.Flags.NONE,requestN:e,streamId:this.streamId}):this.initialRequestN+=e)},e.prototype.cancel=function(){var e,t=this.inboundDone,r=this.outboundDone;t&&r||(this.inboundDone=!0,this.outboundDone=!0,r||this.receiver.cancel(),this.streamId?(this.stream.send({type:t?a.FrameTypes.ERROR:a.FrameTypes.CANCEL,flags:a.Flags.NONE,streamId:this.streamId,code:s.ErrorCodes.CANCELED,message:"Cancelled"}),this.stream.disconnect(this),i.cancel(this)):null===(e=this.leaseManager)||void 0===e||e.cancelRequest(this))},e.prototype.onNext=function(e,t){var r,s;if(!this.outboundDone)if(t&&(this.outboundDone=!0,this.inboundDone&&this.stream.disconnect(this)),(0,o.isFragmentable)(e,this.fragmentSize,a.FrameTypes.PAYLOAD))try{for(var i=n((0,o.fragment)(this.streamId,e,this.fragmentSize,a.FrameTypes.PAYLOAD,t)),u=i.next();!u.done;u=i.next()){var l=u.value;this.stream.send(l)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(s=i.return)&&s.call(i)}finally{if(r)throw r.error}}else this.stream.send({type:a.FrameTypes.PAYLOAD,streamId:this.streamId,flags:a.Flags.NEXT|(e.metadata?a.Flags.METADATA:a.Flags.NONE)|(t?a.Flags.COMPLETE:a.Flags.NONE),data:e.data,metadata:e.metadata})},e.prototype.onComplete=function(){this.streamId?this.outboundDone||(this.outboundDone=!0,this.stream.send({type:a.FrameTypes.PAYLOAD,streamId:this.streamId,flags:a.Flags.COMPLETE,data:null,metadata:null}),this.inboundDone&&this.stream.disconnect(this)):this.isComplete=!0},e.prototype.onError=function(e){if(!this.outboundDone){var t=this.inboundDone;this.outboundDone=!0,this.inboundDone=!0,this.stream.send({type:a.FrameTypes.ERROR,streamId:this.streamId,flags:a.Flags.NONE,code:e instanceof s.RSocketError?e.code:s.ErrorCodes.APPLICATION_ERROR,message:e.message}),this.stream.disconnect(this),t||this.receiver.onError(e)}},e.prototype.onExtension=function(e,t,r){if(!this.outboundDone)return this.streamId?void this.stream.send({streamId:this.streamId,type:a.FrameTypes.EXT,extendedType:e,extendedContent:t,flags:r?a.Flags.IGNORE:a.Flags.NONE}):(this.hasExtension=!0,this.extendedType=e,this.extendedContent=t,void(this.flags=r?a.Flags.IGNORE:a.Flags.NONE))},e.prototype.close=function(e){if(!this.inboundDone||!this.outboundDone){var t=this.inboundDone,r=this.outboundDone;this.inboundDone=!0,this.outboundDone=!0,i.cancel(this),r||this.receiver.cancel(),t||(e?this.receiver.onError(e):this.receiver.onComplete())}},e}();L.RequestChannelRequesterStream=u;var l=function(){function e(e,t,r,n,s){if(this.streamId=e,this.stream=t,this.fragmentSize=r,this.handler=n,this.streamType=a.FrameTypes.REQUEST_CHANNEL,t.connect(this),a.Flags.hasFollows(s.flags))return i.add(this,s.data,s.metadata),this.initialRequestN=s.requestN,void(this.isComplete=a.Flags.hasComplete(s.flags));var o={data:s.data,metadata:s.metadata},u=a.Flags.hasComplete(s.flags);this.inboundDone=u;try{this.receiver=n(o,s.requestN,u,this),this.outboundDone&&this.defferedError&&this.receiver.onError(this.defferedError)}catch(e){this.outboundDone&&!this.inboundDone?this.cancel():this.inboundDone=!0,this.onError(e)}}return e.prototype.handle=function(e){var t,r=e.type;switch(r){case a.FrameTypes.PAYLOAD:if(a.Flags.hasFollows(e.flags)){if(i.add(this,e.data,e.metadata))return;t="Unexpected frame size";break}var n=this.hasFragments?i.reassemble(this,e.data,e.metadata):{data:e.data,metadata:e.metadata},o=a.Flags.hasComplete(e.flags);if(this.receiver){if(o&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this),!a.Flags.hasNext(e.flags)))return void this.receiver.onComplete();this.receiver.onNext(n,o)}else{(u=this.isComplete||o)&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this));try{this.receiver=this.handler(n,this.initialRequestN,u,this),this.outboundDone&&this.defferedError}catch(c){this.outboundDone&&!this.inboundDone?this.cancel():this.inboundDone=!0,this.onError(c)}}return;case a.FrameTypes.REQUEST_N:if(!this.receiver||this.hasFragments){t="Unexpected frame type [".concat(r,"] during reassembly");break}return void this.receiver.request(e.requestN);case a.FrameTypes.ERROR:case a.FrameTypes.CANCEL:var u=this.inboundDone,l=this.outboundDone;if(this.inboundDone=!0,this.outboundDone=!0,this.stream.disconnect(this),i.cancel(this),!this.receiver)return;if(l||this.receiver.cancel(),!u){var c=r===a.FrameTypes.CANCEL?new s.RSocketError(s.ErrorCodes.CANCELED,"Cancelled"):new s.RSocketError(e.code,e.message);this.receiver.onError(c)}return;case a.FrameTypes.EXT:if(!this.receiver||this.hasFragments){t="Unexpected frame type [".concat(r,"] during reassembly");break}return void this.receiver.onExtension(e.extendedType,e.extendedContent,a.Flags.hasIgnore(e.flags));default:t="Unexpected frame type [".concat(r,"]")}this.stream.send({type:a.FrameTypes.ERROR,flags:a.Flags.NONE,code:s.ErrorCodes.CANCELED,message:t,streamId:this.streamId}),this.stream.disconnect(this),this.close(new s.RSocketError(s.ErrorCodes.CANCELED,t))},e.prototype.onError=function(e){if(this.outboundDone)console.warn("Trying to error for the second time. ".concat(e?"Dropping error [".concat(e,"]."):""));else{var t=this.inboundDone;this.outboundDone=!0,this.inboundDone=!0,this.stream.send({type:a.FrameTypes.ERROR,flags:a.Flags.NONE,code:e instanceof s.RSocketError?e.code:s.ErrorCodes.APPLICATION_ERROR,message:e.message,streamId:this.streamId}),this.stream.disconnect(this),t||(this.receiver?this.receiver.onError(e):this.defferedError=e)}},e.prototype.onNext=function(e,t){var r,s;if(!this.outboundDone){if(t&&(this.outboundDone=!0),(0,o.isFragmentable)(e,this.fragmentSize,a.FrameTypes.PAYLOAD))try{for(var i=n((0,o.fragment)(this.streamId,e,this.fragmentSize,a.FrameTypes.PAYLOAD,t)),u=i.next();!u.done;u=i.next()){var l=u.value;this.stream.send(l)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(s=i.return)&&s.call(i)}finally{if(r)throw r.error}}else this.stream.send({type:a.FrameTypes.PAYLOAD,flags:a.Flags.NEXT|(t?a.Flags.COMPLETE:a.Flags.NONE)|(e.metadata?a.Flags.METADATA:a.Flags.NONE),data:e.data,metadata:e.metadata,streamId:this.streamId});t&&this.inboundDone&&this.stream.disconnect(this)}},e.prototype.onComplete=function(){this.outboundDone||(this.outboundDone=!0,this.stream.send({type:a.FrameTypes.PAYLOAD,flags:a.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.inboundDone&&this.stream.disconnect(this))},e.prototype.onExtension=function(e,t,r){this.outboundDone&&this.inboundDone||this.stream.send({type:a.FrameTypes.EXT,streamId:this.streamId,flags:r?a.Flags.IGNORE:a.Flags.NONE,extendedType:e,extendedContent:t})},e.prototype.request=function(e){this.inboundDone||this.stream.send({type:a.FrameTypes.REQUEST_N,flags:a.Flags.NONE,streamId:this.streamId,requestN:e})},e.prototype.cancel=function(){this.inboundDone||(this.inboundDone=!0,this.stream.send({type:a.FrameTypes.CANCEL,flags:a.Flags.NONE,streamId:this.streamId}),this.outboundDone&&this.stream.disconnect(this))},e.prototype.close=function(e){if(this.inboundDone&&this.outboundDone)console.warn("Trying to close for the second time. ".concat(e?"Dropping error [".concat(e,"]."):""));else{var t=this.inboundDone,r=this.outboundDone;this.inboundDone=!0,this.outboundDone=!0,i.cancel(this);var n=this.receiver;n&&(r||n.cancel(),t||(e?n.onError(e):n.onComplete()))}},e}();return L.RequestChannelResponderStream=l,L}(),n=function(){if(k)return q;k=1;var e=q&&q.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),t=q&&q.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=q&&q.__importStar||function(r){if(r&&r.__esModule)return r;var n={};if(null!=r)for(var s in r)"default"!==s&&Object.prototype.hasOwnProperty.call(r,s)&&e(n,r,s);return t(n,r),n},n=q&&q.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(q,"__esModule",{value:!0}),q.RequestFnfResponderStream=q.RequestFnFRequesterStream=void 0;var s=F(),o=D(),a=p(),i=r(B()),u=function(){function e(e,t,r,n){this.payload=e,this.receiver=t,this.fragmentSize=r,this.leaseManager=n,this.streamType=a.FrameTypes.REQUEST_FNF}return e.prototype.handleReady=function(e,t){var r,s;if(this.done)return!1;if(this.streamId=e,(0,o.isFragmentable)(this.payload,this.fragmentSize,a.FrameTypes.REQUEST_FNF))try{for(var i=n((0,o.fragment)(e,this.payload,this.fragmentSize,a.FrameTypes.REQUEST_FNF)),u=i.next();!u.done;u=i.next()){var l=u.value;t.send(l)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(s=i.return)&&s.call(i)}finally{if(r)throw r.error}}else t.send({type:a.FrameTypes.REQUEST_FNF,data:this.payload.data,metadata:this.payload.metadata,flags:this.payload.metadata?a.Flags.METADATA:0,streamId:e});return this.done=!0,this.receiver.onComplete(),!0},e.prototype.handleReject=function(e){this.done||(this.done=!0,this.receiver.onError(e))},e.prototype.cancel=function(){var e;this.done||(this.done=!0,null===(e=this.leaseManager)||void 0===e||e.cancelRequest(this))},e.prototype.handle=function(e){e.type!=a.FrameTypes.ERROR?this.close(new s.RSocketError(s.ErrorCodes.CANCELED,"Received invalid frame")):this.close(new s.RSocketError(e.code,e.message))},e.prototype.close=function(e){this.done?console.warn("Trying to close for the second time. ".concat(e?"Dropping error [".concat(e,"]."):"")):e?this.receiver.onError(e):this.receiver.onComplete()},e}();q.RequestFnFRequesterStream=u;var l=function(){function e(e,t,r,n){if(this.streamId=e,this.stream=t,this.handler=r,this.streamType=a.FrameTypes.REQUEST_FNF,a.Flags.hasFollows(n.flags))return i.add(this,n.data,n.metadata),void t.connect(this);var s={data:n.data,metadata:n.metadata};try{this.cancellable=r(s,this)}catch(e){}}return e.prototype.handle=function(e){var t;if(e.type==a.FrameTypes.PAYLOAD){if(!a.Flags.hasFollows(e.flags)){this.stream.disconnect(this);var r=i.reassemble(this,e.data,e.metadata);try{this.cancellable=this.handler(r,this)}catch(e){}return}if(i.add(this,e.data,e.metadata))return;t="Unexpected fragment size"}else t="Unexpected frame type [".concat(e.type,"]");this.done=!0,e.type!=a.FrameTypes.CANCEL&&e.type!=a.FrameTypes.ERROR&&this.stream.send({type:a.FrameTypes.ERROR,streamId:this.streamId,flags:a.Flags.NONE,code:s.ErrorCodes.CANCELED,message:t}),this.stream.disconnect(this),i.cancel(this)},e.prototype.close=function(e){var t;this.done?console.warn("Trying to close for the second time. ".concat(e?"Dropping error [".concat(e,"]."):"")):(this.done=!0,i.cancel(this),null===(t=this.cancellable)||void 0===t||t.cancel())},e.prototype.onError=function(e){},e.prototype.onComplete=function(){},e}();return q.RequestFnfResponderStream=l,q}(),s=function(){if(j)return z;j=1;var e=z&&z.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),t=z&&z.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=z&&z.__importStar||function(r){if(r&&r.__esModule)return r;var n={};if(null!=r)for(var s in r)"default"!==s&&Object.prototype.hasOwnProperty.call(r,s)&&e(n,r,s);return t(n,r),n},n=z&&z.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(z,"__esModule",{value:!0}),z.RequestResponseResponderStream=z.RequestResponseRequesterStream=void 0;var s=F(),o=D(),a=p(),i=r(B()),u=function(){function e(e,t,r,n){this.payload=e,this.receiver=t,this.fragmentSize=r,this.leaseManager=n,this.streamType=a.FrameTypes.REQUEST_RESPONSE}return e.prototype.handleReady=function(e,t){var r,s;if(this.done)return!1;if(this.streamId=e,this.stream=t,t.connect(this),(0,o.isFragmentable)(this.payload,this.fragmentSize,a.FrameTypes.REQUEST_RESPONSE))try{for(var i=n((0,o.fragment)(e,this.payload,this.fragmentSize,a.FrameTypes.REQUEST_RESPONSE)),u=i.next();!u.done;u=i.next()){var l=u.value;this.stream.send(l)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(s=i.return)&&s.call(i)}finally{if(r)throw r.error}}else this.stream.send({type:a.FrameTypes.REQUEST_RESPONSE,data:this.payload.data,metadata:this.payload.metadata,flags:this.payload.metadata?a.Flags.METADATA:0,streamId:e});return this.hasExtension&&this.stream.send({type:a.FrameTypes.EXT,streamId:e,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},e.prototype.handleReject=function(e){this.done||(this.done=!0,this.receiver.onError(e))},e.prototype.handle=function(e){var t,r=e.type;switch(r){case a.FrameTypes.PAYLOAD:var n=a.Flags.hasComplete(e.flags),o=a.Flags.hasNext(e.flags);if(n||!a.Flags.hasFollows(e.flags)){if(this.done=!0,this.stream.disconnect(this),!o)return void this.receiver.onComplete();var u=this.hasFragments?i.reassemble(this,e.data,e.metadata):{data:e.data,metadata:e.metadata};return void this.receiver.onNext(u,!0)}if(!i.add(this,e.data,e.metadata)){t="Unexpected fragment size";break}return;case a.FrameTypes.ERROR:return this.done=!0,this.stream.disconnect(this),i.cancel(this),void this.receiver.onError(new s.RSocketError(e.code,e.message));case a.FrameTypes.EXT:if(this.hasFragments){t="Unexpected frame type [".concat(r,"] during reassembly");break}return void this.receiver.onExtension(e.extendedType,e.extendedContent,a.Flags.hasIgnore(e.flags));default:t="Unexpected frame type [".concat(r,"]")}this.close(new s.RSocketError(s.ErrorCodes.CANCELED,t)),this.stream.send({type:a.FrameTypes.CANCEL,streamId:this.streamId,flags:a.Flags.NONE}),this.stream.disconnect(this)},e.prototype.cancel=function(){var e;this.done||(this.done=!0,this.streamId?(this.stream.send({type:a.FrameTypes.CANCEL,flags:a.Flags.NONE,streamId:this.streamId}),this.stream.disconnect(this),i.cancel(this)):null===(e=this.leaseManager)||void 0===e||e.cancelRequest(this))},e.prototype.onExtension=function(e,t,r){if(!this.done)return this.streamId?void this.stream.send({streamId:this.streamId,type:a.FrameTypes.EXT,extendedType:e,extendedContent:t,flags:r?a.Flags.IGNORE:a.Flags.NONE}):(this.hasExtension=!0,this.extendedType=e,this.extendedContent=t,void(this.flags=r?a.Flags.IGNORE:a.Flags.NONE))},e.prototype.close=function(e){this.done||(this.done=!0,i.cancel(this),e?this.receiver.onError(e):this.receiver.onComplete())},e}();z.RequestResponseRequesterStream=u;var l=function(){function e(e,t,r,n,s){if(this.streamId=e,this.stream=t,this.fragmentSize=r,this.handler=n,this.streamType=a.FrameTypes.REQUEST_RESPONSE,t.connect(this),a.Flags.hasFollows(s.flags))i.add(this,s.data,s.metadata);else{var o={data:s.data,metadata:s.metadata};try{this.receiver=n(o,this)}catch(e){this.onError(e)}}}return e.prototype.handle=function(e){var t,r;if(!this.receiver||this.hasFragments)if(e.type===a.FrameTypes.PAYLOAD){if(!a.Flags.hasFollows(e.flags)){var n=i.reassemble(this,e.data,e.metadata);try{this.receiver=this.handler(n,this)}catch(e){this.onError(e)}return}if(i.add(this,e.data,e.metadata))return;r="Unexpected fragment size"}else r="Unexpected frame type [".concat(e.type,"] during reassembly");else{if(e.type===a.FrameTypes.EXT)return void this.receiver.onExtension(e.extendedType,e.extendedContent,a.Flags.hasIgnore(e.flags));r="Unexpected frame type [".concat(e.type,"]")}this.done=!0,null===(t=this.receiver)||void 0===t||t.cancel(),e.type!==a.FrameTypes.CANCEL&&e.type!==a.FrameTypes.ERROR&&this.stream.send({type:a.FrameTypes.ERROR,flags:a.Flags.NONE,code:s.ErrorCodes.CANCELED,message:r,streamId:this.streamId}),this.stream.disconnect(this),i.cancel(this)},e.prototype.onError=function(e){this.done?console.warn("Trying to error for the second time. ".concat(e?"Dropping error [".concat(e,"]."):"")):(this.done=!0,this.stream.send({type:a.FrameTypes.ERROR,flags:a.Flags.NONE,code:e instanceof s.RSocketError?e.code:s.ErrorCodes.APPLICATION_ERROR,message:e.message,streamId:this.streamId}),this.stream.disconnect(this))},e.prototype.onNext=function(e,t){var r,s;if(!this.done){if(this.done=!0,(0,o.isFragmentable)(e,this.fragmentSize,a.FrameTypes.PAYLOAD))try{for(var i=n((0,o.fragment)(this.streamId,e,this.fragmentSize,a.FrameTypes.PAYLOAD,!0)),u=i.next();!u.done;u=i.next()){var l=u.value;this.stream.send(l)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(s=i.return)&&s.call(i)}finally{if(r)throw r.error}}else this.stream.send({type:a.FrameTypes.PAYLOAD,flags:a.Flags.NEXT|a.Flags.COMPLETE|(e.metadata?a.Flags.METADATA:0),data:e.data,metadata:e.metadata,streamId:this.streamId});this.stream.disconnect(this)}},e.prototype.onComplete=function(){this.done||(this.done=!0,this.stream.send({type:a.FrameTypes.PAYLOAD,flags:a.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.stream.disconnect(this))},e.prototype.onExtension=function(e,t,r){this.done||this.stream.send({type:a.FrameTypes.EXT,streamId:this.streamId,flags:r?a.Flags.IGNORE:a.Flags.NONE,extendedType:e,extendedContent:t})},e.prototype.close=function(e){var t;this.done?console.warn("Trying to close for the second time. ".concat(e?"Dropping error [".concat(e,"]."):"")):(i.cancel(this),null===(t=this.receiver)||void 0===t||t.cancel())},e}();return z.RequestResponseResponderStream=l,z}(),o=function(){if(Q)return X;Q=1;var e=X&&X.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),t=X&&X.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=X&&X.__importStar||function(r){if(r&&r.__esModule)return r;var n={};if(null!=r)for(var s in r)"default"!==s&&Object.prototype.hasOwnProperty.call(r,s)&&e(n,r,s);return t(n,r),n},n=X&&X.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(X,"__esModule",{value:!0}),X.RequestStreamResponderStream=X.RequestStreamRequesterStream=void 0;var s=F(),o=D(),a=p(),i=r(B()),u=function(){function e(e,t,r,n,s){this.payload=e,this.receiver=t,this.fragmentSize=r,this.initialRequestN=n,this.leaseManager=s,this.streamType=a.FrameTypes.REQUEST_STREAM}return e.prototype.handleReady=function(e,t){var r,s;if(this.done)return!1;if(this.streamId=e,this.stream=t,t.connect(this),(0,o.isFragmentable)(this.payload,this.fragmentSize,a.FrameTypes.REQUEST_STREAM))try{for(var i=n((0,o.fragmentWithRequestN)(e,this.payload,this.fragmentSize,a.FrameTypes.REQUEST_STREAM,this.initialRequestN)),u=i.next();!u.done;u=i.next()){var l=u.value;this.stream.send(l)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(s=i.return)&&s.call(i)}finally{if(r)throw r.error}}else this.stream.send({type:a.FrameTypes.REQUEST_STREAM,data:this.payload.data,metadata:this.payload.metadata,requestN:this.initialRequestN,flags:void 0!==this.payload.metadata?a.Flags.METADATA:0,streamId:e});return this.hasExtension&&this.stream.send({type:a.FrameTypes.EXT,streamId:e,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},e.prototype.handleReject=function(e){this.done||(this.done=!0,this.receiver.onError(e))},e.prototype.handle=function(e){var t,r=e.type;switch(r){case a.FrameTypes.PAYLOAD:var n=a.Flags.hasComplete(e.flags),o=a.Flags.hasNext(e.flags);if(n||!a.Flags.hasFollows(e.flags)){if(n&&(this.done=!0,this.stream.disconnect(this),!o))return void this.receiver.onComplete();var u=this.hasFragments?i.reassemble(this,e.data,e.metadata):{data:e.data,metadata:e.metadata};return void this.receiver.onNext(u,n)}if(!i.add(this,e.data,e.metadata)){t="Unexpected fragment size";break}return;case a.FrameTypes.ERROR:return this.done=!0,this.stream.disconnect(this),i.cancel(this),void this.receiver.onError(new s.RSocketError(e.code,e.message));case a.FrameTypes.EXT:if(this.hasFragments){t="Unexpected frame type [".concat(r,"] during reassembly");break}return void this.receiver.onExtension(e.extendedType,e.extendedContent,a.Flags.hasIgnore(e.flags));default:t="Unexpected frame type [".concat(r,"]")}this.close(new s.RSocketError(s.ErrorCodes.CANCELED,t)),this.stream.send({type:a.FrameTypes.CANCEL,streamId:this.streamId,flags:a.Flags.NONE}),this.stream.disconnect(this)},e.prototype.request=function(e){this.done||(this.streamId?this.stream.send({type:a.FrameTypes.REQUEST_N,flags:a.Flags.NONE,requestN:e,streamId:this.streamId}):this.initialRequestN+=e)},e.prototype.cancel=function(){var e;this.done||(this.done=!0,this.streamId?(this.stream.send({type:a.FrameTypes.CANCEL,flags:a.Flags.NONE,streamId:this.streamId}),this.stream.disconnect(this),i.cancel(this)):null===(e=this.leaseManager)||void 0===e||e.cancelRequest(this))},e.prototype.onExtension=function(e,t,r){if(!this.done)return this.streamId?void this.stream.send({streamId:this.streamId,type:a.FrameTypes.EXT,extendedType:e,extendedContent:t,flags:r?a.Flags.IGNORE:a.Flags.NONE}):(this.hasExtension=!0,this.extendedType=e,this.extendedContent=t,void(this.flags=r?a.Flags.IGNORE:a.Flags.NONE))},e.prototype.close=function(e){this.done||(this.done=!0,i.cancel(this),e?this.receiver.onError(e):this.receiver.onComplete())},e}();X.RequestStreamRequesterStream=u;var l=function(){function e(e,t,r,n,s){if(this.streamId=e,this.stream=t,this.fragmentSize=r,this.handler=n,this.streamType=a.FrameTypes.REQUEST_STREAM,t.connect(this),a.Flags.hasFollows(s.flags))return this.initialRequestN=s.requestN,void i.add(this,s.data,s.metadata);var o={data:s.data,metadata:s.metadata};try{this.receiver=n(o,s.requestN,this)}catch(e){this.onError(e)}}return e.prototype.handle=function(e){var t,r;if(!this.receiver||this.hasFragments)if(e.type===a.FrameTypes.PAYLOAD){if(!a.Flags.hasFollows(e.flags)){var n=i.reassemble(this,e.data,e.metadata);try{this.receiver=this.handler(n,this.initialRequestN,this)}catch(e){this.onError(e)}return}if(i.add(this,e.data,e.metadata))return;r="Unexpected frame size"}else r="Unexpected frame type [".concat(e.type,"] during reassembly");else{if(e.type===a.FrameTypes.REQUEST_N)return void this.receiver.request(e.requestN);if(e.type===a.FrameTypes.EXT)return void this.receiver.onExtension(e.extendedType,e.extendedContent,a.Flags.hasIgnore(e.flags));r="Unexpected frame type [".concat(e.type,"]")}this.done=!0,i.cancel(this),null===(t=this.receiver)||void 0===t||t.cancel(),e.type!==a.FrameTypes.CANCEL&&e.type!==a.FrameTypes.ERROR&&this.stream.send({type:a.FrameTypes.ERROR,flags:a.Flags.NONE,code:s.ErrorCodes.CANCELED,message:r,streamId:this.streamId}),this.stream.disconnect(this)},e.prototype.onError=function(e){this.done?console.warn("Trying to error for the second time. ".concat(e?"Dropping error [".concat(e,"]."):"")):(this.done=!0,this.stream.send({type:a.FrameTypes.ERROR,flags:a.Flags.NONE,code:e instanceof s.RSocketError?e.code:s.ErrorCodes.APPLICATION_ERROR,message:e.message,streamId:this.streamId}),this.stream.disconnect(this))},e.prototype.onNext=function(e,t){var r,s;if(!this.done){if(t&&(this.done=!0),(0,o.isFragmentable)(e,this.fragmentSize,a.FrameTypes.PAYLOAD))try{for(var i=n((0,o.fragment)(this.streamId,e,this.fragmentSize,a.FrameTypes.PAYLOAD,t)),u=i.next();!u.done;u=i.next()){var l=u.value;this.stream.send(l)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(s=i.return)&&s.call(i)}finally{if(r)throw r.error}}else this.stream.send({type:a.FrameTypes.PAYLOAD,flags:a.Flags.NEXT|(t?a.Flags.COMPLETE:a.Flags.NONE)|(e.metadata?a.Flags.METADATA:a.Flags.NONE),data:e.data,metadata:e.metadata,streamId:this.streamId});t&&this.stream.disconnect(this)}},e.prototype.onComplete=function(){this.done||(this.done=!0,this.stream.send({type:a.FrameTypes.PAYLOAD,flags:a.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.stream.disconnect(this))},e.prototype.onExtension=function(e,t,r){this.done||this.stream.send({type:a.FrameTypes.EXT,streamId:this.streamId,flags:r?a.Flags.IGNORE:a.Flags.NONE,extendedType:e,extendedContent:t})},e.prototype.close=function(e){var t;this.done?console.warn("Trying to close for the second time. ".concat(e?"Dropping error [".concat(e,"]."):"")):(i.cancel(this),null===(t=this.receiver)||void 0===t||t.cancel())},e}();return X.RequestStreamResponderStream=l,X}(),a=function(){function e(e,t,r){this.connection=e,this.fragmentSize=t,this.leaseManager=r}return e.prototype.fireAndForget=function(e,t){var r=new n.RequestFnFRequesterStream(e,t,this.fragmentSize,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(r):this.connection.multiplexerDemultiplexer.createRequestStream(r),r},e.prototype.requestResponse=function(e,t){var r=new s.RequestResponseRequesterStream(e,t,this.fragmentSize,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(r):this.connection.multiplexerDemultiplexer.createRequestStream(r),r},e.prototype.requestStream=function(e,t,r){var n=new o.RequestStreamRequesterStream(e,r,this.fragmentSize,t,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(n):this.connection.multiplexerDemultiplexer.createRequestStream(n),n},e.prototype.requestChannel=function(e,t,n,s){var o=new r.RequestChannelRequesterStream(e,n,s,this.fragmentSize,t,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(o):this.connection.multiplexerDemultiplexer.createRequestStream(o),o},e.prototype.metadataPush=function(e,t){throw new Error("Method not implemented.")},e.prototype.close=function(e){this.connection.close(e)},e.prototype.onClose=function(e){this.connection.onClose(e)},e}();C.RSocketRequester=a;var i=function(){function t(e,t){this.maxPendingRequests=e,this.multiplexer=t,this.pendingRequests=[],this.expirationTime=0,this.availableLease=0}return t.prototype.handle=function(e){for(this.expirationTime=e.ttl+Date.now(),this.availableLease=e.requestCount;this.availableLease>0&&this.pendingRequests.length>0;){var t=this.pendingRequests.shift();this.availableLease--,this.multiplexer.createRequestStream(t)}},t.prototype.requestLease=function(t){var r=this.availableLease;if(r>0&&Date.now()=this.maxPendingRequests?t.handleReject(new e.RSocketError(e.ErrorCodes.REJECTED,"No available lease given")):this.pendingRequests.push(t)},t.prototype.cancelRequest=function(e){var t=this.pendingRequests.indexOf(e);t>-1&&this.pendingRequests.splice(t,1)},t}();C.LeaseHandler=i;var u=function(){function a(e,t){this.rsocket=e,this.fragmentSize=t}return a.prototype.handle=function(e,a){switch(e.type){case t.FrameTypes.REQUEST_FNF:return void(this.rsocket.fireAndForget&&new n.RequestFnfResponderStream(e.streamId,a,this.rsocket.fireAndForget.bind(this.rsocket),e));case t.FrameTypes.REQUEST_RESPONSE:return this.rsocket.requestResponse?void new s.RequestResponseResponderStream(e.streamId,a,this.fragmentSize,this.rsocket.requestResponse.bind(this.rsocket),e):void this.rejectRequest(e.streamId,a);case t.FrameTypes.REQUEST_STREAM:return this.rsocket.requestStream?void new o.RequestStreamResponderStream(e.streamId,a,this.fragmentSize,this.rsocket.requestStream.bind(this.rsocket),e):void this.rejectRequest(e.streamId,a);case t.FrameTypes.REQUEST_CHANNEL:return this.rsocket.requestChannel?void new r.RequestChannelResponderStream(e.streamId,a,this.fragmentSize,this.rsocket.requestChannel.bind(this.rsocket),e):void this.rejectRequest(e.streamId,a)}},a.prototype.rejectRequest=function(r,n){n.send({type:t.FrameTypes.ERROR,streamId:r,flags:t.Flags.NONE,code:e.ErrorCodes.REJECTED,message:"No available handler found"})},a.prototype.close=function(){},a}();C.DefaultStreamRequestHandler=u;var l,c=function(){function r(e,t,r,n,s){this.connection=e,this.keepAliveHandler=t,this.keepAliveSender=r,this.leaseHandler=n,this.rsocket=s}return r.prototype.handle=function(r){switch(r.type){case t.FrameTypes.KEEPALIVE:return void this.keepAliveHandler.handle(r);case t.FrameTypes.LEASE:return this.leaseHandler?void this.leaseHandler.handle(r):void 0;case t.FrameTypes.ERROR:return void this.connection.close(new e.RSocketError(r.code,r.message));case t.FrameTypes.METADATA_PUSH:return void this.rsocket.metadataPush;default:this.connection.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,flags:t.Flags.NONE,message:"Received unknown frame type",code:e.ErrorCodes.CONNECTION_ERROR})}},r.prototype.pause=function(){var e;this.keepAliveHandler.pause(),null===(e=this.keepAliveSender)||void 0===e||e.pause()},r.prototype.resume=function(){var e;this.keepAliveHandler.start(),null===(e=this.keepAliveSender)||void 0===e||e.start()},r.prototype.close=function(e){var t;this.keepAliveHandler.close(),null===(t=this.rsocket.close)||void 0===t||t.call(this.rsocket,e)},r}();C.DefaultConnectionFrameHandler=c,function(e){e[e.Paused=0]="Paused",e[e.Running=1]="Running",e[e.Closed=2]="Closed"}(l||(l={}));var d,f=function(){function e(e,t){this.connection=e,this.keepAliveTimeoutDuration=t,this.state=l.Paused,this.outbound=e.multiplexerDemultiplexer.connectionOutbound}return e.prototype.handle=function(e){this.keepAliveLastReceivedMillis=Date.now(),t.Flags.hasRespond(e.flags)&&this.outbound.send({type:t.FrameTypes.KEEPALIVE,streamId:0,data:e.data,flags:e.flags^t.Flags.RESPOND,lastReceivedPosition:0})},e.prototype.start=function(){this.state===l.Paused&&(this.keepAliveLastReceivedMillis=Date.now(),this.state=l.Running,this.activeTimeout=setTimeout(this.timeoutCheck.bind(this),this.keepAliveTimeoutDuration))},e.prototype.pause=function(){this.state===l.Running&&(this.state=l.Paused,clearTimeout(this.activeTimeout))},e.prototype.close=function(){this.state=l.Closed,clearTimeout(this.activeTimeout)},e.prototype.timeoutCheck=function(){var e=Date.now()-this.keepAliveLastReceivedMillis;e>=this.keepAliveTimeoutDuration?this.connection.close(new Error("No keep-alive acks for ".concat(this.keepAliveTimeoutDuration," millis"))):this.activeTimeout=setTimeout(this.timeoutCheck.bind(this),Math.max(100,this.keepAliveTimeoutDuration-e))},e}();C.KeepAliveHandler=f,function(e){e[e.Paused=0]="Paused",e[e.Running=1]="Running",e[e.Closed=2]="Closed"}(d||(d={}));var h=function(){function e(e,t){this.outbound=e,this.keepAlivePeriodDuration=t,this.state=d.Paused}return e.prototype.sendKeepAlive=function(){this.outbound.send({type:t.FrameTypes.KEEPALIVE,streamId:0,data:void 0,flags:t.Flags.RESPOND,lastReceivedPosition:0})},e.prototype.start=function(){this.state===d.Paused&&(this.state=d.Running,this.activeInterval=setInterval(this.sendKeepAlive.bind(this),this.keepAlivePeriodDuration))},e.prototype.pause=function(){this.state===d.Running&&(this.state=d.Paused,clearInterval(this.activeInterval))},e.prototype.close=function(){this.state=d.Closed,clearInterval(this.activeInterval)},e}();return C.KeepAliveSender=h,C}var V,G,K={};function W(){if(V)return K;V=1;var e=K&&K.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(K,"__esModule",{value:!0}),K.FrameStore=void 0;var t=se(),r=m(),n=function(){function n(){this.storedFrames=[],this._lastReceivedFramePosition=0,this._firstAvailableFramePosition=0,this._lastSentFramePosition=0}return Object.defineProperty(n.prototype,"lastReceivedFramePosition",{get:function(){return this._lastReceivedFramePosition},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"firstAvailableFramePosition",{get:function(){return this._firstAvailableFramePosition},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"lastSentFramePosition",{get:function(){return this._lastSentFramePosition},enumerable:!1,configurable:!0}),n.prototype.store=function(e){this._lastSentFramePosition+=(0,r.sizeOfFrame)(e),this.storedFrames.push(e)},n.prototype.record=function(e){this._lastReceivedFramePosition+=(0,r.sizeOfFrame)(e)},n.prototype.dropTo=function(e){for(var n=e-this._firstAvailableFramePosition;n>0&&this.storedFrames.length>0;){var s=this.storedFrames.shift();n-=(0,r.sizeOfFrame)(s)}if(0!==n)throw new t.RSocketError(t.ErrorCodes.CONNECTION_ERROR,"State inconsistency. Expected bytes to drop ".concat(e-this._firstAvailableFramePosition," but actual ").concat(n));this._firstAvailableFramePosition=e},n.prototype.drain=function(t){var r,n;try{for(var s=e(this.storedFrames),o=s.next();!o.done;o=s.next()){t(o.value)}}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}},n}();return K.FrameStore=n,K}function $(){if(G)return O;G=1;var e=O&&O.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(s,o){function a(e){try{u(n.next(e))}catch(e){o(e)}}function i(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(a,i)}u((n=n.apply(e,t||[])).next())})},t=O&&O.__generator||function(e,t){var r,n,s,o,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(s=2&o[0]?n.return:o[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,o[1])).done)return s;switch(n=0,s&&(o=[2&o[0],s.value]),o[0]){case 0:case 1:s=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(s=a.trys,(s=s.length>0&&s[s.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]0&&s[s.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!s||o[1]>s[0]&&o[1]{m.countOutstandingEvents<=5&&(p=!1,b())}});let y=!1,E=!1,g=c,v=null;const T=()=>{y||(y=!0,clearTimeout(d),f&&f.close(),h&&h.close(),m.notify(null))};function b(){const e=c-g;!p&&e>0&&(v?.request(e),g=c)}if(n.aborted)throw new this.#e.AbortOperation("Connection request aborted");n.addEventListener("abort",T);const R=()=>{clearTimeout(d),d=setTimeout(()=>{e.logger.log({level:this.#e.LogLevels.error,message:"No data received on WebSocket in 30000ms, closing connection."}),T()},3e4)};R();const F=new ue.RSocketConnector({transport:new ye.WebsocketClientTransport({url:r.url,wsCreator:t=>{const r=f=e.createSocket(t);return r.addEventListener("message",()=>{R()}),r}}),setup:{keepAlive:2e4,lifetime:9e4,dataMimeType:o,metadataMimeType:o,payload:{data:null,metadata:l({token:r.headers.Authorization,user_agent:a})}}});try{h=await F.connect(),f=null}catch(t){throw e.logger.log({level:this.#e.LogLevels.error,message:"Failed to connect WebSocket",error:t}),T(),t}return R(),h.onClose(()=>h=null),await new Promise((t,o)=>{const a={next:async()=>{if(y)return u;const e=await m.waitForEvent(n);return y?u:{done:!1,value:e}}};v=h.requestStream({data:l(s),metadata:l({path:r.path})},c,{onError:t=>{t.message.includes("PSYNC_")?t.message.includes("PSYNC_S21")&&e.invalidateCredentials():"Closed. "!==t.message&&e.invalidateCredentials(),"Closed. "!==t.message&&e.logger.log({level:this.#e.LogLevels.error,message:"RSocket error",error:t}),T(),E||o(t)},onNext:e=>{E||(E=!0,t(a));const{data:r}=e;var n;r&&(n=r,m.notify(n),m.countOutstandingEvents>=10&&(p=!0)),g--,b()},onComplete:()=>{T()},onExtension:()=>{}})})}}export{Ee as WebSocketSupport}; //# sourceMappingURL=websockets-Q8W_lerF.js.map