var __bare_os_bundle_exports__ = (() => { var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // ../../node_modules/safety-catch/index.js var require_safety_catch = __commonJS({ "../../node_modules/safety-catch/index.js"(exports, module) { module.exports = safetyCatch; function isActuallyUncaught(err) { if (!err) return false; return err instanceof TypeError || err instanceof SyntaxError || err instanceof ReferenceError || err instanceof EvalError || err instanceof RangeError || err instanceof URIError || err.code === "ERR_ASSERTION" || err.name === "AssertionError"; } function throwErrorNT(err) { queueMicrotask(() => { throw err; }); } function safetyCatch(err) { if (isActuallyUncaught(err)) { throwErrorNT(err); throw err; } } } }); // ../../node_modules/b4a/index.js var require_b4a = __commonJS({ "../../node_modules/b4a/index.js"(exports, module) { function isBuffer(value) { return Buffer.isBuffer(value) || value instanceof Uint8Array; } function isEncoding(encoding) { return Buffer.isEncoding(encoding); } function alloc(size, fill2, encoding) { return Buffer.alloc(size, fill2, encoding); } function allocUnsafe(size) { return Buffer.allocUnsafe(size); } function allocUnsafeSlow(size) { return Buffer.allocUnsafeSlow(size); } function byteLength(string, encoding) { return Buffer.byteLength(string, encoding); } function compare(a, b) { return Buffer.compare(a, b); } function concat(buffers, totalLength) { return Buffer.concat(buffers, totalLength); } function copy(source, target, targetStart, start, end) { return toBuffer(source).copy(target, targetStart, start, end); } function equals(a, b) { return toBuffer(a).equals(b); } function fill(buffer, value, offset, end, encoding) { return toBuffer(buffer).fill(value, offset, end, encoding); } function from(value, encodingOrOffset, length) { return Buffer.from(value, encodingOrOffset, length); } function includes(buffer, value, byteOffset, encoding) { return toBuffer(buffer).includes(value, byteOffset, encoding); } function indexOf(buffer, value, byfeOffset, encoding) { return toBuffer(buffer).indexOf(value, byfeOffset, encoding); } function lastIndexOf(buffer, value, byteOffset, encoding) { return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding); } function swap16(buffer) { return toBuffer(buffer).swap16(); } function swap32(buffer) { return toBuffer(buffer).swap32(); } function swap64(buffer) { return toBuffer(buffer).swap64(); } function toBuffer(buffer) { if (Buffer.isBuffer(buffer)) return buffer; return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength); } function toString(buffer, encoding, start, end) { return toBuffer(buffer).toString(encoding, start, end); } function write(buffer, string, offset, length, encoding) { return toBuffer(buffer).write(string, offset, length, encoding); } function readDoubleBE(buffer, offset) { return toBuffer(buffer).readDoubleBE(offset); } function readDoubleLE(buffer, offset) { return toBuffer(buffer).readDoubleLE(offset); } function readFloatBE(buffer, offset) { return toBuffer(buffer).readFloatBE(offset); } function readFloatLE(buffer, offset) { return toBuffer(buffer).readFloatLE(offset); } function readInt32BE(buffer, offset) { return toBuffer(buffer).readInt32BE(offset); } function readInt32LE(buffer, offset) { return toBuffer(buffer).readInt32LE(offset); } function readUInt32BE(buffer, offset) { return toBuffer(buffer).readUInt32BE(offset); } function readUInt32LE(buffer, offset) { return toBuffer(buffer).readUInt32LE(offset); } function writeDoubleBE(buffer, value, offset) { return toBuffer(buffer).writeDoubleBE(value, offset); } function writeDoubleLE(buffer, value, offset) { return toBuffer(buffer).writeDoubleLE(value, offset); } function writeFloatBE(buffer, value, offset) { return toBuffer(buffer).writeFloatBE(value, offset); } function writeFloatLE(buffer, value, offset) { return toBuffer(buffer).writeFloatLE(value, offset); } function writeInt32BE(buffer, value, offset) { return toBuffer(buffer).writeInt32BE(value, offset); } function writeInt32LE(buffer, value, offset) { return toBuffer(buffer).writeInt32LE(value, offset); } function writeUInt32BE(buffer, value, offset) { return toBuffer(buffer).writeUInt32BE(value, offset); } function writeUInt32LE(buffer, value, offset) { return toBuffer(buffer).writeUInt32LE(value, offset); } module.exports = { isBuffer, isEncoding, alloc, allocUnsafe, allocUnsafeSlow, byteLength, compare, concat, copy, equals, fill, from, includes, indexOf, lastIndexOf, swap16, swap32, swap64, toBuffer, toString, write, readDoubleBE, readDoubleLE, readFloatBE, readFloatLE, readInt32BE, readInt32LE, readUInt32BE, readUInt32LE, writeDoubleBE, writeDoubleLE, writeFloatBE, writeFloatLE, writeInt32BE, writeInt32LE, writeUInt32BE, writeUInt32LE }; } }); // ../../node_modules/bare-rpc/node_modules/compact-encoding/endian.js var require_endian = __commonJS({ "../../node_modules/bare-rpc/node_modules/compact-encoding/endian.js"(exports) { var LE = exports.LE = new Uint8Array(new Uint16Array([255]).buffer)[0] === 255; exports.BE = !LE; } }); // ../../node_modules/bare-rpc/node_modules/compact-encoding/raw.js var require_raw = __commonJS({ "../../node_modules/bare-rpc/node_modules/compact-encoding/raw.js"(exports, module) { var b4a = require_b4a(); var { BE } = require_endian(); exports = module.exports = { preencode(state, b) { state.end += b.byteLength; }, encode(state, b) { state.buffer.set(b, state.start); state.start += b.byteLength; }, decode(state) { const b = state.buffer.subarray(state.start, state.end); state.start = state.end; return b; } }; var buffer = exports.buffer = { preencode(state, b) { uint8array.preencode(state, b); }, encode(state, b) { uint8array.encode(state, b); }, decode(state) { const b = state.buffer.subarray(state.start); state.start = state.end; return b; } }; exports.binary = { ...buffer, preencode(state, b) { if (typeof b === "string") utf8.preencode(state, b); else buffer.preencode(state, b); }, encode(state, b) { if (typeof b === "string") utf8.encode(state, b); else buffer.encode(state, b); } }; exports.arraybuffer = { preencode(state, b) { state.end += b.byteLength; }, encode(state, b) { const view = new Uint8Array(b); state.buffer.set(view, state.start); state.start += b.byteLength; }, decode(state) { const b = new ArrayBuffer(state.end - state.start); const view = new Uint8Array(b); view.set(state.buffer.subarray(state.start)); state.start = state.end; return b; } }; function typedarray(TypedArray, swap) { const n = TypedArray.BYTES_PER_ELEMENT; return { preencode(state, b) { state.end += b.byteLength; }, encode(state, b) { const view = new Uint8Array(b.buffer, b.byteOffset, b.byteLength); if (BE && swap) swap(view); state.buffer.set(view, state.start); state.start += b.byteLength; }, decode(state) { let b = state.buffer.subarray(state.start); if (b.byteOffset % n !== 0) b = new Uint8Array(b); if (BE && swap) swap(b); state.start = state.end; return new TypedArray(b.buffer, b.byteOffset, b.byteLength / n); } }; } var uint8array = exports.uint8array = typedarray(Uint8Array); exports.uint16array = typedarray(Uint16Array, b4a.swap16); exports.uint32array = typedarray(Uint32Array, b4a.swap32); exports.int8array = typedarray(Int8Array); exports.int16array = typedarray(Int16Array, b4a.swap16); exports.int32array = typedarray(Int32Array, b4a.swap32); exports.biguint64array = typedarray(BigUint64Array, b4a.swap64); exports.bigint64array = typedarray(BigInt64Array, b4a.swap64); exports.float32array = typedarray(Float32Array, b4a.swap32); exports.float64array = typedarray(Float64Array, b4a.swap64); function string(encoding) { return { preencode(state, s) { state.end += b4a.byteLength(s, encoding); }, encode(state, s) { state.start += b4a.write(state.buffer, s, state.start, encoding); }, decode(state) { const s = b4a.toString(state.buffer, encoding, state.start); state.start = state.end; return s; } }; } var utf8 = exports.string = exports.utf8 = string("utf-8"); exports.ascii = string("ascii"); exports.hex = string("hex"); exports.base64 = string("base64"); exports.ucs2 = exports.utf16le = string("utf16le"); exports.array = function array(enc) { return { preencode(state, list) { for (const value of list) enc.preencode(state, value); }, encode(state, list) { for (const value of list) enc.encode(state, value); }, decode(state) { const arr = []; while (state.start < state.end) arr.push(enc.decode(state)); return arr; } }; }; exports.json = { preencode(state, v) { utf8.preencode(state, JSON.stringify(v)); }, encode(state, v) { utf8.encode(state, JSON.stringify(v)); }, decode(state) { return JSON.parse(utf8.decode(state)); } }; exports.ndjson = { preencode(state, v) { utf8.preencode(state, JSON.stringify(v) + "\n"); }, encode(state, v) { utf8.encode(state, JSON.stringify(v) + "\n"); }, decode(state) { return JSON.parse(utf8.decode(state)); } }; } }); // ../../node_modules/bare-rpc/node_modules/compact-encoding/lexint.js var require_lexint = __commonJS({ "../../node_modules/bare-rpc/node_modules/compact-encoding/lexint.js"(exports, module) { module.exports = { preencode, encode, decode }; function preencode(state, num) { if (num < 251) { state.end++; } else if (num < 256) { state.end += 2; } else if (num < 65536) { state.end += 3; } else if (num < 16777216) { state.end += 4; } else if (num < 4294967296) { state.end += 5; } else { state.end++; const exp = Math.floor(Math.log(num) / Math.log(2)) - 32; preencode(state, exp); state.end += 6; } } function encode(state, num) { const max = 251; const x = num - max; if (num < max) { state.buffer[state.start++] = num; } else if (num < 256) { state.buffer[state.start++] = max; state.buffer[state.start++] = x; } else if (num < 65536) { state.buffer[state.start++] = max + 1; state.buffer[state.start++] = x >> 8 & 255; state.buffer[state.start++] = x & 255; } else if (num < 16777216) { state.buffer[state.start++] = max + 2; state.buffer[state.start++] = x >> 16; state.buffer[state.start++] = x >> 8 & 255; state.buffer[state.start++] = x & 255; } else if (num < 4294967296) { state.buffer[state.start++] = max + 3; state.buffer[state.start++] = x >> 24; state.buffer[state.start++] = x >> 16 & 255; state.buffer[state.start++] = x >> 8 & 255; state.buffer[state.start++] = x & 255; } else { const exp = Math.floor(Math.log(x) / Math.log(2)) - 32; state.buffer[state.start++] = 255; encode(state, exp); const rem = x / Math.pow(2, exp - 11); for (let i = 5; i >= 0; i--) { state.buffer[state.start++] = rem / Math.pow(2, 8 * i) & 255; } } } function decode(state) { const max = 251; if (state.end - state.start < 1) throw new Error("Out of bounds"); const flag = state.buffer[state.start++]; if (flag < max) return flag; if (state.end - state.start < flag - max + 1) { throw new Error("Out of bounds."); } if (flag < 252) { return state.buffer[state.start++] + max; } if (flag < 253) { return (state.buffer[state.start++] << 8) + state.buffer[state.start++] + max; } if (flag < 254) { return (state.buffer[state.start++] << 16) + (state.buffer[state.start++] << 8) + state.buffer[state.start++] + max; } if (flag < 255) { return state.buffer[state.start++] * 16777216 + (state.buffer[state.start++] << 16) + (state.buffer[state.start++] << 8) + state.buffer[state.start++] + max; } const exp = decode(state); if (state.end - state.start < 6) throw new Error("Out of bounds"); let rem = 0; for (let i = 5; i >= 0; i--) { rem += state.buffer[state.start++] * Math.pow(2, 8 * i); } return rem * Math.pow(2, exp - 11) + max; } } }); // ../../node_modules/bare-rpc/node_modules/compact-encoding/index.js var require_compact_encoding = __commonJS({ "../../node_modules/bare-rpc/node_modules/compact-encoding/index.js"(exports) { var b4a = require_b4a(); var { BE } = require_endian(); exports.state = function(start = 0, end = 0, buffer2 = null) { return { start, end, buffer: buffer2 }; }; var raw = exports.raw = require_raw(); var uint = exports.uint = { preencode(state, n) { state.end += n <= 252 ? 1 : n <= 65535 ? 3 : n <= 4294967295 ? 5 : 9; }, encode(state, n) { if (n <= 252) uint8.encode(state, n); else if (n <= 65535) { state.buffer[state.start++] = 253; uint16.encode(state, n); } else if (n <= 4294967295) { state.buffer[state.start++] = 254; uint32.encode(state, n); } else { state.buffer[state.start++] = 255; uint64.encode(state, n); } }, decode(state) { const a = uint8.decode(state); if (a <= 252) return a; if (a === 253) return uint16.decode(state); if (a === 254) return uint32.decode(state); return uint64.decode(state); } }; var uint8 = exports.uint8 = { preencode(state, n) { state.end += 1; }, encode(state, n) { validateUint(n); state.buffer[state.start++] = n; }, decode(state) { if (state.start >= state.end) throw new Error("Out of bounds"); return state.buffer[state.start++]; } }; var uint16 = exports.uint16 = { preencode(state, n) { state.end += 2; }, encode(state, n) { validateUint(n); state.buffer[state.start++] = n; state.buffer[state.start++] = n >>> 8; }, decode(state) { if (state.end - state.start < 2) throw new Error("Out of bounds"); return state.buffer[state.start++] + state.buffer[state.start++] * 256; } }; var uint24 = exports.uint24 = { preencode(state, n) { state.end += 3; }, encode(state, n) { validateUint(n); state.buffer[state.start++] = n; state.buffer[state.start++] = n >>> 8; state.buffer[state.start++] = n >>> 16; }, decode(state) { if (state.end - state.start < 3) throw new Error("Out of bounds"); return state.buffer[state.start++] + state.buffer[state.start++] * 256 + state.buffer[state.start++] * 65536; } }; var uint32 = exports.uint32 = { preencode(state, n) { state.end += 4; }, encode(state, n) { validateUint(n); state.buffer[state.start++] = n; state.buffer[state.start++] = n >>> 8; state.buffer[state.start++] = n >>> 16; state.buffer[state.start++] = n >>> 24; }, decode(state) { if (state.end - state.start < 4) throw new Error("Out of bounds"); return state.buffer[state.start++] + state.buffer[state.start++] * 256 + state.buffer[state.start++] * 65536 + state.buffer[state.start++] * 16777216; } }; var uint32be = exports.uint32be = { preencode(state, n) { state.end += 4; }, encode(state, n) { validateUint(n); state.buffer[state.start++] = n >>> 24; state.buffer[state.start++] = n >>> 16; state.buffer[state.start++] = n >>> 8; state.buffer[state.start++] = n; }, decode(state) { if (state.end - state.start < 4) throw new Error("Out of bounds"); return state.buffer[state.start++] * 16777216 + state.buffer[state.start++] * 65536 + state.buffer[state.start++] * 256 + state.buffer[state.start++]; } }; var uint40 = exports.uint40 = { preencode(state, n) { state.end += 5; }, encode(state, n) { validateUint(n); const r = Math.floor(n / 256); uint8.encode(state, n); uint32.encode(state, r); }, decode(state) { if (state.end - state.start < 5) throw new Error("Out of bounds"); return uint8.decode(state) + 256 * uint32.decode(state); } }; var uint48 = exports.uint48 = { preencode(state, n) { state.end += 6; }, encode(state, n) { validateUint(n); const r = Math.floor(n / 65536); uint16.encode(state, n); uint32.encode(state, r); }, decode(state) { if (state.end - state.start < 6) throw new Error("Out of bounds"); return uint16.decode(state) + 65536 * uint32.decode(state); } }; var uint56 = exports.uint56 = { preencode(state, n) { state.end += 7; }, encode(state, n) { validateUint(n); const r = Math.floor(n / 16777216); uint24.encode(state, n); uint32.encode(state, r); }, decode(state) { if (state.end - state.start < 7) throw new Error("Out of bounds"); return validateSafeUint( uint24.decode(state) + 16777216 * uint32.decode(state) ); } }; var uint64 = exports.uint64 = { preencode(state, n) { state.end += 8; }, encode(state, n) { validateUint(n); const r = Math.floor(n / 4294967296); uint32.encode(state, n); uint32.encode(state, r); }, decode(state) { if (state.end - state.start < 8) throw new Error("Out of bounds"); return validateSafeUint( uint32.decode(state) + 4294967296 * uint32.decode(state) ); } }; exports.uint64be = { preencode(state, n) { state.end += 8; }, encode(state, n) { validateUint(n); const r = Math.floor(n / 4294967296); uint32be.encode(state, r); uint32be.encode(state, n); }, decode(state) { if (state.end - state.start < 8) throw new Error("Out of bounds"); return validateSafeUint( 4294967296 * uint32be.decode(state) + uint32be.decode(state) ); } }; var int = exports.int = zigZagInt(uint); exports.int8 = zigZagInt(uint8); exports.int16 = zigZagInt(uint16); exports.int24 = zigZagInt(uint24); exports.int32 = zigZagInt(uint32); exports.int40 = zigZagInt(uint40); exports.int48 = zigZagInt(uint48); exports.int56 = zigZagInt(uint56); exports.int64 = zigZagInt(uint64); var biguint64 = exports.biguint64 = { preencode(state, n) { state.end += 8; }, encode(state, n) { const view = new DataView( state.buffer.buffer, state.start + state.buffer.byteOffset, 8 ); view.setBigUint64(0, n, true); state.start += 8; }, decode(state) { if (state.end - state.start < 8) throw new Error("Out of bounds"); const view = new DataView( state.buffer.buffer, state.start + state.buffer.byteOffset, 8 ); const n = view.getBigUint64(0, true); state.start += 8; return n; } }; exports.bigint64 = zigZagBigInt(biguint64); var biguint = exports.biguint = { preencode(state, n) { let len = 0; for (let m = n; m; m = m >> 64n) len++; uint.preencode(state, len); state.end += 8 * len; }, encode(state, n) { let len = 0; for (let m = n; m; m = m >> 64n) len++; uint.encode(state, len); const view = new DataView( state.buffer.buffer, state.start + state.buffer.byteOffset, 8 * len ); for (let m = n, i = 0; m; m = m >> 64n, i += 8) { view.setBigUint64(i, BigInt.asUintN(64, m), true); } state.start += 8 * len; }, decode(state) { const len = uint.decode(state); if (state.end - state.start < 8 * len) throw new Error("Out of bounds"); const view = new DataView( state.buffer.buffer, state.start + state.buffer.byteOffset, 8 * len ); let n = 0n; for (let i = len - 1; i >= 0; i--) n = (n << 64n) + view.getBigUint64(i * 8, true); state.start += 8 * len; return n; } }; exports.bigint = zigZagBigInt(biguint); exports.lexint = require_lexint(); exports.float32 = { preencode(state, n) { state.end += 4; }, encode(state, n) { const view = new DataView( state.buffer.buffer, state.start + state.buffer.byteOffset, 4 ); view.setFloat32(0, n, true); state.start += 4; }, decode(state) { if (state.end - state.start < 4) throw new Error("Out of bounds"); const view = new DataView( state.buffer.buffer, state.start + state.buffer.byteOffset, 4 ); const float = view.getFloat32(0, true); state.start += 4; return float; } }; exports.float64 = { preencode(state, n) { state.end += 8; }, encode(state, n) { const view = new DataView( state.buffer.buffer, state.start + state.buffer.byteOffset, 8 ); view.setFloat64(0, n, true); state.start += 8; }, decode(state) { if (state.end - state.start < 8) throw new Error("Out of bounds"); const view = new DataView( state.buffer.buffer, state.start + state.buffer.byteOffset, 8 ); const float = view.getFloat64(0, true); state.start += 8; return float; } }; var buffer = exports.buffer = { preencode(state, b) { uint8array.preencode(state, b); }, encode(state, b) { uint8array.encode(state, b); }, decode(state) { const len = uint.decode(state); if (state.end - state.start < len) throw new Error("Out of bounds"); return state.buffer.subarray(state.start, state.start += len); } }; exports.optionalBuffer = { preencode(state, b) { if (b) uint8array.preencode(state, b); else state.end++; }, encode(state, b) { if (b) uint8array.encode(state, b); else state.buffer[state.start++] = 0; }, decode(state) { const len = uint.decode(state); if (len === 0) return null; if (state.end - state.start < len) throw new Error("Out of bounds"); return state.buffer.subarray(state.start, state.start += len); } }; exports.binary = { ...buffer, preencode(state, b) { if (typeof b === "string") utf8.preencode(state, b); else buffer.preencode(state, b); }, encode(state, b) { if (typeof b === "string") utf8.encode(state, b); else buffer.encode(state, b); } }; exports.arraybuffer = { preencode(state, b) { uint.preencode(state, b.byteLength); state.end += b.byteLength; }, encode(state, b) { uint.encode(state, b.byteLength); const view = new Uint8Array(b); state.buffer.set(view, state.start); state.start += b.byteLength; }, decode(state) { const len = uint.decode(state); const b = new ArrayBuffer(len); const view = new Uint8Array(b); view.set(state.buffer.subarray(state.start, state.start += len)); return b; } }; function typedarray(TypedArray, swap) { const n = TypedArray.BYTES_PER_ELEMENT; return { preencode(state, b) { uint.preencode(state, b.length); state.end += b.byteLength; }, encode(state, b) { uint.encode(state, b.length); const view = new Uint8Array(b.buffer, b.byteOffset, b.byteLength); if (BE && swap) swap(view); state.buffer.set(view, state.start); state.start += b.byteLength; }, decode(state) { const len = uint.decode(state); let b = state.buffer.subarray(state.start, state.start += len * n); if (b.byteLength !== len * n) throw new Error("Out of bounds"); if (b.byteOffset % n !== 0) b = new Uint8Array(b); if (BE && swap) swap(b); return new TypedArray(b.buffer, b.byteOffset, b.byteLength / n); } }; } var uint8array = exports.uint8array = typedarray(Uint8Array); exports.uint16array = typedarray(Uint16Array, b4a.swap16); exports.uint32array = typedarray(Uint32Array, b4a.swap32); exports.int8array = typedarray(Int8Array); exports.int16array = typedarray(Int16Array, b4a.swap16); exports.int32array = typedarray(Int32Array, b4a.swap32); exports.biguint64array = typedarray(BigUint64Array, b4a.swap64); exports.bigint64array = typedarray(BigInt64Array, b4a.swap64); exports.float32array = typedarray(Float32Array, b4a.swap32); exports.float64array = typedarray(Float64Array, b4a.swap64); function string(encoding) { return { preencode(state, s) { const len = b4a.byteLength(s, encoding); uint.preencode(state, len); state.end += len; }, encode(state, s) { const len = b4a.byteLength(s, encoding); uint.encode(state, len); b4a.write(state.buffer, s, state.start, encoding); state.start += len; }, decode(state) { const len = uint.decode(state); if (state.end - state.start < len) throw new Error("Out of bounds"); return b4a.toString( state.buffer, encoding, state.start, state.start += len ); }, fixed(n) { return { preencode(state) { state.end += n; }, encode(state, s) { b4a.write(state.buffer, s, state.start, n, encoding); state.start += n; }, decode(state) { if (state.end - state.start < n) throw new Error("Out of bounds"); return b4a.toString( state.buffer, encoding, state.start, state.start += n ); } }; } }; } var utf8 = exports.string = exports.utf8 = string("utf-8"); exports.ascii = string("ascii"); exports.hex = string("hex"); exports.base64 = string("base64"); exports.ucs2 = exports.utf16le = string("utf16le"); exports.bool = { preencode(state, b) { state.end++; }, encode(state, b) { state.buffer[state.start++] = b ? 1 : 0; }, decode(state) { if (state.start >= state.end) throw Error("Out of bounds"); return state.buffer[state.start++] === 1; } }; var fixed = exports.fixed = function fixed2(n) { return { preencode(state, s) { if (s.byteLength !== n) throw new Error("Incorrect buffer size"); state.end += n; }, encode(state, s) { state.buffer.set(s, state.start); state.start += n; }, decode(state) { if (state.end - state.start < n) throw new Error("Out of bounds"); return state.buffer.subarray(state.start, state.start += n); } }; }; exports.fixed32 = fixed(32); exports.fixed64 = fixed(64); exports.array = function array(enc) { return { preencode(state, list) { uint.preencode(state, list.length); for (let i = 0; i < list.length; i++) enc.preencode(state, list[i]); }, encode(state, list) { uint.encode(state, list.length); for (let i = 0; i < list.length; i++) enc.encode(state, list[i]); }, decode(state) { const len = uint.decode(state); if (len > 1048576) throw new Error("Array is too big"); const arr = new Array(len); for (let i = 0; i < len; i++) arr[i] = enc.decode(state); return arr; } }; }; exports.frame = function frame(enc) { const dummy = exports.state(); return { preencode(state, m) { const end = state.end; enc.preencode(state, m); uint.preencode(state, state.end - end); }, encode(state, m) { dummy.end = 0; enc.preencode(dummy, m); uint.encode(state, dummy.end); enc.encode(state, m); }, decode(state) { const end = state.end; const len = uint.decode(state); state.end = state.start + len; const m = enc.decode(state); state.start = state.end; state.end = end; return m; } }; }; exports.date = { preencode(state, d) { int.preencode(state, d.getTime()); }, encode(state, d) { int.encode(state, d.getTime()); }, decode(state, d) { return new Date(int.decode(state)); } }; exports.json = { preencode(state, v) { utf8.preencode(state, JSON.stringify(v)); }, encode(state, v) { utf8.encode(state, JSON.stringify(v)); }, decode(state) { return JSON.parse(utf8.decode(state)); } }; exports.ndjson = { preencode(state, v) { utf8.preencode(state, JSON.stringify(v) + "\n"); }, encode(state, v) { utf8.encode(state, JSON.stringify(v) + "\n"); }, decode(state) { return JSON.parse(utf8.decode(state)); } }; exports.none = { preencode(state, n) { }, encode(state, n) { }, decode(state) { return null; } }; var anyArray = { preencode(state, arr) { uint.preencode(state, arr.length); for (let i = 0; i < arr.length; i++) { any.preencode(state, arr[i]); } }, encode(state, arr) { uint.encode(state, arr.length); for (let i = 0; i < arr.length; i++) { any.encode(state, arr[i]); } }, decode(state) { const arr = []; let len = uint.decode(state); while (len-- > 0) { arr.push(any.decode(state)); } return arr; } }; var anyObject = { preencode(state, o) { const keys = Object.keys(o); uint.preencode(state, keys.length); for (const key of keys) { utf8.preencode(state, key); any.preencode(state, o[key]); } }, encode(state, o) { const keys = Object.keys(o); uint.encode(state, keys.length); for (const key of keys) { utf8.encode(state, key); any.encode(state, o[key]); } }, decode(state) { let len = uint.decode(state); const o = {}; while (len-- > 0) { const key = utf8.decode(state); o[key] = any.decode(state); } return o; } }; var anyTypes = [ exports.none, exports.bool, exports.string, exports.buffer, exports.uint, exports.int, exports.float64, anyArray, anyObject, exports.date ]; var any = exports.any = { preencode(state, o) { const t = getType(o); uint.preencode(state, t); anyTypes[t].preencode(state, o); }, encode(state, o) { const t = getType(o); uint.encode(state, t); anyTypes[t].encode(state, o); }, decode(state) { const t = uint.decode(state); if (t >= anyTypes.length) throw new Error("Unknown type: " + t); return anyTypes[t].decode(state); } }; var port = exports.port = uint16; var address = (host, family) => { return { preencode(state, m) { host.preencode(state, m.host); port.preencode(state, m.port); }, encode(state, m) { host.encode(state, m.host); port.encode(state, m.port); }, decode(state) { return { host: host.decode(state), family, port: port.decode(state) }; } }; }; var ipv4 = exports.ipv4 = { preencode(state) { state.end += 4; }, encode(state, string2) { const start = state.start; const end = start + 4; let i = 0; while (i < string2.length) { let n = 0; let c; while (i < string2.length && (c = string2.charCodeAt(i++)) !== /* . */ 46) { n = n * 10 + (c - /* 0 */ 48); } state.buffer[state.start++] = n; } state.start = end; }, decode(state) { if (state.end - state.start < 4) throw new Error("Out of bounds"); return state.buffer[state.start++] + "." + state.buffer[state.start++] + "." + state.buffer[state.start++] + "." + state.buffer[state.start++]; } }; exports.ipv4Address = address(ipv4, 4); var ipv6 = exports.ipv6 = { preencode(state) { state.end += 16; }, encode(state, string2) { const start = state.start; const end = start + 16; let i = 0; let split = null; while (i < string2.length) { let n = 0; let c; while (i < string2.length && (c = string2.charCodeAt(i++)) !== /* : */ 58) { if (c >= 48 && c <= 57) n = n * 16 + (c - /* 0 */ 48); else if (c >= 65 && c <= 70) n = n * 16 + (c - /* A */ 65 + 10); else if (c >= 97 && c <= 102) n = n * 16 + (c - /* a */ 97 + 10); } state.buffer[state.start++] = n >>> 8; state.buffer[state.start++] = n; if (i < string2.length && string2.charCodeAt(i) === /* : */ 58) { i++; split = state.start; } } if (split !== null) { const offset = end - state.start; state.buffer.copyWithin(split + offset, split).fill(0, split, split + offset); } state.start = end; }, decode(state) { if (state.end - state.start < 16) throw new Error("Out of bounds"); return (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16); } }; exports.ipv6Address = address(ipv6, 6); var ip = exports.ip = { preencode(state, string2) { const family = string2.includes(":") ? 6 : 4; uint8.preencode(state, family); if (family === 4) ipv4.preencode(state); else ipv6.preencode(state); }, encode(state, string2) { const family = string2.includes(":") ? 6 : 4; uint8.encode(state, family); if (family === 4) ipv4.encode(state, string2); else ipv6.encode(state, string2); }, decode(state) { const family = uint8.decode(state); if (family === 4) return ipv4.decode(state); else return ipv6.decode(state); } }; exports.ipAddress = { preencode(state, m) { ip.preencode(state, m.host); port.preencode(state, m.port); }, encode(state, m) { ip.encode(state, m.host); port.encode(state, m.port); }, decode(state) { const family = uint8.decode(state); return { host: family === 4 ? ipv4.decode(state) : ipv6.decode(state), family, port: port.decode(state) }; } }; var record = exports.record = function(keyEncoding, valueEncoding) { return { preencode(state, v) { const keys = Object.keys(v); uint.preencode(state, keys.length); for (const k of keys) { keyEncoding.preencode(state, k); valueEncoding.preencode(state, v[k]); } }, encode(state, v) { const keys = Object.keys(v); uint.encode(state, keys.length); for (const k of keys) { keyEncoding.encode(state, k); valueEncoding.encode(state, v[k]); } }, decode(state) { const out = /* @__PURE__ */ Object.create(null); const keys = uint.decode(state); for (let i = 0; i < keys; i++) { out[keyEncoding.decode(state)] = valueEncoding.decode(state); } return out; } }; }; exports.stringRecord = record(utf8, utf8); function getType(o) { if (o === null || o === void 0) return 0; if (typeof o === "boolean") return 1; if (typeof o === "string") return 2; if (b4a.isBuffer(o)) return 3; if (typeof o === "number") { if (Number.isInteger(o)) return o >= 0 ? 4 : 5; return 6; } if (Array.isArray(o)) return 7; if (o instanceof Date) return 9; if (typeof o === "object") return 8; throw new Error("Unsupported type for " + o); } exports.from = function from(enc) { if (typeof enc === "string") return fromNamed(enc); if (enc.preencode) return enc; if (enc.encodingLength) return fromAbstractEncoder(enc); return fromCodec(enc); }; function fromNamed(enc) { switch (enc) { case "ascii": return raw.ascii; case "utf-8": case "utf8": return raw.utf8; case "hex": return raw.hex; case "base64": return raw.base64; case "utf16-le": case "utf16le": case "ucs-2": case "ucs2": return raw.ucs2; case "ndjson": return raw.ndjson; case "json": return raw.json; case "binary": default: return raw.binary; } } function fromCodec(enc) { let tmpM = null; let tmpBuf = null; return { preencode(state, m) { tmpM = m; tmpBuf = enc.encode(m); state.end += tmpBuf.byteLength; }, encode(state, m) { raw.encode(state, m === tmpM ? tmpBuf : enc.encode(m)); tmpM = tmpBuf = null; }, decode(state) { return enc.decode(raw.decode(state)); } }; } function fromAbstractEncoder(enc) { return { preencode(state, m) { state.end += enc.encodingLength(m); }, encode(state, m) { enc.encode(m, state.buffer, state.start); state.start += enc.encode.bytes; }, decode(state) { const m = enc.decode(state.buffer, state.start, state.end); state.start += enc.decode.bytes; return m; } }; } exports.encode = function encode(enc, m) { const state = exports.state(); enc.preencode(state, m); state.buffer = b4a.allocUnsafe(state.end); enc.encode(state, m); return state.buffer; }; exports.decode = function decode(enc, buffer2) { return enc.decode(exports.state(0, buffer2.byteLength, buffer2)); }; function zigZagInt(enc) { return { preencode(state, n) { enc.preencode(state, zigZagEncodeInt(n)); }, encode(state, n) { enc.encode(state, zigZagEncodeInt(n)); }, decode(state) { return zigZagDecodeInt(enc.decode(state)); } }; } function zigZagDecodeInt(n) { return n === 0 ? n : (n & 1) === 0 ? n / 2 : -(n + 1) / 2; } function zigZagEncodeInt(n) { return n < 0 ? 2 * -n - 1 : n === 0 ? 0 : 2 * n; } function zigZagBigInt(enc) { return { preencode(state, n) { enc.preencode(state, zigZagEncodeBigInt(n)); }, encode(state, n) { enc.encode(state, zigZagEncodeBigInt(n)); }, decode(state) { return zigZagDecodeBigInt(enc.decode(state)); } }; } function zigZagDecodeBigInt(n) { return n === 0n ? n : (n & 1n) === 0n ? n / 2n : -(n + 1n) / 2n; } function zigZagEncodeBigInt(n) { return n < 0n ? 2n * -n - 1n : n === 0n ? 0n : 2n * n; } function validateSafeUint(n) { if (n > Number.MAX_SAFE_INTEGER) throw new Error( "uint is greater than the maximum safe integer, use biguint/bigint" ); return n; } function validateUint(n) { if (n >= 0 === false) throw new Error("uint must be positive"); if (n > Number.MAX_SAFE_INTEGER) throw new Error( "integer is greater than the maximum safe integer, use biguint/bigint" ); } } }); // ../../node_modules/bare-rpc/lib/constants.js var require_constants = __commonJS({ "../../node_modules/bare-rpc/lib/constants.js"(exports, module) { module.exports = { type: { REQUEST: 1, RESPONSE: 2, STREAM: 3 }, stream: { OPEN: 1, CLOSE: 2, PAUSE: 4, RESUME: 8, DATA: 16, END: 32, DESTROY: 64, ERROR: 128, REQUEST: 256, RESPONSE: 512 } }; } }); // ../../node_modules/bare-rpc/lib/errors.js var require_errors = __commonJS({ "../../node_modules/bare-rpc/lib/errors.js"(exports, module) { module.exports = class RPCError extends Error { constructor(msg, code, fn = RPCError) { super(`${code}: ${msg}`); this.code = code; if (Error.captureStackTrace) { Error.captureStackTrace(this, fn); } } get name() { return "RPCError"; } static UNKNOWN_MESSAGE(msg) { return new RPCError(msg, "UNKNOWN_MESSAGE", RPCError.UNKNOWN_MESSAGE); } static ALREADY_SENT(msg) { return new RPCError(msg, "ALREADY_SENT", RPCError.ALREADY_SENT); } static ALREADY_RECEIVED(msg) { return new RPCError(msg, "ALREADY_RECEIVED", RPCError.ALREADY_RECEIVED); } static CHANNEL_CLOSED(msg) { return new RPCError(msg, "CHANNEL_CLOSED", RPCError.CHANNEL_CLOSED); } }; } }); // ../../node_modules/bare-rpc/lib/messages.js var require_messages = __commonJS({ "../../node_modules/bare-rpc/lib/messages.js"(exports) { var c = require_compact_encoding(); var { type: t, stream: s } = require_constants(); var errors = require_errors(); var error = { preencode(state, m) { c.utf8.preencode(state, m.message); c.utf8.preencode(state, m.code === void 0 || m.code === null ? "" : String(m.code)); c.int.preencode(state, Number(m.errno) || 0); }, encode(state, m) { c.utf8.encode(state, m.message); c.utf8.encode(state, m.code === void 0 || m.code === null ? "" : String(m.code)); c.int.encode(state, Number(m.errno) || 0); }, decode(state) { const err = new Error(`${c.utf8.decode(state)}`); err.code = c.utf8.decode(state); err.errno = c.int.decode(state); return err; } }; exports.header = { preencode(state, m) { c.uint32.preencode(state, 0); c.uint.preencode(state, m.type); c.uint.preencode(state, m.id); let hasData = false; switch (m.type) { case t.REQUEST: c.uint.preencode(state, m.command); c.uint.preencode(state, m.stream); if (m.stream === 0) hasData = true; break; case t.RESPONSE: c.bool.preencode(state, !!m.error); c.uint.preencode(state, m.stream); if (m.error) error.preencode(state, m.error); else if (m.stream === 0) hasData = true; break; case t.STREAM: c.uint.preencode(state, m.stream); if (m.stream & s.ERROR) error.preencode(state, m.error); else if (m.stream & s.DATA) hasData = true; break; } if (hasData) c.uint.preencode(state, m.data ? m.data.byteLength : 0); }, encode(state, m) { const frame = state.start; c.uint32.encode(state, 0); const start = state.start; c.uint.encode(state, m.type); c.uint.encode(state, m.id); let hasData = false; switch (m.type) { case t.REQUEST: c.uint.encode(state, m.command); c.uint.encode(state, m.stream); if (m.stream === 0) hasData = true; break; case t.RESPONSE: c.bool.encode(state, !!m.error); c.uint.encode(state, m.stream); if (m.error) error.encode(state, m.error); else if (m.stream === 0) hasData = true; break; case t.STREAM: c.uint.encode(state, m.stream); if (m.stream & s.ERROR) error.encode(state, m.error); else if (m.stream & s.DATA) hasData = true; break; } if (hasData) c.uint.encode(state, m.data ? m.data.byteLength : 0); const end = state.start; state.start = frame; c.uint32.encode(state, end - start + (hasData && m.data ? m.data.byteLength : 0)); state.start = end; } }; exports.message = { decode(state) { const frame = c.uint32.decode(state); if (state.end - state.start < frame) throw new RangeError("Out of bounds"); const type = c.uint.decode(state); const id = c.uint.decode(state); switch (type) { case t.REQUEST: { const command = c.uint.decode(state); const stream = c.uint.decode(state); const data = stream === 0 ? c.buffer.decode(state) : null; return { type, id, command, stream, data }; } case t.RESPONSE: { const err = c.bool.decode(state); const stream = c.uint.decode(state); if (err) { return { type, id, stream, error: error.decode(state), data: null }; } if (stream === 0) { return { type, id, stream, error: null, data: c.buffer.decode(state) }; } return { type, id, stream, error: null, data: null }; } case t.STREAM: { const stream = c.uint.decode(state); if (stream & s.ERROR) { return { type, id, stream, error: error.decode(state), data: null }; } if (stream & s.DATA) { return { type, id, stream, error: null, data: c.buffer.decode(state) }; } return { type, id, stream, error: null, data: null }; } default: throw errors.UNKNOWN_MESSAGE(`Unknown message '${type}'`); } } }; } }); // ../../node_modules/bare-rpc/lib/incoming-event.js var require_incoming_event = __commonJS({ "../../node_modules/bare-rpc/lib/incoming-event.js"(exports, module) { module.exports = class RPCIncomingEvent { constructor(rpc, command, data) { this.rpc = rpc; this.command = command; this.data = data; } }; } }); // ../../node_modules/bare-rpc/lib/incoming-request.js var require_incoming_request = __commonJS({ "../../node_modules/bare-rpc/lib/incoming-request.js"(exports, module) { var c = require_compact_encoding(); var errors = require_errors(); module.exports = class RPCIncomingRequest { constructor(rpc, id, command, data) { this.rpc = rpc; this.id = id; this.command = command; this.data = data; this.sent = false; this.received = false; this._requestStream = null; this._responseStream = null; } reply(data, encoding) { if (this.sent) { throw errors.ALREADY_SENT("Response has already been sent"); } encoding = encoding && encoding !== "buffer" ? c.from(encoding) : typeof data === "string" ? c.raw.utf8 : null; this.sent = true; this.rpc._sendResponse(this, encoding ? c.encode(encoding, data) : data); } createResponseStream(opts = {}) { if (this.sent) { throw errors.ALREADY_SENT("Response has already been sent"); } this.sent = true; this.rpc._createResponseStream(this, true, opts); return this._responseStream; } createRequestStream(opts = {}) { if (this.received) { throw errors.ALREADY_RECEIVED("Request has already been received"); } this.received = true; this.rpc._createRequestStream(this, false, opts); return this._requestStream; } }; } }); // ../../node_modules/bare-events/lib/errors.js var require_errors2 = __commonJS({ "../../node_modules/bare-events/lib/errors.js"(exports, module) { module.exports = class EventEmitterError extends Error { constructor(msg, code, fn = EventEmitterError, opts) { super(`${code}: ${msg}`, opts); this.code = code; if (Error.captureStackTrace) { Error.captureStackTrace(this, fn); } } get name() { return "EventEmitterError"; } static OPERATION_ABORTED(cause, msg = "Operation aborted") { return new EventEmitterError(msg, "OPERATION_ABORTED", EventEmitterError.OPERATION_ABORTED, { cause }); } static UNHANDLED_ERROR(cause, msg = "Unhandled error") { return new EventEmitterError(msg, "UNHANDLED_ERROR", EventEmitterError.UNHANDLED_ERROR, { cause }); } }; } }); // ../../node_modules/bare-events/index.js var require_bare_events = __commonJS({ "../../node_modules/bare-events/index.js"(exports, module) { var errors = require_errors2(); var EventListener = class { constructor() { this.list = []; this.count = 0; } append(ctx, name, fn, once) { this.count++; ctx.emit("newListener", name, fn); this.list.push([fn, once]); } prepend(ctx, name, fn, once) { this.count++; ctx.emit("newListener", name, fn); this.list.unshift([fn, once]); } remove(ctx, name, fn) { for (let i = 0, n = this.list.length; i < n; i++) { const l = this.list[i]; if (l[0] === fn) { this.list.splice(i, 1); if (this.count === 1) delete ctx._events[name]; ctx.emit("removeListener", name, fn); this.count--; return; } } } removeAll(ctx, name) { const list = [...this.list]; this.list = []; if (this.count === list.length) delete ctx._events[name]; for (let i = list.length - 1; i >= 0; i--) { ctx.emit("removeListener", name, list[i][0]); } this.count -= list.length; } emit(ctx, name, ...args) { const list = [...this.list]; for (let i = 0, n = list.length; i < n; i++) { const l = list[i]; if (l[1] === true) this.remove(ctx, name, l[0]); Reflect.apply(l[0], ctx, args); } return list.length > 0; } }; function appendListener(ctx, name, fn, once) { if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null); const e = ctx._events[name] || (ctx._events[name] = new EventListener()); e.append(ctx, name, fn, once); return ctx; } function prependListener(ctx, name, fn, once) { if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null); const e = ctx._events[name] || (ctx._events[name] = new EventListener()); e.prepend(ctx, name, fn, once); return ctx; } function removeListener(ctx, name, fn) { if (ctx._events === void 0) return ctx; const e = ctx._events[name]; if (e !== void 0) e.remove(ctx, name, fn); return ctx; } function throwUnhandledError(...args) { let err; if (args.length > 0) err = args[0]; if (err instanceof Error === false) err = errors.UNHANDLED_ERROR(err); if (Error.captureStackTrace) { Error.captureStackTrace(err, exports.prototype.emit); } queueMicrotask(() => { throw err; }); } module.exports = exports = class EventEmitter { constructor() { this._events = /* @__PURE__ */ Object.create(null); } addListener(name, fn) { return appendListener(this, name, fn, false); } addOnceListener(name, fn) { return appendListener(this, name, fn, true); } prependListener(name, fn) { return prependListener(this, name, fn, false); } prependOnceListener(name, fn) { return prependListener(this, name, fn, true); } removeListener(name, fn) { return removeListener(this, name, fn); } on(name, fn) { return appendListener(this, name, fn, false); } once(name, fn) { return appendListener(this, name, fn, true); } off(name, fn) { return removeListener(this, name, fn); } emit(name, ...args) { if (name === "error" && this._events !== void 0 && this._events.error === void 0) { throwUnhandledError(...args); } if (this._events === void 0) return false; const e = this._events[name]; return e === void 0 ? false : e.emit(this, name, ...args); } listeners(name) { if (this._events === void 0) return []; const e = this._events[name]; return e === void 0 ? [] : [...e.list]; } rawListeners(name) { if (this._events === void 0) return []; const e = this._events[name]; return e === void 0 ? [] : e.list.map((l) => l[0]); } eventNames() { if (this._events === void 0) return []; return Reflect.ownKeys(this._events); } listenerCount(name) { if (this._events === void 0) return 0; const e = this._events[name]; return e === void 0 ? 0 : e.list.length; } getMaxListeners() { return EventEmitter.defaultMaxListeners; } setMaxListeners(n) { } removeAllListeners(name) { if (arguments.length === 0) { for (const key of Reflect.ownKeys(this._events)) { if (key === "removeListener") continue; this.removeAllListeners(key); } this.removeAllListeners("removeListener"); } else { const e = this._events[name]; if (e !== void 0) e.removeAll(this, name); } return this; } }; exports.EventEmitter = exports; exports.errors = errors; exports.defaultMaxListeners = 10; exports.on = function on(emitter, name, opts = {}) { const { signal } = opts; if (signal && signal.aborted) { throw errors.OPERATION_ABORTED(signal.reason); } let error = null; let done = false; const events = []; const promises = []; if (name !== "error") emitter.on("error", onerror); if (signal) signal.addEventListener("abort", onabort); emitter.on(name, onevent); return { next() { if (events.length) { return Promise.resolve({ value: events.shift(), done: false }); } if (error) { const err = error; error = null; return Promise.reject(err); } if (done) return onclose(); return new Promise((resolve, reject) => promises.push({ resolve, reject })); }, return() { return onclose(); }, throw(err) { return onerror(err); }, [Symbol.asyncIterator]() { return this; } }; function onevent(...args) { if (promises.length) { promises.shift().resolve({ value: args, done: false }); } else { events.push(args); } } function onerror(err) { emitter.off(name, onevent).off("error", onerror); if (promises.length) { promises.shift().reject(err); } else { error = err; } return Promise.resolve({ done: true }); } function onabort() { signal.removeEventListener("abort", onabort); onerror(errors.OPERATION_ABORTED(signal.reason)); } function onclose() { emitter.off(name, onevent); if (name !== "error") emitter.off("error", onerror); if (signal) signal.removeEventListener("abort", onabort); done = true; if (promises.length) promises.shift().resolve({ done: true }); return Promise.resolve({ done: true }); } }; exports.once = function once(emitter, name, opts = {}) { const { signal } = opts; if (signal && signal.aborted) { return Promise.reject(errors.OPERATION_ABORTED(signal.reason)); } return new Promise((resolve, reject) => { if (name !== "error") emitter.on("error", onerror); if (signal) signal.addEventListener("abort", onabort); emitter.once(name, onevent); function onevent(...args) { if (name !== "error") emitter.off("error", onerror); if (signal) signal.removeEventListener("abort", onabort); resolve(args); } function onerror(err) { emitter.off(name, onevent); if (name !== "error") emitter.off("error", onerror); reject(err); } function onabort() { signal.removeEventListener("abort", onabort); onerror(errors.OPERATION_ABORTED(signal.reason)); } }); }; exports.forward = function forward(from, to, names, opts = {}) { if (typeof names === "string") names = [names]; const { emit = to.emit.bind(to) } = opts; const listeners = names.map( (name) => function onevent(...args) { emit(name, ...args); } ); to.on("newListener", (name) => { const i = names.indexOf(name); if (i !== -1 && to.listenerCount(name) === 0) { from.on(name, listeners[i]); } }).on("removeListener", (name) => { const i = names.indexOf(name); if (i !== -1 && to.listenerCount(name) === 0) { from.off(name, listeners[i]); } }); }; exports.listenerCount = function listenerCount(emitter, name) { return emitter.listenerCount(name); }; exports.getMaxListeners = function getMaxListeners(emitter) { if (typeof emitter.getMaxListeners === "function") { return emitter.getMaxListeners(); } return exports.defaultMaxListeners; }; exports.setMaxListeners = function setMaxListeners(n, ...emitters) { if (emitters.length === 0) exports.defaultMaxListeners = n; else { for (const emitter of emitters) { if (typeof emitter.setMaxListeners === "function") { emitter.setMaxListeners(n); } } } }; } }); // ../bare-os-openssh/vendor/bare-node-shims/bare-node-events/index.js var require_bare_node_events = __commonJS({ "../bare-os-openssh/vendor/bare-node-shims/bare-node-events/index.js"(exports, module) { module.exports = require_bare_events(); } }); // ../../node_modules/events-universal/default.js var require_default = __commonJS({ "../../node_modules/events-universal/default.js"(exports, module) { module.exports = require_bare_node_events(); } }); // ../../node_modules/fast-fifo/fixed-size.js var require_fixed_size = __commonJS({ "../../node_modules/fast-fifo/fixed-size.js"(exports, module) { module.exports = class FixedFIFO { constructor(hwm) { if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) throw new Error("Max size for a FixedFIFO should be a power of two"); this.buffer = new Array(hwm); this.mask = hwm - 1; this.top = 0; this.btm = 0; this.next = null; } clear() { this.top = this.btm = 0; this.next = null; this.buffer.fill(void 0); } push(data) { if (this.buffer[this.top] !== void 0) return false; this.buffer[this.top] = data; this.top = this.top + 1 & this.mask; return true; } shift() { const last = this.buffer[this.btm]; if (last === void 0) return void 0; this.buffer[this.btm] = void 0; this.btm = this.btm + 1 & this.mask; return last; } peek() { return this.buffer[this.btm]; } isEmpty() { return this.buffer[this.btm] === void 0; } }; } }); // ../../node_modules/fast-fifo/index.js var require_fast_fifo = __commonJS({ "../../node_modules/fast-fifo/index.js"(exports, module) { var FixedFIFO = require_fixed_size(); module.exports = class FastFIFO { constructor(hwm) { this.hwm = hwm || 16; this.head = new FixedFIFO(this.hwm); this.tail = this.head; this.length = 0; } clear() { this.head = this.tail; this.head.clear(); this.length = 0; } push(val) { this.length++; if (!this.head.push(val)) { const prev = this.head; this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length); this.head.push(val); } } shift() { if (this.length !== 0) this.length--; const val = this.tail.shift(); if (val === void 0 && this.tail.next) { const next = this.tail.next; this.tail.next = null; this.tail = next; return this.tail.shift(); } return val; } peek() { const val = this.tail.peek(); if (val === void 0 && this.tail.next) return this.tail.next.peek(); return val; } isEmpty() { return this.length === 0; } }; } }); // ../../node_modules/text-decoder/lib/pass-through-decoder.js var require_pass_through_decoder = __commonJS({ "../../node_modules/text-decoder/lib/pass-through-decoder.js"(exports, module) { var b4a = require_b4a(); module.exports = class PassThroughDecoder { constructor(encoding) { this.encoding = encoding; } get remaining() { return 0; } decode(data) { return b4a.toString(data, this.encoding); } flush() { return ""; } }; } }); // ../../node_modules/text-decoder/lib/utf8-decoder.js var require_utf8_decoder = __commonJS({ "../../node_modules/text-decoder/lib/utf8-decoder.js"(exports, module) { var b4a = require_b4a(); module.exports = class UTF8Decoder { constructor() { this._reset(); } get remaining() { return this.bytesSeen; } decode(data) { if (data.byteLength === 0) return ""; if (this.bytesNeeded === 0 && trailingIncomplete(data, 0) === 0) { this.bytesSeen = trailingBytesSeen(data); return b4a.toString(data, "utf8"); } let result = ""; let start = 0; if (this.bytesNeeded > 0) { while (start < data.byteLength) { const byte = data[start]; if (byte < this.lowerBoundary || byte > this.upperBoundary) { result += "\uFFFD"; this._reset(); break; } this.lowerBoundary = 128; this.upperBoundary = 191; this.codePoint = this.codePoint << 6 | byte & 63; this.bytesSeen++; start++; if (this.bytesSeen === this.bytesNeeded) { result += String.fromCodePoint(this.codePoint); this._reset(); break; } } if (this.bytesNeeded > 0) return result; } const trailing = trailingIncomplete(data, start); const end = data.byteLength - trailing; if (end > start) result += b4a.toString(data, "utf8", start, end); for (let i = end; i < data.byteLength; i++) { const byte = data[i]; if (this.bytesNeeded === 0) { if (byte <= 127) { this.bytesSeen = 0; result += String.fromCharCode(byte); } else if (byte >= 194 && byte <= 223) { this.bytesNeeded = 2; this.bytesSeen = 1; this.codePoint = byte & 31; } else if (byte >= 224 && byte <= 239) { if (byte === 224) this.lowerBoundary = 160; else if (byte === 237) this.upperBoundary = 159; this.bytesNeeded = 3; this.bytesSeen = 1; this.codePoint = byte & 15; } else if (byte >= 240 && byte <= 244) { if (byte === 240) this.lowerBoundary = 144; else if (byte === 244) this.upperBoundary = 143; this.bytesNeeded = 4; this.bytesSeen = 1; this.codePoint = byte & 7; } else { this.bytesSeen = 1; result += "\uFFFD"; } continue; } if (byte < this.lowerBoundary || byte > this.upperBoundary) { result += "\uFFFD"; i--; this._reset(); continue; } this.lowerBoundary = 128; this.upperBoundary = 191; this.codePoint = this.codePoint << 6 | byte & 63; this.bytesSeen++; if (this.bytesSeen === this.bytesNeeded) { result += String.fromCodePoint(this.codePoint); this._reset(); } } return result; } flush() { const result = this.bytesNeeded > 0 ? "\uFFFD" : ""; this._reset(); return result; } _reset() { this.codePoint = 0; this.bytesNeeded = 0; this.bytesSeen = 0; this.lowerBoundary = 128; this.upperBoundary = 191; } }; function trailingIncomplete(data, start) { const len = data.byteLength; if (len <= start) return 0; const limit = Math.max(start, len - 4); let i = len - 1; while (i > limit && (data[i] & 192) === 128) i--; if (i < start) return 0; const byte = data[i]; let needed; if (byte <= 127) return 0; if (byte >= 194 && byte <= 223) needed = 2; else if (byte >= 224 && byte <= 239) needed = 3; else if (byte >= 240 && byte <= 244) needed = 4; else return 0; const available = len - i; return available < needed ? available : 0; } function trailingBytesSeen(data) { const len = data.byteLength; if (len === 0) return 0; const last = data[len - 1]; if (last <= 127) return 0; if ((last & 192) !== 128) return 1; const limit = Math.max(0, len - 4); let i = len - 2; while (i >= limit && (data[i] & 192) === 128) i--; if (i < 0) return 1; const first = data[i]; let needed; if (first >= 194 && first <= 223) needed = 2; else if (first >= 224 && first <= 239) needed = 3; else if (first >= 240 && first <= 244) needed = 4; else return 1; if (len - i !== needed) return 1; if (needed >= 3) { const second = data[i + 1]; if (first === 224 && second < 160) return 1; if (first === 237 && second > 159) return 1; if (first === 240 && second < 144) return 1; if (first === 244 && second > 143) return 1; } return 0; } } }); // ../../node_modules/text-decoder/index.js var require_text_decoder = __commonJS({ "../../node_modules/text-decoder/index.js"(exports, module) { var PassThroughDecoder = require_pass_through_decoder(); var UTF8Decoder = require_utf8_decoder(); module.exports = class TextDecoder { constructor(encoding = "utf8") { this.encoding = normalizeEncoding(encoding); switch (this.encoding) { case "utf8": this.decoder = new UTF8Decoder(); break; case "utf16le": case "base64": throw new Error("Unsupported encoding: " + this.encoding); default: this.decoder = new PassThroughDecoder(this.encoding); } } get remaining() { return this.decoder.remaining; } push(data) { if (typeof data === "string") return data; return this.decoder.decode(data); } // For Node.js compatibility write(data) { return this.push(data); } end(data) { let result = ""; if (data) result = this.push(data); result += this.decoder.flush(); return result; } }; function normalizeEncoding(encoding) { encoding = encoding.toLowerCase(); switch (encoding) { case "utf8": case "utf-8": return "utf8"; case "ucs2": case "ucs-2": case "utf16le": case "utf-16le": return "utf16le"; case "latin1": case "binary": return "latin1"; case "base64": case "ascii": case "hex": return encoding; default: throw new Error("Unknown encoding: " + encoding); } } } }); // ../../node_modules/streamx/lib/errors.js var require_errors3 = __commonJS({ "../../node_modules/streamx/lib/errors.js"(exports, module) { module.exports = class StreamError extends Error { constructor(msg, code, fn = StreamError) { super(msg); this.code = code; if (Error.captureStackTrace) { Error.captureStackTrace(this, fn); } } static isStreamDestroyed(err) { return err && err.code === "STREAM_DESTROYED"; } static isPrematureClose(err) { return err && err.code === "PREMATURE_CLOSE"; } static isAborted(err) { return err && err.code === "ABORTED"; } static isBadArgument(err) { return err && err.code === "BAD_ARGUMENT"; } get name() { return "StreamError"; } static STREAM_DESTROYED() { return new StreamError("Stream was destroyed", "STREAM_DESTROYED", StreamError.STREAM_DESTROYED); } static PREMATURE_CLOSE(msg = "Premature close") { return new StreamError(msg, "PREMATURE_CLOSE", StreamError.PREMATURE_CLOSE); } static ABORTED() { return new StreamError("Stream aborted", "ABORTED", StreamError.ABORTED); } static BAD_ARGUMENT(msg = "Bad argument") { return new StreamError(msg, "BAD_ARGUMENT", StreamError.BAD_ARGUMENT); } }; } }); // ../../node_modules/streamx/index.js var require_streamx = __commonJS({ "../../node_modules/streamx/index.js"(exports, module) { var { EventEmitter } = require_default(); var FIFO = require_fast_fifo(); var TextDecoder = require_text_decoder(); var StreamError = require_errors3(); var qmt = typeof queueMicrotask === "undefined" ? (fn) => global.process.nextTick(fn) : queueMicrotask; var MAX = (1 << 29) - 1; var OPENING = 1; var PREDESTROYING = 2; var DESTROYING = 4; var DESTROYED = 8; var NOT_OPENING = MAX ^ OPENING; var NOT_PREDESTROYING = MAX ^ PREDESTROYING; var READ_ACTIVE = 1 << 4; var READ_UPDATING = 2 << 4; var READ_PRIMARY = 4 << 4; var READ_QUEUED = 8 << 4; var READ_RESUMED = 16 << 4; var READ_PIPE_DRAINED = 32 << 4; var READ_ENDING = 64 << 4; var READ_EMIT_DATA = 128 << 4; var READ_EMIT_READABLE = 256 << 4; var READ_EMITTED_READABLE = 512 << 4; var READ_DONE = 1024 << 4; var READ_NEXT_TICK = 2048 << 4; var READ_NEEDS_PUSH = 4096 << 4; var READ_READ_AHEAD = 8192 << 4; var READ_FLOWING = READ_RESUMED | READ_PIPE_DRAINED; var READ_ACTIVE_AND_NEEDS_PUSH = READ_ACTIVE | READ_NEEDS_PUSH; var READ_PRIMARY_AND_ACTIVE = READ_PRIMARY | READ_ACTIVE; var READ_EMIT_READABLE_AND_QUEUED = READ_EMIT_READABLE | READ_QUEUED; var READ_RESUMED_READ_AHEAD = READ_RESUMED | READ_READ_AHEAD; var READ_NOT_ACTIVE = MAX ^ READ_ACTIVE; var READ_NON_PRIMARY = MAX ^ READ_PRIMARY; var READ_NON_PRIMARY_AND_PUSHED = MAX ^ (READ_PRIMARY | READ_NEEDS_PUSH); var READ_PUSHED = MAX ^ READ_NEEDS_PUSH; var READ_PAUSED = MAX ^ READ_RESUMED; var READ_NOT_QUEUED = MAX ^ (READ_QUEUED | READ_EMITTED_READABLE); var READ_NOT_ENDING = MAX ^ READ_ENDING; var READ_PIPE_NOT_DRAINED = MAX ^ READ_FLOWING; var READ_NOT_NEXT_TICK = MAX ^ READ_NEXT_TICK; var READ_NOT_UPDATING = MAX ^ READ_UPDATING; var READ_NO_READ_AHEAD = MAX ^ READ_READ_AHEAD; var READ_PAUSED_NO_READ_AHEAD = MAX ^ READ_RESUMED_READ_AHEAD; var WRITE_ACTIVE = 1 << 18; var WRITE_UPDATING = 2 << 18; var WRITE_PRIMARY = 4 << 18; var WRITE_QUEUED = 8 << 18; var WRITE_UNDRAINED = 16 << 18; var WRITE_DONE = 32 << 18; var WRITE_EMIT_DRAIN = 64 << 18; var WRITE_NEXT_TICK = 128 << 18; var WRITE_WRITING = 256 << 18; var WRITE_FINISHING = 512 << 18; var WRITE_CORKED = 1024 << 18; var WRITE_NOT_ACTIVE = MAX ^ (WRITE_ACTIVE | WRITE_WRITING); var WRITE_NON_PRIMARY = MAX ^ WRITE_PRIMARY; var WRITE_NOT_FINISHING = MAX ^ (WRITE_ACTIVE | WRITE_FINISHING); var WRITE_DRAINED = MAX ^ WRITE_UNDRAINED; var WRITE_NOT_QUEUED = MAX ^ WRITE_QUEUED; var WRITE_NOT_NEXT_TICK = MAX ^ WRITE_NEXT_TICK; var WRITE_NOT_UPDATING = MAX ^ WRITE_UPDATING; var WRITE_NOT_CORKED = MAX ^ WRITE_CORKED; var ACTIVE = READ_ACTIVE | WRITE_ACTIVE; var NOT_ACTIVE = MAX ^ ACTIVE; var DONE = READ_DONE | WRITE_DONE; var DESTROY_STATUS = DESTROYING | DESTROYED | PREDESTROYING; var OPEN_STATUS = DESTROY_STATUS | OPENING; var AUTO_DESTROY = DESTROY_STATUS | DONE; var NON_PRIMARY = WRITE_NON_PRIMARY & READ_NON_PRIMARY; var ACTIVE_OR_TICKING = WRITE_NEXT_TICK | READ_NEXT_TICK; var TICKING = ACTIVE_OR_TICKING & NOT_ACTIVE; var IS_OPENING = OPEN_STATUS | TICKING; var READ_PRIMARY_STATUS = OPEN_STATUS | READ_ENDING | READ_DONE; var READ_STATUS = OPEN_STATUS | READ_DONE | READ_QUEUED; var READ_ENDING_STATUS = OPEN_STATUS | READ_ENDING | READ_QUEUED; var READ_READABLE_STATUS = OPEN_STATUS | READ_EMIT_READABLE | READ_QUEUED | READ_EMITTED_READABLE; var SHOULD_NOT_READ = OPEN_STATUS | READ_ACTIVE | READ_ENDING | READ_DONE | READ_NEEDS_PUSH | READ_READ_AHEAD; var READ_BACKPRESSURE_STATUS = DESTROY_STATUS | READ_ENDING | READ_DONE; var READ_UPDATE_SYNC_STATUS = READ_UPDATING | OPEN_STATUS | READ_NEXT_TICK | READ_PRIMARY; var READ_NEXT_TICK_OR_OPENING = READ_NEXT_TICK | OPENING; var WRITE_PRIMARY_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_DONE; var WRITE_QUEUED_AND_UNDRAINED = WRITE_QUEUED | WRITE_UNDRAINED; var WRITE_QUEUED_AND_ACTIVE = WRITE_QUEUED | WRITE_ACTIVE; var WRITE_DRAIN_STATUS = WRITE_QUEUED | WRITE_UNDRAINED | OPEN_STATUS | WRITE_ACTIVE; var WRITE_STATUS = OPEN_STATUS | WRITE_ACTIVE | WRITE_QUEUED | WRITE_CORKED; var WRITE_PRIMARY_AND_ACTIVE = WRITE_PRIMARY | WRITE_ACTIVE; var WRITE_ACTIVE_AND_WRITING = WRITE_ACTIVE | WRITE_WRITING; var WRITE_FINISHING_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_QUEUED_AND_ACTIVE | WRITE_DONE; var WRITE_BACKPRESSURE_STATUS = WRITE_UNDRAINED | DESTROY_STATUS | WRITE_FINISHING | WRITE_DONE; var WRITE_UPDATE_SYNC_STATUS = WRITE_UPDATING | OPEN_STATUS | WRITE_NEXT_TICK | WRITE_PRIMARY; var WRITE_DROP_DATA = WRITE_FINISHING | WRITE_DONE | DESTROY_STATUS; var asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator"); var WritableState = class { constructor(stream, { highWaterMark = 16384, map = null, mapWritable, byteLength, byteLengthWritable } = {}) { this.stream = stream; this.queue = new FIFO(); this.highWaterMark = highWaterMark; this.buffered = 0; this.error = null; this.pipeline = null; this.drains = null; this.byteLength = byteLengthWritable || byteLength || defaultByteLength; this.map = mapWritable || map; this.afterWrite = afterWrite.bind(this); this.afterUpdateNextTick = updateWriteNT.bind(this); } get ending() { return (this.stream._duplexState & WRITE_FINISHING) !== 0; } get ended() { return (this.stream._duplexState & WRITE_DONE) !== 0; } push(data) { if ((this.stream._duplexState & WRITE_DROP_DATA) !== 0) return false; if (this.map !== null) data = this.map(data); this.buffered += this.byteLength(data); this.queue.push(data); if (this.buffered < this.highWaterMark) { this.stream._duplexState |= WRITE_QUEUED; return true; } this.stream._duplexState |= WRITE_QUEUED_AND_UNDRAINED; return false; } shift() { const data = this.queue.shift(); this.buffered -= this.byteLength(data); if (this.buffered === 0) this.stream._duplexState &= WRITE_NOT_QUEUED; return data; } end(data) { if (typeof data === "function") { this.stream.once("finish", data); } else if (data !== void 0 && data !== null) { this.push(data); } this.stream._duplexState = (this.stream._duplexState | WRITE_FINISHING) & WRITE_NON_PRIMARY; } autoBatch(data, cb) { const buffer = []; const stream = this.stream; buffer.push(data); while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED_AND_ACTIVE) { buffer.push(stream._writableState.shift()); } if ((stream._duplexState & OPEN_STATUS) !== 0) return cb(null); stream._writev(buffer, cb); } update() { const stream = this.stream; stream._duplexState |= WRITE_UPDATING; do { while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED) { const data = this.shift(); stream._duplexState |= WRITE_ACTIVE_AND_WRITING; stream._write(data, this.afterWrite); } if ((stream._duplexState & WRITE_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary(); } while (this.continueUpdate() === true); stream._duplexState &= WRITE_NOT_UPDATING; } updateNonPrimary() { const stream = this.stream; if ((stream._duplexState & WRITE_FINISHING_STATUS) === WRITE_FINISHING) { stream._duplexState = stream._duplexState | WRITE_ACTIVE; stream._final(afterFinal.bind(this)); return; } if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) { if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) { stream._duplexState |= ACTIVE; stream._destroy(afterDestroy.bind(this)); } return; } if ((stream._duplexState & IS_OPENING) === OPENING) { stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING; stream._open(afterOpen.bind(this)); } } continueUpdate() { if ((this.stream._duplexState & WRITE_NEXT_TICK) === 0) return false; this.stream._duplexState &= WRITE_NOT_NEXT_TICK; return true; } updateCallback() { if ((this.stream._duplexState & WRITE_UPDATE_SYNC_STATUS) === WRITE_PRIMARY) { this.update(); } else { this.updateNextTick(); } } updateNextTick() { if ((this.stream._duplexState & WRITE_NEXT_TICK) !== 0) return; this.stream._duplexState |= WRITE_NEXT_TICK; if ((this.stream._duplexState & WRITE_UPDATING) === 0) qmt(this.afterUpdateNextTick); } }; var ReadableState = class { constructor(stream, { highWaterMark = 16384, map = null, mapReadable, byteLength, byteLengthReadable } = {}) { this.stream = stream; this.queue = new FIFO(); this.highWaterMark = highWaterMark === 0 ? 1 : highWaterMark; this.buffered = 0; this.readAhead = highWaterMark > 0; this.error = null; this.pipeline = null; this.byteLength = byteLengthReadable || byteLength || defaultByteLength; this.map = mapReadable || map; this.pipeTo = null; this.afterRead = afterRead.bind(this); this.afterUpdateNextTick = updateReadNT.bind(this); } get ending() { return (this.stream._duplexState & READ_ENDING) !== 0; } get ended() { return (this.stream._duplexState & READ_DONE) !== 0; } pipe(pipeTo, cb) { if (this.pipeTo !== null) throw StreamError.BAD_ARGUMENT("Can only pipe to one destination"); if (typeof cb !== "function") cb = null; this.stream._duplexState |= READ_PIPE_DRAINED; this.pipeTo = pipeTo; this.pipeline = new Pipeline(this.stream, pipeTo, cb); if (cb) this.stream.on("error", noop); if (isStreamx(pipeTo)) { pipeTo._writableState.pipeline = this.pipeline; if (cb) pipeTo.on("error", noop); pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline)); } else { const onerror = this.pipeline.done.bind(this.pipeline, pipeTo); const onclose = this.pipeline.done.bind(this.pipeline, pipeTo, null); pipeTo.on("error", onerror); pipeTo.on("close", onclose); pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline)); } pipeTo.on("drain", afterDrain.bind(this)); this.stream.emit("piping", pipeTo); pipeTo.emit("pipe", this.stream); } push(data) { const stream = this.stream; if (data === null) { this.highWaterMark = 0; stream._duplexState = (stream._duplexState | READ_ENDING) & READ_NON_PRIMARY_AND_PUSHED; return false; } if (this.map !== null) { data = this.map(data); if (data === null) { stream._duplexState &= READ_PUSHED; return this.buffered < this.highWaterMark; } } this.buffered += this.byteLength(data); this.queue.push(data); stream._duplexState = (stream._duplexState | READ_QUEUED) & READ_PUSHED; return this.buffered < this.highWaterMark; } shift() { const data = this.queue.shift(); this.buffered -= this.byteLength(data); if (this.buffered === 0) { this.stream._duplexState &= READ_NOT_QUEUED; } return data; } unshift(data) { const pending = [this.map !== null ? this.map(data) : data]; while (this.buffered > 0) pending.push(this.shift()); for (let i = 0; i < pending.length - 1; i++) { const data2 = pending[i]; this.buffered += this.byteLength(data2); this.queue.push(data2); } this.push(pending[pending.length - 1]); } read() { const stream = this.stream; if ((stream._duplexState & READ_STATUS) === READ_QUEUED) { const data = this.shift(); if (this.pipeTo !== null && this.pipeTo.write(data) === false) { stream._duplexState &= READ_PIPE_NOT_DRAINED; } if ((stream._duplexState & READ_EMIT_DATA) !== 0) { stream.emit("data", data); } return data; } if (this.readAhead === false) { stream._duplexState |= READ_READ_AHEAD; this.updateNextTick(); } return null; } drain() { const stream = this.stream; while ((stream._duplexState & READ_STATUS) === READ_QUEUED && (stream._duplexState & READ_FLOWING) !== 0) { const data = this.shift(); if (this.pipeTo !== null && this.pipeTo.write(data) === false) { stream._duplexState &= READ_PIPE_NOT_DRAINED; } if ((stream._duplexState & READ_EMIT_DATA) !== 0) { stream.emit("data", data); } } } update() { const stream = this.stream; stream._duplexState |= READ_UPDATING; do { this.drain(); while (this.buffered < this.highWaterMark && (stream._duplexState & SHOULD_NOT_READ) === READ_READ_AHEAD) { stream._duplexState |= READ_ACTIVE_AND_NEEDS_PUSH; stream._read(this.afterRead); this.drain(); } if ((stream._duplexState & READ_READABLE_STATUS) === READ_EMIT_READABLE_AND_QUEUED) { stream._duplexState |= READ_EMITTED_READABLE; stream.emit("readable"); } if ((stream._duplexState & READ_PRIMARY_AND_ACTIVE) === 0) { this.updateNonPrimary(); } } while (this.continueUpdate() === true); stream._duplexState &= READ_NOT_UPDATING; } updateNonPrimary() { const stream = this.stream; if ((stream._duplexState & READ_ENDING_STATUS) === READ_ENDING) { stream._duplexState = (stream._duplexState | READ_DONE) & READ_NOT_ENDING; stream.emit("end"); if ((stream._duplexState & AUTO_DESTROY) === DONE) { stream._duplexState |= DESTROYING; } if (this.pipeTo !== null) { this.pipeTo.end(); } } if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) { if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) { stream._duplexState |= ACTIVE; stream._destroy(afterDestroy.bind(this)); } return; } if ((stream._duplexState & IS_OPENING) === OPENING) { stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING; stream._open(afterOpen.bind(this)); } } continueUpdate() { if ((this.stream._duplexState & READ_NEXT_TICK) === 0) return false; this.stream._duplexState &= READ_NOT_NEXT_TICK; return true; } updateCallback() { if ((this.stream._duplexState & READ_UPDATE_SYNC_STATUS) === READ_PRIMARY) { this.update(); } else { this.updateNextTick(); } } updateNextTickIfOpen() { if ((this.stream._duplexState & READ_NEXT_TICK_OR_OPENING) !== 0) return; this.stream._duplexState |= READ_NEXT_TICK; if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick); } updateNextTick() { if ((this.stream._duplexState & READ_NEXT_TICK) !== 0) return; this.stream._duplexState |= READ_NEXT_TICK; if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick); } }; var TransformState = class { constructor(stream) { this.data = null; this.afterTransform = afterTransform.bind(stream); this.afterFinal = null; } }; var Pipeline = class { constructor(src, dst, cb) { this.from = src; this.to = dst; this.afterPipe = cb; this.error = null; this.pipeToFinished = false; } finished() { this.pipeToFinished = true; } done(stream, err) { if (err) this.error = err; if (stream === this.to) { this.to = null; if (this.from !== null) { if ((this.from._duplexState & READ_DONE) === 0 || !this.pipeToFinished) { this.from.destroy(this.error || StreamError.PREMATURE_CLOSE("Writable stream closed")); } return; } } if (stream === this.from) { this.from = null; if (this.to !== null) { if ((stream._duplexState & READ_DONE) === 0) { this.to.destroy(this.error || StreamError.PREMATURE_CLOSE("Readable stream closed")); } return; } } if (this.afterPipe !== null) this.afterPipe(this.error); this.to = this.from = this.afterPipe = null; } }; function afterDrain() { this.stream._duplexState |= READ_PIPE_DRAINED; this.updateCallback(); } function afterFinal(err) { const stream = this.stream; if (err) stream.destroy(err); if ((stream._duplexState & DESTROY_STATUS) === 0) { stream._duplexState |= WRITE_DONE; stream.emit("finish"); } if ((stream._duplexState & AUTO_DESTROY) === DONE) { stream._duplexState |= DESTROYING; } stream._duplexState &= WRITE_NOT_FINISHING; if ((stream._duplexState & WRITE_UPDATING) === 0) { this.update(); } else { this.updateNextTick(); } } function afterDestroy(err) { const stream = this.stream; if (!err && !StreamError.isStreamDestroyed(this.error)) err = this.error; if (err) stream.emit("error", err); stream._duplexState |= DESTROYED; stream.emit("close"); const rs = stream._readableState; const ws = stream._writableState; if (rs !== null && rs.pipeline !== null) { rs.pipeline.done(stream, err); } if (ws !== null) { while (ws.drains !== null && ws.drains.length > 0) { ws.drains.shift().resolve(false); } if (ws.pipeline !== null) { ws.pipeline.done(stream, err); } } } function afterWrite(err) { const stream = this.stream; if (err) stream.destroy(err); stream._duplexState &= WRITE_NOT_ACTIVE; if (this.drains !== null) tickDrains(this.drains); if ((stream._duplexState & WRITE_DRAIN_STATUS) === WRITE_UNDRAINED) { stream._duplexState &= WRITE_DRAINED; if ((stream._duplexState & WRITE_EMIT_DRAIN) === WRITE_EMIT_DRAIN) { stream.emit("drain"); } } this.updateCallback(); } function afterRead(err) { if (err) this.stream.destroy(err); this.stream._duplexState &= READ_NOT_ACTIVE; if (this.readAhead === false && (this.stream._duplexState & READ_RESUMED) === 0) { this.stream._duplexState &= READ_NO_READ_AHEAD; } this.updateCallback(); } function updateReadNT() { if ((this.stream._duplexState & READ_UPDATING) === 0) { this.stream._duplexState &= READ_NOT_NEXT_TICK; this.update(); } } function updateWriteNT() { if ((this.stream._duplexState & WRITE_UPDATING) === 0) { this.stream._duplexState &= WRITE_NOT_NEXT_TICK; this.update(); } } function tickDrains(drains) { for (let i = 0; i < drains.length; i++) { if (--drains[i].writes === 0) { drains.shift().resolve(true); i--; } } } function afterOpen(err) { const stream = this.stream; if (err) stream.destroy(err); if ((stream._duplexState & DESTROYING) === 0) { if ((stream._duplexState & READ_PRIMARY_STATUS) === 0) { stream._duplexState |= READ_PRIMARY; } if ((stream._duplexState & WRITE_PRIMARY_STATUS) === 0) { stream._duplexState |= WRITE_PRIMARY; } stream.emit("open"); } stream._duplexState &= NOT_ACTIVE; if (stream._writableState !== null) { stream._writableState.updateCallback(); } if (stream._readableState !== null) { stream._readableState.updateCallback(); } } function afterTransform(err, data) { if (data !== void 0 && data !== null) this.push(data); this._writableState.afterWrite(err); } function newListener(name) { if (this._readableState !== null) { if (name === "data") { this._duplexState |= READ_EMIT_DATA | READ_RESUMED_READ_AHEAD; this._readableState.updateNextTick(); } if (name === "readable") { this._duplexState |= READ_EMIT_READABLE; this._readableState.updateNextTick(); } } if (this._writableState !== null) { if (name === "drain") { this._duplexState |= WRITE_EMIT_DRAIN; this._writableState.updateNextTick(); } } } var Stream = class extends EventEmitter { constructor(opts) { super(); this._duplexState = 0; this._readableState = null; this._writableState = null; if (opts) { if (opts.open) this._open = opts.open; if (opts.destroy) this._destroy = opts.destroy; if (opts.predestroy) this._predestroy = opts.predestroy; if (opts.signal) opts.signal.addEventListener("abort", abort.bind(this)); } this.on("newListener", newListener); } _open(cb) { cb(null); } _destroy(cb) { cb(null); } _predestroy() { } get readable() { return this._readableState !== null ? true : void 0; } get writable() { return this._writableState !== null ? true : void 0; } get destroyed() { return (this._duplexState & DESTROYED) !== 0; } get destroying() { return (this._duplexState & DESTROY_STATUS) !== 0; } destroy(err) { if ((this._duplexState & DESTROY_STATUS) === 0) { if (!err) err = StreamError.STREAM_DESTROYED(); this._duplexState = (this._duplexState | DESTROYING) & NON_PRIMARY; if (this._readableState !== null) { this._readableState.highWaterMark = 0; this._readableState.error = err; } if (this._writableState !== null) { this._writableState.highWaterMark = 0; this._writableState.error = err; } this._duplexState |= PREDESTROYING; this._predestroy(); this._duplexState &= NOT_PREDESTROYING; if (this._readableState !== null) { this._readableState.updateNextTick(); } if (this._writableState !== null) { this._writableState.updateNextTick(); } } } }; var Readable = class _Readable extends Stream { constructor(opts) { super(opts); this._duplexState |= OPENING | WRITE_DONE | READ_READ_AHEAD; this._readableState = new ReadableState(this, opts); if (opts) { if (this._readableState.readAhead === false) this._duplexState &= READ_NO_READ_AHEAD; if (opts.read) this._read = opts.read; if (opts.eagerOpen) this._readableState.updateNextTick(); if (opts.encoding) this.setEncoding(opts.encoding); } } static deferred(fn, opts) { const out = new PassThrough(opts); fn().then((src) => { if (src === null) return out.end(); if (out.destroying) return; pipeline(src, out, noop); }).catch((err) => out.destroy(err)); return out; } setEncoding(encoding) { const dec = new TextDecoder(encoding); const map = this._readableState.map || echo; this._readableState.map = mapOrSkip; return this; function mapOrSkip(data) { const next = dec.push(data); return next === "" && (data.byteLength !== 0 || dec.remaining > 0) ? null : map(next); } } _read(cb) { cb(null); } pipe(dest, cb) { this._readableState.updateNextTick(); this._readableState.pipe(dest, cb); return dest; } read() { this._readableState.updateNextTick(); return this._readableState.read(); } push(data) { this._readableState.updateNextTickIfOpen(); return this._readableState.push(data); } unshift(data) { this._readableState.updateNextTickIfOpen(); return this._readableState.unshift(data); } resume() { this._duplexState |= READ_RESUMED_READ_AHEAD; this._readableState.updateNextTick(); return this; } pause() { this._duplexState &= this._readableState.readAhead === false ? READ_PAUSED_NO_READ_AHEAD : READ_PAUSED; return this; } static _fromAsyncIterator(ite, opts) { let destroy; const rs = new _Readable({ ...opts, read(cb) { ite.next().then(push).then(cb.bind(null, null)).catch(cb); }, predestroy() { destroy = ite.return(); }, destroy(cb) { if (!destroy) return cb(null); destroy.then(cb.bind(null, null)).catch(cb); } }); return rs; function push(data) { if (data.done) rs.push(null); else rs.push(data.value); } } static from(data, opts) { if (isReadStreamx(data)) return data; if (data[asyncIterator]) return this._fromAsyncIterator(data[asyncIterator](), opts); if (!Array.isArray(data)) data = data === void 0 ? [] : [data]; let i = 0; return new _Readable({ ...opts, read(cb) { this.push(i === data.length ? null : data[i++]); cb(null); } }); } static isBackpressured(rs) { return (rs._duplexState & READ_BACKPRESSURE_STATUS) !== 0 || rs._readableState.buffered >= rs._readableState.highWaterMark; } static isPaused(rs) { return (rs._duplexState & READ_RESUMED) === 0; } [asyncIterator]() { const stream = this; let error = null; let promiseResolve = null; let promiseReject = null; this.on("error", (err) => { error = err; }); this.on("readable", onreadable); this.on("close", onclose); return { [asyncIterator]() { return this; }, next() { return new Promise(function(resolve, reject) { promiseResolve = resolve; promiseReject = reject; const data = stream.read(); if (data !== null) ondata(data); else if ((stream._duplexState & DESTROYED) !== 0) ondata(null); }); }, return() { return destroy(null); }, throw(err) { return destroy(err); } }; function onreadable() { if (promiseResolve !== null) ondata(stream.read()); } function onclose() { if (promiseResolve !== null) ondata(null); } function ondata(data) { if (promiseReject === null) return; if (error) { promiseReject(error); } else if (data === null && (stream._duplexState & READ_DONE) === 0) { promiseReject(StreamError.STREAM_DESTROYED()); } else { promiseResolve({ value: data, done: data === null }); } promiseReject = promiseResolve = null; } function destroy(err) { stream.destroy(err); return new Promise((resolve, reject) => { if (stream._duplexState & DESTROYED) return resolve({ value: void 0, done: true }); stream.once("close", function() { if (err) reject(err); else resolve({ value: void 0, done: true }); }); }); } } }; var Writable = class extends Stream { constructor(opts) { super(opts); this._duplexState |= OPENING | READ_DONE; this._writableState = new WritableState(this, opts); if (opts) { if (opts.writev) this._writev = opts.writev; if (opts.write) this._write = opts.write; if (opts.final) this._final = opts.final; if (opts.eagerOpen) this._writableState.updateNextTick(); } } cork() { this._duplexState |= WRITE_CORKED; } uncork() { this._duplexState &= WRITE_NOT_CORKED; this._writableState.updateNextTick(); } _writev(batch, cb) { cb(null); } _write(data, cb) { this._writableState.autoBatch(data, cb); } _final(cb) { cb(null); } static isBackpressured(ws) { return (ws._duplexState & WRITE_BACKPRESSURE_STATUS) !== 0; } static drained(ws) { if (ws.destroyed) return Promise.resolve(false); const state = ws._writableState; const pending = isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length; const writes = pending + (ws._duplexState & WRITE_WRITING ? 1 : 0); if (writes === 0) return Promise.resolve(true); if (state.drains === null) state.drains = []; return new Promise((resolve) => { state.drains.push({ writes, resolve }); }); } write(data) { this._writableState.updateNextTick(); return this._writableState.push(data); } end(data) { this._writableState.updateNextTick(); this._writableState.end(data); return this; } }; var Duplex = class extends Readable { // and Writable constructor(opts) { super(opts); this._duplexState = OPENING | this._duplexState & READ_READ_AHEAD; this._writableState = new WritableState(this, opts); if (opts) { if (opts.writev) this._writev = opts.writev; if (opts.write) this._write = opts.write; if (opts.final) this._final = opts.final; } } cork() { this._duplexState |= WRITE_CORKED; } uncork() { this._duplexState &= WRITE_NOT_CORKED; this._writableState.updateNextTick(); } _writev(batch, cb) { cb(null); } _write(data, cb) { this._writableState.autoBatch(data, cb); } _final(cb) { cb(null); } write(data) { this._writableState.updateNextTick(); return this._writableState.push(data); } end(data) { this._writableState.updateNextTick(); this._writableState.end(data); return this; } }; var Transform = class extends Duplex { constructor(opts) { super(opts); this._transformState = new TransformState(this); if (opts) { if (opts.transform) this._transform = opts.transform; if (opts.flush) this._flush = opts.flush; } } _write(data, cb) { if (this._readableState.buffered >= this._readableState.highWaterMark) { this._transformState.data = data; } else { this._transform(data, this._transformState.afterTransform); } } _read(cb) { if (this._transformState.data !== null) { const data = this._transformState.data; this._transformState.data = null; cb(null); this._transform(data, this._transformState.afterTransform); } else { cb(null); } } destroy(err) { super.destroy(err); if (this._transformState.data !== null) { this._transformState.data = null; this._transformState.afterTransform(); } } _transform(data, cb) { cb(null, data); } _flush(cb) { cb(null); } _final(cb) { this._transformState.afterFinal = cb; this._flush(transformAfterFlush.bind(this)); } }; var PassThrough = class extends Transform { }; function transformAfterFlush(err, data) { const cb = this._transformState.afterFinal; if (err) return cb(err); if (data !== null && data !== void 0) this.push(data); this.push(null); cb(null); } function pipelinePromise(...streams) { return new Promise((resolve, reject) => { return pipeline(...streams, (err) => { if (err) return reject(err); resolve(); }); }); } function pipeline(stream, ...streams) { const all = Array.isArray(stream) ? [...stream, ...streams] : [stream, ...streams]; const done = all.length && typeof all[all.length - 1] === "function" ? all.pop() : null; if (all.length < 2) throw StreamError.BAD_ARGUMENT("Pipeline requires at least 2 streams"); let src = all[0]; let dest = null; let error = null; for (let i = 1; i < all.length; i++) { dest = all[i]; if (isStreamx(src)) { src.pipe(dest, onerror); } else { errorHandle(src, true, i > 1, onerror); src.pipe(dest); } src = dest; } if (done) { let fin = false; const autoDestroy = isStreamx(dest) || !!(dest._writableState && dest._writableState.autoDestroy); dest.on("error", (err) => { if (error === null) error = err; }); dest.on("finish", () => { fin = true; if (!autoDestroy) done(error); }); if (autoDestroy) { dest.on("close", () => done(error || (fin ? null : StreamError.PREMATURE_CLOSE()))); } } return dest; function errorHandle(s, rd, wr, onerror2) { s.on("error", onerror2); s.on("close", onclose); function onclose() { if (rd && s._readableState && !s._readableState.ended) { return onerror2(StreamError.PREMATURE_CLOSE()); } if (wr && s._writableState && !s._writableState.ended) { return onerror2(StreamError.PREMATURE_CLOSE()); } } } function onerror(err) { if (!err || error) return; error = err; for (const s of all) { s.destroy(err); } } } function echo(s) { return s; } function isStream(stream) { return !!stream._readableState || !!stream._writableState; } function isStreamx(stream) { return typeof stream._duplexState === "number" && isStream(stream); } function isEnding(stream) { return !!stream._readableState && stream._readableState.ending; } function isEnded(stream) { return !!stream._readableState && stream._readableState.ended; } function isFinishing(stream) { return !!stream._writableState && stream._writableState.ending; } function isFinished(stream) { return !!stream._writableState && stream._writableState.ended; } function getStreamError(stream, opts = {}) { const err = stream._readableState && stream._readableState.error || stream._writableState && stream._writableState.error; return !opts.all && StreamError.isStreamDestroyed(err) ? null : err; } function isReadStreamx(stream) { return isStreamx(stream) && stream.readable; } function isDisturbed(stream) { return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & DESTROYING) === DESTROYING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0; } function isTypedArray(data) { return typeof data === "object" && data !== null && typeof data.byteLength === "number"; } function defaultByteLength(data) { return isTypedArray(data) ? data.byteLength : 1024; } function noop() { } function abort() { this.destroy(StreamError.ABORTED()); } function isWritev(s) { return s._writev !== Writable.prototype._writev && s._writev !== Duplex.prototype._writev; } module.exports = { pipeline, pipelinePromise, isStream, isStreamx, isEnding, isEnded, isFinishing, isFinished, isDisturbed, getStreamError, Stream, Writable, Readable, Duplex, Transform, // Export PassThrough for compatibility with Node.js core's stream module PassThrough }; } }); // ../../node_modules/teex/index.js var require_teex = __commonJS({ "../../node_modules/teex/index.js"(exports, module) { var { Readable } = require_streamx(); module.exports = function(s, forks = 2) { const streams = new Array(forks); const status = new Array(forks).fill(true); let ended = false; for (let i = 0; i < forks; i++) { streams[i] = new Readable({ read(cb) { const check = !status[i]; status[i] = true; if (check && allReadable()) s.resume(); cb(null); } }); } s.on("end", function() { ended = true; for (const stream of streams) stream.push(null); }); s.on("error", function(err) { for (const stream of streams) stream.destroy(err); }); s.on("close", function() { if (ended) return; for (const stream of streams) stream.destroy(); }); s.on("data", function(data) { let needsPause = false; for (let i = 0; i < streams.length; i++) { if (!(status[i] = streams[i].push(data))) { needsPause = true; } } if (needsPause) s.pause(); }); return streams; function allReadable() { for (let j = 0; j < status.length; j++) { if (!status[j]) return false; } return true; } }; } }); // ../../node_modules/bare-stream/web.js var require_web = __commonJS({ "../../node_modules/bare-stream/web.js"(exports) { var { Readable, Writable, Transform, getStreamError, isStreamx, isDisturbed } = require_streamx(); var tee = require_teex(); var readableKind = Symbol.for("bare.stream.readable.kind"); var writableKind = Symbol.for("bare.stream.writable.kind"); var transformKind = Symbol.for("bare.stream.transform.kind"); exports.ReadableStreamDefaultReader = class ReadableStreamDefaultReader { constructor(stream) { this._stream = stream; this._stream._stream.once("close", onclose).once("error", onerror); const closed = Promise.withResolvers(); closed.promise.catch(noop); this._closed = closed; function onclose() { closed.resolve(); } function onerror(err) { closed.reject(err); } } get closed() { return this._closed.promise; } read() { const stream = this._stream._stream; return new Promise((resolve, reject) => { const err = getStreamError(stream); if (err) return reject(err); if (stream.destroyed) { return resolve({ value: void 0, done: true }); } const value = stream.read(); if (value !== null) { return resolve({ value, done: false }); } stream.once("readable", onreadable).once("close", onclose).once("error", onerror); function onreadable() { const value2 = stream.read(); ondone(null, value2 === null ? { value: void 0, done: true } : { value: value2, done: false }); } function onclose() { ondone(null, { value: void 0, done: true }); } function onerror(err2) { ondone(err2, null); } function ondone(err2, value2) { stream.off("readable", onreadable).off("close", onclose).off("error", onerror); if (err2) reject(err2); else resolve(value2); } }); } releaseLock() { this._closed.reject(new TypeError("Reader was released")); this._stream._releaseLock(); this._stream = null; } cancel(reason = new TypeError("Stream was cancelled")) { const stream = this._stream._stream; if (stream.destroyed) return Promise.resolve(); return new Promise( (resolve) => stream.once("close", resolve).once("error", noop).destroy(reason) ); } }; exports.ReadableStreamDefaultController = class ReadableStreamDefaultController { constructor(stream) { this._stream = stream; } get desiredSize() { const stream = this._stream._stream; return stream._readableState.highWaterMark - stream._readableState.buffered; } enqueue(data) { this._stream._stream.push(data); } close() { this._stream._stream.push(null); } error(err) { this._stream._stream.destroy(err); } }; var ReadableStream = class _ReadableStream { static get [readableKind]() { return 0; } static from(iterable) { return new _ReadableStream(Readable.from(iterable)); } constructor(underlyingSource = {}, queuingStrategy) { if (isStreamx(underlyingSource)) { this._stream = underlyingSource; } else { if (queuingStrategy === void 0) { queuingStrategy = new exports.CountQueuingStrategy(); } const { start, pull, cancel } = underlyingSource; const { highWaterMark = 1, size = defaultSize } = queuingStrategy; this._stream = new Readable({ highWaterMark, byteLength: size }); const controller = new exports.ReadableStreamDefaultController(this); try { let starting = Promise.resolve(); if (start) starting = forwardError(start.call(this, controller), controller); if (pull) { this._stream._read = this._read.bind(this, starting, pull.bind(this, controller)); } if (cancel) { this._stream.once("error", cancel.bind(this)); } } catch (err) { controller.error(err); } } this._reader = null; } get [readableKind]() { return _ReadableStream[readableKind]; } get locked() { return this._reader !== null; } getReader() { if (this.locked) throw new TypeError("Stream is locked"); this._reader = new exports.ReadableStreamDefaultReader(this); return this._reader; } cancel(reason = new TypeError("Stream was cancelled")) { const stream = this._stream; if (stream.destroyed) return Promise.resolve(); if (this.locked) return Promise.reject(new TypeError("Stream is locked")); return new Promise( (resolve) => stream.once("close", resolve).once("error", noop).destroy(reason) ); } tee() { const [a, b] = tee(this._stream); return [new _ReadableStream(a), new _ReadableStream(b)]; } pipeTo(destination) { return new Promise( (resolve, reject) => this._stream.pipe(destination._stream, (err) => { err ? reject(err) : resolve(); }) ); } [Symbol.asyncIterator]() { return this._stream[Symbol.asyncIterator](); } _releaseLock() { this._reader = null; } async _read(starting, pull, cb) { await starting; let err = null; try { await pull(); } catch (e) { err = e; } cb(err); } }; function defaultSize() { return 1; } exports.ReadableStream = ReadableStream; exports.CountQueuingStrategy = class CountQueuingStrategy { constructor(opts = {}) { const { highWaterMark = 1 } = opts; this.highWaterMark = highWaterMark; } size(chunk) { return 1; } }; exports.ByteLengthQueuingStrategy = class ByteLengthQueuingStrategy { constructor(opts = {}) { const { highWaterMark = 16384 } = opts; this.highWaterMark = highWaterMark; } size(chunk) { return chunk.byteLength; } }; exports.isReadableStream = function isReadableStream(value) { if (value instanceof ReadableStream) return true; return typeof value === "object" && value !== null && value[readableKind] === ReadableStream[readableKind]; }; exports.isReadableStreamErrored = function isReadableStreamErrored(stream) { return getStreamError(stream._stream) !== null; }; exports.isReadableStreamDisturbed = function isReadableStreamDisturbed(stream) { return isDisturbed(stream._stream); }; exports.WritableStreamDefaultWriter = class WritableStreamDefaultWriter { constructor(stream) { this._stream = stream; this._stream._stream.once("close", onclose).once("error", onerror); const closed = Promise.withResolvers(); closed.promise.catch(noop); this._closed = closed; function onclose() { closed.resolve(); } function onerror(err) { closed.reject(err); } } get desiredSize() { const stream = this._stream._stream; return stream._writableState.highWaterMark - stream._writableState.buffered; } get closed() { return this._closed.promise; } get ready() { const stream = this._stream._stream; if (getStreamError(stream)) return Promise.reject(); return Writable.drained(stream).then(); } async write(chunk) { const stream = this._stream._stream; let err = getStreamError(stream); if (err) return Promise.reject(err); stream.write(chunk); await Writable.drained(stream); err = getStreamError(stream); if (err) return Promise.reject(err); } releaseLock() { this._closed.reject(new TypeError("Writer was released")); this._stream._releaseLock(); this._stream = null; } close() { const stream = this._stream._stream; if (stream.destroyed) return Promise.resolve(); return new Promise((resolve) => stream.once("close", resolve).end()); } abort(reason = new TypeError("Stream was aborted")) { const stream = this._stream._stream; if (stream.destroyed) return Promise.resolve(); return new Promise((resolve) => stream.once("close", resolve).destroy(reason)); } }; exports.WritableStreamDefaultController = class WritableStreamDefaultController { constructor(stream) { this._stream = stream; } error(err) { this._stream._stream.destroy(err); } }; var WritableStream = class _WritableStream { static get [writableKind]() { return 0; } constructor(underlyingSink = {}, queuingStrategy = {}) { if (isStreamx(underlyingSink)) { this._stream = underlyingSink; } else { if (queuingStrategy === void 0) { queuingStrategy = new exports.CountQueuingStrategy(); } const { start, write, close, abort } = underlyingSink; const { highWaterMark = 1, size = defaultSize } = queuingStrategy; this._stream = new Writable({ highWaterMark, byteLength: size }); const controller = new exports.WritableStreamDefaultController(this); this._controller = controller; try { let starting = Promise.resolve(); if (start) starting = forwardError(start.call(this, controller), controller); if (write) { this._stream._write = this._write.bind(this, starting, write.bind(this)); } if (close) { this._stream._destroy = this._destroy.bind(this, close.call(this)); } if (abort) { this._stream.once("error", abort.bind(this)); } } catch (err) { controller.error(err); } } this._writer = null; } get [writableKind]() { return _WritableStream[writableKind]; } get locked() { return this._writer !== null; } getWriter() { if (this.locked) throw new TypeError("Stream is locked"); this._writer = new exports.WritableStreamDefaultWriter(this); return this._writer; } abort(reason = new TypeError("Stream was aborted")) { if (this._stream.destroyed) return Promise.resolve(); if (this.locked) return Promise.reject(new TypeError("Stream is locked")); return new Promise((resolve) => this._stream.once("close", resolve).destroy(reason)); } close() { if (this._stream.destroyed) return Promise.resolve(); if (this.locked) return Promise.reject(new TypeError("Stream is locked")); return new Promise((resolve) => this._stream.once("close", resolve).end()); } _releaseLock() { this._writer = null; } async _write(starting, write, data, cb) { await starting; let err = null; try { await write(data, this._controller); } catch (e) { err = e; } cb(err); } async _destroy(closing, cb) { let err = null; try { await closing; } catch (e) { err = e; } cb(err); } }; exports.WritableStream = WritableStream; exports.isWritableStream = function isWritableStream(value) { if (value instanceof WritableStream) return true; return typeof value === "object" && value !== null && value[writableKind] === WritableStream[writableKind]; }; exports.TransformStreamDefaultController = class TransformStreamDefaultController { constructor(stream) { this._stream = stream; } get desiredSize() { const stream = this._stream._stream; return stream._readableState.highWaterMark - stream._readableState.buffered; } enqueue(data) { this._stream._stream.push(data); } error(err) { this._stream._stream.destroy(err); } terminate() { const stream = this._stream._stream; stream.push(null); stream.destroy(new TypeError("Stream has been terminated")); } }; var TransformStream = class _TransformStream { static get [transformKind]() { return 0; } constructor(transformer = {}, writableStrategy = {}, readableStrategy = {}) { if (isStreamx(transformer)) { this._stream = transformer; } else { const { start, transform, flush } = transformer; this._stream = new Transform({ ...writableStrategy, ...readableStrategy }); const controller = new exports.TransformStreamDefaultController(this); this._controller = controller; try { let starting = Promise.resolve(); if (start) starting = forwardError(start.call(this, controller), controller); if (transform) { this._stream._transform = this._transform.bind(this, starting, transform.bind(this)); } if (flush) { this._stream._flush = this._flush.bind(this, flush.call(this, this._controller)); } } catch (err) { controller.error(err); } } this._writable = new WritableStream(this._stream); this._readable = new ReadableStream(this._stream); } get [transformKind]() { return _TransformStream[transformKind]; } get writable() { return this._writable; } get readable() { return this._readable; } async _transform(starting, transform, data, cb) { await starting; let err = null; try { await transform(data, this._controller); } catch (e) { err = e; } cb(err); } async _flush(flush, cb) { let err = null; try { await flush; } catch (e) { err = e; } cb(err); } }; exports.TransformStream = TransformStream; exports.isTransformStream = function isTransformStream(value) { if (value instanceof TransformStream) return true; return typeof value === "object" && value !== null && value[transformKind] === TransformStream[transformKind]; }; async function forwardError(promise, controller) { try { await promise; } catch (err) { controller.error(err); } } function noop() { } } }); // ../../node_modules/bare-stream/index.js var require_bare_stream = __commonJS({ "../../node_modules/bare-stream/index.js"(exports, module) { var b4a = require_b4a(); var stream = require_streamx(); var { ReadableStream, WritableStream } = require_web(); var defaultEncoding = "utf8"; module.exports = exports = stream.Stream; exports.pipeline = stream.pipeline; exports.isStream = stream.isStream; exports.isEnding = stream.isEnding; exports.isEnded = stream.isEnded; exports.isFinishing = stream.isFinishing; exports.isFinished = stream.isFinished; exports.isDisturbed = stream.isDisturbed; exports.isErrored = function isErrored(stream2) { return exports.getStreamError(stream2) !== null; }; exports.isReadable = function isReadable(stream2) { return stream2.readable && !stream2.destroying && !exports.isEnded(stream2); }; exports.isWritable = function isWritable(stream2) { return stream2.writable && !stream2.destroying && !exports.isFinishing(stream2); }; exports.getStreamError = stream.getStreamError; exports.addAbortSignal = function addAbortSignal(signal, stream2) { function onAbort() { stream2.destroy(signal.reason); } if (signal.aborted) onAbort(); else signal.addEventListener("abort", onAbort); return stream2; }; exports.Stream = exports; exports.Readable = class Readable extends stream.Readable { constructor(opts = {}) { super({ ...opts, byteLength: null, byteLengthReadable: null, map: null, mapReadable: null }); if (this._construct) this._open = this._construct; if (this._read !== stream.Readable.prototype._read) { this._read = read.bind(this, this._read); } if (this._destroy !== stream.Stream.prototype._destroy) { this._destroy = destroy.bind(this, this._destroy); } } get closed() { return !exports.isReadable(this); } get errored() { return stream.getStreamError(this); } push(chunk, encoding) { if (typeof chunk === "string") { chunk = b4a.from(chunk, encoding || defaultEncoding); } return super.push(chunk); } unshift(chunk, encoding) { if (typeof chunk === "string") { chunk = b4a.from(chunk, encoding || defaultEncoding); } super.unshift(chunk); } static fromWeb(readableStream, opts = {}) { const stream2 = readableStream._stream; if (opts.encoding) stream2.setEncoding(opts.encoding); if (opts.signal) exports.addAbortSignal(opts.signal, stream2); return stream2; } static toWeb(readable, opts = {}) { return new ReadableStream(readable, opts.strategy); } async [Symbol.asyncDispose]() { if (!this.destroyed) this.destroy(); await new Promise((resolve) => exports.finished(this, resolve)); } }; exports.Writable = class Writable extends stream.Writable { constructor(opts = {}) { super({ ...opts, byteLength: null, byteLengthWritable, map: null, mapWritable: null }); if (this._construct) this._open = this._construct; if (this._write !== stream.Writable.prototype._write) { this._write = write.bind(this, this._write); } if (this._destroy !== stream.Stream.prototype._destroy) { this._destroy = destroy.bind(this, this._destroy); } } get closed() { return !exports.isWritable(this); } get errored() { return stream.getStreamError(this); } write(chunk, encoding, cb) { if (typeof encoding === "function") { cb = encoding; encoding = null; } if (typeof chunk === "string") { encoding = encoding || defaultEncoding; chunk = b4a.from(chunk, encoding); } else { encoding = "buffer"; } const result = super.write({ chunk, encoding }); if (cb) stream.Writable.drained(this).then(() => cb(null), cb); return result; } end(chunk, encoding, cb) { if (typeof chunk === "function") { cb = chunk; chunk = null; } else if (typeof encoding === "function") { cb = encoding; encoding = null; } if (typeof chunk === "string") { encoding = encoding || defaultEncoding; chunk = b4a.from(chunk, encoding || defaultEncoding); } else { encoding = "buffer"; } const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end(); if (cb) this.once("finish", () => cb(null)); return result; } static fromWeb(writableStream, opts = {}) { const stream2 = writableStream._stream; if (opts.signal) exports.addAbortSignal(opts.signal, stream2); return stream2; } static toWeb(writable) { return new WritableStream(writable); } async [Symbol.asyncDispose]() { if (!this.destroyed) this.destroy(); await new Promise((resolve) => exports.finished(this, resolve)); } }; exports.Duplex = class Duplex extends stream.Duplex { constructor(opts = {}) { super({ ...opts, byteLength: null, byteLengthReadable: null, byteLengthWritable, map: null, mapReadable: null, mapWritable: null }); if (this._construct) this._open = this._construct; if (this._read !== stream.Readable.prototype._read) { this._read = read.bind(this, this._read); } if (this._write !== stream.Duplex.prototype._write) { this._write = write.bind(this, this._write); } if (this._destroy !== stream.Stream.prototype._destroy) { this._destroy = destroy.bind(this, this._destroy); } } push(chunk, encoding) { if (typeof chunk === "string") { chunk = b4a.from(chunk, encoding || defaultEncoding); } return super.push(chunk); } unshift(chunk, encoding) { if (typeof chunk === "string") { chunk = b4a.from(chunk, encoding || defaultEncoding); } super.unshift(chunk); } write(chunk, encoding, cb) { if (typeof encoding === "function") { cb = encoding; encoding = null; } if (typeof chunk === "string") { encoding = encoding || defaultEncoding; chunk = b4a.from(chunk, encoding); } else { encoding = "buffer"; } const result = super.write({ chunk, encoding }); if (cb) stream.Writable.drained(this).then(() => cb(null), cb); return result; } end(chunk, encoding, cb) { if (typeof chunk === "function") { cb = chunk; chunk = null; } else if (typeof encoding === "function") { cb = encoding; encoding = null; } if (typeof chunk === "string") { encoding = encoding || defaultEncoding; chunk = b4a.from(chunk, encoding); } else { encoding = "buffer"; } const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end(); if (cb) this.once("finish", () => cb(null)); return result; } static fromWeb({ readable: readableStream, writable: writableStream }, opts) { const readable = exports.Readable.fromWeb(readableStream, opts); const writable = exports.Writable.fromWeb(writableStream, opts); const duplex = new exports.Duplex({ write(data, encoding, cb) { writable.write(data, encoding, cb); } }); readable.on("data", (data) => duplex.push(data)).on("end", () => duplex.push(null)).on("error", (err) => duplex.destroy(err)); writable.on("finish", () => duplex.end()).on("error", (err) => duplex.destroy(err)); return duplex; } static toWeb(duplex) { const readableStream = exports.Readable.toWeb(duplex); const writableStream = exports.Writable.toWeb(duplex); return { readable: readableStream, writable: writableStream }; } }; var DuplexSide = class extends exports.Duplex { constructor(opts) { super(opts); this._otherSide = null; this._cb = null; } _read() { const cb = this._cb; if (!cb) return; this._cb = null; cb(); } _write(chunk, encoding, cb) { this._otherSide.push(chunk, encoding); this._otherSide._cb = cb; } _final(cb) { this._otherSide.on("end", cb); this._otherSide.push(null); } }; exports.duplexPair = function duplexPair(opts) { const sideA = new DuplexSide(opts); const sideB = new DuplexSide(opts); sideA._otherSide = sideB; sideB._otherSide = sideA; return [sideA, sideB]; }; exports.Transform = class Transform extends stream.Transform { constructor(opts = {}) { super({ ...opts, byteLength: null, byteLengthReadable: null, byteLengthWritable, map: null, mapReadable: null, mapWritable: null }); if (this._transform !== stream.Transform.prototype._transform) { this._transform = transform.bind(this, this._transform); } else { this._transform = passthrough; } } push(chunk, encoding) { if (typeof chunk === "string") { chunk = b4a.from(chunk, encoding || defaultEncoding); } return super.push(chunk); } unshift(chunk, encoding) { if (typeof chunk === "string") { chunk = b4a.from(chunk, encoding || defaultEncoding); } super.unshift(chunk); } write(chunk, encoding, cb) { if (typeof encoding === "function") { cb = encoding; encoding = null; } if (typeof chunk === "string") { encoding = encoding || defaultEncoding; chunk = b4a.from(chunk, encoding); } else { encoding = "buffer"; } const result = super.write({ chunk, encoding }); if (cb) stream.Writable.drained(this).then(() => cb(null), cb); return result; } end(chunk, encoding, cb) { if (typeof chunk === "function") { cb = chunk; chunk = null; } else if (typeof encoding === "function") { cb = encoding; encoding = null; } if (typeof chunk === "string") { encoding = encoding || defaultEncoding; chunk = b4a.from(chunk, encoding); } else { encoding = "buffer"; } const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end(); if (cb) this.once("finish", () => cb(null)); return result; } }; exports.PassThrough = class PassThrough extends exports.Transform { }; exports.finished = function finished(stream2, opts, cb) { if (typeof opts === "function") { cb = opts; opts = {}; } if (!opts) opts = {}; const { cleanup = false } = opts; const done = () => { cb(exports.getStreamError(stream2, { all: true })); if (cleanup) detach(); }; const detach = () => { stream2.off("close", done); stream2.off("error", noop); }; if (stream2.destroyed) { done(); } else { stream2.on("close", done); stream2.on("error", noop); } return detach; }; function read(read2, cb) { read2.call(this, 65536); cb(null); } function write(write2, data, cb) { write2.call(this, data.chunk, data.encoding, cb); } function transform(transform2, data, cb) { transform2.call(this, data.chunk, data.encoding, cb); } function destroy(destroy2, cb) { destroy2.call(this, exports.getStreamError(this), cb); } function passthrough(data, cb) { cb(null, data.chunk); } function byteLengthWritable(data) { return data.chunk.byteLength; } function noop() { } } }); // ../../node_modules/bare-rpc/lib/incoming-stream.js var require_incoming_stream = __commonJS({ "../../node_modules/bare-rpc/lib/incoming-stream.js"(exports, module) { var { Readable } = require_bare_stream(); var { type: t, stream: s } = require_constants(); module.exports = class RPCIncomingStream extends Readable { constructor(rpc, request, type, opts) { super({ ...opts, eagerOpen: true }); this._rpc = rpc; this._request = request; this._type = type; this._mask = type === t.REQUEST ? s.REQUEST : s.RESPONSE; } _open(cb) { this._rpc._sendMessage( { type: t.STREAM, id: this._request.id, stream: this._mask | s.OPEN, error: null, data: null }, cb ); } _read() { this._rpc._sendMessage({ type: t.STREAM, id: this._request.id, stream: this._mask | s.RESUME, error: null, data: null }); } _destroy(err, cb) { if (err) { this._rpc._sendMessage( { type: t.STREAM, id: this._request.id, stream: this._mask | s.DESTROY | s.ERROR, error: err, data: null }, cb ); } else { this._rpc._sendMessage( { type: t.STREAM, id: this._request.id, stream: this._mask | s.DESTROY, error: null, data: null }, cb ); } } }; } }); // ../../node_modules/bare-rpc/lib/outgoing-event.js var require_outgoing_event = __commonJS({ "../../node_modules/bare-rpc/lib/outgoing-event.js"(exports, module) { var c = require_compact_encoding(); var errors = require_errors(); module.exports = class RPCOutgoingEvent { constructor(rpc, command) { this.rpc = rpc; this.command = command; this.sent = false; } send(data, encoding) { if (this.sent) { throw errors.ALREADY_SENT("Event has already been sent"); } encoding = encoding && encoding !== "buffer" ? c.from(encoding) : typeof data === "string" ? c.raw.utf8 : null; this.sent = true; this.rpc._sendEvent(this, encoding ? c.encode(encoding, data) : data); } }; } }); // ../../node_modules/bare-rpc/lib/outgoing-request.js var require_outgoing_request = __commonJS({ "../../node_modules/bare-rpc/lib/outgoing-request.js"(exports, module) { var c = require_compact_encoding(); var errors = require_errors(); module.exports = class RPCOutgoingRequest { constructor(rpc, id, command) { this.rpc = rpc; this.id = id; this.command = command; this.sent = false; this.received = false; this._responded = false; this._promise = new Promise((resolve, reject) => { this._resolve = resolve; this._reject = reject; }); this._requestStream = null; this._responseStream = null; } send(data, encoding) { if (this.sent) { throw errors.ALREADY_SENT("Request has already been sent"); } encoding = encoding && encoding !== "buffer" ? c.from(encoding) : typeof data === "string" ? c.raw.utf8 : null; this.sent = true; this.rpc._sendRequest(this, encoding ? c.encode(encoding, data) : data); } reply(encoding) { if (this.received) { throw errors.ALREADY_RECEIVED("Response is already being received"); } encoding = encoding && encoding !== "buffer" ? c.from(encoding) : null; this.received = true; if (this.rpc._closed && !this._responded) this._reject(this.rpc._error); return encoding ? this._promise.then((data) => c.decode(encoding, data)) : this._promise; } createRequestStream(opts = {}) { if (this.sent) { throw errors.ALREADY_SENT("Request has already been sent"); } this.sent = true; this.rpc._createRequestStream(this, true, opts); return this._requestStream; } createResponseStream(opts = {}) { if (this.received) { throw errors.ALREADY_RECEIVED("Response has already been received"); } this.received = true; this.rpc._createResponseStream(this, false, opts); return this._responseStream; } }; } }); // ../../node_modules/bare-rpc/lib/outgoing-stream.js var require_outgoing_stream = __commonJS({ "../../node_modules/bare-rpc/lib/outgoing-stream.js"(exports, module) { var { Writable } = require_bare_stream(); var { type: t, stream: s } = require_constants(); module.exports = class RPCOutgoingStream extends Writable { constructor(rpc, request, type, opts) { super({ ...opts, eagerOpen: true }); this._rpc = rpc; this._request = request; this._type = type; this._mask = type === t.REQUEST ? s.REQUEST : s.RESPONSE; this._pendingOpen = null; } _open(cb) { let pending; const onflushed = () => { if (pending.has(this._request.id)) { pending.delete(this._request.id); cb(null); } else { this._pendingOpen = cb; } }; switch (this._type) { case t.REQUEST: pending = this._rpc._pendingRequests; this._rpc._sendMessage( { type: t.REQUEST, id: this._request.id, command: this._request.command, stream: s.OPEN, data: null }, onflushed ); break; case t.RESPONSE: pending = this._rpc._pendingResponses; this._rpc._sendMessage( { type: t.RESPONSE, id: this._request.id, error: false, stream: s.OPEN, data: null }, onflushed ); break; } } _continueOpen() { if (this._pendingOpen === null) return; const cb = this._pendingOpen; this._pendingOpen = null; cb(); } _write(data, encoding, cb) { this._rpc._sendMessage( { type: t.STREAM, id: this._request.id, stream: this._mask | s.DATA, error: null, data }, cb ); } _final(cb) { this._rpc._sendMessage( { type: t.STREAM, id: this._request.id, stream: this._mask | s.END, error: null, data: null }, cb ); } _destroy(err, cb) { if (err) { this._rpc._sendMessage( { type: t.STREAM, id: this._request.id, stream: this._mask | s.CLOSE | s.ERROR, error: err, data: null }, cb ); } else { this._rpc._sendMessage( { type: t.STREAM, id: this._request.id, stream: this._mask | s.CLOSE, error: null, data: null }, cb ); } } }; } }); // ../../node_modules/bare-rpc/lib/command-router.js var require_command_router = __commonJS({ "../../node_modules/bare-rpc/lib/command-router.js"(exports, module) { var c = require_compact_encoding(); module.exports = class RPCCommandRouter { constructor(opts = {}) { const { valueEncoding = c.raw } = opts; this._responders = /* @__PURE__ */ new Map(); this._defaultValueEncoding = valueEncoding; } respond(command, opts = {}, onrequest) { if (typeof opts === "function") { onrequest = opts; opts = {}; } const { valueEncoding = this._defaultValueEncoding, requestEncoding = valueEncoding, responseEncoding = valueEncoding } = opts; this._responders.set(command, { onrequest, requestEncoding, responseEncoding }); } async _onrequest(req) { const responder = this._responders.get(req.command); if (responder === void 0) return; const { onrequest, requestEncoding, responseEncoding } = responder; let data = req.data; if (requestEncoding) data = c.decode(requestEncoding, data); data = await onrequest(req, data); if (req.sent) return; if (responseEncoding) data = c.encode(responseEncoding, data); req.reply(data); } }; } }); // ../../node_modules/bare-rpc/index.js var require_bare_rpc = __commonJS({ "../../node_modules/bare-rpc/index.js"(exports, module) { var safetyCatch = require_safety_catch(); var b4a = require_b4a(); var c = require_compact_encoding(); var m = require_messages(); var errors = require_errors(); var { type: t, stream: s } = require_constants(); var IncomingEvent = require_incoming_event(); var IncomingRequest = require_incoming_request(); var IncomingStream = require_incoming_stream(); var OutgoingEvent = require_outgoing_event(); var OutgoingRequest = require_outgoing_request(); var OutgoingStream = require_outgoing_stream(); var CommandRouter = require_command_router(); module.exports = exports = class RPC { constructor(stream, onrequest = noop) { this._stream = stream; this._id = 0; this._outgoingRequests = /* @__PURE__ */ new Map(); this._outgoingResponses = /* @__PURE__ */ new Map(); this._incomingRequests = /* @__PURE__ */ new Map(); this._incomingResponses = /* @__PURE__ */ new Map(); this._pendingRequests = /* @__PURE__ */ new Set(); this._pendingResponses = /* @__PURE__ */ new Set(); this._buffer = []; this._buffered = 0; this._frame = -1; this._draining = []; this._closed = false; this._error = null; if (typeof onrequest === "function") { onrequest = onrequest.bind(this); } else { onrequest = onrequest._onrequest.bind(onrequest); } this._onrequest = onrequest; this._onerror = this._onerror.bind(this); this._onclose = this._onclose.bind(this); this._ondata = this._ondata.bind(this); this._ondrain = this._ondrain.bind(this); this._stream.on("error", this._onerror).on("close", this._onclose).on("data", this._ondata).on("drain", this._ondrain); } // Whether there are no requests or responses currently in flight. Useful for // determining when it is safe to tear down the underlying stream. get idle() { return this._outgoingRequests.size === 0 && this._outgoingResponses.size === 0 && this._incomingRequests.size === 0 && this._incomingResponses.size === 0 && this._pendingRequests.size === 0 && this._pendingResponses.size === 0; } event(command) { return new OutgoingEvent(this, command); } request(command) { return new OutgoingRequest(this, ++this._id, command); } _sendMessage(message, cb) { if (this._stream.destroying) { if (cb) cb(null); return; } const header = c.encode(m.header, message); let flushed = this._stream.write(header); if (message.data) flushed = this._stream.write(message.data); if (cb) { if (flushed) cb(null); else this._draining.push(cb); } } _sendEvent(request, data = null) { this._sendMessage({ type: t.REQUEST, id: 0, command: request.command, stream: 0, data }); } _sendRequest(request, data = null) { if (this._closed) return; this._outgoingRequests.set(request.id, request); this._sendMessage({ type: t.REQUEST, id: request.id, command: request.command, stream: 0, data }); } _createRequestStream(request, isInitiator, opts) { if (isInitiator) { request._requestStream = new OutgoingStream(this, request, t.REQUEST, opts); if (this._closed) return request._requestStream.destroy(this._error); this._outgoingRequests.set(request.id, request); request._requestStream.on("close", () => this._gcOutgoingRequest(request)); } else { request._requestStream = new IncomingStream(this, request, t.REQUEST, opts); if (this._closed) return request._requestStream.destroy(this._error); this._incomingRequests.set(request.id, request); request._requestStream.on("close", () => this._incomingRequests.delete(request.id)); } } _sendResponse(request, data) { if (this._closed) return; this._sendMessage({ type: t.RESPONSE, id: request.id, stream: 0, error: null, data }); } _createResponseStream(request, isInitiator, opts) { if (isInitiator) { request._responseStream = new OutgoingStream(this, request, t.RESPONSE, opts); if (this._closed) return request._responseStream.destroy(this._error); this._outgoingResponses.set(request.id, request); request._responseStream.on("close", () => this._outgoingResponses.delete(request.id)); } else { request._responseStream = new IncomingStream(this, request, t.RESPONSE, opts); if (this._closed) return request._responseStream.destroy(this._error); this._incomingResponses.set(request.id, request); request._responseStream.on("close", () => { this._incomingResponses.delete(request.id); request._responded = true; this._gcOutgoingRequest(request); }); } } _sendError(request, err) { this._sendMessage({ type: t.RESPONSE, id: request.id, stream: 0, error: err, data: null }); } _gcOutgoingRequest(request) { if (!request._responded) return; if (request._requestStream !== null && !request._requestStream.destroyed) return; this._outgoingRequests.delete(request.id); } _onerror(err) { this._teardown(err); } _onclose() { this._teardown(errors.CHANNEL_CLOSED("Channel closed")); } _teardown(err) { this._closed = true; this._error = err; this._ondrain(err); for (const request of this._outgoingRequests.values()) { if (request.received && request._responseStream === null) request._reject(err); } const streams = /* @__PURE__ */ new Set(); for (const request of this._outgoingRequests.values()) { if (request._requestStream !== null) streams.add(request._requestStream); } for (const request of this._incomingRequests.values()) { if (request._requestStream !== null) streams.add(request._requestStream); } for (const request of this._outgoingResponses.values()) { if (request._responseStream !== null) streams.add(request._responseStream); } for (const request of this._incomingResponses.values()) { if (request._responseStream !== null) streams.add(request._responseStream); } this._outgoingRequests.clear(); this._outgoingResponses.clear(); this._incomingRequests.clear(); this._incomingResponses.clear(); this._pendingRequests.clear(); this._pendingResponses.clear(); for (const stream of streams) stream.destroy(err); } _ondata(data) { this._buffer.push(data); this._buffered += data.byteLength; if (this._frame === -1) { this._onbeforeframe(); } else { this._onafterframe(); } } _onbeforeframe() { if (this._buffered < 4) return; const buffer = this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer); this._buffer = [buffer]; this._frame = 4 + c.uint32.decode(c.state(0, 4, buffer)); this._onafterframe(); } _onafterframe() { if (this._buffered < this._frame) return; const buffer = this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer); const frame = this._frame; this._buffered -= frame; this._buffer = this._buffered > 0 ? [buffer.subarray(frame)] : []; this._frame = -1; this._onmessage(buffer.subarray(0, frame)); this._onbeforeframe(); } async _onmessage(buffer) { let message; try { message = m.message.decode(c.state(0, buffer.length, buffer)); } catch (err) { safetyCatch(err); return this._stream.destroy(err); } switch (message.type) { case t.REQUEST: { const request = message.id === 0 ? new IncomingEvent(this, message.command, message.data) : new IncomingRequest(this, message.id, message.command, message.data); try { await this._onrequest(request); } catch (err) { safetyCatch(err); if (message.id) this._sendError(request, err); else this._stream.destroy(err); } break; } case t.RESPONSE: try { this._onresponse(message); } catch (err) { safetyCatch(err); } break; case t.STREAM: try { this._onstream(message); } catch (err) { safetyCatch(err); } } } _onresponse(message) { if (message.id === 0) return; const request = this._outgoingRequests.get(message.id); if (request === void 0) return; if (message.error) { request._responded = true; this._gcOutgoingRequest(request); request._reject(message.error); } else if (message.stream === 0) { request._responded = true; this._gcOutgoingRequest(request); request._resolve(message.data); } } _onstream(message) { if (message.id === 0) return; if (message.stream & s.OPEN) this._onstreamopen(message); else if (message.stream & s.CLOSE) this._onstreamclose(message); else if (message.stream & s.PAUSE) this._onstreampause(message); else if (message.stream & s.RESUME) this._onstreamresume(message); else if (message.stream & s.DATA) this._onstreamdata(message); else if (message.stream & s.END) this._onstreamend(message); else if (message.stream & s.DESTROY) this._onstreamdestroy(message); } _onstreamopen(message) { let stream; if (message.stream & s.REQUEST) { const request = this._outgoingRequests.get(message.id); if (request === void 0) { this._pendingRequests.add(message.id); return; } stream = request._requestStream; if (stream === null || stream._pendingOpen === null) { this._pendingRequests.add(message.id); return; } } else if (message.stream & s.RESPONSE) { const request = this._outgoingResponses.get(message.id); if (request === void 0) { this._pendingResponses.add(message.id); return; } stream = request._responseStream; if (stream === null || stream._pendingOpen === null) { this._pendingResponses.add(message.id); return; } } else { return; } stream._continueOpen(); } _onstreamclose(message) { let stream; if (message.stream & s.REQUEST) { const request = this._incomingRequests.get(message.id); if (request === void 0) return; stream = request._requestStream; } else if (message.stream & s.RESPONSE) { const request = this._incomingResponses.get(message.id); if (request === void 0) return; stream = request._responseStream; } else { return; } if (stream === null) return; if (message.error) stream.destroy(message.error); else stream.push(null); } _onstreampause(message) { let stream; if (message.stream & s.REQUEST) { const request = this._outgoingRequests.get(message.id); if (request === void 0) return; stream = request._requestStream; } else if (message.stream & s.RESPONSE) { const request = this._outgoingResponses.get(message.id); if (request === void 0) return; stream = request._responseStream; } else { return; } if (stream === null) return; stream.cork(); } _onstreamresume(message) { let stream; if (message.stream & s.REQUEST) { const request = this._outgoingRequests.get(message.id); if (request === void 0) return; stream = request._requestStream; } else if (message.stream & s.RESPONSE) { const request = this._outgoingResponses.get(message.id); if (request === void 0) return; stream = request._responseStream; } else { return; } if (stream === null) return; stream.uncork(); } _onstreamdata(message) { let stream; if (message.stream & s.REQUEST) { const request = this._incomingRequests.get(message.id); if (request === void 0) return; stream = request._requestStream; } else if (message.stream & s.RESPONSE) { const request = this._incomingResponses.get(message.id); if (request === void 0) return; stream = request._responseStream; } else { return; } if (stream === null) return; if (stream.push(message.data) === false) { this._sendMessage({ type: t.STREAM, id: stream._request.id, stream: stream._mask | s.PAUSE, error: null, data: null }); } } _onstreamend(message) { let stream; if (message.stream & s.REQUEST) { const request = this._incomingRequests.get(message.id); if (request === void 0) return; stream = request._requestStream; } else if (message.stream & s.RESPONSE) { const request = this._incomingResponses.get(message.id); if (request === void 0) return; stream = request._responseStream; } else { return; } if (stream === null) return; stream.push(null); } _onstreamdestroy(message) { let stream; if (message.stream & s.REQUEST) { const request = this._outgoingRequests.get(message.id); if (request === void 0) return; stream = request._requestStream; } else if (message.stream & s.RESPONSE) { const request = this._outgoingResponses.get(message.id); if (request === void 0) return; stream = request._responseStream; } else { return; } if (stream === null) return; stream.destroy(message.error); } _ondrain(err = null) { const draining = this._draining; this._draining = []; for (const cb of draining) cb(err); } }; exports.CommandRouter = CommandRouter; function noop() { } } }); // ../../bare-lib-entry-bareRpc.js var bare_lib_entry_bareRpc_exports = {}; __export(bare_lib_entry_bareRpc_exports, { default: () => bare_lib_entry_bareRpc_default }); var import_bare_rpc = __toESM(require_bare_rpc()); var bare_lib_entry_bareRpc_default = import_bare_rpc.default; return __toCommonJS(bare_lib_entry_bareRpc_exports); })(); ;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["bareRpc"]=v;})();