spacewave 0.57.21 → 0.57.23
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/THIRD_PARTY_NOTICES.txt +9 -9
- package/dist/build.json +1 -1
- package/dist/chunks/json-9p1QyRAu.mjs +2 -0
- package/dist/chunks/node.pb-QNjWnpTx.mjs +2 -0
- package/dist/engine-worker.mjs +99 -99
- package/dist/index.mjs +1 -1
- package/dist/react.mjs +1 -1
- package/dist/server.mjs +3 -3
- package/examples/task-board/package.json +1 -1
- package/package.json +1 -1
- package/dist/chunks/json-D4YdjcVu.mjs +0 -2
- package/dist/chunks/node.pb-VgU29ra5.mjs +0 -2
|
@@ -6,7 +6,7 @@ This project is dual licensed under MIT and Apache-2.0.
|
|
|
6
6
|
MIT: https://www.opensource.org/licenses/mit
|
|
7
7
|
Apache-2.0: https://www.apache.org/licenses/license-2.0
|
|
8
8
|
|
|
9
|
-
@aptre/protobuf-es-lite 1.1.
|
|
9
|
+
@aptre/protobuf-es-lite 1.1.5
|
|
10
10
|
=============================
|
|
11
11
|
|
|
12
12
|
Apache License
|
|
@@ -861,7 +861,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
861
861
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
862
862
|
SOFTWARE.
|
|
863
863
|
|
|
864
|
-
github.com/aperturerobotics/bbolt/errors v0.0.0-
|
|
864
|
+
github.com/aperturerobotics/bbolt/errors v0.0.0-20261004101904-ce8197909cd4
|
|
865
865
|
===========================================================================
|
|
866
866
|
|
|
867
867
|
The MIT License (MIT)
|
|
@@ -1600,7 +1600,7 @@ Apache License
|
|
|
1600
1600
|
incurred by, or claims asserted against, such Contributor by reason
|
|
1601
1601
|
of your accepting any such warranty or additional liability.
|
|
1602
1602
|
|
|
1603
|
-
github.com/aperturerobotics/starpc v0.52.
|
|
1603
|
+
github.com/aperturerobotics/starpc v0.52.3-0.20261003025950-d2cfc2af89e9
|
|
1604
1604
|
========================================================================
|
|
1605
1605
|
|
|
1606
1606
|
Copyright (c) 2022-2025 Aperture Robotics, LLC.
|
|
@@ -2191,8 +2191,8 @@ SOFTWARE.
|
|
|
2191
2191
|
|
|
2192
2192
|
<http://www.opensource.org/licenses/mit-license.php>
|
|
2193
2193
|
|
|
2194
|
-
github.com/go-git/go-billy/v6 v6.0.0-
|
|
2195
|
-
|
|
2194
|
+
github.com/go-git/go-billy/v6 v6.0.0-beta.1
|
|
2195
|
+
===========================================
|
|
2196
2196
|
|
|
2197
2197
|
Apache License
|
|
2198
2198
|
Version 2.0, January 2004
|
|
@@ -2601,7 +2601,7 @@ Apache License
|
|
|
2601
2601
|
See the License for the specific language governing permissions and
|
|
2602
2602
|
limitations under the License.
|
|
2603
2603
|
|
|
2604
|
-
github.com/klauspost/compress/internal v1.20.2-0.
|
|
2604
|
+
github.com/klauspost/compress/internal v1.20.2-0.20261004115517-d189b4c2eb01
|
|
2605
2605
|
============================================================================
|
|
2606
2606
|
|
|
2607
2607
|
Copyright (c) 2012 The Go Authors. All rights reserved.
|
|
@@ -2909,7 +2909,7 @@ The above copyright notice and this permission notice shall be included in all c
|
|
|
2909
2909
|
|
|
2910
2910
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
2911
2911
|
|
|
2912
|
-
github.com/klauspost/compress/s2 v1.20.2-0.
|
|
2912
|
+
github.com/klauspost/compress/s2 v1.20.2-0.20261004115517-d189b4c2eb01
|
|
2913
2913
|
======================================================================
|
|
2914
2914
|
|
|
2915
2915
|
Copyright (c) 2011 The Snappy-Go Authors. All rights reserved.
|
|
@@ -3439,7 +3439,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
3439
3439
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
3440
3440
|
THE SOFTWARE.
|
|
3441
3441
|
|
|
3442
|
-
github.com/tidwall/btree v1.8.
|
|
3442
|
+
github.com/tidwall/btree v1.8.2
|
|
3443
3443
|
===============================
|
|
3444
3444
|
|
|
3445
3445
|
Copyright (c) 2020 Josh Baker
|
|
@@ -4157,7 +4157,7 @@ Licensed under either of
|
|
|
4157
4157
|
|
|
4158
4158
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
|
4159
4159
|
|
|
4160
|
-
starpc 0.52.
|
|
4160
|
+
starpc 0.52.2
|
|
4161
4161
|
=============
|
|
4162
4162
|
|
|
4163
4163
|
Copyright (c) 2022-2025 Aperture Robotics, LLC.
|
package/dist/build.json
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);const t=`ERR_RPC_ABORT`;function n(e){return typeof e==`object`&&e.message===t}var r=class extends Error{rpcService;rpcMethod;rpcError;constructor(e,t,n){super(n),this.name=`RemoteRPCError`,this.rpcService=e,this.rpcMethod=t,this.rpcError=n}};function i(e,t){if(t||=`error`,!e)return Error(t);if(typeof e==`string`)return Error(e);let n=e;if(n.message)return n;if(e.toString){let t=e.toString();if(t)return Error(t)}return Error(t)}function a(){let e={};return e.promise=new Promise((t,n)=>{e.resolve=t,e.reject=n}),e}var o=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw Error(`Max size for a FixedFIFO should be a power of two`);this.buffer=Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]===void 0&&(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},s=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new o(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength==null?1:e.byteLength}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new o(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}},c=class extends Error{type;code;constructor(e,t){super(e??`The operation was aborted`),this.type=`aborted`,this.code=t??`ABORT_ERR`}};function l(e={}){return ee(e=>{let t=e.shift();if(t==null)return{done:!0};if(t.error!=null)throw t.error;return{done:t.done===!0,value:t.value}},e)}function ee(e,t){t??={};let n=t.onEnd,r=new s,i,o,l,ee=a(),te=async()=>{try{return r.isEmpty()?l?{done:!0}:await new Promise((t,n)=>{o=a=>{o=null,r.push(a);try{t(e(r))}catch(e){n(e)}return i}}):e(r)}finally{r.isEmpty()&&queueMicrotask(()=>{ee.resolve(),ee=a()})}},u=e=>o==null?(r.push(e),i):o(e),ne=e=>(r=new s,o==null?(r.push({error:e}),i):o({error:e})),re=e=>{if(l)return i;if(t?.objectMode!==!0&&e?.byteLength==null)throw Error(`objectMode was not true but tried to push non-Uint8Array value`);return u({done:!1,value:e})},d=e=>l?i:(l=!0,e==null?u({done:!0}):ne(e)),ie=()=>(r=new s,d(),{done:!0}),ae=e=>(d(e),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:te,return:ie,throw:ae,push:re,end:d,get readableLength(){return r.size},onEmpty:async e=>{let t=e?.signal;if(t?.throwIfAborted(),r.isEmpty())return;let n,i;t!=null&&(n=new Promise((e,n)=>{i=()=>{n(new c)},t.addEventListener(`abort`,i)}));try{await Promise.race([ee.promise,n])}finally{i!=null&&t!=null&&t?.removeEventListener(`abort`,i)}}},n==null)return i;let f=i;return i={[Symbol.asyncIterator](){return this},next(){return f.next()},throw(e){return f.throw(e),n!=null&&(n(e),n=void 0),{done:!0}},return(){return f.return(),n!=null&&(n(),n=void 0),{done:!0}},push:re,end(e){return f.end(e),n!=null&&(n(e),n=void 0),i},get readableLength(){return f.readableLength},onEmpty:e=>f.onEmpty(e)},i}var te=class extends Error{type;code;constructor(e,t,n){super(e??`The operation was aborted`),this.type=`aborted`,this.name=n??`AbortError`,this.code=t??`ABORT_ERR`}};async function u(e,t,n){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new te(n?.errorMessage,n?.errorCode,n?.errorName));let r,i=new te(n?.errorMessage,n?.errorCode,n?.errorName);try{return await Promise.race([e,new Promise((e,n)=>{r=()=>{n(i)},t.addEventListener(`abort`,r)})])}finally{r!=null&&t.removeEventListener(`abort`,r)}}var ne=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=a(),this.haveNext=a()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult??await this.haveNext.promise,this.nextResult==null)throw Error(`HaveNext promise resolved but nextResult was undefined`);let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=a(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,t){await this._push(e,t)}async end(e,t){e==null?await this._push(void 0,t):await this.throw(e)}async _push(e,t){if(e!=null&&this.ended)throw this.error??Error(`Cannot push value onto an ended pushable`);for(;this.nextResult!=null;)await this.readNext.promise;e==null?(this.ended=!0,this.nextResult={done:!0,value:void 0}):this.nextResult={done:!1,value:e},this.haveNext.resolve(),this.haveNext=a(),await u(this.readNext.promise,t?.signal,t)}};function re(){return new ne}function d(e){return e[Symbol.asyncIterator]!=null}async function ie(e,t,n){try{await Promise.all(e.map(async e=>{for await(let r of e)await t.push(r,{signal:n}),n.throwIfAborted()})),await t.end(void 0,{signal:n})}catch(e){await t.end(e,{signal:n}).catch(()=>{})}}async function*ae(e){let t=new AbortController,n=re();ie(e,n,t.signal).catch(()=>{});try{yield*n}finally{t.abort()}}function*f(e){for(let t of e)yield*t}function oe(...e){let t=[];for(let n of e)d(n)||t.push(n);return t.length===e.length?f(t):ae(e)}function p(e,...t){if(e==null)throw Error(`Empty pipeline`);if(ue(e)){let t=e;e=()=>t.source}else if(le(e)||ce(e)){let t=e;e=()=>t}let n=[e,...t];if(n.length>1&&ue(n[n.length-1])&&(n[n.length-1]=n[n.length-1].sink),n.length>2)for(let e=1;e<n.length-1;e++)ue(n[e])&&(n[e]=de(n[e]));return se(...n)}const se=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},ce=e=>e?.[Symbol.asyncIterator]!=null,le=e=>e?.[Symbol.iterator]!=null,ue=e=>e!=null&&e.sink!=null&&e.source!=null,de=e=>t=>{let n=e.sink(t);if(n?.then!=null){let t=l({objectMode:!0});n.then(()=>{t.end()},e=>{t.end(e)});let r,i=e.source;if(ce(i))r=async function*(){yield*i,t.end()};else if(le(i))r=function*(){yield*i,t.end()};else throw Error(`Unknown duplex source type - must be Iterable or AsyncIterable`);return oe(t,r())}return e.source};function m(e,t){if(!e)throw Error(t)}function h(e){if(typeof e!=`number`)throw Error(`invalid int 32: `+typeof e);if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw Error(`invalid int 32: `+e)}function fe(e){if(typeof e!=`number`)throw Error(`invalid uint 32: `+typeof e);if(!Number.isInteger(e)||e>4294967295||e<0)throw Error(`invalid uint 32: `+e)}function pe(e){if(typeof e!=`number`)throw Error(`invalid float 32: `+typeof e);if(Number.isFinite(e)&&(e>34028234663852886e22||e<-34028234663852886e22))throw Error(`invalid float 32: `+e)}function me(){let e=0,t=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(e|=(r&127)<<n,!(r&128))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(n&15)<<28,t=(n&112)>>4,!(n&128))return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(t|=(r&127)<<n,!(r&128))return this.assertBounds(),[e,t]}throw Error(`invalid varint`)}function he(e,t,n){for(let r=0;r<28;r+=7){let i=e>>>r,a=!(!(i>>>7)&&t==0),o=(a?i|128:i)&255;if(n.push(o),!a)return}let r=e>>>28&15|(t&7)<<4,i=!!(t>>3);if(n.push((i?r|128:r)&255),i){for(let e=3;e<31;e+=7){let r=t>>>e,i=!!(r>>>7),a=(i?r|128:r)&255;if(n.push(a),!i)return}n.push(t>>>31&1)}}const g=4294967296;function ge(e){let t=e[0]===`-`;t&&(e=e.slice(1));let n=1e6,r=0,i=0;function a(t,a){let o=Number(e.slice(t,a));i*=n,r=r*n+o,r>=g&&(i+=r/g|0,r%=g)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?xe(r,i):be(r,i)}function _e(e,t){let n=be(e,t),r=n.hi&2147483648;r&&(n=xe(n.lo,n.hi));let i=ve(n.lo,n.hi);return r?`-`+i:i}function ve(e,t){if({lo:e,hi:t}=ye(e,t),t<=2097151)return String(g*t+e);let n=e&16777215,r=(e>>>24|t<<8)&16777215,i=t>>16&65535,a=n+r*6777216+i*6710656,o=r+i*8147497,s=i*2,c=1e7;return a>=c&&(o+=Math.floor(a/c),a%=c),o>=c&&(s+=Math.floor(o/c),o%=c),s.toString()+Se(o)+Se(a)}function ye(e,t){return{lo:e>>>0,hi:t>>>0}}function be(e,t){return{lo:e|0,hi:t|0}}function xe(e,t){return t=~t,e?e=~e+1:t+=1,be(e,t)}const Se=e=>{let t=String(e);return`0000000`.slice(t.length)+t};function Ce(e,t){if(e>=0){for(;e>127;)t.push(e&127|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(e&127|128),e>>=7;t.push(1)}}function we(){let e=this.buf[this.pos++],t=e&127;if(!(e&128)||(e=this.buf[this.pos++],t|=(e&127)<<7,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<14,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<21,!(e&128)))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let t=5;e&128&&t<10;t++)e=this.buf[this.pos++];if(e&128)throw Error(`invalid varint`);return this.assertBounds(),t>>>0}function Te(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt==`function`&&typeof e.getBigInt64==`function`&&typeof e.getBigUint64==`function`&&typeof e.setBigInt64==`function`&&typeof e.setBigUint64==`function`&&(typeof process!=`object`||typeof process.env!=`object`||process.env.BUF_BIGINT_DISABLE!==`1`)){let t=BigInt(`-9223372036854775808`),n=BigInt(`9223372036854775807`),r=BigInt(`0`),i=BigInt(`18446744073709551615`);return{zero:BigInt(0),supported:!0,parse(e){let r=typeof e==`bigint`?e:BigInt(e);if(r>n||r<t)throw Error(`int64 invalid: ${e}`);return r},uParse(e){let t=typeof e==`bigint`?e:BigInt(e);if(t>i||t<r)throw Error(`uint64 invalid: ${e}`);return t},enc(t){return e.setBigInt64(0,this.parse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(t){return e.setBigInt64(0,this.uParse(t),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigInt64(0,!0)},uDec(t,n){return e.setInt32(0,t,!0),e.setInt32(4,n,!0),e.getBigUint64(0,!0)}}}let t=e=>m(/^-?[0-9]+$/.test(e),`int64 invalid: ${e}`),n=e=>m(/^[0-9]+$/.test(e),`uint64 invalid: ${e}`);return{zero:`0`,supported:!1,parse(e){return typeof e!=`string`&&(e=e.toString()),t(e),e},uParse(e){return typeof e!=`string`&&(e=e.toString()),n(e),e},enc(e){return typeof e!=`string`&&(e=e.toString()),t(e),ge(e)},uEnc(e){return typeof e!=`string`&&(e=e.toString()),n(e),ge(e)},dec(e,t){return _e(e,t)},uDec(e,t){return ve(e,t)}}}const _=Te();var v;(function(e){e[e.DOUBLE=1]=`DOUBLE`,e[e.FLOAT=2]=`FLOAT`,e[e.INT64=3]=`INT64`,e[e.UINT64=4]=`UINT64`,e[e.INT32=5]=`INT32`,e[e.FIXED64=6]=`FIXED64`,e[e.FIXED32=7]=`FIXED32`,e[e.BOOL=8]=`BOOL`,e[e.STRING=9]=`STRING`,e[e.BYTES=12]=`BYTES`,e[e.UINT32=13]=`UINT32`,e[e.SFIXED32=15]=`SFIXED32`,e[e.SFIXED64=16]=`SFIXED64`,e[e.SINT32=17]=`SINT32`,e[e.SINT64=18]=`SINT64`,e[e.DATE=100]=`DATE`})(v||={});var y;(function(e){e[e.BIGINT=0]=`BIGINT`,e[e.STRING=1]=`STRING`})(y||={});function Ee(e,t,n){if(t===n)return!0;if(t==null||n==null)return t===n;if(e==v.BYTES){if(!(t instanceof Uint8Array)||!(n instanceof Uint8Array)||t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}if(e==v.DATE){let e=ke(t,!1),r=ke(n,!1);return e==null||r==null?e===r:e!=null&&r!=null&&+e==+r}switch(e){case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return t==n}return!1}function b(e,t){switch(e){case v.BOOL:return!1;case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return t==0?_.zero:`0`;case v.DOUBLE:case v.FLOAT:return 0;case v.BYTES:return new Uint8Array;case v.STRING:return``;case v.DATE:return null;default:return 0}}const De=+new Date(0);function x(e,t){if(t==null)return!0;switch(e){case v.DATE:return+t===De;case v.BOOL:return t===!1;case v.STRING:return t===``;case v.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return t==0}}function S(e,t,n,r=y.BIGINT){return t==null?b(e,r):e===v.BYTES?Oe(t,n):x(e,t)?b(e,r):e===v.DATE?ke(t,n):t}function Oe(e,t){return!t&&e instanceof Uint8Array?e:new Uint8Array(e)}function ke(e,t){if(e instanceof Date)return t?new Date(e.getTime()):e;if(typeof e==`string`||typeof e==`number`){let t=new Date(e);return isNaN(t.getTime())?null:t}return null}function Ae(e,t){let n=Me(e);return t?n:Le(Ie(n))}function je(e){return Ae(e,!1)}function Me(e){let t=!1,n=[];for(let r=0;r<e.length;r++){let i=e.charAt(r);switch(i){case`_`:t=!0;break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n.push(i),t=!1;break;default:t&&(t=!1,i=i.toUpperCase()),n.push(i)}}return n.join(``)}const Ne=new Set([`constructor`,`toString`,`toJSON`,`valueOf`,`__proto__`,`prototype`]),Pe=new Set([`__proto__`]),Fe=e=>`${e}$`,Ie=e=>Pe.has(e)?Fe(e):e,Le=e=>Ne.has(e)?Fe(e):e;function Re(e){return typeof e==`string`&&!!e.length&&!Ne.has(e)}function C(e){if(typeof e!=`string`)throw Error(`illegal non-string object key: `+typeof e);if(!Re(e))throw Error(`illegal object key: `+e)}var ze=class{_fields;_normalizer;all;numbersAsc;jsonNames;numbers;members;constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){let e={};for(let t of this.list())e[t.jsonName]=e[t.name]=t;this.jsonNames=e}return this.jsonNames[e]}find(e){if(!this.numbers){let e={};for(let t of this.list())e[t.no]=t;this.numbers=e}return this.numbers[e]}list(){return this.all||=this._normalizer(this._fields),this.all}byNumber(){return this.numbersAsc||=this.list().concat().sort((e,t)=>e.no-t.no),this.numbersAsc}byMember(){if(!this.members){this.members=[];let e=this.members,t;for(let n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}};function Be(e,t){return new ze(e,e=>We(e,t))}function Ve(e,t){let n=e.localName;if(!t)return!1;if(e.repeated)return!!t[n]?.length;if(e.oneof)return t[e.oneof.localName]?.case===n;switch(e.kind){case`enum`:case`scalar`:return e.opt||e.req?t[n]!=null:e.kind==`enum`?t[n]!==e.T.values[0].no:!x(e.T,t[n]);case`message`:return t[n]!=null;case`map`:return t[n]!=null&&!!Object.keys(t[n]).length}}const He=Me;function w(e){return e instanceof Function?e():e}var Ue=class{kind=`oneof`;name;localName;repeated=!1;packed=!1;opt=!1;req=!1;default=void 0;fields=[];_lookup;constructor(e){this.name=e,this.localName=je(e)}addField(e){m(e.oneof===this,`field ${e.name} not one of ${this.name}`),this.fields.push(e)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let e=0;e<this.fields.length;e++)this._lookup[this.fields[e].localName]=this.fields[e]}return this._lookup[e]}};function We(e,t){let n=[],r;for(let i of typeof e==`function`?e():e){let e=i;if(e.localName=Ae(i.name,i.oneof!==void 0),e.jsonName=i.jsonName??He(i.name),e.repeated=i.repeated??!1,i.kind==`scalar`&&(e.L=i.L??y.BIGINT,e.utf8=i.utf8??!1),i.kind==`map`&&(e.keyUtf8=i.keyUtf8??!1),e.delimited=i.delimited??!1,e.req=i.req??!1,e.opt=i.opt??!1,i.packed===void 0&&(e.packed=t?i.kind==`enum`||i.kind==`scalar`&&i.T!=v.BYTES&&i.T!=v.STRING:!1),i.oneof!==void 0){let t=typeof i.oneof==`string`?i.oneof:i.oneof.name;(!r||r.name!=t)&&(r=new Ue(t)),e.oneof=r,r.addField(e)}n.push(e)}return n}function Ge(e){return Array.isArray(e)}function Ke(e){return!Array.isArray(e)}function qe(e,t){let n=[];for(let r of Object.keys(e)){let i=e[r];typeof i==`number`&&n.push({no:i,name:t+r,localName:r})}return n}function Je(e,t,n=``){let r=Object.create(null),i=Object.create(null),a=Ke(t)?qe(t,n):t,o=[];for(let e of a){let t=Ge(e)?{no:e[0],name:e[1],localName:e[1]}:`localName`in e?e:{...e,localName:e.name};o.push(t),r[t.name]=t,i[t.no]=t}return{typeName:e,values:o,findName(e){return r[e]},findNumber(e){return i[e]}}}function Ye(e){if(e.values.length<1)throw Error(`invalid enum: missing at least one value`);return e.values[0].no}function Xe(e,t){let n=Ye(e);if(t==null||t===``||t===n)return n;if(typeof t==`string`){let n=e.findName(t);if(!n)throw Error(`enum ${e.typeName}: invalid value: "${t}"`);return n.no}return t}function T(){return{}}function E(){return Object.create(null)}function D(e){return e}function O(e,t,n,r=!1){if(e==null||t==null)return;let i=D(t),a=D(e);for(let e of n.byMember()){let t=e.localName;if(C(t),!(t in a)||a[t]===void 0)continue;let n=a[t];if(n===null){delete i[t];continue}switch(e.kind){case`oneof`:{if(typeof n!=`object`)throw Error(`field ${t}: invalid oneof: must be an object with case and value`);let{case:a,value:o}=n,s=a==null?null:e.findField(a),c=t in i?i[t]:void 0;if(typeof c!=`object`&&(c=T()),a!=null&&s==null)throw Error(`field ${t}: invalid oneof case: ${a}`);if(c.case=a,(c.case!==a||a==null)&&delete c.value,i[t]=c,!s)break;if(s.kind===`message`){let e=c.value;if(typeof e!=`object`&&(e=c.value=T()),o!=null){let t=w(s.T);O(o,e,t.fields)}}else s.kind===`scalar`?c.value=S(s.T,o,r):c.value=o;break}case`scalar`:if(e.repeated){if(!Array.isArray(n))throw Error(`field ${t}: invalid value: must be array`);let a=t in i?i[t]:null;(a==null||!Array.isArray(a))&&(a=i[t]=[]),a.push(...n.map(t=>S(e.T,t,r)));break}i[t]=S(e.T,n,r);break;case`enum`:i[t]=Xe(e.T,n);break;case`map`:{if(typeof n!=`object`)throw Error(`field ${e.localName}: invalid value: must be object`);let a=i[t];typeof a!=`object`&&(a=i[t]=E()),Ze(n,a,e.V,r);break}case`message`:{let r=w(e.T);if(e.repeated){if(!Array.isArray(n))throw Error(`field ${t}: invalid value: must be array`);let e=i[t];Array.isArray(e)||(e=i[t]=[]);for(let t of n)t!=null&&(r.fieldWrapper?e.push(r.fieldWrapper.unwrapField(r.fieldWrapper.wrapField(t))):e.push(r.create(t)));break}if(r.fieldWrapper)i[t]=r.fieldWrapper.unwrapField(r.fieldWrapper.wrapField(n));else{if(typeof n!=`object`)throw Error(`field ${e.localName}: invalid value: must be object`);let a=i[t];typeof a!=`object`&&(a=i[t]=T()),O(n,a,r.fields)}break}}}}function Ze(e,t,n,r){if(e!=null){if(typeof e!=`object`)throw Error(`invalid map: must be object`);switch(n.kind){case`scalar`:for(let[i,a]of Object.entries(e))C(i),a===void 0?delete t[i]:t[i]=S(n.T,a,r);break;case`enum`:for(let[r,i]of Object.entries(e))C(r),i===void 0?delete t[r]:t[r]=Xe(n.T,i);break;case`message`:{let r=w(n.T);for(let[n,i]of Object.entries(e)){if(C(n),i===void 0){delete t[n];continue}if(typeof i!=`object`)throw Error(`invalid value: must be object`);let e=t[n];r.fieldWrapper?e=t[n]=Lt(r.fields):typeof e!=`object`&&(e=t[n]=T()),O(i,e,r.fields)}break}}}}const k=Symbol(`@aptre/protobuf-es-lite/unknown-fields`);function Qe(e,t,n,r){if(typeof e!=`object`)return;let i=e;Array.isArray(i[k])||(i[k]=[]),i[k].push({no:t,wireType:n,data:r})}function $e(e,t){return e?e.wrapField(t):t}function A(e,t){return e?e.unwrapField(t):t}v.DATE,v.DOUBLE,v.FLOAT,v.INT64,v.UINT64,v.INT32,v.UINT32,v.BOOL,v.STRING,v.BYTES;var j;(function(e){e[e.Varint=0]=`Varint`,e[e.Bit64=1]=`Bit64`,e[e.LengthDelimited=2]=`LengthDelimited`,e[e.StartGroup=3]=`StartGroup`,e[e.EndGroup=4]=`EndGroup`,e[e.Bit32=5]=`Bit32`})(j||={});var et=class{chunks;buf;stack=[];textEncoder;constructor(e){this.textEncoder=e??new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let t=0;t<this.chunks.length;t++)e+=this.chunks[t].length;let t=new Uint8Array(e),n=0;for(let e=0;e<this.chunks.length;e++)t.set(this.chunks[e],n),n+=this.chunks[e].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw Error(`invalid state, fork stack empty`);return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(fe(e);e>127;)this.buf.push(e&127|128),e>>>=7;return this.buf.push(e),this}int32(e){return h(e),Ce(e,this.buf),this}bool(e){return this.buf.push(+!!e),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){pe(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){fe(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){h(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return h(e),e=(e<<1^e>>31)>>>0,Ce(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=_.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=_.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=_.enc(e);return he(t.lo,t.hi,this.buf),this}sint64(e){let t=_.enc(e),n=t.hi>>31;return he(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=_.uEnc(e);return he(t.lo,t.hi,this.buf),this}},tt=class{pos;len;buf;view;textDecoder;fatalTextDecoder;constructor(e,t,n){this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t??new TextDecoder,this.fatalTextDecoder=n}tag(){let e=this.uint32(),t=e>>>3,n=e&7;if(t<=0||n<0||n>5)throw Error(`illegal tag: field no `+t+` wire type `+n);return[t,n]}skip(e){let t=this.pos;switch(e){case j.Varint:for(;this.buf[this.pos++]&128;);break;case j.Bit64:this.pos+=4;case j.Bit32:this.pos+=4;break;case j.LengthDelimited:let t=this.uint32();this.pos+=t;break;case j.StartGroup:let n;for(;(n=this.tag()[1])!==j.EndGroup;)this.skip(n);break;default:throw Error(`cant skip wire type `+e)}return this.assertBounds(),this.buf.subarray(t,this.pos)}varint64=me;assertBounds(){if(this.pos>this.len)throw RangeError(`premature EOF`)}uint32=we;int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return _.dec(...this.varint64())}uint64(){return _.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,_.dec(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return _.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return _.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(e=!1){return(e?this.fatalTextDecoder??=new TextDecoder(`utf-8`,{fatal:!0}):this.textDecoder).decode(this.bytes())}};const nt={readUnknownFields:!0,readerFactory:e=>new tt(e)},rt={writeUnknownFields:!0,writerFactory:()=>new et};function it(e){return e?{...nt,...e}:nt}function at(e){return e?{...rt,...e}:rt}function ot(e,t,n,r,i){let{repeated:a}=n,{localName:o}=n;if(n.oneof){let t=e[n.oneof.localName];t||=e[n.oneof.localName]=T(),e=t,e.case!=o&&delete e.value,e.case=o,o=`value`}switch(n.kind){case`scalar`:case`enum`:{let i=n.kind==`enum`?v.INT32:n.T,s=M,c=n.kind==`scalar`&&n.utf8;if(n.kind==`scalar`&&n.L>0&&(s=ct),a){let n=e[o];if(Array.isArray(n)||(n=e[o]=[]),r==j.LengthDelimited&&i!=v.STRING&&i!=v.BYTES){let e=t.uint32()+t.pos;for(;t.pos<e;)n.push(s(t,i,c))}else n.push(s(t,i,c))}else e[o]=s(t,i,c);break}case`message`:{let r=n.T,s=r instanceof Function?r():r;if(a){let r=e[o];Array.isArray(r)||(r=e[o]=[]),r.push(A(s.fieldWrapper,lt(t,T(),s.fields,i,n)))}else e[o]=A(s.fieldWrapper,lt(t,T(),s.fields,i,n));break}case`map`:{let[r,a]=st(n,t,i);typeof e[o]!=`object`&&(e[o]=E()),e[o][r]=a;break}}}function st(e,t,n){let r=t.uint32(),i=t.pos+r,a,o;for(;t.pos<i;){let[r]=t.tag();switch(r){case 1:a=M(t,e.K,e.keyUtf8);break;case 2:switch(e.V.kind){case`scalar`:o=M(t,e.V.T,e.V.utf8===!0);break;case`enum`:o=t.int32();break;case`message`:o=lt(t,T(),w(e.V.T).fields,n,void 0)}}}if(a===void 0&&(a=b(e.K,y.BIGINT)),typeof a!=`string`&&typeof a!=`number`&&(a=a?.toString()??``),o===void 0)switch(e.V.kind){case`scalar`:o=b(e.V.T,y.BIGINT);break;case`enum`:o=e.V.T.values[0].no;break;case`message`:o=T()}return[a,o]}function M(e,t,n=!1){switch(t){case v.STRING:return e.string(n);case v.BOOL:return e.bool();case v.DOUBLE:return e.double();case v.FLOAT:return e.float();case v.INT32:return e.int32();case v.INT64:return e.int64();case v.UINT64:return e.uint64();case v.FIXED64:return e.fixed64();case v.BYTES:return e.bytes();case v.FIXED32:return e.fixed32();case v.SFIXED32:return e.sfixed32();case v.SFIXED64:return e.sfixed64();case v.SINT64:return e.sint64();case v.UINT32:return e.uint32();case v.SINT32:return e.sint32();case v.DATE:throw Error(`cannot read a date with readScalar`);default:throw Error(`unknown scalar type`)}}function ct(e,t,n=!1){let r=M(e,t,n);return typeof r==`bigint`?r.toString():r}function lt(e,t,n,r,i){return ut(t,n,e,i?.delimited?i.no:e.uint32(),r,i?.delimited??!1),t}function ut(e,t,n,r,i,a){let o=a?n.len:n.pos+r,s,c;for(;n.pos<o&&([s,c]=n.tag(),c!=j.EndGroup);){let r=t.find(s);if(!r){let t=n.skip(c);i.readUnknownFields&&Qe(e,s,c,t);continue}ot(e,n,r,c,i)}if(a&&(c!=j.EndGroup||s!==r))throw Error(`invalid end group tag`)}function dt(e,t,n,r){for(let i of t.byNumber()){let t=e;if(!Ve(i,t)){if(i.req)throw Error(`cannot encode field ${i.name} to binary: required field not set`);continue}let a=i.oneof?t[i.oneof.localName].value:t[i.localName];a!==void 0&&ft(i,a,n,r)}r.writeUnknownFields&&pt(e,n)}function ft(e,t,n,r){m(t!==void 0);let i=e.repeated;switch(e.kind){case`scalar`:case`enum`:{let r=e.kind==`enum`?v.INT32:e.T;if(i){if(m(Array.isArray(t)),e.packed)ht(n,r,e.no,t);else for(let i of t)N(n,r,e.no,i)}else N(n,r,e.no,t);break}case`message`:if(i){m(Array.isArray(t));for(let i of t)mt(n,r,e,i)}else mt(n,r,e,t);break;case`map`:m(typeof t==`object`&&!!t);for(let[i,a]of Object.entries(t))_t(n,r,e,i,a)}}function pt(e,t){let n=e[k];if(n)for(let e of n)t.tag(e.no,e.wireType).raw(e.data)}function mt(e,t,n,r){let i=w(n.T),a=$e(i.fieldWrapper,r);n.delimited?e.tag(n.no,j.StartGroup).raw(i.toBinary(a,t)).tag(n.no,j.EndGroup):e.tag(n.no,j.LengthDelimited).bytes(i.toBinary(a,t))}function N(e,t,n,r){m(r!==void 0);let[i,a]=gt(t);e.tag(n,i)[a](r)}function ht(e,t,n,r){if(!r.length)return;e.tag(n,j.LengthDelimited).fork();let[,i]=gt(t);for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}function gt(e){let t=j.Varint;switch(e){case v.BYTES:case v.STRING:t=j.LengthDelimited;break;case v.DOUBLE:case v.FIXED64:case v.SFIXED64:t=j.Bit64;break;case v.FIXED32:case v.SFIXED32:case v.FLOAT:t=j.Bit32}let n=v[e].toLowerCase();return[t,n]}function _t(e,t,n,r,i){e.tag(n.no,j.LengthDelimited),e.fork();let a=r;switch(n.K){case v.INT32:case v.FIXED32:case v.UINT32:case v.SFIXED32:case v.SINT32:a=Number.parseInt(r);break;case v.BOOL:m(r==`true`||r==`false`),a=r==`true`}switch(N(e,n.K,1,a),n.V.kind){case`scalar`:N(e,n.V.T,2,i);break;case`enum`:N(e,v.INT32,2,i);break;case`message`:{m(i!==void 0);let r=w(n.V.T);e.tag(2,j.LengthDelimited).bytes(r.toBinary(i,t));break}}e.join()}let P=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),F=[];for(let e=0;e<P.length;e++)F[P[e].charCodeAt(0)]=e;F[45]=P.indexOf(`+`),F[95]=P.indexOf(`/`);const vt={dec(e){let t=e.length*3/4;e[e.length-2]==`=`?t-=2:e[e.length-1]==`=`&&--t;let n=new Uint8Array(t),r=0,i=0,a,o=0;for(let t=0;t<e.length;t++){if(a=F[e.charCodeAt(t)],a===void 0)switch(e[t]){case`=`:i=0;case`
|
|
2
|
+
`:case`\r`:case` `:case` `:continue;default:throw Error(`invalid base64 string.`)}switch(i){case 0:o=a,i=1;break;case 1:n[r++]=o<<2|(a&48)>>4,o=a,i=2;break;case 2:n[r++]=(o&15)<<4|(a&60)>>2,o=a,i=3;break;case 3:n[r++]=(o&3)<<6|a,i=0}}if(i==1)throw Error(`invalid base64 string.`);return n.subarray(0,r)},enc(e){let t=``,n=0,r,i=0;for(let a=0;a<e.length;a++)switch(r=e[a],n){case 0:t+=P[r>>2],i=(r&3)<<4,n=1;break;case 1:t+=P[i|r>>4],i=(r&15)<<2,n=2;break;case 2:t+=P[i|r>>6],t+=P[r&63],n=0}return n&&(t+=P[i],t+=`=`,n==1&&(t+=`=`)),t}},yt={ignoreUnknownFields:!1},bt={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function xt(e){return e?{...yt,...e}:yt}function St(e){return e?{...bt,...e}:bt}function I(e){if(e===null)return`null`;switch(typeof e){case`object`:return Array.isArray(e)?`array`:`object`;case`string`:return e.length>100?`string`:`"${e.split(`"`).join(`\\"`)}"`;default:return String(e)}}function Ct(e,t,n,r,i){if(n==null||Array.isArray(n)||typeof n!=`object`)throw Error(`cannot decode message ${t} from JSON: ${I(n)}`);let a=new Map;for(let[o,s]of Object.entries(n)){let n=e.findJsonName(o);if(n){if(n.oneof){if(s===null&&n.kind==`scalar`)continue;let e=a.get(n.oneof);if(e!==void 0)throw Error(`cannot decode message ${t} from JSON: multiple keys for oneof "${n.oneof.name}" present: "${e}", "${o}"`);a.set(n.oneof,o)}Tt(i,s,n,r)}else if(!r.ignoreUnknownFields)throw Error(`cannot decode message ${t} from JSON: key "${o}" is unknown`)}return i}function wt(e,t,n){let r=Object.create(null),i;try{for(i of t.byNumber()){let t=e;if(!Ve(i,t)){if(i.req)throw`required field not set`;if(!n.emitDefaultValues||!kt(i))continue}let a=i.oneof?t[i.oneof.localName].value:t[i.localName],o=At(i,a,n);o!==void 0&&(r[n.useProtoFieldName?i.name:i.jsonName]=o)}}catch(e){let t=i?`cannot encode field ${i.name} to JSON`:`cannot encode message to JSON`,n=e instanceof Error?e.message:String(e);throw Error(t+(n.length>0?`: ${n}`:``),{cause:e})}return r}function Tt(e,t,n,r){let i=n.localName;if(n.repeated){if(m(n.kind!=`map`),t===null)return;if(!Array.isArray(t))throw Error(`cannot decode field ${n.name} from JSON: ${I(t)}`);let a=e[i];Array.isArray(a)||(a=e[i]=[]);for(let e of t){if(e===null)throw Error(`cannot decode field ${n.name} from JSON: ${I(e)}`);switch(n.kind){case`message`:{let t=w(n.T);a.push(A(t.fieldWrapper,t.fromJson(e,r)));break}case`enum`:{let t=Et(n.T,e,r.ignoreUnknownFields,!0);t!==R&&a.push(t);break}case`scalar`:try{a.push(z(n.T,e,n.L,!0))}catch(t){let r=`cannot decode field ${n.name} from JSON: ${I(e)}`;throw t instanceof Error&&t.message.length>0&&(r+=`: ${t.message}`),Error(r,{cause:t})}}}}else if(n.kind==`map`){if(t===null)return;if(typeof t!=`object`||Array.isArray(t))throw Error(`cannot decode field ${n.name} from JSON: ${I(t)}`);let a=e[i];typeof a!=`object`&&(a=e[i]=E());for(let[e,i]of Object.entries(t)){if(i===null)throw Error(`cannot decode field ${n.name} from JSON: map value null`);let o;try{o=Dt(n.K,e)}catch(e){let r=`cannot decode map key for field ${n.name} from JSON: ${I(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r,{cause:e})}switch(C(o),n.V.kind){case`message`:{let e=w(n.V.T);a[o]=e.fromJson(i,r);break}case`enum`:{let e=Et(n.V.T,i,r.ignoreUnknownFields,!0);e!==R&&(a[o]=e);break}case`scalar`:try{a[o]=z(n.V.T,i,y.BIGINT,!0)}catch(e){let r=`cannot decode map value for field ${n.name} from JSON: ${I(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r,{cause:e})}}}}else switch(n.oneof&&(e=e[n.oneof.localName]={case:i},i=`value`),n.kind){case`message`:{let a=w(n.T);if(t===null&&a.typeName!=`google.protobuf.Value`)return;e[i]=A(a.fieldWrapper,a.fromJson(t,r));break}case`enum`:{let a=Et(n.T,t,r.ignoreUnknownFields,!1);switch(a){case L:Ot(n,e);break;case R:break;default:e[i]=a}break}case`scalar`:try{let r=z(n.T,t,n.L,!1);switch(r){case L:Ot(n,e);break;default:e[i]=r}}catch(e){let r=`cannot decode field ${n.name} from JSON: ${I(t)}`;throw e instanceof Error&&e.message.length>0&&(r+=`: ${e.message}`),Error(r,{cause:e})}}}const L=Symbol(),R=Symbol();function Et(e,t,n,r){if(t===null)return e.typeName==`google.protobuf.NullValue`?0:r?e.values[0].no:L;switch(typeof t){case`number`:if(Number.isInteger(t))return t;break;case`string`:{let r=e.findName(t);if(r!==void 0)return r.no;if(n)return R;break}}throw Error(`cannot decode enum ${e.typeName} from JSON: ${I(t)}`)}function z(e,t,n=y.BIGINT,r=!0){if(t==null)return r?b(e,n):L;switch(e){case v.DOUBLE:case v.FLOAT:{if(t===`NaN`)return NaN;if(t===`Infinity`)return 1/0;if(t===`-Infinity`)return-1/0;if(t===``||typeof t==`string`&&t.trim().length!==t.length||typeof t!=`string`&&typeof t!=`number`)break;let n=Number(t);if(Number.isNaN(n)||!Number.isFinite(n))break;return e==v.FLOAT&&pe(n),n}case v.INT32:case v.FIXED32:case v.SFIXED32:case v.SINT32:case v.UINT32:{let n;if(typeof t==`number`?n=t:typeof t==`string`&&t.length>0&&t.trim().length===t.length&&(n=Number(t)),n===void 0)break;return e==v.UINT32||e==v.FIXED32?fe(n):h(n),n}case v.INT64:case v.SFIXED64:case v.SINT64:{if(typeof t!=`number`&&typeof t!=`string`)break;let e=_.parse(t);return n?e.toString():e}case v.FIXED64:case v.UINT64:{if(typeof t!=`number`&&typeof t!=`string`)break;let e=_.uParse(t);return n?e.toString():e}case v.BOOL:if(typeof t!=`boolean`)break;return t;case v.STRING:if(typeof t!=`string`)break;return t;case v.BYTES:if(t===``)return new Uint8Array;if(typeof t!=`string`)break;return vt.dec(t)}throw Error()}function Dt(e,t){if(e===v.BOOL)switch(t){case`true`:t=!0;break;case`false`:t=!1}return z(e,t,y.BIGINT,!0)?.toString()??``}function Ot(e,t){let n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case`map`:t[n]=E();break;case`enum`:t[n]=r?e.T.values[0].no:void 0;break;case`scalar`:t[n]=r?b(e.T,e.L):void 0;break;case`message`:t[n]=void 0}}function kt(e){return e.repeated||e.kind==`map`?!0:!(e.oneof||e.kind==`message`||e.opt||e.req)}function At(e,t,n){if(e.kind==`map`){let r=Object.create(null);m(!t||typeof t==`object`);let i=t?Object.entries(t):[];switch(e.V.kind){case`scalar`:for(let[t,n]of i)r[t.toString()]=jt(e.V.T,n);break;case`message`:for(let[t,a]of i){let i=w(e.V.T);r[t.toString()]=i.toJson(a,n)}break;case`enum`:{let t=e.V.T;for(let[e,a]of i)r[e.toString()]=Mt(t,a,n.enumAsInteger);break}}return n.emitDefaultValues||i.length>0?r:void 0}if(e.repeated){m(!t||Array.isArray(t));let r=[],i=t;if(i&&i.length)switch(e.kind){case`scalar`:for(let t=0;t<i.length;t++)r.push(jt(e.T,i[t]));break;case`enum`:for(let t=0;t<i.length;t++)r.push(Mt(e.T,i[t],n.enumAsInteger));break;case`message`:{let t=w(e.T);for(let e=0;e<i.length;e++)r.push(t.toJson($e(t.fieldWrapper,i[e])));break}}return n.emitDefaultValues||r.length>0?r:void 0}switch(e.kind){case`scalar`:{let r=S(e.T,t,!1);return!n.emitDefaultValues&&x(e.T,r)?void 0:jt(e.T,t)}case`enum`:{let r=Xe(e.T,t);return!n.emitDefaultValues&&Ye(e.T)===r?void 0:Mt(e.T,t,n.enumAsInteger)}case`message`:{if(!n.emitDefaultValues&&t==null)return;let r=w(e.T);return r.toJson($e(r.fieldWrapper,t))}}}function jt(e,t){switch(e){case v.INT32:case v.SFIXED32:case v.SINT32:case v.FIXED32:case v.UINT32:return m(typeof t==`number`),t;case v.FLOAT:case v.DOUBLE:return m(typeof t==`number`),Number.isNaN(t)?`NaN`:t===1/0?`Infinity`:t===-1/0?`-Infinity`:t;case v.STRING:return m(typeof t==`string`),t;case v.BOOL:return m(typeof t==`boolean`),t;case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return m(typeof t==`bigint`||typeof t==`string`||typeof t==`number`),t.toString();case v.BYTES:return m(t instanceof Uint8Array),vt.enc(t);case v.DATE:throw Error(`cannot write date with writeScalar`);default:throw Error(`unknown scalar type`)}}function Mt(e,t,n){return m(typeof t==`number`),e.typeName==`google.protobuf.NullValue`?null:n?t:e.findNumber(t)?.name??t}const Nt=[];function B(e,t){let{fields:n,typeName:r,delimitedMessageEncoding:i,fieldWrapper:a}=e,o=Be(n,e.packedByDefault??!0),s={typeName:r,fields:o,fieldWrapper:a,create(e){let t=T();return O(e,t,o),t},createComplete(e){let t=Lt(o);return O(e,t,o),t},equals(e,t){return Ft(o,e,t)},clone(e){return e==null?e:It(e,o)},fromBinary(e,t){let n={};if(e&&e.length){let r=it(t);ut(n,o,r.readerFactory(e),e.byteLength,r,i??!1)}return n},fromJson(e,t){let n={};if(e!=null){let i=xt(t);Ct(o,r,e,i,n)}return n},fromJsonString(e,t){let n=null;if(e)try{n=JSON.parse(e)}catch(e){throw Error(`cannot decode ${r} from JSON: ${e instanceof Error?e.message:String(e)}`,{cause:e})}return s.fromJson(n,t)},toBinary(e,t){if(e==null)return new Uint8Array;let n=at(t),r=n.writerFactory();return dt(e,o,r,n),r.finish()},toJson(e,t){let n=St(t);return wt(e,o,n)},toJsonString(e,t){let n=s.toJson(e,t);return JSON.stringify(n,null,t?.prettySpaces??0)},...t??{}};return s}function Pt(e,t){return B({typeName:e,fields:Nt,packedByDefault:t})}function Ft(e,t,n){if(t===n)return!0;let r=D(t??{}),i=D(n??{});return e.byMember().every(e=>{let t=r[e.localName],n=i[e.localName];if(e.repeated){let r=t??[],i=n??[];if(r.length!==i.length)return!1;switch(e.kind){case`message`:{let t=w(e.T);return r.every((e,n)=>t.equals(e,i[n]))}case`scalar`:return r.every((t,n)=>Ee(e.T,t,i[n]));case`enum`:return r.every((e,t)=>Ee(v.INT32,e,i[t]))}throw Error(`repeated cannot contain ${e.kind}`)}switch(e.kind){case`message`:return w(e.T).equals(t,n);case`enum`:return V(v.INT32,t,n);case`scalar`:return V(e.T,t,n);case`oneof`:{let r=t,i=n;if(r?.case!==i?.case)return!1;let a=r?.case,o=a===void 0?void 0:e.findField(a);if(o===void 0)return!0;switch(o.kind){case`message`:return w(o.T).equals(r?.value,i?.value);case`enum`:return V(v.INT32,r?.value,i?.value);case`scalar`:return V(o.T,r?.value,i?.value)}throw Error(`oneof cannot contain ${o.kind}`)}case`map`:{let r=t??{},i=n??{},a=Object.keys(r);if(a.length!==Object.keys(i).length)return!1;let o=e.V;return a.every(e=>{if(!(e in i))return!1;switch(o.kind){case`message`:return w(o.T).equals(r[e],i[e]);case`enum`:return V(v.INT32,r[e],i[e]);case`scalar`:return V(o.T,r[e],i[e])}})}}})}function V(e,t,n){return x(e,t)&&x(e,n)?!0:Ee(e,t,n)}function It(e,t){if(e==null)return null;let n=T();return O(e,n,t,!0),n}function Lt(e){let t={};for(let n of e.byMember()){let{localName:e,kind:r}=n;switch(C(e),r){case`oneof`:t[e]=T(),t[e].case=void 0;break;case`scalar`:t[e]=n.repeated?[]:b(n.T,y.BIGINT);break;case`enum`:t[e]=n.repeated?[]:Ye(n.T);break;case`message`:{if(n.oneof)break;if(n.repeated){t[e]=[];break}let r=w(n.T);t[e]=r.fieldWrapper?r.fieldWrapper.unwrapField(null):Lt(r.fields);break}case`map`:t[e]=E()}}return t}const Rt=B({typeName:`srpc.CallStart`,fields:[{no:1,name:`rpc_service`,kind:`scalar`,T:v.STRING},{no:2,name:`rpc_method`,kind:`scalar`,T:v.STRING},{no:3,name:`data`,kind:`scalar`,T:v.BYTES},{no:4,name:`data_is_zero`,kind:`scalar`,T:v.BOOL}],packedByDefault:!0}),zt=B({typeName:`srpc.CallData`,fields:[{no:1,name:`data`,kind:`scalar`,T:v.BYTES},{no:2,name:`data_is_zero`,kind:`scalar`,T:v.BOOL},{no:3,name:`complete`,kind:`scalar`,T:v.BOOL},{no:4,name:`error`,kind:`scalar`,T:v.STRING}],packedByDefault:!0}),Bt=B({typeName:`srpc.Packet`,fields:[{no:1,name:`call_start`,kind:`message`,T:()=>Rt,oneof:`body`},{no:2,name:`call_data`,kind:`message`,T:()=>zt,oneof:`body`},{no:3,name:`call_cancel`,kind:`scalar`,T:v.BOOL,oneof:`body`}],packedByDefault:!0});var Vt=class{sink;source;rpcDataSource;_source=l({objectMode:!0});_rpcDataSource=l({objectMode:!0});service;method;closed;remoteError;remoteCompleted=!1;invocationController=new AbortController;writeDrainAbort=new AbortController;constructor(){this.sink=this._createSink(),this.source=this._source,this.rpcDataSource=this.readRpcData()}get isClosed(){return this.closed??!1}get isRemoteCompleted(){return this.remoteCompleted}get invocationSignal(){return this.invocationController.signal}async writeCallData(e,t,n){await this.writeCallDataPacket(e,t,n)}async writeCallDataPacket(e,t,n,r){let i={data:e||new Uint8Array,dataIsZero:!!e&&e.length===0,complete:t||!1,error:n||``};await this.writePacket({body:{case:`callData`,value:i}},r)}async writeCallCancel(e=!1){await this.writePacket({body:{case:`callCancel`,value:!0}},{waitForDrain:!1}),e&&await this._source.onEmpty({signal:this.writeDrainAbort.signal})}async writeCallDataFromSource(e){try{for await(let t of e)await this.writeCallData(t);await this.writeCallData(void 0,!0)}catch(e){this.close(e)}}async writePacket(e,n){if(this.closed&&!n?.allowClosed)throw Error(t);if(this._source.push(e),!(n?.waitForDrain===!1||this._source.readableLength<=1))try{await this._source.onEmpty({signal:this.writeDrainAbort.signal})}catch(e){throw this.closed?Error(t,{cause:e}):e}}async handleMessage(e){return this.handlePacket(Bt.fromBinary(e))}async handlePacket(e){try{switch(e?.body?.case){case`callStart`:await this.handleCallStart(e.body.value);break;case`callData`:await this.handleCallData(e.body.value);break;case`callCancel`:e.body.value&&await this.handleCallCancel()}}catch(e){let t=e;t?.message||(t=Error(`error handling packet`)),this.close(t)}}async handleCallStart(e){throw Error(`unexpected call start: ${e.rpcService}/${e.rpcMethod}`)}pushRpcData(e,t){if(t)(!e||e.length!==0)&&(e=new Uint8Array);else if(!e||e.length===0)return;this._rpcDataSource.push(e)}async handleCallData(e){if(!this.service||!this.method)throw Error(`call start must be sent before call data`);this.pushRpcData(e.data,e.dataIsZero);let t=e.error?new r(this.service,this.method,e.error):void 0;t&&(this.remoteError??=t,this.invocationController.abort()),(e.complete||t)&&(this.remoteCompleted=!0,this.endRpcData(t))}async handleCallCancel(){await this.close(Error(t))}async close(e){this.closed||(this.closed=e??!0,!this.remoteError&&e&&(this.remoteError=e),this.invocationController.abort(),e&&e.message&&await this.writeCallDataPacket(void 0,!0,e.message,{allowClosed:!0,waitForDrain:!1}),this.writeDrainAbort.abort(),this._source.end(),this.endRpcData(e))}endRpcData(e){e&&this._rpcDataSource.push(e),this._rpcDataSource.end()}async*readRpcData(){for await(let e of this._rpcDataSource){if(e instanceof Error)throw e;yield e}}async handleSourceEnd(){}_createSink(){return async e=>{try{if(Symbol.asyncIterator in e)for await(let t of e)await this.handlePacket(t);else for(let t of e)await this.handlePacket(t);await this.handleSourceEnd()}catch(e){this.close(e)}}}},Ht=class extends Vt{constructor(e,t){super(),this.service=e,this.method=t}async writeCallStart(e){if(!this.service||!this.method)throw Error(`service and method must be set`);let t={rpcService:this.service,rpcMethod:this.method,data:e||new Uint8Array,dataIsZero:!!e&&e.length===0};await this.writePacket({body:{case:`callStart`,value:t}})}async handleCallStart(e){throw Error(`unexpected server to client rpc: ${e.rpcService||`<empty>`}/${e.rpcMethod||`<empty>`}`)}async handleSourceEnd(){this.isRemoteCompleted||await this.close(Error(`ERR_CLOSED_BEFORE_COMPLETION`))}};async function Ut(e,t){try{for await(let n of e)t.push(n);t.end()}catch(e){t.end(e)}}function H(e=0){return new Uint8Array(e)}function Wt(e=0){return new Uint8Array(e)}function Gt(e){return e?.buffer instanceof ArrayBuffer}function Kt(e){if(Gt(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function qt(e,t){t??=e.reduce((e,t)=>e+t.length,0);let n=Wt(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return Kt(n)}function Jt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0}const Yt=Symbol.for(`@achingbrain/uint8arraylist`);function Xt(e,t){if(t==null||t<0)throw RangeError(`index is out of bounds`);let n=0;for(let r of e){let e=n+r.byteLength;if(t<e)return{buf:r,index:t-n};n=e}throw RangeError(`index is out of bounds`)}function U(e){return!!e?.[Yt]}var W=class e{bufs;length;[Yt]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(U(n)){t+=n.byteLength;for(let e of n.bufs)this.bufs.push(e)}else throw Error(`Could not append value, must be an Uint8Array or a Uint8ArrayList`);this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(U(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw Error(`Could not prepend value, must be an Uint8Array or a Uint8ArrayList`);this.length+=t}get(e){let t=Xt(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Xt(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(U(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw Error(`Could not write value, must be an Uint8Array or a Uint8ArrayList`)}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:r}=this._subList(e,t);return qt(n,r)}subarray(e,t){let{bufs:n,length:r}=this._subList(e,t);return n.length===1?n[0]:qt(n,r)}sublist(t,n){let{bufs:r,length:i}=this._subList(t,n),a=new e;return a.length=i,a.bufs=r,a}_subList(e,t){if(e??=0,t??=this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw RangeError(`index is out of bounds`);if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],r=0;for(let i=0;i<this.bufs.length;i++){let a=this.bufs[i],o=r,s=o+a.byteLength;if(r=s,e>=s)continue;let c=e>=o&&e<s,l=t>o&&t<=s;if(c&&l){if(e===o&&t===s){n.push(a);break}let r=e-o;n.push(a.subarray(r,r+(t-e)));break}if(c){if(e===0){n.push(a);continue}n.push(a.subarray(e-o));continue}if(l){if(t===s){n.push(a);break}n.push(a.subarray(0,t-o));break}n.push(a)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!U(e)&&!(e instanceof Uint8Array))throw TypeError(`The "value" argument must be a Uint8ArrayList or Uint8Array`);let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let r=n.byteLength;if(r===0)throw TypeError(`search must be at least 1 byte long`);let i=new Int32Array(256);for(let e=0;e<256;e++)i[e]=-1;for(let e=0;e<r;e++)i[n[e]]=e;let a=i,o=this.byteLength-n.byteLength,s=n.byteLength-1,c;for(let e=t;e<=o;e+=c){c=0;for(let t=s;t>=0;t--){let r=this.get(e+t);if(n[t]!==r){c=Math.max(1,t-a[r]);break}}if(c===0)return e}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let r=H(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt16(0,t,n),this.write(r,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let r=H(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt32(0,t,n),this.write(r,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let r=H(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigInt64(0,t,n),this.write(r,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let r=H(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint16(0,t,n),this.write(r,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let r=H(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint32(0,t,n),this.write(r,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let r=H(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigUint64(0,t,n),this.write(r,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let r=H(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat32(0,t,n),this.write(r,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let r=H(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat64(0,t,n),this.write(r,e)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Jt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,n){let r=new e;return r.bufs=t,n??=t.reduce((e,t)=>e+t.byteLength,0),r.length=n,r}};function Zt(e){let t=e.fromBinary.bind(e);return async function*(e){for await(let n of e)if(Array.isArray(n))for(let e of n)yield*[t(e)];else yield*[t(n)]}}function Qt(e){return async function*(t){for await(let n of t)if(Array.isArray(n))for(let t of n)yield e.toBinary(t);else yield e.toBinary(n)}}const $t=1e7,en=Zt(Bt),tn=Qt(Bt),nn=e=>{if(e.length<4)throw RangeError(`Could not decode int32BE`);return e.getUint32(0,!0)};nn.bytes=4;const rn=e=>{let t=new W(new Uint8Array(4));return t.setUint32(0,e,!0),t};rn.bytes=4;async function*an(e,t){for await(let n of e){let e=n instanceof Uint8Array?n.length:n.byteLength;if(e===0||e>$t)throw RangeError(`invalid packet length: ${e}`);yield new W(t(e),n)}}async function*on(e,t){let n=new W;for await(let r of e)for(n.append(r);n.length>=t.bytes;){let e=t(n);if(e===0||e>$t)throw RangeError(`invalid packet length: ${e}`);let r=t.bytes+e;if(n.length<r)break;yield new W(n.slice(t.bytes,r)),n.consume(r)}if(n.length!==0)throw RangeError(`truncated packet frame`)}function sn(e=rn){return t=>an(t,e)}function cn(e=nn){return t=>on(t,e)}var ln=class{_value;_waiters;constructor(e){this._value=e||void 0,this._waiters=[]}get value(){return this._value}async wait(){let e=this._value;return e===void 0?new Promise(e=>{this.waitWithCb(t=>{e(t)})}):e}waitWithCb(e){e&&this._waiters.push(e)}set(e){if(this._value=e,e===void 0)return;let t=this._waiters;if(t.length!==0){this._waiters=[];for(let n of t)n(e)}}},un=class extends ln{constructor(e){super(e)}get openStreamFunc(){return async()=>{let e=this.value;return e||=await this.wait(),e()}}},dn=class{openStreamCtr;constructor(e){this.openStreamCtr=new un(e||void 0)}setOpenStreamFn(e){this.openStreamCtr.set(e||void 0)}async request(e,t,n,r){let i=await this.startRpc(e,t,n,r);for await(let e of i.rpcDataSource)return i.close(),e;let a=Error(`empty response`);throw i.close(a),a}async clientStreamingRequest(e,t,n,r){let i=await this.startRpc(e,t,null,r);i.writeCallDataFromSource(n).catch(e=>i.close(e));for await(let e of i.rpcDataSource)return i.close(),e;let a=Error(`empty response`);throw i.close(a),a}serverStreamingRequest(e,t,n,r){let i=l({objectMode:!0});return this.startRpc(e,t,n,r).then(async e=>Ut(e.rpcDataSource,i)).catch(e=>i.end(e)),i}bidirectionalStreamingRequest(e,t,n,r){let i=l({objectMode:!0});return this.startRpc(e,t,null,r).then(async e=>{let t=t=>{i.end(t),e.close(t)};e.writeCallDataFromSource(n).catch(t);try{for await(let t of e.rpcDataSource)i.push(t);i.end(),e.close()}catch(e){t(e)}}).catch(e=>i.end(e)),i}async startRpc(e,n,r,i){if(i?.aborted)throw Error(t);let a=await(await this.openStreamCtr.wait())(),o=new Ht(e,n),s=()=>{if(o.isClosed)return;let e=Error(t);o.writeCallCancel().catch(()=>void 0),a.abort(e),o.close(e).catch(()=>void 0)};return i?.addEventListener(`abort`,s,{once:!0}),p(a,en,o,tn,a).then(async()=>{if(o.isClosed instanceof Error){a.abort(o.isClosed);return}await a.close(),await o.close()},async e=>{let t=e instanceof Error?e:Error(String(e));a.abort(t),await o.close(t)}).finally(()=>{i?.removeEventListener(`abort`,s)}),await o.writeCallStart(r??void 0),o}},fn=class extends Vt{lookupMethod;constructor(e){super(),this.lookupMethod=e}async handleCallStart(e){if(this.service||this.method)throw Error(`call start must be sent only once`);if(this.service=e.rpcService,this.method=e.rpcMethod,!this.service||!this.method)throw Error(`rpcService and rpcMethod cannot be empty`);if(!this.lookupMethod)throw Error(`LookupMethod is not defined`);let t=await this.lookupMethod(this.service,this.method);if(!t)throw Error(`not found: ${this.service}/${this.method}`);this.pushRpcData(e.data,e.dataIsZero),this.invokeRPC(t)}async handleCallData(e){if(!this.service||!this.method)throw Error(`call start must be sent before call data`);return super.handleCallData(e)}async invokeRPC(e){let t=this._createDataSink();try{await e(this.rpcDataSource,t,{signal:this.invocationSignal})}catch(e){this.close(e)}}_createDataSink(){return async e=>{try{for await(let t of e)await this.writeCallData(t);await this.writeCallData(void 0,!0),this.close()}catch(e){this.close(e)}}}},pn=class{lookupMethod;constructor(e){this.lookupMethod=e}get rpcStreamHandler(){return async e=>mn(e,this.startRpc())}startRpc(){return new fn(this.lookupMethod)}handlePacketStream(e){let t=this.startRpc();return mn(e,t).catch(()=>void 0),t}};async function mn(e,t){try{if(await p(e,en,t,tn,e),t.isClosed instanceof Error)throw e.abort(t.isClosed),t.isClosed;await e.close(),await t.close()}catch(n){let r=n instanceof Error?n:Error(String(n));throw e.abort(r),await t.close(r),r}}function hn(e){if(e!=null){if(typeof e[Symbol.iterator]==`function`)return e[Symbol.iterator]();if(typeof e[Symbol.asyncIterator]==`function`)return e[Symbol.asyncIterator]();if(typeof e.next==`function`)return e}throw Error(`argument is not an iterator or iterable`)}var G=class extends Error{static name=`InvalidFrameError`;constructor(e=`The frame was invalid`){super(e),this.name=`InvalidFrameError`}},gn=class extends Error{static name=`UnrequestedPingError`;constructor(e=`Unrequested ping error`){super(e),this.name=`UnrequestedPingError`}},_n=class extends Error{static name=`NotMatchingPingError`;constructor(e=`Unrequested ping error`){super(e),this.name=`NotMatchingPingError`}},vn=class extends Error{static name=`InvalidStateError`;constructor(e=`Invalid state`){super(e),this.name=`InvalidStateError`}},yn=class extends Error{static name=`StreamAlreadyExistsError`;constructor(e=`Strean already exists`){super(e),this.name=`StreamAlreadyExistsError`}},bn=class extends Error{static name=`DecodeInvalidVersionError`;constructor(e=`Decode invalid version`){super(e),this.name=`DecodeInvalidVersionError`}},xn=class extends Error{static name=`BothClientsError`;constructor(e=`Both clients`){super(e),this.name=`BothClientsError`}},Sn=class extends Error{static name=`ReceiveWindowExceededError`;constructor(e=`Receive window exceeded`){super(e),this.name=`ReceiveWindowExceededError`}};const Cn=new Set([G.name,gn.name,_n.name,yn.name,bn.name,xn.name,Sn.name]),wn=262144,Tn=Symbol.for(`@libp2p/service-capabilities`);var En=class extends Error{static name=`AbortError`;constructor(e=`The operation was aborted`){super(e),this.name=`AbortError`}},K=class extends Error{static name=`InvalidParametersError`;constructor(e=`Invalid parameters`){super(e),this.name=`InvalidParametersError`}},q=class extends Error{static name=`MuxerClosedError`;constructor(e=`The muxer is closed`){super(e),this.name=`MuxerClosedError`}},Dn=class extends Error{static name=`TooManyOutboundProtocolStreamsError`;constructor(e=`Too many outbound protocol streams`){super(e),this.name=`TooManyOutboundProtocolStreamsError`}};const On={enableKeepAlive:!0,keepAliveInterval:3e4,maxInboundStreams:1e3,maxOutboundStreams:1e3,initialStreamWindowSize:wn,maxStreamWindowSize:16777216,maxMessageSize:65536};function kn(e){if(e.keepAliveInterval<=0)throw new K(`keep-alive interval must be positive`);if(e.maxInboundStreams<0)throw new K(`max inbound streams must be larger or equal 0`);if(e.maxOutboundStreams<0)throw new K(`max outbound streams must be larger or equal 0`);if(e.initialStreamWindowSize<262144)throw new K(`InitialStreamWindowSize must be larger or equal 256 kB`);if(e.maxStreamWindowSize<e.initialStreamWindowSize)throw new K(`MaxStreamWindowSize must be larger than the InitialStreamWindowSize`);if(e.maxStreamWindowSize>2**32-1)throw new K(`MaxStreamWindowSize must be less than equal MAX_UINT32`);if(e.maxMessageSize<1024)throw new K(`MaxMessageSize must be greater than a kilobyte`)}var J;(function(e){e[e.Data=0]=`Data`,e[e.WindowUpdate=1]=`WindowUpdate`,e[e.Ping=2]=`Ping`,e[e.GoAway=3]=`GoAway`})(J||={});var Y;(function(e){e[e.SYN=1]=`SYN`,e[e.ACK=2]=`ACK`,e[e.FIN=4]=`FIN`,e[e.RST=8]=`RST`})(Y||={}),Object.values(Y).filter(e=>typeof e!=`string`);var X;(function(e){e[e.NormalTermination=0]=`NormalTermination`,e[e.ProtocolError=1]=`ProtocolError`,e[e.InternalError=2]=`InternalError`})(X||={});const An=2**24;function jn(e){if(e[0]!==0)throw new G(`Invalid frame version`);return{type:e[1],flag:(e[2]<<8)+e[3],streamID:e[4]*An+(e[5]<<16)+(e[6]<<8)+e[7],length:e[8]*An+(e[9]<<16)+(e[10]<<8)+e[11]}}var Mn=class{source;buffer;frameInProgress;constructor(e){this.source=Nn(e),this.buffer=new W,this.frameInProgress=!1}async*emitFrames(){for await(let e of this.source)for(this.buffer.append(e);;){let e=this.readHeader();if(e===void 0)break;let{type:t,length:n}=e;t===J.Data?(this.frameInProgress=!0,yield{header:e,readData:this.readBytes.bind(this,n)}):yield{header:e}}}readHeader(){if(this.frameInProgress)throw new vn(`decoding frame already in progress`);if(this.buffer.length<12)return;let e=jn(this.buffer.subarray(0,12));return this.buffer.consume(12),e}async readBytes(e){if(this.buffer.length<e){for await(let t of this.source)if(this.buffer.append(t),this.buffer.length>=e)break}let t=this.buffer.sublist(0,e);return this.buffer.consume(e),this.frameInProgress=!1,t}};function Nn(e){if(e[Symbol.iterator]!==void 0){let t=e[Symbol.iterator]();return t.return=void 0,{[Symbol.iterator](){return t}}}if(e[Symbol.asyncIterator]!==void 0){let t=e[Symbol.asyncIterator]();return t.return=void 0,{[Symbol.asyncIterator](){return t}}}throw Error(`a source must be either an iterable or an async iterable`)}function Pn(e){let t=new Uint8Array(12);return t[1]=e.type,t[2]=e.flag>>>8,t[3]=e.flag,t[4]=e.streamID>>>24,t[5]=e.streamID>>>16,t[6]=e.streamID>>>8,t[7]=e.streamID,t[8]=e.length>>>24,t[9]=e.length>>>16,t[10]=e.length>>>8,t[11]=e.length,t}var Fn=class extends Error{static name=`StreamResetError`;constructor(e=`The stream has been reset`){super(e),this.name=`StreamResetError`}},In=class extends Error{static name=`StreamStateError`;constructor(e=`The stream is in an invalid state`){super(e),this.name=`StreamStateError`}};function Ln(e){return e!=null&&typeof e.then==`function`&&typeof e.catch==`function`&&typeof e.finally==`function`}function Rn(e,t){let n=hn(e).return?.();Ln(n)&&n.catch(e=>{t.error(`could not cause iterator to return`,e)})}function zn(e){return e!=null&&typeof e.then==`function`&&typeof e.catch==`function`&&typeof e.finally==`function`}var Bn=class{id;direction;timeline;protocol;metadata;source;status;readStatus;writeStatus;log;sinkController;sinkEnd;closed;endErr;streamSource;onEnd;onCloseRead;onCloseWrite;onReset;onAbort;sendCloseWriteTimeout;sendingData;constructor(e){this.sinkController=new AbortController,this.sinkEnd=a(),this.closed=a(),this.log=e.log,this.status=`open`,this.readStatus=`ready`,this.writeStatus=`ready`,this.id=e.id,this.metadata=e.metadata??{},this.direction=e.direction,this.timeline={open:Date.now()},this.sendCloseWriteTimeout=e.sendCloseWriteTimeout??5e3,this.onEnd=e.onEnd,this.onCloseRead=e.onCloseRead,this.onCloseWrite=e.onCloseWrite,this.onReset=e.onReset,this.onAbort=e.onAbort,this.source=this.streamSource=l({onEnd:e=>{e==null?this.log.trace(`source ended`):this.log.trace(`source ended with error`,e),this.onSourceEnd(e)}}),this.sink=this.sink.bind(this)}async sink(e){if(this.writeStatus!==`ready`)throw new In(`writable end state is "${this.writeStatus}" not "ready"`);try{this.writeStatus=`writing`;let t={signal:this.sinkController.signal};if(this.direction===`outbound`){let e=this.sendNewStream(t);zn(e)&&await e}let n=()=>{Rn(e,this.log)};try{this.sinkController.signal.addEventListener(`abort`,n),this.log.trace(`sink reading from source`);for await(let n of e){n=n instanceof Uint8Array?new W(n):n;let e=this.sendData(n,t);zn(e)&&(this.sendingData=a(),await e,this.sendingData.resolve(),this.sendingData=void 0)}}finally{this.sinkController.signal.removeEventListener(`abort`,n)}this.log.trace(`sink finished reading from source, write status is "%s"`,this.writeStatus),this.writeStatus===`writing`&&(this.writeStatus=`closing`,this.log.trace(`send close write to remote`),await this.sendCloseWrite({signal:AbortSignal.timeout(this.sendCloseWriteTimeout)}),this.writeStatus=`closed`),this.onSinkEnd()}catch(e){throw this.log.trace(`sink ended with error, calling abort with error`,e),this.abort(e),e}finally{this.log.trace(`resolve sink end`),this.sinkEnd.resolve()}}onSourceEnd(e){this.timeline.closeRead??(this.timeline.closeRead=Date.now(),this.readStatus=`closed`,e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseRead?.(),this.timeline.closeWrite==null?this.log.trace(`source ended, waiting for sink to end`):(this.log.trace(`source and sink ended`),this.timeline.close=Date.now(),this.status!==`aborted`&&this.status!==`reset`&&(this.status=`closed`),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()))}onSinkEnd(e){this.timeline.closeWrite??(this.timeline.closeWrite=Date.now(),this.writeStatus=`closed`,e!=null&&this.endErr==null&&(this.endErr=e),this.onCloseWrite?.(),this.timeline.closeRead==null?this.log.trace(`sink ended, waiting for source to end`):(this.log.trace(`sink and source ended`),this.timeline.close=Date.now(),this.status!==`aborted`&&this.status!==`reset`&&(this.status=`closed`),this.onEnd!=null&&this.onEnd(this.endErr),this.closed.resolve()))}async close(e){this.status===`open`&&(this.log.trace(`closing gracefully`),this.status=`closing`,await u(Promise.all([this.closeWrite(e),this.closeRead(e),this.closed.promise]),e?.signal),this.status=`closed`,this.log.trace(`closed gracefully`))}async closeRead(e={}){if(this.readStatus===`closing`||this.readStatus===`closed`)return;this.log.trace(`closing readable end of stream with starting read status "%s"`,this.readStatus);let t=this.readStatus;this.readStatus=`closing`,this.status!==`reset`&&this.status!==`aborted`&&this.timeline.closeRead==null&&(this.log.trace(`send close read to remote`),await this.sendCloseRead(e)),t===`ready`&&(this.log.trace(`ending internal source queue with %d queued bytes`,this.streamSource.readableLength),this.streamSource.end()),this.log.trace(`closed readable end of stream`)}async closeWrite(e={}){this.writeStatus!==`closing`&&this.writeStatus!==`closed`&&(this.log.trace(`closing writable end of stream with starting write status "%s"`,this.writeStatus),this.writeStatus===`ready`&&(this.log.trace(`sink was never sunk, sink an empty array`),await u(this.sink([]),e.signal)),this.writeStatus===`writing`&&(this.sendingData!=null&&await u(this.sendingData.promise,e.signal),this.log.trace(`aborting source passed to .sink`),this.sinkController.abort(),await u(this.sinkEnd.promise,e.signal)),this.writeStatus=`closed`,this.log.trace(`closed writable end of stream`))}abort(e){if(this.status===`closed`||this.status===`aborted`||this.status===`reset`)return;this.log(`abort with error`,e),this.log(`try to send reset to remote`);let t=this.sendReset();zn(t)&&t.catch(e=>{this.log.error(`error sending reset message`,e)}),this.status=`aborted`,this.timeline.abort=Date.now(),this._closeSinkAndSource(e),this.onAbort?.(e)}reset(){if(this.status===`closed`||this.status===`aborted`||this.status===`reset`)return;let e=new Fn(`stream reset`);this.status=`reset`,this.timeline.reset=Date.now(),this._closeSinkAndSource(e),this.onReset?.()}_closeSinkAndSource(e){this._closeSink(e),this._closeSource(e)}_closeSink(e){this.writeStatus===`writing`&&(this.log.trace(`end sink source`),this.sinkController.abort()),this.onSinkEnd(e)}_closeSource(e){this.readStatus!==`closing`&&this.readStatus!==`closed`&&(this.log.trace(`ending source with %d bytes to be read by consumer`,this.streamSource.readableLength),this.readStatus=`closing`,this.streamSource.end(e))}remoteCloseWrite(){if(this.readStatus===`closing`||this.readStatus===`closed`){this.log(`received remote close write but local source is already closed`);return}this.log.trace(`remote close write`),this._closeSource()}remoteCloseRead(){if(this.writeStatus===`closing`||this.writeStatus===`closed`){this.log(`received remote close read but local sink is already closed`);return}this.log.trace(`remote close read`),this._closeSink()}destroy(){if(this.status===`closed`||this.status===`aborted`||this.status===`reset`){this.log(`received destroy but we are already closed`);return}this.log.trace(`stream destroyed`),this._closeSinkAndSource()}sourcePush(e){this.streamSource.push(e)}sourceReadableLength(){return this.streamSource.readableLength}};function Vn(e){let[t,n]=e[Symbol.asyncIterator]==null?[e[Symbol.iterator](),Symbol.iterator]:[e[Symbol.asyncIterator](),Symbol.asyncIterator],r=[];return{peek:()=>t.next(),push:e=>{r.push(e)},next:()=>r.length>0?{done:!1,value:r.shift()}:t.next(),[n](){return this}}}function Hn(e){return e[Symbol.asyncIterator]!=null}function Un(e){return e?.then!=null}function Wn(e,t){let n=0;if(Hn(e))return(async function*(){for await(let r of e){let e=t(r,n++);Un(e)&&await e,yield r}})();let r=Vn(e),{value:i,done:a}=r.next();if(a===!0)return function*(){}();let o=t(i,n++);if(typeof o?.then==`function`)return(async function*(){await o,yield i;for(let e of r){let r=t(e,n++);Un(r)&&await r,yield e}})();let s=t;return(function*(){yield i;for(let e of r)s(e,n++),yield e})()}var Z;(function(e){e[e.Init=0]=`Init`,e[e.SYNSent=1]=`SYNSent`,e[e.SYNReceived=2]=`SYNReceived`,e[e.Established=3]=`Established`,e[e.Finished=4]=`Finished`})(Z||={});var Gn=class extends Bn{name;state;config;_id;sendWindowCapacity;sendWindowCapacityUpdate;recvWindow;recvWindowCapacity;epochStart;getRTT;sendFrame;constructor(e){super({...e,onEnd:t=>{this.state=Z.Finished,e.onEnd?.(t)}}),this.config=e.config,this._id=parseInt(e.id,10),this.name=e.name,this.state=e.state,this.sendWindowCapacity=wn,this.recvWindow=this.config.initialStreamWindowSize,this.recvWindowCapacity=this.recvWindow,this.epochStart=Date.now(),this.getRTT=e.getRTT,this.sendFrame=e.sendFrame,this.source=Wn(this.source,()=>{this.sendWindowUpdate()})}async sendNewStream(){}async sendData(e,t={}){for(e=e.sublist();e.byteLength!==0;){if(this.sendWindowCapacity===0&&(this.log?.trace(`wait for send window capacity, status %s`,this.status),await this.waitForSendWindowCapacity(t),this.status===`closed`||this.status===`aborted`||this.status===`reset`)){this.log?.trace(`%s while waiting for send window capacity`,this.status);return}let n=Math.min(this.sendWindowCapacity,this.config.maxMessageSize-12,e.length),r=this.getSendFlags();this.sendFrame({type:J.Data,flag:r,streamID:this._id,length:n},e.sublist(0,n)),this.sendWindowCapacity-=n,e.consume(n)}}sendReset(){this.sendFrame({type:J.WindowUpdate,flag:Y.RST,streamID:this._id,length:0})}async sendCloseWrite(){let e=this.getSendFlags()|Y.FIN;this.sendFrame({type:J.WindowUpdate,flag:e,streamID:this._id,length:0})}async sendCloseRead(){}async waitForSendWindowCapacity(e={}){if(this.sendWindowCapacity>0)return;let t,n,r=()=>{this.status===`open`||this.status===`closing`?n(new En(`Stream aborted`)):t()};e.signal?.addEventListener(`abort`,r);try{await new Promise((e,r)=>{this.sendWindowCapacityUpdate=()=>{e()},n=r,t=e})}finally{e.signal?.removeEventListener(`abort`,r)}}handleWindowUpdate(e){this.log?.trace(`stream received window update id=%s`,this._id),this.processFlags(e.flag);let t=this.sendWindowCapacity;this.sendWindowCapacity+=e.length,t===0&&e.length>0&&this.sendWindowCapacityUpdate?.()}async handleData(e,t){if(this.log?.trace(`stream received data id=%s`,this._id),this.processFlags(e.flag),this.recvWindowCapacity<e.length)throw new Sn(`Receive window exceeded`);let n=await t();this.recvWindowCapacity-=e.length,this.sourcePush(n)}processFlags(e){(e&Y.ACK)===Y.ACK&&this.state===Z.SYNSent&&(this.state=Z.Established),(e&Y.FIN)===Y.FIN&&this.remoteCloseWrite(),(e&Y.RST)===Y.RST&&this.reset()}getSendFlags(){switch(this.state){case Z.Init:return this.state=Z.SYNSent,Y.SYN;case Z.SYNReceived:return this.state=Z.Established,Y.ACK;default:return 0}}sendWindowUpdate(){if(this.readStatus!==`ready`)return;let e=this.getSendFlags(),t=Date.now(),n=this.getRTT();if(e===0&&n>-1&&t-this.epochStart<n*4&&(this.recvWindow=Math.min(this.recvWindow*2,this.config.maxStreamWindowSize)),this.recvWindowCapacity>=this.recvWindow&&e===0)return;let r=this.recvWindow-this.recvWindowCapacity;this.recvWindowCapacity=this.recvWindow,this.epochStart=t,this.sendFrame({type:J.WindowUpdate,flag:e,streamID:this._id,length:r})}};const Kn=`/yamux/1.0.0`;var qn=class{protocol=Kn;_components;_init;constructor(e,t={}){this._components=e,this._init=t}[Symbol.toStringTag]=`@chainsafe/libp2p-yamux`;[Tn]=[`@libp2p/stream-multiplexing`];createStreamMuxer(e){return new Jn(this._components,{...this._init,...e})}},Jn=class{protocol=Kn;source;sink;config;log;logger;closeController;nextStreamID;_streams;nextPingID;activePing;rtt;client;localGoAway;remoteGoAway;numInboundStreams;numOutboundStreams;onIncomingStream;onStreamEnd;constructor(e,t){this.client=t.direction===`outbound`,this.config={...On,...t},this.logger=e.logger,this.log=this.logger.forComponent(`libp2p:yamux`),kn(this.config),this.closeController=new AbortController,this.closeController.signal,this.onIncomingStream=t.onIncomingStream,this.onStreamEnd=t.onStreamEnd,this._streams=new Map,this.source=l({onEnd:()=>{this.log?.trace(`muxer source ended`),this._streams.forEach(e=>{e.destroy()})}}),this.sink=async e=>{let t=()=>{let t=hn(e);if(t.return!=null){let e=t.return();Yn(e)&&e.catch(e=>{this.log?.(`could not cause sink source to return`,e)})}},n,r;try{let r=new Mn(e);try{this.closeController.signal.addEventListener(`abort`,t);for await(let e of r.emitFrames())await this.handleFrame(e.header,e.readData)}finally{this.closeController.signal.removeEventListener(`abort`,t)}n=X.NormalTermination}catch(e){Cn.has(e.name)?(this.log?.error(`protocol error in sink`,e),n=X.ProtocolError):(this.log?.error(`internal error in sink`,e),n=X.InternalError),r=e}this.log?.trace(`muxer sink ended`),r==null?await this.close({reason:n}):this.abort(r,n)},this.numInboundStreams=0,this.numOutboundStreams=0,this.nextStreamID=this.client?1:2,this.nextPingID=0,this.rtt=-1,this.log?.trace(`muxer created`),this.config.enableKeepAlive&&this.keepAliveLoop().catch(e=>this.log?.error(`keepalive error: %s`,e)),this.ping().catch(e=>this.log?.error(`ping error: %s`,e))}get streams(){return Array.from(this._streams.values())}newStream(e){if(this.remoteGoAway!==void 0)throw new q(`Muxer closed remotely`);if(this.localGoAway!==void 0)throw new q(`Muxer closed locally`);let t=this.nextStreamID;if(this.nextStreamID+=2,this.numOutboundStreams>=this.config.maxOutboundStreams)throw new Dn(`max outbound streams exceeded`);this.log?.trace(`new outgoing stream id=%s`,t);let n=this._newStream(t,e,Z.Init,`outbound`);return this._streams.set(t,n),this.numOutboundStreams++,n.sendWindowUpdate(),n}async ping(){if(this.remoteGoAway!==void 0)throw new q(`Muxer closed remotely`);if(this.localGoAway!==void 0)throw new q(`Muxer closed locally`);if(this.activePing===void 0){let e=()=>{};this.activePing={id:this.nextPingID++,promise:new Promise((t,n)=>{let r=()=>{n(new q(`Muxer closed locally`))};this.closeController.signal.addEventListener(`abort`,r,{once:!0}),e=()=>{this.closeController.signal.removeEventListener(`abort`,r),t()}}),resolve:e};let t=Date.now();this.sendPing(this.activePing.id);try{await this.activePing.promise}finally{delete this.activePing}let n=Date.now();this.rtt=n-t}else await this.activePing.promise;return this.rtt}getRTT(){return this.rtt}async close(e={}){if(this.closeController.signal.aborted)return;let t=e?.reason??X.NormalTermination;if(this.log?.trace(`muxer close reason=%s`,t),e.signal==null){let t=AbortSignal.timeout(500);e={...e,signal:t}}try{await Promise.all([...this._streams.values()].map(async t=>t.close(e))),this.sendGoAway(t),this._closeMuxer()}catch(e){this.abort(e)}}abort(e,t){if(!this.closeController.signal.aborted){t??=X.InternalError,this.log?.error(`muxer abort reason=%s error=%s`,t,e);for(let t of this._streams.values())t.abort(e);this.sendGoAway(t),this._closeMuxer()}}isClosed(){return this.closeController.signal.aborted}_closeMuxer(){this.closeController.abort(),this.source.end()}_newStream(e,t,n,r){if(this._streams.get(e)!=null)throw new K(`Stream already exists with that id`);let i=new Gn({id:e.toString(),name:t,state:n,direction:r,sendFrame:this.sendFrame.bind(this),onEnd:()=>{this.closeStream(e),this.onStreamEnd?.(i)},log:this.logger.forComponent(`libp2p:yamux:${r}:${e}`),config:this.config,getRTT:this.getRTT.bind(this)});return i}closeStream(e){this.client===(e%2==0)?this.numInboundStreams--:this.numOutboundStreams--,this._streams.delete(e)}async keepAliveLoop(){for(this.log?.trace(`muxer keepalive enabled interval=%s`,this.config.keepAliveInterval);;){let e;try{await u(new Promise(t=>{e=setTimeout(t,this.config.keepAliveInterval)}),this.closeController.signal),this.ping().catch(e=>this.log?.error(`ping error: %s`,e))}catch{clearInterval(e);return}}}async handleFrame(e,t){let{streamID:n,type:r,length:i}=e;if(this.log?.trace(`received frame %o`,e),n===0)switch(r){case J.Ping:this.handlePing(e);return;case J.GoAway:this.handleGoAway(i);return;default:throw new G(`Invalid frame type`)}else switch(e.type){case J.Data:case J.WindowUpdate:await this.handleStreamMessage(e,t);return;default:throw new G(`Invalid frame type`)}}handlePing(e){if(e.flag===Y.SYN)this.log?.trace(`received ping request pingId=%s`,e.length),this.sendPing(e.length,Y.ACK);else if(e.flag===Y.ACK)this.log?.trace(`received ping response pingId=%s`,e.length),this.handlePingResponse(e.length);else throw new G(`Invalid frame flag`)}handlePingResponse(e){if(this.activePing===void 0)throw new gn(`ping not requested`);if(this.activePing.id!==e)throw new _n(`ping doesn't match our id`);this.activePing.resolve()}handleGoAway(e){this.log?.trace(`received GoAway reason=%s`,X[e]??`unknown`),this.remoteGoAway=e;for(let e of this._streams.values())e.reset();this._closeMuxer()}async handleStreamMessage(e,t){let{streamID:n,flag:r,type:i}=e;(r&Y.SYN)===Y.SYN&&this.incomingStream(n);let a=this._streams.get(n);if(a===void 0){if(i===J.Data){if(this.log?.(`discarding data for stream id=%s`,n),t===void 0)throw Error(`unreachable`);await t()}else this.log?.trace(`frame for missing stream id=%s`,n);return}switch(i){case J.WindowUpdate:a.handleWindowUpdate(e);return;case J.Data:if(t===void 0)throw Error(`unreachable`);await a.handleData(e,t);return;default:throw Error(`unreachable`)}}incomingStream(e){if(this.client!==(e%2==0))throw new K(`Both endpoints are clients`);if(this._streams.has(e))return;if(this.log?.trace(`new incoming stream id=%s`,e),this.localGoAway!==void 0){this.sendFrame({type:J.WindowUpdate,flag:Y.RST,streamID:e,length:0});return}if(this.numInboundStreams>=this.config.maxInboundStreams){this.log?.(`maxIncomingStreams exceeded, forcing stream reset`),this.sendFrame({type:J.WindowUpdate,flag:Y.RST,streamID:e,length:0});return}let t=this._newStream(e,void 0,Z.SYNReceived,`inbound`);this.numInboundStreams++,this._streams.set(e,t),this.onIncomingStream?.(t)}sendFrame(e,t){if(this.log?.trace(`sending frame %o`,e),e.type===J.Data){if(t===void 0)throw new G(`Invalid frame`);this.source.push(new W(Pn(e),t))}else this.source.push(Pn(e))}sendPing(e,t=Y.SYN){t===Y.SYN?this.log?.trace(`sending ping request pingId=%s`,e):this.log?.trace(`sending ping response pingId=%s`,e),this.sendFrame({type:J.Ping,flag:t,streamID:0,length:e})}sendGoAway(e=X.NormalTermination){this.log?.(`sending GoAway reason=%s`,X[e]),this.localGoAway=e,this.sendFrame({type:J.GoAway,flag:0,streamID:0,length:e})}};function Yn(e){return e!=null&&typeof e.then==`function`}function Xn(e={}){return t=>new qn(t,e)}function Zn(){return async function*(e){for await(let t of e)U(t)?yield t.subarray():yield t}}var Qn=class{_waiters=new Set;_error;_terminated=!1;get terminated(){return this._terminated}terminate(e){if(this._terminated)return!1;this._terminated=!0,this._error=e;for(let t of this._waiters)t(e);return this._waiters.clear(),!0}async wait(e){if(this._terminated)return{terminated:!0,error:this._error};let t,n=new Promise(e=>{t=t=>e({terminated:!0,error:t}),this._waiters.add(t)}),r=e.then(e=>({result:e}),e=>({error:e}));try{let e=await Promise.race([r,n]);return this._terminated?{terminated:!0,error:this._error}:e}finally{this._waiters.delete(t)}}next(e){return this.wait(e.next())}};function $n(e){if(Symbol.asyncIterator in e)return e[Symbol.asyncIterator]();let t=e[Symbol.iterator]();return{next:async()=>t.next()}}function er(e){e.return&&Promise.resolve(e.return()).catch(()=>void 0)}function tr(e){let t=new Qn;return{close:async()=>{t.terminate()&&await e.close()},abort:n=>{t.terminate(n)&&e.abort(n)},source:(async function*(){let n=p(e,cn(),Zn())[Symbol.asyncIterator]();try{for(;;){let e=await t.next(n);if(`terminated`in e){if(e.error)throw e.error;return}if(`error`in e)throw e.error;if(e.result.done)return;yield e.result.value}}finally{er(n)}})(),sink:async n=>{let r=$n(p(n,sn())),i=(async function*(){for(;;){let e=await t.next(r);if(`terminated`in e){if(e.error)throw e.error;return}if(`error`in e)throw e.error;if(e.result.done||t.terminated)return;yield e.result.value}})();try{let n=await t.wait(e.sink(i));if(`terminated`in n){if(n.error)throw n.error;return}if(`error`in n)throw n.error;await e.closeWrite()}catch(n){let r=n instanceof Error?n:Error(String(n));throw t.terminate(r)&&e.abort(r),r}finally{er(r)}}}}function nr(e){let t=()=>{};return t.enabled=!1,t.color=``,t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t.debug=t,t.error=t,t.trace=t,t.newScope=()=>t,t}function rr(){return{forComponent:nr}}var ir=class{_muxer;_server;constructor(e,t){e&&(this._server=e);let n=t?.muxerFactory??Xn({enableKeepAlive:!1,...t?.yamuxParams})({logger:t?.logger??rr()});this._muxer=n.createStreamMuxer({onIncomingStream:this.handleIncomingStream.bind(this),direction:t?.direction||`outbound`})}get sink(){return this._muxer.sink}get source(){return this._muxer.source}get streams(){return this._muxer.streams}get muxer(){return this._muxer}get server(){return this._server}buildClient(){return new dn(this.openStream.bind(this))}async openStream(){return tr(await this.muxer.newStream())}buildOpenStreamFunc(){return this.openStream.bind(this)}handleIncomingStream(e){let t=this.server;if(!t)return e.abort(Error(`server not implemented`));t.handlePacketStream(tr(e))}close(e){e?this.muxer.abort(e):this.muxer.close()}},ar=async e=>{if(e.readyState>=2)throw Error(`socket closed`);e.readyState!==1&&await new Promise((t,n)=>{function r(){e.removeEventListener(`open`,i),e.removeEventListener(`error`,a)}function i(){r(),t()}function a(t){r(),n(t.error??Error(`connect ECONNREFUSED ${e.url}`))}e.addEventListener(`open`,i),e.addEventListener(`error`,a)})},or=(e,t)=>(t??={},t.closeOnEnd=t.closeOnEnd!==!1,async n=>{for await(let t of n){try{await ar(e)}catch(e){if(e.message===`socket closed`)break;throw e}if(e.readyState===e.CLOSING||e.readyState===e.CLOSED)break;e.send(t)}t.closeOnEnd!=null&&e.readyState<=1&&await new Promise((t,n)=>{e.addEventListener(`close`,e=>{e.wasClean||e.code===1006?t():n(Object.assign(Error(`ws error`),{event:e}))}),setTimeout(()=>{e.close()})})}),sr=e((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=class{constructor(){this.pullQueue=[],this.pushQueue=[],this.eventHandlers={},this.isPaused=!1,this.isStopped=!1}push(e){if(this.isStopped)return;let t={value:e,done:!1};if(this.pullQueue.length){let e=this.pullQueue.shift();e&&e.resolve(t)}else this.pushQueue.push(Promise.resolve(t)),this.highWaterMark!==void 0&&this.pushQueue.length>=this.highWaterMark&&!this.isPaused&&(this.isPaused=!0,this.eventHandlers.highWater?this.eventHandlers.highWater():console&&console.warn(`EventIterator queue reached ${this.pushQueue.length} items`))}stop(){if(!this.isStopped){this.isStopped=!0,this.remove();for(let e of this.pullQueue)e.resolve({value:void 0,done:!0});this.pullQueue.length=0}}fail(e){if(!this.isStopped){if(this.isStopped=!0,this.remove(),this.pullQueue.length){for(let t of this.pullQueue)t.reject(e);this.pullQueue.length=0}else{let t=Promise.reject(e);t.catch(()=>{}),this.pushQueue.push(t)}}}remove(){Promise.resolve().then(()=>{this.removeCallback&&this.removeCallback()})}[Symbol.asyncIterator](){return{next:e=>{let t=this.pushQueue.shift();return t?(this.lowWaterMark!==void 0&&this.pushQueue.length<=this.lowWaterMark&&this.isPaused&&(this.isPaused=!1,this.eventHandlers.lowWater&&this.eventHandlers.lowWater()),t):this.isStopped?Promise.resolve({value:void 0,done:!0}):new Promise((e,t)=>{this.pullQueue.push({resolve:e,reject:t})})},return:()=>(this.isStopped=!0,this.pushQueue.length=0,this.remove(),Promise.resolve({value:void 0,done:!0}))}}},n=class{constructor(e,{highWaterMark:n=100,lowWaterMark:r=1}={}){let i=new t;i.highWaterMark=n,i.lowWaterMark=r,i.removeCallback=e({push:e=>i.push(e),stop:()=>i.stop(),fail:e=>i.fail(e),on:(e,t)=>{i.eventHandlers[e]=t}})||(()=>{}),this[Symbol.asyncIterator]=()=>i[Symbol.asyncIterator](),Object.freeze(this)}};e.EventIterator=n,e.default=n})),cr=e((e=>{Object.defineProperty(e,"__esModule",{value:!0});let t=sr();e.EventIterator=t.EventIterator,e.default=t.EventIterator}))();function lr(e){return e instanceof ArrayBuffer||e?.constructor?.name===`ArrayBuffer`&&typeof e?.byteLength==`number`}var ur=e=>{e.binaryType=`arraybuffer`;let t=async()=>{await new Promise((t,n)=>{if(r){t();return}if(i!=null){n(i);return}let a=t=>{e.removeEventListener(`open`,o),e.removeEventListener(`error`,s),t()},o=()=>{a(t)},s=t=>{a(()=>{n(t.error??Error(`connect ECONNREFUSED ${e.url}`))})};e.addEventListener(`open`,o),e.addEventListener(`error`,s)})},n=async function*(){let n=new cr.EventIterator(({push:t,stop:n,fail:r})=>{let i=e=>{let n=null;if(typeof e.data==`string`)throw Error(`Unsupported string encoding`);lr(e.data)&&(n=new Uint8Array(e.data)),e.data instanceof Uint8Array&&(n=e.data),n!=null&&t(n)},a=e=>{r(e.error??Error(`Socket error`))};return e.addEventListener(`message`,i),e.addEventListener(`error`,a),e.addEventListener(`close`,n),()=>{e.removeEventListener(`message`,i),e.removeEventListener(`error`,a),e.removeEventListener(`close`,n)}},{highWaterMark:1/0});await t();for await(let e of n)yield lr(e)?new Uint8Array(e):e}(),r=e.readyState===1,i;return e.addEventListener(`open`,()=>{r=!0,i=null}),e.addEventListener(`close`,()=>{r=!1,i=null}),e.addEventListener(`error`,t=>{r||(i=t.error??Error(`connect ECONNREFUSED ${e.url}`))}),Object.assign(n,{connected:t})},dr=(e,t)=>{t??={};let n=ur(e),r=t.remoteAddress,i=t.remotePort;if(e.url!=null)try{let t=new URL(e.url);r=t.hostname,i=parseInt(t.port,10)}catch{}if(r==null||i==null)throw Error(`Remote connection did not have address and/or port`);return{sink:or(e,t),source:n,connected:async()=>{await n.connected()},close:async()=>{(e.readyState===e.CONNECTING||e.readyState===e.OPEN)&&await new Promise(t=>{e.addEventListener(`close`,()=>{t()}),e.close()})},destroy:()=>{e.terminate==null?e.close():e.terminate()},remoteAddress:r,remotePort:i,socket:e}},fr=class extends ir{socket;constructor(e,t,n){super(n,{direction:t}),this.socket=e;let r=dr(e);p(r,this,Zn(),r).catch(e=>this.close(e)).then(()=>this.close())}getSocket(){return this.socket}},Q;(function(e){e[e.Unary=0]=`Unary`,e[e.ServerStreaming=1]=`ServerStreaming`,e[e.ClientStreaming=2]=`ClientStreaming`,e[e.BiDiStreaming=3]=`BiDiStreaming`})(Q||={});var pr;(function(e){e[e.NoSideEffects=1]=`NoSideEffects`,e[e.Idempotent=2]=`Idempotent`})(pr||={});const mr=B({typeName:`rpcstream.RpcStreamInit`,fields:[{no:1,name:`component_id`,kind:`scalar`,T:v.STRING}],packedByDefault:!0}),hr=B({typeName:`rpcstream.RpcAck`,fields:[{no:1,name:`error`,kind:`scalar`,T:v.STRING}],packedByDefault:!0}),gr=B({typeName:`rpcstream.RpcStreamPacket`,fields:[{no:1,name:`init`,kind:`message`,T:()=>mr,oneof:`body`},{no:2,name:`ack`,kind:`message`,T:()=>hr,oneof:`body`},{no:3,name:`data`,kind:`scalar`,T:v.BYTES,oneof:`body`}],packedByDefault:!0}),$=B({typeName:`echo.EchoMsg`,fields:[{no:1,name:`body`,kind:`scalar`,T:v.STRING}],packedByDefault:!0}),_r=Pt(`google.protobuf.Empty`,!0);({typeName:`echo.Echoer`,methods:{Echo:{name:`Echo`,I:$,O:$,kind:Q.Unary},EchoServerStream:{name:`EchoServerStream`,I:$,O:$,kind:Q.ServerStreaming},EchoClientStream:{name:`EchoClientStream`,I:$,O:$,kind:Q.ClientStreaming},EchoBidiStream:{name:`EchoBidiStream`,I:$,O:$,kind:Q.BiDiStreaming},RpcStream:{name:`RpcStream`,I:gr,O:gr,kind:Q.BiDiStreaming},DoNothing:{name:`DoNothing`,I:_r,O:_r,kind:Q.Unary}}}).typeName;for(let e of[`dispose`,`asyncDispose`])Symbol[e]||Object.defineProperty(Symbol,e,{value:Symbol.for(`Symbol.${e}`)});const vr=Symbol.for(`spacewave.SyncError`);var yr=class extends Error{code;requestId;name=`SyncError`;[vr]=!0;static[Symbol.hasInstance](e){return e instanceof Error&&vr in e&&e[vr]===!0}constructor(e,t,n){super(t),this.code=e,this.requestId=n}};function br(e){return e instanceof yr?e:new yr(`STORAGE`,`The data operation could not complete`)}function xr(e){return wr(e,`$`,[])}function Sr(e){return new TextEncoder().encode(xr(e))}function Cr(e){let t;try{t=new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{throw TypeError(`invalid JSON at $: data is not valid UTF-8`)}let n;try{n=JSON.parse(t)}catch{throw TypeError(`invalid JSON at $: data is not valid JSON`)}return xr(n),n}function wr(e,t,n){switch(typeof e){case`boolean`:return e?`true`:`false`;case`number`:if(!Number.isFinite(e))throw TypeError(`invalid JSON at ${t}: non-finite number`);return JSON.stringify(e);case`string`:return JSON.stringify(e);case`object`:if(e===null)return`null`;break;default:throw TypeError(`invalid JSON at ${t}: ${typeof e} is not a JSON value`)}for(let r of n)if(r===e)throw TypeError(`invalid JSON at ${t}: cycle`);n.push(e);let r=Array.isArray(e)?Tr(e,t,n):Er(e,t,n);return n.pop(),r}function Tr(e,t,n){let r=e.length,i=Array.from({length:r}),a=Array.from({length:r},()=>!1);for(let o of Reflect.ownKeys(e)){let s=Object.getOwnPropertyDescriptor(e,o);if(s.get!==void 0||s.set!==void 0)throw TypeError(`invalid JSON at ${t}[${String(o)}]: accessor property`);if(typeof o==`symbol`){if(s.enumerable)throw TypeError(`invalid JSON at ${t}: enumerable symbol key is not supported`);continue}let c=Number(o);if(Number.isInteger(c)&&c>=0&&c<r&&String(c)===o){a[c]=!0,i[c]=wr(s.value,`${t}[${c}]`,n);continue}if(s.enumerable)throw TypeError(`invalid JSON at ${t}: extra enumerable array property ${JSON.stringify(o)}`)}for(let e=0;e<r;e++)if(!a[e])throw TypeError(`invalid JSON at ${t}[${e}]: array hole (missing index)`);return`[${i.join(`,`)}]`}function Er(e,t,n){let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw TypeError(`invalid JSON at ${t}: not a plain object`);let i=[];for(let r of Reflect.ownKeys(e)){let a=Object.getOwnPropertyDescriptor(e,r);if(a.get!==void 0||a.set!==void 0)throw TypeError(`invalid JSON at ${t}.${String(r)}: accessor property`);if(typeof r==`symbol`){if(a.enumerable)throw TypeError(`invalid JSON at ${t}: enumerable symbol key is not supported`);continue}a.enumerable&&i.push({key:r,json:wr(a.value,`${t}.${r}`,n)})}return i.sort((e,t)=>e.key<t.key?-1:+(e.key>t.key)),`{${i.map(e=>`${JSON.stringify(e.key)}:${e.json}`).join(`,`)}}`}export{t as C,l as S,n as T,Pt as _,br as a,v as b,ir as c,$n as d,Zn as f,Qt as g,Zt as h,yr as i,Qn as l,dn as m,Cr as n,Q as o,pn as p,Sr as r,fr as s,xr as t,er as u,B as v,i as w,p as x,Je as y};
|