@powersync/common 1.20.0 → 1.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.mjs
CHANGED
|
@@ -14,4 +14,4 @@ read:function(l,n,u,e,t){var r,o,i=8*t-e-1,a=(1<<i)-1,s=a>>1,c=-7,d=u?t-1:0,h=u?
|
|
|
14
14
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
15
15
|
* @license MIT
|
|
16
16
|
*/
|
|
17
|
-
!function(l){var n=Me,u=Ve,e="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;l.Buffer=o,l.SlowBuffer=function(l){+l!=l&&(l=0);return o.alloc(+l)},l.INSPECT_MAX_BYTES=50;var t=2147483647;function r(l){if(l>t)throw new RangeError('The value "'+l+'" is invalid for option "size"');var n=new Uint8Array(l);return Object.setPrototypeOf(n,o.prototype),n}function o(l,n,u){if("number"==typeof l){if("string"==typeof n)throw new TypeError('The "string" argument must be of type string. Received type number');return s(l)}return i(l,n,u)}function i(l,n,u){if("string"==typeof l)return function(l,n){"string"==typeof n&&""!==n||(n="utf8");if(!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);var u=0|f(l,n),e=r(u),t=e.write(l,n);t!==u&&(e=e.slice(0,t));return e}(l,n);if(ArrayBuffer.isView(l))return function(l){if(M(l,Uint8Array)){var n=new Uint8Array(l);return d(n.buffer,n.byteOffset,n.byteLength)}return c(l)}(l);if(null==l)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof l);if(M(l,ArrayBuffer)||l&&M(l.buffer,ArrayBuffer))return d(l,n,u);if("undefined"!=typeof SharedArrayBuffer&&(M(l,SharedArrayBuffer)||l&&M(l.buffer,SharedArrayBuffer)))return d(l,n,u);if("number"==typeof l)throw new TypeError('The "value" argument must not be of type number. Received type number');var e=l.valueOf&&l.valueOf();if(null!=e&&e!==l)return o.from(e,n,u);var t=function(l){if(o.isBuffer(l)){var n=0|h(l.length),u=r(n);return 0===u.length||l.copy(u,0,0,n),u}if(void 0!==l.length)return"number"!=typeof l.length||q(l.length)?r(0):c(l);if("Buffer"===l.type&&Array.isArray(l.data))return c(l.data)}(l);if(t)return t;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof l[Symbol.toPrimitive])return o.from(l[Symbol.toPrimitive]("string"),n,u);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof l)}function a(l){if("number"!=typeof l)throw new TypeError('"size" argument must be of type number');if(l<0)throw new RangeError('The value "'+l+'" is invalid for option "size"')}function s(l){return a(l),r(l<0?0:0|h(l))}function c(l){for(var n=l.length<0?0:0|h(l.length),u=r(n),e=0;e<n;e+=1)u[e]=255&l[e];return u}function d(l,n,u){if(n<0||l.byteLength<n)throw new RangeError('"offset" is outside of buffer bounds');if(l.byteLength<n+(u||0))throw new RangeError('"length" is outside of buffer bounds');var e;return e=void 0===n&&void 0===u?new Uint8Array(l):void 0===u?new Uint8Array(l,n):new Uint8Array(l,n,u),Object.setPrototypeOf(e,o.prototype),e}function h(l){if(l>=t)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+t.toString(16)+" bytes");return 0|l}function f(l,n){if(o.isBuffer(l))return l.length;if(ArrayBuffer.isView(l)||M(l,ArrayBuffer))return l.byteLength;if("string"!=typeof l)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof l);var u=l.length,e=arguments.length>2&&!0===arguments[2];if(!e&&0===u)return 0;for(var t=!1;;)switch(n){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return U(l).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*u;case"hex":return u>>>1;case"base64":return B(l).length;default:if(t)return e?-1:U(l).length;n=(""+n).toLowerCase(),t=!0}}function p(l,n,u){var e=!1;if((void 0===n||n<0)&&(n=0),n>this.length)return"";if((void 0===u||u>this.length)&&(u=this.length),u<=0)return"";if((u>>>=0)<=(n>>>=0))return"";for(l||(l="utf8");;)switch(l){case"hex":return C(this,n,u);case"utf8":case"utf-8":return T(this,n,u);case"ascii":return O(this,n,u);case"latin1":case"binary":return A(this,n,u);case"base64":return S(this,n,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return F(this,n,u);default:if(e)throw new TypeError("Unknown encoding: "+l);l=(l+"").toLowerCase(),e=!0}}function y(l,n,u){var e=l[n];l[n]=l[u],l[u]=e}function m(l,n,u,e,t){if(0===l.length)return-1;if("string"==typeof u?(e=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),q(u=+u)&&(u=t?0:l.length-1),u<0&&(u=l.length+u),u>=l.length){if(t)return-1;u=l.length-1}else if(u<0){if(!t)return-1;u=0}if("string"==typeof n&&(n=o.from(n,e)),o.isBuffer(n))return 0===n.length?-1:g(l,n,u,e,t);if("number"==typeof n)return n&=255,"function"==typeof Uint8Array.prototype.indexOf?t?Uint8Array.prototype.indexOf.call(l,n,u):Uint8Array.prototype.lastIndexOf.call(l,n,u):g(l,[n],u,e,t);throw new TypeError("val must be string, number or Buffer")}function g(l,n,u,e,t){var r,o=1,i=l.length,a=n.length;if(void 0!==e&&("ucs2"===(e=String(e).toLowerCase())||"ucs-2"===e||"utf16le"===e||"utf-16le"===e)){if(l.length<2||n.length<2)return-1;o=2,i/=2,a/=2,u/=2}function s(l,n){return 1===o?l[n]:l.readUInt16BE(n*o)}if(t){var c=-1;for(r=u;r<i;r++)if(s(l,r)===s(n,-1===c?0:r-c)){if(-1===c&&(c=r),r-c+1===a)return c*o}else-1!==c&&(r-=r-c),c=-1}else for(u+a>i&&(u=i-a),r=u;r>=0;r--){for(var d=!0,h=0;h<a;h++)if(s(l,r+h)!==s(n,h)){d=!1;break}if(d)return r}return-1}function b(l,n,u,e){u=Number(u)||0;var t=l.length-u;e?(e=Number(e))>t&&(e=t):e=t;var r=n.length;e>r/2&&(e=r/2);for(var o=0;o<e;++o){var i=parseInt(n.substr(2*o,2),16);if(q(i))return o;l[u+o]=i}return o}function v(l,n,u,e){return D(U(n,l.length-u),l,u,e)}function E(l,n,u,e){return D(function(l){for(var n=[],u=0;u<l.length;++u)n.push(255&l.charCodeAt(u));return n}(n),l,u,e)}function w(l,n,u,e){return D(B(n),l,u,e)}function _(l,n,u,e){return D(function(l,n){for(var u,e,t,r=[],o=0;o<l.length&&!((n-=2)<0);++o)e=(u=l.charCodeAt(o))>>8,t=u%256,r.push(t),r.push(e);return r}(n,l.length-u),l,u,e)}function S(l,u,e){return 0===u&&e===l.length?n.fromByteArray(l):n.fromByteArray(l.slice(u,e))}function T(l,n,u){u=Math.min(l.length,u);for(var e=[],t=n;t<u;){var r,o,i,a,s=l[t],c=null,d=s>239?4:s>223?3:s>191?2:1;if(t+d<=u)switch(d){case 1:s<128&&(c=s);break;case 2:128==(192&(r=l[t+1]))&&(a=(31&s)<<6|63&r)>127&&(c=a);break;case 3:r=l[t+1],o=l[t+2],128==(192&r)&&128==(192&o)&&(a=(15&s)<<12|(63&r)<<6|63&o)>2047&&(a<55296||a>57343)&&(c=a);break;case 4:r=l[t+1],o=l[t+2],i=l[t+3],128==(192&r)&&128==(192&o)&&128==(192&i)&&(a=(15&s)<<18|(63&r)<<12|(63&o)<<6|63&i)>65535&&a<1114112&&(c=a)}null===c?(c=65533,d=1):c>65535&&(c-=65536,e.push(c>>>10&1023|55296),c=56320|1023&c),e.push(c),t+=d}return function(l){var n=l.length;if(n<=R)return String.fromCharCode.apply(String,l);var u="",e=0;for(;e<n;)u+=String.fromCharCode.apply(String,l.slice(e,e+=R));return u}(e)}l.kMaxLength=t,o.TYPED_ARRAY_SUPPORT=function(){try{var l=new Uint8Array(1),n={foo:function(){return 42}};return Object.setPrototypeOf(n,Uint8Array.prototype),Object.setPrototypeOf(l,n),42===l.foo()}catch(l){return!1}}(),o.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(l,n,u){return i(l,n,u)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(l,n,u){return function(l,n,u){return a(l),l<=0?r(l):void 0!==n?"string"==typeof u?r(l).fill(n,u):r(l).fill(n):r(l)}(l,n,u)},o.allocUnsafe=function(l){return s(l)},o.allocUnsafeSlow=function(l){return s(l)},o.isBuffer=function(l){return null!=l&&!0===l._isBuffer&&l!==o.prototype},o.compare=function(l,n){if(M(l,Uint8Array)&&(l=o.from(l,l.offset,l.byteLength)),M(n,Uint8Array)&&(n=o.from(n,n.offset,n.byteLength)),!o.isBuffer(l)||!o.isBuffer(n))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(l===n)return 0;for(var u=l.length,e=n.length,t=0,r=Math.min(u,e);t<r;++t)if(l[t]!==n[t]){u=l[t],e=n[t];break}return u<e?-1:e<u?1:0},o.isEncoding=function(l){switch(String(l).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(l,n){if(!Array.isArray(l))throw new TypeError('"list" argument must be an Array of Buffers');if(0===l.length)return o.alloc(0);var u;if(void 0===n)for(n=0,u=0;u<l.length;++u)n+=l[u].length;var e=o.allocUnsafe(n),t=0;for(u=0;u<l.length;++u){var r=l[u];if(M(r,Uint8Array))t+r.length>e.length?o.from(r).copy(e,t):Uint8Array.prototype.set.call(e,r,t);else{if(!o.isBuffer(r))throw new TypeError('"list" argument must be an Array of Buffers');r.copy(e,t)}t+=r.length}return e},o.byteLength=f,o.prototype._isBuffer=!0,o.prototype.swap16=function(){var l=this.length;if(l%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var n=0;n<l;n+=2)y(this,n,n+1);return this},o.prototype.swap32=function(){var l=this.length;if(l%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var n=0;n<l;n+=4)y(this,n,n+3),y(this,n+1,n+2);return this},o.prototype.swap64=function(){var l=this.length;if(l%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var n=0;n<l;n+=8)y(this,n,n+7),y(this,n+1,n+6),y(this,n+2,n+5),y(this,n+3,n+4);return this},o.prototype.toString=function(){var l=this.length;return 0===l?"":0===arguments.length?T(this,0,l):p.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(l){if(!o.isBuffer(l))throw new TypeError("Argument must be a Buffer");return this===l||0===o.compare(this,l)},o.prototype.inspect=function(){var n="",u=l.INSPECT_MAX_BYTES;return n=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(n+=" ... "),"<Buffer "+n+">"},e&&(o.prototype[e]=o.prototype.inspect),o.prototype.compare=function(l,n,u,e,t){if(M(l,Uint8Array)&&(l=o.from(l,l.offset,l.byteLength)),!o.isBuffer(l))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof l);if(void 0===n&&(n=0),void 0===u&&(u=l?l.length:0),void 0===e&&(e=0),void 0===t&&(t=this.length),n<0||u>l.length||e<0||t>this.length)throw new RangeError("out of range index");if(e>=t&&n>=u)return 0;if(e>=t)return-1;if(n>=u)return 1;if(this===l)return 0;for(var r=(t>>>=0)-(e>>>=0),i=(u>>>=0)-(n>>>=0),a=Math.min(r,i),s=this.slice(e,t),c=l.slice(n,u),d=0;d<a;++d)if(s[d]!==c[d]){r=s[d],i=c[d];break}return r<i?-1:i<r?1:0},o.prototype.includes=function(l,n,u){return-1!==this.indexOf(l,n,u)},o.prototype.indexOf=function(l,n,u){return m(this,l,n,u,!0)},o.prototype.lastIndexOf=function(l,n,u){return m(this,l,n,u,!1)},o.prototype.write=function(l,n,u,e){if(void 0===n)e="utf8",u=this.length,n=0;else if(void 0===u&&"string"==typeof n)e=n,u=this.length,n=0;else{if(!isFinite(n))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");n>>>=0,isFinite(u)?(u>>>=0,void 0===e&&(e="utf8")):(e=u,u=void 0)}var t=this.length-n;if((void 0===u||u>t)&&(u=t),l.length>0&&(u<0||n<0)||n>this.length)throw new RangeError("Attempt to write outside buffer bounds");e||(e="utf8");for(var r=!1;;)switch(e){case"hex":return b(this,l,n,u);case"utf8":case"utf-8":return v(this,l,n,u);case"ascii":case"latin1":case"binary":return E(this,l,n,u);case"base64":return w(this,l,n,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,l,n,u);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(""+e).toLowerCase(),r=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var R=4096;function O(l,n,u){var e="";u=Math.min(l.length,u);for(var t=n;t<u;++t)e+=String.fromCharCode(127&l[t]);return e}function A(l,n,u){var e="";u=Math.min(l.length,u);for(var t=n;t<u;++t)e+=String.fromCharCode(l[t]);return e}function C(l,n,u){var e=l.length;(!n||n<0)&&(n=0),(!u||u<0||u>e)&&(u=e);for(var t="",r=n;r<u;++r)t+=j[l[r]];return t}function F(l,n,u){for(var e=l.slice(n,u),t="",r=0;r<e.length-1;r+=2)t+=String.fromCharCode(e[r]+256*e[r+1]);return t}function I(l,n,u){if(l%1!=0||l<0)throw new RangeError("offset is not uint");if(l+n>u)throw new RangeError("Trying to access beyond buffer length")}function k(l,n,u,e,t,r){if(!o.isBuffer(l))throw new TypeError('"buffer" argument must be a Buffer instance');if(n>t||n<r)throw new RangeError('"value" argument is out of bounds');if(u+e>l.length)throw new RangeError("Index out of range")}function P(l,n,u,e,t,r){if(u+e>l.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function L(l,n,e,t,r){return n=+n,e>>>=0,r||P(l,0,e,4),u.write(l,n,e,t,23,4),e+4}function N(l,n,e,t,r){return n=+n,e>>>=0,r||P(l,0,e,8),u.write(l,n,e,t,52,8),e+8}o.prototype.slice=function(l,n){var u=this.length;(l=~~l)<0?(l+=u)<0&&(l=0):l>u&&(l=u),(n=void 0===n?u:~~n)<0?(n+=u)<0&&(n=0):n>u&&(n=u),n<l&&(n=l);var e=this.subarray(l,n);return Object.setPrototypeOf(e,o.prototype),e},o.prototype.readUintLE=o.prototype.readUIntLE=function(l,n,u){l>>>=0,n>>>=0,u||I(l,n,this.length);for(var e=this[l],t=1,r=0;++r<n&&(t*=256);)e+=this[l+r]*t;return e},o.prototype.readUintBE=o.prototype.readUIntBE=function(l,n,u){l>>>=0,n>>>=0,u||I(l,n,this.length);for(var e=this[l+--n],t=1;n>0&&(t*=256);)e+=this[l+--n]*t;return e},o.prototype.readUint8=o.prototype.readUInt8=function(l,n){return l>>>=0,n||I(l,1,this.length),this[l]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(l,n){return l>>>=0,n||I(l,2,this.length),this[l]|this[l+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(l,n){return l>>>=0,n||I(l,2,this.length),this[l]<<8|this[l+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(l,n){return l>>>=0,n||I(l,4,this.length),(this[l]|this[l+1]<<8|this[l+2]<<16)+16777216*this[l+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(l,n){return l>>>=0,n||I(l,4,this.length),16777216*this[l]+(this[l+1]<<16|this[l+2]<<8|this[l+3])},o.prototype.readIntLE=function(l,n,u){l>>>=0,n>>>=0,u||I(l,n,this.length);for(var e=this[l],t=1,r=0;++r<n&&(t*=256);)e+=this[l+r]*t;return e>=(t*=128)&&(e-=Math.pow(2,8*n)),e},o.prototype.readIntBE=function(l,n,u){l>>>=0,n>>>=0,u||I(l,n,this.length);for(var e=n,t=1,r=this[l+--e];e>0&&(t*=256);)r+=this[l+--e]*t;return r>=(t*=128)&&(r-=Math.pow(2,8*n)),r},o.prototype.readInt8=function(l,n){return l>>>=0,n||I(l,1,this.length),128&this[l]?-1*(255-this[l]+1):this[l]},o.prototype.readInt16LE=function(l,n){l>>>=0,n||I(l,2,this.length);var u=this[l]|this[l+1]<<8;return 32768&u?4294901760|u:u},o.prototype.readInt16BE=function(l,n){l>>>=0,n||I(l,2,this.length);var u=this[l+1]|this[l]<<8;return 32768&u?4294901760|u:u},o.prototype.readInt32LE=function(l,n){return l>>>=0,n||I(l,4,this.length),this[l]|this[l+1]<<8|this[l+2]<<16|this[l+3]<<24},o.prototype.readInt32BE=function(l,n){return l>>>=0,n||I(l,4,this.length),this[l]<<24|this[l+1]<<16|this[l+2]<<8|this[l+3]},o.prototype.readFloatLE=function(l,n){return l>>>=0,n||I(l,4,this.length),u.read(this,l,!0,23,4)},o.prototype.readFloatBE=function(l,n){return l>>>=0,n||I(l,4,this.length),u.read(this,l,!1,23,4)},o.prototype.readDoubleLE=function(l,n){return l>>>=0,n||I(l,8,this.length),u.read(this,l,!0,52,8)},o.prototype.readDoubleBE=function(l,n){return l>>>=0,n||I(l,8,this.length),u.read(this,l,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(l,n,u,e){(l=+l,n>>>=0,u>>>=0,e)||k(this,l,n,u,Math.pow(2,8*u)-1,0);var t=1,r=0;for(this[n]=255&l;++r<u&&(t*=256);)this[n+r]=l/t&255;return n+u},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(l,n,u,e){(l=+l,n>>>=0,u>>>=0,e)||k(this,l,n,u,Math.pow(2,8*u)-1,0);var t=u-1,r=1;for(this[n+t]=255&l;--t>=0&&(r*=256);)this[n+t]=l/r&255;return n+u},o.prototype.writeUint8=o.prototype.writeUInt8=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,1,255,0),this[n]=255&l,n+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,2,65535,0),this[n]=255&l,this[n+1]=l>>>8,n+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,2,65535,0),this[n]=l>>>8,this[n+1]=255&l,n+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,4,4294967295,0),this[n+3]=l>>>24,this[n+2]=l>>>16,this[n+1]=l>>>8,this[n]=255&l,n+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,4,4294967295,0),this[n]=l>>>24,this[n+1]=l>>>16,this[n+2]=l>>>8,this[n+3]=255&l,n+4},o.prototype.writeIntLE=function(l,n,u,e){if(l=+l,n>>>=0,!e){var t=Math.pow(2,8*u-1);k(this,l,n,u,t-1,-t)}var r=0,o=1,i=0;for(this[n]=255&l;++r<u&&(o*=256);)l<0&&0===i&&0!==this[n+r-1]&&(i=1),this[n+r]=(l/o|0)-i&255;return n+u},o.prototype.writeIntBE=function(l,n,u,e){if(l=+l,n>>>=0,!e){var t=Math.pow(2,8*u-1);k(this,l,n,u,t-1,-t)}var r=u-1,o=1,i=0;for(this[n+r]=255&l;--r>=0&&(o*=256);)l<0&&0===i&&0!==this[n+r+1]&&(i=1),this[n+r]=(l/o|0)-i&255;return n+u},o.prototype.writeInt8=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,1,127,-128),l<0&&(l=255+l+1),this[n]=255&l,n+1},o.prototype.writeInt16LE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,2,32767,-32768),this[n]=255&l,this[n+1]=l>>>8,n+2},o.prototype.writeInt16BE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,2,32767,-32768),this[n]=l>>>8,this[n+1]=255&l,n+2},o.prototype.writeInt32LE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,4,2147483647,-2147483648),this[n]=255&l,this[n+1]=l>>>8,this[n+2]=l>>>16,this[n+3]=l>>>24,n+4},o.prototype.writeInt32BE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,4,2147483647,-2147483648),l<0&&(l=4294967295+l+1),this[n]=l>>>24,this[n+1]=l>>>16,this[n+2]=l>>>8,this[n+3]=255&l,n+4},o.prototype.writeFloatLE=function(l,n,u){return L(this,l,n,!0,u)},o.prototype.writeFloatBE=function(l,n,u){return L(this,l,n,!1,u)},o.prototype.writeDoubleLE=function(l,n,u){return N(this,l,n,!0,u)},o.prototype.writeDoubleBE=function(l,n,u){return N(this,l,n,!1,u)},o.prototype.copy=function(l,n,u,e){if(!o.isBuffer(l))throw new TypeError("argument should be a Buffer");if(u||(u=0),e||0===e||(e=this.length),n>=l.length&&(n=l.length),n||(n=0),e>0&&e<u&&(e=u),e===u)return 0;if(0===l.length||0===this.length)return 0;if(n<0)throw new RangeError("targetStart out of bounds");if(u<0||u>=this.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("sourceEnd out of bounds");e>this.length&&(e=this.length),l.length-n<e-u&&(e=l.length-n+u);var t=e-u;return this===l&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(n,u,e):Uint8Array.prototype.set.call(l,this.subarray(u,e),n),t},o.prototype.fill=function(l,n,u,e){if("string"==typeof l){if("string"==typeof n?(e=n,n=0,u=this.length):"string"==typeof u&&(e=u,u=this.length),void 0!==e&&"string"!=typeof e)throw new TypeError("encoding must be a string");if("string"==typeof e&&!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);if(1===l.length){var t=l.charCodeAt(0);("utf8"===e&&t<128||"latin1"===e)&&(l=t)}}else"number"==typeof l?l&=255:"boolean"==typeof l&&(l=Number(l));if(n<0||this.length<n||this.length<u)throw new RangeError("Out of range index");if(u<=n)return this;var r;if(n>>>=0,u=void 0===u?this.length:u>>>0,l||(l=0),"number"==typeof l)for(r=n;r<u;++r)this[r]=l;else{var i=o.isBuffer(l)?l:o.from(l,e),a=i.length;if(0===a)throw new TypeError('The value "'+l+'" is invalid for argument "value"');for(r=0;r<u-n;++r)this[r+n]=i[r%a]}return this};var x=/[^+/0-9A-Za-z-_]/g;function U(l,n){var u;n=n||1/0;for(var e=l.length,t=null,r=[],o=0;o<e;++o){if((u=l.charCodeAt(o))>55295&&u<57344){if(!t){if(u>56319){(n-=3)>-1&&r.push(239,191,189);continue}if(o+1===e){(n-=3)>-1&&r.push(239,191,189);continue}t=u;continue}if(u<56320){(n-=3)>-1&&r.push(239,191,189),t=u;continue}u=65536+(t-55296<<10|u-56320)}else t&&(n-=3)>-1&&r.push(239,191,189);if(t=null,u<128){if((n-=1)<0)break;r.push(u)}else if(u<2048){if((n-=2)<0)break;r.push(u>>6|192,63&u|128)}else if(u<65536){if((n-=3)<0)break;r.push(u>>12|224,u>>6&63|128,63&u|128)}else{if(!(u<1114112))throw new Error("Invalid code point");if((n-=4)<0)break;r.push(u>>18|240,u>>12&63|128,u>>6&63|128,63&u|128)}}return r}function B(l){return n.toByteArray(function(l){if((l=(l=l.split("=")[0]).trim().replace(x,"")).length<2)return"";for(;l.length%4!=0;)l+="=";return l}(l))}function D(l,n,u,e){for(var t=0;t<e&&!(t+u>=n.length||t>=l.length);++t)n[t+u]=l[t];return t}function M(l,n){return l instanceof n||null!=l&&null!=l.constructor&&null!=l.constructor.name&&l.constructor.name===n.name}function q(l){return l!=l}var j=function(){for(var l="0123456789abcdef",n=new Array(256),u=0;u<16;++u)for(var e=16*u,t=0;t<16;++t)n[e+t]=l[u]+l[t];return n}()}(et);var tt,rt,ot,it,at,st={},ct={};tt=ct,Object.defineProperty(tt,"__esModule",{value:!0}),tt.Frame=tt.Lengths=tt.Flags=tt.FrameTypes=void 0,function(l){l[l.RESERVED=0]="RESERVED",l[l.SETUP=1]="SETUP",l[l.LEASE=2]="LEASE",l[l.KEEPALIVE=3]="KEEPALIVE",l[l.REQUEST_RESPONSE=4]="REQUEST_RESPONSE",l[l.REQUEST_FNF=5]="REQUEST_FNF",l[l.REQUEST_STREAM=6]="REQUEST_STREAM",l[l.REQUEST_CHANNEL=7]="REQUEST_CHANNEL",l[l.REQUEST_N=8]="REQUEST_N",l[l.CANCEL=9]="CANCEL",l[l.PAYLOAD=10]="PAYLOAD",l[l.ERROR=11]="ERROR",l[l.METADATA_PUSH=12]="METADATA_PUSH",l[l.RESUME=13]="RESUME",l[l.RESUME_OK=14]="RESUME_OK",l[l.EXT=63]="EXT"}(rt=tt.FrameTypes||(tt.FrameTypes={})),(ot=tt.Flags||(tt.Flags={}))[ot.NONE=0]="NONE",ot[ot.COMPLETE=64]="COMPLETE",ot[ot.FOLLOWS=128]="FOLLOWS",ot[ot.IGNORE=512]="IGNORE",ot[ot.LEASE=64]="LEASE",ot[ot.METADATA=256]="METADATA",ot[ot.NEXT=32]="NEXT",ot[ot.RESPOND=128]="RESPOND",ot[ot.RESUME_ENABLE=128]="RESUME_ENABLE",function(l){l.hasMetadata=function(n){return(n&l.METADATA)===l.METADATA},l.hasComplete=function(n){return(n&l.COMPLETE)===l.COMPLETE},l.hasNext=function(n){return(n&l.NEXT)===l.NEXT},l.hasFollows=function(n){return(n&l.FOLLOWS)===l.FOLLOWS},l.hasIgnore=function(n){return(n&l.IGNORE)===l.IGNORE},l.hasRespond=function(n){return(n&l.RESPOND)===l.RESPOND},l.hasLease=function(n){return(n&l.LEASE)===l.LEASE},l.hasResume=function(n){return(n&l.RESUME_ENABLE)===l.RESUME_ENABLE}}(tt.Flags||(tt.Flags={})),(it=tt.Lengths||(tt.Lengths={}))[it.FRAME=3]="FRAME",it[it.HEADER=6]="HEADER",it[it.METADATA=3]="METADATA",it[it.REQUEST=3]="REQUEST",(at=tt.Frame||(tt.Frame={})).isConnection=function(l){return 0===l.streamId},at.isRequest=function(l){return rt.REQUEST_RESPONSE<=l.type&&l.type<=rt.REQUEST_CHANNEL},function(l){var n=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(l,"__esModule",{value:!0}),l.Deserializer=l.sizeOfFrame=l.serializeFrame=l.deserializeFrame=l.serializeFrameWithLength=l.deserializeFrames=l.deserializeFrameWithLength=l.writeUInt64BE=l.readUInt64BE=l.writeUInt24BE=l.readUInt24BE=l.MAX_VERSION=l.MAX_TTL=l.MAX_STREAM_ID=l.MAX_RESUME_LENGTH=l.MAX_REQUEST_N=l.MAX_REQUEST_COUNT=l.MAX_MIME_LENGTH=l.MAX_METADATA_LENGTH=l.MAX_LIFETIME=l.MAX_KEEPALIVE=l.MAX_CODE=l.FRAME_TYPE_OFFFSET=l.FLAGS_MASK=void 0;var u=ct;l.FLAGS_MASK=1023,l.FRAME_TYPE_OFFFSET=10,l.MAX_CODE=2147483647,l.MAX_KEEPALIVE=2147483647,l.MAX_LIFETIME=2147483647,l.MAX_METADATA_LENGTH=16777215,l.MAX_MIME_LENGTH=255,l.MAX_REQUEST_COUNT=2147483647,l.MAX_REQUEST_N=2147483647,l.MAX_RESUME_LENGTH=65535,l.MAX_STREAM_ID=2147483647,l.MAX_TTL=2147483647,l.MAX_VERSION=65535;var e=4294967296;function t(l,n){return l.readUInt8(n)<<16|l.readUInt8(n+1)<<8|l.readUInt8(n+2)}function r(l,n,u){return u=l.writeUInt8(n>>>16,u),u=l.writeUInt8(n>>>8&255,u),l.writeUInt8(255&n,u)}function i(l,n){var u=l.readUInt32BE(n),t=l.readUInt32BE(n+4);return u*e+t}function a(l,n,u){var t=n/e|0,r=n%e;return u=l.writeUInt32BE(t,u),l.writeUInt32BE(r,u)}l.readUInt24BE=t,l.writeUInt24BE=r,l.readUInt64BE=i,l.writeUInt64BE=a;function s(l){var n=t(l,0);return d(l.slice(3,3+n))}function c(l){var u,e,r,o,i;return n(this,(function(n){switch(n.label){case 0:u=0,n.label=1;case 1:return u+3<l.length?(e=t(l,u),(o=(r=u+3)+e)>l.length?[3,3]:(i=l.slice(r,o),[4,[d(i),u=o]])):[3,3];case 2:return n.sent(),[3,1];case 3:return[2]}}))}function d(n){var e=0,t=n.readInt32BE(e);e+=4;var r=n.readUInt16BE(e);e+=2;var o=r>>>l.FRAME_TYPE_OFFFSET,a=r&l.FLAGS_MASK;switch(o){case u.FrameTypes.SETUP:return function(l,n,e){l.length;var t=6,r=l.readUInt16BE(t);t+=2;var o=l.readUInt16BE(t);t+=2;var i=l.readInt32BE(t);t+=4;var a=l.readInt32BE(t);t+=4;var s=null;if(e&u.Flags.RESUME_ENABLE){var c=l.readInt16BE(t);t+=2,s=l.slice(t,t+c),t+=c}var d=l.readUInt8(t);t+=1;var h=l.toString("ascii",t,t+d);t+=d;var f=l.readUInt8(t);t+=1;var p=l.toString("ascii",t,t+f);t+=f;var y={data:null,dataMimeType:p,flags:e,keepAlive:i,lifetime:a,majorVersion:r,metadata:null,metadataMimeType:h,minorVersion:o,resumeToken:s,streamId:0,type:u.FrameTypes.SETUP};return R(l,y,t),y}(n,0,a);case u.FrameTypes.PAYLOAD:return function(l,n,e){l.length;var t={data:null,flags:e,metadata:null,streamId:n,type:u.FrameTypes.PAYLOAD};return R(l,t,6),t}(n,t,a);case u.FrameTypes.ERROR:return function(l,n,e){l.length;var t=6,r=l.readInt32BE(t);t+=4;var o=l.length-t,i="";o>0&&(i=l.toString("utf8",t,t+o),t+=o);return{code:r,flags:e,message:i,streamId:n,type:u.FrameTypes.ERROR}}(n,t,a);case u.FrameTypes.KEEPALIVE:return function(l,n,e){l.length;var t=6,r=i(l,t);t+=8;var o=null;t<l.length&&(o=l.slice(t,l.length));return{data:o,flags:e,lastReceivedPosition:r,streamId:0,type:u.FrameTypes.KEEPALIVE}}(n,0,a);case u.FrameTypes.REQUEST_FNF:return function(l,n,e){l.length;var t={data:null,flags:e,metadata:null,streamId:n,type:u.FrameTypes.REQUEST_FNF};return R(l,t,6),t}(n,t,a);case u.FrameTypes.REQUEST_RESPONSE:return function(l,n,e){var t={data:null,flags:e,metadata:null,streamId:n,type:u.FrameTypes.REQUEST_RESPONSE};return R(l,t,6),t}(n,t,a);case u.FrameTypes.REQUEST_STREAM:return function(l,n,e){l.length;var t=6,r=l.readInt32BE(t);t+=4;var o={data:null,flags:e,metadata:null,requestN:r,streamId:n,type:u.FrameTypes.REQUEST_STREAM};return R(l,o,t),o}(n,t,a);case u.FrameTypes.REQUEST_CHANNEL:return function(l,n,e){l.length;var t=6,r=l.readInt32BE(t);t+=4;var o={data:null,flags:e,metadata:null,requestN:r,streamId:n,type:u.FrameTypes.REQUEST_CHANNEL};return R(l,o,t),o}(n,t,a);case u.FrameTypes.METADATA_PUSH:return function(l,n,e){return{flags:e,metadata:6===length?null:l.slice(6,length),streamId:0,type:u.FrameTypes.METADATA_PUSH}}(n,0,a);case u.FrameTypes.REQUEST_N:return function(l,n,e){l.length;var t=l.readInt32BE(6);return{flags:e,requestN:t,streamId:n,type:u.FrameTypes.REQUEST_N}}(n,t,a);case u.FrameTypes.RESUME:return function(l,n,e){l.length;var t=6,r=l.readUInt16BE(t);t+=2;var o=l.readUInt16BE(t);t+=2;var a=l.readInt16BE(t);t+=2;var s=l.slice(t,t+a);t+=a;var c=i(l,t);t+=8;var d=i(l,t);return t+=8,{clientPosition:d,flags:e,majorVersion:r,minorVersion:o,resumeToken:s,serverPosition:c,streamId:0,type:u.FrameTypes.RESUME}}(n,0,a);case u.FrameTypes.RESUME_OK:return function(l,n,e){l.length;var t=i(l,6);return{clientPosition:t,flags:e,streamId:0,type:u.FrameTypes.RESUME_OK}}(n,0,a);case u.FrameTypes.CANCEL:return function(l,n,e){return l.length,{flags:e,streamId:n,type:u.FrameTypes.CANCEL}}(n,t,a);case u.FrameTypes.LEASE:return function(l,n,e){var t=6,r=l.readUInt32BE(t);t+=4;var o=l.readUInt32BE(t);t+=4;var i=null;t<l.length&&(i=l.slice(t,l.length));return{flags:e,metadata:i,requestCount:o,streamId:0,ttl:r,type:u.FrameTypes.LEASE}}(n,0,a)}}function h(l){switch(l.type){case u.FrameTypes.SETUP:return function(l){var n=null!=l.resumeToken?l.resumeToken.byteLength:0,e=null!=l.metadataMimeType?et.Buffer.byteLength(l.metadataMimeType,"ascii"):0,t=null!=l.dataMimeType?et.Buffer.byteLength(l.dataMimeType,"ascii"):0,r=S(l),o=et.Buffer.allocUnsafe(6+f+(n?p+n:0)+e+t+r),i=_(l,o);i=o.writeUInt16BE(l.majorVersion,i),i=o.writeUInt16BE(l.minorVersion,i),i=o.writeUInt32BE(l.keepAlive,i),i=o.writeUInt32BE(l.lifetime,i),l.flags&u.Flags.RESUME_ENABLE&&(i=o.writeUInt16BE(n,i),null!=l.resumeToken&&(i+=l.resumeToken.copy(o,i)));i=o.writeUInt8(e,i),null!=l.metadataMimeType&&(i+=o.write(l.metadataMimeType,i,i+e,"ascii"));i=o.writeUInt8(t,i),null!=l.dataMimeType&&(i+=o.write(l.dataMimeType,i,i+t,"ascii"));return T(l,o,i),o}(l);case u.FrameTypes.PAYLOAD:return function(l){var n=S(l),u=et.Buffer.allocUnsafe(6+n),e=_(l,u);return T(l,u,e),u}(l);case u.FrameTypes.ERROR:return function(l){var n=null!=l.message?et.Buffer.byteLength(l.message,"utf8"):0,u=et.Buffer.allocUnsafe(6+y+n),e=_(l,u);e=u.writeUInt32BE(l.code,e),null!=l.message&&u.write(l.message,e,e+n,"utf8");return u}(l);case u.FrameTypes.KEEPALIVE:return function(l){var n=null!=l.data?l.data.byteLength:0,u=et.Buffer.allocUnsafe(6+m+n),e=_(l,u);e=a(u,l.lastReceivedPosition,e),null!=l.data&&l.data.copy(u,e);return u}(l);case u.FrameTypes.REQUEST_FNF:case u.FrameTypes.REQUEST_RESPONSE:return function(l){var n=S(l),u=et.Buffer.allocUnsafe(6+n),e=_(l,u);return T(l,u,e),u}(l);case u.FrameTypes.REQUEST_STREAM:case u.FrameTypes.REQUEST_CHANNEL:return function(l){var n=S(l),u=et.Buffer.allocUnsafe(6+b+n),e=_(l,u);return e=u.writeUInt32BE(l.requestN,e),T(l,u,e),u}(l);case u.FrameTypes.METADATA_PUSH:return function(l){var n=l.metadata;if(null!=n){var u=_(l,e=et.Buffer.allocUnsafe(6+n.byteLength));return n.copy(e,u),e}var e;return _(l,e=et.Buffer.allocUnsafe(6)),e}(l);case u.FrameTypes.REQUEST_N:return function(l){var n=et.Buffer.allocUnsafe(6+v),u=_(l,n);return n.writeUInt32BE(l.requestN,u),n}(l);case u.FrameTypes.RESUME:return function(l){var n=l.resumeToken.byteLength,u=et.Buffer.allocUnsafe(6+E+n),e=_(l,u);return e=u.writeUInt16BE(l.majorVersion,e),e=u.writeUInt16BE(l.minorVersion,e),e=u.writeUInt16BE(n,e),e+=l.resumeToken.copy(u,e),e=a(u,l.serverPosition,e),a(u,l.clientPosition,e),u}(l);case u.FrameTypes.RESUME_OK:return function(l){var n=et.Buffer.allocUnsafe(6+w),u=_(l,n);return a(n,l.clientPosition,u),n}(l);case u.FrameTypes.CANCEL:return function(l){var n=et.Buffer.allocUnsafe(6);return _(l,n),n}(l);case u.FrameTypes.LEASE:return function(l){var n=null!=l.metadata?l.metadata.byteLength:0,u=et.Buffer.allocUnsafe(6+g+n),e=_(l,u);e=u.writeUInt32BE(l.ttl,e),e=u.writeUInt32BE(l.requestCount,e),null!=l.metadata&&l.metadata.copy(u,e);return u}(l)}}l.deserializeFrameWithLength=s,l.deserializeFrames=c,l.serializeFrameWithLength=function(l){var n=h(l),u=et.Buffer.allocUnsafe(n.length+3);return r(u,n.length,0),n.copy(u,3),u},l.deserializeFrame=d,l.serializeFrame=h,l.sizeOfFrame=function(l){switch(l.type){case u.FrameTypes.SETUP:return function(l){var n=null!=l.resumeToken?l.resumeToken.byteLength:0,u=null!=l.metadataMimeType?et.Buffer.byteLength(l.metadataMimeType,"ascii"):0,e=null!=l.dataMimeType?et.Buffer.byteLength(l.dataMimeType,"ascii"):0,t=S(l);return 6+f+(n?p+n:0)+u+e+t}(l);case u.FrameTypes.PAYLOAD:return function(l){var n=S(l);return 6+n}(l);case u.FrameTypes.ERROR:return function(l){var n=null!=l.message?et.Buffer.byteLength(l.message,"utf8"):0;return 6+y+n}(l);case u.FrameTypes.KEEPALIVE:return function(l){var n=null!=l.data?l.data.byteLength:0;return 6+m+n}(l);case u.FrameTypes.REQUEST_FNF:case u.FrameTypes.REQUEST_RESPONSE:return function(l){var n=S(l);return 6+n}(l);case u.FrameTypes.REQUEST_STREAM:case u.FrameTypes.REQUEST_CHANNEL:return function(l){var n=S(l);return 6+b+n}(l);case u.FrameTypes.METADATA_PUSH:return function(l){return 6+(null!=l.metadata?l.metadata.byteLength:0)}(l);case u.FrameTypes.REQUEST_N:return 6+v;case u.FrameTypes.RESUME:return function(l){var n=l.resumeToken.byteLength;return 6+E+n}(l);case u.FrameTypes.RESUME_OK:return 6+w;case u.FrameTypes.CANCEL:return 6;case u.FrameTypes.LEASE:return function(l){var n=null!=l.metadata?l.metadata.byteLength:0;return 6+g+n}(l)}};var f=14,p=2;var y=4;var m=8;var g=8;var b=4;var v=4;var E=22;var w=8;function _(n,u){var e=u.writeInt32BE(n.streamId,0);return u.writeUInt16BE(n.type<<l.FRAME_TYPE_OFFFSET|n.flags&l.FLAGS_MASK,e)}function S(l){var n=0;return null!=l.data&&(n+=l.data.byteLength),u.Flags.hasMetadata(l.flags)&&(n+=3,null!=l.metadata&&(n+=l.metadata.byteLength)),n}function T(l,n,e){u.Flags.hasMetadata(l.flags)&&(null!=l.metadata?(e=r(n,l.metadata.byteLength,e),e+=l.metadata.copy(n,e)):e=r(n,0,e));null!=l.data&&l.data.copy(n,e)}function R(l,n,e){if(u.Flags.hasMetadata(n.flags)){var r=t(l,e);e+=3,r>0&&(n.metadata=l.slice(e,e+r),e+=r)}e<l.length&&(n.data=l.slice(e,l.length))}var O=function(){function l(){}return l.prototype.deserializeFrame=function(l){return d(l)},l.prototype.deserializeFrameWithLength=function(l){return s(l)},l.prototype.deserializeFrames=function(l){return c(l)},l}();l.Deserializer=O}(st);var dt={};Object.defineProperty(dt,"__esModule",{value:!0});var ht={},ft=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(ht,"__esModule",{value:!0}),ht.Deferred=void 0;var pt=function(){function l(){this._done=!1,this.onCloseCallbacks=[]}return Object.defineProperty(l.prototype,"done",{get:function(){return this._done},enumerable:!1,configurable:!0}),l.prototype.close=function(l){var n,u,e,t;if(this.done)console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):""));else if(this._done=!0,this._error=l,l)try{for(var r=ft(this.onCloseCallbacks),o=r.next();!o.done;o=r.next()){(0,o.value)(l)}}catch(l){n={error:l}}finally{try{o&&!o.done&&(u=r.return)&&u.call(r)}finally{if(n)throw n.error}}else try{for(var i=ft(this.onCloseCallbacks),a=i.next();!a.done;a=i.next()){(0,a.value)()}}catch(l){e={error:l}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}},l.prototype.onClose=function(l){this._done?l(this._error):this.onCloseCallbacks.push(l)},l}();ht.Deferred=pt;var yt={};!function(l){var n,u=o&&o.__extends||(n=function(l,u){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,n){l.__proto__=n}||function(l,n){for(var u in n)Object.prototype.hasOwnProperty.call(n,u)&&(l[u]=n[u])},n(l,u)},function(l,u){if("function"!=typeof u&&null!==u)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");function e(){this.constructor=l}n(l,u),l.prototype=null===u?Object.create(u):(e.prototype=u.prototype,new e)});Object.defineProperty(l,"__esModule",{value:!0}),l.ErrorCodes=l.RSocketError=void 0;var e,t=function(l){function n(n,u){var e=l.call(this,u)||this;return e.code=n,e}return u(n,l),n}(Error);l.RSocketError=t,(e=l.ErrorCodes||(l.ErrorCodes={}))[e.RESERVED=0]="RESERVED",e[e.INVALID_SETUP=1]="INVALID_SETUP",e[e.UNSUPPORTED_SETUP=2]="UNSUPPORTED_SETUP",e[e.REJECTED_SETUP=3]="REJECTED_SETUP",e[e.REJECTED_RESUME=4]="REJECTED_RESUME",e[e.CONNECTION_CLOSE=258]="CONNECTION_CLOSE",e[e.CONNECTION_ERROR=257]="CONNECTION_ERROR",e[e.APPLICATION_ERROR=513]="APPLICATION_ERROR",e[e.REJECTED=514]="REJECTED",e[e.CANCELED=515]="CANCELED",e[e.INVALID=516]="INVALID",e[e.RESERVED_EXTENSION=4294967295]="RESERVED_EXTENSION"}(yt);var mt={};Object.defineProperty(mt,"__esModule",{value:!0});var gt,bt={},vt={};function Et(){return gt||(gt=1,function(l){var n,u=o&&o.__extends||(n=function(l,u){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,n){l.__proto__=n}||function(l,n){for(var u in n)Object.prototype.hasOwnProperty.call(n,u)&&(l[u]=n[u])},n(l,u)},function(l,u){if("function"!=typeof u&&null!==u)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");function e(){this.constructor=l}n(l,u),l.prototype=null===u?Object.create(u):(e.prototype=u.prototype,new e)}),e=o&&o.__awaiter||function(l,n,u,e){return new(u||(u=Promise))((function(t,r){function o(l){try{a(e.next(l))}catch(l){r(l)}}function i(l){try{a(e.throw(l))}catch(l){r(l)}}function a(l){var n;l.done?t(l.value):(n=l.value,n instanceof u?n:new u((function(l){l(n)}))).then(o,i)}a((e=e.apply(l,n||[])).next())}))},t=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(l,"__esModule",{value:!0}),l.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer=l.ResumableClientServerInputMultiplexerDemultiplexer=l.ClientServerInputMultiplexerDemultiplexer=l.StreamIdGenerator=void 0;var r=qr(),i=ht,a=yt,s=ct;!function(l){l.create=function(l){return new n(l)};var n=function(){function l(l){this.currentId=l}return l.prototype.next=function(l){var n=this.currentId+2;l(n)&&(this.currentId=n)},l}()}(l.StreamIdGenerator||(l.StreamIdGenerator={}));var c=function(l){function n(n,u,e){var t=l.call(this)||this;return t.streamIdSupplier=n,t.outbound=u,t.closeable=e,t.registry={},e.onClose(t.close.bind(t)),t}return u(n,l),n.prototype.handle=function(l){if(s.Frame.isConnection(l)){if(l.type===r.FrameTypes.RESERVED)return;this.connectionFramesHandler.handle(l)}else if(s.Frame.isRequest(l)){if(this.registry[l.streamId])return;this.requestFramesHandler.handle(l,this)}else{var n=this.registry[l.streamId];if(!n)return;n.handle(l)}},n.prototype.connectionInbound=function(l){if(this.connectionFramesHandler)throw new Error("Connection frame handler has already been installed");this.connectionFramesHandler=l},n.prototype.handleRequestStream=function(l){if(this.requestFramesHandler)throw new Error("Stream handler has already been installed");this.requestFramesHandler=l},n.prototype.send=function(l){this.outbound.send(l)},Object.defineProperty(n.prototype,"connectionOutbound",{get:function(){return this},enumerable:!1,configurable:!0}),n.prototype.createRequestStream=function(l){var n=this;if(this.done)l.handleReject(new Error("Already closed"));else{var u=this.registry;this.streamIdSupplier.next((function(u){return l.handleReady(u,n)}),Object.keys(u))}},n.prototype.connect=function(l){this.registry[l.streamId]=l},n.prototype.disconnect=function(l){delete this.registry[l.streamId]},n.prototype.close=function(n){if(this.done)l.prototype.close.call(this,n);else{for(var u in this.registry){this.registry[u].close(new Error("Closed. ".concat(n?"Original cause [".concat(n,"]."):"")))}l.prototype.close.call(this,n)}},n}(i.Deferred);l.ClientServerInputMultiplexerDemultiplexer=c;var d=function(l){function n(n,u,e,t,r,o,a){var s=l.call(this,n,u,new i.Deferred)||this;return s.frameStore=t,s.token=r,s.sessionTimeout=a,o instanceof Function?s.reconnector=o:s.sessionStore=o,e.onClose(s.handleConnectionClose.bind(s)),s}return u(n,l),n.prototype.send=function(n){if(s.Frame.isConnection(n)){if(n.type===r.FrameTypes.KEEPALIVE)n.lastReceivedPosition=this.frameStore.lastReceivedFramePosition;else if(n.type===r.FrameTypes.ERROR)return this.outbound.send(n),this.sessionStore&&delete this.sessionStore[this.token],void l.prototype.close.call(this,new a.RSocketError(n.code,n.message))}else this.frameStore.store(n);this.outbound.send(n)},n.prototype.handle=function(n){if(s.Frame.isConnection(n)){if(n.type===r.FrameTypes.KEEPALIVE)try{this.frameStore.dropTo(n.lastReceivedPosition)}catch(l){this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,flags:r.Flags.NONE,code:l.code,message:l.message}),this.close(l)}else if(n.type===r.FrameTypes.ERROR)return l.prototype.handle.call(this,n),this.sessionStore&&delete this.sessionStore[this.token],void l.prototype.close.call(this,new a.RSocketError(n.code,n.message))}else this.frameStore.record(n);l.prototype.handle.call(this,n)},n.prototype.resume=function(l,n,u){switch(this.outbound=n,l.type){case r.FrameTypes.RESUME:if(clearTimeout(this.timeoutId),this.frameStore.lastReceivedFramePosition<l.clientPosition){var e=new a.RSocketError(r.ErrorCodes.REJECTED_RESUME,"Impossible to resume since first available client frame position is greater than last received server frame position");return this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,flags:r.Flags.NONE,code:e.code,message:e.message}),void this.close(e)}try{this.frameStore.dropTo(l.serverPosition)}catch(l){return this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,flags:r.Flags.NONE,code:l.code,message:l.message}),void this.close(l)}this.outbound.send({type:r.FrameTypes.RESUME_OK,streamId:0,flags:r.Flags.NONE,clientPosition:this.frameStore.lastReceivedFramePosition});break;case r.FrameTypes.RESUME_OK:try{this.frameStore.dropTo(l.clientPosition)}catch(l){this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,flags:r.Flags.NONE,code:l.code,message:l.message}),this.close(l)}}this.frameStore.drain(this.outbound.send.bind(this.outbound)),u.onClose(this.handleConnectionClose.bind(this)),this.connectionFramesHandler.resume()},n.prototype.handleConnectionClose=function(l){return e(this,void 0,void 0,(function(){var l;return t(this,(function(n){switch(n.label){case 0:if(this.connectionFramesHandler.pause(),!this.reconnector)return[3,5];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.reconnector(this,this.frameStore)];case 2:return n.sent(),[3,4];case 3:return l=n.sent(),this.close(l),[3,4];case 4:return[3,6];case 5:this.timeoutId=setTimeout(this.close.bind(this),this.sessionTimeout),n.label=6;case 6:return[2]}}))}))},n}(c);l.ResumableClientServerInputMultiplexerDemultiplexer=d;var h=function(){function l(l,n,u){this.outbound=l,this.closeable=n,this.delegate=u,this.resumed=!1}return l.prototype.close=function(){this.delegate.close()},l.prototype.onClose=function(l){this.delegate.onClose(l)},Object.defineProperty(l.prototype,"connectionOutbound",{get:function(){return this.delegate.connectionOutbound},enumerable:!1,configurable:!0}),l.prototype.createRequestStream=function(l){this.delegate.createRequestStream(l)},l.prototype.connectionInbound=function(l){this.delegate.connectionInbound(l)},l.prototype.handleRequestStream=function(l){this.delegate.handleRequestStream(l)},l.prototype.handle=function(l){var n=this;if(!this.resumed)return l.type===r.FrameTypes.RESUME_OK?(this.resumed=!0,void this.delegate.resume(l,this.outbound,this.closeable)):(this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,code:r.ErrorCodes.CONNECTION_ERROR,message:"Incomplete RESUME handshake. Unexpected frame ".concat(l.type," received"),flags:r.Flags.NONE}),this.closeable.close(),void this.closeable.onClose((function(){return n.delegate.close(new a.RSocketError(r.ErrorCodes.CONNECTION_ERROR,"Incomplete RESUME handshake. Unexpected frame ".concat(l.type," received")))})));this.delegate.handle(l)},l}();l.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer=h}(vt)),vt}var wt={},_t={},St={},Tt=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(St,"__esModule",{value:!0}),St.fragmentWithRequestN=St.fragment=St.isFragmentable=void 0;var Rt=ct;St.isFragmentable=function(l,n,u){return 0!==n&&l.data.byteLength+(l.metadata?l.metadata.byteLength+Rt.Lengths.METADATA:0)+(u==Rt.FrameTypes.REQUEST_STREAM||u==Rt.FrameTypes.REQUEST_CHANNEL?Rt.Lengths.REQUEST:0)>n},St.fragment=function(l,n,u,e,t){var r,o,i,a,s,c,d,h,f,p,y,m;return void 0===t&&(t=!1),Tt(this,(function(g){switch(g.label){case 0:return r=null!==(m=null===(y=n.data)||void 0===y?void 0:y.byteLength)&&void 0!==m?m:0,o=e!==Rt.FrameTypes.PAYLOAD,i=u,n.metadata?0!==(s=n.metadata.byteLength)?[3,1]:(i-=Rt.Lengths.METADATA,a=et.Buffer.allocUnsafe(0),[3,6]):[3,6];case 1:return c=0,o?(i-=Rt.Lengths.METADATA,d=Math.min(s,c+i),a=n.metadata.slice(c,d),i-=a.byteLength,c=d,0!==i?[3,3]:(o=!1,[4,{type:e,flags:Rt.Flags.FOLLOWS|Rt.Flags.METADATA,data:void 0,metadata:a,streamId:l}])):[3,3];case 2:g.sent(),a=void 0,i=u,g.label=3;case 3:return c<s?(i-=Rt.Lengths.METADATA,d=Math.min(s,c+i),a=n.metadata.slice(c,d),i-=a.byteLength,c=d,0!==i&&0!==r?[3,5]:[4,{type:Rt.FrameTypes.PAYLOAD,flags:Rt.Flags.NEXT|Rt.Flags.METADATA|(c===s&&t&&0===r?Rt.Flags.COMPLETE:Rt.Flags.FOLLOWS),data:void 0,metadata:a,streamId:l}]):[3,6];case 4:g.sent(),a=void 0,i=u,g.label=5;case 5:return[3,3];case 6:return h=0,o?(p=Math.min(r,h+i),f=n.data.slice(h,p),i-=f.byteLength,h=p,[4,{type:e,flags:Rt.Flags.FOLLOWS|(a?Rt.Flags.METADATA:Rt.Flags.NONE),data:f,metadata:a,streamId:l}]):[3,8];case 7:g.sent(),a=void 0,f=void 0,i=u,g.label=8;case 8:return h<r?(p=Math.min(r,h+i),f=n.data.slice(h,p),i-=f.byteLength,h=p,[4,{type:Rt.FrameTypes.PAYLOAD,flags:h===r?(t?Rt.Flags.COMPLETE:Rt.Flags.NONE)|Rt.Flags.NEXT|(a?Rt.Flags.METADATA:0):Rt.Flags.FOLLOWS|Rt.Flags.NEXT|(a?Rt.Flags.METADATA:0),data:f,metadata:a,streamId:l}]):[3,10];case 9:return g.sent(),a=void 0,f=void 0,i=u,[3,8];case 10:return[2]}}))},St.fragmentWithRequestN=function(l,n,u,e,t,r){var o,i,a,s,c,d,h,f,p,y,m,g;return void 0===r&&(r=!1),Tt(this,(function(b){switch(b.label){case 0:return o=null!==(g=null===(m=n.data)||void 0===m?void 0:m.byteLength)&&void 0!==g?g:0,i=!0,a=u,n.metadata?0!==(c=n.metadata.byteLength)?[3,1]:(a-=Rt.Lengths.METADATA,s=et.Buffer.allocUnsafe(0),[3,6]):[3,6];case 1:return d=0,i?(a-=Rt.Lengths.METADATA+Rt.Lengths.REQUEST,h=Math.min(c,d+a),s=n.metadata.slice(d,h),a-=s.byteLength,d=h,0!==a?[3,3]:(i=!1,[4,{type:e,flags:Rt.Flags.FOLLOWS|Rt.Flags.METADATA,data:void 0,requestN:t,metadata:s,streamId:l}])):[3,3];case 2:b.sent(),s=void 0,a=u,b.label=3;case 3:return d<c?(a-=Rt.Lengths.METADATA,h=Math.min(c,d+a),s=n.metadata.slice(d,h),a-=s.byteLength,d=h,0!==a&&0!==o?[3,5]:[4,{type:Rt.FrameTypes.PAYLOAD,flags:Rt.Flags.NEXT|Rt.Flags.METADATA|(d===c&&r&&0===o?Rt.Flags.COMPLETE:Rt.Flags.FOLLOWS),data:void 0,metadata:s,streamId:l}]):[3,6];case 4:b.sent(),s=void 0,a=u,b.label=5;case 5:return[3,3];case 6:return f=0,i?(a-=Rt.Lengths.REQUEST,y=Math.min(o,f+a),p=n.data.slice(f,y),a-=p.byteLength,f=y,[4,{type:e,flags:Rt.Flags.FOLLOWS|(s?Rt.Flags.METADATA:Rt.Flags.NONE),data:p,requestN:t,metadata:s,streamId:l}]):[3,8];case 7:b.sent(),s=void 0,p=void 0,a=u,b.label=8;case 8:return f<o?(y=Math.min(o,f+a),p=n.data.slice(f,y),a-=p.byteLength,f=y,[4,{type:Rt.FrameTypes.PAYLOAD,flags:f===o?(r?Rt.Flags.COMPLETE:Rt.Flags.NONE)|Rt.Flags.NEXT|(s?Rt.Flags.METADATA:0):Rt.Flags.FOLLOWS|Rt.Flags.NEXT|(s?Rt.Flags.METADATA:0),data:p,metadata:s,streamId:l}]):[3,10];case 9:return b.sent(),s=void 0,p=void 0,a=u,[3,8];case 10:return[2]}}))};var Ot={};Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.cancel=Ot.reassemble=Ot.add=void 0,Ot.add=function(l,n,u){return l.hasFragments?(l.data=l.data?et.Buffer.concat([l.data,n]):n,l.metadata&&u&&(l.metadata=et.Buffer.concat([l.metadata,u])),!0):(l.hasFragments=!0,l.data=n,u&&(l.metadata=u),!0)},Ot.reassemble=function(l,n,u){l.hasFragments=!1;var e=l.data?et.Buffer.concat([l.data,n]):n;if(l.data=void 0,l.metadata){var t=u?et.Buffer.concat([l.metadata,u]):l.metadata;return l.metadata=void 0,{data:e,metadata:t}}return{data:e}},Ot.cancel=function(l){l.hasFragments=!1,l.data=void 0,l.metadata=void 0};var At=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),Ct=o&&o.__setModuleDefault||(Object.create?function(l,n){Object.defineProperty(l,"default",{enumerable:!0,value:n})}:function(l,n){l.default=n}),Ft=o&&o.__importStar||function(l){if(l&&l.__esModule)return l;var n={};if(null!=l)for(var u in l)"default"!==u&&Object.prototype.hasOwnProperty.call(l,u)&&At(n,l,u);return Ct(n,l),n},It=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(_t,"__esModule",{value:!0}),_t.RequestChannelResponderStream=_t.RequestChannelRequesterStream=void 0;var kt=yt,Pt=St,Lt=ct,Nt=Ft(Ot),xt=function(){function l(l,n,u,e,t,r){this.payload=l,this.isComplete=n,this.receiver=u,this.fragmentSize=e,this.initialRequestN=t,this.leaseManager=r,this.streamType=Lt.FrameTypes.REQUEST_CHANNEL}return l.prototype.handleReady=function(l,n){var u,e;if(this.outboundDone)return!1;this.streamId=l,this.stream=n,n.connect(this);var t=this.isComplete;if(t&&(this.outboundDone=t),(0,Pt.isFragmentable)(this.payload,this.fragmentSize,Lt.FrameTypes.REQUEST_CHANNEL))try{for(var r=It((0,Pt.fragmentWithRequestN)(l,this.payload,this.fragmentSize,Lt.FrameTypes.REQUEST_CHANNEL,this.initialRequestN,t)),o=r.next();!o.done;o=r.next()){var i=o.value;this.stream.send(i)}}catch(l){u={error:l}}finally{try{o&&!o.done&&(e=r.return)&&e.call(r)}finally{if(u)throw u.error}}else this.stream.send({type:Lt.FrameTypes.REQUEST_CHANNEL,data:this.payload.data,metadata:this.payload.metadata,requestN:this.initialRequestN,flags:(void 0!==this.payload.metadata?Lt.Flags.METADATA:Lt.Flags.NONE)|(t?Lt.Flags.COMPLETE:Lt.Flags.NONE),streamId:l});return this.hasExtension&&this.stream.send({type:Lt.FrameTypes.EXT,streamId:l,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},l.prototype.handleReject=function(l){this.inboundDone||(this.inboundDone=!0,this.outboundDone=!0,this.receiver.onError(l))},l.prototype.handle=function(l){var n,u=l.type;switch(u){case Lt.FrameTypes.PAYLOAD:var e=Lt.Flags.hasComplete(l.flags),t=Lt.Flags.hasNext(l.flags);if(e||!Lt.Flags.hasFollows(l.flags)){if(e&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this),!t))return void this.receiver.onComplete();var r=this.hasFragments?Nt.reassemble(this,l.data,l.metadata):{data:l.data,metadata:l.metadata};return void this.receiver.onNext(r,e)}if(Nt.add(this,l.data,l.metadata))return;n="Unexpected frame size";break;case Lt.FrameTypes.CANCEL:if(this.outboundDone)return;return this.outboundDone=!0,this.inboundDone&&this.stream.disconnect(this),void this.receiver.cancel();case Lt.FrameTypes.REQUEST_N:if(this.outboundDone)return;if(this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.request(l.requestN);case Lt.FrameTypes.ERROR:var o=this.outboundDone;return this.inboundDone=!0,this.outboundDone=!0,this.stream.disconnect(this),Nt.cancel(this),o||this.receiver.cancel(),void this.receiver.onError(new kt.RSocketError(l.code,l.message));case Lt.FrameTypes.EXT:return void this.receiver.onExtension(l.extendedType,l.extendedContent,Lt.Flags.hasIgnore(l.flags));default:n="Unexpected frame type [".concat(u,"]")}this.close(new kt.RSocketError(kt.ErrorCodes.CANCELED,n)),this.stream.send({type:Lt.FrameTypes.CANCEL,streamId:this.streamId,flags:Lt.Flags.NONE}),this.stream.disconnect(this)},l.prototype.request=function(l){this.inboundDone||(this.streamId?this.stream.send({type:Lt.FrameTypes.REQUEST_N,flags:Lt.Flags.NONE,requestN:l,streamId:this.streamId}):this.initialRequestN+=l)},l.prototype.cancel=function(){var l,n=this.inboundDone,u=this.outboundDone;n&&u||(this.inboundDone=!0,this.outboundDone=!0,u||this.receiver.cancel(),this.streamId?(this.stream.send({type:n?Lt.FrameTypes.ERROR:Lt.FrameTypes.CANCEL,flags:Lt.Flags.NONE,streamId:this.streamId,code:kt.ErrorCodes.CANCELED,message:"Cancelled"}),this.stream.disconnect(this),Nt.cancel(this)):null===(l=this.leaseManager)||void 0===l||l.cancelRequest(this))},l.prototype.onNext=function(l,n){var u,e;if(!this.outboundDone)if(n&&(this.outboundDone=!0,this.inboundDone&&this.stream.disconnect(this)),(0,Pt.isFragmentable)(l,this.fragmentSize,Lt.FrameTypes.PAYLOAD))try{for(var t=It((0,Pt.fragment)(this.streamId,l,this.fragmentSize,Lt.FrameTypes.PAYLOAD,n)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:Lt.FrameTypes.PAYLOAD,streamId:this.streamId,flags:Lt.Flags.NEXT|(l.metadata?Lt.Flags.METADATA:Lt.Flags.NONE)|(n?Lt.Flags.COMPLETE:Lt.Flags.NONE),data:l.data,metadata:l.metadata})},l.prototype.onComplete=function(){this.streamId?this.outboundDone||(this.outboundDone=!0,this.stream.send({type:Lt.FrameTypes.PAYLOAD,streamId:this.streamId,flags:Lt.Flags.COMPLETE,data:null,metadata:null}),this.inboundDone&&this.stream.disconnect(this)):this.isComplete=!0},l.prototype.onError=function(l){if(!this.outboundDone){var n=this.inboundDone;this.outboundDone=!0,this.inboundDone=!0,this.stream.send({type:Lt.FrameTypes.ERROR,streamId:this.streamId,flags:Lt.Flags.NONE,code:l instanceof kt.RSocketError?l.code:kt.ErrorCodes.APPLICATION_ERROR,message:l.message}),this.stream.disconnect(this),n||this.receiver.onError(l)}},l.prototype.onExtension=function(l,n,u){if(!this.outboundDone)return this.streamId?void this.stream.send({streamId:this.streamId,type:Lt.FrameTypes.EXT,extendedType:l,extendedContent:n,flags:u?Lt.Flags.IGNORE:Lt.Flags.NONE}):(this.hasExtension=!0,this.extendedType=l,this.extendedContent=n,void(this.flags=u?Lt.Flags.IGNORE:Lt.Flags.NONE))},l.prototype.close=function(l){if(!this.inboundDone||!this.outboundDone){var n=this.inboundDone,u=this.outboundDone;this.inboundDone=!0,this.outboundDone=!0,Nt.cancel(this),u||this.receiver.cancel(),n||(l?this.receiver.onError(l):this.receiver.onComplete())}},l}();_t.RequestChannelRequesterStream=xt;var Ut=function(){function l(l,n,u,e,t){if(this.streamId=l,this.stream=n,this.fragmentSize=u,this.handler=e,this.streamType=Lt.FrameTypes.REQUEST_CHANNEL,n.connect(this),Lt.Flags.hasFollows(t.flags))return Nt.add(this,t.data,t.metadata),this.initialRequestN=t.requestN,void(this.isComplete=Lt.Flags.hasComplete(t.flags));var r={data:t.data,metadata:t.metadata},o=Lt.Flags.hasComplete(t.flags);this.inboundDone=o;try{this.receiver=e(r,t.requestN,o,this),this.outboundDone&&this.defferedError&&this.receiver.onError(this.defferedError)}catch(l){this.outboundDone&&!this.inboundDone?this.cancel():this.inboundDone=!0,this.onError(l)}}return l.prototype.handle=function(l){var n,u=l.type;switch(u){case Lt.FrameTypes.PAYLOAD:if(Lt.Flags.hasFollows(l.flags)){if(Nt.add(this,l.data,l.metadata))return;n="Unexpected frame size";break}var e=this.hasFragments?Nt.reassemble(this,l.data,l.metadata):{data:l.data,metadata:l.metadata},t=Lt.Flags.hasComplete(l.flags);if(this.receiver){if(t&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this),!Lt.Flags.hasNext(l.flags)))return void this.receiver.onComplete();this.receiver.onNext(e,t)}else{(r=this.isComplete||t)&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this));try{this.receiver=this.handler(e,this.initialRequestN,r,this),this.outboundDone&&this.defferedError}catch(i){this.outboundDone&&!this.inboundDone?this.cancel():this.inboundDone=!0,this.onError(i)}}return;case Lt.FrameTypes.REQUEST_N:if(!this.receiver||this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.request(l.requestN);case Lt.FrameTypes.ERROR:case Lt.FrameTypes.CANCEL:var r=this.inboundDone,o=this.outboundDone;if(this.inboundDone=!0,this.outboundDone=!0,this.stream.disconnect(this),Nt.cancel(this),!this.receiver)return;if(o||this.receiver.cancel(),!r){var i=u===Lt.FrameTypes.CANCEL?new kt.RSocketError(kt.ErrorCodes.CANCELED,"Cancelled"):new kt.RSocketError(l.code,l.message);this.receiver.onError(i)}return;case Lt.FrameTypes.EXT:if(!this.receiver||this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.onExtension(l.extendedType,l.extendedContent,Lt.Flags.hasIgnore(l.flags));default:n="Unexpected frame type [".concat(u,"]")}this.stream.send({type:Lt.FrameTypes.ERROR,flags:Lt.Flags.NONE,code:kt.ErrorCodes.CANCELED,message:n,streamId:this.streamId}),this.stream.disconnect(this),this.close(new kt.RSocketError(kt.ErrorCodes.CANCELED,n))},l.prototype.onError=function(l){if(this.outboundDone)console.warn("Trying to error for the second time. ".concat(l?"Dropping error [".concat(l,"]."):""));else{var n=this.inboundDone;this.outboundDone=!0,this.inboundDone=!0,this.stream.send({type:Lt.FrameTypes.ERROR,flags:Lt.Flags.NONE,code:l instanceof kt.RSocketError?l.code:kt.ErrorCodes.APPLICATION_ERROR,message:l.message,streamId:this.streamId}),this.stream.disconnect(this),n||(this.receiver?this.receiver.onError(l):this.defferedError=l)}},l.prototype.onNext=function(l,n){var u,e;if(!this.outboundDone){if(n&&(this.outboundDone=!0),(0,Pt.isFragmentable)(l,this.fragmentSize,Lt.FrameTypes.PAYLOAD))try{for(var t=It((0,Pt.fragment)(this.streamId,l,this.fragmentSize,Lt.FrameTypes.PAYLOAD,n)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:Lt.FrameTypes.PAYLOAD,flags:Lt.Flags.NEXT|(n?Lt.Flags.COMPLETE:Lt.Flags.NONE)|(l.metadata?Lt.Flags.METADATA:Lt.Flags.NONE),data:l.data,metadata:l.metadata,streamId:this.streamId});n&&this.inboundDone&&this.stream.disconnect(this)}},l.prototype.onComplete=function(){this.outboundDone||(this.outboundDone=!0,this.stream.send({type:Lt.FrameTypes.PAYLOAD,flags:Lt.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.inboundDone&&this.stream.disconnect(this))},l.prototype.onExtension=function(l,n,u){this.outboundDone&&this.inboundDone||this.stream.send({type:Lt.FrameTypes.EXT,streamId:this.streamId,flags:u?Lt.Flags.IGNORE:Lt.Flags.NONE,extendedType:l,extendedContent:n})},l.prototype.request=function(l){this.inboundDone||this.stream.send({type:Lt.FrameTypes.REQUEST_N,flags:Lt.Flags.NONE,streamId:this.streamId,requestN:l})},l.prototype.cancel=function(){this.inboundDone||(this.inboundDone=!0,this.stream.send({type:Lt.FrameTypes.CANCEL,flags:Lt.Flags.NONE,streamId:this.streamId}),this.outboundDone&&this.stream.disconnect(this))},l.prototype.close=function(l){if(this.inboundDone&&this.outboundDone)console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):""));else{var n=this.inboundDone,u=this.outboundDone;this.inboundDone=!0,this.outboundDone=!0,Nt.cancel(this);var e=this.receiver;e&&(u||e.cancel(),n||(l?e.onError(l):e.onComplete()))}},l}();_t.RequestChannelResponderStream=Ut;var Bt={},Dt=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),Mt=o&&o.__setModuleDefault||(Object.create?function(l,n){Object.defineProperty(l,"default",{enumerable:!0,value:n})}:function(l,n){l.default=n}),qt=o&&o.__importStar||function(l){if(l&&l.__esModule)return l;var n={};if(null!=l)for(var u in l)"default"!==u&&Object.prototype.hasOwnProperty.call(l,u)&&Dt(n,l,u);return Mt(n,l),n},jt=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.RequestFnfResponderStream=Bt.RequestFnFRequesterStream=void 0;var Wt=yt,zt=St,Qt=ct,$t=qt(Ot),Ht=function(){function l(l,n,u,e){this.payload=l,this.receiver=n,this.fragmentSize=u,this.leaseManager=e,this.streamType=Qt.FrameTypes.REQUEST_FNF}return l.prototype.handleReady=function(l,n){var u,e;if(this.done)return!1;if(this.streamId=l,(0,zt.isFragmentable)(this.payload,this.fragmentSize,Qt.FrameTypes.REQUEST_FNF))try{for(var t=jt((0,zt.fragment)(l,this.payload,this.fragmentSize,Qt.FrameTypes.REQUEST_FNF)),r=t.next();!r.done;r=t.next()){var o=r.value;n.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else n.send({type:Qt.FrameTypes.REQUEST_FNF,data:this.payload.data,metadata:this.payload.metadata,flags:this.payload.metadata?Qt.Flags.METADATA:0,streamId:l});return this.done=!0,this.receiver.onComplete(),!0},l.prototype.handleReject=function(l){this.done||(this.done=!0,this.receiver.onError(l))},l.prototype.cancel=function(){var l;this.done||(this.done=!0,null===(l=this.leaseManager)||void 0===l||l.cancelRequest(this))},l.prototype.handle=function(l){l.type!=Qt.FrameTypes.ERROR?this.close(new Wt.RSocketError(Wt.ErrorCodes.CANCELED,"Received invalid frame")):this.close(new Wt.RSocketError(l.code,l.message))},l.prototype.close=function(l){this.done?console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):l?this.receiver.onError(l):this.receiver.onComplete()},l}();Bt.RequestFnFRequesterStream=Ht;var Vt=function(){function l(l,n,u,e){if(this.streamId=l,this.stream=n,this.handler=u,this.streamType=Qt.FrameTypes.REQUEST_FNF,Qt.Flags.hasFollows(e.flags))return $t.add(this,e.data,e.metadata),void n.connect(this);var t={data:e.data,metadata:e.metadata};try{this.cancellable=u(t,this)}catch(l){}}return l.prototype.handle=function(l){var n;if(l.type==Qt.FrameTypes.PAYLOAD){if(!Qt.Flags.hasFollows(l.flags)){this.stream.disconnect(this);var u=$t.reassemble(this,l.data,l.metadata);try{this.cancellable=this.handler(u,this)}catch(l){}return}if($t.add(this,l.data,l.metadata))return;n="Unexpected fragment size"}else n="Unexpected frame type [".concat(l.type,"]");this.done=!0,l.type!=Qt.FrameTypes.CANCEL&&l.type!=Qt.FrameTypes.ERROR&&this.stream.send({type:Qt.FrameTypes.ERROR,streamId:this.streamId,flags:Qt.Flags.NONE,code:Wt.ErrorCodes.CANCELED,message:n}),this.stream.disconnect(this),$t.cancel(this)},l.prototype.close=function(l){var n;this.done?console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(this.done=!0,$t.cancel(this),null===(n=this.cancellable)||void 0===n||n.cancel())},l.prototype.onError=function(l){},l.prototype.onComplete=function(){},l}();Bt.RequestFnfResponderStream=Vt;var Jt={},Yt=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),Xt=o&&o.__setModuleDefault||(Object.create?function(l,n){Object.defineProperty(l,"default",{enumerable:!0,value:n})}:function(l,n){l.default=n}),Gt=o&&o.__importStar||function(l){if(l&&l.__esModule)return l;var n={};if(null!=l)for(var u in l)"default"!==u&&Object.prototype.hasOwnProperty.call(l,u)&&Yt(n,l,u);return Xt(n,l),n},Kt=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(Jt,"__esModule",{value:!0}),Jt.RequestResponseResponderStream=Jt.RequestResponseRequesterStream=void 0;var Zt=yt,lr=St,nr=ct,ur=Gt(Ot),er=function(){function l(l,n,u,e){this.payload=l,this.receiver=n,this.fragmentSize=u,this.leaseManager=e,this.streamType=nr.FrameTypes.REQUEST_RESPONSE}return l.prototype.handleReady=function(l,n){var u,e;if(this.done)return!1;if(this.streamId=l,this.stream=n,n.connect(this),(0,lr.isFragmentable)(this.payload,this.fragmentSize,nr.FrameTypes.REQUEST_RESPONSE))try{for(var t=Kt((0,lr.fragment)(l,this.payload,this.fragmentSize,nr.FrameTypes.REQUEST_RESPONSE)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:nr.FrameTypes.REQUEST_RESPONSE,data:this.payload.data,metadata:this.payload.metadata,flags:this.payload.metadata?nr.Flags.METADATA:0,streamId:l});return this.hasExtension&&this.stream.send({type:nr.FrameTypes.EXT,streamId:l,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},l.prototype.handleReject=function(l){this.done||(this.done=!0,this.receiver.onError(l))},l.prototype.handle=function(l){var n,u=l.type;switch(u){case nr.FrameTypes.PAYLOAD:var e=nr.Flags.hasComplete(l.flags),t=nr.Flags.hasNext(l.flags);if(e||!nr.Flags.hasFollows(l.flags)){if(this.done=!0,this.stream.disconnect(this),!t)return void this.receiver.onComplete();var r=this.hasFragments?ur.reassemble(this,l.data,l.metadata):{data:l.data,metadata:l.metadata};return void this.receiver.onNext(r,!0)}if(!ur.add(this,l.data,l.metadata)){n="Unexpected fragment size";break}return;case nr.FrameTypes.ERROR:return this.done=!0,this.stream.disconnect(this),ur.cancel(this),void this.receiver.onError(new Zt.RSocketError(l.code,l.message));case nr.FrameTypes.EXT:if(this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.onExtension(l.extendedType,l.extendedContent,nr.Flags.hasIgnore(l.flags));default:n="Unexpected frame type [".concat(u,"]")}this.close(new Zt.RSocketError(Zt.ErrorCodes.CANCELED,n)),this.stream.send({type:nr.FrameTypes.CANCEL,streamId:this.streamId,flags:nr.Flags.NONE}),this.stream.disconnect(this)},l.prototype.cancel=function(){var l;this.done||(this.done=!0,this.streamId?(this.stream.send({type:nr.FrameTypes.CANCEL,flags:nr.Flags.NONE,streamId:this.streamId}),this.stream.disconnect(this),ur.cancel(this)):null===(l=this.leaseManager)||void 0===l||l.cancelRequest(this))},l.prototype.onExtension=function(l,n,u){if(!this.done)return this.streamId?void this.stream.send({streamId:this.streamId,type:nr.FrameTypes.EXT,extendedType:l,extendedContent:n,flags:u?nr.Flags.IGNORE:nr.Flags.NONE}):(this.hasExtension=!0,this.extendedType=l,this.extendedContent=n,void(this.flags=u?nr.Flags.IGNORE:nr.Flags.NONE))},l.prototype.close=function(l){this.done||(this.done=!0,ur.cancel(this),l?this.receiver.onError(l):this.receiver.onComplete())},l}();Jt.RequestResponseRequesterStream=er;var tr=function(){function l(l,n,u,e,t){if(this.streamId=l,this.stream=n,this.fragmentSize=u,this.handler=e,this.streamType=nr.FrameTypes.REQUEST_RESPONSE,n.connect(this),nr.Flags.hasFollows(t.flags))ur.add(this,t.data,t.metadata);else{var r={data:t.data,metadata:t.metadata};try{this.receiver=e(r,this)}catch(l){this.onError(l)}}}return l.prototype.handle=function(l){var n,u;if(!this.receiver||this.hasFragments)if(l.type===nr.FrameTypes.PAYLOAD){if(!nr.Flags.hasFollows(l.flags)){var e=ur.reassemble(this,l.data,l.metadata);try{this.receiver=this.handler(e,this)}catch(l){this.onError(l)}return}if(ur.add(this,l.data,l.metadata))return;u="Unexpected fragment size"}else u="Unexpected frame type [".concat(l.type,"] during reassembly");else{if(l.type===nr.FrameTypes.EXT)return void this.receiver.onExtension(l.extendedType,l.extendedContent,nr.Flags.hasIgnore(l.flags));u="Unexpected frame type [".concat(l.type,"]")}this.done=!0,null===(n=this.receiver)||void 0===n||n.cancel(),l.type!==nr.FrameTypes.CANCEL&&l.type!==nr.FrameTypes.ERROR&&this.stream.send({type:nr.FrameTypes.ERROR,flags:nr.Flags.NONE,code:Zt.ErrorCodes.CANCELED,message:u,streamId:this.streamId}),this.stream.disconnect(this),ur.cancel(this)},l.prototype.onError=function(l){this.done?console.warn("Trying to error for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(this.done=!0,this.stream.send({type:nr.FrameTypes.ERROR,flags:nr.Flags.NONE,code:l instanceof Zt.RSocketError?l.code:Zt.ErrorCodes.APPLICATION_ERROR,message:l.message,streamId:this.streamId}),this.stream.disconnect(this))},l.prototype.onNext=function(l,n){var u,e;if(!this.done){if(this.done=!0,(0,lr.isFragmentable)(l,this.fragmentSize,nr.FrameTypes.PAYLOAD))try{for(var t=Kt((0,lr.fragment)(this.streamId,l,this.fragmentSize,nr.FrameTypes.PAYLOAD,!0)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:nr.FrameTypes.PAYLOAD,flags:nr.Flags.NEXT|nr.Flags.COMPLETE|(l.metadata?nr.Flags.METADATA:0),data:l.data,metadata:l.metadata,streamId:this.streamId});this.stream.disconnect(this)}},l.prototype.onComplete=function(){this.done||(this.done=!0,this.stream.send({type:nr.FrameTypes.PAYLOAD,flags:nr.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.stream.disconnect(this))},l.prototype.onExtension=function(l,n,u){this.done||this.stream.send({type:nr.FrameTypes.EXT,streamId:this.streamId,flags:u?nr.Flags.IGNORE:nr.Flags.NONE,extendedType:l,extendedContent:n})},l.prototype.close=function(l){var n;this.done?console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(ur.cancel(this),null===(n=this.receiver)||void 0===n||n.cancel())},l}();Jt.RequestResponseResponderStream=tr;var rr={},or=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),ir=o&&o.__setModuleDefault||(Object.create?function(l,n){Object.defineProperty(l,"default",{enumerable:!0,value:n})}:function(l,n){l.default=n}),ar=o&&o.__importStar||function(l){if(l&&l.__esModule)return l;var n={};if(null!=l)for(var u in l)"default"!==u&&Object.prototype.hasOwnProperty.call(l,u)&&or(n,l,u);return ir(n,l),n},sr=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(rr,"__esModule",{value:!0}),rr.RequestStreamResponderStream=rr.RequestStreamRequesterStream=void 0;var cr=yt,dr=St,hr=ct,fr=ar(Ot),pr=function(){function l(l,n,u,e,t){this.payload=l,this.receiver=n,this.fragmentSize=u,this.initialRequestN=e,this.leaseManager=t,this.streamType=hr.FrameTypes.REQUEST_STREAM}return l.prototype.handleReady=function(l,n){var u,e;if(this.done)return!1;if(this.streamId=l,this.stream=n,n.connect(this),(0,dr.isFragmentable)(this.payload,this.fragmentSize,hr.FrameTypes.REQUEST_STREAM))try{for(var t=sr((0,dr.fragmentWithRequestN)(l,this.payload,this.fragmentSize,hr.FrameTypes.REQUEST_STREAM,this.initialRequestN)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:hr.FrameTypes.REQUEST_STREAM,data:this.payload.data,metadata:this.payload.metadata,requestN:this.initialRequestN,flags:void 0!==this.payload.metadata?hr.Flags.METADATA:0,streamId:l});return this.hasExtension&&this.stream.send({type:hr.FrameTypes.EXT,streamId:l,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},l.prototype.handleReject=function(l){this.done||(this.done=!0,this.receiver.onError(l))},l.prototype.handle=function(l){var n,u=l.type;switch(u){case hr.FrameTypes.PAYLOAD:var e=hr.Flags.hasComplete(l.flags),t=hr.Flags.hasNext(l.flags);if(e||!hr.Flags.hasFollows(l.flags)){if(e&&(this.done=!0,this.stream.disconnect(this),!t))return void this.receiver.onComplete();var r=this.hasFragments?fr.reassemble(this,l.data,l.metadata):{data:l.data,metadata:l.metadata};return void this.receiver.onNext(r,e)}if(!fr.add(this,l.data,l.metadata)){n="Unexpected fragment size";break}return;case hr.FrameTypes.ERROR:return this.done=!0,this.stream.disconnect(this),fr.cancel(this),void this.receiver.onError(new cr.RSocketError(l.code,l.message));case hr.FrameTypes.EXT:if(this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.onExtension(l.extendedType,l.extendedContent,hr.Flags.hasIgnore(l.flags));default:n="Unexpected frame type [".concat(u,"]")}this.close(new cr.RSocketError(cr.ErrorCodes.CANCELED,n)),this.stream.send({type:hr.FrameTypes.CANCEL,streamId:this.streamId,flags:hr.Flags.NONE}),this.stream.disconnect(this)},l.prototype.request=function(l){this.done||(this.streamId?this.stream.send({type:hr.FrameTypes.REQUEST_N,flags:hr.Flags.NONE,requestN:l,streamId:this.streamId}):this.initialRequestN+=l)},l.prototype.cancel=function(){var l;this.done||(this.done=!0,this.streamId?(this.stream.send({type:hr.FrameTypes.CANCEL,flags:hr.Flags.NONE,streamId:this.streamId}),this.stream.disconnect(this),fr.cancel(this)):null===(l=this.leaseManager)||void 0===l||l.cancelRequest(this))},l.prototype.onExtension=function(l,n,u){if(!this.done)return this.streamId?void this.stream.send({streamId:this.streamId,type:hr.FrameTypes.EXT,extendedType:l,extendedContent:n,flags:u?hr.Flags.IGNORE:hr.Flags.NONE}):(this.hasExtension=!0,this.extendedType=l,this.extendedContent=n,void(this.flags=u?hr.Flags.IGNORE:hr.Flags.NONE))},l.prototype.close=function(l){this.done||(this.done=!0,fr.cancel(this),l?this.receiver.onError(l):this.receiver.onComplete())},l}();rr.RequestStreamRequesterStream=pr;var yr=function(){function l(l,n,u,e,t){if(this.streamId=l,this.stream=n,this.fragmentSize=u,this.handler=e,this.streamType=hr.FrameTypes.REQUEST_STREAM,n.connect(this),hr.Flags.hasFollows(t.flags))return this.initialRequestN=t.requestN,void fr.add(this,t.data,t.metadata);var r={data:t.data,metadata:t.metadata};try{this.receiver=e(r,t.requestN,this)}catch(l){this.onError(l)}}return l.prototype.handle=function(l){var n,u;if(!this.receiver||this.hasFragments)if(l.type===hr.FrameTypes.PAYLOAD){if(!hr.Flags.hasFollows(l.flags)){var e=fr.reassemble(this,l.data,l.metadata);try{this.receiver=this.handler(e,this.initialRequestN,this)}catch(l){this.onError(l)}return}if(fr.add(this,l.data,l.metadata))return;u="Unexpected frame size"}else u="Unexpected frame type [".concat(l.type,"] during reassembly");else{if(l.type===hr.FrameTypes.REQUEST_N)return void this.receiver.request(l.requestN);if(l.type===hr.FrameTypes.EXT)return void this.receiver.onExtension(l.extendedType,l.extendedContent,hr.Flags.hasIgnore(l.flags));u="Unexpected frame type [".concat(l.type,"]")}this.done=!0,fr.cancel(this),null===(n=this.receiver)||void 0===n||n.cancel(),l.type!==hr.FrameTypes.CANCEL&&l.type!==hr.FrameTypes.ERROR&&this.stream.send({type:hr.FrameTypes.ERROR,flags:hr.Flags.NONE,code:cr.ErrorCodes.CANCELED,message:u,streamId:this.streamId}),this.stream.disconnect(this)},l.prototype.onError=function(l){this.done?console.warn("Trying to error for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(this.done=!0,this.stream.send({type:hr.FrameTypes.ERROR,flags:hr.Flags.NONE,code:l instanceof cr.RSocketError?l.code:cr.ErrorCodes.APPLICATION_ERROR,message:l.message,streamId:this.streamId}),this.stream.disconnect(this))},l.prototype.onNext=function(l,n){var u,e;if(!this.done){if(n&&(this.done=!0),(0,dr.isFragmentable)(l,this.fragmentSize,hr.FrameTypes.PAYLOAD))try{for(var t=sr((0,dr.fragment)(this.streamId,l,this.fragmentSize,hr.FrameTypes.PAYLOAD,n)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:hr.FrameTypes.PAYLOAD,flags:hr.Flags.NEXT|(n?hr.Flags.COMPLETE:hr.Flags.NONE)|(l.metadata?hr.Flags.METADATA:hr.Flags.NONE),data:l.data,metadata:l.metadata,streamId:this.streamId});n&&this.stream.disconnect(this)}},l.prototype.onComplete=function(){this.done||(this.done=!0,this.stream.send({type:hr.FrameTypes.PAYLOAD,flags:hr.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.stream.disconnect(this))},l.prototype.onExtension=function(l,n,u){this.done||this.stream.send({type:hr.FrameTypes.EXT,streamId:this.streamId,flags:u?hr.Flags.IGNORE:hr.Flags.NONE,extendedType:l,extendedContent:n})},l.prototype.close=function(l){var n;this.done?console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(fr.cancel(this),null===(n=this.receiver)||void 0===n||n.cancel())},l}();rr.RequestStreamResponderStream=yr,Object.defineProperty(wt,"__esModule",{value:!0}),wt.KeepAliveSender=wt.KeepAliveHandler=wt.DefaultConnectionFrameHandler=wt.DefaultStreamRequestHandler=wt.LeaseHandler=wt.RSocketRequester=void 0;var mr=yt,gr=ct,br=_t,vr=Bt,Er=Jt,wr=rr,_r=function(){function l(l,n,u){this.connection=l,this.fragmentSize=n,this.leaseManager=u}return l.prototype.fireAndForget=function(l,n){var u=new vr.RequestFnFRequesterStream(l,n,this.fragmentSize,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(u):this.connection.multiplexerDemultiplexer.createRequestStream(u),u},l.prototype.requestResponse=function(l,n){var u=new Er.RequestResponseRequesterStream(l,n,this.fragmentSize,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(u):this.connection.multiplexerDemultiplexer.createRequestStream(u),u},l.prototype.requestStream=function(l,n,u){var e=new wr.RequestStreamRequesterStream(l,u,this.fragmentSize,n,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(e):this.connection.multiplexerDemultiplexer.createRequestStream(e),e},l.prototype.requestChannel=function(l,n,u,e){var t=new br.RequestChannelRequesterStream(l,u,e,this.fragmentSize,n,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(t):this.connection.multiplexerDemultiplexer.createRequestStream(t),t},l.prototype.metadataPush=function(l,n){throw new Error("Method not implemented.")},l.prototype.close=function(l){this.connection.close(l)},l.prototype.onClose=function(l){this.connection.onClose(l)},l}();wt.RSocketRequester=_r;var Sr=function(){function l(l,n){this.maxPendingRequests=l,this.multiplexer=n,this.pendingRequests=[],this.expirationTime=0,this.availableLease=0}return l.prototype.handle=function(l){for(this.expirationTime=l.ttl+Date.now(),this.availableLease=l.requestCount;this.availableLease>0&&this.pendingRequests.length>0;){var n=this.pendingRequests.shift();this.availableLease--,this.multiplexer.createRequestStream(n)}},l.prototype.requestLease=function(l){var n=this.availableLease;if(n>0&&Date.now()<this.expirationTime)return this.availableLease=n-1,void this.multiplexer.createRequestStream(l);this.pendingRequests.length>=this.maxPendingRequests?l.handleReject(new mr.RSocketError(mr.ErrorCodes.REJECTED,"No available lease given")):this.pendingRequests.push(l)},l.prototype.cancelRequest=function(l){var n=this.pendingRequests.indexOf(l);n>-1&&this.pendingRequests.splice(n,1)},l}();wt.LeaseHandler=Sr;var Tr=function(){function l(l,n){this.rsocket=l,this.fragmentSize=n}return l.prototype.handle=function(l,n){switch(l.type){case gr.FrameTypes.REQUEST_FNF:return void(this.rsocket.fireAndForget&&new vr.RequestFnfResponderStream(l.streamId,n,this.rsocket.fireAndForget.bind(this.rsocket),l));case gr.FrameTypes.REQUEST_RESPONSE:return this.rsocket.requestResponse?void new Er.RequestResponseResponderStream(l.streamId,n,this.fragmentSize,this.rsocket.requestResponse.bind(this.rsocket),l):void this.rejectRequest(l.streamId,n);case gr.FrameTypes.REQUEST_STREAM:return this.rsocket.requestStream?void new wr.RequestStreamResponderStream(l.streamId,n,this.fragmentSize,this.rsocket.requestStream.bind(this.rsocket),l):void this.rejectRequest(l.streamId,n);case gr.FrameTypes.REQUEST_CHANNEL:return this.rsocket.requestChannel?void new br.RequestChannelResponderStream(l.streamId,n,this.fragmentSize,this.rsocket.requestChannel.bind(this.rsocket),l):void this.rejectRequest(l.streamId,n)}},l.prototype.rejectRequest=function(l,n){n.send({type:gr.FrameTypes.ERROR,streamId:l,flags:gr.Flags.NONE,code:mr.ErrorCodes.REJECTED,message:"No available handler found"})},l.prototype.close=function(){},l}();wt.DefaultStreamRequestHandler=Tr;var Rr,Or=function(){function l(l,n,u,e,t){this.connection=l,this.keepAliveHandler=n,this.keepAliveSender=u,this.leaseHandler=e,this.rsocket=t}return l.prototype.handle=function(l){switch(l.type){case gr.FrameTypes.KEEPALIVE:return void this.keepAliveHandler.handle(l);case gr.FrameTypes.LEASE:return this.leaseHandler?void this.leaseHandler.handle(l):void 0;case gr.FrameTypes.ERROR:return void this.connection.close(new mr.RSocketError(l.code,l.message));case gr.FrameTypes.METADATA_PUSH:return void this.rsocket.metadataPush;default:this.connection.multiplexerDemultiplexer.connectionOutbound.send({type:gr.FrameTypes.ERROR,streamId:0,flags:gr.Flags.NONE,message:"Received unknown frame type",code:mr.ErrorCodes.CONNECTION_ERROR})}},l.prototype.pause=function(){var l;this.keepAliveHandler.pause(),null===(l=this.keepAliveSender)||void 0===l||l.pause()},l.prototype.resume=function(){var l;this.keepAliveHandler.start(),null===(l=this.keepAliveSender)||void 0===l||l.start()},l.prototype.close=function(l){var n;this.keepAliveHandler.close(),null===(n=this.rsocket.close)||void 0===n||n.call(this.rsocket,l)},l}();wt.DefaultConnectionFrameHandler=Or,function(l){l[l.Paused=0]="Paused",l[l.Running=1]="Running",l[l.Closed=2]="Closed"}(Rr||(Rr={}));var Ar,Cr=function(){function l(l,n){this.connection=l,this.keepAliveTimeoutDuration=n,this.state=Rr.Paused,this.outbound=l.multiplexerDemultiplexer.connectionOutbound}return l.prototype.handle=function(l){this.keepAliveLastReceivedMillis=Date.now(),gr.Flags.hasRespond(l.flags)&&this.outbound.send({type:gr.FrameTypes.KEEPALIVE,streamId:0,data:l.data,flags:l.flags^gr.Flags.RESPOND,lastReceivedPosition:0})},l.prototype.start=function(){this.state===Rr.Paused&&(this.keepAliveLastReceivedMillis=Date.now(),this.state=Rr.Running,this.activeTimeout=setTimeout(this.timeoutCheck.bind(this),this.keepAliveTimeoutDuration))},l.prototype.pause=function(){this.state===Rr.Running&&(this.state=Rr.Paused,clearTimeout(this.activeTimeout))},l.prototype.close=function(){this.state=Rr.Closed,clearTimeout(this.activeTimeout)},l.prototype.timeoutCheck=function(){var l=Date.now()-this.keepAliveLastReceivedMillis;l>=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-l))},l}();wt.KeepAliveHandler=Cr,function(l){l[l.Paused=0]="Paused",l[l.Running=1]="Running",l[l.Closed=2]="Closed"}(Ar||(Ar={}));var Fr=function(){function l(l,n){this.outbound=l,this.keepAlivePeriodDuration=n,this.state=Ar.Paused}return l.prototype.sendKeepAlive=function(){this.outbound.send({type:gr.FrameTypes.KEEPALIVE,streamId:0,data:void 0,flags:gr.Flags.RESPOND,lastReceivedPosition:0})},l.prototype.start=function(){this.state===Ar.Paused&&(this.state=Ar.Running,this.activeInterval=setInterval(this.sendKeepAlive.bind(this),this.keepAlivePeriodDuration))},l.prototype.pause=function(){this.state===Ar.Running&&(this.state=Ar.Paused,clearInterval(this.activeInterval))},l.prototype.close=function(){this.state=Ar.Closed,clearInterval(this.activeInterval)},l}();wt.KeepAliveSender=Fr;var Ir,kr,Pr={};function Lr(){if(Ir)return Pr;Ir=1;var l=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(Pr,"__esModule",{value:!0}),Pr.FrameStore=void 0;var n=qr(),u=st,e=function(){function e(){this.storedFrames=[],this._lastReceivedFramePosition=0,this._firstAvailableFramePosition=0,this._lastSentFramePosition=0}return Object.defineProperty(e.prototype,"lastReceivedFramePosition",{get:function(){return this._lastReceivedFramePosition},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"firstAvailableFramePosition",{get:function(){return this._firstAvailableFramePosition},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lastSentFramePosition",{get:function(){return this._lastSentFramePosition},enumerable:!1,configurable:!0}),e.prototype.store=function(l){this._lastSentFramePosition+=(0,u.sizeOfFrame)(l),this.storedFrames.push(l)},e.prototype.record=function(l){this._lastReceivedFramePosition+=(0,u.sizeOfFrame)(l)},e.prototype.dropTo=function(l){for(var e=l-this._firstAvailableFramePosition;e>0&&this.storedFrames.length>0;){var t=this.storedFrames.shift();e-=(0,u.sizeOfFrame)(t)}if(0!==e)throw new n.RSocketError(n.ErrorCodes.CONNECTION_ERROR,"State inconsistency. Expected bytes to drop ".concat(l-this._firstAvailableFramePosition," but actual ").concat(e));this._firstAvailableFramePosition=l},e.prototype.drain=function(n){var u,e;try{for(var t=l(this.storedFrames),r=t.next();!r.done;r=t.next()){n(r.value)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}},e}();return Pr.FrameStore=e,Pr}function Nr(){if(kr)return bt;kr=1;var l=o&&o.__awaiter||function(l,n,u,e){return new(u||(u=Promise))((function(t,r){function o(l){try{a(e.next(l))}catch(l){r(l)}}function i(l){try{a(e.throw(l))}catch(l){r(l)}}function a(l){var n;l.done?t(l.value):(n=l.value,n instanceof u?n:new u((function(l){l(n)}))).then(o,i)}a((e=e.apply(l,n||[])).next())}))},n=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(bt,"__esModule",{value:!0}),bt.RSocketConnector=void 0;var u=Et(),e=ct,t=wt,r=Lr(),i=function(){function o(l){this.config=l}return o.prototype.connect=function(){var o,i,a,s,c,d,h,f,p,y,m,g,b,v,E,w,_,S,T,R;return l(this,void 0,void 0,(function(){var O,A,C,F,I,k,P,L,N,x=this;return n(this,(function(U){switch(U.label){case 0:return O=this.config,A={type:e.FrameTypes.SETUP,dataMimeType:null!==(i=null===(o=O.setup)||void 0===o?void 0:o.dataMimeType)&&void 0!==i?i:"application/octet-stream",metadataMimeType:null!==(s=null===(a=O.setup)||void 0===a?void 0:a.metadataMimeType)&&void 0!==s?s:"application/octet-stream",keepAlive:null!==(d=null===(c=O.setup)||void 0===c?void 0:c.keepAlive)&&void 0!==d?d:6e4,lifetime:null!==(f=null===(h=O.setup)||void 0===h?void 0:h.lifetime)&&void 0!==f?f:3e5,metadata:null===(y=null===(p=O.setup)||void 0===p?void 0:p.payload)||void 0===y?void 0:y.metadata,data:null===(g=null===(m=O.setup)||void 0===m?void 0:m.payload)||void 0===g?void 0:g.data,resumeToken:null!==(v=null===(b=O.resume)||void 0===b?void 0:b.tokenGenerator())&&void 0!==v?v:null,streamId:0,majorVersion:1,minorVersion:0,flags:((null===(w=null===(E=O.setup)||void 0===E?void 0:E.payload)||void 0===w?void 0:w.metadata)?e.Flags.METADATA:e.Flags.NONE)|(O.lease?e.Flags.LEASE:e.Flags.NONE)|(O.resume?e.Flags.RESUME_ENABLE:e.Flags.NONE)},[4,O.transport.connect((function(t){return O.resume?new u.ResumableClientServerInputMultiplexerDemultiplexer(u.StreamIdGenerator.create(-1),t,t,new r.FrameStore,A.resumeToken.toString(),(function(t,r){return l(x,void 0,void 0,(function(){var l,o,i;return n(this,(function(n){switch(n.label){case 0:return l=function(l){return l.send({type:e.FrameTypes.RESUME,streamId:0,flags:e.Flags.NONE,clientPosition:r.firstAvailableFramePosition,serverPosition:r.lastReceivedFramePosition,majorVersion:A.minorVersion,minorVersion:A.majorVersion,resumeToken:A.resumeToken}),new u.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer(l,l,t)},o=-1,[4,(i=function(){return o++,O.resume.reconnectFunction(o).then((function(){return O.transport.connect(l).catch(i)}))})()];case 1:return n.sent(),[2]}}))}))})):new u.ClientServerInputMultiplexerDemultiplexer(u.StreamIdGenerator.create(-1),t,t)}))];case 1:return C=U.sent(),F=new t.KeepAliveSender(C.multiplexerDemultiplexer.connectionOutbound,A.keepAlive),I=new t.KeepAliveHandler(C,A.lifetime),k=O.lease?new t.LeaseHandler(null!==(_=O.lease.maxPendingRequests)&&void 0!==_?_:256,C.multiplexerDemultiplexer):void 0,P=null!==(S=O.responder)&&void 0!==S?S:{},L=new t.DefaultConnectionFrameHandler(C,I,F,k,P),N=new t.DefaultStreamRequestHandler(P,0),C.onClose((function(l){F.close(),I.close(),L.close(l)})),C.multiplexerDemultiplexer.connectionInbound(L),C.multiplexerDemultiplexer.handleRequestStream(N),C.multiplexerDemultiplexer.connectionOutbound.send(A),I.start(),F.start(),[2,new t.RSocketRequester(C,null!==(R=null===(T=O.fragmentation)||void 0===T?void 0:T.maxOutboundFragmentSize)&&void 0!==R?R:0,k)]}}))}))},o}();return bt.RSocketConnector=i,bt}var xr,Ur={};function Br(){if(xr)return Ur;xr=1;var l=o&&o.__awaiter||function(l,n,u,e){return new(u||(u=Promise))((function(t,r){function o(l){try{a(e.next(l))}catch(l){r(l)}}function i(l){try{a(e.throw(l))}catch(l){r(l)}}function a(l){var n;l.done?t(l.value):(n=l.value,n instanceof u?n:new u((function(l){l(n)}))).then(o,i)}a((e=e.apply(l,n||[])).next())}))},n=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(Ur,"__esModule",{value:!0}),Ur.RSocketServer=void 0;var u=Et(),e=yt,t=ct,r=wt,i=Lr(),a=function(){function o(l){var n,u;this.acceptor=l.acceptor,this.transport=l.transport,this.lease=l.lease,this.serverSideKeepAlive=l.serverSideKeepAlive,this.sessionStore=l.resume?{}:void 0,this.sessionTimeout=null!==(u=null===(n=l.resume)||void 0===n?void 0:n.sessionTimeout)&&void 0!==u?u:void 0}return o.prototype.bind=function(){return l(this,void 0,void 0,(function(){var o=this;return n(this,(function(a){switch(a.label){case 0:return[4,this.transport.bind((function(u,i){return l(o,void 0,void 0,(function(){var l,o,a,s,c,d,h,f,p,y,m,g,b;return n(this,(function(n){switch(n.label){case 0:switch(u.type){case t.FrameTypes.SETUP:return[3,1];case t.FrameTypes.RESUME:return[3,5]}return[3,6];case 1:return n.trys.push([1,3,,4]),this.lease&&!t.Flags.hasLease(u.flags)?(l=new e.RSocketError(e.ErrorCodes.REJECTED_SETUP,"Lease has to be enabled"),i.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,flags:t.Flags.NONE,code:l.code,message:l.message}),i.close(l),[2]):t.Flags.hasLease(u.flags)&&!this.lease?(l=new e.RSocketError(e.ErrorCodes.REJECTED_SETUP,"Lease has to be disabled"),i.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,flags:t.Flags.NONE,code:l.code,message:l.message}),i.close(l),[2]):(o=t.Flags.hasLease(u.flags)?new r.LeaseHandler(null!==(y=this.lease.maxPendingRequests)&&void 0!==y?y:256,i.multiplexerDemultiplexer):void 0,a=new r.RSocketRequester(i,null!==(g=null===(m=this.fragmentation)||void 0===m?void 0:m.maxOutboundFragmentSize)&&void 0!==g?g:0,o),[4,this.acceptor.accept({data:u.data,dataMimeType:u.dataMimeType,metadata:u.metadata,metadataMimeType:u.metadataMimeType,flags:u.flags,keepAliveMaxLifetime:u.lifetime,keepAliveInterval:u.keepAlive,resumeToken:u.resumeToken},a)]);case 2:return s=n.sent(),c=new r.KeepAliveHandler(i,u.lifetime),d=this.serverSideKeepAlive?new r.KeepAliveSender(i.multiplexerDemultiplexer.connectionOutbound,u.keepAlive):void 0,h=new r.DefaultConnectionFrameHandler(i,c,d,o,s),f=new r.DefaultStreamRequestHandler(s,0),i.onClose((function(l){null==d||d.close(),c.close(),h.close(l)})),i.multiplexerDemultiplexer.connectionInbound(h),i.multiplexerDemultiplexer.handleRequestStream(f),c.start(),null==d||d.start(),[3,4];case 3:return p=n.sent(),i.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,code:e.ErrorCodes.REJECTED_SETUP,message:null!==(b=p.message)&&void 0!==b?b:"",flags:t.Flags.NONE}),i.close(p instanceof e.RSocketError?p:new e.RSocketError(e.ErrorCodes.REJECTED_SETUP,p.message)),[3,4];case 4:case 5:return[2];case 6:i.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,code:e.ErrorCodes.UNSUPPORTED_SETUP,message:"Unsupported setup",flags:t.Flags.NONE}),i.close(new e.RSocketError(e.ErrorCodes.UNSUPPORTED_SETUP)),n.label=7;case 7:return[2]}}))}))}),(function(l,n){if(l.type===t.FrameTypes.RESUME){if(o.sessionStore){var r=o.sessionStore[l.resumeToken.toString()];return r?(r.resume(l,n,n),r):(n.send({type:t.FrameTypes.ERROR,streamId:0,code:e.ErrorCodes.REJECTED_RESUME,message:"No session found for the given resume token",flags:t.Flags.NONE}),void n.close())}return n.send({type:t.FrameTypes.ERROR,streamId:0,code:e.ErrorCodes.REJECTED_RESUME,message:"Resume is not enabled",flags:t.Flags.NONE}),void n.close()}if(l.type===t.FrameTypes.SETUP&&t.Flags.hasResume(l.flags)){if(!o.sessionStore){var a=new e.RSocketError(e.ErrorCodes.REJECTED_SETUP,"No resume support");return n.send({type:t.FrameTypes.ERROR,streamId:0,flags:t.Flags.NONE,code:a.code,message:a.message}),void n.close(a)}var s=new u.ResumableClientServerInputMultiplexerDemultiplexer(u.StreamIdGenerator.create(0),n,n,new i.FrameStore,l.resumeToken.toString(),o.sessionStore,o.sessionTimeout);return o.sessionStore[l.resumeToken.toString()]=s,s}return new u.ClientServerInputMultiplexerDemultiplexer(u.StreamIdGenerator.create(0),n,n)}))];case 1:return[2,a.sent()]}}))}))},o}();return Ur.RSocketServer=a,Ur}var Dr,Mr={};function qr(){return Dr||(Dr=1,function(l){var n=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),u=o&&o.__exportStar||function(l,u){for(var e in l)"default"===e||Object.prototype.hasOwnProperty.call(u,e)||n(u,l,e)};Object.defineProperty(l,"__esModule",{value:!0}),u(st,l),u(dt,l),u(ht,l),u(yt,l),u(ct,l),u(mt,l),u(Nr(),l),u(Br(),l),u(Mr,l)}(ut)),ut}Object.defineProperty(Mr,"__esModule",{value:!0});var jr,Wr=qr(),zr={},Qr={},$r={},Hr=o&&o.__extends||(jr=function(l,n){return jr=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,n){l.__proto__=n}||function(l,n){for(var u in n)Object.prototype.hasOwnProperty.call(n,u)&&(l[u]=n[u])},jr(l,n)},function(l,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function u(){this.constructor=l}jr(l,n),l.prototype=null===n?Object.create(n):(u.prototype=n.prototype,new u)});Object.defineProperty($r,"__esModule",{value:!0}),$r.WebsocketDuplexConnection=void 0;var Vr=qr(),Jr=function(l){function n(n,u,e){var t=l.call(this)||this;return t.websocket=n,t.deserializer=u,t.handleClosed=function(l){t.close(new Error(l.reason||"WebsocketDuplexConnection: Socket closed unexpectedly."))},t.handleError=function(l){t.close(l.error)},t.handleMessage=function(l){try{var n=et.Buffer.from(l.data),u=t.deserializer.deserializeFrame(n);t.multiplexerDemultiplexer.handle(u)}catch(l){t.close(l)}},n.addEventListener("close",t.handleClosed),n.addEventListener("error",t.handleError),n.addEventListener("message",t.handleMessage),t.multiplexerDemultiplexer=e(t),t}return Hr(n,l),Object.defineProperty(n.prototype,"availability",{get:function(){return this.done?0:1},enumerable:!1,configurable:!0}),n.prototype.close=function(n){this.done||(this.websocket.removeEventListener("close",this.handleClosed),this.websocket.removeEventListener("error",this.handleError),this.websocket.removeEventListener("message",this.handleMessage),this.websocket.close(),delete this.websocket),l.prototype.close.call(this,n)},n.prototype.send=function(l){if(!this.done){var n=(0,Vr.serializeFrame)(l);this.websocket.send(n)}},n}(Vr.Deferred);$r.WebsocketDuplexConnection=Jr,Object.defineProperty(Qr,"__esModule",{value:!0}),Qr.WebsocketClientTransport=void 0;var Yr=qr(),Xr=$r,Gr=function(){function l(l){var n;this.url=l.url,this.factory=null!==(n=l.wsCreator)&&void 0!==n?n:function(l){return new WebSocket(l)}}return l.prototype.connect=function(l){var n=this;return new Promise((function(u,e){var t=n.factory(n.url);t.binaryType="arraybuffer";var r=function(){t.removeEventListener("open",r),t.removeEventListener("error",o),u(new Xr.WebsocketDuplexConnection(t,new Yr.Deserializer,l))},o=function(l){t.removeEventListener("open",r),t.removeEventListener("error",o),e(l.error)};t.addEventListener("open",r),t.addEventListener("error",o)}))},l}();Qr.WebsocketClientTransport=Gr,function(l){var n=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),u=o&&o.__exportStar||function(l,u){for(var e in l)"default"===e||Object.prototype.hasOwnProperty.call(u,e)||n(u,l,e)};Object.defineProperty(l,"__esModule",{value:!0}),u(Qr,l)}(zr);const Kr={highWater:10,lowWater:0};class Zr extends v{options;dataQueue;isClosed;processingPromise;logger;constructor(n){if(super(),this.options=n,this.processingPromise=null,this.isClosed=!1,this.dataQueue=[],this.logger=n?.logger??l.get("DataStream"),n?.closeOnError){const l=this.registerListener({error:n=>{l?.(),this.close()}})}}get highWatermark(){return this.options?.pressure?.highWaterMark??Kr.highWater}get lowWatermark(){return this.options?.pressure?.lowWaterMark??Kr.lowWater}get closed(){return this.isClosed}async close(){this.isClosed=!0,await this.processingPromise,this.iterateListeners((l=>l.closed?.())),this.dataQueue=[],this.listeners.clear()}enqueueData(l){if(this.isClosed)throw new Error("Cannot enqueue data into closed stream.");this.dataQueue.push(l),this.processQueue()}async read(){return this.dataQueue.length<=this.lowWatermark&&await this.iterateAsyncErrored((async l=>l.lowWater?.())),this.closed?null:new Promise(((l,n)=>{const u=this.registerListener({data:async n=>{l(n),u?.()},closed:()=>{l(null),u?.()},error:l=>{n(l),u?.()}});this.processQueue()}))}forEach(l){return this.dataQueue.length<=this.lowWatermark&&this.iterateAsyncErrored((async l=>l.lowWater?.())),this.registerListener({data:l})}async processQueue(){if(!this.processingPromise)return this.dataQueue.length>=this.highWatermark&&await this.iterateAsyncErrored((async l=>l.highWater?.())),this.processingPromise=this._processQueue()}map(l){const n=new Zr(this.options),u=this.registerListener({data:async u=>{n.enqueueData(l(u))},closed:()=>{n.close(),u?.()}});return n}hasDataReader(){return Array.from(this.listeners.values()).some((l=>!!l.data))}async _processQueue(){if(!this.dataQueue.length||this.isClosed||!this.hasDataReader())return void Promise.resolve().then((()=>this.processingPromise=null));const l=this.dataQueue.shift();await this.iterateAsyncErrored((async n=>n.data?.(l))),this.dataQueue.length<=this.lowWatermark&&await this.iterateAsyncErrored((async l=>l.lowWater?.())),this.processingPromise=null,this.dataQueue.length&&setTimeout((()=>this.processQueue()))}async iterateAsyncErrored(l){for(let n of Array.from(this.listeners.values()))try{await l(n)}catch(l){this.logger.error(l),this.iterateListeners((n=>n.error?.(l)))}}}const lo=l.get("PowerSyncRemote");class no{getFetch(){throw new Error("Unspecified fetch implementation")}}const uo={socketUrlTransformer:l=>l.replace(/^https?:\/\//,(function(l){return"https://"===l?"wss://":"ws://"})),fetchImplementation:new no};class eo{connector;logger;credentials=null;options;constructor(l,n=lo,u){this.connector=l,this.logger=n,this.options={...uo,...u??{}}}get fetch(){const{fetchImplementation:l}=this.options;return l instanceof no?l.getFetch():l}async getCredentials(){const{expiresAt:l}=this.credentials??{};return l&&l>new Date((new Date).valueOf()+3e4)||(this.credentials=await this.connector.fetchCredentials()),this.credentials}getUserAgent(){return"powersync-js/1.20.0"}async buildRequest(l){const n=await this.getCredentials();if(null!=n&&(null==n.endpoint||""==n.endpoint))throw new Error("PowerSync endpoint not configured");if(null==n?.token||""==n?.token){const l=new Error("Not signed in");throw l.status=401,l}const u=this.getUserAgent();return{url:n.endpoint+l,headers:{"content-type":"application/json",Authorization:`Token ${n.token}`,"x-user-agent":u}}}async post(l,n,u={}){const e=await this.buildRequest(l),t=await this.fetch(e.url,{method:"POST",headers:{...u,...e.headers},body:JSON.stringify(n)});if(!t.ok)throw new Error(`Received ${t.status} - ${t.statusText} when posting to ${l}: ${await t.text()}}`);return t.json()}async get(l,n){const u=await this.buildRequest(l),e=await this.fetch(u.url,{method:"GET",headers:{...n,...u.headers}});if(!e.ok)throw new Error(`Received ${e.status} - ${e.statusText} when getting from ${l}: ${await e.text()}}`);return e.json()}async postStreaming(l,n,u={},e){const t=await this.buildRequest(l),r=await this.fetch(t.url,{method:"POST",headers:{...u,...t.headers},body:JSON.stringify(n),signal:e,cache:"no-store"}).catch((n=>{throw this.logger.error(`Caught ex when POST streaming to ${l}`,n),n}));if(!r.ok){const n=await r.text();this.logger.error(`Could not POST streaming to ${l} - ${r.status} - ${r.statusText}: ${n}`);const u=new Error(`HTTP ${r.statusText}: ${n}`);throw u.status=r.status,u}return r}async socketStream(l){const{path:n}=l,u=await this.buildRequest(n),e=await this.getBSON(),t=this.getUserAgent(),r=new Wr.RSocketConnector({transport:new zr.WebsocketClientTransport({url:this.options.socketUrlTransformer(u.url)}),setup:{keepAlive:2e4,lifetime:3e4,dataMimeType:"application/bson",metadataMimeType:"application/bson",payload:{data:null,metadata:De.Buffer.from(e.serialize({token:u.headers.Authorization,user_agent:t}))}}});let o;try{o=await r.connect()}catch(l){throw new Error(`Could not connect to PowerSync instance: ${JSON.stringify(l)}`)}const i=new Zr({logger:this.logger,pressure:{lowWaterMark:5}});let a=!1;o.onClose((()=>a=!0));let s=10;const c=i.registerListener({closed:()=>{a||(a=!0,o.close()),c()}}),d=await new Promise(((u,t)=>{let r=!1;const a=o.requestStream({data:De.Buffer.from(e.serialize(l.data)),metadata:De.Buffer.from(e.serialize({path:n}))},10,{onError:l=>{"Closed. "!==l.message&&this.logger.error(l),i.close(),r||t(l)},onNext:l=>{r||(r=!0,u(a));const{data:n}=l;if(s--,!n)return;const t=e.deserialize(n);i.enqueueData(t)},onComplete:()=>{i.close()},onExtension:()=>{}})})),h=i.registerListener({lowWater:async()=>{10-s>0&&(d.request(10-s),s=10)},closed:()=>{h()}});return l.abortSignal?.aborted?i.close():l.abortSignal?.addEventListener("abort",(()=>{i.close()})),i}async postStream(l){const{data:n,path:u,headers:e,abortSignal:t}=l,r=await this.buildRequest(u),o=new AbortController;let i=!1;t?.addEventListener("abort",(()=>{i||o.abort(t.reason??new L("Cancelling network request before it resolves. Abort signal has been received."))}));const a=await this.fetch(r.url,{method:"POST",headers:{...e,...r.headers},body:JSON.stringify(n),signal:o.signal,cache:"no-store",...l.fetchOptions}).catch((l=>{if("AbortError"==l.name)throw new L(`Pending fetch request to ${r.url} has been aborted.`);throw l}));if(!a)throw new Error("Fetch request was aborted");if(i=!0,!a.ok||!a.body){const l=await a.text();this.logger.error(`Could not POST streaming to ${u} - ${a.status} - ${a.statusText}: ${l}`);const n=new Error(`HTTP ${a.statusText}: ${l}`);throw n.status=a.status,n}const s=a.body.getReader(),c=async()=>{try{await s.cancel()}catch(l){}s.releaseLock()};t?.addEventListener("abort",(()=>{c()}));const d=new Se({start:l=>{(async()=>{for(;!t?.aborted;)try{const{done:n,value:u}=await s.read();if(n)break;l.enqueue(u)}catch(l){this.logger.error("Caught exception when reading sync stream",l);break}t?.aborted||await c(),l.close()})()}}),h=nt(d),f=new Zr({logger:this.logger}),p=h.getReader(),y=f.registerListener({lowWater:async()=>{try{const{done:l,value:n}=await p.read();if(l)return f.close(),void y?.();f.enqueueData(n)}catch(l){throw f.close(),l}},closed:()=>{c(),y?.()}});return f}}var to;!function(l){l.TEXT="TEXT",l.INTEGER="INTEGER",l.REAL="REAL"}(to||(to={}));const ro={type:to.TEXT},oo={type:to.INTEGER},io={type:to.REAL},ao=63,so={text:ro,integer:oo,real:io};class co{options;constructor(l){this.options=l}get name(){return this.options.name}get type(){return this.options.type}toJSON(){return{name:this.name,type:this.type}}}const ho={ascending:!0};class fo{options;static createAscending(l){return new fo({name:l,ascending:!0})}constructor(l){this.options={...ho,...l}}get name(){return this.options.name}get ascending(){return this.options.ascending}toJSON(l){return{name:this.name,ascending:this.ascending,type:l.columns.find((l=>l.name===this.name))?.type??to.TEXT}}}const po={columns:[]};class yo{options;static createAscending(l,n){return new yo({...l,columns:n.map((l=>fo.createAscending(l)))})}constructor(l){this.options=l,this.options={...po,...l}}get name(){return this.options.name}get columns(){return this.options.columns??[]}toJSON(l){return{name:this.name,columns:this.columns.map((n=>n.toJSON(l)))}}}const mo={indexes:[],insertOnly:!1,localOnly:!1},go=/["'%,.#\s[\]]/;class bo{options;_mappedColumns;static createLocalOnly(l){return new bo({...l,localOnly:!0,insertOnly:!1})}static createInsertOnly(l){return new bo({...l,localOnly:!1,insertOnly:!0})}static createTable(l,n){return new bo({name:l,columns:n.columns,indexes:n.indexes,localOnly:n.options.localOnly,insertOnly:n.options.insertOnly,viewName:n.options.viewName})}constructor(l,n){this.isTableV1(l)?this.initTableV1(l):this.initTableV2(l,n)}isTableV1(l){return"columns"in l&&Array.isArray(l.columns)}initTableV1(l){this.options={...l,indexes:l.indexes||[],insertOnly:l.insertOnly??mo.insertOnly,localOnly:l.localOnly??mo.localOnly}}initTableV2(l,n){const u=Object.entries(l).map((([l,n])=>new co({name:l,type:n.type}))),e=Object.entries(n?.indexes??{}).map((([l,n])=>new yo({name:l,columns:n.map((l=>new fo({name:l.replace(/^-/,""),ascending:!l.startsWith("-")})))})));this.options={name:"",columns:u,indexes:e,insertOnly:n?.insertOnly??mo.insertOnly,localOnly:n?.localOnly??mo.localOnly,viewName:n?.viewName},this._mappedColumns=l}get name(){return this.options.name}get viewNameOverride(){return this.options.viewName}get viewName(){return this.viewNameOverride??this.name}get columns(){return this.options.columns}get columnMap(){return this._mappedColumns??this.columns.reduce(((l,n)=>(l[n.name]={type:n.type??to.TEXT},l)),{})}get indexes(){return this.options.indexes??[]}get localOnly(){return this.options.localOnly??!1}get insertOnly(){return this.options.insertOnly??!1}get internalName(){return this.options.localOnly?`ps_data_local__${this.name}`:`ps_data__${this.name}`}get validName(){return!go.test(this.name)&&(null==this.viewNameOverride||!go.test(this.viewNameOverride))}validate(){if(go.test(this.name))throw new Error(`Invalid characters in table name: ${this.name}`);if(this.viewNameOverride&&go.test(this.viewNameOverride))throw new Error(`Invalid characters in view name: ${this.viewNameOverride}`);if(this.columns.length>63)throw new Error("Table has too many columns. The maximum number of columns is 63.");const l=new Set;l.add("id");for(const n of this.columns){const{name:u}=n;if("id"===n.name)throw new Error("An id column is automatically added, custom id columns are not supported");if(l.has(u))throw new Error(`Duplicate column ${u}`);if(go.test(u))throw new Error(`Invalid characters in column name: ${n.name}`);l.add(u)}const n=new Set;for(const u of this.indexes){if(n.has(u.name))throw new Error(`Duplicate index ${u.name}`);if(go.test(u.name))throw new Error(`Invalid characters in index name: ${u.name}`);for(const n of u.columns)if(!l.has(n.name))throw new Error(`Column ${n.name} not found for index ${u.name}`);n.add(u.name)}}toJSON(){return{name:this.name,view_name:this.viewName,local_only:this.localOnly,insert_only:this.insertOnly,columns:this.columns.map((l=>l.toJSON())),indexes:this.indexes.map((l=>l.toJSON(this)))}}}class vo{types;props;tables;constructor(l){Array.isArray(l)?this.tables=l:(this.props=l,this.tables=this.convertToClassicTables(this.props))}validate(){for(const l of this.tables)l.validate()}toJSON(){return{tables:this.tables.map((l=>l.toJSON()))}}convertToClassicTables(l){return Object.entries(l).map((([l,n])=>new bo({name:l,columns:n.columns,indexes:n.indexes,localOnly:n.localOnly,insertOnly:n.insertOnly,viewName:n.viewNameOverride||l})))}}class Eo extends bo{}const wo=(l,n)=>{let u;if("string"==typeof l)u=l;else{if(n.length>0)throw new Error("You cannot pass parameters to a compiled query.");const e=l.compile();u=e.sql,n=e.parameters}return{sqlStatement:u,parameters:n}};export{L as AbortOperation,nl as AbstractPowerSyncDatabase,ul as AbstractPowerSyncDatabaseOpenFactory,eo as AbstractRemote,V as AbstractStreamingSyncImplementation,v as BaseObserver,co as Column,to as ColumnType,I as CrudBatch,k as CrudEntry,P as CrudTransaction,Q as DEFAULT_CRUD_UPLOAD_THROTTLE_MS,ho as DEFAULT_INDEX_COLUMN_OPTIONS,po as DEFAULT_INDEX_OPTIONS,Z as DEFAULT_LOCK_TIMEOUT_MS,X as DEFAULT_POWERSYNC_CLOSE_OPTIONS,K as DEFAULT_POWERSYNC_DB_OPTIONS,Kr as DEFAULT_PRESSURE_LIMITS,lo as DEFAULT_REMOTE_LOGGER,uo as DEFAULT_REMOTE_OPTIONS,$ as DEFAULT_STREAMING_SYNC_OPTIONS,H as DEFAULT_STREAM_CONNECTION_OPTIONS,mo as DEFAULT_TABLE_OPTIONS,G as DEFAULT_WATCH_THROTTLE_MS,Zr as DataStream,no as FetchImplementationProvider,yo as Index,fo as IndexedColumn,go as InvalidSQLCharacters,C as LockType,ao as MAX_AMOUNT_OF_COLUMNS,el as MAX_OP_ID,N as OpType,A as OpTypeEnum,x as OplogEntry,R as PSInternalTable,f as RowUpdateType,vo as Schema,rl as SqliteBucketStorage,ol as SyncDataBatch,U as SyncDataBucket,g as SyncStatus,F as SyncStreamConnectionMethod,bo as Table,Eo as TableV2,O as UpdateType,b as UploadQueueStats,so as column,m as extractTableUpdates,y as isBatchedUpdateNotification,W as isContinueCheckpointRequest,T as isDBAdapter,ll as isPowerSyncDatabaseOptionsWithSettings,S as isSQLOpenFactory,_ as isSQLOpenOptions,D as isStreamingKeepalive,M as isStreamingSyncCheckpoint,q as isStreamingSyncCheckpointComplete,j as isStreamingSyncCheckpointDiff,B as isStreamingSyncData,z as isSyncNewCheckpointRequest,wo as parseQuery};
|
|
17
|
+
!function(l){var n=Me,u=Ve,e="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;l.Buffer=o,l.SlowBuffer=function(l){+l!=l&&(l=0);return o.alloc(+l)},l.INSPECT_MAX_BYTES=50;var t=2147483647;function r(l){if(l>t)throw new RangeError('The value "'+l+'" is invalid for option "size"');var n=new Uint8Array(l);return Object.setPrototypeOf(n,o.prototype),n}function o(l,n,u){if("number"==typeof l){if("string"==typeof n)throw new TypeError('The "string" argument must be of type string. Received type number');return s(l)}return i(l,n,u)}function i(l,n,u){if("string"==typeof l)return function(l,n){"string"==typeof n&&""!==n||(n="utf8");if(!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);var u=0|f(l,n),e=r(u),t=e.write(l,n);t!==u&&(e=e.slice(0,t));return e}(l,n);if(ArrayBuffer.isView(l))return function(l){if(M(l,Uint8Array)){var n=new Uint8Array(l);return d(n.buffer,n.byteOffset,n.byteLength)}return c(l)}(l);if(null==l)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof l);if(M(l,ArrayBuffer)||l&&M(l.buffer,ArrayBuffer))return d(l,n,u);if("undefined"!=typeof SharedArrayBuffer&&(M(l,SharedArrayBuffer)||l&&M(l.buffer,SharedArrayBuffer)))return d(l,n,u);if("number"==typeof l)throw new TypeError('The "value" argument must not be of type number. Received type number');var e=l.valueOf&&l.valueOf();if(null!=e&&e!==l)return o.from(e,n,u);var t=function(l){if(o.isBuffer(l)){var n=0|h(l.length),u=r(n);return 0===u.length||l.copy(u,0,0,n),u}if(void 0!==l.length)return"number"!=typeof l.length||q(l.length)?r(0):c(l);if("Buffer"===l.type&&Array.isArray(l.data))return c(l.data)}(l);if(t)return t;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof l[Symbol.toPrimitive])return o.from(l[Symbol.toPrimitive]("string"),n,u);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof l)}function a(l){if("number"!=typeof l)throw new TypeError('"size" argument must be of type number');if(l<0)throw new RangeError('The value "'+l+'" is invalid for option "size"')}function s(l){return a(l),r(l<0?0:0|h(l))}function c(l){for(var n=l.length<0?0:0|h(l.length),u=r(n),e=0;e<n;e+=1)u[e]=255&l[e];return u}function d(l,n,u){if(n<0||l.byteLength<n)throw new RangeError('"offset" is outside of buffer bounds');if(l.byteLength<n+(u||0))throw new RangeError('"length" is outside of buffer bounds');var e;return e=void 0===n&&void 0===u?new Uint8Array(l):void 0===u?new Uint8Array(l,n):new Uint8Array(l,n,u),Object.setPrototypeOf(e,o.prototype),e}function h(l){if(l>=t)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+t.toString(16)+" bytes");return 0|l}function f(l,n){if(o.isBuffer(l))return l.length;if(ArrayBuffer.isView(l)||M(l,ArrayBuffer))return l.byteLength;if("string"!=typeof l)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof l);var u=l.length,e=arguments.length>2&&!0===arguments[2];if(!e&&0===u)return 0;for(var t=!1;;)switch(n){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return U(l).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*u;case"hex":return u>>>1;case"base64":return B(l).length;default:if(t)return e?-1:U(l).length;n=(""+n).toLowerCase(),t=!0}}function p(l,n,u){var e=!1;if((void 0===n||n<0)&&(n=0),n>this.length)return"";if((void 0===u||u>this.length)&&(u=this.length),u<=0)return"";if((u>>>=0)<=(n>>>=0))return"";for(l||(l="utf8");;)switch(l){case"hex":return C(this,n,u);case"utf8":case"utf-8":return T(this,n,u);case"ascii":return O(this,n,u);case"latin1":case"binary":return A(this,n,u);case"base64":return S(this,n,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return F(this,n,u);default:if(e)throw new TypeError("Unknown encoding: "+l);l=(l+"").toLowerCase(),e=!0}}function y(l,n,u){var e=l[n];l[n]=l[u],l[u]=e}function m(l,n,u,e,t){if(0===l.length)return-1;if("string"==typeof u?(e=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),q(u=+u)&&(u=t?0:l.length-1),u<0&&(u=l.length+u),u>=l.length){if(t)return-1;u=l.length-1}else if(u<0){if(!t)return-1;u=0}if("string"==typeof n&&(n=o.from(n,e)),o.isBuffer(n))return 0===n.length?-1:g(l,n,u,e,t);if("number"==typeof n)return n&=255,"function"==typeof Uint8Array.prototype.indexOf?t?Uint8Array.prototype.indexOf.call(l,n,u):Uint8Array.prototype.lastIndexOf.call(l,n,u):g(l,[n],u,e,t);throw new TypeError("val must be string, number or Buffer")}function g(l,n,u,e,t){var r,o=1,i=l.length,a=n.length;if(void 0!==e&&("ucs2"===(e=String(e).toLowerCase())||"ucs-2"===e||"utf16le"===e||"utf-16le"===e)){if(l.length<2||n.length<2)return-1;o=2,i/=2,a/=2,u/=2}function s(l,n){return 1===o?l[n]:l.readUInt16BE(n*o)}if(t){var c=-1;for(r=u;r<i;r++)if(s(l,r)===s(n,-1===c?0:r-c)){if(-1===c&&(c=r),r-c+1===a)return c*o}else-1!==c&&(r-=r-c),c=-1}else for(u+a>i&&(u=i-a),r=u;r>=0;r--){for(var d=!0,h=0;h<a;h++)if(s(l,r+h)!==s(n,h)){d=!1;break}if(d)return r}return-1}function b(l,n,u,e){u=Number(u)||0;var t=l.length-u;e?(e=Number(e))>t&&(e=t):e=t;var r=n.length;e>r/2&&(e=r/2);for(var o=0;o<e;++o){var i=parseInt(n.substr(2*o,2),16);if(q(i))return o;l[u+o]=i}return o}function v(l,n,u,e){return D(U(n,l.length-u),l,u,e)}function E(l,n,u,e){return D(function(l){for(var n=[],u=0;u<l.length;++u)n.push(255&l.charCodeAt(u));return n}(n),l,u,e)}function w(l,n,u,e){return D(B(n),l,u,e)}function _(l,n,u,e){return D(function(l,n){for(var u,e,t,r=[],o=0;o<l.length&&!((n-=2)<0);++o)e=(u=l.charCodeAt(o))>>8,t=u%256,r.push(t),r.push(e);return r}(n,l.length-u),l,u,e)}function S(l,u,e){return 0===u&&e===l.length?n.fromByteArray(l):n.fromByteArray(l.slice(u,e))}function T(l,n,u){u=Math.min(l.length,u);for(var e=[],t=n;t<u;){var r,o,i,a,s=l[t],c=null,d=s>239?4:s>223?3:s>191?2:1;if(t+d<=u)switch(d){case 1:s<128&&(c=s);break;case 2:128==(192&(r=l[t+1]))&&(a=(31&s)<<6|63&r)>127&&(c=a);break;case 3:r=l[t+1],o=l[t+2],128==(192&r)&&128==(192&o)&&(a=(15&s)<<12|(63&r)<<6|63&o)>2047&&(a<55296||a>57343)&&(c=a);break;case 4:r=l[t+1],o=l[t+2],i=l[t+3],128==(192&r)&&128==(192&o)&&128==(192&i)&&(a=(15&s)<<18|(63&r)<<12|(63&o)<<6|63&i)>65535&&a<1114112&&(c=a)}null===c?(c=65533,d=1):c>65535&&(c-=65536,e.push(c>>>10&1023|55296),c=56320|1023&c),e.push(c),t+=d}return function(l){var n=l.length;if(n<=R)return String.fromCharCode.apply(String,l);var u="",e=0;for(;e<n;)u+=String.fromCharCode.apply(String,l.slice(e,e+=R));return u}(e)}l.kMaxLength=t,o.TYPED_ARRAY_SUPPORT=function(){try{var l=new Uint8Array(1),n={foo:function(){return 42}};return Object.setPrototypeOf(n,Uint8Array.prototype),Object.setPrototypeOf(l,n),42===l.foo()}catch(l){return!1}}(),o.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(l,n,u){return i(l,n,u)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(l,n,u){return function(l,n,u){return a(l),l<=0?r(l):void 0!==n?"string"==typeof u?r(l).fill(n,u):r(l).fill(n):r(l)}(l,n,u)},o.allocUnsafe=function(l){return s(l)},o.allocUnsafeSlow=function(l){return s(l)},o.isBuffer=function(l){return null!=l&&!0===l._isBuffer&&l!==o.prototype},o.compare=function(l,n){if(M(l,Uint8Array)&&(l=o.from(l,l.offset,l.byteLength)),M(n,Uint8Array)&&(n=o.from(n,n.offset,n.byteLength)),!o.isBuffer(l)||!o.isBuffer(n))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(l===n)return 0;for(var u=l.length,e=n.length,t=0,r=Math.min(u,e);t<r;++t)if(l[t]!==n[t]){u=l[t],e=n[t];break}return u<e?-1:e<u?1:0},o.isEncoding=function(l){switch(String(l).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(l,n){if(!Array.isArray(l))throw new TypeError('"list" argument must be an Array of Buffers');if(0===l.length)return o.alloc(0);var u;if(void 0===n)for(n=0,u=0;u<l.length;++u)n+=l[u].length;var e=o.allocUnsafe(n),t=0;for(u=0;u<l.length;++u){var r=l[u];if(M(r,Uint8Array))t+r.length>e.length?o.from(r).copy(e,t):Uint8Array.prototype.set.call(e,r,t);else{if(!o.isBuffer(r))throw new TypeError('"list" argument must be an Array of Buffers');r.copy(e,t)}t+=r.length}return e},o.byteLength=f,o.prototype._isBuffer=!0,o.prototype.swap16=function(){var l=this.length;if(l%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var n=0;n<l;n+=2)y(this,n,n+1);return this},o.prototype.swap32=function(){var l=this.length;if(l%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var n=0;n<l;n+=4)y(this,n,n+3),y(this,n+1,n+2);return this},o.prototype.swap64=function(){var l=this.length;if(l%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var n=0;n<l;n+=8)y(this,n,n+7),y(this,n+1,n+6),y(this,n+2,n+5),y(this,n+3,n+4);return this},o.prototype.toString=function(){var l=this.length;return 0===l?"":0===arguments.length?T(this,0,l):p.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(l){if(!o.isBuffer(l))throw new TypeError("Argument must be a Buffer");return this===l||0===o.compare(this,l)},o.prototype.inspect=function(){var n="",u=l.INSPECT_MAX_BYTES;return n=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(n+=" ... "),"<Buffer "+n+">"},e&&(o.prototype[e]=o.prototype.inspect),o.prototype.compare=function(l,n,u,e,t){if(M(l,Uint8Array)&&(l=o.from(l,l.offset,l.byteLength)),!o.isBuffer(l))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof l);if(void 0===n&&(n=0),void 0===u&&(u=l?l.length:0),void 0===e&&(e=0),void 0===t&&(t=this.length),n<0||u>l.length||e<0||t>this.length)throw new RangeError("out of range index");if(e>=t&&n>=u)return 0;if(e>=t)return-1;if(n>=u)return 1;if(this===l)return 0;for(var r=(t>>>=0)-(e>>>=0),i=(u>>>=0)-(n>>>=0),a=Math.min(r,i),s=this.slice(e,t),c=l.slice(n,u),d=0;d<a;++d)if(s[d]!==c[d]){r=s[d],i=c[d];break}return r<i?-1:i<r?1:0},o.prototype.includes=function(l,n,u){return-1!==this.indexOf(l,n,u)},o.prototype.indexOf=function(l,n,u){return m(this,l,n,u,!0)},o.prototype.lastIndexOf=function(l,n,u){return m(this,l,n,u,!1)},o.prototype.write=function(l,n,u,e){if(void 0===n)e="utf8",u=this.length,n=0;else if(void 0===u&&"string"==typeof n)e=n,u=this.length,n=0;else{if(!isFinite(n))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");n>>>=0,isFinite(u)?(u>>>=0,void 0===e&&(e="utf8")):(e=u,u=void 0)}var t=this.length-n;if((void 0===u||u>t)&&(u=t),l.length>0&&(u<0||n<0)||n>this.length)throw new RangeError("Attempt to write outside buffer bounds");e||(e="utf8");for(var r=!1;;)switch(e){case"hex":return b(this,l,n,u);case"utf8":case"utf-8":return v(this,l,n,u);case"ascii":case"latin1":case"binary":return E(this,l,n,u);case"base64":return w(this,l,n,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,l,n,u);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(""+e).toLowerCase(),r=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var R=4096;function O(l,n,u){var e="";u=Math.min(l.length,u);for(var t=n;t<u;++t)e+=String.fromCharCode(127&l[t]);return e}function A(l,n,u){var e="";u=Math.min(l.length,u);for(var t=n;t<u;++t)e+=String.fromCharCode(l[t]);return e}function C(l,n,u){var e=l.length;(!n||n<0)&&(n=0),(!u||u<0||u>e)&&(u=e);for(var t="",r=n;r<u;++r)t+=j[l[r]];return t}function F(l,n,u){for(var e=l.slice(n,u),t="",r=0;r<e.length-1;r+=2)t+=String.fromCharCode(e[r]+256*e[r+1]);return t}function I(l,n,u){if(l%1!=0||l<0)throw new RangeError("offset is not uint");if(l+n>u)throw new RangeError("Trying to access beyond buffer length")}function k(l,n,u,e,t,r){if(!o.isBuffer(l))throw new TypeError('"buffer" argument must be a Buffer instance');if(n>t||n<r)throw new RangeError('"value" argument is out of bounds');if(u+e>l.length)throw new RangeError("Index out of range")}function P(l,n,u,e,t,r){if(u+e>l.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function L(l,n,e,t,r){return n=+n,e>>>=0,r||P(l,0,e,4),u.write(l,n,e,t,23,4),e+4}function N(l,n,e,t,r){return n=+n,e>>>=0,r||P(l,0,e,8),u.write(l,n,e,t,52,8),e+8}o.prototype.slice=function(l,n){var u=this.length;(l=~~l)<0?(l+=u)<0&&(l=0):l>u&&(l=u),(n=void 0===n?u:~~n)<0?(n+=u)<0&&(n=0):n>u&&(n=u),n<l&&(n=l);var e=this.subarray(l,n);return Object.setPrototypeOf(e,o.prototype),e},o.prototype.readUintLE=o.prototype.readUIntLE=function(l,n,u){l>>>=0,n>>>=0,u||I(l,n,this.length);for(var e=this[l],t=1,r=0;++r<n&&(t*=256);)e+=this[l+r]*t;return e},o.prototype.readUintBE=o.prototype.readUIntBE=function(l,n,u){l>>>=0,n>>>=0,u||I(l,n,this.length);for(var e=this[l+--n],t=1;n>0&&(t*=256);)e+=this[l+--n]*t;return e},o.prototype.readUint8=o.prototype.readUInt8=function(l,n){return l>>>=0,n||I(l,1,this.length),this[l]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(l,n){return l>>>=0,n||I(l,2,this.length),this[l]|this[l+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(l,n){return l>>>=0,n||I(l,2,this.length),this[l]<<8|this[l+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(l,n){return l>>>=0,n||I(l,4,this.length),(this[l]|this[l+1]<<8|this[l+2]<<16)+16777216*this[l+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(l,n){return l>>>=0,n||I(l,4,this.length),16777216*this[l]+(this[l+1]<<16|this[l+2]<<8|this[l+3])},o.prototype.readIntLE=function(l,n,u){l>>>=0,n>>>=0,u||I(l,n,this.length);for(var e=this[l],t=1,r=0;++r<n&&(t*=256);)e+=this[l+r]*t;return e>=(t*=128)&&(e-=Math.pow(2,8*n)),e},o.prototype.readIntBE=function(l,n,u){l>>>=0,n>>>=0,u||I(l,n,this.length);for(var e=n,t=1,r=this[l+--e];e>0&&(t*=256);)r+=this[l+--e]*t;return r>=(t*=128)&&(r-=Math.pow(2,8*n)),r},o.prototype.readInt8=function(l,n){return l>>>=0,n||I(l,1,this.length),128&this[l]?-1*(255-this[l]+1):this[l]},o.prototype.readInt16LE=function(l,n){l>>>=0,n||I(l,2,this.length);var u=this[l]|this[l+1]<<8;return 32768&u?4294901760|u:u},o.prototype.readInt16BE=function(l,n){l>>>=0,n||I(l,2,this.length);var u=this[l+1]|this[l]<<8;return 32768&u?4294901760|u:u},o.prototype.readInt32LE=function(l,n){return l>>>=0,n||I(l,4,this.length),this[l]|this[l+1]<<8|this[l+2]<<16|this[l+3]<<24},o.prototype.readInt32BE=function(l,n){return l>>>=0,n||I(l,4,this.length),this[l]<<24|this[l+1]<<16|this[l+2]<<8|this[l+3]},o.prototype.readFloatLE=function(l,n){return l>>>=0,n||I(l,4,this.length),u.read(this,l,!0,23,4)},o.prototype.readFloatBE=function(l,n){return l>>>=0,n||I(l,4,this.length),u.read(this,l,!1,23,4)},o.prototype.readDoubleLE=function(l,n){return l>>>=0,n||I(l,8,this.length),u.read(this,l,!0,52,8)},o.prototype.readDoubleBE=function(l,n){return l>>>=0,n||I(l,8,this.length),u.read(this,l,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(l,n,u,e){(l=+l,n>>>=0,u>>>=0,e)||k(this,l,n,u,Math.pow(2,8*u)-1,0);var t=1,r=0;for(this[n]=255&l;++r<u&&(t*=256);)this[n+r]=l/t&255;return n+u},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(l,n,u,e){(l=+l,n>>>=0,u>>>=0,e)||k(this,l,n,u,Math.pow(2,8*u)-1,0);var t=u-1,r=1;for(this[n+t]=255&l;--t>=0&&(r*=256);)this[n+t]=l/r&255;return n+u},o.prototype.writeUint8=o.prototype.writeUInt8=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,1,255,0),this[n]=255&l,n+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,2,65535,0),this[n]=255&l,this[n+1]=l>>>8,n+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,2,65535,0),this[n]=l>>>8,this[n+1]=255&l,n+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,4,4294967295,0),this[n+3]=l>>>24,this[n+2]=l>>>16,this[n+1]=l>>>8,this[n]=255&l,n+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,4,4294967295,0),this[n]=l>>>24,this[n+1]=l>>>16,this[n+2]=l>>>8,this[n+3]=255&l,n+4},o.prototype.writeIntLE=function(l,n,u,e){if(l=+l,n>>>=0,!e){var t=Math.pow(2,8*u-1);k(this,l,n,u,t-1,-t)}var r=0,o=1,i=0;for(this[n]=255&l;++r<u&&(o*=256);)l<0&&0===i&&0!==this[n+r-1]&&(i=1),this[n+r]=(l/o|0)-i&255;return n+u},o.prototype.writeIntBE=function(l,n,u,e){if(l=+l,n>>>=0,!e){var t=Math.pow(2,8*u-1);k(this,l,n,u,t-1,-t)}var r=u-1,o=1,i=0;for(this[n+r]=255&l;--r>=0&&(o*=256);)l<0&&0===i&&0!==this[n+r+1]&&(i=1),this[n+r]=(l/o|0)-i&255;return n+u},o.prototype.writeInt8=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,1,127,-128),l<0&&(l=255+l+1),this[n]=255&l,n+1},o.prototype.writeInt16LE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,2,32767,-32768),this[n]=255&l,this[n+1]=l>>>8,n+2},o.prototype.writeInt16BE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,2,32767,-32768),this[n]=l>>>8,this[n+1]=255&l,n+2},o.prototype.writeInt32LE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,4,2147483647,-2147483648),this[n]=255&l,this[n+1]=l>>>8,this[n+2]=l>>>16,this[n+3]=l>>>24,n+4},o.prototype.writeInt32BE=function(l,n,u){return l=+l,n>>>=0,u||k(this,l,n,4,2147483647,-2147483648),l<0&&(l=4294967295+l+1),this[n]=l>>>24,this[n+1]=l>>>16,this[n+2]=l>>>8,this[n+3]=255&l,n+4},o.prototype.writeFloatLE=function(l,n,u){return L(this,l,n,!0,u)},o.prototype.writeFloatBE=function(l,n,u){return L(this,l,n,!1,u)},o.prototype.writeDoubleLE=function(l,n,u){return N(this,l,n,!0,u)},o.prototype.writeDoubleBE=function(l,n,u){return N(this,l,n,!1,u)},o.prototype.copy=function(l,n,u,e){if(!o.isBuffer(l))throw new TypeError("argument should be a Buffer");if(u||(u=0),e||0===e||(e=this.length),n>=l.length&&(n=l.length),n||(n=0),e>0&&e<u&&(e=u),e===u)return 0;if(0===l.length||0===this.length)return 0;if(n<0)throw new RangeError("targetStart out of bounds");if(u<0||u>=this.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("sourceEnd out of bounds");e>this.length&&(e=this.length),l.length-n<e-u&&(e=l.length-n+u);var t=e-u;return this===l&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(n,u,e):Uint8Array.prototype.set.call(l,this.subarray(u,e),n),t},o.prototype.fill=function(l,n,u,e){if("string"==typeof l){if("string"==typeof n?(e=n,n=0,u=this.length):"string"==typeof u&&(e=u,u=this.length),void 0!==e&&"string"!=typeof e)throw new TypeError("encoding must be a string");if("string"==typeof e&&!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);if(1===l.length){var t=l.charCodeAt(0);("utf8"===e&&t<128||"latin1"===e)&&(l=t)}}else"number"==typeof l?l&=255:"boolean"==typeof l&&(l=Number(l));if(n<0||this.length<n||this.length<u)throw new RangeError("Out of range index");if(u<=n)return this;var r;if(n>>>=0,u=void 0===u?this.length:u>>>0,l||(l=0),"number"==typeof l)for(r=n;r<u;++r)this[r]=l;else{var i=o.isBuffer(l)?l:o.from(l,e),a=i.length;if(0===a)throw new TypeError('The value "'+l+'" is invalid for argument "value"');for(r=0;r<u-n;++r)this[r+n]=i[r%a]}return this};var x=/[^+/0-9A-Za-z-_]/g;function U(l,n){var u;n=n||1/0;for(var e=l.length,t=null,r=[],o=0;o<e;++o){if((u=l.charCodeAt(o))>55295&&u<57344){if(!t){if(u>56319){(n-=3)>-1&&r.push(239,191,189);continue}if(o+1===e){(n-=3)>-1&&r.push(239,191,189);continue}t=u;continue}if(u<56320){(n-=3)>-1&&r.push(239,191,189),t=u;continue}u=65536+(t-55296<<10|u-56320)}else t&&(n-=3)>-1&&r.push(239,191,189);if(t=null,u<128){if((n-=1)<0)break;r.push(u)}else if(u<2048){if((n-=2)<0)break;r.push(u>>6|192,63&u|128)}else if(u<65536){if((n-=3)<0)break;r.push(u>>12|224,u>>6&63|128,63&u|128)}else{if(!(u<1114112))throw new Error("Invalid code point");if((n-=4)<0)break;r.push(u>>18|240,u>>12&63|128,u>>6&63|128,63&u|128)}}return r}function B(l){return n.toByteArray(function(l){if((l=(l=l.split("=")[0]).trim().replace(x,"")).length<2)return"";for(;l.length%4!=0;)l+="=";return l}(l))}function D(l,n,u,e){for(var t=0;t<e&&!(t+u>=n.length||t>=l.length);++t)n[t+u]=l[t];return t}function M(l,n){return l instanceof n||null!=l&&null!=l.constructor&&null!=l.constructor.name&&l.constructor.name===n.name}function q(l){return l!=l}var j=function(){for(var l="0123456789abcdef",n=new Array(256),u=0;u<16;++u)for(var e=16*u,t=0;t<16;++t)n[e+t]=l[u]+l[t];return n}()}(et);var tt,rt,ot,it,at,st={},ct={};tt=ct,Object.defineProperty(tt,"__esModule",{value:!0}),tt.Frame=tt.Lengths=tt.Flags=tt.FrameTypes=void 0,function(l){l[l.RESERVED=0]="RESERVED",l[l.SETUP=1]="SETUP",l[l.LEASE=2]="LEASE",l[l.KEEPALIVE=3]="KEEPALIVE",l[l.REQUEST_RESPONSE=4]="REQUEST_RESPONSE",l[l.REQUEST_FNF=5]="REQUEST_FNF",l[l.REQUEST_STREAM=6]="REQUEST_STREAM",l[l.REQUEST_CHANNEL=7]="REQUEST_CHANNEL",l[l.REQUEST_N=8]="REQUEST_N",l[l.CANCEL=9]="CANCEL",l[l.PAYLOAD=10]="PAYLOAD",l[l.ERROR=11]="ERROR",l[l.METADATA_PUSH=12]="METADATA_PUSH",l[l.RESUME=13]="RESUME",l[l.RESUME_OK=14]="RESUME_OK",l[l.EXT=63]="EXT"}(rt=tt.FrameTypes||(tt.FrameTypes={})),(ot=tt.Flags||(tt.Flags={}))[ot.NONE=0]="NONE",ot[ot.COMPLETE=64]="COMPLETE",ot[ot.FOLLOWS=128]="FOLLOWS",ot[ot.IGNORE=512]="IGNORE",ot[ot.LEASE=64]="LEASE",ot[ot.METADATA=256]="METADATA",ot[ot.NEXT=32]="NEXT",ot[ot.RESPOND=128]="RESPOND",ot[ot.RESUME_ENABLE=128]="RESUME_ENABLE",function(l){l.hasMetadata=function(n){return(n&l.METADATA)===l.METADATA},l.hasComplete=function(n){return(n&l.COMPLETE)===l.COMPLETE},l.hasNext=function(n){return(n&l.NEXT)===l.NEXT},l.hasFollows=function(n){return(n&l.FOLLOWS)===l.FOLLOWS},l.hasIgnore=function(n){return(n&l.IGNORE)===l.IGNORE},l.hasRespond=function(n){return(n&l.RESPOND)===l.RESPOND},l.hasLease=function(n){return(n&l.LEASE)===l.LEASE},l.hasResume=function(n){return(n&l.RESUME_ENABLE)===l.RESUME_ENABLE}}(tt.Flags||(tt.Flags={})),(it=tt.Lengths||(tt.Lengths={}))[it.FRAME=3]="FRAME",it[it.HEADER=6]="HEADER",it[it.METADATA=3]="METADATA",it[it.REQUEST=3]="REQUEST",(at=tt.Frame||(tt.Frame={})).isConnection=function(l){return 0===l.streamId},at.isRequest=function(l){return rt.REQUEST_RESPONSE<=l.type&&l.type<=rt.REQUEST_CHANNEL},function(l){var n=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(l,"__esModule",{value:!0}),l.Deserializer=l.sizeOfFrame=l.serializeFrame=l.deserializeFrame=l.serializeFrameWithLength=l.deserializeFrames=l.deserializeFrameWithLength=l.writeUInt64BE=l.readUInt64BE=l.writeUInt24BE=l.readUInt24BE=l.MAX_VERSION=l.MAX_TTL=l.MAX_STREAM_ID=l.MAX_RESUME_LENGTH=l.MAX_REQUEST_N=l.MAX_REQUEST_COUNT=l.MAX_MIME_LENGTH=l.MAX_METADATA_LENGTH=l.MAX_LIFETIME=l.MAX_KEEPALIVE=l.MAX_CODE=l.FRAME_TYPE_OFFFSET=l.FLAGS_MASK=void 0;var u=ct;l.FLAGS_MASK=1023,l.FRAME_TYPE_OFFFSET=10,l.MAX_CODE=2147483647,l.MAX_KEEPALIVE=2147483647,l.MAX_LIFETIME=2147483647,l.MAX_METADATA_LENGTH=16777215,l.MAX_MIME_LENGTH=255,l.MAX_REQUEST_COUNT=2147483647,l.MAX_REQUEST_N=2147483647,l.MAX_RESUME_LENGTH=65535,l.MAX_STREAM_ID=2147483647,l.MAX_TTL=2147483647,l.MAX_VERSION=65535;var e=4294967296;function t(l,n){return l.readUInt8(n)<<16|l.readUInt8(n+1)<<8|l.readUInt8(n+2)}function r(l,n,u){return u=l.writeUInt8(n>>>16,u),u=l.writeUInt8(n>>>8&255,u),l.writeUInt8(255&n,u)}function i(l,n){var u=l.readUInt32BE(n),t=l.readUInt32BE(n+4);return u*e+t}function a(l,n,u){var t=n/e|0,r=n%e;return u=l.writeUInt32BE(t,u),l.writeUInt32BE(r,u)}l.readUInt24BE=t,l.writeUInt24BE=r,l.readUInt64BE=i,l.writeUInt64BE=a;function s(l){var n=t(l,0);return d(l.slice(3,3+n))}function c(l){var u,e,r,o,i;return n(this,(function(n){switch(n.label){case 0:u=0,n.label=1;case 1:return u+3<l.length?(e=t(l,u),(o=(r=u+3)+e)>l.length?[3,3]:(i=l.slice(r,o),[4,[d(i),u=o]])):[3,3];case 2:return n.sent(),[3,1];case 3:return[2]}}))}function d(n){var e=0,t=n.readInt32BE(e);e+=4;var r=n.readUInt16BE(e);e+=2;var o=r>>>l.FRAME_TYPE_OFFFSET,a=r&l.FLAGS_MASK;switch(o){case u.FrameTypes.SETUP:return function(l,n,e){l.length;var t=6,r=l.readUInt16BE(t);t+=2;var o=l.readUInt16BE(t);t+=2;var i=l.readInt32BE(t);t+=4;var a=l.readInt32BE(t);t+=4;var s=null;if(e&u.Flags.RESUME_ENABLE){var c=l.readInt16BE(t);t+=2,s=l.slice(t,t+c),t+=c}var d=l.readUInt8(t);t+=1;var h=l.toString("ascii",t,t+d);t+=d;var f=l.readUInt8(t);t+=1;var p=l.toString("ascii",t,t+f);t+=f;var y={data:null,dataMimeType:p,flags:e,keepAlive:i,lifetime:a,majorVersion:r,metadata:null,metadataMimeType:h,minorVersion:o,resumeToken:s,streamId:0,type:u.FrameTypes.SETUP};return R(l,y,t),y}(n,0,a);case u.FrameTypes.PAYLOAD:return function(l,n,e){l.length;var t={data:null,flags:e,metadata:null,streamId:n,type:u.FrameTypes.PAYLOAD};return R(l,t,6),t}(n,t,a);case u.FrameTypes.ERROR:return function(l,n,e){l.length;var t=6,r=l.readInt32BE(t);t+=4;var o=l.length-t,i="";o>0&&(i=l.toString("utf8",t,t+o),t+=o);return{code:r,flags:e,message:i,streamId:n,type:u.FrameTypes.ERROR}}(n,t,a);case u.FrameTypes.KEEPALIVE:return function(l,n,e){l.length;var t=6,r=i(l,t);t+=8;var o=null;t<l.length&&(o=l.slice(t,l.length));return{data:o,flags:e,lastReceivedPosition:r,streamId:0,type:u.FrameTypes.KEEPALIVE}}(n,0,a);case u.FrameTypes.REQUEST_FNF:return function(l,n,e){l.length;var t={data:null,flags:e,metadata:null,streamId:n,type:u.FrameTypes.REQUEST_FNF};return R(l,t,6),t}(n,t,a);case u.FrameTypes.REQUEST_RESPONSE:return function(l,n,e){var t={data:null,flags:e,metadata:null,streamId:n,type:u.FrameTypes.REQUEST_RESPONSE};return R(l,t,6),t}(n,t,a);case u.FrameTypes.REQUEST_STREAM:return function(l,n,e){l.length;var t=6,r=l.readInt32BE(t);t+=4;var o={data:null,flags:e,metadata:null,requestN:r,streamId:n,type:u.FrameTypes.REQUEST_STREAM};return R(l,o,t),o}(n,t,a);case u.FrameTypes.REQUEST_CHANNEL:return function(l,n,e){l.length;var t=6,r=l.readInt32BE(t);t+=4;var o={data:null,flags:e,metadata:null,requestN:r,streamId:n,type:u.FrameTypes.REQUEST_CHANNEL};return R(l,o,t),o}(n,t,a);case u.FrameTypes.METADATA_PUSH:return function(l,n,e){return{flags:e,metadata:6===length?null:l.slice(6,length),streamId:0,type:u.FrameTypes.METADATA_PUSH}}(n,0,a);case u.FrameTypes.REQUEST_N:return function(l,n,e){l.length;var t=l.readInt32BE(6);return{flags:e,requestN:t,streamId:n,type:u.FrameTypes.REQUEST_N}}(n,t,a);case u.FrameTypes.RESUME:return function(l,n,e){l.length;var t=6,r=l.readUInt16BE(t);t+=2;var o=l.readUInt16BE(t);t+=2;var a=l.readInt16BE(t);t+=2;var s=l.slice(t,t+a);t+=a;var c=i(l,t);t+=8;var d=i(l,t);return t+=8,{clientPosition:d,flags:e,majorVersion:r,minorVersion:o,resumeToken:s,serverPosition:c,streamId:0,type:u.FrameTypes.RESUME}}(n,0,a);case u.FrameTypes.RESUME_OK:return function(l,n,e){l.length;var t=i(l,6);return{clientPosition:t,flags:e,streamId:0,type:u.FrameTypes.RESUME_OK}}(n,0,a);case u.FrameTypes.CANCEL:return function(l,n,e){return l.length,{flags:e,streamId:n,type:u.FrameTypes.CANCEL}}(n,t,a);case u.FrameTypes.LEASE:return function(l,n,e){var t=6,r=l.readUInt32BE(t);t+=4;var o=l.readUInt32BE(t);t+=4;var i=null;t<l.length&&(i=l.slice(t,l.length));return{flags:e,metadata:i,requestCount:o,streamId:0,ttl:r,type:u.FrameTypes.LEASE}}(n,0,a)}}function h(l){switch(l.type){case u.FrameTypes.SETUP:return function(l){var n=null!=l.resumeToken?l.resumeToken.byteLength:0,e=null!=l.metadataMimeType?et.Buffer.byteLength(l.metadataMimeType,"ascii"):0,t=null!=l.dataMimeType?et.Buffer.byteLength(l.dataMimeType,"ascii"):0,r=S(l),o=et.Buffer.allocUnsafe(6+f+(n?p+n:0)+e+t+r),i=_(l,o);i=o.writeUInt16BE(l.majorVersion,i),i=o.writeUInt16BE(l.minorVersion,i),i=o.writeUInt32BE(l.keepAlive,i),i=o.writeUInt32BE(l.lifetime,i),l.flags&u.Flags.RESUME_ENABLE&&(i=o.writeUInt16BE(n,i),null!=l.resumeToken&&(i+=l.resumeToken.copy(o,i)));i=o.writeUInt8(e,i),null!=l.metadataMimeType&&(i+=o.write(l.metadataMimeType,i,i+e,"ascii"));i=o.writeUInt8(t,i),null!=l.dataMimeType&&(i+=o.write(l.dataMimeType,i,i+t,"ascii"));return T(l,o,i),o}(l);case u.FrameTypes.PAYLOAD:return function(l){var n=S(l),u=et.Buffer.allocUnsafe(6+n),e=_(l,u);return T(l,u,e),u}(l);case u.FrameTypes.ERROR:return function(l){var n=null!=l.message?et.Buffer.byteLength(l.message,"utf8"):0,u=et.Buffer.allocUnsafe(6+y+n),e=_(l,u);e=u.writeUInt32BE(l.code,e),null!=l.message&&u.write(l.message,e,e+n,"utf8");return u}(l);case u.FrameTypes.KEEPALIVE:return function(l){var n=null!=l.data?l.data.byteLength:0,u=et.Buffer.allocUnsafe(6+m+n),e=_(l,u);e=a(u,l.lastReceivedPosition,e),null!=l.data&&l.data.copy(u,e);return u}(l);case u.FrameTypes.REQUEST_FNF:case u.FrameTypes.REQUEST_RESPONSE:return function(l){var n=S(l),u=et.Buffer.allocUnsafe(6+n),e=_(l,u);return T(l,u,e),u}(l);case u.FrameTypes.REQUEST_STREAM:case u.FrameTypes.REQUEST_CHANNEL:return function(l){var n=S(l),u=et.Buffer.allocUnsafe(6+b+n),e=_(l,u);return e=u.writeUInt32BE(l.requestN,e),T(l,u,e),u}(l);case u.FrameTypes.METADATA_PUSH:return function(l){var n=l.metadata;if(null!=n){var u=_(l,e=et.Buffer.allocUnsafe(6+n.byteLength));return n.copy(e,u),e}var e;return _(l,e=et.Buffer.allocUnsafe(6)),e}(l);case u.FrameTypes.REQUEST_N:return function(l){var n=et.Buffer.allocUnsafe(6+v),u=_(l,n);return n.writeUInt32BE(l.requestN,u),n}(l);case u.FrameTypes.RESUME:return function(l){var n=l.resumeToken.byteLength,u=et.Buffer.allocUnsafe(6+E+n),e=_(l,u);return e=u.writeUInt16BE(l.majorVersion,e),e=u.writeUInt16BE(l.minorVersion,e),e=u.writeUInt16BE(n,e),e+=l.resumeToken.copy(u,e),e=a(u,l.serverPosition,e),a(u,l.clientPosition,e),u}(l);case u.FrameTypes.RESUME_OK:return function(l){var n=et.Buffer.allocUnsafe(6+w),u=_(l,n);return a(n,l.clientPosition,u),n}(l);case u.FrameTypes.CANCEL:return function(l){var n=et.Buffer.allocUnsafe(6);return _(l,n),n}(l);case u.FrameTypes.LEASE:return function(l){var n=null!=l.metadata?l.metadata.byteLength:0,u=et.Buffer.allocUnsafe(6+g+n),e=_(l,u);e=u.writeUInt32BE(l.ttl,e),e=u.writeUInt32BE(l.requestCount,e),null!=l.metadata&&l.metadata.copy(u,e);return u}(l)}}l.deserializeFrameWithLength=s,l.deserializeFrames=c,l.serializeFrameWithLength=function(l){var n=h(l),u=et.Buffer.allocUnsafe(n.length+3);return r(u,n.length,0),n.copy(u,3),u},l.deserializeFrame=d,l.serializeFrame=h,l.sizeOfFrame=function(l){switch(l.type){case u.FrameTypes.SETUP:return function(l){var n=null!=l.resumeToken?l.resumeToken.byteLength:0,u=null!=l.metadataMimeType?et.Buffer.byteLength(l.metadataMimeType,"ascii"):0,e=null!=l.dataMimeType?et.Buffer.byteLength(l.dataMimeType,"ascii"):0,t=S(l);return 6+f+(n?p+n:0)+u+e+t}(l);case u.FrameTypes.PAYLOAD:return function(l){var n=S(l);return 6+n}(l);case u.FrameTypes.ERROR:return function(l){var n=null!=l.message?et.Buffer.byteLength(l.message,"utf8"):0;return 6+y+n}(l);case u.FrameTypes.KEEPALIVE:return function(l){var n=null!=l.data?l.data.byteLength:0;return 6+m+n}(l);case u.FrameTypes.REQUEST_FNF:case u.FrameTypes.REQUEST_RESPONSE:return function(l){var n=S(l);return 6+n}(l);case u.FrameTypes.REQUEST_STREAM:case u.FrameTypes.REQUEST_CHANNEL:return function(l){var n=S(l);return 6+b+n}(l);case u.FrameTypes.METADATA_PUSH:return function(l){return 6+(null!=l.metadata?l.metadata.byteLength:0)}(l);case u.FrameTypes.REQUEST_N:return 6+v;case u.FrameTypes.RESUME:return function(l){var n=l.resumeToken.byteLength;return 6+E+n}(l);case u.FrameTypes.RESUME_OK:return 6+w;case u.FrameTypes.CANCEL:return 6;case u.FrameTypes.LEASE:return function(l){var n=null!=l.metadata?l.metadata.byteLength:0;return 6+g+n}(l)}};var f=14,p=2;var y=4;var m=8;var g=8;var b=4;var v=4;var E=22;var w=8;function _(n,u){var e=u.writeInt32BE(n.streamId,0);return u.writeUInt16BE(n.type<<l.FRAME_TYPE_OFFFSET|n.flags&l.FLAGS_MASK,e)}function S(l){var n=0;return null!=l.data&&(n+=l.data.byteLength),u.Flags.hasMetadata(l.flags)&&(n+=3,null!=l.metadata&&(n+=l.metadata.byteLength)),n}function T(l,n,e){u.Flags.hasMetadata(l.flags)&&(null!=l.metadata?(e=r(n,l.metadata.byteLength,e),e+=l.metadata.copy(n,e)):e=r(n,0,e));null!=l.data&&l.data.copy(n,e)}function R(l,n,e){if(u.Flags.hasMetadata(n.flags)){var r=t(l,e);e+=3,r>0&&(n.metadata=l.slice(e,e+r),e+=r)}e<l.length&&(n.data=l.slice(e,l.length))}var O=function(){function l(){}return l.prototype.deserializeFrame=function(l){return d(l)},l.prototype.deserializeFrameWithLength=function(l){return s(l)},l.prototype.deserializeFrames=function(l){return c(l)},l}();l.Deserializer=O}(st);var dt={};Object.defineProperty(dt,"__esModule",{value:!0});var ht={},ft=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(ht,"__esModule",{value:!0}),ht.Deferred=void 0;var pt=function(){function l(){this._done=!1,this.onCloseCallbacks=[]}return Object.defineProperty(l.prototype,"done",{get:function(){return this._done},enumerable:!1,configurable:!0}),l.prototype.close=function(l){var n,u,e,t;if(this.done)console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):""));else if(this._done=!0,this._error=l,l)try{for(var r=ft(this.onCloseCallbacks),o=r.next();!o.done;o=r.next()){(0,o.value)(l)}}catch(l){n={error:l}}finally{try{o&&!o.done&&(u=r.return)&&u.call(r)}finally{if(n)throw n.error}}else try{for(var i=ft(this.onCloseCallbacks),a=i.next();!a.done;a=i.next()){(0,a.value)()}}catch(l){e={error:l}}finally{try{a&&!a.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}},l.prototype.onClose=function(l){this._done?l(this._error):this.onCloseCallbacks.push(l)},l}();ht.Deferred=pt;var yt={};!function(l){var n,u=o&&o.__extends||(n=function(l,u){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,n){l.__proto__=n}||function(l,n){for(var u in n)Object.prototype.hasOwnProperty.call(n,u)&&(l[u]=n[u])},n(l,u)},function(l,u){if("function"!=typeof u&&null!==u)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");function e(){this.constructor=l}n(l,u),l.prototype=null===u?Object.create(u):(e.prototype=u.prototype,new e)});Object.defineProperty(l,"__esModule",{value:!0}),l.ErrorCodes=l.RSocketError=void 0;var e,t=function(l){function n(n,u){var e=l.call(this,u)||this;return e.code=n,e}return u(n,l),n}(Error);l.RSocketError=t,(e=l.ErrorCodes||(l.ErrorCodes={}))[e.RESERVED=0]="RESERVED",e[e.INVALID_SETUP=1]="INVALID_SETUP",e[e.UNSUPPORTED_SETUP=2]="UNSUPPORTED_SETUP",e[e.REJECTED_SETUP=3]="REJECTED_SETUP",e[e.REJECTED_RESUME=4]="REJECTED_RESUME",e[e.CONNECTION_CLOSE=258]="CONNECTION_CLOSE",e[e.CONNECTION_ERROR=257]="CONNECTION_ERROR",e[e.APPLICATION_ERROR=513]="APPLICATION_ERROR",e[e.REJECTED=514]="REJECTED",e[e.CANCELED=515]="CANCELED",e[e.INVALID=516]="INVALID",e[e.RESERVED_EXTENSION=4294967295]="RESERVED_EXTENSION"}(yt);var mt={};Object.defineProperty(mt,"__esModule",{value:!0});var gt,bt={},vt={};function Et(){return gt||(gt=1,function(l){var n,u=o&&o.__extends||(n=function(l,u){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,n){l.__proto__=n}||function(l,n){for(var u in n)Object.prototype.hasOwnProperty.call(n,u)&&(l[u]=n[u])},n(l,u)},function(l,u){if("function"!=typeof u&&null!==u)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");function e(){this.constructor=l}n(l,u),l.prototype=null===u?Object.create(u):(e.prototype=u.prototype,new e)}),e=o&&o.__awaiter||function(l,n,u,e){return new(u||(u=Promise))((function(t,r){function o(l){try{a(e.next(l))}catch(l){r(l)}}function i(l){try{a(e.throw(l))}catch(l){r(l)}}function a(l){var n;l.done?t(l.value):(n=l.value,n instanceof u?n:new u((function(l){l(n)}))).then(o,i)}a((e=e.apply(l,n||[])).next())}))},t=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(l,"__esModule",{value:!0}),l.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer=l.ResumableClientServerInputMultiplexerDemultiplexer=l.ClientServerInputMultiplexerDemultiplexer=l.StreamIdGenerator=void 0;var r=qr(),i=ht,a=yt,s=ct;!function(l){l.create=function(l){return new n(l)};var n=function(){function l(l){this.currentId=l}return l.prototype.next=function(l){var n=this.currentId+2;l(n)&&(this.currentId=n)},l}()}(l.StreamIdGenerator||(l.StreamIdGenerator={}));var c=function(l){function n(n,u,e){var t=l.call(this)||this;return t.streamIdSupplier=n,t.outbound=u,t.closeable=e,t.registry={},e.onClose(t.close.bind(t)),t}return u(n,l),n.prototype.handle=function(l){if(s.Frame.isConnection(l)){if(l.type===r.FrameTypes.RESERVED)return;this.connectionFramesHandler.handle(l)}else if(s.Frame.isRequest(l)){if(this.registry[l.streamId])return;this.requestFramesHandler.handle(l,this)}else{var n=this.registry[l.streamId];if(!n)return;n.handle(l)}},n.prototype.connectionInbound=function(l){if(this.connectionFramesHandler)throw new Error("Connection frame handler has already been installed");this.connectionFramesHandler=l},n.prototype.handleRequestStream=function(l){if(this.requestFramesHandler)throw new Error("Stream handler has already been installed");this.requestFramesHandler=l},n.prototype.send=function(l){this.outbound.send(l)},Object.defineProperty(n.prototype,"connectionOutbound",{get:function(){return this},enumerable:!1,configurable:!0}),n.prototype.createRequestStream=function(l){var n=this;if(this.done)l.handleReject(new Error("Already closed"));else{var u=this.registry;this.streamIdSupplier.next((function(u){return l.handleReady(u,n)}),Object.keys(u))}},n.prototype.connect=function(l){this.registry[l.streamId]=l},n.prototype.disconnect=function(l){delete this.registry[l.streamId]},n.prototype.close=function(n){if(this.done)l.prototype.close.call(this,n);else{for(var u in this.registry){this.registry[u].close(new Error("Closed. ".concat(n?"Original cause [".concat(n,"]."):"")))}l.prototype.close.call(this,n)}},n}(i.Deferred);l.ClientServerInputMultiplexerDemultiplexer=c;var d=function(l){function n(n,u,e,t,r,o,a){var s=l.call(this,n,u,new i.Deferred)||this;return s.frameStore=t,s.token=r,s.sessionTimeout=a,o instanceof Function?s.reconnector=o:s.sessionStore=o,e.onClose(s.handleConnectionClose.bind(s)),s}return u(n,l),n.prototype.send=function(n){if(s.Frame.isConnection(n)){if(n.type===r.FrameTypes.KEEPALIVE)n.lastReceivedPosition=this.frameStore.lastReceivedFramePosition;else if(n.type===r.FrameTypes.ERROR)return this.outbound.send(n),this.sessionStore&&delete this.sessionStore[this.token],void l.prototype.close.call(this,new a.RSocketError(n.code,n.message))}else this.frameStore.store(n);this.outbound.send(n)},n.prototype.handle=function(n){if(s.Frame.isConnection(n)){if(n.type===r.FrameTypes.KEEPALIVE)try{this.frameStore.dropTo(n.lastReceivedPosition)}catch(l){this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,flags:r.Flags.NONE,code:l.code,message:l.message}),this.close(l)}else if(n.type===r.FrameTypes.ERROR)return l.prototype.handle.call(this,n),this.sessionStore&&delete this.sessionStore[this.token],void l.prototype.close.call(this,new a.RSocketError(n.code,n.message))}else this.frameStore.record(n);l.prototype.handle.call(this,n)},n.prototype.resume=function(l,n,u){switch(this.outbound=n,l.type){case r.FrameTypes.RESUME:if(clearTimeout(this.timeoutId),this.frameStore.lastReceivedFramePosition<l.clientPosition){var e=new a.RSocketError(r.ErrorCodes.REJECTED_RESUME,"Impossible to resume since first available client frame position is greater than last received server frame position");return this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,flags:r.Flags.NONE,code:e.code,message:e.message}),void this.close(e)}try{this.frameStore.dropTo(l.serverPosition)}catch(l){return this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,flags:r.Flags.NONE,code:l.code,message:l.message}),void this.close(l)}this.outbound.send({type:r.FrameTypes.RESUME_OK,streamId:0,flags:r.Flags.NONE,clientPosition:this.frameStore.lastReceivedFramePosition});break;case r.FrameTypes.RESUME_OK:try{this.frameStore.dropTo(l.clientPosition)}catch(l){this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,flags:r.Flags.NONE,code:l.code,message:l.message}),this.close(l)}}this.frameStore.drain(this.outbound.send.bind(this.outbound)),u.onClose(this.handleConnectionClose.bind(this)),this.connectionFramesHandler.resume()},n.prototype.handleConnectionClose=function(l){return e(this,void 0,void 0,(function(){var l;return t(this,(function(n){switch(n.label){case 0:if(this.connectionFramesHandler.pause(),!this.reconnector)return[3,5];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.reconnector(this,this.frameStore)];case 2:return n.sent(),[3,4];case 3:return l=n.sent(),this.close(l),[3,4];case 4:return[3,6];case 5:this.timeoutId=setTimeout(this.close.bind(this),this.sessionTimeout),n.label=6;case 6:return[2]}}))}))},n}(c);l.ResumableClientServerInputMultiplexerDemultiplexer=d;var h=function(){function l(l,n,u){this.outbound=l,this.closeable=n,this.delegate=u,this.resumed=!1}return l.prototype.close=function(){this.delegate.close()},l.prototype.onClose=function(l){this.delegate.onClose(l)},Object.defineProperty(l.prototype,"connectionOutbound",{get:function(){return this.delegate.connectionOutbound},enumerable:!1,configurable:!0}),l.prototype.createRequestStream=function(l){this.delegate.createRequestStream(l)},l.prototype.connectionInbound=function(l){this.delegate.connectionInbound(l)},l.prototype.handleRequestStream=function(l){this.delegate.handleRequestStream(l)},l.prototype.handle=function(l){var n=this;if(!this.resumed)return l.type===r.FrameTypes.RESUME_OK?(this.resumed=!0,void this.delegate.resume(l,this.outbound,this.closeable)):(this.outbound.send({type:r.FrameTypes.ERROR,streamId:0,code:r.ErrorCodes.CONNECTION_ERROR,message:"Incomplete RESUME handshake. Unexpected frame ".concat(l.type," received"),flags:r.Flags.NONE}),this.closeable.close(),void this.closeable.onClose((function(){return n.delegate.close(new a.RSocketError(r.ErrorCodes.CONNECTION_ERROR,"Incomplete RESUME handshake. Unexpected frame ".concat(l.type," received")))})));this.delegate.handle(l)},l}();l.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer=h}(vt)),vt}var wt={},_t={},St={},Tt=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(St,"__esModule",{value:!0}),St.fragmentWithRequestN=St.fragment=St.isFragmentable=void 0;var Rt=ct;St.isFragmentable=function(l,n,u){return 0!==n&&l.data.byteLength+(l.metadata?l.metadata.byteLength+Rt.Lengths.METADATA:0)+(u==Rt.FrameTypes.REQUEST_STREAM||u==Rt.FrameTypes.REQUEST_CHANNEL?Rt.Lengths.REQUEST:0)>n},St.fragment=function(l,n,u,e,t){var r,o,i,a,s,c,d,h,f,p,y,m;return void 0===t&&(t=!1),Tt(this,(function(g){switch(g.label){case 0:return r=null!==(m=null===(y=n.data)||void 0===y?void 0:y.byteLength)&&void 0!==m?m:0,o=e!==Rt.FrameTypes.PAYLOAD,i=u,n.metadata?0!==(s=n.metadata.byteLength)?[3,1]:(i-=Rt.Lengths.METADATA,a=et.Buffer.allocUnsafe(0),[3,6]):[3,6];case 1:return c=0,o?(i-=Rt.Lengths.METADATA,d=Math.min(s,c+i),a=n.metadata.slice(c,d),i-=a.byteLength,c=d,0!==i?[3,3]:(o=!1,[4,{type:e,flags:Rt.Flags.FOLLOWS|Rt.Flags.METADATA,data:void 0,metadata:a,streamId:l}])):[3,3];case 2:g.sent(),a=void 0,i=u,g.label=3;case 3:return c<s?(i-=Rt.Lengths.METADATA,d=Math.min(s,c+i),a=n.metadata.slice(c,d),i-=a.byteLength,c=d,0!==i&&0!==r?[3,5]:[4,{type:Rt.FrameTypes.PAYLOAD,flags:Rt.Flags.NEXT|Rt.Flags.METADATA|(c===s&&t&&0===r?Rt.Flags.COMPLETE:Rt.Flags.FOLLOWS),data:void 0,metadata:a,streamId:l}]):[3,6];case 4:g.sent(),a=void 0,i=u,g.label=5;case 5:return[3,3];case 6:return h=0,o?(p=Math.min(r,h+i),f=n.data.slice(h,p),i-=f.byteLength,h=p,[4,{type:e,flags:Rt.Flags.FOLLOWS|(a?Rt.Flags.METADATA:Rt.Flags.NONE),data:f,metadata:a,streamId:l}]):[3,8];case 7:g.sent(),a=void 0,f=void 0,i=u,g.label=8;case 8:return h<r?(p=Math.min(r,h+i),f=n.data.slice(h,p),i-=f.byteLength,h=p,[4,{type:Rt.FrameTypes.PAYLOAD,flags:h===r?(t?Rt.Flags.COMPLETE:Rt.Flags.NONE)|Rt.Flags.NEXT|(a?Rt.Flags.METADATA:0):Rt.Flags.FOLLOWS|Rt.Flags.NEXT|(a?Rt.Flags.METADATA:0),data:f,metadata:a,streamId:l}]):[3,10];case 9:return g.sent(),a=void 0,f=void 0,i=u,[3,8];case 10:return[2]}}))},St.fragmentWithRequestN=function(l,n,u,e,t,r){var o,i,a,s,c,d,h,f,p,y,m,g;return void 0===r&&(r=!1),Tt(this,(function(b){switch(b.label){case 0:return o=null!==(g=null===(m=n.data)||void 0===m?void 0:m.byteLength)&&void 0!==g?g:0,i=!0,a=u,n.metadata?0!==(c=n.metadata.byteLength)?[3,1]:(a-=Rt.Lengths.METADATA,s=et.Buffer.allocUnsafe(0),[3,6]):[3,6];case 1:return d=0,i?(a-=Rt.Lengths.METADATA+Rt.Lengths.REQUEST,h=Math.min(c,d+a),s=n.metadata.slice(d,h),a-=s.byteLength,d=h,0!==a?[3,3]:(i=!1,[4,{type:e,flags:Rt.Flags.FOLLOWS|Rt.Flags.METADATA,data:void 0,requestN:t,metadata:s,streamId:l}])):[3,3];case 2:b.sent(),s=void 0,a=u,b.label=3;case 3:return d<c?(a-=Rt.Lengths.METADATA,h=Math.min(c,d+a),s=n.metadata.slice(d,h),a-=s.byteLength,d=h,0!==a&&0!==o?[3,5]:[4,{type:Rt.FrameTypes.PAYLOAD,flags:Rt.Flags.NEXT|Rt.Flags.METADATA|(d===c&&r&&0===o?Rt.Flags.COMPLETE:Rt.Flags.FOLLOWS),data:void 0,metadata:s,streamId:l}]):[3,6];case 4:b.sent(),s=void 0,a=u,b.label=5;case 5:return[3,3];case 6:return f=0,i?(a-=Rt.Lengths.REQUEST,y=Math.min(o,f+a),p=n.data.slice(f,y),a-=p.byteLength,f=y,[4,{type:e,flags:Rt.Flags.FOLLOWS|(s?Rt.Flags.METADATA:Rt.Flags.NONE),data:p,requestN:t,metadata:s,streamId:l}]):[3,8];case 7:b.sent(),s=void 0,p=void 0,a=u,b.label=8;case 8:return f<o?(y=Math.min(o,f+a),p=n.data.slice(f,y),a-=p.byteLength,f=y,[4,{type:Rt.FrameTypes.PAYLOAD,flags:f===o?(r?Rt.Flags.COMPLETE:Rt.Flags.NONE)|Rt.Flags.NEXT|(s?Rt.Flags.METADATA:0):Rt.Flags.FOLLOWS|Rt.Flags.NEXT|(s?Rt.Flags.METADATA:0),data:p,metadata:s,streamId:l}]):[3,10];case 9:return b.sent(),s=void 0,p=void 0,a=u,[3,8];case 10:return[2]}}))};var Ot={};Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.cancel=Ot.reassemble=Ot.add=void 0,Ot.add=function(l,n,u){return l.hasFragments?(l.data=l.data?et.Buffer.concat([l.data,n]):n,l.metadata&&u&&(l.metadata=et.Buffer.concat([l.metadata,u])),!0):(l.hasFragments=!0,l.data=n,u&&(l.metadata=u),!0)},Ot.reassemble=function(l,n,u){l.hasFragments=!1;var e=l.data?et.Buffer.concat([l.data,n]):n;if(l.data=void 0,l.metadata){var t=u?et.Buffer.concat([l.metadata,u]):l.metadata;return l.metadata=void 0,{data:e,metadata:t}}return{data:e}},Ot.cancel=function(l){l.hasFragments=!1,l.data=void 0,l.metadata=void 0};var At=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),Ct=o&&o.__setModuleDefault||(Object.create?function(l,n){Object.defineProperty(l,"default",{enumerable:!0,value:n})}:function(l,n){l.default=n}),Ft=o&&o.__importStar||function(l){if(l&&l.__esModule)return l;var n={};if(null!=l)for(var u in l)"default"!==u&&Object.prototype.hasOwnProperty.call(l,u)&&At(n,l,u);return Ct(n,l),n},It=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(_t,"__esModule",{value:!0}),_t.RequestChannelResponderStream=_t.RequestChannelRequesterStream=void 0;var kt=yt,Pt=St,Lt=ct,Nt=Ft(Ot),xt=function(){function l(l,n,u,e,t,r){this.payload=l,this.isComplete=n,this.receiver=u,this.fragmentSize=e,this.initialRequestN=t,this.leaseManager=r,this.streamType=Lt.FrameTypes.REQUEST_CHANNEL}return l.prototype.handleReady=function(l,n){var u,e;if(this.outboundDone)return!1;this.streamId=l,this.stream=n,n.connect(this);var t=this.isComplete;if(t&&(this.outboundDone=t),(0,Pt.isFragmentable)(this.payload,this.fragmentSize,Lt.FrameTypes.REQUEST_CHANNEL))try{for(var r=It((0,Pt.fragmentWithRequestN)(l,this.payload,this.fragmentSize,Lt.FrameTypes.REQUEST_CHANNEL,this.initialRequestN,t)),o=r.next();!o.done;o=r.next()){var i=o.value;this.stream.send(i)}}catch(l){u={error:l}}finally{try{o&&!o.done&&(e=r.return)&&e.call(r)}finally{if(u)throw u.error}}else this.stream.send({type:Lt.FrameTypes.REQUEST_CHANNEL,data:this.payload.data,metadata:this.payload.metadata,requestN:this.initialRequestN,flags:(void 0!==this.payload.metadata?Lt.Flags.METADATA:Lt.Flags.NONE)|(t?Lt.Flags.COMPLETE:Lt.Flags.NONE),streamId:l});return this.hasExtension&&this.stream.send({type:Lt.FrameTypes.EXT,streamId:l,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},l.prototype.handleReject=function(l){this.inboundDone||(this.inboundDone=!0,this.outboundDone=!0,this.receiver.onError(l))},l.prototype.handle=function(l){var n,u=l.type;switch(u){case Lt.FrameTypes.PAYLOAD:var e=Lt.Flags.hasComplete(l.flags),t=Lt.Flags.hasNext(l.flags);if(e||!Lt.Flags.hasFollows(l.flags)){if(e&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this),!t))return void this.receiver.onComplete();var r=this.hasFragments?Nt.reassemble(this,l.data,l.metadata):{data:l.data,metadata:l.metadata};return void this.receiver.onNext(r,e)}if(Nt.add(this,l.data,l.metadata))return;n="Unexpected frame size";break;case Lt.FrameTypes.CANCEL:if(this.outboundDone)return;return this.outboundDone=!0,this.inboundDone&&this.stream.disconnect(this),void this.receiver.cancel();case Lt.FrameTypes.REQUEST_N:if(this.outboundDone)return;if(this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.request(l.requestN);case Lt.FrameTypes.ERROR:var o=this.outboundDone;return this.inboundDone=!0,this.outboundDone=!0,this.stream.disconnect(this),Nt.cancel(this),o||this.receiver.cancel(),void this.receiver.onError(new kt.RSocketError(l.code,l.message));case Lt.FrameTypes.EXT:return void this.receiver.onExtension(l.extendedType,l.extendedContent,Lt.Flags.hasIgnore(l.flags));default:n="Unexpected frame type [".concat(u,"]")}this.close(new kt.RSocketError(kt.ErrorCodes.CANCELED,n)),this.stream.send({type:Lt.FrameTypes.CANCEL,streamId:this.streamId,flags:Lt.Flags.NONE}),this.stream.disconnect(this)},l.prototype.request=function(l){this.inboundDone||(this.streamId?this.stream.send({type:Lt.FrameTypes.REQUEST_N,flags:Lt.Flags.NONE,requestN:l,streamId:this.streamId}):this.initialRequestN+=l)},l.prototype.cancel=function(){var l,n=this.inboundDone,u=this.outboundDone;n&&u||(this.inboundDone=!0,this.outboundDone=!0,u||this.receiver.cancel(),this.streamId?(this.stream.send({type:n?Lt.FrameTypes.ERROR:Lt.FrameTypes.CANCEL,flags:Lt.Flags.NONE,streamId:this.streamId,code:kt.ErrorCodes.CANCELED,message:"Cancelled"}),this.stream.disconnect(this),Nt.cancel(this)):null===(l=this.leaseManager)||void 0===l||l.cancelRequest(this))},l.prototype.onNext=function(l,n){var u,e;if(!this.outboundDone)if(n&&(this.outboundDone=!0,this.inboundDone&&this.stream.disconnect(this)),(0,Pt.isFragmentable)(l,this.fragmentSize,Lt.FrameTypes.PAYLOAD))try{for(var t=It((0,Pt.fragment)(this.streamId,l,this.fragmentSize,Lt.FrameTypes.PAYLOAD,n)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:Lt.FrameTypes.PAYLOAD,streamId:this.streamId,flags:Lt.Flags.NEXT|(l.metadata?Lt.Flags.METADATA:Lt.Flags.NONE)|(n?Lt.Flags.COMPLETE:Lt.Flags.NONE),data:l.data,metadata:l.metadata})},l.prototype.onComplete=function(){this.streamId?this.outboundDone||(this.outboundDone=!0,this.stream.send({type:Lt.FrameTypes.PAYLOAD,streamId:this.streamId,flags:Lt.Flags.COMPLETE,data:null,metadata:null}),this.inboundDone&&this.stream.disconnect(this)):this.isComplete=!0},l.prototype.onError=function(l){if(!this.outboundDone){var n=this.inboundDone;this.outboundDone=!0,this.inboundDone=!0,this.stream.send({type:Lt.FrameTypes.ERROR,streamId:this.streamId,flags:Lt.Flags.NONE,code:l instanceof kt.RSocketError?l.code:kt.ErrorCodes.APPLICATION_ERROR,message:l.message}),this.stream.disconnect(this),n||this.receiver.onError(l)}},l.prototype.onExtension=function(l,n,u){if(!this.outboundDone)return this.streamId?void this.stream.send({streamId:this.streamId,type:Lt.FrameTypes.EXT,extendedType:l,extendedContent:n,flags:u?Lt.Flags.IGNORE:Lt.Flags.NONE}):(this.hasExtension=!0,this.extendedType=l,this.extendedContent=n,void(this.flags=u?Lt.Flags.IGNORE:Lt.Flags.NONE))},l.prototype.close=function(l){if(!this.inboundDone||!this.outboundDone){var n=this.inboundDone,u=this.outboundDone;this.inboundDone=!0,this.outboundDone=!0,Nt.cancel(this),u||this.receiver.cancel(),n||(l?this.receiver.onError(l):this.receiver.onComplete())}},l}();_t.RequestChannelRequesterStream=xt;var Ut=function(){function l(l,n,u,e,t){if(this.streamId=l,this.stream=n,this.fragmentSize=u,this.handler=e,this.streamType=Lt.FrameTypes.REQUEST_CHANNEL,n.connect(this),Lt.Flags.hasFollows(t.flags))return Nt.add(this,t.data,t.metadata),this.initialRequestN=t.requestN,void(this.isComplete=Lt.Flags.hasComplete(t.flags));var r={data:t.data,metadata:t.metadata},o=Lt.Flags.hasComplete(t.flags);this.inboundDone=o;try{this.receiver=e(r,t.requestN,o,this),this.outboundDone&&this.defferedError&&this.receiver.onError(this.defferedError)}catch(l){this.outboundDone&&!this.inboundDone?this.cancel():this.inboundDone=!0,this.onError(l)}}return l.prototype.handle=function(l){var n,u=l.type;switch(u){case Lt.FrameTypes.PAYLOAD:if(Lt.Flags.hasFollows(l.flags)){if(Nt.add(this,l.data,l.metadata))return;n="Unexpected frame size";break}var e=this.hasFragments?Nt.reassemble(this,l.data,l.metadata):{data:l.data,metadata:l.metadata},t=Lt.Flags.hasComplete(l.flags);if(this.receiver){if(t&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this),!Lt.Flags.hasNext(l.flags)))return void this.receiver.onComplete();this.receiver.onNext(e,t)}else{(r=this.isComplete||t)&&(this.inboundDone=!0,this.outboundDone&&this.stream.disconnect(this));try{this.receiver=this.handler(e,this.initialRequestN,r,this),this.outboundDone&&this.defferedError}catch(i){this.outboundDone&&!this.inboundDone?this.cancel():this.inboundDone=!0,this.onError(i)}}return;case Lt.FrameTypes.REQUEST_N:if(!this.receiver||this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.request(l.requestN);case Lt.FrameTypes.ERROR:case Lt.FrameTypes.CANCEL:var r=this.inboundDone,o=this.outboundDone;if(this.inboundDone=!0,this.outboundDone=!0,this.stream.disconnect(this),Nt.cancel(this),!this.receiver)return;if(o||this.receiver.cancel(),!r){var i=u===Lt.FrameTypes.CANCEL?new kt.RSocketError(kt.ErrorCodes.CANCELED,"Cancelled"):new kt.RSocketError(l.code,l.message);this.receiver.onError(i)}return;case Lt.FrameTypes.EXT:if(!this.receiver||this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.onExtension(l.extendedType,l.extendedContent,Lt.Flags.hasIgnore(l.flags));default:n="Unexpected frame type [".concat(u,"]")}this.stream.send({type:Lt.FrameTypes.ERROR,flags:Lt.Flags.NONE,code:kt.ErrorCodes.CANCELED,message:n,streamId:this.streamId}),this.stream.disconnect(this),this.close(new kt.RSocketError(kt.ErrorCodes.CANCELED,n))},l.prototype.onError=function(l){if(this.outboundDone)console.warn("Trying to error for the second time. ".concat(l?"Dropping error [".concat(l,"]."):""));else{var n=this.inboundDone;this.outboundDone=!0,this.inboundDone=!0,this.stream.send({type:Lt.FrameTypes.ERROR,flags:Lt.Flags.NONE,code:l instanceof kt.RSocketError?l.code:kt.ErrorCodes.APPLICATION_ERROR,message:l.message,streamId:this.streamId}),this.stream.disconnect(this),n||(this.receiver?this.receiver.onError(l):this.defferedError=l)}},l.prototype.onNext=function(l,n){var u,e;if(!this.outboundDone){if(n&&(this.outboundDone=!0),(0,Pt.isFragmentable)(l,this.fragmentSize,Lt.FrameTypes.PAYLOAD))try{for(var t=It((0,Pt.fragment)(this.streamId,l,this.fragmentSize,Lt.FrameTypes.PAYLOAD,n)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:Lt.FrameTypes.PAYLOAD,flags:Lt.Flags.NEXT|(n?Lt.Flags.COMPLETE:Lt.Flags.NONE)|(l.metadata?Lt.Flags.METADATA:Lt.Flags.NONE),data:l.data,metadata:l.metadata,streamId:this.streamId});n&&this.inboundDone&&this.stream.disconnect(this)}},l.prototype.onComplete=function(){this.outboundDone||(this.outboundDone=!0,this.stream.send({type:Lt.FrameTypes.PAYLOAD,flags:Lt.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.inboundDone&&this.stream.disconnect(this))},l.prototype.onExtension=function(l,n,u){this.outboundDone&&this.inboundDone||this.stream.send({type:Lt.FrameTypes.EXT,streamId:this.streamId,flags:u?Lt.Flags.IGNORE:Lt.Flags.NONE,extendedType:l,extendedContent:n})},l.prototype.request=function(l){this.inboundDone||this.stream.send({type:Lt.FrameTypes.REQUEST_N,flags:Lt.Flags.NONE,streamId:this.streamId,requestN:l})},l.prototype.cancel=function(){this.inboundDone||(this.inboundDone=!0,this.stream.send({type:Lt.FrameTypes.CANCEL,flags:Lt.Flags.NONE,streamId:this.streamId}),this.outboundDone&&this.stream.disconnect(this))},l.prototype.close=function(l){if(this.inboundDone&&this.outboundDone)console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):""));else{var n=this.inboundDone,u=this.outboundDone;this.inboundDone=!0,this.outboundDone=!0,Nt.cancel(this);var e=this.receiver;e&&(u||e.cancel(),n||(l?e.onError(l):e.onComplete()))}},l}();_t.RequestChannelResponderStream=Ut;var Bt={},Dt=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),Mt=o&&o.__setModuleDefault||(Object.create?function(l,n){Object.defineProperty(l,"default",{enumerable:!0,value:n})}:function(l,n){l.default=n}),qt=o&&o.__importStar||function(l){if(l&&l.__esModule)return l;var n={};if(null!=l)for(var u in l)"default"!==u&&Object.prototype.hasOwnProperty.call(l,u)&&Dt(n,l,u);return Mt(n,l),n},jt=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.RequestFnfResponderStream=Bt.RequestFnFRequesterStream=void 0;var Wt=yt,zt=St,Qt=ct,$t=qt(Ot),Ht=function(){function l(l,n,u,e){this.payload=l,this.receiver=n,this.fragmentSize=u,this.leaseManager=e,this.streamType=Qt.FrameTypes.REQUEST_FNF}return l.prototype.handleReady=function(l,n){var u,e;if(this.done)return!1;if(this.streamId=l,(0,zt.isFragmentable)(this.payload,this.fragmentSize,Qt.FrameTypes.REQUEST_FNF))try{for(var t=jt((0,zt.fragment)(l,this.payload,this.fragmentSize,Qt.FrameTypes.REQUEST_FNF)),r=t.next();!r.done;r=t.next()){var o=r.value;n.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else n.send({type:Qt.FrameTypes.REQUEST_FNF,data:this.payload.data,metadata:this.payload.metadata,flags:this.payload.metadata?Qt.Flags.METADATA:0,streamId:l});return this.done=!0,this.receiver.onComplete(),!0},l.prototype.handleReject=function(l){this.done||(this.done=!0,this.receiver.onError(l))},l.prototype.cancel=function(){var l;this.done||(this.done=!0,null===(l=this.leaseManager)||void 0===l||l.cancelRequest(this))},l.prototype.handle=function(l){l.type!=Qt.FrameTypes.ERROR?this.close(new Wt.RSocketError(Wt.ErrorCodes.CANCELED,"Received invalid frame")):this.close(new Wt.RSocketError(l.code,l.message))},l.prototype.close=function(l){this.done?console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):l?this.receiver.onError(l):this.receiver.onComplete()},l}();Bt.RequestFnFRequesterStream=Ht;var Vt=function(){function l(l,n,u,e){if(this.streamId=l,this.stream=n,this.handler=u,this.streamType=Qt.FrameTypes.REQUEST_FNF,Qt.Flags.hasFollows(e.flags))return $t.add(this,e.data,e.metadata),void n.connect(this);var t={data:e.data,metadata:e.metadata};try{this.cancellable=u(t,this)}catch(l){}}return l.prototype.handle=function(l){var n;if(l.type==Qt.FrameTypes.PAYLOAD){if(!Qt.Flags.hasFollows(l.flags)){this.stream.disconnect(this);var u=$t.reassemble(this,l.data,l.metadata);try{this.cancellable=this.handler(u,this)}catch(l){}return}if($t.add(this,l.data,l.metadata))return;n="Unexpected fragment size"}else n="Unexpected frame type [".concat(l.type,"]");this.done=!0,l.type!=Qt.FrameTypes.CANCEL&&l.type!=Qt.FrameTypes.ERROR&&this.stream.send({type:Qt.FrameTypes.ERROR,streamId:this.streamId,flags:Qt.Flags.NONE,code:Wt.ErrorCodes.CANCELED,message:n}),this.stream.disconnect(this),$t.cancel(this)},l.prototype.close=function(l){var n;this.done?console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(this.done=!0,$t.cancel(this),null===(n=this.cancellable)||void 0===n||n.cancel())},l.prototype.onError=function(l){},l.prototype.onComplete=function(){},l}();Bt.RequestFnfResponderStream=Vt;var Jt={},Yt=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),Xt=o&&o.__setModuleDefault||(Object.create?function(l,n){Object.defineProperty(l,"default",{enumerable:!0,value:n})}:function(l,n){l.default=n}),Gt=o&&o.__importStar||function(l){if(l&&l.__esModule)return l;var n={};if(null!=l)for(var u in l)"default"!==u&&Object.prototype.hasOwnProperty.call(l,u)&&Yt(n,l,u);return Xt(n,l),n},Kt=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(Jt,"__esModule",{value:!0}),Jt.RequestResponseResponderStream=Jt.RequestResponseRequesterStream=void 0;var Zt=yt,lr=St,nr=ct,ur=Gt(Ot),er=function(){function l(l,n,u,e){this.payload=l,this.receiver=n,this.fragmentSize=u,this.leaseManager=e,this.streamType=nr.FrameTypes.REQUEST_RESPONSE}return l.prototype.handleReady=function(l,n){var u,e;if(this.done)return!1;if(this.streamId=l,this.stream=n,n.connect(this),(0,lr.isFragmentable)(this.payload,this.fragmentSize,nr.FrameTypes.REQUEST_RESPONSE))try{for(var t=Kt((0,lr.fragment)(l,this.payload,this.fragmentSize,nr.FrameTypes.REQUEST_RESPONSE)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:nr.FrameTypes.REQUEST_RESPONSE,data:this.payload.data,metadata:this.payload.metadata,flags:this.payload.metadata?nr.Flags.METADATA:0,streamId:l});return this.hasExtension&&this.stream.send({type:nr.FrameTypes.EXT,streamId:l,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},l.prototype.handleReject=function(l){this.done||(this.done=!0,this.receiver.onError(l))},l.prototype.handle=function(l){var n,u=l.type;switch(u){case nr.FrameTypes.PAYLOAD:var e=nr.Flags.hasComplete(l.flags),t=nr.Flags.hasNext(l.flags);if(e||!nr.Flags.hasFollows(l.flags)){if(this.done=!0,this.stream.disconnect(this),!t)return void this.receiver.onComplete();var r=this.hasFragments?ur.reassemble(this,l.data,l.metadata):{data:l.data,metadata:l.metadata};return void this.receiver.onNext(r,!0)}if(!ur.add(this,l.data,l.metadata)){n="Unexpected fragment size";break}return;case nr.FrameTypes.ERROR:return this.done=!0,this.stream.disconnect(this),ur.cancel(this),void this.receiver.onError(new Zt.RSocketError(l.code,l.message));case nr.FrameTypes.EXT:if(this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.onExtension(l.extendedType,l.extendedContent,nr.Flags.hasIgnore(l.flags));default:n="Unexpected frame type [".concat(u,"]")}this.close(new Zt.RSocketError(Zt.ErrorCodes.CANCELED,n)),this.stream.send({type:nr.FrameTypes.CANCEL,streamId:this.streamId,flags:nr.Flags.NONE}),this.stream.disconnect(this)},l.prototype.cancel=function(){var l;this.done||(this.done=!0,this.streamId?(this.stream.send({type:nr.FrameTypes.CANCEL,flags:nr.Flags.NONE,streamId:this.streamId}),this.stream.disconnect(this),ur.cancel(this)):null===(l=this.leaseManager)||void 0===l||l.cancelRequest(this))},l.prototype.onExtension=function(l,n,u){if(!this.done)return this.streamId?void this.stream.send({streamId:this.streamId,type:nr.FrameTypes.EXT,extendedType:l,extendedContent:n,flags:u?nr.Flags.IGNORE:nr.Flags.NONE}):(this.hasExtension=!0,this.extendedType=l,this.extendedContent=n,void(this.flags=u?nr.Flags.IGNORE:nr.Flags.NONE))},l.prototype.close=function(l){this.done||(this.done=!0,ur.cancel(this),l?this.receiver.onError(l):this.receiver.onComplete())},l}();Jt.RequestResponseRequesterStream=er;var tr=function(){function l(l,n,u,e,t){if(this.streamId=l,this.stream=n,this.fragmentSize=u,this.handler=e,this.streamType=nr.FrameTypes.REQUEST_RESPONSE,n.connect(this),nr.Flags.hasFollows(t.flags))ur.add(this,t.data,t.metadata);else{var r={data:t.data,metadata:t.metadata};try{this.receiver=e(r,this)}catch(l){this.onError(l)}}}return l.prototype.handle=function(l){var n,u;if(!this.receiver||this.hasFragments)if(l.type===nr.FrameTypes.PAYLOAD){if(!nr.Flags.hasFollows(l.flags)){var e=ur.reassemble(this,l.data,l.metadata);try{this.receiver=this.handler(e,this)}catch(l){this.onError(l)}return}if(ur.add(this,l.data,l.metadata))return;u="Unexpected fragment size"}else u="Unexpected frame type [".concat(l.type,"] during reassembly");else{if(l.type===nr.FrameTypes.EXT)return void this.receiver.onExtension(l.extendedType,l.extendedContent,nr.Flags.hasIgnore(l.flags));u="Unexpected frame type [".concat(l.type,"]")}this.done=!0,null===(n=this.receiver)||void 0===n||n.cancel(),l.type!==nr.FrameTypes.CANCEL&&l.type!==nr.FrameTypes.ERROR&&this.stream.send({type:nr.FrameTypes.ERROR,flags:nr.Flags.NONE,code:Zt.ErrorCodes.CANCELED,message:u,streamId:this.streamId}),this.stream.disconnect(this),ur.cancel(this)},l.prototype.onError=function(l){this.done?console.warn("Trying to error for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(this.done=!0,this.stream.send({type:nr.FrameTypes.ERROR,flags:nr.Flags.NONE,code:l instanceof Zt.RSocketError?l.code:Zt.ErrorCodes.APPLICATION_ERROR,message:l.message,streamId:this.streamId}),this.stream.disconnect(this))},l.prototype.onNext=function(l,n){var u,e;if(!this.done){if(this.done=!0,(0,lr.isFragmentable)(l,this.fragmentSize,nr.FrameTypes.PAYLOAD))try{for(var t=Kt((0,lr.fragment)(this.streamId,l,this.fragmentSize,nr.FrameTypes.PAYLOAD,!0)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:nr.FrameTypes.PAYLOAD,flags:nr.Flags.NEXT|nr.Flags.COMPLETE|(l.metadata?nr.Flags.METADATA:0),data:l.data,metadata:l.metadata,streamId:this.streamId});this.stream.disconnect(this)}},l.prototype.onComplete=function(){this.done||(this.done=!0,this.stream.send({type:nr.FrameTypes.PAYLOAD,flags:nr.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.stream.disconnect(this))},l.prototype.onExtension=function(l,n,u){this.done||this.stream.send({type:nr.FrameTypes.EXT,streamId:this.streamId,flags:u?nr.Flags.IGNORE:nr.Flags.NONE,extendedType:l,extendedContent:n})},l.prototype.close=function(l){var n;this.done?console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(ur.cancel(this),null===(n=this.receiver)||void 0===n||n.cancel())},l}();Jt.RequestResponseResponderStream=tr;var rr={},or=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),ir=o&&o.__setModuleDefault||(Object.create?function(l,n){Object.defineProperty(l,"default",{enumerable:!0,value:n})}:function(l,n){l.default=n}),ar=o&&o.__importStar||function(l){if(l&&l.__esModule)return l;var n={};if(null!=l)for(var u in l)"default"!==u&&Object.prototype.hasOwnProperty.call(l,u)&&or(n,l,u);return ir(n,l),n},sr=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(rr,"__esModule",{value:!0}),rr.RequestStreamResponderStream=rr.RequestStreamRequesterStream=void 0;var cr=yt,dr=St,hr=ct,fr=ar(Ot),pr=function(){function l(l,n,u,e,t){this.payload=l,this.receiver=n,this.fragmentSize=u,this.initialRequestN=e,this.leaseManager=t,this.streamType=hr.FrameTypes.REQUEST_STREAM}return l.prototype.handleReady=function(l,n){var u,e;if(this.done)return!1;if(this.streamId=l,this.stream=n,n.connect(this),(0,dr.isFragmentable)(this.payload,this.fragmentSize,hr.FrameTypes.REQUEST_STREAM))try{for(var t=sr((0,dr.fragmentWithRequestN)(l,this.payload,this.fragmentSize,hr.FrameTypes.REQUEST_STREAM,this.initialRequestN)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:hr.FrameTypes.REQUEST_STREAM,data:this.payload.data,metadata:this.payload.metadata,requestN:this.initialRequestN,flags:void 0!==this.payload.metadata?hr.Flags.METADATA:0,streamId:l});return this.hasExtension&&this.stream.send({type:hr.FrameTypes.EXT,streamId:l,extendedContent:this.extendedContent,extendedType:this.extendedType,flags:this.flags}),!0},l.prototype.handleReject=function(l){this.done||(this.done=!0,this.receiver.onError(l))},l.prototype.handle=function(l){var n,u=l.type;switch(u){case hr.FrameTypes.PAYLOAD:var e=hr.Flags.hasComplete(l.flags),t=hr.Flags.hasNext(l.flags);if(e||!hr.Flags.hasFollows(l.flags)){if(e&&(this.done=!0,this.stream.disconnect(this),!t))return void this.receiver.onComplete();var r=this.hasFragments?fr.reassemble(this,l.data,l.metadata):{data:l.data,metadata:l.metadata};return void this.receiver.onNext(r,e)}if(!fr.add(this,l.data,l.metadata)){n="Unexpected fragment size";break}return;case hr.FrameTypes.ERROR:return this.done=!0,this.stream.disconnect(this),fr.cancel(this),void this.receiver.onError(new cr.RSocketError(l.code,l.message));case hr.FrameTypes.EXT:if(this.hasFragments){n="Unexpected frame type [".concat(u,"] during reassembly");break}return void this.receiver.onExtension(l.extendedType,l.extendedContent,hr.Flags.hasIgnore(l.flags));default:n="Unexpected frame type [".concat(u,"]")}this.close(new cr.RSocketError(cr.ErrorCodes.CANCELED,n)),this.stream.send({type:hr.FrameTypes.CANCEL,streamId:this.streamId,flags:hr.Flags.NONE}),this.stream.disconnect(this)},l.prototype.request=function(l){this.done||(this.streamId?this.stream.send({type:hr.FrameTypes.REQUEST_N,flags:hr.Flags.NONE,requestN:l,streamId:this.streamId}):this.initialRequestN+=l)},l.prototype.cancel=function(){var l;this.done||(this.done=!0,this.streamId?(this.stream.send({type:hr.FrameTypes.CANCEL,flags:hr.Flags.NONE,streamId:this.streamId}),this.stream.disconnect(this),fr.cancel(this)):null===(l=this.leaseManager)||void 0===l||l.cancelRequest(this))},l.prototype.onExtension=function(l,n,u){if(!this.done)return this.streamId?void this.stream.send({streamId:this.streamId,type:hr.FrameTypes.EXT,extendedType:l,extendedContent:n,flags:u?hr.Flags.IGNORE:hr.Flags.NONE}):(this.hasExtension=!0,this.extendedType=l,this.extendedContent=n,void(this.flags=u?hr.Flags.IGNORE:hr.Flags.NONE))},l.prototype.close=function(l){this.done||(this.done=!0,fr.cancel(this),l?this.receiver.onError(l):this.receiver.onComplete())},l}();rr.RequestStreamRequesterStream=pr;var yr=function(){function l(l,n,u,e,t){if(this.streamId=l,this.stream=n,this.fragmentSize=u,this.handler=e,this.streamType=hr.FrameTypes.REQUEST_STREAM,n.connect(this),hr.Flags.hasFollows(t.flags))return this.initialRequestN=t.requestN,void fr.add(this,t.data,t.metadata);var r={data:t.data,metadata:t.metadata};try{this.receiver=e(r,t.requestN,this)}catch(l){this.onError(l)}}return l.prototype.handle=function(l){var n,u;if(!this.receiver||this.hasFragments)if(l.type===hr.FrameTypes.PAYLOAD){if(!hr.Flags.hasFollows(l.flags)){var e=fr.reassemble(this,l.data,l.metadata);try{this.receiver=this.handler(e,this.initialRequestN,this)}catch(l){this.onError(l)}return}if(fr.add(this,l.data,l.metadata))return;u="Unexpected frame size"}else u="Unexpected frame type [".concat(l.type,"] during reassembly");else{if(l.type===hr.FrameTypes.REQUEST_N)return void this.receiver.request(l.requestN);if(l.type===hr.FrameTypes.EXT)return void this.receiver.onExtension(l.extendedType,l.extendedContent,hr.Flags.hasIgnore(l.flags));u="Unexpected frame type [".concat(l.type,"]")}this.done=!0,fr.cancel(this),null===(n=this.receiver)||void 0===n||n.cancel(),l.type!==hr.FrameTypes.CANCEL&&l.type!==hr.FrameTypes.ERROR&&this.stream.send({type:hr.FrameTypes.ERROR,flags:hr.Flags.NONE,code:cr.ErrorCodes.CANCELED,message:u,streamId:this.streamId}),this.stream.disconnect(this)},l.prototype.onError=function(l){this.done?console.warn("Trying to error for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(this.done=!0,this.stream.send({type:hr.FrameTypes.ERROR,flags:hr.Flags.NONE,code:l instanceof cr.RSocketError?l.code:cr.ErrorCodes.APPLICATION_ERROR,message:l.message,streamId:this.streamId}),this.stream.disconnect(this))},l.prototype.onNext=function(l,n){var u,e;if(!this.done){if(n&&(this.done=!0),(0,dr.isFragmentable)(l,this.fragmentSize,hr.FrameTypes.PAYLOAD))try{for(var t=sr((0,dr.fragment)(this.streamId,l,this.fragmentSize,hr.FrameTypes.PAYLOAD,n)),r=t.next();!r.done;r=t.next()){var o=r.value;this.stream.send(o)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}else this.stream.send({type:hr.FrameTypes.PAYLOAD,flags:hr.Flags.NEXT|(n?hr.Flags.COMPLETE:hr.Flags.NONE)|(l.metadata?hr.Flags.METADATA:hr.Flags.NONE),data:l.data,metadata:l.metadata,streamId:this.streamId});n&&this.stream.disconnect(this)}},l.prototype.onComplete=function(){this.done||(this.done=!0,this.stream.send({type:hr.FrameTypes.PAYLOAD,flags:hr.Flags.COMPLETE,streamId:this.streamId,data:null,metadata:null}),this.stream.disconnect(this))},l.prototype.onExtension=function(l,n,u){this.done||this.stream.send({type:hr.FrameTypes.EXT,streamId:this.streamId,flags:u?hr.Flags.IGNORE:hr.Flags.NONE,extendedType:l,extendedContent:n})},l.prototype.close=function(l){var n;this.done?console.warn("Trying to close for the second time. ".concat(l?"Dropping error [".concat(l,"]."):"")):(fr.cancel(this),null===(n=this.receiver)||void 0===n||n.cancel())},l}();rr.RequestStreamResponderStream=yr,Object.defineProperty(wt,"__esModule",{value:!0}),wt.KeepAliveSender=wt.KeepAliveHandler=wt.DefaultConnectionFrameHandler=wt.DefaultStreamRequestHandler=wt.LeaseHandler=wt.RSocketRequester=void 0;var mr=yt,gr=ct,br=_t,vr=Bt,Er=Jt,wr=rr,_r=function(){function l(l,n,u){this.connection=l,this.fragmentSize=n,this.leaseManager=u}return l.prototype.fireAndForget=function(l,n){var u=new vr.RequestFnFRequesterStream(l,n,this.fragmentSize,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(u):this.connection.multiplexerDemultiplexer.createRequestStream(u),u},l.prototype.requestResponse=function(l,n){var u=new Er.RequestResponseRequesterStream(l,n,this.fragmentSize,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(u):this.connection.multiplexerDemultiplexer.createRequestStream(u),u},l.prototype.requestStream=function(l,n,u){var e=new wr.RequestStreamRequesterStream(l,u,this.fragmentSize,n,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(e):this.connection.multiplexerDemultiplexer.createRequestStream(e),e},l.prototype.requestChannel=function(l,n,u,e){var t=new br.RequestChannelRequesterStream(l,u,e,this.fragmentSize,n,this.leaseManager);return this.leaseManager?this.leaseManager.requestLease(t):this.connection.multiplexerDemultiplexer.createRequestStream(t),t},l.prototype.metadataPush=function(l,n){throw new Error("Method not implemented.")},l.prototype.close=function(l){this.connection.close(l)},l.prototype.onClose=function(l){this.connection.onClose(l)},l}();wt.RSocketRequester=_r;var Sr=function(){function l(l,n){this.maxPendingRequests=l,this.multiplexer=n,this.pendingRequests=[],this.expirationTime=0,this.availableLease=0}return l.prototype.handle=function(l){for(this.expirationTime=l.ttl+Date.now(),this.availableLease=l.requestCount;this.availableLease>0&&this.pendingRequests.length>0;){var n=this.pendingRequests.shift();this.availableLease--,this.multiplexer.createRequestStream(n)}},l.prototype.requestLease=function(l){var n=this.availableLease;if(n>0&&Date.now()<this.expirationTime)return this.availableLease=n-1,void this.multiplexer.createRequestStream(l);this.pendingRequests.length>=this.maxPendingRequests?l.handleReject(new mr.RSocketError(mr.ErrorCodes.REJECTED,"No available lease given")):this.pendingRequests.push(l)},l.prototype.cancelRequest=function(l){var n=this.pendingRequests.indexOf(l);n>-1&&this.pendingRequests.splice(n,1)},l}();wt.LeaseHandler=Sr;var Tr=function(){function l(l,n){this.rsocket=l,this.fragmentSize=n}return l.prototype.handle=function(l,n){switch(l.type){case gr.FrameTypes.REQUEST_FNF:return void(this.rsocket.fireAndForget&&new vr.RequestFnfResponderStream(l.streamId,n,this.rsocket.fireAndForget.bind(this.rsocket),l));case gr.FrameTypes.REQUEST_RESPONSE:return this.rsocket.requestResponse?void new Er.RequestResponseResponderStream(l.streamId,n,this.fragmentSize,this.rsocket.requestResponse.bind(this.rsocket),l):void this.rejectRequest(l.streamId,n);case gr.FrameTypes.REQUEST_STREAM:return this.rsocket.requestStream?void new wr.RequestStreamResponderStream(l.streamId,n,this.fragmentSize,this.rsocket.requestStream.bind(this.rsocket),l):void this.rejectRequest(l.streamId,n);case gr.FrameTypes.REQUEST_CHANNEL:return this.rsocket.requestChannel?void new br.RequestChannelResponderStream(l.streamId,n,this.fragmentSize,this.rsocket.requestChannel.bind(this.rsocket),l):void this.rejectRequest(l.streamId,n)}},l.prototype.rejectRequest=function(l,n){n.send({type:gr.FrameTypes.ERROR,streamId:l,flags:gr.Flags.NONE,code:mr.ErrorCodes.REJECTED,message:"No available handler found"})},l.prototype.close=function(){},l}();wt.DefaultStreamRequestHandler=Tr;var Rr,Or=function(){function l(l,n,u,e,t){this.connection=l,this.keepAliveHandler=n,this.keepAliveSender=u,this.leaseHandler=e,this.rsocket=t}return l.prototype.handle=function(l){switch(l.type){case gr.FrameTypes.KEEPALIVE:return void this.keepAliveHandler.handle(l);case gr.FrameTypes.LEASE:return this.leaseHandler?void this.leaseHandler.handle(l):void 0;case gr.FrameTypes.ERROR:return void this.connection.close(new mr.RSocketError(l.code,l.message));case gr.FrameTypes.METADATA_PUSH:return void this.rsocket.metadataPush;default:this.connection.multiplexerDemultiplexer.connectionOutbound.send({type:gr.FrameTypes.ERROR,streamId:0,flags:gr.Flags.NONE,message:"Received unknown frame type",code:mr.ErrorCodes.CONNECTION_ERROR})}},l.prototype.pause=function(){var l;this.keepAliveHandler.pause(),null===(l=this.keepAliveSender)||void 0===l||l.pause()},l.prototype.resume=function(){var l;this.keepAliveHandler.start(),null===(l=this.keepAliveSender)||void 0===l||l.start()},l.prototype.close=function(l){var n;this.keepAliveHandler.close(),null===(n=this.rsocket.close)||void 0===n||n.call(this.rsocket,l)},l}();wt.DefaultConnectionFrameHandler=Or,function(l){l[l.Paused=0]="Paused",l[l.Running=1]="Running",l[l.Closed=2]="Closed"}(Rr||(Rr={}));var Ar,Cr=function(){function l(l,n){this.connection=l,this.keepAliveTimeoutDuration=n,this.state=Rr.Paused,this.outbound=l.multiplexerDemultiplexer.connectionOutbound}return l.prototype.handle=function(l){this.keepAliveLastReceivedMillis=Date.now(),gr.Flags.hasRespond(l.flags)&&this.outbound.send({type:gr.FrameTypes.KEEPALIVE,streamId:0,data:l.data,flags:l.flags^gr.Flags.RESPOND,lastReceivedPosition:0})},l.prototype.start=function(){this.state===Rr.Paused&&(this.keepAliveLastReceivedMillis=Date.now(),this.state=Rr.Running,this.activeTimeout=setTimeout(this.timeoutCheck.bind(this),this.keepAliveTimeoutDuration))},l.prototype.pause=function(){this.state===Rr.Running&&(this.state=Rr.Paused,clearTimeout(this.activeTimeout))},l.prototype.close=function(){this.state=Rr.Closed,clearTimeout(this.activeTimeout)},l.prototype.timeoutCheck=function(){var l=Date.now()-this.keepAliveLastReceivedMillis;l>=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-l))},l}();wt.KeepAliveHandler=Cr,function(l){l[l.Paused=0]="Paused",l[l.Running=1]="Running",l[l.Closed=2]="Closed"}(Ar||(Ar={}));var Fr=function(){function l(l,n){this.outbound=l,this.keepAlivePeriodDuration=n,this.state=Ar.Paused}return l.prototype.sendKeepAlive=function(){this.outbound.send({type:gr.FrameTypes.KEEPALIVE,streamId:0,data:void 0,flags:gr.Flags.RESPOND,lastReceivedPosition:0})},l.prototype.start=function(){this.state===Ar.Paused&&(this.state=Ar.Running,this.activeInterval=setInterval(this.sendKeepAlive.bind(this),this.keepAlivePeriodDuration))},l.prototype.pause=function(){this.state===Ar.Running&&(this.state=Ar.Paused,clearInterval(this.activeInterval))},l.prototype.close=function(){this.state=Ar.Closed,clearInterval(this.activeInterval)},l}();wt.KeepAliveSender=Fr;var Ir,kr,Pr={};function Lr(){if(Ir)return Pr;Ir=1;var l=o&&o.__values||function(l){var n="function"==typeof Symbol&&Symbol.iterator,u=n&&l[n],e=0;if(u)return u.call(l);if(l&&"number"==typeof l.length)return{next:function(){return l&&e>=l.length&&(l=void 0),{value:l&&l[e++],done:!l}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(Pr,"__esModule",{value:!0}),Pr.FrameStore=void 0;var n=qr(),u=st,e=function(){function e(){this.storedFrames=[],this._lastReceivedFramePosition=0,this._firstAvailableFramePosition=0,this._lastSentFramePosition=0}return Object.defineProperty(e.prototype,"lastReceivedFramePosition",{get:function(){return this._lastReceivedFramePosition},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"firstAvailableFramePosition",{get:function(){return this._firstAvailableFramePosition},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lastSentFramePosition",{get:function(){return this._lastSentFramePosition},enumerable:!1,configurable:!0}),e.prototype.store=function(l){this._lastSentFramePosition+=(0,u.sizeOfFrame)(l),this.storedFrames.push(l)},e.prototype.record=function(l){this._lastReceivedFramePosition+=(0,u.sizeOfFrame)(l)},e.prototype.dropTo=function(l){for(var e=l-this._firstAvailableFramePosition;e>0&&this.storedFrames.length>0;){var t=this.storedFrames.shift();e-=(0,u.sizeOfFrame)(t)}if(0!==e)throw new n.RSocketError(n.ErrorCodes.CONNECTION_ERROR,"State inconsistency. Expected bytes to drop ".concat(l-this._firstAvailableFramePosition," but actual ").concat(e));this._firstAvailableFramePosition=l},e.prototype.drain=function(n){var u,e;try{for(var t=l(this.storedFrames),r=t.next();!r.done;r=t.next()){n(r.value)}}catch(l){u={error:l}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(u)throw u.error}}},e}();return Pr.FrameStore=e,Pr}function Nr(){if(kr)return bt;kr=1;var l=o&&o.__awaiter||function(l,n,u,e){return new(u||(u=Promise))((function(t,r){function o(l){try{a(e.next(l))}catch(l){r(l)}}function i(l){try{a(e.throw(l))}catch(l){r(l)}}function a(l){var n;l.done?t(l.value):(n=l.value,n instanceof u?n:new u((function(l){l(n)}))).then(o,i)}a((e=e.apply(l,n||[])).next())}))},n=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(bt,"__esModule",{value:!0}),bt.RSocketConnector=void 0;var u=Et(),e=ct,t=wt,r=Lr(),i=function(){function o(l){this.config=l}return o.prototype.connect=function(){var o,i,a,s,c,d,h,f,p,y,m,g,b,v,E,w,_,S,T,R;return l(this,void 0,void 0,(function(){var O,A,C,F,I,k,P,L,N,x=this;return n(this,(function(U){switch(U.label){case 0:return O=this.config,A={type:e.FrameTypes.SETUP,dataMimeType:null!==(i=null===(o=O.setup)||void 0===o?void 0:o.dataMimeType)&&void 0!==i?i:"application/octet-stream",metadataMimeType:null!==(s=null===(a=O.setup)||void 0===a?void 0:a.metadataMimeType)&&void 0!==s?s:"application/octet-stream",keepAlive:null!==(d=null===(c=O.setup)||void 0===c?void 0:c.keepAlive)&&void 0!==d?d:6e4,lifetime:null!==(f=null===(h=O.setup)||void 0===h?void 0:h.lifetime)&&void 0!==f?f:3e5,metadata:null===(y=null===(p=O.setup)||void 0===p?void 0:p.payload)||void 0===y?void 0:y.metadata,data:null===(g=null===(m=O.setup)||void 0===m?void 0:m.payload)||void 0===g?void 0:g.data,resumeToken:null!==(v=null===(b=O.resume)||void 0===b?void 0:b.tokenGenerator())&&void 0!==v?v:null,streamId:0,majorVersion:1,minorVersion:0,flags:((null===(w=null===(E=O.setup)||void 0===E?void 0:E.payload)||void 0===w?void 0:w.metadata)?e.Flags.METADATA:e.Flags.NONE)|(O.lease?e.Flags.LEASE:e.Flags.NONE)|(O.resume?e.Flags.RESUME_ENABLE:e.Flags.NONE)},[4,O.transport.connect((function(t){return O.resume?new u.ResumableClientServerInputMultiplexerDemultiplexer(u.StreamIdGenerator.create(-1),t,t,new r.FrameStore,A.resumeToken.toString(),(function(t,r){return l(x,void 0,void 0,(function(){var l,o,i;return n(this,(function(n){switch(n.label){case 0:return l=function(l){return l.send({type:e.FrameTypes.RESUME,streamId:0,flags:e.Flags.NONE,clientPosition:r.firstAvailableFramePosition,serverPosition:r.lastReceivedFramePosition,majorVersion:A.minorVersion,minorVersion:A.majorVersion,resumeToken:A.resumeToken}),new u.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer(l,l,t)},o=-1,[4,(i=function(){return o++,O.resume.reconnectFunction(o).then((function(){return O.transport.connect(l).catch(i)}))})()];case 1:return n.sent(),[2]}}))}))})):new u.ClientServerInputMultiplexerDemultiplexer(u.StreamIdGenerator.create(-1),t,t)}))];case 1:return C=U.sent(),F=new t.KeepAliveSender(C.multiplexerDemultiplexer.connectionOutbound,A.keepAlive),I=new t.KeepAliveHandler(C,A.lifetime),k=O.lease?new t.LeaseHandler(null!==(_=O.lease.maxPendingRequests)&&void 0!==_?_:256,C.multiplexerDemultiplexer):void 0,P=null!==(S=O.responder)&&void 0!==S?S:{},L=new t.DefaultConnectionFrameHandler(C,I,F,k,P),N=new t.DefaultStreamRequestHandler(P,0),C.onClose((function(l){F.close(),I.close(),L.close(l)})),C.multiplexerDemultiplexer.connectionInbound(L),C.multiplexerDemultiplexer.handleRequestStream(N),C.multiplexerDemultiplexer.connectionOutbound.send(A),I.start(),F.start(),[2,new t.RSocketRequester(C,null!==(R=null===(T=O.fragmentation)||void 0===T?void 0:T.maxOutboundFragmentSize)&&void 0!==R?R:0,k)]}}))}))},o}();return bt.RSocketConnector=i,bt}var xr,Ur={};function Br(){if(xr)return Ur;xr=1;var l=o&&o.__awaiter||function(l,n,u,e){return new(u||(u=Promise))((function(t,r){function o(l){try{a(e.next(l))}catch(l){r(l)}}function i(l){try{a(e.throw(l))}catch(l){r(l)}}function a(l){var n;l.done?t(l.value):(n=l.value,n instanceof u?n:new u((function(l){l(n)}))).then(o,i)}a((e=e.apply(l,n||[])).next())}))},n=o&&o.__generator||function(l,n){var u,e,t,r,o={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return r={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function i(r){return function(i){return function(r){if(u)throw new TypeError("Generator is already executing.");for(;o;)try{if(u=1,e&&(t=2&r[0]?e.return:r[0]?e.throw||((t=e.return)&&t.call(e),0):e.next)&&!(t=t.call(e,r[1])).done)return t;switch(e=0,t&&(r=[2&r[0],t.value]),r[0]){case 0:case 1:t=r;break;case 4:return o.label++,{value:r[1],done:!1};case 5:o.label++,e=r[1],r=[0];continue;case 7:r=o.ops.pop(),o.trys.pop();continue;default:if(!(t=o.trys,(t=t.length>0&&t[t.length-1])||6!==r[0]&&2!==r[0])){o=0;continue}if(3===r[0]&&(!t||r[1]>t[0]&&r[1]<t[3])){o.label=r[1];break}if(6===r[0]&&o.label<t[1]){o.label=t[1],t=r;break}if(t&&o.label<t[2]){o.label=t[2],o.ops.push(r);break}t[2]&&o.ops.pop(),o.trys.pop();continue}r=n.call(l,o)}catch(l){r=[6,l],e=0}finally{u=t=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,i])}}};Object.defineProperty(Ur,"__esModule",{value:!0}),Ur.RSocketServer=void 0;var u=Et(),e=yt,t=ct,r=wt,i=Lr(),a=function(){function o(l){var n,u;this.acceptor=l.acceptor,this.transport=l.transport,this.lease=l.lease,this.serverSideKeepAlive=l.serverSideKeepAlive,this.sessionStore=l.resume?{}:void 0,this.sessionTimeout=null!==(u=null===(n=l.resume)||void 0===n?void 0:n.sessionTimeout)&&void 0!==u?u:void 0}return o.prototype.bind=function(){return l(this,void 0,void 0,(function(){var o=this;return n(this,(function(a){switch(a.label){case 0:return[4,this.transport.bind((function(u,i){return l(o,void 0,void 0,(function(){var l,o,a,s,c,d,h,f,p,y,m,g,b;return n(this,(function(n){switch(n.label){case 0:switch(u.type){case t.FrameTypes.SETUP:return[3,1];case t.FrameTypes.RESUME:return[3,5]}return[3,6];case 1:return n.trys.push([1,3,,4]),this.lease&&!t.Flags.hasLease(u.flags)?(l=new e.RSocketError(e.ErrorCodes.REJECTED_SETUP,"Lease has to be enabled"),i.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,flags:t.Flags.NONE,code:l.code,message:l.message}),i.close(l),[2]):t.Flags.hasLease(u.flags)&&!this.lease?(l=new e.RSocketError(e.ErrorCodes.REJECTED_SETUP,"Lease has to be disabled"),i.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,flags:t.Flags.NONE,code:l.code,message:l.message}),i.close(l),[2]):(o=t.Flags.hasLease(u.flags)?new r.LeaseHandler(null!==(y=this.lease.maxPendingRequests)&&void 0!==y?y:256,i.multiplexerDemultiplexer):void 0,a=new r.RSocketRequester(i,null!==(g=null===(m=this.fragmentation)||void 0===m?void 0:m.maxOutboundFragmentSize)&&void 0!==g?g:0,o),[4,this.acceptor.accept({data:u.data,dataMimeType:u.dataMimeType,metadata:u.metadata,metadataMimeType:u.metadataMimeType,flags:u.flags,keepAliveMaxLifetime:u.lifetime,keepAliveInterval:u.keepAlive,resumeToken:u.resumeToken},a)]);case 2:return s=n.sent(),c=new r.KeepAliveHandler(i,u.lifetime),d=this.serverSideKeepAlive?new r.KeepAliveSender(i.multiplexerDemultiplexer.connectionOutbound,u.keepAlive):void 0,h=new r.DefaultConnectionFrameHandler(i,c,d,o,s),f=new r.DefaultStreamRequestHandler(s,0),i.onClose((function(l){null==d||d.close(),c.close(),h.close(l)})),i.multiplexerDemultiplexer.connectionInbound(h),i.multiplexerDemultiplexer.handleRequestStream(f),c.start(),null==d||d.start(),[3,4];case 3:return p=n.sent(),i.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,code:e.ErrorCodes.REJECTED_SETUP,message:null!==(b=p.message)&&void 0!==b?b:"",flags:t.Flags.NONE}),i.close(p instanceof e.RSocketError?p:new e.RSocketError(e.ErrorCodes.REJECTED_SETUP,p.message)),[3,4];case 4:case 5:return[2];case 6:i.multiplexerDemultiplexer.connectionOutbound.send({type:t.FrameTypes.ERROR,streamId:0,code:e.ErrorCodes.UNSUPPORTED_SETUP,message:"Unsupported setup",flags:t.Flags.NONE}),i.close(new e.RSocketError(e.ErrorCodes.UNSUPPORTED_SETUP)),n.label=7;case 7:return[2]}}))}))}),(function(l,n){if(l.type===t.FrameTypes.RESUME){if(o.sessionStore){var r=o.sessionStore[l.resumeToken.toString()];return r?(r.resume(l,n,n),r):(n.send({type:t.FrameTypes.ERROR,streamId:0,code:e.ErrorCodes.REJECTED_RESUME,message:"No session found for the given resume token",flags:t.Flags.NONE}),void n.close())}return n.send({type:t.FrameTypes.ERROR,streamId:0,code:e.ErrorCodes.REJECTED_RESUME,message:"Resume is not enabled",flags:t.Flags.NONE}),void n.close()}if(l.type===t.FrameTypes.SETUP&&t.Flags.hasResume(l.flags)){if(!o.sessionStore){var a=new e.RSocketError(e.ErrorCodes.REJECTED_SETUP,"No resume support");return n.send({type:t.FrameTypes.ERROR,streamId:0,flags:t.Flags.NONE,code:a.code,message:a.message}),void n.close(a)}var s=new u.ResumableClientServerInputMultiplexerDemultiplexer(u.StreamIdGenerator.create(0),n,n,new i.FrameStore,l.resumeToken.toString(),o.sessionStore,o.sessionTimeout);return o.sessionStore[l.resumeToken.toString()]=s,s}return new u.ClientServerInputMultiplexerDemultiplexer(u.StreamIdGenerator.create(0),n,n)}))];case 1:return[2,a.sent()]}}))}))},o}();return Ur.RSocketServer=a,Ur}var Dr,Mr={};function qr(){return Dr||(Dr=1,function(l){var n=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),u=o&&o.__exportStar||function(l,u){for(var e in l)"default"===e||Object.prototype.hasOwnProperty.call(u,e)||n(u,l,e)};Object.defineProperty(l,"__esModule",{value:!0}),u(st,l),u(dt,l),u(ht,l),u(yt,l),u(ct,l),u(mt,l),u(Nr(),l),u(Br(),l),u(Mr,l)}(ut)),ut}Object.defineProperty(Mr,"__esModule",{value:!0});var jr,Wr=qr(),zr={},Qr={},$r={},Hr=o&&o.__extends||(jr=function(l,n){return jr=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,n){l.__proto__=n}||function(l,n){for(var u in n)Object.prototype.hasOwnProperty.call(n,u)&&(l[u]=n[u])},jr(l,n)},function(l,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function u(){this.constructor=l}jr(l,n),l.prototype=null===n?Object.create(n):(u.prototype=n.prototype,new u)});Object.defineProperty($r,"__esModule",{value:!0}),$r.WebsocketDuplexConnection=void 0;var Vr=qr(),Jr=function(l){function n(n,u,e){var t=l.call(this)||this;return t.websocket=n,t.deserializer=u,t.handleClosed=function(l){t.close(new Error(l.reason||"WebsocketDuplexConnection: Socket closed unexpectedly."))},t.handleError=function(l){t.close(l.error)},t.handleMessage=function(l){try{var n=et.Buffer.from(l.data),u=t.deserializer.deserializeFrame(n);t.multiplexerDemultiplexer.handle(u)}catch(l){t.close(l)}},n.addEventListener("close",t.handleClosed),n.addEventListener("error",t.handleError),n.addEventListener("message",t.handleMessage),t.multiplexerDemultiplexer=e(t),t}return Hr(n,l),Object.defineProperty(n.prototype,"availability",{get:function(){return this.done?0:1},enumerable:!1,configurable:!0}),n.prototype.close=function(n){this.done||(this.websocket.removeEventListener("close",this.handleClosed),this.websocket.removeEventListener("error",this.handleError),this.websocket.removeEventListener("message",this.handleMessage),this.websocket.close(),delete this.websocket),l.prototype.close.call(this,n)},n.prototype.send=function(l){if(!this.done){var n=(0,Vr.serializeFrame)(l);this.websocket.send(n)}},n}(Vr.Deferred);$r.WebsocketDuplexConnection=Jr,Object.defineProperty(Qr,"__esModule",{value:!0}),Qr.WebsocketClientTransport=void 0;var Yr=qr(),Xr=$r,Gr=function(){function l(l){var n;this.url=l.url,this.factory=null!==(n=l.wsCreator)&&void 0!==n?n:function(l){return new WebSocket(l)}}return l.prototype.connect=function(l){var n=this;return new Promise((function(u,e){var t=n.factory(n.url);t.binaryType="arraybuffer";var r=function(){t.removeEventListener("open",r),t.removeEventListener("error",o),u(new Xr.WebsocketDuplexConnection(t,new Yr.Deserializer,l))},o=function(l){t.removeEventListener("open",r),t.removeEventListener("error",o),e(l.error)};t.addEventListener("open",r),t.addEventListener("error",o)}))},l}();Qr.WebsocketClientTransport=Gr,function(l){var n=o&&o.__createBinding||(Object.create?function(l,n,u,e){void 0===e&&(e=u),Object.defineProperty(l,e,{enumerable:!0,get:function(){return n[u]}})}:function(l,n,u,e){void 0===e&&(e=u),l[e]=n[u]}),u=o&&o.__exportStar||function(l,u){for(var e in l)"default"===e||Object.prototype.hasOwnProperty.call(u,e)||n(u,l,e)};Object.defineProperty(l,"__esModule",{value:!0}),u(Qr,l)}(zr);const Kr={highWater:10,lowWater:0};class Zr extends v{options;dataQueue;isClosed;processingPromise;logger;constructor(n){if(super(),this.options=n,this.processingPromise=null,this.isClosed=!1,this.dataQueue=[],this.logger=n?.logger??l.get("DataStream"),n?.closeOnError){const l=this.registerListener({error:n=>{l?.(),this.close()}})}}get highWatermark(){return this.options?.pressure?.highWaterMark??Kr.highWater}get lowWatermark(){return this.options?.pressure?.lowWaterMark??Kr.lowWater}get closed(){return this.isClosed}async close(){this.isClosed=!0,await this.processingPromise,this.iterateListeners((l=>l.closed?.())),this.dataQueue=[],this.listeners.clear()}enqueueData(l){if(this.isClosed)throw new Error("Cannot enqueue data into closed stream.");this.dataQueue.push(l),this.processQueue()}async read(){return this.dataQueue.length<=this.lowWatermark&&await this.iterateAsyncErrored((async l=>l.lowWater?.())),this.closed?null:new Promise(((l,n)=>{const u=this.registerListener({data:async n=>{l(n),u?.()},closed:()=>{l(null),u?.()},error:l=>{n(l),u?.()}});this.processQueue()}))}forEach(l){return this.dataQueue.length<=this.lowWatermark&&this.iterateAsyncErrored((async l=>l.lowWater?.())),this.registerListener({data:l})}async processQueue(){if(!this.processingPromise)return this.dataQueue.length>=this.highWatermark&&await this.iterateAsyncErrored((async l=>l.highWater?.())),this.processingPromise=this._processQueue()}map(l){const n=new Zr(this.options),u=this.registerListener({data:async u=>{n.enqueueData(l(u))},closed:()=>{n.close(),u?.()}});return n}hasDataReader(){return Array.from(this.listeners.values()).some((l=>!!l.data))}async _processQueue(){if(!this.dataQueue.length||this.isClosed||!this.hasDataReader())return void Promise.resolve().then((()=>this.processingPromise=null));const l=this.dataQueue.shift();await this.iterateAsyncErrored((async n=>n.data?.(l))),this.dataQueue.length<=this.lowWatermark&&await this.iterateAsyncErrored((async l=>l.lowWater?.())),this.processingPromise=null,this.dataQueue.length&&setTimeout((()=>this.processQueue()))}async iterateAsyncErrored(l){for(let n of Array.from(this.listeners.values()))try{await l(n)}catch(l){this.logger.error(l),this.iterateListeners((n=>n.error?.(l)))}}}const lo=/\/+$/,no=l.get("PowerSyncRemote");class uo{getFetch(){throw new Error("Unspecified fetch implementation")}}const eo={socketUrlTransformer:l=>l.replace(/^https?:\/\//,(function(l){return"https://"===l?"wss://":"ws://"})),fetchImplementation:new uo};class to{connector;logger;credentials=null;options;constructor(l,n=no,u){this.connector=l,this.logger=n,this.options={...eo,...u??{}}}get fetch(){const{fetchImplementation:l}=this.options;return l instanceof uo?l.getFetch():l}async getCredentials(){const{expiresAt:l}=this.credentials??{};if(l&&l>new Date((new Date).valueOf()+3e4))return this.credentials;if(this.credentials=await this.connector.fetchCredentials(),this.credentials?.endpoint.match(lo))throw new Error(`A trailing forward slash "/" was found in the fetchCredentials endpoint: "${this.credentials.endpoint}". Remove the trailing forward slash "/" to fix this error.`);return this.credentials}getUserAgent(){return"powersync-js/1.20.1"}async buildRequest(l){const n=await this.getCredentials();if(null!=n&&(null==n.endpoint||""==n.endpoint))throw new Error("PowerSync endpoint not configured");if(null==n?.token||""==n?.token){const l=new Error("Not signed in");throw l.status=401,l}const u=this.getUserAgent();return{url:n.endpoint+l,headers:{"content-type":"application/json",Authorization:`Token ${n.token}`,"x-user-agent":u}}}async post(l,n,u={}){const e=await this.buildRequest(l),t=await this.fetch(e.url,{method:"POST",headers:{...u,...e.headers},body:JSON.stringify(n)});if(!t.ok)throw new Error(`Received ${t.status} - ${t.statusText} when posting to ${l}: ${await t.text()}}`);return t.json()}async get(l,n){const u=await this.buildRequest(l),e=await this.fetch(u.url,{method:"GET",headers:{...n,...u.headers}});if(!e.ok)throw new Error(`Received ${e.status} - ${e.statusText} when getting from ${l}: ${await e.text()}}`);return e.json()}async postStreaming(l,n,u={},e){const t=await this.buildRequest(l),r=await this.fetch(t.url,{method:"POST",headers:{...u,...t.headers},body:JSON.stringify(n),signal:e,cache:"no-store"}).catch((n=>{throw this.logger.error(`Caught ex when POST streaming to ${l}`,n),n}));if(!r.ok){const n=await r.text();this.logger.error(`Could not POST streaming to ${l} - ${r.status} - ${r.statusText}: ${n}`);const u=new Error(`HTTP ${r.statusText}: ${n}`);throw u.status=r.status,u}return r}async socketStream(l){const{path:n}=l,u=await this.buildRequest(n),e=await this.getBSON(),t=this.getUserAgent(),r=new Wr.RSocketConnector({transport:new zr.WebsocketClientTransport({url:this.options.socketUrlTransformer(u.url)}),setup:{keepAlive:2e4,lifetime:3e4,dataMimeType:"application/bson",metadataMimeType:"application/bson",payload:{data:null,metadata:De.Buffer.from(e.serialize({token:u.headers.Authorization,user_agent:t}))}}});let o;try{o=await r.connect()}catch(l){throw new Error(`Could not connect to PowerSync instance: ${JSON.stringify(l)}`)}const i=new Zr({logger:this.logger,pressure:{lowWaterMark:5}});let a=!1;o.onClose((()=>a=!0));let s=10;const c=i.registerListener({closed:()=>{a||(a=!0,o.close()),c()}}),d=await new Promise(((u,t)=>{let r=!1;const a=o.requestStream({data:De.Buffer.from(e.serialize(l.data)),metadata:De.Buffer.from(e.serialize({path:n}))},10,{onError:l=>{"Closed. "!==l.message&&this.logger.error(l),i.close(),r||t(l)},onNext:l=>{r||(r=!0,u(a));const{data:n}=l;if(s--,!n)return;const t=e.deserialize(n);i.enqueueData(t)},onComplete:()=>{i.close()},onExtension:()=>{}})})),h=i.registerListener({lowWater:async()=>{10-s>0&&(d.request(10-s),s=10)},closed:()=>{h()}});return l.abortSignal?.aborted?i.close():l.abortSignal?.addEventListener("abort",(()=>{i.close()})),i}async postStream(l){const{data:n,path:u,headers:e,abortSignal:t}=l,r=await this.buildRequest(u),o=new AbortController;let i=!1;t?.addEventListener("abort",(()=>{i||o.abort(t.reason??new L("Cancelling network request before it resolves. Abort signal has been received."))}));const a=await this.fetch(r.url,{method:"POST",headers:{...e,...r.headers},body:JSON.stringify(n),signal:o.signal,cache:"no-store",...l.fetchOptions}).catch((l=>{if("AbortError"==l.name)throw new L(`Pending fetch request to ${r.url} has been aborted.`);throw l}));if(!a)throw new Error("Fetch request was aborted");if(i=!0,!a.ok||!a.body){const l=await a.text();this.logger.error(`Could not POST streaming to ${u} - ${a.status} - ${a.statusText}: ${l}`);const n=new Error(`HTTP ${a.statusText}: ${l}`);throw n.status=a.status,n}const s=a.body.getReader(),c=async()=>{try{await s.cancel()}catch(l){}s.releaseLock()};t?.addEventListener("abort",(()=>{c()}));const d=new Se({start:l=>{(async()=>{for(;!t?.aborted;)try{const{done:n,value:u}=await s.read();if(n)break;l.enqueue(u)}catch(l){this.logger.error("Caught exception when reading sync stream",l);break}t?.aborted||await c(),l.close()})()}}),h=nt(d),f=new Zr({logger:this.logger}),p=h.getReader(),y=f.registerListener({lowWater:async()=>{try{const{done:l,value:n}=await p.read();if(l)return f.close(),void y?.();f.enqueueData(n)}catch(l){throw f.close(),l}},closed:()=>{c(),y?.()}});return f}}var ro;!function(l){l.TEXT="TEXT",l.INTEGER="INTEGER",l.REAL="REAL"}(ro||(ro={}));const oo={type:ro.TEXT},io={type:ro.INTEGER},ao={type:ro.REAL},so=63,co={text:oo,integer:io,real:ao};class ho{options;constructor(l){this.options=l}get name(){return this.options.name}get type(){return this.options.type}toJSON(){return{name:this.name,type:this.type}}}const fo={ascending:!0};class po{options;static createAscending(l){return new po({name:l,ascending:!0})}constructor(l){this.options={...fo,...l}}get name(){return this.options.name}get ascending(){return this.options.ascending}toJSON(l){return{name:this.name,ascending:this.ascending,type:l.columns.find((l=>l.name===this.name))?.type??ro.TEXT}}}const yo={columns:[]};class mo{options;static createAscending(l,n){return new mo({...l,columns:n.map((l=>po.createAscending(l)))})}constructor(l){this.options=l,this.options={...yo,...l}}get name(){return this.options.name}get columns(){return this.options.columns??[]}toJSON(l){return{name:this.name,columns:this.columns.map((n=>n.toJSON(l)))}}}const go={indexes:[],insertOnly:!1,localOnly:!1},bo=/["'%,.#\s[\]]/;class vo{options;_mappedColumns;static createLocalOnly(l){return new vo({...l,localOnly:!0,insertOnly:!1})}static createInsertOnly(l){return new vo({...l,localOnly:!1,insertOnly:!0})}static createTable(l,n){return new vo({name:l,columns:n.columns,indexes:n.indexes,localOnly:n.options.localOnly,insertOnly:n.options.insertOnly,viewName:n.options.viewName})}constructor(l,n){this.isTableV1(l)?this.initTableV1(l):this.initTableV2(l,n)}isTableV1(l){return"columns"in l&&Array.isArray(l.columns)}initTableV1(l){this.options={...l,indexes:l.indexes||[],insertOnly:l.insertOnly??go.insertOnly,localOnly:l.localOnly??go.localOnly}}initTableV2(l,n){const u=Object.entries(l).map((([l,n])=>new ho({name:l,type:n.type}))),e=Object.entries(n?.indexes??{}).map((([l,n])=>new mo({name:l,columns:n.map((l=>new po({name:l.replace(/^-/,""),ascending:!l.startsWith("-")})))})));this.options={name:"",columns:u,indexes:e,insertOnly:n?.insertOnly??go.insertOnly,localOnly:n?.localOnly??go.localOnly,viewName:n?.viewName},this._mappedColumns=l}get name(){return this.options.name}get viewNameOverride(){return this.options.viewName}get viewName(){return this.viewNameOverride??this.name}get columns(){return this.options.columns}get columnMap(){return this._mappedColumns??this.columns.reduce(((l,n)=>(l[n.name]={type:n.type??ro.TEXT},l)),{})}get indexes(){return this.options.indexes??[]}get localOnly(){return this.options.localOnly??!1}get insertOnly(){return this.options.insertOnly??!1}get internalName(){return this.options.localOnly?`ps_data_local__${this.name}`:`ps_data__${this.name}`}get validName(){return!bo.test(this.name)&&(null==this.viewNameOverride||!bo.test(this.viewNameOverride))}validate(){if(bo.test(this.name))throw new Error(`Invalid characters in table name: ${this.name}`);if(this.viewNameOverride&&bo.test(this.viewNameOverride))throw new Error(`Invalid characters in view name: ${this.viewNameOverride}`);if(this.columns.length>63)throw new Error("Table has too many columns. The maximum number of columns is 63.");const l=new Set;l.add("id");for(const n of this.columns){const{name:u}=n;if("id"===n.name)throw new Error("An id column is automatically added, custom id columns are not supported");if(l.has(u))throw new Error(`Duplicate column ${u}`);if(bo.test(u))throw new Error(`Invalid characters in column name: ${n.name}`);l.add(u)}const n=new Set;for(const u of this.indexes){if(n.has(u.name))throw new Error(`Duplicate index ${u.name}`);if(bo.test(u.name))throw new Error(`Invalid characters in index name: ${u.name}`);for(const n of u.columns)if(!l.has(n.name))throw new Error(`Column ${n.name} not found for index ${u.name}`);n.add(u.name)}}toJSON(){return{name:this.name,view_name:this.viewName,local_only:this.localOnly,insert_only:this.insertOnly,columns:this.columns.map((l=>l.toJSON())),indexes:this.indexes.map((l=>l.toJSON(this)))}}}class Eo{types;props;tables;constructor(l){Array.isArray(l)?this.tables=l:(this.props=l,this.tables=this.convertToClassicTables(this.props))}validate(){for(const l of this.tables)l.validate()}toJSON(){return{tables:this.tables.map((l=>l.toJSON()))}}convertToClassicTables(l){return Object.entries(l).map((([l,n])=>new vo({name:l,columns:n.columns,indexes:n.indexes,localOnly:n.localOnly,insertOnly:n.insertOnly,viewName:n.viewNameOverride||l})))}}class wo extends vo{}const _o=(l,n)=>{let u;if("string"==typeof l)u=l;else{if(n.length>0)throw new Error("You cannot pass parameters to a compiled query.");const e=l.compile();u=e.sql,n=e.parameters}return{sqlStatement:u,parameters:n}};export{L as AbortOperation,nl as AbstractPowerSyncDatabase,ul as AbstractPowerSyncDatabaseOpenFactory,to as AbstractRemote,V as AbstractStreamingSyncImplementation,v as BaseObserver,ho as Column,ro as ColumnType,I as CrudBatch,k as CrudEntry,P as CrudTransaction,Q as DEFAULT_CRUD_UPLOAD_THROTTLE_MS,fo as DEFAULT_INDEX_COLUMN_OPTIONS,yo as DEFAULT_INDEX_OPTIONS,Z as DEFAULT_LOCK_TIMEOUT_MS,X as DEFAULT_POWERSYNC_CLOSE_OPTIONS,K as DEFAULT_POWERSYNC_DB_OPTIONS,Kr as DEFAULT_PRESSURE_LIMITS,no as DEFAULT_REMOTE_LOGGER,eo as DEFAULT_REMOTE_OPTIONS,$ as DEFAULT_STREAMING_SYNC_OPTIONS,H as DEFAULT_STREAM_CONNECTION_OPTIONS,go as DEFAULT_TABLE_OPTIONS,G as DEFAULT_WATCH_THROTTLE_MS,Zr as DataStream,uo as FetchImplementationProvider,mo as Index,po as IndexedColumn,bo as InvalidSQLCharacters,C as LockType,so as MAX_AMOUNT_OF_COLUMNS,el as MAX_OP_ID,N as OpType,A as OpTypeEnum,x as OplogEntry,R as PSInternalTable,f as RowUpdateType,Eo as Schema,rl as SqliteBucketStorage,ol as SyncDataBatch,U as SyncDataBucket,g as SyncStatus,F as SyncStreamConnectionMethod,vo as Table,wo as TableV2,O as UpdateType,b as UploadQueueStats,co as column,m as extractTableUpdates,y as isBatchedUpdateNotification,W as isContinueCheckpointRequest,T as isDBAdapter,ll as isPowerSyncDatabaseOptionsWithSettings,S as isSQLOpenFactory,_ as isSQLOpenOptions,D as isStreamingKeepalive,M as isStreamingSyncCheckpoint,q as isStreamingSyncCheckpointComplete,j as isStreamingSyncCheckpointDiff,B as isStreamingSyncData,z as isSyncNewCheckpointRequest,_o as parseQuery};
|
|
@@ -6,6 +6,7 @@ import { WebsocketClientTransport } from 'rsocket-websocket-client';
|
|
|
6
6
|
import { AbortOperation } from '../../../utils/AbortOperation.js';
|
|
7
7
|
import { DataStream } from '../../../utils/DataStream.js';
|
|
8
8
|
import { version as POWERSYNC_JS_VERSION } from '../../../../package.json';
|
|
9
|
+
const POWERSYNC_TRAILING_SLASH_MATCH = /\/+$/;
|
|
9
10
|
// Refresh at least 30 sec before it expires
|
|
10
11
|
const REFRESH_CREDENTIALS_SAFETY_PERIOD_MS = 30_000;
|
|
11
12
|
const SYNC_QUEUE_REQUEST_N = 10;
|
|
@@ -61,6 +62,9 @@ export class AbstractRemote {
|
|
|
61
62
|
return this.credentials;
|
|
62
63
|
}
|
|
63
64
|
this.credentials = await this.connector.fetchCredentials();
|
|
65
|
+
if (this.credentials?.endpoint.match(POWERSYNC_TRAILING_SLASH_MATCH)) {
|
|
66
|
+
throw new Error(`A trailing forward slash "/" was found in the fetchCredentials endpoint: "${this.credentials.endpoint}". Remove the trailing forward slash "/" to fix this error.`);
|
|
67
|
+
}
|
|
64
68
|
return this.credentials;
|
|
65
69
|
}
|
|
66
70
|
getUserAgent() {
|