@moq/net 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/stream.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,IAAI,EAA+B,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACN,iBAAiB,EACjB,UAAU,EACV,KAAK,EACL,eAAe,EACf,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,KAAK,EACL,gBAAgB,EAChB,SAAS,GACT,MAAM,kBAAkB,CAAC;AAE1B,kFAAkF;AAClF,4EAA4E;AAC5E,SAAS,QAAQ,CAAC,MAAe,EAAE,MAAqB;IACvD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAChD,OAAO,IAAI,KAAK,UAAU,CAAC,QAAQ,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,IA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,CAAgB;IAExB,YAAY,IAAkB,EAAE,OAAsB;QACrD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,EAE1D,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI;QACT,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO;QACtB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACD","sourcesContent":["import { race } from \"@moq/signals\";\nimport { fromTransport, StreamCode, StreamError, toStreamCode, toTransport } from \"./error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { Version } from \"./ietf/version.ts\";\nimport { Version as Lite, type Version as LiteVersion } from \"./lite/version.ts\";\nimport { TimeoutError, withTimeout } from \"./util/timeout.ts\";\nimport { POW32, toBigInt, toNumber, U64 } from \"./util/u64.ts\";\nimport { decodeUtf8 } from \"./util/utf8.ts\";\nimport {\n\tlengthLeadingOnes,\n\tlengthQuic,\n\tparts,\n\tpeekLeadingOnes,\n\tpeekQuic,\n\treadLeadingOnes,\n\treadQuic,\n\tsplit,\n\twriteLeadingOnes,\n\twriteQuic,\n} from \"./util/varint.ts\";\n\n// Decode raw transport errors before mapping so they cannot bypass the negotiated\n// registry. Ordinary errors already send 0 and retain their local identity.\nfunction withCode(reason: unknown, stream: StreamVersion): unknown {\n\tconst version = asIetf(stream);\n\tconst decoded = fromTransport(reason, { version });\n\tconst code = toStreamCode(decoded, { version });\n\treturn code === StreamCode.Internal && decoded === reason ? reason : toTransport(code, decoded.message);\n}\n\nconst MAX_U31 = 2 ** 31 - 1;\nconst MAX_READ_SIZE = 1024 * 1024 * 64; // don't allocate more than 64MB for a message\n\n/**\n * Options handed to the transport for one outgoing stream.\n *\n * `waitUntilAvailable` waits for the peer's concurrent stream limit to free a slot instead\n * of rejecting with a `QuotaExceededError`, which is what we want for the streams a session\n * opens occasionally. `@types/web` doesn't declare it yet, hence the intersection.\n */\nexport function sendOptions(options?: OpenOptions): WebTransportSendStreamOptions & { waitUntilAvailable?: boolean } {\n\treturn { sendOrder: options?.sendOrder, waitUntilAvailable: options?.waitUntilAvailable ?? true };\n}\n\n// How long any open may wait for the peer to free a stream slot. Every open needs this,\n// whether or not it asked to wait: an implementation may park an over-limit open rather\n// than rejecting it, and a peer can advertise a stream limit of zero and never raise it.\n// Matches the subscribe budget.\nconst OPEN_TIMEOUT_MS = 10_000;\n\n/**\n * Bound an open that would otherwise park until the peer grants stream credit, restoring\n * the pre-waitUntilAvailable failure after a grace period. A stream arriving after the\n * deadline is discarded, since nobody is waiting for it any more.\n */\nasync function openWithin<T>(opening: Promise<T>, timeout: number, discard: (stream: T) => void): Promise<T> {\n\ttry {\n\t\treturn await withTimeout(opening, timeout, `stream open timed out after ${timeout}ms waiting for a slot`);\n\t} catch (err: unknown) {\n\t\topening.then(discard).catch(() => void 0);\n\t\tthrow err;\n\t}\n}\n\n/**\n * The version a stream's bytes follow: a moq-transport draft or a moq-lite draft. Required on\n * every stream so the varint form never defaults silently; a stream opened before negotiation\n * names the version its handshake is encoded with.\n */\nexport type StreamVersion = IetfVersion | LiteVersion;\n\nconst LITE: ReadonlySet<number> = new Set(Object.values(Lite));\n\nfunction isLite(version: StreamVersion): version is LiteVersion {\n\treturn LITE.has(version);\n}\n\n/** The moq-transport draft a stream follows, or undefined on moq-lite, whose stream codes are the same on every draft. */\nexport function asIetf(version: StreamVersion): IetfVersion | undefined {\n\treturn isLite(version) ? undefined : version;\n}\n\n// Every draft newer than these counts leading ones, so a new version falls forward.\nfunction isLeadingOnes(version: StreamVersion): boolean {\n\tswitch (version) {\n\t\tcase Version.DRAFT_14:\n\t\tcase Version.DRAFT_15:\n\t\tcase Version.DRAFT_16:\n\t\tcase Lite.DRAFT_01:\n\t\tcase Lite.DRAFT_02:\n\t\tcase Lite.DRAFT_03:\n\t\tcase Lite.DRAFT_04:\n\t\tcase Lite.DRAFT_05:\n\t\tcase Lite.DRAFT_06:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n// Encode `hi`/`lo` into `dst` in the varint form `version` uses: QUIC up to 2^62-1, leading-ones up to 2^64-1.\nfunction encodeTo(dst: ArrayBuffer, hi: number, lo: number, version: StreamVersion): Uint8Array {\n\tlet buf: Uint8Array;\n\tif (isLeadingOnes(version)) {\n\t\tbuf = new Uint8Array(dst, 0, lengthLeadingOnes(hi, lo));\n\t\twriteLeadingOnes(buf, hi, lo, buf.length);\n\t} else {\n\t\tbuf = new Uint8Array(dst, 0, lengthQuic(hi, lo));\n\t\twriteQuic(buf, hi, lo, buf.length);\n\t}\n\treturn buf;\n}\n\n/** Encode one varint in the form `version` uses, for a body written outside a {@link Writer}. */\nexport function encodeVarint(v: number | bigint, version: StreamVersion): Uint8Array {\n\tconst lo = split(v);\n\treturn encodeTo(new ArrayBuffer(9), parts.hi, lo, version);\n}\n\n/**\n * The `WebTransportSendStream` that every outgoing stream is, narrowed to the one attribute\n * this package uses. The DOM types available here still describe them as plain\n * `WritableStream`s, so the interface has to be named structurally.\n *\n * `sendOrder` is optional because it is absent until set, and stays absent on an\n * implementation that doesn't carry the interface at all.\n *\n * @see https://www.w3.org/TR/webtransport/#webtransportsendstream\n */\nexport type SendStream = WritableStream<Uint8Array> & { sendOrder?: number };\n\n/** Options for opening an outgoing stream. */\nexport interface OpenOptions {\n\t/** The negotiated version, which selects the varint encoding. */\n\tversion: StreamVersion;\n\n\t/**\n\t * The transport send order, where HIGHER values are transmitted first.\n\t * Left to the transport's default when unset.\n\t */\n\tsendOrder?: number;\n\n\t/**\n\t * Reject if the peer hasn't freed a stream slot within this many milliseconds. Defaults\n\t * to 10s. There is no way to wait indefinitely: a peer can advertise a stream limit of\n\t * zero and never raise it, so every open needs a way out.\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Ask the transport to wait for a stream slot rather than failing when the peer's\n\t * concurrent stream limit is exhausted. Defaults to true.\n\t *\n\t * Set it false on a path that opens streams faster than the peer can retire them. The\n\t * transport queues the opens it can't satisfy and serves them in order, with no way to\n\t * cancel one, so waiting there spends returning credit on whatever was requested first\n\t * rather than on what matters now.\n\t */\n\twaitUntilAvailable?: boolean;\n}\n\n/** Options for {@link Writer.tryOpen}. */\nexport interface TryOpenOptions extends OpenOptions {\n\t/** Give up once this resolves. */\n\tcancel: Promise<void>;\n}\n\nexport class Stream {\n\treader: Reader;\n\twriter: Writer;\n\n\t/** Wrap the two halves of a transport stream. */\n\tconstructor(props: {\n\t\twritable: WritableStream<Uint8Array>;\n\t\treadable: ReadableStream<Uint8Array>;\n\t\tversion: StreamVersion;\n\t});\n\t/** Pair halves that were opened separately, as the SETUP exchange does. */\n\tconstructor(props: { writer: Writer; reader: Reader });\n\tconstructor(props: {\n\t\twritable?: WritableStream<Uint8Array>;\n\t\treadable?: ReadableStream<Uint8Array>;\n\t\twriter?: Writer;\n\t\treader?: Reader;\n\t\tversion?: StreamVersion;\n\t}) {\n\t\tconst version = props.version;\n\t\tconst writer = props.writer ?? (props.writable && version !== undefined && new Writer(props.writable, version));\n\t\tconst reader =\n\t\t\tprops.reader ?? (props.readable && version !== undefined && new Reader(props.readable, undefined, version));\n\t\tif (!writer || !reader) throw new Error(\"stream needs both halves\");\n\n\t\tthis.writer = writer;\n\t\tthis.reader = reader;\n\t}\n\n\tstatic async accept(quic: WebTransport, version: StreamVersion): Promise<Stream | undefined> {\n\t\tfor (;;) {\n\t\t\tconst reader =\n\t\t\t\tquic.incomingBidirectionalStreams.getReader() as ReadableStreamDefaultReader<WebTransportBidirectionalStream>;\n\t\t\tconst next = await reader.read();\n\t\t\treader.releaseLock();\n\n\t\t\tif (next.done) return;\n\t\t\tconst { readable, writable } = next.value;\n\t\t\treturn new Stream({ readable, writable, version });\n\t\t}\n\t}\n\n\t/**\n\t * Open an outgoing bidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options: OpenOptions): Promise<Stream> {\n\t\tconst { readable, writable } = await openWithin(\n\t\t\tquic.createBidirectionalStream(sendOptions(options)),\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => {\n\t\t\t\tvoid stream.writable.abort().catch(() => void 0);\n\t\t\t\tvoid stream.readable.cancel().catch(() => void 0);\n\t\t\t},\n\t\t);\n\t\treturn new Stream({ readable, writable, version: options.version });\n\t}\n\n\tclose() {\n\t\tthis.writer.close();\n\t\t// A routine unsubscribe, so send CANCELLED. A bare Error would put 0 on the wire,\n\t\t// which the stream registry reads as INTERNAL_ERROR: the peer would log a failure\n\t\t// for every subscription we walk away from.\n\t\tthis.reader.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t}\n\n\tabort(reason: Error) {\n\t\tthis.writer.reset(reason);\n\t\tthis.reader.stop(reason);\n\t}\n}\n\n// Reader wraps a stream and provides convience methods for reading pieces from a stream\n// Unfortunately we can't use a BYOB reader because it's not supported with WebTransport+WebWorkers yet.\nexport class Reader {\n\t// Contiguous unread bytes, followed by chunks not yet joined onto it. Joining only once a\n\t// read needs the bytes keeps a frame arriving in N chunks linear rather than quadratic.\n\t#buffer: Uint8Array;\n\t#chunks: Uint8Array[] = [];\n\t#chunked = 0; // bytes across #chunks\n\t#stream?: ReadableStream<Uint8Array>; // if undefined, the buffer is consumed then EOF\n\t#reader?: ReadableStreamDefaultReader<Uint8Array>;\n\t#closed?: Promise<void>;\n\t// The decode that last ran short and how far, so a retry can wait for those bytes.\n\t#short?: { decode: (c: Cursor) => unknown; err: Short };\n\tversion: StreamVersion;\n\n\t// Either stream or buffer MUST be provided.\n\tconstructor(stream: ReadableStream<Uint8Array>, buffer: Uint8Array | undefined, version: StreamVersion);\n\tconstructor(stream: undefined, buffer: Uint8Array, version: StreamVersion);\n\tconstructor(\n\t\tstream: ReadableStream<Uint8Array> | undefined,\n\t\tbuffer: Uint8Array | undefined,\n\t\tversion: StreamVersion,\n\t) {\n\t\tthis.#buffer = buffer ?? new Uint8Array();\n\t\tthis.#stream = stream;\n\t\tthis.#reader = this.#stream?.getReader();\n\t\tthis.version = version;\n\t}\n\n\t// Adds more data to the buffer, returning true if more data was added.\n\tasync #fill(): Promise<boolean> {\n\t\tif (!this.#reader) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Every read of this stream funnels through here, so decoding the peer's reset code\n\t\t// once is enough to keep the raw transport error out of every caller (and every app).\n\t\tconst result = await this.#reader.read().catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: asIetf(this.version) });\n\t\t});\n\n\t\tif (result.done) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (result.value.byteLength === 0) {\n\t\t\tthrow new Error(\"unexpected empty chunk\");\n\t\t}\n\n\t\tthis.#chunks.push(result.value);\n\t\tthis.#chunked += result.value.byteLength;\n\n\t\treturn true;\n\t}\n\n\t// Add more data to the buffer until it's at least size bytes.\n\tasync #fillTo(size: number) {\n\t\tif (size > MAX_READ_SIZE) {\n\t\t\tthrow new Error(`read size ${size} exceeds max size ${MAX_READ_SIZE}`);\n\t\t}\n\n\t\tif (this.#buffer.byteLength >= size) return;\n\n\t\twhile (this.#buffer.byteLength + this.#chunked < size) {\n\t\t\tif (!(await this.#fill())) {\n\t\t\t\tthrow new UnexpectedEnd();\n\t\t\t}\n\t\t}\n\n\t\tthis.#join();\n\t}\n\n\t// Move every pending chunk into the buffer, copying only when there's more than one piece.\n\t#join() {\n\t\tif (this.#chunks.length === 0) return;\n\n\t\tif (this.#buffer.byteLength === 0 && this.#chunks.length === 1) {\n\t\t\tthis.#buffer = this.#chunks[0];\n\t\t} else {\n\t\t\tconst joined = new Uint8Array(this.#buffer.byteLength + this.#chunked);\n\t\t\tjoined.set(this.#buffer);\n\t\t\tlet offset = this.#buffer.byteLength;\n\t\t\tfor (const chunk of this.#chunks) {\n\t\t\t\tjoined.set(chunk, offset);\n\t\t\t\toffset += chunk.byteLength;\n\t\t\t}\n\t\t\tthis.#buffer = joined;\n\t\t}\n\n\t\tthis.#chunks = [];\n\t\tthis.#chunked = 0;\n\t}\n\n\t// Consumes the first size bytes of the buffer.\n\t#slice(size: number): Uint8Array {\n\t\tconst result = new Uint8Array(this.#buffer.buffer, this.#buffer.byteOffset, size);\n\t\tthis.#buffer = new Uint8Array(\n\t\t\tthis.#buffer.buffer,\n\t\t\tthis.#buffer.byteOffset + size,\n\t\t\tthis.#buffer.byteLength - size,\n\t\t);\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Run a synchronous decode over the buffered bytes and consume what it read.\n\t *\n\t * Returns undefined and consumes nothing when the decode ran past the buffered bytes, so a\n\t * caller can drain every complete message already here without waiting on the stream.\n\t */\n\ttryDecode<T extends NonNullable<unknown>>(decode: (c: Cursor) => T): T | undefined {\n\t\tconst result = this.#try(decode);\n\t\treturn result instanceof Short ? undefined : result;\n\t}\n\n\t/** Run a synchronous decode, filling from the stream until it has the bytes it needs. */\n\tasync decode<T>(decode: (c: Cursor) => T): Promise<T> {\n\t\tfor (;;) {\n\t\t\tconst result = this.#try(decode);\n\t\t\tif (!(result instanceof Short)) return result;\n\t\t\tawait this.#fillTo(result.need);\n\t\t}\n\t}\n\n\t// Like decode, but leaves the bytes buffered for the next read.\n\tasync #peek<T>(decode: (c: Cursor) => T): Promise<T> {\n\t\tfor (;;) {\n\t\t\tconst result = this.#try(decode, false);\n\t\t\tif (!(result instanceof Short)) return result;\n\t\t\tawait this.#fillTo(result.need);\n\t\t}\n\t}\n\n\t/** Like {@link decode}, but returns undefined if the stream ends cleanly first. */\n\tasync decodeMaybe<T>(decode: (c: Cursor) => T): Promise<T | undefined> {\n\t\tif (await this.done()) return undefined;\n\t\treturn this.decode(decode);\n\t}\n\n\t#try<T>(decode: (c: Cursor) => T, consume = true): T | Short {\n\t\t// A retry of the decode that last ran short, before the bytes it needs have arrived,\n\t\t// would only throw again. Every decode reads at least a byte, so none can succeed on\n\t\t// an empty buffer either.\n\t\tconst available = this.#buffer.byteLength + this.#chunked;\n\t\tif (available === 0) return EMPTY;\n\t\tif (decode === this.#short?.decode && available < this.#short.err.need) return this.#short.err;\n\n\t\tthis.#join();\n\t\tconst cursor = new Cursor(this.#buffer, this.version);\n\t\ttry {\n\t\t\tconst result = decode(cursor);\n\t\t\tif (consume) this.#slice(cursor.offset);\n\t\t\tthis.#short = undefined;\n\t\t\treturn result;\n\t\t} catch (err: unknown) {\n\t\t\tif (!(err instanceof Short)) throw err;\n\t\t\t// Filling could never satisfy it, so retrying would spin.\n\t\t\tif (err.need <= this.#buffer.byteLength) throw new Error(\"decode ran short of bytes it already had\");\n\t\t\tthis.#short = { decode, err };\n\t\t\treturn err;\n\t\t}\n\t}\n\n\tasync read(size: number): Promise<Uint8Array> {\n\t\tif (size === 0) return new Uint8Array();\n\t\treturn this.decode((c) => c.read(size));\n\t}\n\n\tasync readAll(): Promise<Uint8Array> {\n\t\twhile (await this.#fill()) {\n\t\t\t// keep going\n\t\t}\n\t\tthis.#join();\n\t\treturn this.#slice(this.#buffer.byteLength);\n\t}\n\n\t// Reads to the end of the stream, dropping every byte instead of buffering it.\n\tasync discard(): Promise<void> {\n\t\tthis.#buffer = new Uint8Array();\n\t\tdo {\n\t\t\tthis.#chunks = [];\n\t\t\tthis.#chunked = 0;\n\t\t} while (await this.#fill());\n\t}\n\n\tasync string(): Promise<string> {\n\t\treturn this.decode(STRING);\n\t}\n\n\tasync bool(): Promise<boolean> {\n\t\treturn this.decode(BOOL);\n\t}\n\n\tasync u8(): Promise<number> {\n\t\treturn this.decode(U8);\n\t}\n\n\tasync u16(): Promise<number> {\n\t\treturn this.decode(U16);\n\t}\n\n\t// Returns a Number using 53-bits, the max Javascript can use for integer math.\n\tasync u53(): Promise<number> {\n\t\treturn this.decode(U53);\n\t}\n\n\t// NOTE: Returns a bigint instead of a number since it may be larger than 53-bits\n\tasync u62(): Promise<bigint> {\n\t\treturn this.decode(U62);\n\t}\n\n\t/** Like {@link u62}, but leaves the varint buffered, so a stream's type can be read twice. */\n\tasync peekU62(): Promise<bigint> {\n\t\treturn this.#peek(U62);\n\t}\n\n\tasync varint(): Promise<U64> {\n\t\treturn this.decode(VARINT);\n\t}\n\n\t// Returns false if there is more data to read, blocking if it hasn't been received yet.\n\tasync done(): Promise<boolean> {\n\t\tif (this.#buffer.byteLength > 0 || this.#chunked > 0) return false;\n\t\treturn !(await this.#fill());\n\t}\n\n\tstop(reason: unknown) {\n\t\tthis.#reader?.cancel(withCode(reason, this.version)).catch(() => void 0);\n\t}\n\n\t// Decoded like #fill: a caller racing this against a read must not get a different error\n\t// shape depending on which one won. Derived once, so racing it per frame doesn't allocate.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= (this.#reader?.closed ?? Promise.resolve()).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: asIetf(this.version) });\n\t\t});\n\t\treturn this.#closed;\n\t}\n}\n\n/** The stream ended cleanly partway through a read. */\nexport class UnexpectedEnd extends Error {\n\tconstructor() {\n\t\tsuper(\"unexpected end of stream\");\n\t}\n}\n\n// Thrown by a Cursor read that runs past the buffered bytes, carrying how many bytes from the\n// start of the buffer the decode needs. Not an Error: it ends every chunk, so it must not\n// capture a stack.\nclass Short {\n\treadonly need: number;\n\n\tconstructor(need: number) {\n\t\tthis.need = need;\n\t}\n}\n\nconst EMPTY = new Short(1);\n\n/**\n * A synchronous view over a {@link Reader}'s buffered bytes, handed to {@link Reader.decode}.\n *\n * A read past the buffered bytes throws an internal signal that the Reader catches: it consumes\n * nothing, fills, and runs the decode again from the start. A decode must therefore not mutate\n * anything before its last read, must not swallow what it throws, and must read at least a byte.\n */\nexport class Cursor {\n\treadonly version: StreamVersion;\n\t#buffer: Uint8Array;\n\t#offset = 0;\n\t// Resolved once, since every varint read branches on it.\n\t#leadingOnes: boolean;\n\t// First bytes below this are a whole 1-byte varint, and below this + 0x40 a 2-byte one whose\n\t// value is the low 6 bits and the next byte. Both formats share that shape; only the bound moves.\n\t#short: number;\n\t// First bytes below this are a varint of at most 4 bytes: 0xc0 for QUIC, 0xf0 for leading-ones.\n\t#word: number;\n\n\tconstructor(buffer: Uint8Array, version: StreamVersion) {\n\t\tthis.#buffer = buffer;\n\t\tthis.version = version;\n\t\tthis.#leadingOnes = isLeadingOnes(version);\n\t\tthis.#short = this.#leadingOnes ? 0x80 : 0x40;\n\t\tthis.#word = this.#leadingOnes ? 0xf0 : 0xc0;\n\t}\n\n\t/** How many bytes have been read. */\n\tget offset(): number {\n\t\treturn this.#offset;\n\t}\n\n\t/** How many buffered bytes are left to read. */\n\tget remaining(): number {\n\t\treturn this.#buffer.byteLength - this.#offset;\n\t}\n\n\t/**\n\t * Decode the next `size` bytes on their own. Running past them, or leaving any unread, is\n\t * malformed rather than a reason to wait for more.\n\t */\n\texact<T>(size: number, decode: (c: Cursor) => T): T {\n\t\tconst inner = new Cursor(this.read(size), this.version);\n\t\tlet result: T;\n\t\ttry {\n\t\t\tresult = decode(inner);\n\t\t} catch (err: unknown) {\n\t\t\tif (err instanceof Short) throw new Error(`message is shorter than its fields: ${size} bytes`);\n\t\t\tthrow err;\n\t\t}\n\t\tif (inner.remaining > 0) throw new Error(`message has ${inner.remaining} unread bytes`);\n\t\treturn result;\n\t}\n\n\t#ensure(size: number) {\n\t\tconst need = this.#offset + size;\n\t\t// Checked here too, and on the whole decode like the fill, since bytes that are already\n\t\t// buffered never reach the fill.\n\t\tif (need > MAX_READ_SIZE) throw new Error(`read size ${need} exceeds max size ${MAX_READ_SIZE}`);\n\t\tif (need > this.#buffer.byteLength) throw new Short(need);\n\t}\n\n\t/** Read `size` bytes, as a view onto the buffer rather than a copy. */\n\tread(size: number): Uint8Array {\n\t\tthis.#ensure(size);\n\t\tconst start = this.#offset;\n\t\tthis.#offset += size;\n\t\treturn this.#buffer.subarray(start, this.#offset);\n\t}\n\n\tstring(): string {\n\t\treturn decodeUtf8(this.read(this.u53()));\n\t}\n\n\tbool(): boolean {\n\t\tconst v = this.u8();\n\t\tif (v === 0) return false;\n\t\tif (v === 1) return true;\n\t\tthrow new Error(\"invalid bool value\");\n\t}\n\n\tu8(): number {\n\t\tthis.#ensure(1);\n\t\treturn this.#buffer[this.#offset++];\n\t}\n\n\tu16(): number {\n\t\tthis.#ensure(2);\n\t\tconst b = this.#buffer;\n\t\tconst o = this.#offset;\n\t\tthis.#offset += 2;\n\t\treturn (b[o] << 8) | b[o + 1];\n\t}\n\n\t/** Read a varint as a `number`, throwing if it is above `Number.MAX_SAFE_INTEGER`. */\n\tu53(): number {\n\t\t// Most varints are 1 or 2 bytes, which skip the general decode.\n\t\tthis.#ensure(1);\n\t\tconst b = this.#buffer;\n\t\tconst o = this.#offset;\n\t\tconst first = b[o];\n\t\tif (first < this.#short) {\n\t\t\tthis.#offset = o + 1;\n\t\t\treturn first;\n\t\t}\n\t\tif (first < this.#short + 0x40) {\n\t\t\tthis.#ensure(2);\n\t\t\tthis.#offset = o + 2;\n\t\t\treturn ((first & 0x3f) << 8) | b[o + 1];\n\t\t}\n\t\t// Up to 4 bytes still fits 28 (leading-ones) or 30 (QUIC) bits, with no upper half.\n\t\tif (first < this.#word) {\n\t\t\tconst size = this.#leadingOnes ? peekLeadingOnes(first) : 4;\n\t\t\tthis.#ensure(size);\n\t\t\tthis.#offset = o + size;\n\t\t\tif (size === 3) return ((first & 0x1f) << 16) | (b[o + 1] << 8) | b[o + 2];\n\t\t\treturn ((first & (this.#leadingOnes ? 0x0f : 0x3f)) << 24) | (b[o + 1] << 16) | (b[o + 2] << 8) | b[o + 3];\n\t\t}\n\t\tconst lo = this.#varint();\n\t\treturn toNumber(parts.hi, lo);\n\t}\n\n\t/** Read a varint as a bigint. A leading-ones varint may exceed 62 bits. */\n\tu62(): bigint {\n\t\tconst lo = this.#varint();\n\t\treturn toBigInt(parts.hi, lo);\n\t}\n\n\t/** Read a varint. */\n\tvarint(): U64 {\n\t\tconst lo = this.#varint();\n\t\treturn new U64(parts.hi, lo);\n\t}\n\n\t// Decode the next varint in the version's format, returning its lower half and leaving the upper in `parts`.\n\t#varint(): number {\n\t\tthis.#ensure(1);\n\t\tconst b = this.#buffer;\n\t\tconst o = this.#offset;\n\t\tlet size: number;\n\t\tif (this.#leadingOnes) {\n\t\t\tsize = peekLeadingOnes(b[o]);\n\t\t\t// 1111110x is a 7-byte form. Draft-17 rejects it; draft-18+ allows it per #1595.\n\t\t\tif (size === 7 && this.version === Version.DRAFT_17) {\n\t\t\t\tthrow new Error(\"invalid leading-ones varint: 1111110x prefix is reserved on draft-17\");\n\t\t\t}\n\t\t\tthis.#ensure(size);\n\t\t\tthis.#offset += size;\n\t\t\treturn readLeadingOnes(b, o, size);\n\t\t}\n\t\tsize = peekQuic(b[o]);\n\t\tthis.#ensure(size);\n\t\tthis.#offset += size;\n\t\treturn readQuic(b, o, size);\n\t}\n}\n\n// Shared decodes for the Reader's async primitives, so a read allocates no closure.\nconst STRING = (c: Cursor) => c.string();\nconst BOOL = (c: Cursor) => c.bool();\nconst U8 = (c: Cursor) => c.u8();\nconst U16 = (c: Cursor) => c.u16();\nconst U53 = (c: Cursor) => c.u53();\nconst U62 = (c: Cursor) => c.u62();\nconst VARINT = (c: Cursor) => c.varint();\n\n// Writer wraps a stream and writes chunks of data\nexport class Writer {\n\t#writer: WritableStreamDefaultWriter<Uint8Array>;\n\t#stream: WritableStream<Uint8Array>;\n\t#closed?: Promise<void>;\n\n\t// Scratch buffer for each primitive write, sized for the longest (a 9-byte leading-ones varint).\n\t#scratch: ArrayBuffer;\n\n\tversion: StreamVersion;\n\n\tconstructor(stream: WritableStream<Uint8Array>, version: StreamVersion) {\n\t\tthis.#stream = stream;\n\t\tthis.#scratch = new ArrayBuffer(9);\n\t\tthis.#writer = this.#stream.getWriter();\n\t\tthis.version = version;\n\t}\n\n\t/**\n\t * Rank this stream against the session's others, where HIGHER values are sent first.\n\t *\n\t * A send order only schedules the local end, so a stream the peer opened has to be ranked\n\t * here rather than at the peer's {@link open}.\n\t *\n\t * The spec makes `sendOrder` a settable attribute on every {@link SendStream}. Where the\n\t * interface isn't implemented (Chrome as of writing, a mock, a polyfill) this just sets an\n\t * ignored property, the same way an ignored `sendOrder` option does at {@link open}.\n\t */\n\tsetPriority(sendOrder: number) {\n\t\t(this.#stream as SendStream).sendOrder = sendOrder;\n\t}\n\n\tasync bool(v: boolean) {\n\t\tawait this.write(setUint8(this.#scratch, v ? 1 : 0));\n\t}\n\n\tasync u8(v: number) {\n\t\tif (!Number.isInteger(v) || v < 0 || v > 255) {\n\t\t\tthrow new RangeError(`invalid u8: ${v}`);\n\t\t}\n\t\tawait this.write(setUint8(this.#scratch, v));\n\t}\n\n\tasync u16(v: number) {\n\t\tawait this.write(setUint16(this.#scratch, v));\n\t}\n\n\tasync i32(v: number) {\n\t\tif (Math.abs(v) > MAX_U31) {\n\t\t\tthrow new Error(`overflow, value larger than 32-bits: ${v.toString()}`);\n\t\t}\n\n\t\t// We don't use a varint, so it always takes 4 bytes.\n\t\t// This could be improved but nothing is standardized yet.\n\t\tawait this.write(setInt32(this.#scratch, v));\n\t}\n\n\tasync u53(v: number) {\n\t\tif (!Number.isSafeInteger(v) || v < 0) {\n\t\t\tthrow new RangeError(`invalid u53: ${v}`);\n\t\t}\n\t\tawait this.#varint(Math.floor(v / POW32), v >>> 0);\n\t}\n\n\tasync u62(v: bigint) {\n\t\tconst lo = split(v);\n\t\tawait this.#varint(parts.hi, lo);\n\t}\n\n\tasync varint(v: U64) {\n\t\tawait this.#varint(v.hi, v.lo);\n\t}\n\n\t#varint(hi: number, lo: number): Promise<void> {\n\t\treturn this.write(encodeTo(this.#scratch, hi, lo, this.version));\n\t}\n\n\tasync write(v: Uint8Array) {\n\t\t// Mirrors Reader.#fill: every write funnels through here, so a STOP_SENDING from the\n\t\t// peer surfaces as a typed code rather than the transport's own error shape.\n\t\tawait this.#writer.write(v).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: asIetf(this.version) });\n\t\t});\n\t}\n\n\tasync string(str: string) {\n\t\tconst data = new TextEncoder().encode(str);\n\t\tawait this.u53(data.byteLength);\n\t\tawait this.write(data);\n\t}\n\n\tclose() {\n\t\tthis.#writer.close().catch(() => void 0);\n\t}\n\n\t// Mirrors Reader.closed: a STOP_SENDING reaches a caller racing this with the same\n\t// typed code it would get from a write.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= this.#writer.closed.catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: asIetf(this.version) });\n\t\t});\n\t\treturn this.#closed;\n\t}\n\n\treset(reason: unknown) {\n\t\tthis.#writer.abort(withCode(reason, this.version)).catch(() => void 0);\n\t}\n\n\t/**\n\t * Open an outgoing unidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options: OpenOptions): Promise<Writer> {\n\t\tconst writable = await openWithin(\n\t\t\tquic.createUnidirectionalStream(sendOptions(options)) as Promise<WritableStream<Uint8Array>>,\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => void stream.abort().catch(() => void 0),\n\t\t);\n\n\t\treturn new Writer(writable, options.version);\n\t}\n\n\t/**\n\t * Like {@link Writer.open}, but gives up when `cancel` settles or `timeout` elapses,\n\t * returning undefined so the caller can drop whatever it meant to send. A stream that\n\t * opens after that is reset rather than leaked. A real transport failure still throws.\n\t *\n\t * Worth using even with `waitUntilAvailable: false`, since an implementation may park\n\t * an over-limit open instead of rejecting it.\n\t */\n\tstatic async tryOpen(quic: WebTransport, options: TryOpenOptions): Promise<Writer | undefined> {\n\t\t// Raced ahead of the open, so an already-cancelled caller wins even against a slot\n\t\t// that is free right now. `race` rather than `Promise.race`: the caller shares one\n\t\t// `cancel` across every group of a subscription, which must not gain a reaction per call.\n\t\tconst open = Writer.open(quic, options);\n\n\t\t// Resets a stream that opens after we gave up; a no-op if the open itself failed.\n\t\tconst abandon = () => {\n\t\t\tconst abandoned = new Error(\"abandoned waiting for a stream slot\");\n\t\t\topen.then((w) => w.reset(abandoned)).catch(() => void 0);\n\t\t};\n\n\t\ttry {\n\t\t\tconst stream = await race([options.cancel, open]);\n\t\t\tif (stream) return stream;\n\t\t} catch (err: unknown) {\n\t\t\t// open already discarded the late stream on its way out.\n\t\t\tif (err instanceof TimeoutError) return undefined;\n\t\t\t// A rejected `cancel` still leaves the open pending.\n\t\t\tabandon();\n\t\t\tthrow err;\n\t\t}\n\n\t\tabandon();\n\t\treturn undefined;\n\t}\n}\n\nfunction setUint8(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst buffer = new Uint8Array(dst, 0, 1);\n\tbuffer[0] = v;\n\treturn buffer;\n}\n\nfunction setUint16(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 2);\n\tview.setUint16(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setInt32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setInt32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\n// Returns the next stream from the connection\nexport class Readers {\n\t#reader: ReadableStreamDefaultReader<ReadableStream<Uint8Array>>;\n\t#version: StreamVersion;\n\n\tconstructor(quic: WebTransport, version: StreamVersion) {\n\t\tthis.#reader = quic.incomingUnidirectionalStreams.getReader() as ReadableStreamDefaultReader<\n\t\t\tReadableStream<Uint8Array>\n\t\t>;\n\t\tthis.#version = version;\n\t}\n\n\tasync next(): Promise<Reader | undefined> {\n\t\tconst next = await this.#reader.read();\n\t\tif (next.done) return;\n\t\treturn new Reader(next.value, undefined, this.#version);\n\t}\n\n\tclose() {\n\t\tthis.#reader.cancel();\n\t}\n}\n"]}
1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EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACD","sourcesContent":["import { race } from \"@moq/signals\";\nimport { fromTransport, StreamCode, StreamError, toStreamCode, toTransport } from \"./error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { Version } from \"./ietf/version.ts\";\nimport { Version as Lite, type Version as LiteVersion } from \"./lite/version.ts\";\nimport { TimeoutError, withTimeout } from \"./util/timeout.ts\";\nimport { POW32, toBigInt, toNumber, U64 } from \"./util/u64.ts\";\nimport { decodeUtf8 } from \"./util/utf8.ts\";\nimport {\n\tlengthLeadingOnes,\n\tlengthQuic,\n\tparts,\n\tpeekLeadingOnes,\n\tpeekQuic,\n\treadLeadingOnes,\n\treadQuic,\n\tsplit,\n\twriteLeadingOnes,\n\twriteQuic,\n} from \"./util/varint.ts\";\n\n// Decode raw transport errors before mapping so they cannot bypass the negotiated\n// registry. Ordinary errors already send 0 and retain their local identity.\nfunction withCode(reason: unknown, stream: StreamVersion): unknown {\n\tconst version = asIetf(stream);\n\tconst decoded = fromTransport(reason, { version });\n\tconst code = toStreamCode(decoded, { version });\n\treturn code === StreamCode.Internal && decoded === reason ? reason : toTransport(code, decoded.message);\n}\n\nconst MAX_U31 = 2 ** 31 - 1;\nconst MAX_READ_SIZE = 1024 * 1024 * 64; // don't allocate more than 64MB for a message\n\n/**\n * Options handed to the transport for one outgoing stream.\n *\n * `waitUntilAvailable` waits for the peer's concurrent stream limit to free a slot instead\n * of rejecting with a `QuotaExceededError`, which is what we want for the streams a session\n * opens occasionally. `@types/web` doesn't declare it yet, hence the intersection.\n */\nexport function sendOptions(options?: OpenOptions): WebTransportSendStreamOptions & { waitUntilAvailable?: boolean } {\n\treturn { sendOrder: options?.sendOrder, waitUntilAvailable: options?.waitUntilAvailable ?? true };\n}\n\n// How long any open may wait for the peer to free a stream slot. Every open needs this,\n// whether or not it asked to wait: an implementation may park an over-limit open rather\n// than rejecting it, and a peer can advertise a stream limit of zero and never raise it.\n// Matches the subscribe budget.\nconst OPEN_TIMEOUT_MS = 10_000;\n\n/**\n * Bound an open that would otherwise park until the peer grants stream credit, restoring\n * the pre-waitUntilAvailable failure after a grace period. A stream arriving after the\n * deadline is discarded, since nobody is waiting for it any more.\n */\nasync function openWithin<T>(opening: Promise<T>, timeout: number, discard: (stream: T) => void): Promise<T> {\n\ttry {\n\t\treturn await withTimeout(opening, timeout, `stream open timed out after ${timeout}ms waiting for a slot`);\n\t} catch (err: unknown) {\n\t\topening.then(discard).catch(() => void 0);\n\t\tthrow err;\n\t}\n}\n\n/**\n * The version a stream's bytes follow: a moq-transport draft or a moq-lite draft. Required on\n * every stream so the varint form never defaults silently; a stream opened before negotiation\n * names the version its handshake is encoded with.\n */\nexport type StreamVersion = IetfVersion | LiteVersion;\n\nconst LITE: ReadonlySet<number> = new Set(Object.values(Lite));\n\nfunction isLite(version: StreamVersion): version is LiteVersion {\n\treturn LITE.has(version);\n}\n\n/** The moq-transport draft a stream follows, or undefined on moq-lite, whose stream codes are the same on every draft. */\nexport function asIetf(version: StreamVersion): IetfVersion | undefined {\n\treturn isLite(version) ? undefined : version;\n}\n\n// Every draft newer than these counts leading ones, so a new version falls forward.\nfunction isLeadingOnes(version: StreamVersion): boolean {\n\tswitch (version) {\n\t\tcase Version.DRAFT_14:\n\t\tcase Version.DRAFT_15:\n\t\tcase Version.DRAFT_16:\n\t\tcase Lite.DRAFT_01:\n\t\tcase Lite.DRAFT_02:\n\t\tcase Lite.DRAFT_03:\n\t\tcase Lite.DRAFT_04:\n\t\tcase Lite.DRAFT_05:\n\t\tcase Lite.DRAFT_06:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n// Encode `hi`/`lo` into `dst` in the varint form `version` uses: QUIC up to 2^62-1, leading-ones up to 2^64-1.\nfunction encodeTo(dst: ArrayBuffer, hi: number, lo: number, version: StreamVersion): Uint8Array {\n\tlet buf: Uint8Array;\n\tif (isLeadingOnes(version)) {\n\t\tbuf = new Uint8Array(dst, 0, lengthLeadingOnes(hi, lo));\n\t\twriteLeadingOnes(buf, hi, lo, buf.length);\n\t} else {\n\t\tbuf = new Uint8Array(dst, 0, lengthQuic(hi, lo));\n\t\twriteQuic(buf, hi, lo, buf.length);\n\t}\n\treturn buf;\n}\n\n/** Encode one varint in the form `version` uses, for a body written outside a {@link Writer}. */\nexport function encodeVarint(v: number | bigint, version: StreamVersion): Uint8Array {\n\tconst lo = split(v);\n\treturn encodeTo(new ArrayBuffer(9), parts.hi, lo, version);\n}\n\n/** The parts joined into one buffer, so they can go out in one write. */\nexport function concat(parts: Uint8Array[]): Uint8Array {\n\tconst out = new Uint8Array(parts.reduce((n, p) => n + p.byteLength, 0));\n\tlet offset = 0;\n\tfor (const part of parts) {\n\t\tout.set(part, offset);\n\t\toffset += part.byteLength;\n\t}\n\treturn out;\n}\n\n/**\n * The `WebTransportSendStream` that every outgoing stream is, narrowed to the one attribute\n * this package uses. The DOM types available here still describe them as plain\n * `WritableStream`s, so the interface has to be named structurally.\n *\n * `sendOrder` is optional because it is absent until set, and stays absent on an\n * implementation that doesn't carry the interface at all.\n *\n * @see https://www.w3.org/TR/webtransport/#webtransportsendstream\n */\nexport type SendStream = WritableStream<Uint8Array> & { sendOrder?: number };\n\n/** Options for opening an outgoing stream. */\nexport interface OpenOptions {\n\t/** The negotiated version, which selects the varint encoding. */\n\tversion: StreamVersion;\n\n\t/**\n\t * The transport send order, where HIGHER values are transmitted first.\n\t * Left to the transport's default when unset.\n\t */\n\tsendOrder?: number;\n\n\t/**\n\t * Reject if the peer hasn't freed a stream slot within this many milliseconds. Defaults\n\t * to 10s. There is no way to wait indefinitely: a peer can advertise a stream limit of\n\t * zero and never raise it, so every open needs a way out.\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Ask the transport to wait for a stream slot rather than failing when the peer's\n\t * concurrent stream limit is exhausted. Defaults to true.\n\t *\n\t * Set it false on a path that opens streams faster than the peer can retire them. The\n\t * transport queues the opens it can't satisfy and serves them in order, with no way to\n\t * cancel one, so waiting there spends returning credit on whatever was requested first\n\t * rather than on what matters now.\n\t */\n\twaitUntilAvailable?: boolean;\n}\n\n/** Options for {@link Writer.tryOpen}. */\nexport interface TryOpenOptions extends OpenOptions {\n\t/** Give up once this resolves. */\n\tcancel: Promise<void>;\n}\n\nexport class Stream {\n\treader: Reader;\n\twriter: Writer;\n\n\t/** Wrap the two halves of a transport stream. */\n\tconstructor(props: {\n\t\twritable: WritableStream<Uint8Array>;\n\t\treadable: ReadableStream<Uint8Array>;\n\t\tversion: StreamVersion;\n\t});\n\t/** Pair halves that were opened separately, as the SETUP exchange does. */\n\tconstructor(props: { writer: Writer; reader: Reader });\n\tconstructor(props: {\n\t\twritable?: WritableStream<Uint8Array>;\n\t\treadable?: ReadableStream<Uint8Array>;\n\t\twriter?: Writer;\n\t\treader?: Reader;\n\t\tversion?: StreamVersion;\n\t}) {\n\t\tconst version = props.version;\n\t\tconst writer = props.writer ?? (props.writable && version !== undefined && new Writer(props.writable, version));\n\t\tconst reader =\n\t\t\tprops.reader ?? (props.readable && version !== undefined && new Reader(props.readable, undefined, version));\n\t\tif (!writer || !reader) throw new Error(\"stream needs both halves\");\n\n\t\tthis.writer = writer;\n\t\tthis.reader = reader;\n\t}\n\n\tstatic async accept(quic: WebTransport, version: StreamVersion): Promise<Stream | undefined> {\n\t\tfor (;;) {\n\t\t\tconst reader =\n\t\t\t\tquic.incomingBidirectionalStreams.getReader() as ReadableStreamDefaultReader<WebTransportBidirectionalStream>;\n\t\t\tconst next = await reader.read();\n\t\t\treader.releaseLock();\n\n\t\t\tif (next.done) return;\n\t\t\tconst { readable, writable } = next.value;\n\t\t\treturn new Stream({ readable, writable, version });\n\t\t}\n\t}\n\n\t/**\n\t * Open an outgoing bidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options: OpenOptions): Promise<Stream> {\n\t\tconst { readable, writable } = await openWithin(\n\t\t\tquic.createBidirectionalStream(sendOptions(options)),\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => {\n\t\t\t\tvoid stream.writable.abort().catch(() => void 0);\n\t\t\t\tvoid stream.readable.cancel().catch(() => void 0);\n\t\t\t},\n\t\t);\n\t\treturn new Stream({ readable, writable, version: options.version });\n\t}\n\n\tclose() {\n\t\tthis.writer.close();\n\t\t// A routine unsubscribe, so send CANCELLED. A bare Error would put 0 on the wire,\n\t\t// which the stream registry reads as INTERNAL_ERROR: the peer would log a failure\n\t\t// for every subscription we walk away from.\n\t\tthis.reader.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t}\n\n\tabort(reason: Error) {\n\t\tthis.writer.reset(reason);\n\t\tthis.reader.stop(reason);\n\t}\n}\n\n// Reader wraps a stream and provides convience methods for reading pieces from a stream\n// Unfortunately we can't use a BYOB reader because it's not supported with WebTransport+WebWorkers yet.\nexport class Reader {\n\t// Contiguous unread bytes, followed by chunks not yet joined onto it. Joining only once a\n\t// read needs the bytes keeps a frame arriving in N chunks linear rather than quadratic.\n\t#buffer: Uint8Array;\n\t#chunks: Uint8Array[] = [];\n\t#chunked = 0; // bytes across #chunks\n\t#stream?: ReadableStream<Uint8Array>; // if undefined, the buffer is consumed then EOF\n\t#reader?: ReadableStreamDefaultReader<Uint8Array>;\n\t#closed?: Promise<void>;\n\t// The decode that last ran short and how far, so a retry can wait for those bytes.\n\t#short?: { decode: (c: Cursor) => unknown; err: Short };\n\tversion: StreamVersion;\n\n\t// Either stream or buffer MUST be provided.\n\tconstructor(stream: ReadableStream<Uint8Array>, buffer: Uint8Array | undefined, version: StreamVersion);\n\tconstructor(stream: undefined, buffer: Uint8Array, version: StreamVersion);\n\tconstructor(\n\t\tstream: ReadableStream<Uint8Array> | undefined,\n\t\tbuffer: Uint8Array | undefined,\n\t\tversion: StreamVersion,\n\t) {\n\t\tthis.#buffer = buffer ?? new Uint8Array();\n\t\tthis.#stream = stream;\n\t\tthis.#reader = this.#stream?.getReader();\n\t\tthis.version = version;\n\t}\n\n\t// Adds more data to the buffer, returning true if more data was added.\n\tasync #fill(): Promise<boolean> {\n\t\tif (!this.#reader) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Every read of this stream funnels through here, so decoding the peer's reset code\n\t\t// once is enough to keep the raw transport error out of every caller (and every app).\n\t\tconst result = await this.#reader.read().catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: asIetf(this.version) });\n\t\t});\n\n\t\tif (result.done) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (result.value.byteLength === 0) {\n\t\t\tthrow new Error(\"unexpected empty chunk\");\n\t\t}\n\n\t\tthis.#chunks.push(result.value);\n\t\tthis.#chunked += result.value.byteLength;\n\n\t\treturn true;\n\t}\n\n\t// Add more data to the buffer until it's at least size bytes.\n\tasync #fillTo(size: number) {\n\t\tif (size > MAX_READ_SIZE) {\n\t\t\tthrow new Error(`read size ${size} exceeds max size ${MAX_READ_SIZE}`);\n\t\t}\n\n\t\tif (this.#buffer.byteLength >= size) return;\n\n\t\twhile (this.#buffer.byteLength + this.#chunked < size) {\n\t\t\tif (!(await this.#fill())) {\n\t\t\t\tthrow new UnexpectedEnd();\n\t\t\t}\n\t\t}\n\n\t\tthis.#join();\n\t}\n\n\t// Move every pending chunk into the buffer, copying only when there's more than one piece.\n\t#join() {\n\t\tif (this.#chunks.length === 0) return;\n\n\t\tif (this.#buffer.byteLength === 0 && this.#chunks.length === 1) {\n\t\t\tthis.#buffer = this.#chunks[0];\n\t\t} else {\n\t\t\tconst joined = new Uint8Array(this.#buffer.byteLength + this.#chunked);\n\t\t\tjoined.set(this.#buffer);\n\t\t\tlet offset = this.#buffer.byteLength;\n\t\t\tfor (const chunk of this.#chunks) {\n\t\t\t\tjoined.set(chunk, offset);\n\t\t\t\toffset += chunk.byteLength;\n\t\t\t}\n\t\t\tthis.#buffer = joined;\n\t\t}\n\n\t\tthis.#chunks = [];\n\t\tthis.#chunked = 0;\n\t}\n\n\t// Consumes the first size bytes of the buffer.\n\t#slice(size: number): Uint8Array {\n\t\tconst result = new Uint8Array(this.#buffer.buffer, this.#buffer.byteOffset, size);\n\t\tthis.#buffer = new Uint8Array(\n\t\t\tthis.#buffer.buffer,\n\t\t\tthis.#buffer.byteOffset + size,\n\t\t\tthis.#buffer.byteLength - size,\n\t\t);\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Run a synchronous decode over the buffered bytes and consume what it read.\n\t *\n\t * Returns undefined and consumes nothing when the decode ran past the buffered bytes, so a\n\t * caller can drain every complete message already here without waiting on the stream.\n\t */\n\ttryDecode<T extends NonNullable<unknown>>(decode: (c: Cursor) => T): T | undefined {\n\t\tconst result = this.#try(decode);\n\t\treturn result instanceof Short ? undefined : result;\n\t}\n\n\t/** Run a synchronous decode, filling from the stream until it has the bytes it needs. */\n\tasync decode<T>(decode: (c: Cursor) => T): Promise<T> {\n\t\tfor (;;) {\n\t\t\tconst result = this.#try(decode);\n\t\t\tif (!(result instanceof Short)) return result;\n\t\t\tawait this.#fillTo(result.need);\n\t\t}\n\t}\n\n\t// Like decode, but leaves the bytes buffered for the next read.\n\tasync #peek<T>(decode: (c: Cursor) => T): Promise<T> {\n\t\tfor (;;) {\n\t\t\tconst result = this.#try(decode, false);\n\t\t\tif (!(result instanceof Short)) return result;\n\t\t\tawait this.#fillTo(result.need);\n\t\t}\n\t}\n\n\t/** Like {@link decode}, but returns undefined if the stream ends cleanly first. */\n\tasync decodeMaybe<T>(decode: (c: Cursor) => T): Promise<T | undefined> {\n\t\tif (await this.done()) return undefined;\n\t\treturn this.decode(decode);\n\t}\n\n\t#try<T>(decode: (c: Cursor) => T, consume = true): T | Short {\n\t\t// A retry of the decode that last ran short, before the bytes it needs have arrived,\n\t\t// would only throw again. Every decode reads at least a byte, so none can succeed on\n\t\t// an empty buffer either.\n\t\tconst available = this.#buffer.byteLength + this.#chunked;\n\t\tif (available === 0) return EMPTY;\n\t\tif (decode === this.#short?.decode && available < this.#short.err.need) return this.#short.err;\n\n\t\tthis.#join();\n\t\tconst cursor = new Cursor(this.#buffer, this.version);\n\t\ttry {\n\t\t\tconst result = decode(cursor);\n\t\t\tif (consume) this.#slice(cursor.offset);\n\t\t\tthis.#short = undefined;\n\t\t\treturn result;\n\t\t} catch (err: unknown) {\n\t\t\tif (!(err instanceof Short)) throw err;\n\t\t\t// Filling could never satisfy it, so retrying would spin.\n\t\t\tif (err.need <= this.#buffer.byteLength) throw new Error(\"decode ran short of bytes it already had\");\n\t\t\tthis.#short = { decode, err };\n\t\t\treturn err;\n\t\t}\n\t}\n\n\tasync read(size: number): Promise<Uint8Array> {\n\t\tif (size === 0) return new Uint8Array();\n\t\treturn this.decode((c) => c.read(size));\n\t}\n\n\tasync readAll(): Promise<Uint8Array> {\n\t\twhile (await this.#fill()) {\n\t\t\t// keep going\n\t\t}\n\t\tthis.#join();\n\t\treturn this.#slice(this.#buffer.byteLength);\n\t}\n\n\t// Reads to the end of the stream, dropping every byte instead of buffering it.\n\tasync discard(): Promise<void> {\n\t\tthis.#buffer = new Uint8Array();\n\t\tdo {\n\t\t\tthis.#chunks = [];\n\t\t\tthis.#chunked = 0;\n\t\t} while (await this.#fill());\n\t}\n\n\tasync string(): Promise<string> {\n\t\treturn this.decode(STRING);\n\t}\n\n\tasync bool(): Promise<boolean> {\n\t\treturn this.decode(BOOL);\n\t}\n\n\tasync u8(): Promise<number> {\n\t\treturn this.decode(U8);\n\t}\n\n\tasync u16(): Promise<number> {\n\t\treturn this.decode(U16);\n\t}\n\n\t// Returns a Number using 53-bits, the max Javascript can use for integer math.\n\tasync u53(): Promise<number> {\n\t\treturn this.decode(U53);\n\t}\n\n\t// NOTE: Returns a bigint instead of a number since it may be larger than 53-bits\n\tasync u62(): Promise<bigint> {\n\t\treturn this.decode(U62);\n\t}\n\n\t/** Like {@link u62}, but leaves the varint buffered, so a stream's type can be read twice. */\n\tasync peekU62(): Promise<bigint> {\n\t\treturn this.#peek(U62);\n\t}\n\n\tasync varint(): Promise<U64> {\n\t\treturn this.decode(VARINT);\n\t}\n\n\t// Returns false if there is more data to read, blocking if it hasn't been received yet.\n\tasync done(): Promise<boolean> {\n\t\tif (this.#buffer.byteLength > 0 || this.#chunked > 0) return false;\n\t\treturn !(await this.#fill());\n\t}\n\n\tstop(reason: unknown) {\n\t\tthis.#reader?.cancel(withCode(reason, this.version)).catch(() => void 0);\n\t}\n\n\t// Decoded like #fill: a caller racing this against a read must not get a different error\n\t// shape depending on which one won. Derived once, so racing it per frame doesn't allocate.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= (this.#reader?.closed ?? Promise.resolve()).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: asIetf(this.version) });\n\t\t});\n\t\treturn this.#closed;\n\t}\n}\n\n/** The stream ended cleanly partway through a read. */\nexport class UnexpectedEnd extends Error {\n\tconstructor() {\n\t\tsuper(\"unexpected end of stream\");\n\t}\n}\n\n// Thrown by a Cursor read that runs past the buffered bytes, carrying how many bytes from the\n// start of the buffer the decode needs. Not an Error: it ends every chunk, so it must not\n// capture a stack.\nclass Short {\n\treadonly need: number;\n\n\tconstructor(need: number) {\n\t\tthis.need = need;\n\t}\n}\n\nconst EMPTY = new Short(1);\n\n/**\n * A synchronous view over a {@link Reader}'s buffered bytes, handed to {@link Reader.decode}.\n *\n * A read past the buffered bytes throws an internal signal that the Reader catches: it consumes\n * nothing, fills, and runs the decode again from the start. A decode must therefore not mutate\n * anything before its last read, must not swallow what it throws, and must read at least a byte.\n */\nexport class Cursor {\n\treadonly version: StreamVersion;\n\t#buffer: Uint8Array;\n\t#offset = 0;\n\t// Resolved once, since every varint read branches on it.\n\t#leadingOnes: boolean;\n\t// First bytes below this are a whole 1-byte varint, and below this + 0x40 a 2-byte one whose\n\t// value is the low 6 bits and the next byte. Both formats share that shape; only the bound moves.\n\t#short: number;\n\t// First bytes below this are a varint of at most 4 bytes: 0xc0 for QUIC, 0xf0 for leading-ones.\n\t#word: number;\n\n\tconstructor(buffer: Uint8Array, version: StreamVersion) {\n\t\tthis.#buffer = buffer;\n\t\tthis.version = version;\n\t\tthis.#leadingOnes = isLeadingOnes(version);\n\t\tthis.#short = this.#leadingOnes ? 0x80 : 0x40;\n\t\tthis.#word = this.#leadingOnes ? 0xf0 : 0xc0;\n\t}\n\n\t/** How many bytes have been read. */\n\tget offset(): number {\n\t\treturn this.#offset;\n\t}\n\n\t/** How many buffered bytes are left to read. */\n\tget remaining(): number {\n\t\treturn this.#buffer.byteLength - this.#offset;\n\t}\n\n\t/**\n\t * Decode the next `size` bytes on their own. Running past them, or leaving any unread, is\n\t * malformed rather than a reason to wait for more.\n\t */\n\texact<T>(size: number, decode: (c: Cursor) => T): T {\n\t\tconst inner = new Cursor(this.read(size), this.version);\n\t\tlet result: T;\n\t\ttry {\n\t\t\tresult = decode(inner);\n\t\t} catch (err: unknown) {\n\t\t\tif (err instanceof Short) throw new Error(`message is shorter than its fields: ${size} bytes`);\n\t\t\tthrow err;\n\t\t}\n\t\tif (inner.remaining > 0) throw new Error(`message has ${inner.remaining} unread bytes`);\n\t\treturn result;\n\t}\n\n\t#ensure(size: number) {\n\t\tconst need = this.#offset + size;\n\t\t// Checked here too, and on the whole decode like the fill, since bytes that are already\n\t\t// buffered never reach the fill.\n\t\tif (need > MAX_READ_SIZE) throw new Error(`read size ${need} exceeds max size ${MAX_READ_SIZE}`);\n\t\tif (need > this.#buffer.byteLength) throw new Short(need);\n\t}\n\n\t/** Read `size` bytes, as a view onto the buffer rather than a copy. */\n\tread(size: number): Uint8Array {\n\t\tthis.#ensure(size);\n\t\tconst start = this.#offset;\n\t\tthis.#offset += size;\n\t\treturn this.#buffer.subarray(start, this.#offset);\n\t}\n\n\tstring(): string {\n\t\treturn decodeUtf8(this.read(this.u53()));\n\t}\n\n\tbool(): boolean {\n\t\tconst v = this.u8();\n\t\tif (v === 0) return false;\n\t\tif (v === 1) return true;\n\t\tthrow new Error(\"invalid bool value\");\n\t}\n\n\tu8(): number {\n\t\tthis.#ensure(1);\n\t\treturn this.#buffer[this.#offset++];\n\t}\n\n\tu16(): number {\n\t\tthis.#ensure(2);\n\t\tconst b = this.#buffer;\n\t\tconst o = this.#offset;\n\t\tthis.#offset += 2;\n\t\treturn (b[o] << 8) | b[o + 1];\n\t}\n\n\t/** Read a varint as a `number`, throwing if it is above `Number.MAX_SAFE_INTEGER`. */\n\tu53(): number {\n\t\t// Most varints are 1 or 2 bytes, which skip the general decode.\n\t\tthis.#ensure(1);\n\t\tconst b = this.#buffer;\n\t\tconst o = this.#offset;\n\t\tconst first = b[o];\n\t\tif (first < this.#short) {\n\t\t\tthis.#offset = o + 1;\n\t\t\treturn first;\n\t\t}\n\t\tif (first < this.#short + 0x40) {\n\t\t\tthis.#ensure(2);\n\t\t\tthis.#offset = o + 2;\n\t\t\treturn ((first & 0x3f) << 8) | b[o + 1];\n\t\t}\n\t\t// Up to 4 bytes still fits 28 (leading-ones) or 30 (QUIC) bits, with no upper half.\n\t\tif (first < this.#word) {\n\t\t\tconst size = this.#leadingOnes ? peekLeadingOnes(first) : 4;\n\t\t\tthis.#ensure(size);\n\t\t\tthis.#offset = o + size;\n\t\t\tif (size === 3) return ((first & 0x1f) << 16) | (b[o + 1] << 8) | b[o + 2];\n\t\t\treturn ((first & (this.#leadingOnes ? 0x0f : 0x3f)) << 24) | (b[o + 1] << 16) | (b[o + 2] << 8) | b[o + 3];\n\t\t}\n\t\tconst lo = this.#varint();\n\t\treturn toNumber(parts.hi, lo);\n\t}\n\n\t/** Read a varint as a bigint. A leading-ones varint may exceed 62 bits. */\n\tu62(): bigint {\n\t\tconst lo = this.#varint();\n\t\treturn toBigInt(parts.hi, lo);\n\t}\n\n\t/** Read a varint. */\n\tvarint(): U64 {\n\t\tconst lo = this.#varint();\n\t\treturn new U64(parts.hi, lo);\n\t}\n\n\t// Decode the next varint in the version's format, returning its lower half and leaving the upper in `parts`.\n\t#varint(): number {\n\t\tthis.#ensure(1);\n\t\tconst b = this.#buffer;\n\t\tconst o = this.#offset;\n\t\tlet size: number;\n\t\tif (this.#leadingOnes) {\n\t\t\tsize = peekLeadingOnes(b[o]);\n\t\t\t// 1111110x is a 7-byte form. Draft-17 rejects it; draft-18+ allows it per #1595.\n\t\t\tif (size === 7 && this.version === Version.DRAFT_17) {\n\t\t\t\tthrow new Error(\"invalid leading-ones varint: 1111110x prefix is reserved on draft-17\");\n\t\t\t}\n\t\t\tthis.#ensure(size);\n\t\t\tthis.#offset += size;\n\t\t\treturn readLeadingOnes(b, o, size);\n\t\t}\n\t\tsize = peekQuic(b[o]);\n\t\tthis.#ensure(size);\n\t\tthis.#offset += size;\n\t\treturn readQuic(b, o, size);\n\t}\n}\n\n// Shared decodes for the Reader's async primitives, so a read allocates no closure.\nconst STRING = (c: Cursor) => c.string();\nconst BOOL = (c: Cursor) => c.bool();\nconst U8 = (c: Cursor) => c.u8();\nconst U16 = (c: Cursor) => c.u16();\nconst U53 = (c: Cursor) => c.u53();\nconst U62 = (c: Cursor) => c.u62();\nconst VARINT = (c: Cursor) => c.varint();\n\n// Writer wraps a stream and writes chunks of data\nexport class Writer {\n\t#writer: WritableStreamDefaultWriter<Uint8Array>;\n\t#stream: WritableStream<Uint8Array>;\n\t#closed?: Promise<void>;\n\n\t// Scratch buffer for each primitive write, sized for the longest (a 9-byte leading-ones varint).\n\t#scratch: ArrayBuffer;\n\n\tversion: StreamVersion;\n\n\tconstructor(stream: WritableStream<Uint8Array>, version: StreamVersion) {\n\t\tthis.#stream = stream;\n\t\tthis.#scratch = new ArrayBuffer(9);\n\t\tthis.#writer = this.#stream.getWriter();\n\t\tthis.version = version;\n\t}\n\n\t/**\n\t * Rank this stream against the session's others, where HIGHER values are sent first.\n\t *\n\t * A send order only schedules the local end, so a stream the peer opened has to be ranked\n\t * here rather than at the peer's {@link open}.\n\t *\n\t * The spec makes `sendOrder` a settable attribute on every {@link SendStream}. Where the\n\t * interface isn't implemented (Chrome as of writing, a mock, a polyfill) this just sets an\n\t * ignored property, the same way an ignored `sendOrder` option does at {@link open}.\n\t */\n\tsetPriority(sendOrder: number) {\n\t\t(this.#stream as SendStream).sendOrder = sendOrder;\n\t}\n\n\tasync bool(v: boolean) {\n\t\tawait this.write(setUint8(this.#scratch, v ? 1 : 0));\n\t}\n\n\tasync u8(v: number) {\n\t\tif (!Number.isInteger(v) || v < 0 || v > 255) {\n\t\t\tthrow new RangeError(`invalid u8: ${v}`);\n\t\t}\n\t\tawait this.write(setUint8(this.#scratch, v));\n\t}\n\n\tasync u16(v: number) {\n\t\tawait this.write(setUint16(this.#scratch, v));\n\t}\n\n\tasync i32(v: number) {\n\t\tif (Math.abs(v) > MAX_U31) {\n\t\t\tthrow new Error(`overflow, value larger than 32-bits: ${v.toString()}`);\n\t\t}\n\n\t\t// We don't use a varint, so it always takes 4 bytes.\n\t\t// This could be improved but nothing is standardized yet.\n\t\tawait this.write(setInt32(this.#scratch, v));\n\t}\n\n\tasync u53(v: number) {\n\t\tif (!Number.isSafeInteger(v) || v < 0) {\n\t\t\tthrow new RangeError(`invalid u53: ${v}`);\n\t\t}\n\t\tawait this.#varint(Math.floor(v / POW32), v >>> 0);\n\t}\n\n\tasync u62(v: bigint) {\n\t\tconst lo = split(v);\n\t\tawait this.#varint(parts.hi, lo);\n\t}\n\n\tasync varint(v: U64) {\n\t\tawait this.#varint(v.hi, v.lo);\n\t}\n\n\t#varint(hi: number, lo: number): Promise<void> {\n\t\treturn this.write(encodeTo(this.#scratch, hi, lo, this.version));\n\t}\n\n\tasync write(v: Uint8Array) {\n\t\t// Mirrors Reader.#fill: every write funnels through here, so a STOP_SENDING from the\n\t\t// peer surfaces as a typed code rather than the transport's own error shape.\n\t\tawait this.#writer.write(v).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: asIetf(this.version) });\n\t\t});\n\t}\n\n\tasync string(str: string) {\n\t\tconst data = new TextEncoder().encode(str);\n\t\tawait this.u53(data.byteLength);\n\t\tawait this.write(data);\n\t}\n\n\tclose() {\n\t\tthis.#writer.close().catch(() => void 0);\n\t}\n\n\t// Mirrors Reader.closed: a STOP_SENDING reaches a caller racing this with the same\n\t// typed code it would get from a write.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= this.#writer.closed.catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: asIetf(this.version) });\n\t\t});\n\t\treturn this.#closed;\n\t}\n\n\treset(reason: unknown) {\n\t\tthis.#writer.abort(withCode(reason, this.version)).catch(() => void 0);\n\t}\n\n\t/** Run `f` against a Writer that buffers in memory, returning everything it wrote as one chunk. */\n\tstatic async collect(version: StreamVersion, f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\t\tconst chunks: Uint8Array[] = [];\n\t\t// Copied, since each primitive reuses the Writer's scratch buffer.\n\t\tconst w = new Writer(\n\t\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void chunks.push(chunk.slice()) }),\n\t\t\tversion,\n\t\t);\n\t\ttry {\n\t\t\tawait f(w);\n\t\t} finally {\n\t\t\tw.close();\n\t\t}\n\t\tawait w.closed;\n\t\treturn concat(chunks);\n\t}\n\n\t/**\n\t * Open an outgoing unidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options: OpenOptions): Promise<Writer> {\n\t\tconst writable = await openWithin(\n\t\t\tquic.createUnidirectionalStream(sendOptions(options)) as Promise<WritableStream<Uint8Array>>,\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => void stream.abort().catch(() => void 0),\n\t\t);\n\n\t\treturn new Writer(writable, options.version);\n\t}\n\n\t/**\n\t * Like {@link Writer.open}, but gives up when `cancel` settles or `timeout` elapses,\n\t * returning undefined so the caller can drop whatever it meant to send. A stream that\n\t * opens after that is reset rather than leaked. A real transport failure still throws.\n\t *\n\t * Worth using even with `waitUntilAvailable: false`, since an implementation may park\n\t * an over-limit open instead of rejecting it.\n\t */\n\tstatic async tryOpen(quic: WebTransport, options: TryOpenOptions): Promise<Writer | undefined> {\n\t\t// Raced ahead of the open, so an already-cancelled caller wins even against a slot\n\t\t// that is free right now. `race` rather than `Promise.race`: the caller shares one\n\t\t// `cancel` across every group of a subscription, which must not gain a reaction per call.\n\t\tconst open = Writer.open(quic, options);\n\n\t\t// Resets a stream that opens after we gave up; a no-op if the open itself failed.\n\t\tconst abandon = () => {\n\t\t\tconst abandoned = new Error(\"abandoned waiting for a stream slot\");\n\t\t\topen.then((w) => w.reset(abandoned)).catch(() => void 0);\n\t\t};\n\n\t\ttry {\n\t\t\tconst stream = await race([options.cancel, open]);\n\t\t\tif (stream) return stream;\n\t\t} catch (err: unknown) {\n\t\t\t// open already discarded the late stream on its way out.\n\t\t\tif (err instanceof TimeoutError) return undefined;\n\t\t\t// A rejected `cancel` still leaves the open pending.\n\t\t\tabandon();\n\t\t\tthrow err;\n\t\t}\n\n\t\tabandon();\n\t\treturn undefined;\n\t}\n}\n\nfunction setUint8(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst buffer = new Uint8Array(dst, 0, 1);\n\tbuffer[0] = v;\n\treturn buffer;\n}\n\nfunction setUint16(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 2);\n\tview.setUint16(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setInt32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setInt32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\n// Returns the next stream from the connection\nexport class Readers {\n\t#reader: ReadableStreamDefaultReader<ReadableStream<Uint8Array>>;\n\t#version: StreamVersion;\n\n\tconstructor(quic: WebTransport, version: StreamVersion) {\n\t\tthis.#reader = quic.incomingUnidirectionalStreams.getReader() as ReadableStreamDefaultReader<\n\t\t\tReadableStream<Uint8Array>\n\t\t>;\n\t\tthis.#version = version;\n\t}\n\n\tasync next(): Promise<Reader | undefined> {\n\t\tconst next = await this.#reader.read();\n\t\tif (next.done) return;\n\t\treturn new Reader(next.value, undefined, this.#version);\n\t}\n\n\tclose() {\n\t\tthis.#reader.cancel();\n\t}\n}\n"]}