grpc-libp2p-client 0.0.41 → 0.0.42
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/grpc.js +1 -1
- package/dist/grpc.min.js +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
package/dist/grpc.js
CHANGED
|
@@ -3052,7 +3052,7 @@
|
|
|
3052
3052
|
console.warn("[unaryCall] waiting for stream slot failed:", err_2);
|
|
3053
3053
|
throw err_2;
|
|
3054
3054
|
case 6: return [4 /*yield*/, connection.newStream(this.protocol, {
|
|
3055
|
-
maxOutboundStreams:
|
|
3055
|
+
maxOutboundStreams: 50,
|
|
3056
3056
|
negotiateFully: false,
|
|
3057
3057
|
})];
|
|
3058
3058
|
case 7:
|
package/dist/grpc.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GrpcLibp2pClient={})}(this,function(e){"use strict";"undefined"!=typeof window&&window;var t=function(){return t=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},t.apply(this,arguments)};function r(e,t,r,n){return new(r||(r=Promise))(function(i,a){function o(e){try{c(n.next(e))}catch(e){a(e)}}function s(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,s)}c((n=n.apply(e,t||[])).next())})}function n(e,t){var r,n,i,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}function i(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(e){return this instanceof a?(this.v=e,this):new a(e)}function o(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(e,t||[]),o=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",function(e){return function(t){return Promise.resolve(t).then(e,l)}}),n[Symbol.asyncIterator]=function(){return this},n;function s(e,t){i[e]&&(n[e]=function(t){return new Promise(function(r,n){o.push([e,t,r,n])>1||c(e,t)})},t&&(n[e]=t(n[e])))}function c(e,t){try{(r=i[e](t)).value instanceof a?Promise.resolve(r.value.v).then(u,l):h(o[0][2],r)}catch(e){h(o[0][3],e)}var r}function u(e){c("next",e)}function l(e){c("throw",e)}function h(e,t){e(t),o.shift(),o.length&&c(o[0][0],o[0][1])}}function s(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=i(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise(function(n,i){(function(e,t,r,n){Promise.resolve(n).then(function(t){e({value:t,done:r})},t)})(n,i,(t=e[r](t)).done,t.value)})}}}"function"==typeof SuppressedError&&SuppressedError;var c,u=0,l=1,h=3,d=4,f=6,p=7,g=8,m=1,v=1,b=function(){function e(e){void 0===e&&(e=4096),this.dynamicTable=[],this.dynamicTableSize=0,this.maxDynamicTableSize=e,this.staticTable=[["",""],[":authority",""],[":method","GET"],[":method","POST"],[":path","/"],[":path","/index.html"],[":scheme","http"],[":scheme","https"],[":status","200"],[":status","204"],[":status","206"],[":status","304"],[":status","400"],[":status","404"],[":status","500"],["accept-charset",""],["accept-encoding","gzip, deflate"],["accept-language",""],["accept-ranges",""],["accept",""],["access-control-allow-origin",""],["age",""],["allow",""],["authorization",""],["cache-control",""],["content-disposition",""],["content-encoding",""],["content-language",""],["content-length",""],["content-location",""],["content-range",""],["content-type",""],["cookie",""],["date",""],["etag",""],["expect",""],["expires",""],["from",""],["host",""],["if-match",""],["if-modified-since",""],["if-none-match",""],["if-range",""],["if-unmodified-since",""],["last-modified",""],["link",""],["location",""],["max-forwards",""],["proxy-authenticate",""],["proxy-authorization",""],["range",""],["referer",""],["refresh",""],["retry-after",""],["server",""],["set-cookie",""],["strict-transport-security",""],["transfer-encoding",""],["user-agent",""],["vary",""],["via",""],["www-authenticate",""]],this.huffmanTable=this.buildHuffmanTable()}return e.prototype.encode=function(e){for(var t=[],r=0,n=Object.entries(e);r<n.length;r++){var i=n[r],a=i[0],o=i[1],s=this.findInStaticTable(a,o);if(-1===s){var c=this.findInDynamicTable(a,o);-1===c?this.encodeLiteral(t,a,o):t.push.apply(t,this.encodeInteger(c+this.staticTable.length,7,128))}else t.push.apply(t,this.encodeInteger(s,7,128))}return new Uint8Array(t)},e.prototype.encodeInteger=function(e,t,r){void 0===r&&(r=0);var n=[],i=(1<<t)-1;if(e<i)return n.push(r|e),n;for(n.push(r|i),e-=i;e>=128;)n.push(127&e|128),e>>=7;return n.push(e),n},e.prototype.encodeString=function(e){var t=[],r=(new TextEncoder).encode(e),n=this.huffmanEncode(r);return n.length<r.length?(t.push.apply(t,this.encodeInteger(n.length,7,128)),Array.from(n).forEach(function(e){return t.push(e)})):(t.push.apply(t,this.encodeInteger(r.length,7,0)),Array.from(r).forEach(function(e){return t.push(e)})),t},e.prototype.findInStaticTable=function(e,t){for(var r=1;r<this.staticTable.length;r++)if(this.staticTable[r][0]===e&&this.staticTable[r][1]===t)return r;return-1},e.prototype.findInDynamicTable=function(e,t){for(var r=0;r<this.dynamicTable.length;r++)if(this.dynamicTable[r][0]===e&&this.dynamicTable[r][1]===t)return r;return-1},e.prototype.encodeLiteral=function(e,t,r){var n=this.findInStaticTable(t,"");-1!==n?e.push.apply(e,this.encodeInteger(n,6,64)):(e.push(64),e.push.apply(e,this.encodeString(t))),e.push.apply(e,this.encodeString(r)),this.addToDynamicTable(t,r)},e.prototype.addToDynamicTable=function(e,t){for(var r=e.length+t.length+32;this.dynamicTableSize+r>this.maxDynamicTableSize&&this.dynamicTable.length>0;){var n=this.dynamicTable.pop();n&&(this.dynamicTableSize-=n[0].length+n[1].length+32)}r<=this.maxDynamicTableSize&&(this.dynamicTable.unshift([e,t]),this.dynamicTableSize+=r)},e.prototype.getIndexedHeader=function(e){return e<=this.staticTable.length-1?this.staticTable[e]:this.dynamicTable[e-this.staticTable.length]},e.prototype.buildHuffmanTable=function(){return{codes:new Uint32Array([8184,8388568,268435426,268435427,268435428,268435429,268435430,268435431,268435432,16777194,1073741820,268435433,268435434,1073741821,268435435,268435436,268435437,268435438,268435439,268435440,268435441,268435442,1073741822,268435443,268435444,268435445,268435446,268435447,268435448,268435449,268435450,268435451,20,1016,1017,4090,8185,21,248,2042,1018,1019,249,2043,250,22,23,24,0,1,2,25,26,27,28,29,30,31,92,251,32764,32,4091,1020,8186,33,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,252,115,253,8187,524272,8188,16380,34,32765,3,35,4,36,5,37,38,39,6,116,117,40,41,42,7,43,118,44,8,9,45,119,120,121,122,123,32766,2044,16381,8189,268435452,1048550,4194258,1048551,1048552,4194259,4194260,4194261,8388569,4194262,8388570,8388571,8388572,8388573,8388574,16777195,8388575,16777196,16777197,4194263,8388576,16777198,8388577,8388578,8388579,8388580,2097116,4194264,8388581,4194265,8388582,8388583,16777199,4194266,2097117,1048553,4194267,4194268,8388584,8388585,2097118,8388586,4194269,4194270,16777200,2097119,4194271,8388587,8388588,2097120,2097121,4194272,2097122,8388589,4194273,8388590,8388591,1048554,4194274,4194275,4194276,8388592,4194277,4194278,8388593,67108832,67108833,1048555,524273,4194279,8388594,4194280,33554412,67108834,67108835,67108836,134217694,134217695,67108837,16777201,33554413,524274,2097123,67108838,134217696,134217697,67108839,134217698,16777202,2097124,2097125,67108840,67108841,268435453,134217699,134217700,134217701,1048556,16777203,1048557,2097126,4194281,2097127,2097128,8388595,4194282,4194283,33554414,33554415,16777204,16777205,67108842,8388596,67108843,134217702,67108844,67108845,134217703,134217704,134217705,134217706,134217707,268435454,134217708,134217709,134217710,134217711,134217712,67108846]),lengths:new Uint8Array([13,23,28,28,28,28,28,28,28,24,30,28,28,30,28,28,28,28,28,28,28,28,30,28,28,28,28,28,28,28,28,28,6,10,10,12,13,6,8,11,10,10,8,11,8,6,6,6,5,5,5,6,6,6,6,6,6,6,7,8,15,6,12,10,13,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,7,8,13,19,13,14,6,15,5,6,5,6,5,6,6,6,5,7,7,6,6,6,5,6,7,6,5,5,6,7,7,7,7,7,15,11,14,13,28,20,22,20,20,22,22,22,23,22,23,23,23,23,23,24,23,24,24,22,23,24,23,23,23,23,21,22,23,22,23,23,24,22,21,20,22,22,23,23,21,23,22,22,24,21,22,23,23,21,21,22,21,23,22,23,23,20,22,22,22,23,22,22,23,26,26,20,19,22,23,22,25,26,26,26,27,27,26,24,25,19,21,26,27,27,26,27,24,21,21,26,26,28,27,27,27,20,24,20,21,22,21,21,23,22,22,25,25,24,24,26,23,26,27,26,26,27,27,27,27,27,28,27,27,27,27,27,26])}},e.prototype.decode=function(e){for(var t="",r=0,n=0,i=0;i<e.length;i++){for(r=r<<8|e[i],n+=8;n>=5;){var a=this.findSymbol(r,n);if(!a)break;var o=a[0],s=a[1];t+=String.fromCharCode(o),r&=(1<<n-s)-1,n-=s}}if(n>0){var c=(1<<n)-1;if((r&c)!==c)throw new Error("Invalid Huffman padding")}return t},e.prototype.findSymbol=function(e,t){for(var r=0;r<this.huffmanTable.codes.length;r++){var n=this.huffmanTable.lengths[r];if(!(t<n))if((e>>t-n&(1<<n)-1)===this.huffmanTable.codes[r])return[r,n]}return null},e.prototype.huffmanEncode=function(e){for(var t=[],r=0,n=0,i=0;i<e.length;i++){var a=e[i],o=this.huffmanTable.codes[a],s=this.huffmanTable.lengths[a];for(r=r*(1<<s)+o,n+=s;n>=8;)n-=8,t.push(255&Math.floor(r/(1<<n))),r%=1<<n}if(n>0){var c=8-n;r=r*(1<<c)+((1<<c)-1),t.push(255&r)}return new Uint8Array(t)},e.prototype.decodeHeaderFields=function(e){for(var t=new Map,r=0;r<e.length;){var n=e[r];if(128&n){var i=this.decodeIndexedHeader(e,r),a=i[0],o=i[1],s=i[2];a&&o&&t.set(a,o),r=s}else if(64&n){var c=this.decodeLiteralHeaderWithIndexing(e,r),u=c[0];o=c[1],s=c[2];u&&o&&t.set(u,o),r=s}else if(32&n){var l=this.decodeInteger(e,r,5),h=l[0];s=l[1];for(this.maxDynamicTableSize=h;this.dynamicTableSize>this.maxDynamicTableSize&&this.dynamicTable.length>0;){var d=this.dynamicTable.pop();d&&(this.dynamicTableSize-=d[0].length+d[1].length+32)}r=s}else if(16&n){var f=this.decodeLiteralHeaderWithoutIndexing(e,r),p=f[0];o=f[1],s=f[2];p&&o&&t.set(p,o),r=s}else{var g=this.decodeLiteralHeaderWithoutIndexing(e,r),m=g[0];o=g[1],s=g[2];m&&o&&t.set(m,o),r=s}}return t},e.prototype.decodeInteger=function(e,t,r){var n=(1<<r)-1,i=t,a=e[t]&n;if(a<n)return[a,i+1];i++;for(var o=0;i<e.length;){var s=e[i++];if(a+=(127&s)<<o,o+=7,!(128&s))break}return[a,i]},e.prototype.decodeLiteralString=function(e,t){if(t>=e.length)return["",t];var r=!!(128&e[t]),n=this.decodeInteger(e,t,7),i=n[0],a=n[1];if(a+i>e.length)return["",a];var o,s=e.slice(a,a+i);if(r)try{o=this.decode(s)}catch(e){o=""}else try{o=(new TextDecoder).decode(s)}catch(e){o=""}return[o,a+i]},e.prototype.decodeIndexedHeader=function(e,t){var r=this.decodeInteger(e,t,7),n=r[0],i=r[1];if(n<=0)return["","",i];var a=this.getIndexedHeader(n);return a?[a[0],a[1],i]:["","",i]},e.prototype.decodeLiteralHeaderWithIndexing=function(e,t){var r,n=this.decodeInteger(e,t,6),i=n[0];if(t=n[1],i>0){var a=this.getIndexedHeader(i);r=a?a[0]:""}else{var o=this.decodeLiteralString(e,t);r=o[0],t=o[1]}var s=this.decodeLiteralString(e,t),c=s[0],u=s[1];return this.addToDynamicTable(r,c),[r,c,u]},e.prototype.decodeLiteralHeaderWithoutIndexing=function(e,t){var r,n=this.decodeInteger(e,t,4),i=n[0];if(t=n[1],i>0){var a=this.getIndexedHeader(i);r=a?a[0]:""}else{var o=this.decodeLiteralString(e,t);r=o[0],t=o[1]}var s=this.decodeLiteralString(e,t);return[r,s[0],s[1]]},e.prototype.huffmanDecodeToString=function(e){return this.decode(e)},e}(),w=function(){function e(){}return e.encodeSettingsFrame=function(e){var t=e.payload,r=6*t.length,n=new Uint8Array(9+r);return y(n,{length:r,type:e.type,flags:e.flags,streamId:e.streamId}),function(e,t){var r=9;t.forEach(function(t){!function(e,t,r){e[r]=t>>8&255,e[r+1]=255&t}(e,t.identifier,r),r+=2,S(e,t.value,r),r+=4})}(n,t),n},e.encodeSettingsAckFrame=function(){var e=new Uint8Array(9);return y(e,{length:0,type:4,flags:1,streamId:0}),e},e}();function y(e,t){var r,n=null!==(r=t.length)&&void 0!==r?r:0;e[0]=n>>16&255,e[1]=n>>8&255,e[2]=255&n,e[3]=t.type,e[4]=t.flags,S(e,2147483647&t.streamId,5)}function S(e,t,r){e[r]=t>>24&255,e[r+1]=t>>16&255,e[r+2]=t>>8&255,e[r+3]=255&t}var E=1,T=2,W=3,A=4,k=5,C=6,P=((c={})[E]=4096,c[T]=0,c[W]=100,c[A]=4<<20,c[k]=16384,c[C]=8192,c),I=function(){function e(){}return e.createPreface=function(){return(new TextEncoder).encode("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")},e.createPongFrame=function(t){return e.createFrame(6,1,0,t)},e.createSettingsFrame=function(t){void 0===t&&(t={});var r=e.createOriginSettingsFrame(t);return w.encodeSettingsFrame(r)},e.createSettingsAckFrame=function(){return w.encodeSettingsAckFrame()},e.createWindowUpdateFrame=function(t,r){if(r<=0||r>2147483647)throw new Error("Window size increment must be between 1 and 2^31-1");var n=new Uint8Array(4);return n[0]=r>>24&127,n[1]=r>>16&255,n[2]=r>>8&255,n[3]=255&r,e.createFrame(8,0,t,n)},e.createDataFrames=function(t,r,n,i){void 0===n&&(n=!1),void 0===i&&(i=16384);var a=[],o=r.length,s=new Uint8Array(5+o);s[0]=0,s[1]=o>>24&255,s[2]=o>>16&255,s[3]=o>>8&255,s[4]=255&o,s.set(r,5);for(var c=i,u=0;u<s.length;u+=c){var l=s.length-u,h=Math.min(c,l),d=s.slice(u,u+h),f=u+h>=s.length&&n,p=e.createFrame(0,f?1:0,t,d);a.push(p)}return a},e.createDataFrame=function(t,r,n){void 0===n&&(n=!0);var i=r.length,a=new Uint8Array(5+i);a[0]=0,a[1]=i>>24&255,a[2]=i>>16&255,a[3]=i>>8&255,a[4]=255&i,a.set(r,5);var o=n?1:0;return e.createFrame(0,o,t,a)},e.createHeadersFrame=function(t,r,n,i,a){void 0===n&&(n=!0),void 0===a&&(a="localhost");var o={":path":r,":method":"POST",":scheme":"http",":authority":a,"content-type":"application/grpc+proto","user-agent":"grpc-web-client/0.1",accept:"application/grpc+proto","grpc-timeout":"3600S"};i&&(o.authorization="Bearer ".concat(i));var s=(new b).encode(o),c=n?4:0;return e.createFrame(1,c,t,s)},e.createResponseHeadersFrame=function(t,r,n){void 0===n&&(n=!0);var i=(new b).encode(r),a=n?4:0;return e.createFrame(1,a,t,i)},e.createTrailersFrame=function(t,r){var n=(new b).encode(r);return e.createFrame(1,5,t,n)},e.createOriginSettingsFrame=function(e){void 0===e&&(e={});var r=t(t({},P),e);return function(e){for(var t=0,r=Object.entries(e);t<r.length;t++){var n=r[t],i=n[0],a=n[1];switch(Number(i)){case E:if(a<0)throw new Error("HEADER_TABLE_SIZE must be non-negative");break;case T:if(0!==a&&1!==a)throw new Error("ENABLE_PUSH must be 0 or 1");break;case A:if(a<0||a>2147483647)throw new Error("INITIAL_WINDOW_SIZE must be between 0 and 2^31-1");break;case k:if(a<16384||a>16777215)throw new Error("MAX_FRAME_SIZE must be between 16,384 and 16,777,215");break;case W:case C:if(a<0)throw new Error("Parameter ".concat(i," must be non-negative"));break;default:console.warn("Unknown settings parameter: ".concat(i))}}}(r),{type:4,flags:0,streamId:0,payload:x(r)}},e.createOriginSettingsAckFrame=function(){return{type:4,flags:1,streamId:0,payload:[]}},e.createFrame=function(e,t,r,n){var i=n?n.length:0,a=new Uint8Array(9+i);return a[0]=i>>16&255,a[1]=i>>8&255,a[2]=255&i,a[3]=e,a[4]=t,a[5]=r>>24&255,a[6]=r>>16&255,a[7]=r>>8&255,a[8]=255&r,n&&i>0&&a.set(n,9),a},e}();function x(e){for(var t=[],r=0,n=Object.entries(e);r<n.length;r++){var i=n[r],a=i[0],o=i[1];t.push({identifier:Number(a),value:o})}return t}var z=(new TextEncoder).encode("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"),F=function(){function e(e,t){var r;this.bufferChunks=[],this.bufferTotalLength=0,this.bufferChunks=[],this.bufferTotalLength=0,this.settingsAckReceived=!1,this.peerSettingsReceived=!1,this.connectionWindowSize=4<<20,this.streams=new Map,this.defaultStreamWindowSize=4<<20,this.sendConnWindow=65535,this.sendStreamWindows=new Map,this.peerInitialStreamWindow=65535,this.sendWindowWaiters=[],this.settingsAckWaiters=[],this.peerSettingsWaiters=[],this.endOfStreamWaiters=[],this.endFlag=!1,this.writer=e,this.compatibilityMode=null!==(r=null==t?void 0:t.compatibilityMode)&&void 0!==r&&r}return Object.defineProperty(e.prototype,"buffer",{get:function(){return this._flattenBuffer()},set:function(e){this.bufferChunks=e.length?[e]:[],this.bufferTotalLength=e.length},enumerable:!1,configurable:!0}),e.prototype._flattenBuffer=function(){if(0===this.bufferChunks.length)return new Uint8Array(0);if(1===this.bufferChunks.length)return this.bufferChunks[0];for(var e=new Uint8Array(this.bufferTotalLength),t=0,r=0,n=this.bufferChunks;r<n.length;r++){var i=n[r];e.set(i,t),t+=i.length}return e},e.prototype._wakeWindowWaiters=function(){for(var e=0,t=this.sendWindowWaiters.splice(0);e<t.length;e++){var r=t[e];try{r.resolve()}catch(e){}}},e.prototype.processStream=function(e){return r(this,void 0,void 0,function(){var t,r,i,a,o,c,u,l,h,d,f,p;return n(this,function(n){switch(n.label){case 0:n.trys.push([0,13,,14]),n.label=1;case 1:n.trys.push([1,6,7,12]),o=!0,c=s(e),n.label=2;case 2:return[4,c.next()];case 3:if(u=n.sent(),l=u.done)return[3,5];f=u.value,o=!1,t=f,this._processChunk(t),n.label=4;case 4:return o=!0,[3,2];case 5:return[3,12];case 6:return r=n.sent(),h={error:r},[3,12];case 7:return n.trys.push([7,,10,11]),o||l||!(d=c.return)?[3,9]:[4,d.call(c)];case 8:n.sent(),n.label=9;case 9:return[3,11];case 10:if(h)throw h.error;return[7];case 11:return[7];case 12:if(!this.compatibilityMode&&!this.endFlag)try{null===(p=this.onEnd)||void 0===p||p.call(this)}catch(e){console.error("Error during onEnd callback:",e)}return this.endFlag||this._notifyEndOfStream(),[3,14];case 13:if(i=n.sent(),this.endFlag||this._notifyEndOfStream(),a=i instanceof Error?i.message:String(i),/cleanup/i.test(a))return[2];throw console.error("Error processing stream:",i),i;case 14:return[2]}})})},e.prototype._processChunk=function(e){var t="subarray"in e&&"function"==typeof e.subarray?e.subarray():e;if(t.length>0&&(this.bufferChunks.push(t),this.bufferTotalLength+=t.length),!(this.bufferTotalLength<9)){var r=this._flattenBuffer();this.bufferChunks=[r];for(var n=0;r.length-n>=9;)if(r.length-n>=24&&this.isHttp2Preface(r.subarray(n))){n+=24;var i=I.createSettingsFrame();this.writer.write(i)}else{var a=this._parseFrameHeader(r.subarray(n)),o=9+a.length;if(r.length-n<o)break;var s=r.subarray(n,n+o);this._handleFrame(a,s).catch(function(e){console.error("Error handling frame:",e)}),n+=o}if(n>0)if(n>=r.length)this.bufferChunks=[],this.bufferTotalLength=0;else{var c=r.slice(n);this.bufferChunks=[c],this.bufferTotalLength=c.length}}},e.prototype.isHttp2Preface=function(e){if(e.length<z.length)return!1;for(var t=0;t<z.length;t++)if(e[t]!==z[t])return!1;return!0},e.prototype.waitForSettingsAck=function(){var e=this;return new Promise(function(t,r){if(e.settingsAckReceived)t();else{var n={resolve:t,reject:r};e.settingsAckWaiters.push(n);var i=setTimeout(function(){var t=e.settingsAckWaiters.indexOf(n);t>=0&&e.settingsAckWaiters.splice(t,1),r(new Error("Settings ACK timeout"))},3e4);n.resolve=function(){clearTimeout(i),t()},n.reject=function(e){clearTimeout(i),r(e)}}})},e.prototype._notifySettingsAck=function(){this.settingsAckReceived=!0;for(var e=0,t=this.settingsAckWaiters.splice(0);e<t.length;e++){var r=t[e];try{r.resolve()}catch(e){}}},e.prototype.waitForPeerSettings=function(e){var t=this;return void 0===e&&(e=3e4),new Promise(function(r,n){if(t.peerSettingsReceived)r();else{var i={resolve:r,reject:n};t.peerSettingsWaiters.push(i);var a=setTimeout(function(){var e=t.peerSettingsWaiters.indexOf(i);e>=0&&t.peerSettingsWaiters.splice(e,1),n(new Error("Peer SETTINGS timeout"))},e);i.resolve=function(){clearTimeout(a),r()},i.reject=function(e){clearTimeout(a),n(e)}}})},e.prototype._notifyPeerSettings=function(){this.peerSettingsReceived=!0;for(var e=0,t=this.peerSettingsWaiters.splice(0);e<t.length;e++){var r=t[e];try{r.resolve()}catch(e){}}},e.prototype.registerOutboundStream=function(e){this.sendStreamWindows.has(e)||this.sendStreamWindows.set(e,this.peerInitialStreamWindow)},e.prototype.getSendWindows=function(e){var t,r=null!==(t=this.sendStreamWindows.get(e))&&void 0!==t?t:0;return{conn:this.sendConnWindow,stream:r}},e.prototype.consumeSendWindow=function(e,t){var r;this.sendConnWindow=Math.max(0,this.sendConnWindow-t);var n=null!==(r=this.sendStreamWindows.get(e))&&void 0!==r?r:0;this.sendStreamWindows.set(e,Math.max(0,n-t))},e.prototype.unsafeForceExtendSendWindow=function(e,t){var r;if(!(this.compatibilityMode||t<=0)){this.sendConnWindow=Math.min(2147483647,this.sendConnWindow+t);var n=null!==(r=this.sendStreamWindows.get(e))&&void 0!==r?r:0;this.sendStreamWindows.set(e,Math.min(2147483647,n+t)),this._wakeWindowWaiters()}},e.prototype.waitForSendWindow=function(e,t,r){var n=this;void 0===t&&(t=1),void 0===r&&(r=3e4);var i=this.getSendWindows(e),a=i.conn,o=i.stream;return a>=t&&o>=t?Promise.resolve():new Promise(function(i,a){var o=!1,s=r>0?setTimeout(function(){if(!o){o=!0;var e=n.sendWindowWaiters.findIndex(function(e){return e.resolve===c});e>=0&&n.sendWindowWaiters.splice(e,1),a(new Error("Send window wait timeout"))}},r):void 0,c=function(){if(!o){var r=n.getSendWindows(e),a=r.conn,l=r.stream;a>=t&&l>=t?(o=!0,s&&clearTimeout(s),i()):n.sendWindowWaiters.push({resolve:c,reject:u})}},u=function(e){o||(o=!0,s&&clearTimeout(s),a(e))};n.sendWindowWaiters.push({resolve:c,reject:u})})},e.prototype._handleFrame=function(e,t){return r(this,void 0,void 0,function(){var r,i,a,o,s,c,b,w,y,S,E,T,W,A,k,C,P,x,z,F,O,L,D,H,M,U=this;return n(this,function(n){switch(e.type){case d:if((e.flags&m)===m)this._notifySettingsAck();else{for(r=t.slice(9),i={},a=0,o=void 0,s=0;s<r.length;s+=6)c=r[s]<<8|r[s+1],b=(r[s+2]<<24|r[s+3]<<16|r[s+4]<<8|r[s+5])>>>0,i[c]=b,4===c?(this.defaultStreamWindowSize=b,a=b-this.peerInitialStreamWindow,this.peerInitialStreamWindow=b):3===c&&(o=b);this.compatibilityMode||0===a||Array.from(this.sendStreamWindows.entries()).forEach(function(e){var t=e[0],r=e[1],n=Math.max(0,r+a);U.sendStreamWindows.set(t,n)});try{!this.onSettingsParsed||void 0===o&&0===a||(w={},void 0!==o&&(w.maxConcurrentStreams=o),0!==a&&(w.initialWindowSize=this.peerInitialStreamWindow),this.onSettingsParsed(w))}catch(e){console.error("Error handling parsed SETTINGS callback:",e)}this.onSettings&&this.onSettings(e),this._notifyPeerSettings(),this._wakeWindowWaiters()}break;case u:if(this.onData&&this.onData(t.slice(9),e),(y=null!==(z=e.length)&&void 0!==z?z:0)>0)try{0!==e.streamId&&(S=I.createWindowUpdateFrame(e.streamId,y),this.writer.write(S)),E=I.createWindowUpdateFrame(0,y),this.writer.write(E)}catch(e){console.error("[HTTP2] Error sending window update:",e)}if((e.flags&v)===v)return null===(F=this.onEnd)||void 0===F||F.call(this),this._notifyEndOfStream(),[2];break;case l:if(this.onHeaders&&this.onHeaders(t.slice(9),e),(e.flags&v)===v)return null===(O=this.onEnd)||void 0===O||O.call(this),this._notifyEndOfStream(),[2];break;case g:try{T=this.handleWindowUpdateFrame(e,t),0===e.streamId?this.sendConnWindow+=T.windowSizeIncrement:(W=null!==(L=this.sendStreamWindows.get(e.streamId))&&void 0!==L?L:this.peerInitialStreamWindow,this.sendStreamWindows.set(e.streamId,W+T.windowSizeIncrement)),this._wakeWindowWaiters()}catch(e){}break;case f:this._handlePingFrame(e,t);break;case p:A=void 0;try{(k=t.subarray(9)).length>=8?(C=new DataView(k.buffer,k.byteOffset,k.byteLength),P=2147483647&C.getUint32(0,!1),x=C.getUint32(4,!1),A={lastStreamId:P,errorCode:x},console.warn("[HTTP2] GOAWAY received",A)):(console.warn("[HTTP2] GOAWAY received"),A={})}catch(e){}try{null===(D=this.onGoaway)||void 0===D||D.call(this,null!=A?A:{})}catch(e){console.error("Error during GOAWAY callback:",e)}try{null===(H=this.onEnd)||void 0===H||H.call(this)}catch(e){console.error("Error during GOAWAY onEnd callback:",e)}this._notifyEndOfStream();break;case h:null===(M=this.onEnd)||void 0===M||M.call(this),this._notifyEndOfStream();break;default:console.debug("Unknown frame type:",e.type)}return[2]})})},e.prototype._parseFrameHeader=function(e){return{length:e[0]<<16|e[1]<<8|e[2],type:e[3],flags:e[4],streamId:2147483647&(e[5]<<24|e[6]<<16|e[7]<<8|e[8]),payload:e.slice(0,9)}},e.prototype._handlePingFrame=function(e,t){if(8!==e.length)throw new Error("PING frame must have a length of 8 bytes");if(!(e.flags&m)){var r=I.createPongFrame(t.slice(9));try{this.writer.write(r)}catch(e){throw console.error("Error sending PONG frame:",e),e}}},e.prototype.waitForEndOfStream=function(e){var t=this;return new Promise(function(r,n){if(t.endFlag)r();else{var i={resolve:r,reject:n};t.endOfStreamWaiters.push(i);var a=e>0?setTimeout(function(){var e=t.endOfStreamWaiters.indexOf(i);e>=0&&t.endOfStreamWaiters.splice(e,1),n(new Error("End of stream timeout"))},e):null;i.resolve=function(){a&&clearTimeout(a),r()},i.reject=function(e){a&&clearTimeout(a),n(e)}}})},e.prototype._notifyEndOfStream=function(){this.endFlag=!0;for(var e=0,t=this.endOfStreamWaiters.splice(0);e<t.length;e++){var r=t[e];try{r.resolve()}catch(e){}}},e.prototype.parseWindowUpdateFrame=function(e,t){if(4!==t.length)throw new Error("WINDOW_UPDATE frame must have a length of 4 bytes");var r=new Uint8Array(e.slice(9)),n=(127&r[0])<<24|r[1]<<16|r[2]<<8|r[3];if(0===n)throw new Error("WINDOW_UPDATE increment must not be zero");return{windowSizeIncrement:n}},e.prototype.handleWindowUpdateFrame=function(e,t){try{var r=this.parseWindowUpdateFrame(t,e);return this.connectionWindowSize+=r.windowSizeIncrement,r}catch(e){throw console.error("Error handling WINDOW_UPDATE frame:",e),e}},e}();function O(){const e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}class L{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return void 0===this.buffer[this.top]&&(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){const e=this.buffer[this.btm];if(void 0!==e)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return void 0===this.buffer[this.btm]}}class D{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new L(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return null!=e?.byteLength?e.byteLength:1}push(e){if(null!=e?.value&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){const t=this.head;this.head=t.next=new L(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(void 0===e&&null!=this.tail.next){const t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return null!=e?.value&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}}class H extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}}function M(e={}){return function(e,t){t=t??{};let r,n,i,a=t.onEnd,o=new D,s=O();const c=async()=>{try{return o.isEmpty()?i?{done:!0}:await new Promise((t,i)=>{n=a=>{n=null,o.push(a);try{t(e(o))}catch(e){i(e)}return r}}):e(o)}finally{o.isEmpty()&&queueMicrotask(()=>{s.resolve(),s=O()})}},u=e=>null!=n?n(e):(o.push(e),r),l=e=>(o=new D,null!=n?n({error:e}):(o.push({error:e}),r)),h=e=>{if(i)return r;if(!0!==t?.objectMode&&null==e?.byteLength)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:e})},d=e=>i?r:(i=!0,null!=e?l(e):u({done:!0})),f=()=>(o=new D,d(),{done:!0}),p=e=>(d(e),{done:!0});if(r={[Symbol.asyncIterator](){return this},next:c,return:f,throw:p,push:h,end:d,get readableLength(){return o.size},onEmpty:async e=>{const t=e?.signal;if(t?.throwIfAborted(),o.isEmpty())return;let r,n;null!=t&&(r=new Promise((e,r)=>{n=()=>{r(new H)},t.addEventListener("abort",n)}));try{await Promise.race([s.promise,r])}finally{null!=n&&null!=t&&t?.removeEventListener("abort",n)}}},null==a)return r;const g=r;return r={[Symbol.asyncIterator](){return this},next:()=>g.next(),throw:e=>(g.throw(e),null!=a&&(a(e),a=void 0),{done:!0}),return:()=>(g.return(),null!=a&&(a(),a=void 0),{done:!0}),push:h,end:e=>(g.end(e),null!=a&&(a(e),a=void 0),r),get readableLength(){return g.readableLength},onEmpty:e=>g.onEmpty(e)},r}(e=>{const t=e.shift();if(null==t)return{done:!0};if(null!=t.error)throw t.error;return{done:!0===t.done,value:t.value}},e)}var U=4091,_=function(){function e(e,t){var r,n,i;if(void 0===t&&(t={}),this.stream=e,this.options=t,this.bytesWritten=0,this.abortController=new AbortController,this.backpressureHistory=[],this.isBackpressure=!1,this.writeQueue=[],this.isProcessingQueue=!1,this.lastBackpressureCheck=0,this.bytesDrained=0,this.lastDrainEventAt=0,this.stallStartAt=0,this.lastBytesDrainedSeen=0,this.lastBpWarnAt=0,this.isHandlingError=!1,this.drainWaiters=[],this.listeners=new Map,!e)throw new Error("StreamWriter requires a valid stream object");this.log={trace:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return console.debug.apply(console,function(e,t,r){if(r||2===arguments.length)for(var n,i=0,a=t.length;i<a;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}(["[StreamWriter]"],e,!1))}},this.options=t?{chunkSize:null!==(r=t.chunkSize)&&void 0!==r?r:U,bufferSize:null!==(n=t.bufferSize)&&void 0!==n?n:5242880,retries:null!==(i=t.retries)&&void 0!==i?i:3}:{chunkSize:U,bufferSize:5242880,retries:3},this.options.chunkSize&&this.options.chunkSize>U&&(this.options.chunkSize=U);var a=M({objectMode:!1});a._originalPush=a.push.bind(a),a._originalNext=a.next.bind(a),a._queueSize=0,Object.defineProperty(a,"push",{value:function(e){return a._queueSize+=e.byteLength,a._originalPush(e)},writable:!1,configurable:!1}),this.p=a,this.startPipeline(),this.startWatchdog()}return Object.defineProperty(e.prototype,"queueSize",{get:function(){return this.p._queueSize},enumerable:!1,configurable:!0}),e.prototype.getAverageQueueSize=function(){var e=Date.now(),t=this.queueSize;return e-this.lastBackpressureCheck>100&&(t>0&&(this.backpressureHistory.push(t),this.backpressureHistory.length>5&&this.backpressureHistory.shift()),this.lastBackpressureCheck=e),0===this.backpressureHistory.length?t:this.backpressureHistory.reduce(function(e,t){return e+t},0)/this.backpressureHistory.length},e.prototype.handleError=function(e){var t,r;if(!this.abortController.signal.aborted&&!this.isHandlingError){this.isHandlingError=!0,this.abort(e.message);try{this.dispatchEvent(new CustomEvent("error",{detail:e}))}catch(e){null===(r=null===(t=this.log)||void 0===t?void 0:t.trace)||void 0===r||r.call(t,"Error in error event handler:",e)}}},e.prototype.startPipeline=function(){var e=this;this.pipeToStream().catch(function(t){return e.handleError(t)})},e.prototype.pipeToStream=function(){return r(this,void 0,void 0,function(){var e,t,r,i,a,o,c,u,l,h,d,f,p,g,m;return n(this,function(n){switch(n.label){case 0:if(!this.stream)return null===(p=null===(f=this.log)||void 0===f?void 0:f.trace)||void 0===p||p.call(f,"Stream is null/undefined, cannot start pipeline"),[2];n.label=1;case 1:n.trys.push([1,10,11,16]),e=!0,t=s(this.createTransform()(this.p)),n.label=2;case 2:return[4,t.next()];case 3:if(r=n.sent(),u=r.done)return[3,9];if(d=r.value,e=!1,i=d,this.abortController.signal.aborted)return[3,9];n.label=4;case 4:return n.trys.push([4,7,,8]),this.stream.send(i)?[3,6]:[4,this.stream.onDrain({signal:this.abortController.signal})];case 5:n.sent(),n.label=6;case 6:return[3,8];case 7:if(a=n.sent(),o=(a instanceof Error?a.message:"").toLowerCase(),a instanceof Error&&"StreamStateError"===a.name||o.includes("closing")||o.includes("closed")||o.includes("write to a stream that is closed"))return null===(m=null===(g=this.log)||void 0===g?void 0:g.trace)||void 0===m||m.call(g,"Stream is closing/closed, stopping pipeline"),[3,9];throw a;case 8:return e=!0,[3,2];case 9:return[3,16];case 10:return c=n.sent(),l={error:c},[3,16];case 11:return n.trys.push([11,,14,15]),e||u||!(h=t.return)?[3,13]:[4,h.call(t)];case 12:n.sent(),n.label=13;case 13:return[3,15];case 14:if(l)throw l.error;return[7];case 15:return[7];case 16:return this.cleanup(),[2]}})})},e.prototype.createTransform=function(){var e=this;return function(t){return o(this,arguments,function(){var r,i,o,c,u,l,h,d,f,p,g,m,v,b;return n(this,function(n){switch(n.label){case 0:n.trys.push([0,7,8,13]),r=!0,i=s(t),n.label=1;case 1:return[4,a(i.next())];case 2:return o=n.sent(),(g=o.done)?[3,6]:(b=o.value,r=!1,[4,a(c=b)]);case 3:return[4,n.sent()];case 4:n.sent();try{if(null!=e.p._queueSize&&(e.p._queueSize=Math.max(0,e.p._queueSize-c.byteLength)),e.bytesDrained+=c.byteLength,(u=Date.now())-e.lastDrainEventAt>250&&(e.lastDrainEventAt=u,e.dispatchEvent(new CustomEvent("drain",{detail:{drained:e.bytesDrained,queueSize:e.queueSize}}))),e.drainWaiters.length>0)for(l=e.drainWaiters.splice(0),h=0,d=l;h<d.length;h++){f=d[h];try{f()}catch(e){}}e.lastBytesDrainedSeen=e.bytesDrained}catch(e){console.error("Error updating bytesDrained in StreamWriter transform",e)}n.label=5;case 5:return r=!0,[3,1];case 6:return[3,13];case 7:return p=n.sent(),m={error:p},[3,13];case 8:return n.trys.push([8,,11,12]),r||g||!(v=i.return)?[3,10]:[4,a(v.call(i))];case 9:n.sent(),n.label=10;case 10:return[3,12];case 11:if(m)throw m.error;return[7];case 12:return[7];case 13:return[2]}})})}},e.prototype.startWatchdog=function(e,t){var r=this;if(void 0===e&&(e=500),void 0===t&&(t=1500),!this.watchdogTimer){var n=function(){if(!r.abortController.signal.aborted){var i=.7*r.options.bufferSize,a=r.queueSize,o=Date.now();if(a>=i)if(r.lastBytesDrainedSeen===r.bytesDrained){if(r.stallStartAt||(r.stallStartAt=o),o-r.stallStartAt>=t){var s={queueSize:a,drained:r.bytesDrained,sinceMs:o-r.stallStartAt};setTimeout(function(){r.abortController.signal.aborted||r.dispatchEvent(new CustomEvent("stalled",{detail:s}))},0),r.stallStartAt=o}}else r.stallStartAt=0,r.lastBytesDrainedSeen=r.bytesDrained;else r.stallStartAt=0;r.watchdogTimer=setTimeout(n,e)}};this.watchdogTimer=setTimeout(n,e)}},e.prototype.write=function(e){return r(this,void 0,void 0,function(){var t=this;return n(this,function(i){return this.abortController.signal.aborted?[2,Promise.resolve()]:[2,new Promise(function(i,a){t.writeQueue.push(function(){return r(t,void 0,void 0,function(){var t,r;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),this.abortController.signal.aborted?(i(),[2]):[4,this.convertToBuffer(e)];case 1:return t=n.sent(),[4,this.writeChunks(t)];case 2:return n.sent(),i(),[3,4];case 3:return r=n.sent(),a(r),[3,4];case 4:return[2]}})})}),t.processQueue()})]})})},e.prototype.convertToBuffer=function(e){return r(this,void 0,void 0,function(){return n(this,function(t){return e instanceof Blob?[2,e.arrayBuffer()]:"string"==typeof e?[2,(new TextEncoder).encode(e).buffer]:e instanceof Uint8Array?[2,e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)]:[2,e]})})},e.prototype.writeChunks=function(e){return r(this,void 0,void 0,function(){var t,r,i,a;return n(this,function(n){switch(n.label){case 0:t=new Uint8Array(e),r=0,n.label=1;case 1:return r<t.byteLength?(i=Math.min(r+this.options.chunkSize,t.byteLength),a=t.subarray(r,i),[4,this.retryableWrite(a)]):[3,4];case 2:n.sent(),this.updateProgress(a.byteLength),n.label=3;case 3:return r+=this.options.chunkSize,[3,1];case 4:return[2]}})})},e.prototype.retryableWrite=function(e){return r(this,arguments,void 0,function(e,t){var r,i,a,o;return void 0===t&&(t=0),n(this,function(n){switch(n.label){case 0:if(this.abortController.signal.aborted)throw new Error("Stream is aborted, cannot write");n.label=1;case 1:return n.trys.push([1,4,,7]),r=this.queueSize,i=.7*this.options.bufferSize,r>i?[4,this.monitorBackpressure()]:[3,3];case 2:n.sent(),n.label=3;case 3:if(this.abortController.signal.aborted)throw new Error("Stream aborted during backpressure monitoring");return this.p.push(e),[3,7];case 4:return a=n.sent(),!this.abortController.signal.aborted&&t<this.options.retries?(o=this.calculateRetryDelay(t),[4,new Promise(function(e){return setTimeout(e,o)})]):[3,6];case 5:return n.sent(),[2,this.retryableWrite(e,t+1)];case 6:throw a;case 7:return[2]}})})},e.prototype.monitorBackpressure=function(){return r(this,void 0,void 0,function(){var e,t,r,i,a,o,s,c=this;return n(this,function(u){switch(u.label){case 0:if(e=.7*this.options.bufferSize,t=.9*this.options.bufferSize,this.queueSize<e)return this.isBackpressure&&(this.isBackpressure=!1,this.dispatchBackpressureEvent({currentSize:this.queueSize,averageSize:this.getAverageQueueSize(),threshold:e,waitingTime:0})),[2];this.isBackpressure||(this.isBackpressure=!0,this.dispatchBackpressureEvent({currentSize:this.queueSize,averageSize:this.getAverageQueueSize(),threshold:e,waitingTime:0})),r=3,i=function(r){var i,o;return n(this,function(r){switch(r.label){case 0:return a.abortController.signal.aborted||a.queueSize<e?[2,"break"]:(i=a.queueSize>=t,o=i?100:30,[4,new Promise(function(e){var t=!1,r=setTimeout(function(){t||(t=!0,e())},o);c.drainWaiters.push(function(){t||(t=!0,clearTimeout(r),e())})})]);case 1:return r.sent(),[2]}})},a=this,o=0,u.label=1;case 1:return o<r?[5,i(o)]:[3,4];case 2:if("break"===u.sent())return[3,4];u.label=3;case 3:return o++,[3,1];case 4:return this.queueSize>=e&&(s=Date.now())-this.lastBpWarnAt>1e3&&(this.lastBpWarnAt=s,console.warn("Stream writer: High backpressure detected (".concat(this.queueSize," bytes), continuing anyway"))),[2]}})})},e.prototype.calculateRetryDelay=function(e){return Math.min(10*Math.pow(2,e)+100*Math.random(),100)},e.prototype.processQueue=function(){return r(this,void 0,void 0,function(){var e,t;return n(this,function(r){switch(r.label){case 0:if(this.isProcessingQueue||this.abortController.signal.aborted)return[2];this.isProcessingQueue=!0,r.label=1;case 1:return this.writeQueue.length>0?this.abortController.signal.aborted?[3,5]:(e=this.queueSize,t=.5*this.options.bufferSize,e>t?[4,this.monitorBackpressure()]:[3,3]):[3,5];case 2:r.sent(),r.label=3;case 3:return[4,this.writeQueue.shift()()];case 4:return r.sent(),[3,1];case 5:return this.isProcessingQueue=!1,[2]}})})},e.prototype.updateProgress=function(e){this.bytesWritten+=e,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:this.bytesWritten}}))},e.prototype.end=function(){return r(this,void 0,void 0,function(){var e,t,r,i;return n(this,function(n){switch(n.label){case 0:if(this.p.end(),!this.stream||"function"!=typeof this.stream.close)return[3,4];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.stream.close()];case 2:return n.sent(),[3,4];case 3:return e=n.sent(),(t=(e instanceof Error?e.message:"").toLowerCase()).includes("closed")||t.includes("closing")||null===(i=null===(r=this.log)||void 0===r?void 0:r.trace)||void 0===i||i.call(r,"Stream close error:",e),[3,4];case 4:return this.cleanup(),[2]}})})},e.prototype.abort=function(e){var t,r,n,i;if(void 0===e&&(e="User aborted"),!this.abortController.signal.aborted){this.abortController.abort(e);try{if(this.stream&&"function"==typeof this.stream.abort){var a=this.stream.status||this.stream.state;"closed"!==a&&"closing"!==a&&this.stream.abort(new Error(e))}}catch(e){var o=(e instanceof Error?e.message:"").toLowerCase();o.includes("closed")||o.includes("closing")||o.includes("write")||null===(r=null===(t=this.log)||void 0===t?void 0:t.trace)||void 0===r||r.call(t,"Stream abort error:",e)}this.cleanup();try{this.dispatchEvent(new CustomEvent("abort",{detail:e}))}catch(e){null===(i=null===(n=this.log)||void 0===n?void 0:n.trace)||void 0===i||i.call(n,"Error in abort event handler:",e)}}},e.prototype.cleanup=function(){this.abortController.signal.aborted||this.abortController.abort();for(var e=0,t=this.writeQueue.splice(0);e<t.length;e++){(0,t[e])().catch(function(){})}for(var r=0,n=this.drainWaiters.splice(0);r<n.length;r++){var i=n[r];try{i()}catch(e){}}try{this.p.end()}catch(e){}this.watchdogTimer&&(clearTimeout(this.watchdogTimer),this.watchdogTimer=void 0)},e.prototype.flush=function(){return r(this,arguments,void 0,function(e){var t=this;return void 0===e&&(e=1e4),n(this,function(r){switch(r.label){case 0:return this.queueSize<=0&&!this.isProcessingQueue&&0===this.writeQueue.length||this.abortController.signal.aborted?[2]:[4,new Promise(function(r){if(t.queueSize<=0&&!t.isProcessingQueue&&0===t.writeQueue.length)r();else{var n=!1,i=setTimeout(function(){n||(n=!0,console.warn("Stream writer: flush timeout with ".concat(t.queueSize," bytes still queued")),r())},e),a=function(){t.abortController.signal.aborted||t.queueSize<=0&&!t.isProcessingQueue&&0===t.writeQueue.length?n||(n=!0,clearTimeout(i),r()):t.drainWaiters.push(a)};t.drainWaiters.push(a)}})];case 1:return r.sent(),[2]}})})},e.prototype.addEventListener=function(e,t){var r=this.listeners.get(e)||[];r.push(t),this.listeners.set(e,r)},e.prototype.dispatchEvent=function(e){(this.listeners.get(e.type)||[]).forEach(function(t){return t(e)})},e.prototype.dispatchBackpressureEvent=function(e){this.dispatchEvent(new CustomEvent("backpressure",{detail:e}))},e}(),j=15e3,q=function(){function e(){this.streamIdLock=Promise.resolve(),this.currentStreamId=1}return e.prototype.getNextAppLevelStreamId=function(){return r(this,void 0,void 0,function(){var e=this;return n(this,function(t){return[2,new Promise(function(t){e.streamIdLock=e.streamIdLock.then(function(){var r=e.currentStreamId;e.currentStreamId+=2,t(r)})})]})})},e}(),B=function(){function e(e,t,r,n){this.node=e,this.peerAddr=t,this.protocol=n||"/dc/thread/0.0.1",this.token=r,this.connectionStreamManagers=new WeakMap,this.connectionStates=new WeakMap,this.connectionPool=new Map}return e.prototype.getStreamManagerFor=function(e){var t=this.connectionStreamManagers.get(e);return t||(t=new q,this.connectionStreamManagers.set(e,t)),t},e.prototype.getConnectionState=function(e){var t=this.connectionStates.get(e);return t||(t={activeStreams:0,maxConcurrentStreams:Number.POSITIVE_INFINITY,waiters:[]},this.connectionStates.set(e,t)),t},e.prototype.notifyStreamSlotAvailable=function(e){if(0!==e.waiters.length)for(;e.waiters.length>0&&e.activeStreams<e.maxConcurrentStreams;){var t=e.waiters.shift();if(!t)break;try{t.resolve()}catch(e){console.error("Error resolving stream waiter:",e)}}},e.prototype.rejectStreamWaiters=function(e,t){if(0!==e.waiters.length)for(var r=0,n=e.waiters.splice(0);r<n.length;r++){var i=n[r];try{i.reject(t)}catch(e){console.error("Error rejecting stream waiter:",e)}}},e.prototype.waitForStreamSlot=function(e,t){return r(this,arguments,void 0,function(e,t,r){return void 0===r&&(r=5e3),n(this,function(n){switch(n.label){case 0:if(e.maxConcurrentStreams<=0)throw new Error("No available HTTP/2 streams: server advertised zero concurrent streams");return!Number.isFinite(e.maxConcurrentStreams)||e.activeStreams<e.maxConcurrentStreams?[2]:[4,new Promise(function(n,i){var a,o=!1,s=function(){var r=e.waiters.indexOf(c);r>=0&&e.waiters.splice(r,1),a&&clearTimeout(a),t&&t.removeEventListener("abort",u)},c={resolve:function(){o||(o=!0,s(),n())},reject:function(e){o||(o=!0,s(),i(e))}},u=function(){c.reject(new Error("Aborted while waiting for available HTTP/2 stream slot"))};if(t){if(t.aborted)return void u();t.addEventListener("abort",u,{once:!0})}a=r>0?setTimeout(function(){c.reject(new Error("Timed out waiting for available HTTP/2 stream slot"))},r):void 0,e.waiters.push(c)})];case 1:return n.sent(),[2]}})})},e.prototype.sendFrameWithFlowControl=function(e,t,i,a,o){return r(this,arguments,void 0,function(e,t,r,i,a,o){var s,c,u,l,h,d,f;return void 0===o&&(o=j),n(this,function(n){switch(n.label){case 0:if(null==a?void 0:a.aborted)throw new Error("Operation aborted");if(!((s=Math.max(0,r.length-9))>0))return[3,4];c=e.getSendWindows(t),u=c.conn,l=c.stream,(u<s||l<s)&&console.debug("[stream ".concat(t,"] waiting for send window: need=").concat(s," conn=").concat(u," stream=").concat(l)),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,e.waitForSendWindow(t,s,o)];case 2:return n.sent(),[3,4];case 3:return h=n.sent(),console.warn("[stream ".concat(t,"] send window wait failed (").concat(null!==(f=null==h?void 0:h.message)&&void 0!==f?f:h,"); continuing best-effort")),d=Math.max(s,262144),e.unsafeForceExtendSendWindow(t,d),[3,4];case 4:if(null==a?void 0:a.aborted)throw new Error("Operation aborted");return[4,i.write(r)];case 5:return n.sent(),s>0&&e.consumeSendWindow(t,s),[2]}})})},e.prototype.acquireConnection=function(e){return r(this,void 0,void 0,function(){var t,i,a,o,s,c=this;return n(this,function(u){if(t=this.peerAddr.toString(),!e&&(i=this.connectionPool.get(t))){if(!(a=i.connection))return[2,i.promise];if(!(o=a.status)||"open"===o)return[2,a];this.connectionPool.delete(t)}return s=this.node.dial(this.peerAddr,{signal:AbortSignal.timeout(5e3)}).then(function(i){return r(c,void 0,void 0,function(){var r,a,o=this;return n(this,function(n){if(!e&&(r=this.connectionPool.get(t))&&r.promise===s){r.connection=i,a=function(){var e=o.connectionPool.get(t);e&&e.promise===s&&o.connectionPool.delete(t)};try{i.addEventListener("close",a,{once:!0})}catch(e){}}return[2,i]})})}).catch(function(r){if(!e){var n=c.connectionPool.get(t);n&&n.promise===s&&c.connectionPool.delete(t)}throw r}),e||this.connectionPool.set(t,{promise:s}),[2,s]})})},e.prototype.getDefaultTransportProfile=function(e){return"server-streaming"===e?"compatibility":"flow-control"},e.prototype.setToken=function(e){this.token=e},e.prototype.getAuthority=function(){try{var e=this.peerAddr.toString(),t=e.match(/\/ip4\/(\d[\d.]+)\/tcp\/(\d+)/);if(t)return"".concat(t[1],":").concat(t[2]);var r=e.match(/\/ip6\/([^/]+)\/tcp\/(\d+)/);if(r)return"[".concat(r[1],"]:").concat(r[2]);var n=e.match(/\/dns(?:4|6)?\/([.\w-]+)\/tcp\/(\d+)/);if(n)return"".concat(n[1],":").concat(n[2])}catch(e){}return"localhost"},e.prototype.unaryCall=function(e,t){return r(this,arguments,void 0,function(e,t,r){var i,a,o,s,c,u,l,h,d,f,p,g,m,v,w,y,S,E,T,W,A,k,C,P,x,z,O,L,D=this;return void 0===r&&(r=3e4),n(this,function(n){switch(n.label){case 0:i=null,a=null,o=[],s=-1,c=[],u=new b,l=!1,h="",d=!1,f=null,p=null,g=null,m=!1,v=null,n.label=1;case 1:return n.trys.push([1,23,24,29]),[4,this.acquireConnection(!1)];case 2:p=n.sent(),w=this.peerAddr.toString(),g=this.getConnectionState(p),n.label=3;case 3:return n.trys.push([3,5,,6]),[4,this.waitForStreamSlot(g,void 0,r)];case 4:return n.sent(),g.activeStreams+=1,m=!0,[3,6];case 5:throw y=n.sent(),console.warn("[unaryCall] waiting for stream slot failed:",y),y;case 6:return[4,p.newStream(this.protocol,{maxOutboundStreams:10,negotiateFully:!1})];case 7:return i=n.sent(),[4,this.getStreamManagerFor(p).getNextAppLevelStreamId()];case 8:S=n.sent(),E=new _(i,{bufferSize:16777216}),v=E;try{E.addEventListener("backpressure",function(e){var t=e.detail||{};console.warn("[unary stream ".concat(S,"] backpressure current=").concat(t.currentSize," avg=").concat(t.averageSize," threshold=").concat(t.threshold))}),E.addEventListener("drain",function(){}),E.addEventListener("stalled",function(e){var t,r=e.detail||{};console.warn("[unary stream ".concat(S,"] stalled queue=").concat(r.queueSize," drained=").concat(r.drained," since=").concat(r.sinceMs,"ms — sending PING"));try{var n=new Uint8Array(8);null===(t=crypto.getRandomValues)||void 0===t||t.call(crypto,n);var i=I.createFrame(6,0,0,n);E.write(i)}catch(e){}})}catch(e){}return(T=new F(E)).onGoaway=function(e){console.warn("[unaryCall] GOAWAY received from server",e),D.connectionPool.delete(w),g&&D.rejectStreamWaiters(g,new Error("Connection received GOAWAY")),l=!0,h="GOAWAY received: code=".concat(e.errorCode),null==f||f();try{null==p||p.close()}catch(e){console.warn("Error closing connection after GOAWAY:",e)}},T.onSettingsParsed=function(e){g&&void 0!==e.maxConcurrentStreams&&e.maxConcurrentStreams>0&&(g.maxConcurrentStreams=e.maxConcurrentStreams,D.notifyStreamSlotAvailable(g))},T.registerOutboundStream(S),s=-1,o=[],c=[],T.onData=function(e,t){if(-1===s){var r=e;if(c.length>0){c.push(e);var n=c.reduce(function(e,t){return e+t.length},0);r=new Uint8Array(n);for(var i=0,u=0,l=c;u<l.length;u++){var h=l[u];r.set(h,i),i+=h.length}c=[]}if(r.length<5)return void c.push(r);var p=r.slice(1,5);if((s=new DataView(p.buffer,p.byteOffset).getUint32(0,!1))+5>r.length){var g=r.subarray(5);return o.push(g),void(s-=g.length)}var m=s;g=r.slice(5,5+m);o.push(g),a=g,d=!0,s=-1,null==f||f()}else if(s>0)if((s-=e.length)<=0){var v=s<0?e.slice(0,e.length+s):e;o.push(v),a=new Uint8Array(o.reduce(function(e,t){return e+t.length},0));for(var b=0,w=0,y=o;w<y.length;w++){var S=y[w];a.set(S,b),b+=S.length}s=-1,d=!0,null==f||f()}else o.push(e);if(t&&1&t.flags&&!d){if(o.length>0){var E=o.reduce(function(e,t){return e+t.length},0);a=new Uint8Array(E);b=0;for(var T=0,W=o;T<W.length;T++){S=W[T];a.set(S,b),b+=S.length}}else a=new Uint8Array(0);d=!0,null==f||f()}},T.onEnd=function(){d||(d=!0,null==f||f())},T.onSettings=function(){var e=I.createSettingsAckFrame();E.write(e)},T.onHeaders=function(e){var t=u.decodeHeaderFields(e);"0"===t.get("grpc-status")||void 0!==t.get("grpc-status")&&(l=!0,h=t.get("grpc-message")||"gRPC call failed",null==f||f())},T.processStream(i).catch(function(e){d||(console.error("Error in processStream:",e),l=!0,h||(h=e instanceof Error?e.message:"Stream processing failed"),null==f||f())}),W=I.createPreface(),[4,E.write(W)];case 9:return n.sent(),A=I.createSettingsFrame(),[4,E.write(A)];case 10:return n.sent(),[4,Promise.race([T.waitForPeerSettings(1e3).catch(function(){}),T.waitForSettingsAck().catch(function(){}),new Promise(function(e){return setTimeout(e,300)})])];case 11:return n.sent(),k=I.createHeadersFrame(S,e,!0,this.token,this.getAuthority()),[4,E.write(k)];case 12:n.sent(),C=I.createDataFrames(S,t,!0),P=r>0?r:j,x=0,z=C,n.label=13;case 13:return x<z.length?(O=z[x],[4,this.sendFrameWithFlowControl(T,S,O,E,void 0,P)]):[3,16];case 14:n.sent(),n.label=15;case 15:return x++,[3,13];case 16:return[4,new Promise(function(e,t){if(d||l)e();else{var n=setTimeout(function(){f=null,t(new Error("gRPC response timeout"))},r);f=function(){clearTimeout(n),f=null,e()}}})];case 17:n.sent(),n.label=18;case 18:return n.trys.push([18,20,,21]),[4,E.flush(r)];case 19:case 20:return n.sent(),[3,21];case 21:return[4,E.end()];case 22:return n.sent(),[3,29];case 23:throw L=n.sent(),console.error("unaryCall error:",L),L;case 24:if(null==v||v.abort("unaryCall cleanup"),!i)return[3,28];n.label=25;case 25:return n.trys.push([25,27,,28]),[4,i.close()];case 26:case 27:return n.sent(),[3,28];case 28:return m&&g&&(g.activeStreams=Math.max(0,g.activeStreams-1),this.notifyStreamSlotAvailable(g)),[7];case 29:if(l)throw new Error(h);return a||(a=new Uint8Array),[2,a]}})})},e.prototype.Call=function(e,t){return r(this,arguments,void 0,function(e,t,i,a,o,c,u,l,h,d){var f,p,g,m,v,w,y,S,E,T,W,A=this;return void 0===i&&(i=3e4),n(this,function(k){switch(k.label){case 0:if(f=new AbortController,g=null,v=null!==(W=null==d?void 0:d.transportProfile)&&void 0!==W?W:this.getDefaultTransportProfile(a),w="flow-control"===v,y=function(){if(f.abort(),p&&clearTimeout(p),g)try{g.close()}catch(e){console.error("Error closing stream on cancel:",e)}},null==h?void 0:h.signal){if(h.signal.aborted)return l&&l(new Error("Operation aborted by context")),[2,y];m=function(){y()},h.signal.addEventListener("abort",m)}S=new Promise(function(e,t){p=setTimeout(function(){t(new Error("Operation timed out")),y()},i)}),E=r(A,void 0,void 0,function(){var v,y,S,E,T,W,A,k,C,P,x,z,O,L,D,H,M,U,q,B,G,N,R,Q,Y,V,Z,K,X,J,$,ee,te,re,ne,ie,ae,oe,se,ce,ue,le,he,de,fe,pe,ge,me,ve,be,we,ye,Se=this;return n(this,function(Ee){switch(Ee.label){case 0:v=!1,y=function(e){v||(v=!0,f.abort(),l&&l(e))},S=[],E=0,T=-1,W=function(){if(0===S.length)return new Uint8Array(0);if(1===S.length)return S[0];for(var e=new Uint8Array(E),t=0,r=0,n=S;r<n.length;r++){var i=n[r];e.set(i,t),t+=i.length}return e},A=new b,k=null,C=null,P=null,x=!1,z=null,Ee.label=1;case 1:if(Ee.trys.push([1,49,50,64]),f.signal.aborted)throw new Error("Operation aborted");if(!(null==d?void 0:d.freshConnection))return[3,5];Ee.label=2;case 2:return Ee.trys.push([2,4,,5]),this.connectionPool.delete(this.peerAddr.toString()),[4,this.node.hangUp(this.peerAddr)];case 3:return Ee.sent(),console.warn("[Call] hangUp existing connection before dialing due to freshConnection=true"),[3,5];case 4:return O=Ee.sent(),console.warn("[Call] hangUp failed or not supported, proceeding to dial",O),[3,5];case 5:return[4,this.acquireConnection(Boolean(null==d?void 0:d.freshConnection))];case 6:if(k=Ee.sent(),C=this.peerAddr.toString(),!(P=this.getConnectionState(k)))return[3,10];Ee.label=7;case 7:return Ee.trys.push([7,9,,10]),[4,this.waitForStreamSlot(P,f.signal,i)];case 8:return Ee.sent(),P.activeStreams+=1,x=!0,[3,10];case 9:throw L=Ee.sent(),console.warn("[Call] waiting for stream slot failed:",L),L;case 10:return[4,k.newStream(this.protocol,{maxOutboundStreams:50,signal:AbortSignal.timeout(1e4),negotiateFully:!1})];case 11:return g=Ee.sent(),[4,this.getStreamManagerFor(k).getNextAppLevelStreamId()];case 12:D=Ee.sent(),z=new _(g,{bufferSize:16777216});try{z.addEventListener("backpressure",function(e){var t=e.detail||{};console.warn("[stream ".concat(D,"] backpressure current=").concat(t.currentSize," avg=").concat(t.averageSize," threshold=").concat(t.threshold))}),z.addEventListener("drain",function(){}),z.addEventListener("stalled",function(e){var t,r=e.detail||{};console.warn("[stream ".concat(D,"] stalled queue=").concat(r.queueSize," drained=").concat(r.drained," since=").concat(r.sinceMs,"ms — sending PING"));try{var n=new Uint8Array(8);null===(t=crypto.getRandomValues)||void 0===t||t.call(crypto,n);var i=I.createFrame(6,0,0,n);z.write(i)}catch(e){}})}catch(e){}if((H=new F(z,{compatibilityMode:!w})).onGoaway=function(e){console.warn("[Call] GOAWAY received from server",e),C&&Se.connectionPool.delete(C),P&&Se.rejectStreamWaiters(P,new Error("Connection received GOAWAY")),y(new Error("GOAWAY received: code=".concat(e.errorCode)));try{null==k||k.close()}catch(e){console.warn("Error closing connection after GOAWAY:",e)}},H.onSettingsParsed=function(e){P&&void 0!==e.maxConcurrentStreams&&e.maxConcurrentStreams>0&&(P.maxConcurrentStreams=e.maxConcurrentStreams,Se.notifyStreamSlotAvailable(P))},w&&H.registerOutboundStream(D),M=i>0?i:j,U=function(e){return r(Se,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return w?[4,this.sendFrameWithFlowControl(H,D,e,z,f.signal,M)]:[3,2];case 1:return t.sent(),[3,4];case 2:if(f.signal.aborted)throw new Error("Operation aborted");return[4,z.write(e)];case 3:t.sent(),t.label=4;case 4:return[2]}})})},q=function(e){return r(Se,void 0,void 0,function(){var t,r,i;return n(this,function(n){switch(n.label){case 0:t=0,r=e,n.label=1;case 1:return t<r.length?(i=r[t],[4,U(i)]):[3,4];case 2:n.sent(),n.label=3;case 3:return t++,[3,1];case 4:return[2]}})})},H.onData=function(e){return r(Se,void 0,void 0,function(){var t,r,i,a;return n(this,function(n){if(f.signal.aborted)return[2];try{for(S.push(e),E+=e.length;E>0;){if(f.signal.aborted)return[2];if(-1===T&&E>=5&&(r=W(),S=[r],t=r.slice(1,5),T=new DataView(t.buffer,t.byteOffset).getUint32(0,!1)),!(-1!==T&&E>=T+5))break;r=W(),S=[r],i=r.slice(5,T+5),o(i),a=r.slice(T+5),S=a.length>0?[a]:[],E=a.length,T=-1}}catch(e){y(e)}return[2]})})},H.onSettings=function(){if(!f.signal.aborted){var e=I.createSettingsAckFrame();z.write(e)}},H.onHeaders=function(e){if(!f.signal.aborted){var t=A.decodeHeaderFields(e);if("0"===t.get("grpc-status"));else if(void 0!==t.get("grpc-status")){var r=t.get("grpc-message")||"gRPC call failed";y(new Error(r))}}},H.processStream(g).catch(function(e){f.signal.aborted||(console.error("Error in processStream:",e),y(e))}),f.signal.aborted)throw new Error("Operation aborted");return B=I.createPreface(),[4,z.write(B)];case 13:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return G=I.createSettingsFrame(),[4,z.write(G)];case 14:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return[4,Promise.race([H.waitForPeerSettings(1e3).catch(function(){}),H.waitForSettingsAck().catch(function(){}),new Promise(function(e){return setTimeout(e,300)})])];case 15:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return N=I.createHeadersFrame(D,e,!0,this.token,this.getAuthority()),"unary"!==a&&"server-streaming"!==a?[3,18]:[4,z.write(N)];case 16:return Ee.sent(),R=I.createDataFrames(D,t,!0),[4,q(R)];case 17:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return[3,45];case 18:return"client-streaming"!==a&&"bidirectional"!==a||!c?[3,45]:[4,z.write(N)];case 19:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return t.length>0?(Q=I.createDataFrames(D,t,!1),[4,q(Q)]):[3,21];case 20:Ee.sent(),Ee.label=21;case 21:Y=(null==d?void 0:d.batchSize)||10,V=[],Z=[],K=!1,X=function(){for(var e=0,t=Z.splice(0);e<t.length;e++){var r=t[e];try{r()}catch(e){}}},J=function(){return r(Se,void 0,void 0,function(){var e,t,r,i,a,o,s;return n(this,function(n){switch(n.label){case 0:if(K||0===V.length)return[2];K=!0,e=[],n.label=1;case 1:if(n.trys.push([1,9,10,11]),!((e=V.splice(0,Math.min(Y,V.length))).length>1))return[3,6];t=0,r=e,n.label=2;case 2:if(!(t<r.length))return[3,5];if(a=r[t],f.signal.aborted)throw new Error("Operation aborted");return i=I.createDataFrames(D,a.chunk,!1),[4,q(i)];case 3:n.sent(),n.label=4;case 4:return t++,[3,2];case 5:return e.forEach(function(e){return e.resolve()}),[3,8];case 6:return 1!==e.length?[3,8]:(a=e[0],o=I.createDataFrames(D,a.chunk,!1),[4,q(o)]);case 7:n.sent(),a.resolve(),n.label=8;case 8:return[3,11];case 9:return s=n.sent(),e.forEach(function(e){try{e.reject(s)}catch(e){console.warn("Error rejecting promise:",e)}}),[3,11];case 10:return K=!1,V.length>0&&!f.signal.aborted?J().catch(function(e){console.error("Error in processNextBatch:",e)}):X(),[7];case 11:return[2]}})})},$=function(e){return new Promise(function(t,r){f.signal.aborted?r(new Error("Operation aborted")):(V.push({chunk:e,resolve:t,reject:r}),(V.length>=Y||!K)&&J().catch(function(e){console.error("Error in processNextBatch:",e)}))})},Ee.label=22;case 22:Ee.trys.push([22,36,,37]),Ee.label=23;case 23:Ee.trys.push([23,29,30,35]),ee=!0,te=s(c()),Ee.label=24;case 24:return[4,te.next()];case 25:if(re=Ee.sent(),pe=re.done)return[3,28];if(ve=re.value,ee=!1,ne=ve,f.signal.aborted)throw new Error("Operation aborted");return ie=Array.isArray(ne)?ne:[ne],ae=ie.map(function(e){return $(e)}),[4,Promise.all(ae)];case 26:Ee.sent(),Ee.label=27;case 27:return ee=!0,[3,24];case 28:return[3,35];case 29:return oe=Ee.sent(),ge={error:oe},[3,35];case 30:return Ee.trys.push([30,,33,34]),ee||pe||!(me=te.return)?[3,32]:[4,me.call(te)];case 31:Ee.sent(),Ee.label=32;case 32:return[3,34];case 33:if(ge)throw ge.error;return[7];case 34:return[7];case 35:return[3,37];case 36:throw se=Ee.sent(),V.splice(0).forEach(function(e){try{e.reject(se)}catch(e){console.warn("Error rejecting remaining promise:",e)}}),se;case 37:return[4,new Promise(function(e,t){var r=function(){f.signal.aborted?t(new Error("Operation aborted")):0!==V.length||K?Z.push(r):e()};r()})];case 38:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return ce=I.createFrame(0,1,D,new Uint8Array(0)),[4,U(ce)];case 39:Ee.sent(),Ee.label=40;case 40:return Ee.trys.push([40,42,,43]),[4,z.flush(i)];case 41:case 42:return Ee.sent(),[3,43];case 43:return[4,z.end()];case 44:Ee.sent(),Ee.label=45;case 45:if(f.signal.aborted)throw new Error("Operation aborted");return f.signal.aborted?[3,48]:[4,H.waitForEndOfStream(0)];case 46:return Ee.sent(),[4,Promise.resolve()];case 47:Ee.sent(),!f.signal.aborted&&u&&u(),Ee.label=48;case 48:return[3,64];case 49:return ue=Ee.sent(),f.signal.aborted&&ue instanceof Error&&"Operation aborted"===ue.message?!v&&l&&l(new Error("Operation cancelled by user")):!v&&l?l(ue):v||(ue instanceof Error?console.error("asyncCall error:",ue.message):console.error("asyncCall error:",ue)),[3,64];case 50:if(clearTimeout(p),m&&(null==h?void 0:h.signal)&&h.signal.removeEventListener("abort",m),f.abort(),null==z||z.abort("Call cleanup"),!g)return[3,54];Ee.label=51;case 51:return Ee.trys.push([51,53,,54]),[4,g.close()];case 52:case 53:return Ee.sent(),[3,54];case 54:if(!(null==d?void 0:d.freshConnection))return[3,63];Ee.label=55;case 55:Ee.trys.push([55,62,,63]),le=(null===(we=(be=this.node).getConnections)||void 0===we?void 0:we.call(be,this.peerAddr))||[],he=0,de=le,Ee.label=56;case 56:if(!(he<de.length))return[3,61];fe=de[he],Ee.label=57;case 57:return Ee.trys.push([57,59,,60]),[4,null===(ye=fe.close)||void 0===ye?void 0:ye.call(fe)];case 58:case 59:return Ee.sent(),[3,60];case 60:return he++,[3,56];case 61:return[3,63];case 62:return Ee.sent(),[3,63];case 63:return x&&P&&(P.activeStreams=Math.max(0,P.activeStreams-1),this.notifyStreamSlotAvailable(P)),[7];case 64:return[2]}})}),k.label=1;case 1:return k.trys.push([1,3,,4]),[4,Promise.race([E,S])];case 2:return k.sent(),[2,y];case 3:throw T=k.sent(),y(),T;case 4:return[2]}})})},e}();e.Libp2pGrpcClient=B});//# sourceMappingURL=grpc.min.js.map
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GrpcLibp2pClient={})}(this,function(e){"use strict";"undefined"!=typeof window&&window;var t=function(){return t=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},t.apply(this,arguments)};function r(e,t,r,n){return new(r||(r=Promise))(function(i,a){function o(e){try{c(n.next(e))}catch(e){a(e)}}function s(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,s)}c((n=n.apply(e,t||[])).next())})}function n(e,t){var r,n,i,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}function i(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(e){return this instanceof a?(this.v=e,this):new a(e)}function o(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(e,t||[]),o=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",function(e){return function(t){return Promise.resolve(t).then(e,l)}}),n[Symbol.asyncIterator]=function(){return this},n;function s(e,t){i[e]&&(n[e]=function(t){return new Promise(function(r,n){o.push([e,t,r,n])>1||c(e,t)})},t&&(n[e]=t(n[e])))}function c(e,t){try{(r=i[e](t)).value instanceof a?Promise.resolve(r.value.v).then(u,l):h(o[0][2],r)}catch(e){h(o[0][3],e)}var r}function u(e){c("next",e)}function l(e){c("throw",e)}function h(e,t){e(t),o.shift(),o.length&&c(o[0][0],o[0][1])}}function s(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=i(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise(function(n,i){(function(e,t,r,n){Promise.resolve(n).then(function(t){e({value:t,done:r})},t)})(n,i,(t=e[r](t)).done,t.value)})}}}"function"==typeof SuppressedError&&SuppressedError;var c,u=0,l=1,h=3,d=4,f=6,p=7,g=8,m=1,v=1,b=function(){function e(e){void 0===e&&(e=4096),this.dynamicTable=[],this.dynamicTableSize=0,this.maxDynamicTableSize=e,this.staticTable=[["",""],[":authority",""],[":method","GET"],[":method","POST"],[":path","/"],[":path","/index.html"],[":scheme","http"],[":scheme","https"],[":status","200"],[":status","204"],[":status","206"],[":status","304"],[":status","400"],[":status","404"],[":status","500"],["accept-charset",""],["accept-encoding","gzip, deflate"],["accept-language",""],["accept-ranges",""],["accept",""],["access-control-allow-origin",""],["age",""],["allow",""],["authorization",""],["cache-control",""],["content-disposition",""],["content-encoding",""],["content-language",""],["content-length",""],["content-location",""],["content-range",""],["content-type",""],["cookie",""],["date",""],["etag",""],["expect",""],["expires",""],["from",""],["host",""],["if-match",""],["if-modified-since",""],["if-none-match",""],["if-range",""],["if-unmodified-since",""],["last-modified",""],["link",""],["location",""],["max-forwards",""],["proxy-authenticate",""],["proxy-authorization",""],["range",""],["referer",""],["refresh",""],["retry-after",""],["server",""],["set-cookie",""],["strict-transport-security",""],["transfer-encoding",""],["user-agent",""],["vary",""],["via",""],["www-authenticate",""]],this.huffmanTable=this.buildHuffmanTable()}return e.prototype.encode=function(e){for(var t=[],r=0,n=Object.entries(e);r<n.length;r++){var i=n[r],a=i[0],o=i[1],s=this.findInStaticTable(a,o);if(-1===s){var c=this.findInDynamicTable(a,o);-1===c?this.encodeLiteral(t,a,o):t.push.apply(t,this.encodeInteger(c+this.staticTable.length,7,128))}else t.push.apply(t,this.encodeInteger(s,7,128))}return new Uint8Array(t)},e.prototype.encodeInteger=function(e,t,r){void 0===r&&(r=0);var n=[],i=(1<<t)-1;if(e<i)return n.push(r|e),n;for(n.push(r|i),e-=i;e>=128;)n.push(127&e|128),e>>=7;return n.push(e),n},e.prototype.encodeString=function(e){var t=[],r=(new TextEncoder).encode(e),n=this.huffmanEncode(r);return n.length<r.length?(t.push.apply(t,this.encodeInteger(n.length,7,128)),Array.from(n).forEach(function(e){return t.push(e)})):(t.push.apply(t,this.encodeInteger(r.length,7,0)),Array.from(r).forEach(function(e){return t.push(e)})),t},e.prototype.findInStaticTable=function(e,t){for(var r=1;r<this.staticTable.length;r++)if(this.staticTable[r][0]===e&&this.staticTable[r][1]===t)return r;return-1},e.prototype.findInDynamicTable=function(e,t){for(var r=0;r<this.dynamicTable.length;r++)if(this.dynamicTable[r][0]===e&&this.dynamicTable[r][1]===t)return r;return-1},e.prototype.encodeLiteral=function(e,t,r){var n=this.findInStaticTable(t,"");-1!==n?e.push.apply(e,this.encodeInteger(n,6,64)):(e.push(64),e.push.apply(e,this.encodeString(t))),e.push.apply(e,this.encodeString(r)),this.addToDynamicTable(t,r)},e.prototype.addToDynamicTable=function(e,t){for(var r=e.length+t.length+32;this.dynamicTableSize+r>this.maxDynamicTableSize&&this.dynamicTable.length>0;){var n=this.dynamicTable.pop();n&&(this.dynamicTableSize-=n[0].length+n[1].length+32)}r<=this.maxDynamicTableSize&&(this.dynamicTable.unshift([e,t]),this.dynamicTableSize+=r)},e.prototype.getIndexedHeader=function(e){return e<=this.staticTable.length-1?this.staticTable[e]:this.dynamicTable[e-this.staticTable.length]},e.prototype.buildHuffmanTable=function(){return{codes:new Uint32Array([8184,8388568,268435426,268435427,268435428,268435429,268435430,268435431,268435432,16777194,1073741820,268435433,268435434,1073741821,268435435,268435436,268435437,268435438,268435439,268435440,268435441,268435442,1073741822,268435443,268435444,268435445,268435446,268435447,268435448,268435449,268435450,268435451,20,1016,1017,4090,8185,21,248,2042,1018,1019,249,2043,250,22,23,24,0,1,2,25,26,27,28,29,30,31,92,251,32764,32,4091,1020,8186,33,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,252,115,253,8187,524272,8188,16380,34,32765,3,35,4,36,5,37,38,39,6,116,117,40,41,42,7,43,118,44,8,9,45,119,120,121,122,123,32766,2044,16381,8189,268435452,1048550,4194258,1048551,1048552,4194259,4194260,4194261,8388569,4194262,8388570,8388571,8388572,8388573,8388574,16777195,8388575,16777196,16777197,4194263,8388576,16777198,8388577,8388578,8388579,8388580,2097116,4194264,8388581,4194265,8388582,8388583,16777199,4194266,2097117,1048553,4194267,4194268,8388584,8388585,2097118,8388586,4194269,4194270,16777200,2097119,4194271,8388587,8388588,2097120,2097121,4194272,2097122,8388589,4194273,8388590,8388591,1048554,4194274,4194275,4194276,8388592,4194277,4194278,8388593,67108832,67108833,1048555,524273,4194279,8388594,4194280,33554412,67108834,67108835,67108836,134217694,134217695,67108837,16777201,33554413,524274,2097123,67108838,134217696,134217697,67108839,134217698,16777202,2097124,2097125,67108840,67108841,268435453,134217699,134217700,134217701,1048556,16777203,1048557,2097126,4194281,2097127,2097128,8388595,4194282,4194283,33554414,33554415,16777204,16777205,67108842,8388596,67108843,134217702,67108844,67108845,134217703,134217704,134217705,134217706,134217707,268435454,134217708,134217709,134217710,134217711,134217712,67108846]),lengths:new Uint8Array([13,23,28,28,28,28,28,28,28,24,30,28,28,30,28,28,28,28,28,28,28,28,30,28,28,28,28,28,28,28,28,28,6,10,10,12,13,6,8,11,10,10,8,11,8,6,6,6,5,5,5,6,6,6,6,6,6,6,7,8,15,6,12,10,13,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,7,8,13,19,13,14,6,15,5,6,5,6,5,6,6,6,5,7,7,6,6,6,5,6,7,6,5,5,6,7,7,7,7,7,15,11,14,13,28,20,22,20,20,22,22,22,23,22,23,23,23,23,23,24,23,24,24,22,23,24,23,23,23,23,21,22,23,22,23,23,24,22,21,20,22,22,23,23,21,23,22,22,24,21,22,23,23,21,21,22,21,23,22,23,23,20,22,22,22,23,22,22,23,26,26,20,19,22,23,22,25,26,26,26,27,27,26,24,25,19,21,26,27,27,26,27,24,21,21,26,26,28,27,27,27,20,24,20,21,22,21,21,23,22,22,25,25,24,24,26,23,26,27,26,26,27,27,27,27,27,28,27,27,27,27,27,26])}},e.prototype.decode=function(e){for(var t="",r=0,n=0,i=0;i<e.length;i++){for(r=r<<8|e[i],n+=8;n>=5;){var a=this.findSymbol(r,n);if(!a)break;var o=a[0],s=a[1];t+=String.fromCharCode(o),r&=(1<<n-s)-1,n-=s}}if(n>0){var c=(1<<n)-1;if((r&c)!==c)throw new Error("Invalid Huffman padding")}return t},e.prototype.findSymbol=function(e,t){for(var r=0;r<this.huffmanTable.codes.length;r++){var n=this.huffmanTable.lengths[r];if(!(t<n))if((e>>t-n&(1<<n)-1)===this.huffmanTable.codes[r])return[r,n]}return null},e.prototype.huffmanEncode=function(e){for(var t=[],r=0,n=0,i=0;i<e.length;i++){var a=e[i],o=this.huffmanTable.codes[a],s=this.huffmanTable.lengths[a];for(r=r*(1<<s)+o,n+=s;n>=8;)n-=8,t.push(255&Math.floor(r/(1<<n))),r%=1<<n}if(n>0){var c=8-n;r=r*(1<<c)+((1<<c)-1),t.push(255&r)}return new Uint8Array(t)},e.prototype.decodeHeaderFields=function(e){for(var t=new Map,r=0;r<e.length;){var n=e[r];if(128&n){var i=this.decodeIndexedHeader(e,r),a=i[0],o=i[1],s=i[2];a&&o&&t.set(a,o),r=s}else if(64&n){var c=this.decodeLiteralHeaderWithIndexing(e,r),u=c[0];o=c[1],s=c[2];u&&o&&t.set(u,o),r=s}else if(32&n){var l=this.decodeInteger(e,r,5),h=l[0];s=l[1];for(this.maxDynamicTableSize=h;this.dynamicTableSize>this.maxDynamicTableSize&&this.dynamicTable.length>0;){var d=this.dynamicTable.pop();d&&(this.dynamicTableSize-=d[0].length+d[1].length+32)}r=s}else if(16&n){var f=this.decodeLiteralHeaderWithoutIndexing(e,r),p=f[0];o=f[1],s=f[2];p&&o&&t.set(p,o),r=s}else{var g=this.decodeLiteralHeaderWithoutIndexing(e,r),m=g[0];o=g[1],s=g[2];m&&o&&t.set(m,o),r=s}}return t},e.prototype.decodeInteger=function(e,t,r){var n=(1<<r)-1,i=t,a=e[t]&n;if(a<n)return[a,i+1];i++;for(var o=0;i<e.length;){var s=e[i++];if(a+=(127&s)<<o,o+=7,!(128&s))break}return[a,i]},e.prototype.decodeLiteralString=function(e,t){if(t>=e.length)return["",t];var r=!!(128&e[t]),n=this.decodeInteger(e,t,7),i=n[0],a=n[1];if(a+i>e.length)return["",a];var o,s=e.slice(a,a+i);if(r)try{o=this.decode(s)}catch(e){o=""}else try{o=(new TextDecoder).decode(s)}catch(e){o=""}return[o,a+i]},e.prototype.decodeIndexedHeader=function(e,t){var r=this.decodeInteger(e,t,7),n=r[0],i=r[1];if(n<=0)return["","",i];var a=this.getIndexedHeader(n);return a?[a[0],a[1],i]:["","",i]},e.prototype.decodeLiteralHeaderWithIndexing=function(e,t){var r,n=this.decodeInteger(e,t,6),i=n[0];if(t=n[1],i>0){var a=this.getIndexedHeader(i);r=a?a[0]:""}else{var o=this.decodeLiteralString(e,t);r=o[0],t=o[1]}var s=this.decodeLiteralString(e,t),c=s[0],u=s[1];return this.addToDynamicTable(r,c),[r,c,u]},e.prototype.decodeLiteralHeaderWithoutIndexing=function(e,t){var r,n=this.decodeInteger(e,t,4),i=n[0];if(t=n[1],i>0){var a=this.getIndexedHeader(i);r=a?a[0]:""}else{var o=this.decodeLiteralString(e,t);r=o[0],t=o[1]}var s=this.decodeLiteralString(e,t);return[r,s[0],s[1]]},e.prototype.huffmanDecodeToString=function(e){return this.decode(e)},e}(),w=function(){function e(){}return e.encodeSettingsFrame=function(e){var t=e.payload,r=6*t.length,n=new Uint8Array(9+r);return y(n,{length:r,type:e.type,flags:e.flags,streamId:e.streamId}),function(e,t){var r=9;t.forEach(function(t){!function(e,t,r){e[r]=t>>8&255,e[r+1]=255&t}(e,t.identifier,r),r+=2,S(e,t.value,r),r+=4})}(n,t),n},e.encodeSettingsAckFrame=function(){var e=new Uint8Array(9);return y(e,{length:0,type:4,flags:1,streamId:0}),e},e}();function y(e,t){var r,n=null!==(r=t.length)&&void 0!==r?r:0;e[0]=n>>16&255,e[1]=n>>8&255,e[2]=255&n,e[3]=t.type,e[4]=t.flags,S(e,2147483647&t.streamId,5)}function S(e,t,r){e[r]=t>>24&255,e[r+1]=t>>16&255,e[r+2]=t>>8&255,e[r+3]=255&t}var E=1,T=2,W=3,A=4,k=5,C=6,P=((c={})[E]=4096,c[T]=0,c[W]=100,c[A]=4<<20,c[k]=16384,c[C]=8192,c),I=function(){function e(){}return e.createPreface=function(){return(new TextEncoder).encode("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")},e.createPongFrame=function(t){return e.createFrame(6,1,0,t)},e.createSettingsFrame=function(t){void 0===t&&(t={});var r=e.createOriginSettingsFrame(t);return w.encodeSettingsFrame(r)},e.createSettingsAckFrame=function(){return w.encodeSettingsAckFrame()},e.createWindowUpdateFrame=function(t,r){if(r<=0||r>2147483647)throw new Error("Window size increment must be between 1 and 2^31-1");var n=new Uint8Array(4);return n[0]=r>>24&127,n[1]=r>>16&255,n[2]=r>>8&255,n[3]=255&r,e.createFrame(8,0,t,n)},e.createDataFrames=function(t,r,n,i){void 0===n&&(n=!1),void 0===i&&(i=16384);var a=[],o=r.length,s=new Uint8Array(5+o);s[0]=0,s[1]=o>>24&255,s[2]=o>>16&255,s[3]=o>>8&255,s[4]=255&o,s.set(r,5);for(var c=i,u=0;u<s.length;u+=c){var l=s.length-u,h=Math.min(c,l),d=s.slice(u,u+h),f=u+h>=s.length&&n,p=e.createFrame(0,f?1:0,t,d);a.push(p)}return a},e.createDataFrame=function(t,r,n){void 0===n&&(n=!0);var i=r.length,a=new Uint8Array(5+i);a[0]=0,a[1]=i>>24&255,a[2]=i>>16&255,a[3]=i>>8&255,a[4]=255&i,a.set(r,5);var o=n?1:0;return e.createFrame(0,o,t,a)},e.createHeadersFrame=function(t,r,n,i,a){void 0===n&&(n=!0),void 0===a&&(a="localhost");var o={":path":r,":method":"POST",":scheme":"http",":authority":a,"content-type":"application/grpc+proto","user-agent":"grpc-web-client/0.1",accept:"application/grpc+proto","grpc-timeout":"3600S"};i&&(o.authorization="Bearer ".concat(i));var s=(new b).encode(o),c=n?4:0;return e.createFrame(1,c,t,s)},e.createResponseHeadersFrame=function(t,r,n){void 0===n&&(n=!0);var i=(new b).encode(r),a=n?4:0;return e.createFrame(1,a,t,i)},e.createTrailersFrame=function(t,r){var n=(new b).encode(r);return e.createFrame(1,5,t,n)},e.createOriginSettingsFrame=function(e){void 0===e&&(e={});var r=t(t({},P),e);return function(e){for(var t=0,r=Object.entries(e);t<r.length;t++){var n=r[t],i=n[0],a=n[1];switch(Number(i)){case E:if(a<0)throw new Error("HEADER_TABLE_SIZE must be non-negative");break;case T:if(0!==a&&1!==a)throw new Error("ENABLE_PUSH must be 0 or 1");break;case A:if(a<0||a>2147483647)throw new Error("INITIAL_WINDOW_SIZE must be between 0 and 2^31-1");break;case k:if(a<16384||a>16777215)throw new Error("MAX_FRAME_SIZE must be between 16,384 and 16,777,215");break;case W:case C:if(a<0)throw new Error("Parameter ".concat(i," must be non-negative"));break;default:console.warn("Unknown settings parameter: ".concat(i))}}}(r),{type:4,flags:0,streamId:0,payload:x(r)}},e.createOriginSettingsAckFrame=function(){return{type:4,flags:1,streamId:0,payload:[]}},e.createFrame=function(e,t,r,n){var i=n?n.length:0,a=new Uint8Array(9+i);return a[0]=i>>16&255,a[1]=i>>8&255,a[2]=255&i,a[3]=e,a[4]=t,a[5]=r>>24&255,a[6]=r>>16&255,a[7]=r>>8&255,a[8]=255&r,n&&i>0&&a.set(n,9),a},e}();function x(e){for(var t=[],r=0,n=Object.entries(e);r<n.length;r++){var i=n[r],a=i[0],o=i[1];t.push({identifier:Number(a),value:o})}return t}var z=(new TextEncoder).encode("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"),F=function(){function e(e,t){var r;this.bufferChunks=[],this.bufferTotalLength=0,this.bufferChunks=[],this.bufferTotalLength=0,this.settingsAckReceived=!1,this.peerSettingsReceived=!1,this.connectionWindowSize=4<<20,this.streams=new Map,this.defaultStreamWindowSize=4<<20,this.sendConnWindow=65535,this.sendStreamWindows=new Map,this.peerInitialStreamWindow=65535,this.sendWindowWaiters=[],this.settingsAckWaiters=[],this.peerSettingsWaiters=[],this.endOfStreamWaiters=[],this.endFlag=!1,this.writer=e,this.compatibilityMode=null!==(r=null==t?void 0:t.compatibilityMode)&&void 0!==r&&r}return Object.defineProperty(e.prototype,"buffer",{get:function(){return this._flattenBuffer()},set:function(e){this.bufferChunks=e.length?[e]:[],this.bufferTotalLength=e.length},enumerable:!1,configurable:!0}),e.prototype._flattenBuffer=function(){if(0===this.bufferChunks.length)return new Uint8Array(0);if(1===this.bufferChunks.length)return this.bufferChunks[0];for(var e=new Uint8Array(this.bufferTotalLength),t=0,r=0,n=this.bufferChunks;r<n.length;r++){var i=n[r];e.set(i,t),t+=i.length}return e},e.prototype._wakeWindowWaiters=function(){for(var e=0,t=this.sendWindowWaiters.splice(0);e<t.length;e++){var r=t[e];try{r.resolve()}catch(e){}}},e.prototype.processStream=function(e){return r(this,void 0,void 0,function(){var t,r,i,a,o,c,u,l,h,d,f,p;return n(this,function(n){switch(n.label){case 0:n.trys.push([0,13,,14]),n.label=1;case 1:n.trys.push([1,6,7,12]),o=!0,c=s(e),n.label=2;case 2:return[4,c.next()];case 3:if(u=n.sent(),l=u.done)return[3,5];f=u.value,o=!1,t=f,this._processChunk(t),n.label=4;case 4:return o=!0,[3,2];case 5:return[3,12];case 6:return r=n.sent(),h={error:r},[3,12];case 7:return n.trys.push([7,,10,11]),o||l||!(d=c.return)?[3,9]:[4,d.call(c)];case 8:n.sent(),n.label=9;case 9:return[3,11];case 10:if(h)throw h.error;return[7];case 11:return[7];case 12:if(!this.compatibilityMode&&!this.endFlag)try{null===(p=this.onEnd)||void 0===p||p.call(this)}catch(e){console.error("Error during onEnd callback:",e)}return this.endFlag||this._notifyEndOfStream(),[3,14];case 13:if(i=n.sent(),this.endFlag||this._notifyEndOfStream(),a=i instanceof Error?i.message:String(i),/cleanup/i.test(a))return[2];throw console.error("Error processing stream:",i),i;case 14:return[2]}})})},e.prototype._processChunk=function(e){var t="subarray"in e&&"function"==typeof e.subarray?e.subarray():e;if(t.length>0&&(this.bufferChunks.push(t),this.bufferTotalLength+=t.length),!(this.bufferTotalLength<9)){var r=this._flattenBuffer();this.bufferChunks=[r];for(var n=0;r.length-n>=9;)if(r.length-n>=24&&this.isHttp2Preface(r.subarray(n))){n+=24;var i=I.createSettingsFrame();this.writer.write(i)}else{var a=this._parseFrameHeader(r.subarray(n)),o=9+a.length;if(r.length-n<o)break;var s=r.subarray(n,n+o);this._handleFrame(a,s).catch(function(e){console.error("Error handling frame:",e)}),n+=o}if(n>0)if(n>=r.length)this.bufferChunks=[],this.bufferTotalLength=0;else{var c=r.slice(n);this.bufferChunks=[c],this.bufferTotalLength=c.length}}},e.prototype.isHttp2Preface=function(e){if(e.length<z.length)return!1;for(var t=0;t<z.length;t++)if(e[t]!==z[t])return!1;return!0},e.prototype.waitForSettingsAck=function(){var e=this;return new Promise(function(t,r){if(e.settingsAckReceived)t();else{var n={resolve:t,reject:r};e.settingsAckWaiters.push(n);var i=setTimeout(function(){var t=e.settingsAckWaiters.indexOf(n);t>=0&&e.settingsAckWaiters.splice(t,1),r(new Error("Settings ACK timeout"))},3e4);n.resolve=function(){clearTimeout(i),t()},n.reject=function(e){clearTimeout(i),r(e)}}})},e.prototype._notifySettingsAck=function(){this.settingsAckReceived=!0;for(var e=0,t=this.settingsAckWaiters.splice(0);e<t.length;e++){var r=t[e];try{r.resolve()}catch(e){}}},e.prototype.waitForPeerSettings=function(e){var t=this;return void 0===e&&(e=3e4),new Promise(function(r,n){if(t.peerSettingsReceived)r();else{var i={resolve:r,reject:n};t.peerSettingsWaiters.push(i);var a=setTimeout(function(){var e=t.peerSettingsWaiters.indexOf(i);e>=0&&t.peerSettingsWaiters.splice(e,1),n(new Error("Peer SETTINGS timeout"))},e);i.resolve=function(){clearTimeout(a),r()},i.reject=function(e){clearTimeout(a),n(e)}}})},e.prototype._notifyPeerSettings=function(){this.peerSettingsReceived=!0;for(var e=0,t=this.peerSettingsWaiters.splice(0);e<t.length;e++){var r=t[e];try{r.resolve()}catch(e){}}},e.prototype.registerOutboundStream=function(e){this.sendStreamWindows.has(e)||this.sendStreamWindows.set(e,this.peerInitialStreamWindow)},e.prototype.getSendWindows=function(e){var t,r=null!==(t=this.sendStreamWindows.get(e))&&void 0!==t?t:0;return{conn:this.sendConnWindow,stream:r}},e.prototype.consumeSendWindow=function(e,t){var r;this.sendConnWindow=Math.max(0,this.sendConnWindow-t);var n=null!==(r=this.sendStreamWindows.get(e))&&void 0!==r?r:0;this.sendStreamWindows.set(e,Math.max(0,n-t))},e.prototype.unsafeForceExtendSendWindow=function(e,t){var r;if(!(this.compatibilityMode||t<=0)){this.sendConnWindow=Math.min(2147483647,this.sendConnWindow+t);var n=null!==(r=this.sendStreamWindows.get(e))&&void 0!==r?r:0;this.sendStreamWindows.set(e,Math.min(2147483647,n+t)),this._wakeWindowWaiters()}},e.prototype.waitForSendWindow=function(e,t,r){var n=this;void 0===t&&(t=1),void 0===r&&(r=3e4);var i=this.getSendWindows(e),a=i.conn,o=i.stream;return a>=t&&o>=t?Promise.resolve():new Promise(function(i,a){var o=!1,s=r>0?setTimeout(function(){if(!o){o=!0;var e=n.sendWindowWaiters.findIndex(function(e){return e.resolve===c});e>=0&&n.sendWindowWaiters.splice(e,1),a(new Error("Send window wait timeout"))}},r):void 0,c=function(){if(!o){var r=n.getSendWindows(e),a=r.conn,l=r.stream;a>=t&&l>=t?(o=!0,s&&clearTimeout(s),i()):n.sendWindowWaiters.push({resolve:c,reject:u})}},u=function(e){o||(o=!0,s&&clearTimeout(s),a(e))};n.sendWindowWaiters.push({resolve:c,reject:u})})},e.prototype._handleFrame=function(e,t){return r(this,void 0,void 0,function(){var r,i,a,o,s,c,b,w,y,S,E,T,W,A,k,C,P,x,z,F,O,L,D,H,M,U=this;return n(this,function(n){switch(e.type){case d:if((e.flags&m)===m)this._notifySettingsAck();else{for(r=t.slice(9),i={},a=0,o=void 0,s=0;s<r.length;s+=6)c=r[s]<<8|r[s+1],b=(r[s+2]<<24|r[s+3]<<16|r[s+4]<<8|r[s+5])>>>0,i[c]=b,4===c?(this.defaultStreamWindowSize=b,a=b-this.peerInitialStreamWindow,this.peerInitialStreamWindow=b):3===c&&(o=b);this.compatibilityMode||0===a||Array.from(this.sendStreamWindows.entries()).forEach(function(e){var t=e[0],r=e[1],n=Math.max(0,r+a);U.sendStreamWindows.set(t,n)});try{!this.onSettingsParsed||void 0===o&&0===a||(w={},void 0!==o&&(w.maxConcurrentStreams=o),0!==a&&(w.initialWindowSize=this.peerInitialStreamWindow),this.onSettingsParsed(w))}catch(e){console.error("Error handling parsed SETTINGS callback:",e)}this.onSettings&&this.onSettings(e),this._notifyPeerSettings(),this._wakeWindowWaiters()}break;case u:if(this.onData&&this.onData(t.slice(9),e),(y=null!==(z=e.length)&&void 0!==z?z:0)>0)try{0!==e.streamId&&(S=I.createWindowUpdateFrame(e.streamId,y),this.writer.write(S)),E=I.createWindowUpdateFrame(0,y),this.writer.write(E)}catch(e){console.error("[HTTP2] Error sending window update:",e)}if((e.flags&v)===v)return null===(F=this.onEnd)||void 0===F||F.call(this),this._notifyEndOfStream(),[2];break;case l:if(this.onHeaders&&this.onHeaders(t.slice(9),e),(e.flags&v)===v)return null===(O=this.onEnd)||void 0===O||O.call(this),this._notifyEndOfStream(),[2];break;case g:try{T=this.handleWindowUpdateFrame(e,t),0===e.streamId?this.sendConnWindow+=T.windowSizeIncrement:(W=null!==(L=this.sendStreamWindows.get(e.streamId))&&void 0!==L?L:this.peerInitialStreamWindow,this.sendStreamWindows.set(e.streamId,W+T.windowSizeIncrement)),this._wakeWindowWaiters()}catch(e){}break;case f:this._handlePingFrame(e,t);break;case p:A=void 0;try{(k=t.subarray(9)).length>=8?(C=new DataView(k.buffer,k.byteOffset,k.byteLength),P=2147483647&C.getUint32(0,!1),x=C.getUint32(4,!1),A={lastStreamId:P,errorCode:x},console.warn("[HTTP2] GOAWAY received",A)):(console.warn("[HTTP2] GOAWAY received"),A={})}catch(e){}try{null===(D=this.onGoaway)||void 0===D||D.call(this,null!=A?A:{})}catch(e){console.error("Error during GOAWAY callback:",e)}try{null===(H=this.onEnd)||void 0===H||H.call(this)}catch(e){console.error("Error during GOAWAY onEnd callback:",e)}this._notifyEndOfStream();break;case h:null===(M=this.onEnd)||void 0===M||M.call(this),this._notifyEndOfStream();break;default:console.debug("Unknown frame type:",e.type)}return[2]})})},e.prototype._parseFrameHeader=function(e){return{length:e[0]<<16|e[1]<<8|e[2],type:e[3],flags:e[4],streamId:2147483647&(e[5]<<24|e[6]<<16|e[7]<<8|e[8]),payload:e.slice(0,9)}},e.prototype._handlePingFrame=function(e,t){if(8!==e.length)throw new Error("PING frame must have a length of 8 bytes");if(!(e.flags&m)){var r=I.createPongFrame(t.slice(9));try{this.writer.write(r)}catch(e){throw console.error("Error sending PONG frame:",e),e}}},e.prototype.waitForEndOfStream=function(e){var t=this;return new Promise(function(r,n){if(t.endFlag)r();else{var i={resolve:r,reject:n};t.endOfStreamWaiters.push(i);var a=e>0?setTimeout(function(){var e=t.endOfStreamWaiters.indexOf(i);e>=0&&t.endOfStreamWaiters.splice(e,1),n(new Error("End of stream timeout"))},e):null;i.resolve=function(){a&&clearTimeout(a),r()},i.reject=function(e){a&&clearTimeout(a),n(e)}}})},e.prototype._notifyEndOfStream=function(){this.endFlag=!0;for(var e=0,t=this.endOfStreamWaiters.splice(0);e<t.length;e++){var r=t[e];try{r.resolve()}catch(e){}}},e.prototype.parseWindowUpdateFrame=function(e,t){if(4!==t.length)throw new Error("WINDOW_UPDATE frame must have a length of 4 bytes");var r=new Uint8Array(e.slice(9)),n=(127&r[0])<<24|r[1]<<16|r[2]<<8|r[3];if(0===n)throw new Error("WINDOW_UPDATE increment must not be zero");return{windowSizeIncrement:n}},e.prototype.handleWindowUpdateFrame=function(e,t){try{var r=this.parseWindowUpdateFrame(t,e);return this.connectionWindowSize+=r.windowSizeIncrement,r}catch(e){throw console.error("Error handling WINDOW_UPDATE frame:",e),e}},e}();function O(){const e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}class L{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return void 0===this.buffer[this.top]&&(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){const e=this.buffer[this.btm];if(void 0!==e)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return void 0===this.buffer[this.btm]}}class D{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new L(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return null!=e?.byteLength?e.byteLength:1}push(e){if(null!=e?.value&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){const t=this.head;this.head=t.next=new L(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(void 0===e&&null!=this.tail.next){const t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return null!=e?.value&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}}class H extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}}function M(e={}){return function(e,t){t=t??{};let r,n,i,a=t.onEnd,o=new D,s=O();const c=async()=>{try{return o.isEmpty()?i?{done:!0}:await new Promise((t,i)=>{n=a=>{n=null,o.push(a);try{t(e(o))}catch(e){i(e)}return r}}):e(o)}finally{o.isEmpty()&&queueMicrotask(()=>{s.resolve(),s=O()})}},u=e=>null!=n?n(e):(o.push(e),r),l=e=>(o=new D,null!=n?n({error:e}):(o.push({error:e}),r)),h=e=>{if(i)return r;if(!0!==t?.objectMode&&null==e?.byteLength)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:e})},d=e=>i?r:(i=!0,null!=e?l(e):u({done:!0})),f=()=>(o=new D,d(),{done:!0}),p=e=>(d(e),{done:!0});if(r={[Symbol.asyncIterator](){return this},next:c,return:f,throw:p,push:h,end:d,get readableLength(){return o.size},onEmpty:async e=>{const t=e?.signal;if(t?.throwIfAborted(),o.isEmpty())return;let r,n;null!=t&&(r=new Promise((e,r)=>{n=()=>{r(new H)},t.addEventListener("abort",n)}));try{await Promise.race([s.promise,r])}finally{null!=n&&null!=t&&t?.removeEventListener("abort",n)}}},null==a)return r;const g=r;return r={[Symbol.asyncIterator](){return this},next:()=>g.next(),throw:e=>(g.throw(e),null!=a&&(a(e),a=void 0),{done:!0}),return:()=>(g.return(),null!=a&&(a(),a=void 0),{done:!0}),push:h,end:e=>(g.end(e),null!=a&&(a(e),a=void 0),r),get readableLength(){return g.readableLength},onEmpty:e=>g.onEmpty(e)},r}(e=>{const t=e.shift();if(null==t)return{done:!0};if(null!=t.error)throw t.error;return{done:!0===t.done,value:t.value}},e)}var U=4091,_=function(){function e(e,t){var r,n,i;if(void 0===t&&(t={}),this.stream=e,this.options=t,this.bytesWritten=0,this.abortController=new AbortController,this.backpressureHistory=[],this.isBackpressure=!1,this.writeQueue=[],this.isProcessingQueue=!1,this.lastBackpressureCheck=0,this.bytesDrained=0,this.lastDrainEventAt=0,this.stallStartAt=0,this.lastBytesDrainedSeen=0,this.lastBpWarnAt=0,this.isHandlingError=!1,this.drainWaiters=[],this.listeners=new Map,!e)throw new Error("StreamWriter requires a valid stream object");this.log={trace:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return console.debug.apply(console,function(e,t,r){if(r||2===arguments.length)for(var n,i=0,a=t.length;i<a;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}(["[StreamWriter]"],e,!1))}},this.options=t?{chunkSize:null!==(r=t.chunkSize)&&void 0!==r?r:U,bufferSize:null!==(n=t.bufferSize)&&void 0!==n?n:5242880,retries:null!==(i=t.retries)&&void 0!==i?i:3}:{chunkSize:U,bufferSize:5242880,retries:3},this.options.chunkSize&&this.options.chunkSize>U&&(this.options.chunkSize=U);var a=M({objectMode:!1});a._originalPush=a.push.bind(a),a._originalNext=a.next.bind(a),a._queueSize=0,Object.defineProperty(a,"push",{value:function(e){return a._queueSize+=e.byteLength,a._originalPush(e)},writable:!1,configurable:!1}),this.p=a,this.startPipeline(),this.startWatchdog()}return Object.defineProperty(e.prototype,"queueSize",{get:function(){return this.p._queueSize},enumerable:!1,configurable:!0}),e.prototype.getAverageQueueSize=function(){var e=Date.now(),t=this.queueSize;return e-this.lastBackpressureCheck>100&&(t>0&&(this.backpressureHistory.push(t),this.backpressureHistory.length>5&&this.backpressureHistory.shift()),this.lastBackpressureCheck=e),0===this.backpressureHistory.length?t:this.backpressureHistory.reduce(function(e,t){return e+t},0)/this.backpressureHistory.length},e.prototype.handleError=function(e){var t,r;if(!this.abortController.signal.aborted&&!this.isHandlingError){this.isHandlingError=!0,this.abort(e.message);try{this.dispatchEvent(new CustomEvent("error",{detail:e}))}catch(e){null===(r=null===(t=this.log)||void 0===t?void 0:t.trace)||void 0===r||r.call(t,"Error in error event handler:",e)}}},e.prototype.startPipeline=function(){var e=this;this.pipeToStream().catch(function(t){return e.handleError(t)})},e.prototype.pipeToStream=function(){return r(this,void 0,void 0,function(){var e,t,r,i,a,o,c,u,l,h,d,f,p,g,m;return n(this,function(n){switch(n.label){case 0:if(!this.stream)return null===(p=null===(f=this.log)||void 0===f?void 0:f.trace)||void 0===p||p.call(f,"Stream is null/undefined, cannot start pipeline"),[2];n.label=1;case 1:n.trys.push([1,10,11,16]),e=!0,t=s(this.createTransform()(this.p)),n.label=2;case 2:return[4,t.next()];case 3:if(r=n.sent(),u=r.done)return[3,9];if(d=r.value,e=!1,i=d,this.abortController.signal.aborted)return[3,9];n.label=4;case 4:return n.trys.push([4,7,,8]),this.stream.send(i)?[3,6]:[4,this.stream.onDrain({signal:this.abortController.signal})];case 5:n.sent(),n.label=6;case 6:return[3,8];case 7:if(a=n.sent(),o=(a instanceof Error?a.message:"").toLowerCase(),a instanceof Error&&"StreamStateError"===a.name||o.includes("closing")||o.includes("closed")||o.includes("write to a stream that is closed"))return null===(m=null===(g=this.log)||void 0===g?void 0:g.trace)||void 0===m||m.call(g,"Stream is closing/closed, stopping pipeline"),[3,9];throw a;case 8:return e=!0,[3,2];case 9:return[3,16];case 10:return c=n.sent(),l={error:c},[3,16];case 11:return n.trys.push([11,,14,15]),e||u||!(h=t.return)?[3,13]:[4,h.call(t)];case 12:n.sent(),n.label=13;case 13:return[3,15];case 14:if(l)throw l.error;return[7];case 15:return[7];case 16:return this.cleanup(),[2]}})})},e.prototype.createTransform=function(){var e=this;return function(t){return o(this,arguments,function(){var r,i,o,c,u,l,h,d,f,p,g,m,v,b;return n(this,function(n){switch(n.label){case 0:n.trys.push([0,7,8,13]),r=!0,i=s(t),n.label=1;case 1:return[4,a(i.next())];case 2:return o=n.sent(),(g=o.done)?[3,6]:(b=o.value,r=!1,[4,a(c=b)]);case 3:return[4,n.sent()];case 4:n.sent();try{if(null!=e.p._queueSize&&(e.p._queueSize=Math.max(0,e.p._queueSize-c.byteLength)),e.bytesDrained+=c.byteLength,(u=Date.now())-e.lastDrainEventAt>250&&(e.lastDrainEventAt=u,e.dispatchEvent(new CustomEvent("drain",{detail:{drained:e.bytesDrained,queueSize:e.queueSize}}))),e.drainWaiters.length>0)for(l=e.drainWaiters.splice(0),h=0,d=l;h<d.length;h++){f=d[h];try{f()}catch(e){}}e.lastBytesDrainedSeen=e.bytesDrained}catch(e){console.error("Error updating bytesDrained in StreamWriter transform",e)}n.label=5;case 5:return r=!0,[3,1];case 6:return[3,13];case 7:return p=n.sent(),m={error:p},[3,13];case 8:return n.trys.push([8,,11,12]),r||g||!(v=i.return)?[3,10]:[4,a(v.call(i))];case 9:n.sent(),n.label=10;case 10:return[3,12];case 11:if(m)throw m.error;return[7];case 12:return[7];case 13:return[2]}})})}},e.prototype.startWatchdog=function(e,t){var r=this;if(void 0===e&&(e=500),void 0===t&&(t=1500),!this.watchdogTimer){var n=function(){if(!r.abortController.signal.aborted){var i=.7*r.options.bufferSize,a=r.queueSize,o=Date.now();if(a>=i)if(r.lastBytesDrainedSeen===r.bytesDrained){if(r.stallStartAt||(r.stallStartAt=o),o-r.stallStartAt>=t){var s={queueSize:a,drained:r.bytesDrained,sinceMs:o-r.stallStartAt};setTimeout(function(){r.abortController.signal.aborted||r.dispatchEvent(new CustomEvent("stalled",{detail:s}))},0),r.stallStartAt=o}}else r.stallStartAt=0,r.lastBytesDrainedSeen=r.bytesDrained;else r.stallStartAt=0;r.watchdogTimer=setTimeout(n,e)}};this.watchdogTimer=setTimeout(n,e)}},e.prototype.write=function(e){return r(this,void 0,void 0,function(){var t=this;return n(this,function(i){return this.abortController.signal.aborted?[2,Promise.resolve()]:[2,new Promise(function(i,a){t.writeQueue.push(function(){return r(t,void 0,void 0,function(){var t,r;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),this.abortController.signal.aborted?(i(),[2]):[4,this.convertToBuffer(e)];case 1:return t=n.sent(),[4,this.writeChunks(t)];case 2:return n.sent(),i(),[3,4];case 3:return r=n.sent(),a(r),[3,4];case 4:return[2]}})})}),t.processQueue()})]})})},e.prototype.convertToBuffer=function(e){return r(this,void 0,void 0,function(){return n(this,function(t){return e instanceof Blob?[2,e.arrayBuffer()]:"string"==typeof e?[2,(new TextEncoder).encode(e).buffer]:e instanceof Uint8Array?[2,e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)]:[2,e]})})},e.prototype.writeChunks=function(e){return r(this,void 0,void 0,function(){var t,r,i,a;return n(this,function(n){switch(n.label){case 0:t=new Uint8Array(e),r=0,n.label=1;case 1:return r<t.byteLength?(i=Math.min(r+this.options.chunkSize,t.byteLength),a=t.subarray(r,i),[4,this.retryableWrite(a)]):[3,4];case 2:n.sent(),this.updateProgress(a.byteLength),n.label=3;case 3:return r+=this.options.chunkSize,[3,1];case 4:return[2]}})})},e.prototype.retryableWrite=function(e){return r(this,arguments,void 0,function(e,t){var r,i,a,o;return void 0===t&&(t=0),n(this,function(n){switch(n.label){case 0:if(this.abortController.signal.aborted)throw new Error("Stream is aborted, cannot write");n.label=1;case 1:return n.trys.push([1,4,,7]),r=this.queueSize,i=.7*this.options.bufferSize,r>i?[4,this.monitorBackpressure()]:[3,3];case 2:n.sent(),n.label=3;case 3:if(this.abortController.signal.aborted)throw new Error("Stream aborted during backpressure monitoring");return this.p.push(e),[3,7];case 4:return a=n.sent(),!this.abortController.signal.aborted&&t<this.options.retries?(o=this.calculateRetryDelay(t),[4,new Promise(function(e){return setTimeout(e,o)})]):[3,6];case 5:return n.sent(),[2,this.retryableWrite(e,t+1)];case 6:throw a;case 7:return[2]}})})},e.prototype.monitorBackpressure=function(){return r(this,void 0,void 0,function(){var e,t,r,i,a,o,s,c=this;return n(this,function(u){switch(u.label){case 0:if(e=.7*this.options.bufferSize,t=.9*this.options.bufferSize,this.queueSize<e)return this.isBackpressure&&(this.isBackpressure=!1,this.dispatchBackpressureEvent({currentSize:this.queueSize,averageSize:this.getAverageQueueSize(),threshold:e,waitingTime:0})),[2];this.isBackpressure||(this.isBackpressure=!0,this.dispatchBackpressureEvent({currentSize:this.queueSize,averageSize:this.getAverageQueueSize(),threshold:e,waitingTime:0})),r=3,i=function(r){var i,o;return n(this,function(r){switch(r.label){case 0:return a.abortController.signal.aborted||a.queueSize<e?[2,"break"]:(i=a.queueSize>=t,o=i?100:30,[4,new Promise(function(e){var t=!1,r=setTimeout(function(){t||(t=!0,e())},o);c.drainWaiters.push(function(){t||(t=!0,clearTimeout(r),e())})})]);case 1:return r.sent(),[2]}})},a=this,o=0,u.label=1;case 1:return o<r?[5,i(o)]:[3,4];case 2:if("break"===u.sent())return[3,4];u.label=3;case 3:return o++,[3,1];case 4:return this.queueSize>=e&&(s=Date.now())-this.lastBpWarnAt>1e3&&(this.lastBpWarnAt=s,console.warn("Stream writer: High backpressure detected (".concat(this.queueSize," bytes), continuing anyway"))),[2]}})})},e.prototype.calculateRetryDelay=function(e){return Math.min(10*Math.pow(2,e)+100*Math.random(),100)},e.prototype.processQueue=function(){return r(this,void 0,void 0,function(){var e,t;return n(this,function(r){switch(r.label){case 0:if(this.isProcessingQueue||this.abortController.signal.aborted)return[2];this.isProcessingQueue=!0,r.label=1;case 1:return this.writeQueue.length>0?this.abortController.signal.aborted?[3,5]:(e=this.queueSize,t=.5*this.options.bufferSize,e>t?[4,this.monitorBackpressure()]:[3,3]):[3,5];case 2:r.sent(),r.label=3;case 3:return[4,this.writeQueue.shift()()];case 4:return r.sent(),[3,1];case 5:return this.isProcessingQueue=!1,[2]}})})},e.prototype.updateProgress=function(e){this.bytesWritten+=e,this.dispatchEvent(new CustomEvent("progress",{detail:{loaded:this.bytesWritten}}))},e.prototype.end=function(){return r(this,void 0,void 0,function(){var e,t,r,i;return n(this,function(n){switch(n.label){case 0:if(this.p.end(),!this.stream||"function"!=typeof this.stream.close)return[3,4];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.stream.close()];case 2:return n.sent(),[3,4];case 3:return e=n.sent(),(t=(e instanceof Error?e.message:"").toLowerCase()).includes("closed")||t.includes("closing")||null===(i=null===(r=this.log)||void 0===r?void 0:r.trace)||void 0===i||i.call(r,"Stream close error:",e),[3,4];case 4:return this.cleanup(),[2]}})})},e.prototype.abort=function(e){var t,r,n,i;if(void 0===e&&(e="User aborted"),!this.abortController.signal.aborted){this.abortController.abort(e);try{if(this.stream&&"function"==typeof this.stream.abort){var a=this.stream.status||this.stream.state;"closed"!==a&&"closing"!==a&&this.stream.abort(new Error(e))}}catch(e){var o=(e instanceof Error?e.message:"").toLowerCase();o.includes("closed")||o.includes("closing")||o.includes("write")||null===(r=null===(t=this.log)||void 0===t?void 0:t.trace)||void 0===r||r.call(t,"Stream abort error:",e)}this.cleanup();try{this.dispatchEvent(new CustomEvent("abort",{detail:e}))}catch(e){null===(i=null===(n=this.log)||void 0===n?void 0:n.trace)||void 0===i||i.call(n,"Error in abort event handler:",e)}}},e.prototype.cleanup=function(){this.abortController.signal.aborted||this.abortController.abort();for(var e=0,t=this.writeQueue.splice(0);e<t.length;e++){(0,t[e])().catch(function(){})}for(var r=0,n=this.drainWaiters.splice(0);r<n.length;r++){var i=n[r];try{i()}catch(e){}}try{this.p.end()}catch(e){}this.watchdogTimer&&(clearTimeout(this.watchdogTimer),this.watchdogTimer=void 0)},e.prototype.flush=function(){return r(this,arguments,void 0,function(e){var t=this;return void 0===e&&(e=1e4),n(this,function(r){switch(r.label){case 0:return this.queueSize<=0&&!this.isProcessingQueue&&0===this.writeQueue.length||this.abortController.signal.aborted?[2]:[4,new Promise(function(r){if(t.queueSize<=0&&!t.isProcessingQueue&&0===t.writeQueue.length)r();else{var n=!1,i=setTimeout(function(){n||(n=!0,console.warn("Stream writer: flush timeout with ".concat(t.queueSize," bytes still queued")),r())},e),a=function(){t.abortController.signal.aborted||t.queueSize<=0&&!t.isProcessingQueue&&0===t.writeQueue.length?n||(n=!0,clearTimeout(i),r()):t.drainWaiters.push(a)};t.drainWaiters.push(a)}})];case 1:return r.sent(),[2]}})})},e.prototype.addEventListener=function(e,t){var r=this.listeners.get(e)||[];r.push(t),this.listeners.set(e,r)},e.prototype.dispatchEvent=function(e){(this.listeners.get(e.type)||[]).forEach(function(t){return t(e)})},e.prototype.dispatchBackpressureEvent=function(e){this.dispatchEvent(new CustomEvent("backpressure",{detail:e}))},e}(),j=15e3,q=function(){function e(){this.streamIdLock=Promise.resolve(),this.currentStreamId=1}return e.prototype.getNextAppLevelStreamId=function(){return r(this,void 0,void 0,function(){var e=this;return n(this,function(t){return[2,new Promise(function(t){e.streamIdLock=e.streamIdLock.then(function(){var r=e.currentStreamId;e.currentStreamId+=2,t(r)})})]})})},e}(),B=function(){function e(e,t,r,n){this.node=e,this.peerAddr=t,this.protocol=n||"/dc/thread/0.0.1",this.token=r,this.connectionStreamManagers=new WeakMap,this.connectionStates=new WeakMap,this.connectionPool=new Map}return e.prototype.getStreamManagerFor=function(e){var t=this.connectionStreamManagers.get(e);return t||(t=new q,this.connectionStreamManagers.set(e,t)),t},e.prototype.getConnectionState=function(e){var t=this.connectionStates.get(e);return t||(t={activeStreams:0,maxConcurrentStreams:Number.POSITIVE_INFINITY,waiters:[]},this.connectionStates.set(e,t)),t},e.prototype.notifyStreamSlotAvailable=function(e){if(0!==e.waiters.length)for(;e.waiters.length>0&&e.activeStreams<e.maxConcurrentStreams;){var t=e.waiters.shift();if(!t)break;try{t.resolve()}catch(e){console.error("Error resolving stream waiter:",e)}}},e.prototype.rejectStreamWaiters=function(e,t){if(0!==e.waiters.length)for(var r=0,n=e.waiters.splice(0);r<n.length;r++){var i=n[r];try{i.reject(t)}catch(e){console.error("Error rejecting stream waiter:",e)}}},e.prototype.waitForStreamSlot=function(e,t){return r(this,arguments,void 0,function(e,t,r){return void 0===r&&(r=5e3),n(this,function(n){switch(n.label){case 0:if(e.maxConcurrentStreams<=0)throw new Error("No available HTTP/2 streams: server advertised zero concurrent streams");return!Number.isFinite(e.maxConcurrentStreams)||e.activeStreams<e.maxConcurrentStreams?[2]:[4,new Promise(function(n,i){var a,o=!1,s=function(){var r=e.waiters.indexOf(c);r>=0&&e.waiters.splice(r,1),a&&clearTimeout(a),t&&t.removeEventListener("abort",u)},c={resolve:function(){o||(o=!0,s(),n())},reject:function(e){o||(o=!0,s(),i(e))}},u=function(){c.reject(new Error("Aborted while waiting for available HTTP/2 stream slot"))};if(t){if(t.aborted)return void u();t.addEventListener("abort",u,{once:!0})}a=r>0?setTimeout(function(){c.reject(new Error("Timed out waiting for available HTTP/2 stream slot"))},r):void 0,e.waiters.push(c)})];case 1:return n.sent(),[2]}})})},e.prototype.sendFrameWithFlowControl=function(e,t,i,a,o){return r(this,arguments,void 0,function(e,t,r,i,a,o){var s,c,u,l,h,d,f;return void 0===o&&(o=j),n(this,function(n){switch(n.label){case 0:if(null==a?void 0:a.aborted)throw new Error("Operation aborted");if(!((s=Math.max(0,r.length-9))>0))return[3,4];c=e.getSendWindows(t),u=c.conn,l=c.stream,(u<s||l<s)&&console.debug("[stream ".concat(t,"] waiting for send window: need=").concat(s," conn=").concat(u," stream=").concat(l)),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,e.waitForSendWindow(t,s,o)];case 2:return n.sent(),[3,4];case 3:return h=n.sent(),console.warn("[stream ".concat(t,"] send window wait failed (").concat(null!==(f=null==h?void 0:h.message)&&void 0!==f?f:h,"); continuing best-effort")),d=Math.max(s,262144),e.unsafeForceExtendSendWindow(t,d),[3,4];case 4:if(null==a?void 0:a.aborted)throw new Error("Operation aborted");return[4,i.write(r)];case 5:return n.sent(),s>0&&e.consumeSendWindow(t,s),[2]}})})},e.prototype.acquireConnection=function(e){return r(this,void 0,void 0,function(){var t,i,a,o,s,c=this;return n(this,function(u){if(t=this.peerAddr.toString(),!e&&(i=this.connectionPool.get(t))){if(!(a=i.connection))return[2,i.promise];if(!(o=a.status)||"open"===o)return[2,a];this.connectionPool.delete(t)}return s=this.node.dial(this.peerAddr,{signal:AbortSignal.timeout(5e3)}).then(function(i){return r(c,void 0,void 0,function(){var r,a,o=this;return n(this,function(n){if(!e&&(r=this.connectionPool.get(t))&&r.promise===s){r.connection=i,a=function(){var e=o.connectionPool.get(t);e&&e.promise===s&&o.connectionPool.delete(t)};try{i.addEventListener("close",a,{once:!0})}catch(e){}}return[2,i]})})}).catch(function(r){if(!e){var n=c.connectionPool.get(t);n&&n.promise===s&&c.connectionPool.delete(t)}throw r}),e||this.connectionPool.set(t,{promise:s}),[2,s]})})},e.prototype.getDefaultTransportProfile=function(e){return"server-streaming"===e?"compatibility":"flow-control"},e.prototype.setToken=function(e){this.token=e},e.prototype.getAuthority=function(){try{var e=this.peerAddr.toString(),t=e.match(/\/ip4\/(\d[\d.]+)\/tcp\/(\d+)/);if(t)return"".concat(t[1],":").concat(t[2]);var r=e.match(/\/ip6\/([^/]+)\/tcp\/(\d+)/);if(r)return"[".concat(r[1],"]:").concat(r[2]);var n=e.match(/\/dns(?:4|6)?\/([.\w-]+)\/tcp\/(\d+)/);if(n)return"".concat(n[1],":").concat(n[2])}catch(e){}return"localhost"},e.prototype.unaryCall=function(e,t){return r(this,arguments,void 0,function(e,t,r){var i,a,o,s,c,u,l,h,d,f,p,g,m,v,w,y,S,E,T,W,A,k,C,P,x,z,O,L,D=this;return void 0===r&&(r=3e4),n(this,function(n){switch(n.label){case 0:i=null,a=null,o=[],s=-1,c=[],u=new b,l=!1,h="",d=!1,f=null,p=null,g=null,m=!1,v=null,n.label=1;case 1:return n.trys.push([1,23,24,29]),[4,this.acquireConnection(!1)];case 2:p=n.sent(),w=this.peerAddr.toString(),g=this.getConnectionState(p),n.label=3;case 3:return n.trys.push([3,5,,6]),[4,this.waitForStreamSlot(g,void 0,r)];case 4:return n.sent(),g.activeStreams+=1,m=!0,[3,6];case 5:throw y=n.sent(),console.warn("[unaryCall] waiting for stream slot failed:",y),y;case 6:return[4,p.newStream(this.protocol,{maxOutboundStreams:50,negotiateFully:!1})];case 7:return i=n.sent(),[4,this.getStreamManagerFor(p).getNextAppLevelStreamId()];case 8:S=n.sent(),E=new _(i,{bufferSize:16777216}),v=E;try{E.addEventListener("backpressure",function(e){var t=e.detail||{};console.warn("[unary stream ".concat(S,"] backpressure current=").concat(t.currentSize," avg=").concat(t.averageSize," threshold=").concat(t.threshold))}),E.addEventListener("drain",function(){}),E.addEventListener("stalled",function(e){var t,r=e.detail||{};console.warn("[unary stream ".concat(S,"] stalled queue=").concat(r.queueSize," drained=").concat(r.drained," since=").concat(r.sinceMs,"ms — sending PING"));try{var n=new Uint8Array(8);null===(t=crypto.getRandomValues)||void 0===t||t.call(crypto,n);var i=I.createFrame(6,0,0,n);E.write(i)}catch(e){}})}catch(e){}return(T=new F(E)).onGoaway=function(e){console.warn("[unaryCall] GOAWAY received from server",e),D.connectionPool.delete(w),g&&D.rejectStreamWaiters(g,new Error("Connection received GOAWAY")),l=!0,h="GOAWAY received: code=".concat(e.errorCode),null==f||f();try{null==p||p.close()}catch(e){console.warn("Error closing connection after GOAWAY:",e)}},T.onSettingsParsed=function(e){g&&void 0!==e.maxConcurrentStreams&&e.maxConcurrentStreams>0&&(g.maxConcurrentStreams=e.maxConcurrentStreams,D.notifyStreamSlotAvailable(g))},T.registerOutboundStream(S),s=-1,o=[],c=[],T.onData=function(e,t){if(-1===s){var r=e;if(c.length>0){c.push(e);var n=c.reduce(function(e,t){return e+t.length},0);r=new Uint8Array(n);for(var i=0,u=0,l=c;u<l.length;u++){var h=l[u];r.set(h,i),i+=h.length}c=[]}if(r.length<5)return void c.push(r);var p=r.slice(1,5);if((s=new DataView(p.buffer,p.byteOffset).getUint32(0,!1))+5>r.length){var g=r.subarray(5);return o.push(g),void(s-=g.length)}var m=s;g=r.slice(5,5+m);o.push(g),a=g,d=!0,s=-1,null==f||f()}else if(s>0)if((s-=e.length)<=0){var v=s<0?e.slice(0,e.length+s):e;o.push(v),a=new Uint8Array(o.reduce(function(e,t){return e+t.length},0));for(var b=0,w=0,y=o;w<y.length;w++){var S=y[w];a.set(S,b),b+=S.length}s=-1,d=!0,null==f||f()}else o.push(e);if(t&&1&t.flags&&!d){if(o.length>0){var E=o.reduce(function(e,t){return e+t.length},0);a=new Uint8Array(E);b=0;for(var T=0,W=o;T<W.length;T++){S=W[T];a.set(S,b),b+=S.length}}else a=new Uint8Array(0);d=!0,null==f||f()}},T.onEnd=function(){d||(d=!0,null==f||f())},T.onSettings=function(){var e=I.createSettingsAckFrame();E.write(e)},T.onHeaders=function(e){var t=u.decodeHeaderFields(e);"0"===t.get("grpc-status")||void 0!==t.get("grpc-status")&&(l=!0,h=t.get("grpc-message")||"gRPC call failed",null==f||f())},T.processStream(i).catch(function(e){d||(console.error("Error in processStream:",e),l=!0,h||(h=e instanceof Error?e.message:"Stream processing failed"),null==f||f())}),W=I.createPreface(),[4,E.write(W)];case 9:return n.sent(),A=I.createSettingsFrame(),[4,E.write(A)];case 10:return n.sent(),[4,Promise.race([T.waitForPeerSettings(1e3).catch(function(){}),T.waitForSettingsAck().catch(function(){}),new Promise(function(e){return setTimeout(e,300)})])];case 11:return n.sent(),k=I.createHeadersFrame(S,e,!0,this.token,this.getAuthority()),[4,E.write(k)];case 12:n.sent(),C=I.createDataFrames(S,t,!0),P=r>0?r:j,x=0,z=C,n.label=13;case 13:return x<z.length?(O=z[x],[4,this.sendFrameWithFlowControl(T,S,O,E,void 0,P)]):[3,16];case 14:n.sent(),n.label=15;case 15:return x++,[3,13];case 16:return[4,new Promise(function(e,t){if(d||l)e();else{var n=setTimeout(function(){f=null,t(new Error("gRPC response timeout"))},r);f=function(){clearTimeout(n),f=null,e()}}})];case 17:n.sent(),n.label=18;case 18:return n.trys.push([18,20,,21]),[4,E.flush(r)];case 19:case 20:return n.sent(),[3,21];case 21:return[4,E.end()];case 22:return n.sent(),[3,29];case 23:throw L=n.sent(),console.error("unaryCall error:",L),L;case 24:if(null==v||v.abort("unaryCall cleanup"),!i)return[3,28];n.label=25;case 25:return n.trys.push([25,27,,28]),[4,i.close()];case 26:case 27:return n.sent(),[3,28];case 28:return m&&g&&(g.activeStreams=Math.max(0,g.activeStreams-1),this.notifyStreamSlotAvailable(g)),[7];case 29:if(l)throw new Error(h);return a||(a=new Uint8Array),[2,a]}})})},e.prototype.Call=function(e,t){return r(this,arguments,void 0,function(e,t,i,a,o,c,u,l,h,d){var f,p,g,m,v,w,y,S,E,T,W,A=this;return void 0===i&&(i=3e4),n(this,function(k){switch(k.label){case 0:if(f=new AbortController,g=null,v=null!==(W=null==d?void 0:d.transportProfile)&&void 0!==W?W:this.getDefaultTransportProfile(a),w="flow-control"===v,y=function(){if(f.abort(),p&&clearTimeout(p),g)try{g.close()}catch(e){console.error("Error closing stream on cancel:",e)}},null==h?void 0:h.signal){if(h.signal.aborted)return l&&l(new Error("Operation aborted by context")),[2,y];m=function(){y()},h.signal.addEventListener("abort",m)}S=new Promise(function(e,t){p=setTimeout(function(){t(new Error("Operation timed out")),y()},i)}),E=r(A,void 0,void 0,function(){var v,y,S,E,T,W,A,k,C,P,x,z,O,L,D,H,M,U,q,B,G,N,R,Q,Y,V,Z,K,X,J,$,ee,te,re,ne,ie,ae,oe,se,ce,ue,le,he,de,fe,pe,ge,me,ve,be,we,ye,Se=this;return n(this,function(Ee){switch(Ee.label){case 0:v=!1,y=function(e){v||(v=!0,f.abort(),l&&l(e))},S=[],E=0,T=-1,W=function(){if(0===S.length)return new Uint8Array(0);if(1===S.length)return S[0];for(var e=new Uint8Array(E),t=0,r=0,n=S;r<n.length;r++){var i=n[r];e.set(i,t),t+=i.length}return e},A=new b,k=null,C=null,P=null,x=!1,z=null,Ee.label=1;case 1:if(Ee.trys.push([1,49,50,64]),f.signal.aborted)throw new Error("Operation aborted");if(!(null==d?void 0:d.freshConnection))return[3,5];Ee.label=2;case 2:return Ee.trys.push([2,4,,5]),this.connectionPool.delete(this.peerAddr.toString()),[4,this.node.hangUp(this.peerAddr)];case 3:return Ee.sent(),console.warn("[Call] hangUp existing connection before dialing due to freshConnection=true"),[3,5];case 4:return O=Ee.sent(),console.warn("[Call] hangUp failed or not supported, proceeding to dial",O),[3,5];case 5:return[4,this.acquireConnection(Boolean(null==d?void 0:d.freshConnection))];case 6:if(k=Ee.sent(),C=this.peerAddr.toString(),!(P=this.getConnectionState(k)))return[3,10];Ee.label=7;case 7:return Ee.trys.push([7,9,,10]),[4,this.waitForStreamSlot(P,f.signal,i)];case 8:return Ee.sent(),P.activeStreams+=1,x=!0,[3,10];case 9:throw L=Ee.sent(),console.warn("[Call] waiting for stream slot failed:",L),L;case 10:return[4,k.newStream(this.protocol,{maxOutboundStreams:50,signal:AbortSignal.timeout(1e4),negotiateFully:!1})];case 11:return g=Ee.sent(),[4,this.getStreamManagerFor(k).getNextAppLevelStreamId()];case 12:D=Ee.sent(),z=new _(g,{bufferSize:16777216});try{z.addEventListener("backpressure",function(e){var t=e.detail||{};console.warn("[stream ".concat(D,"] backpressure current=").concat(t.currentSize," avg=").concat(t.averageSize," threshold=").concat(t.threshold))}),z.addEventListener("drain",function(){}),z.addEventListener("stalled",function(e){var t,r=e.detail||{};console.warn("[stream ".concat(D,"] stalled queue=").concat(r.queueSize," drained=").concat(r.drained," since=").concat(r.sinceMs,"ms — sending PING"));try{var n=new Uint8Array(8);null===(t=crypto.getRandomValues)||void 0===t||t.call(crypto,n);var i=I.createFrame(6,0,0,n);z.write(i)}catch(e){}})}catch(e){}if((H=new F(z,{compatibilityMode:!w})).onGoaway=function(e){console.warn("[Call] GOAWAY received from server",e),C&&Se.connectionPool.delete(C),P&&Se.rejectStreamWaiters(P,new Error("Connection received GOAWAY")),y(new Error("GOAWAY received: code=".concat(e.errorCode)));try{null==k||k.close()}catch(e){console.warn("Error closing connection after GOAWAY:",e)}},H.onSettingsParsed=function(e){P&&void 0!==e.maxConcurrentStreams&&e.maxConcurrentStreams>0&&(P.maxConcurrentStreams=e.maxConcurrentStreams,Se.notifyStreamSlotAvailable(P))},w&&H.registerOutboundStream(D),M=i>0?i:j,U=function(e){return r(Se,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return w?[4,this.sendFrameWithFlowControl(H,D,e,z,f.signal,M)]:[3,2];case 1:return t.sent(),[3,4];case 2:if(f.signal.aborted)throw new Error("Operation aborted");return[4,z.write(e)];case 3:t.sent(),t.label=4;case 4:return[2]}})})},q=function(e){return r(Se,void 0,void 0,function(){var t,r,i;return n(this,function(n){switch(n.label){case 0:t=0,r=e,n.label=1;case 1:return t<r.length?(i=r[t],[4,U(i)]):[3,4];case 2:n.sent(),n.label=3;case 3:return t++,[3,1];case 4:return[2]}})})},H.onData=function(e){return r(Se,void 0,void 0,function(){var t,r,i,a;return n(this,function(n){if(f.signal.aborted)return[2];try{for(S.push(e),E+=e.length;E>0;){if(f.signal.aborted)return[2];if(-1===T&&E>=5&&(r=W(),S=[r],t=r.slice(1,5),T=new DataView(t.buffer,t.byteOffset).getUint32(0,!1)),!(-1!==T&&E>=T+5))break;r=W(),S=[r],i=r.slice(5,T+5),o(i),a=r.slice(T+5),S=a.length>0?[a]:[],E=a.length,T=-1}}catch(e){y(e)}return[2]})})},H.onSettings=function(){if(!f.signal.aborted){var e=I.createSettingsAckFrame();z.write(e)}},H.onHeaders=function(e){if(!f.signal.aborted){var t=A.decodeHeaderFields(e);if("0"===t.get("grpc-status"));else if(void 0!==t.get("grpc-status")){var r=t.get("grpc-message")||"gRPC call failed";y(new Error(r))}}},H.processStream(g).catch(function(e){f.signal.aborted||(console.error("Error in processStream:",e),y(e))}),f.signal.aborted)throw new Error("Operation aborted");return B=I.createPreface(),[4,z.write(B)];case 13:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return G=I.createSettingsFrame(),[4,z.write(G)];case 14:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return[4,Promise.race([H.waitForPeerSettings(1e3).catch(function(){}),H.waitForSettingsAck().catch(function(){}),new Promise(function(e){return setTimeout(e,300)})])];case 15:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return N=I.createHeadersFrame(D,e,!0,this.token,this.getAuthority()),"unary"!==a&&"server-streaming"!==a?[3,18]:[4,z.write(N)];case 16:return Ee.sent(),R=I.createDataFrames(D,t,!0),[4,q(R)];case 17:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return[3,45];case 18:return"client-streaming"!==a&&"bidirectional"!==a||!c?[3,45]:[4,z.write(N)];case 19:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return t.length>0?(Q=I.createDataFrames(D,t,!1),[4,q(Q)]):[3,21];case 20:Ee.sent(),Ee.label=21;case 21:Y=(null==d?void 0:d.batchSize)||10,V=[],Z=[],K=!1,X=function(){for(var e=0,t=Z.splice(0);e<t.length;e++){var r=t[e];try{r()}catch(e){}}},J=function(){return r(Se,void 0,void 0,function(){var e,t,r,i,a,o,s;return n(this,function(n){switch(n.label){case 0:if(K||0===V.length)return[2];K=!0,e=[],n.label=1;case 1:if(n.trys.push([1,9,10,11]),!((e=V.splice(0,Math.min(Y,V.length))).length>1))return[3,6];t=0,r=e,n.label=2;case 2:if(!(t<r.length))return[3,5];if(a=r[t],f.signal.aborted)throw new Error("Operation aborted");return i=I.createDataFrames(D,a.chunk,!1),[4,q(i)];case 3:n.sent(),n.label=4;case 4:return t++,[3,2];case 5:return e.forEach(function(e){return e.resolve()}),[3,8];case 6:return 1!==e.length?[3,8]:(a=e[0],o=I.createDataFrames(D,a.chunk,!1),[4,q(o)]);case 7:n.sent(),a.resolve(),n.label=8;case 8:return[3,11];case 9:return s=n.sent(),e.forEach(function(e){try{e.reject(s)}catch(e){console.warn("Error rejecting promise:",e)}}),[3,11];case 10:return K=!1,V.length>0&&!f.signal.aborted?J().catch(function(e){console.error("Error in processNextBatch:",e)}):X(),[7];case 11:return[2]}})})},$=function(e){return new Promise(function(t,r){f.signal.aborted?r(new Error("Operation aborted")):(V.push({chunk:e,resolve:t,reject:r}),(V.length>=Y||!K)&&J().catch(function(e){console.error("Error in processNextBatch:",e)}))})},Ee.label=22;case 22:Ee.trys.push([22,36,,37]),Ee.label=23;case 23:Ee.trys.push([23,29,30,35]),ee=!0,te=s(c()),Ee.label=24;case 24:return[4,te.next()];case 25:if(re=Ee.sent(),pe=re.done)return[3,28];if(ve=re.value,ee=!1,ne=ve,f.signal.aborted)throw new Error("Operation aborted");return ie=Array.isArray(ne)?ne:[ne],ae=ie.map(function(e){return $(e)}),[4,Promise.all(ae)];case 26:Ee.sent(),Ee.label=27;case 27:return ee=!0,[3,24];case 28:return[3,35];case 29:return oe=Ee.sent(),ge={error:oe},[3,35];case 30:return Ee.trys.push([30,,33,34]),ee||pe||!(me=te.return)?[3,32]:[4,me.call(te)];case 31:Ee.sent(),Ee.label=32;case 32:return[3,34];case 33:if(ge)throw ge.error;return[7];case 34:return[7];case 35:return[3,37];case 36:throw se=Ee.sent(),V.splice(0).forEach(function(e){try{e.reject(se)}catch(e){console.warn("Error rejecting remaining promise:",e)}}),se;case 37:return[4,new Promise(function(e,t){var r=function(){f.signal.aborted?t(new Error("Operation aborted")):0!==V.length||K?Z.push(r):e()};r()})];case 38:if(Ee.sent(),f.signal.aborted)throw new Error("Operation aborted");return ce=I.createFrame(0,1,D,new Uint8Array(0)),[4,U(ce)];case 39:Ee.sent(),Ee.label=40;case 40:return Ee.trys.push([40,42,,43]),[4,z.flush(i)];case 41:case 42:return Ee.sent(),[3,43];case 43:return[4,z.end()];case 44:Ee.sent(),Ee.label=45;case 45:if(f.signal.aborted)throw new Error("Operation aborted");return f.signal.aborted?[3,48]:[4,H.waitForEndOfStream(0)];case 46:return Ee.sent(),[4,Promise.resolve()];case 47:Ee.sent(),!f.signal.aborted&&u&&u(),Ee.label=48;case 48:return[3,64];case 49:return ue=Ee.sent(),f.signal.aborted&&ue instanceof Error&&"Operation aborted"===ue.message?!v&&l&&l(new Error("Operation cancelled by user")):!v&&l?l(ue):v||(ue instanceof Error?console.error("asyncCall error:",ue.message):console.error("asyncCall error:",ue)),[3,64];case 50:if(clearTimeout(p),m&&(null==h?void 0:h.signal)&&h.signal.removeEventListener("abort",m),f.abort(),null==z||z.abort("Call cleanup"),!g)return[3,54];Ee.label=51;case 51:return Ee.trys.push([51,53,,54]),[4,g.close()];case 52:case 53:return Ee.sent(),[3,54];case 54:if(!(null==d?void 0:d.freshConnection))return[3,63];Ee.label=55;case 55:Ee.trys.push([55,62,,63]),le=(null===(we=(be=this.node).getConnections)||void 0===we?void 0:we.call(be,this.peerAddr))||[],he=0,de=le,Ee.label=56;case 56:if(!(he<de.length))return[3,61];fe=de[he],Ee.label=57;case 57:return Ee.trys.push([57,59,,60]),[4,null===(ye=fe.close)||void 0===ye?void 0:ye.call(fe)];case 58:case 59:return Ee.sent(),[3,60];case 60:return he++,[3,56];case 61:return[3,63];case 62:return Ee.sent(),[3,63];case 63:return x&&P&&(P.activeStreams=Math.max(0,P.activeStreams-1),this.notifyStreamSlotAvailable(P)),[7];case 64:return[2]}})}),k.label=1;case 1:return k.trys.push([1,3,,4]),[4,Promise.race([E,S])];case 2:return k.sent(),[2,y];case 3:throw T=k.sent(),y(),T;case 4:return[2]}})})},e}();e.Libp2pGrpcClient=B});//# sourceMappingURL=grpc.min.js.map
|
package/dist/index.cjs.js
CHANGED
|
@@ -2219,7 +2219,7 @@ class Libp2pGrpcClient {
|
|
|
2219
2219
|
throw err;
|
|
2220
2220
|
}
|
|
2221
2221
|
stream = await connection.newStream(this.protocol, {
|
|
2222
|
-
maxOutboundStreams:
|
|
2222
|
+
maxOutboundStreams: 50,
|
|
2223
2223
|
negotiateFully: false,
|
|
2224
2224
|
});
|
|
2225
2225
|
const streamManager = this.getStreamManagerFor(connection);
|
package/dist/index.esm.js
CHANGED
|
@@ -2217,7 +2217,7 @@ class Libp2pGrpcClient {
|
|
|
2217
2217
|
throw err;
|
|
2218
2218
|
}
|
|
2219
2219
|
stream = await connection.newStream(this.protocol, {
|
|
2220
|
-
maxOutboundStreams:
|
|
2220
|
+
maxOutboundStreams: 50,
|
|
2221
2221
|
negotiateFully: false,
|
|
2222
2222
|
});
|
|
2223
2223
|
const streamManager = this.getStreamManagerFor(connection);
|
package/dist/stats.html
CHANGED
|
@@ -4929,7 +4929,7 @@ var drawChart = (function (exports) {
|
|
|
4929
4929
|
</script>
|
|
4930
4930
|
<script>
|
|
4931
4931
|
/*<!--*/
|
|
4932
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"grpc.min.js","children":[{"name":"node_modules","children":[{"name":"tslib/tslib.es6.js","uid":"
|
|
4932
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"grpc.min.js","children":[{"name":"node_modules","children":[{"name":"tslib/tslib.es6.js","uid":"b174a134-1"},{"name":"p-defer/index.js","uid":"b174a134-13"},{"name":"it-pushable/dist/src","children":[{"uid":"b174a134-15","name":"fifo.js"},{"uid":"b174a134-17","name":"index.js"}]}]},{"name":"src","children":[{"name":"dc-http2","children":[{"uid":"b174a134-3","name":"types.ts"},{"uid":"b174a134-5","name":"hpack.ts"},{"uid":"b174a134-7","name":"encoder.ts"},{"uid":"b174a134-9","name":"frame.ts"},{"uid":"b174a134-11","name":"parser.ts"},{"uid":"b174a134-19","name":"stream.ts"}]},{"uid":"b174a134-21","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"b174a134-1":{"renderedLength":6736,"gzipLength":2359,"brotliLength":2009,"metaUid":"b174a134-0"},"b174a134-3":{"renderedLength":361,"gzipLength":292,"brotliLength":227,"metaUid":"b174a134-2"},"b174a134-5":{"renderedLength":22089,"gzipLength":5194,"brotliLength":4404,"metaUid":"b174a134-4"},"b174a134-7":{"renderedLength":2534,"gzipLength":899,"brotliLength":758,"metaUid":"b174a134-6"},"b174a134-9":{"renderedLength":10859,"gzipLength":3245,"brotliLength":2688,"metaUid":"b174a134-8"},"b174a134-11":{"renderedLength":30669,"gzipLength":6794,"brotliLength":5673,"metaUid":"b174a134-10"},"b174a134-13":{"renderedLength":181,"gzipLength":136,"brotliLength":117,"metaUid":"b174a134-12"},"b174a134-15":{"renderedLength":2109,"gzipLength":660,"brotliLength":569,"metaUid":"b174a134-14"},"b174a134-17":{"renderedLength":6157,"gzipLength":1606,"brotliLength":1406,"metaUid":"b174a134-16"},"b174a134-19":{"renderedLength":37765,"gzipLength":7719,"brotliLength":6409,"metaUid":"b174a134-18"},"b174a134-21":{"renderedLength":90361,"gzipLength":13635,"brotliLength":11059,"metaUid":"b174a134-20"}},"nodeMetas":{"b174a134-0":{"id":"/node_modules/tslib/tslib.es6.js","moduleParts":{"grpc.min.js":"b174a134-1"},"imported":[],"importedBy":[{"uid":"b174a134-20"},{"uid":"b174a134-10"},{"uid":"b174a134-18"},{"uid":"b174a134-8"}]},"b174a134-2":{"id":"/src/dc-http2/types.ts","moduleParts":{"grpc.min.js":"b174a134-3"},"imported":[],"importedBy":[{"uid":"b174a134-10"}]},"b174a134-4":{"id":"/src/dc-http2/hpack.ts","moduleParts":{"grpc.min.js":"b174a134-5"},"imported":[],"importedBy":[{"uid":"b174a134-20"},{"uid":"b174a134-8"}]},"b174a134-6":{"id":"/src/dc-http2/encoder.ts","moduleParts":{"grpc.min.js":"b174a134-7"},"imported":[],"importedBy":[{"uid":"b174a134-8"}]},"b174a134-8":{"id":"/src/dc-http2/frame.ts","moduleParts":{"grpc.min.js":"b174a134-9"},"imported":[{"uid":"b174a134-0"},{"uid":"b174a134-4"},{"uid":"b174a134-6"}],"importedBy":[{"uid":"b174a134-20"},{"uid":"b174a134-10"}]},"b174a134-10":{"id":"/src/dc-http2/parser.ts","moduleParts":{"grpc.min.js":"b174a134-11"},"imported":[{"uid":"b174a134-0"},{"uid":"b174a134-2"},{"uid":"b174a134-8"}],"importedBy":[{"uid":"b174a134-20"}]},"b174a134-12":{"id":"/node_modules/p-defer/index.js","moduleParts":{"grpc.min.js":"b174a134-13"},"imported":[],"importedBy":[{"uid":"b174a134-16"}]},"b174a134-14":{"id":"/node_modules/it-pushable/dist/src/fifo.js","moduleParts":{"grpc.min.js":"b174a134-15"},"imported":[],"importedBy":[{"uid":"b174a134-16"}]},"b174a134-16":{"id":"/node_modules/it-pushable/dist/src/index.js","moduleParts":{"grpc.min.js":"b174a134-17"},"imported":[{"uid":"b174a134-12"},{"uid":"b174a134-14"}],"importedBy":[{"uid":"b174a134-18"}]},"b174a134-18":{"id":"/src/dc-http2/stream.ts","moduleParts":{"grpc.min.js":"b174a134-19"},"imported":[{"uid":"b174a134-0"},{"uid":"b174a134-16"}],"importedBy":[{"uid":"b174a134-20"}]},"b174a134-20":{"id":"/src/index.ts","moduleParts":{"grpc.min.js":"b174a134-21"},"imported":[{"uid":"b174a134-0"},{"uid":"b174a134-10"},{"uid":"b174a134-18"},{"uid":"b174a134-8"},{"uid":"b174a134-4"}],"importedBy":[],"isEntry":true}},"env":{"rollup":"4.60.1"},"options":{"gzip":true,"brotli":true,"sourcemap":false}};
|
|
4933
4933
|
|
|
4934
4934
|
const run = () => {
|
|
4935
4935
|
const width = window.innerWidth;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -369,7 +369,7 @@ export class Libp2pGrpcClient {
|
|
|
369
369
|
throw err;
|
|
370
370
|
}
|
|
371
371
|
stream = await connection.newStream(this.protocol, {
|
|
372
|
-
maxOutboundStreams:
|
|
372
|
+
maxOutboundStreams: 50,
|
|
373
373
|
negotiateFully: false,
|
|
374
374
|
});
|
|
375
375
|
const streamManager = this.getStreamManagerFor(connection as object);
|