@moq/net 0.3.3 → 0.3.4

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.
Files changed (87) hide show
  1. package/connection/accept.d.ts.map +1 -1
  2. package/connection/accept.js +3 -0
  3. package/connection/accept.js.map +1 -1
  4. package/connection/browser.d.ts.map +1 -1
  5. package/connection/browser.js +3 -0
  6. package/connection/browser.js.map +1 -1
  7. package/connection/connect.d.ts.map +1 -1
  8. package/connection/connect.js +11 -7
  9. package/connection/connect.js.map +1 -1
  10. package/group.d.ts +19 -1
  11. package/group.d.ts.map +1 -1
  12. package/group.js +35 -11
  13. package/group.js.map +1 -1
  14. package/ietf/adapter.d.ts.map +1 -1
  15. package/ietf/adapter.js +76 -45
  16. package/ietf/adapter.js.map +1 -1
  17. package/ietf/fetch.d.ts +17 -0
  18. package/ietf/fetch.d.ts.map +1 -1
  19. package/ietf/fetch.js +21 -0
  20. package/ietf/fetch.js.map +1 -1
  21. package/ietf/filter.d.ts +87 -0
  22. package/ietf/filter.d.ts.map +1 -0
  23. package/ietf/filter.js +292 -0
  24. package/ietf/filter.js.map +1 -0
  25. package/ietf/namespace.d.ts +6 -0
  26. package/ietf/namespace.d.ts.map +1 -1
  27. package/ietf/namespace.js +27 -2
  28. package/ietf/namespace.js.map +1 -1
  29. package/ietf/object.d.ts +44 -2
  30. package/ietf/object.d.ts.map +1 -1
  31. package/ietf/object.js +74 -9
  32. package/ietf/object.js.map +1 -1
  33. package/ietf/parameters.d.ts +16 -4
  34. package/ietf/parameters.d.ts.map +1 -1
  35. package/ietf/parameters.js +54 -10
  36. package/ietf/parameters.js.map +1 -1
  37. package/ietf/properties.d.ts +5 -0
  38. package/ietf/properties.d.ts.map +1 -1
  39. package/ietf/properties.js +5 -0
  40. package/ietf/properties.js.map +1 -1
  41. package/ietf/publisher.d.ts.map +1 -1
  42. package/ietf/publisher.js +371 -25
  43. package/ietf/publisher.js.map +1 -1
  44. package/ietf/subscribe.d.ts +38 -7
  45. package/ietf/subscribe.d.ts.map +1 -1
  46. package/ietf/subscribe.js +94 -29
  47. package/ietf/subscribe.js.map +1 -1
  48. package/ietf/subscriber.d.ts.map +1 -1
  49. package/ietf/subscriber.js +27 -4
  50. package/ietf/subscriber.js.map +1 -1
  51. package/ietf/version.d.ts +7 -1
  52. package/ietf/version.d.ts.map +1 -1
  53. package/ietf/version.js +7 -0
  54. package/ietf/version.js.map +1 -1
  55. package/lite/announce.d.ts.map +1 -1
  56. package/lite/announce.js +7 -7
  57. package/lite/announce.js.map +1 -1
  58. package/lite/setup.d.ts.map +1 -1
  59. package/lite/setup.js +2 -1
  60. package/lite/setup.js.map +1 -1
  61. package/lite/subscriber.d.ts +1 -6
  62. package/lite/subscriber.d.ts.map +1 -1
  63. package/lite/subscriber.js +98 -23
  64. package/lite/subscriber.js.map +1 -1
  65. package/lite/version.d.ts +4 -0
  66. package/lite/version.d.ts.map +1 -1
  67. package/lite/version.js +15 -0
  68. package/lite/version.js.map +1 -1
  69. package/origin.d.ts +1 -1
  70. package/origin.d.ts.map +1 -1
  71. package/origin.js +1 -1
  72. package/origin.js.map +1 -1
  73. package/package.json +4 -3
  74. package/stream.d.ts.map +1 -1
  75. package/stream.js +3 -5
  76. package/stream.js.map +1 -1
  77. package/track.d.ts +38 -0
  78. package/track.d.ts.map +1 -1
  79. package/track.js +69 -11
  80. package/track.js.map +1 -1
  81. package/util/utf8.d.ts +3 -0
  82. package/util/utf8.d.ts.map +1 -0
  83. package/util/utf8.js +7 -0
  84. package/util/utf8.js.map +1 -0
  85. package/zod.d.ts +1 -1
  86. package/zod.d.ts.map +1 -1
  87. package/zod.js.map +1 -1
package/stream.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C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AAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,8CAA8C;AAC9C,MAAM,OAAO,OAAO;IACnB,OAAO,CAA0D;IACjE,QAAQ,CAAe;IAEvB,YAAY,IAAkB,EAAE,OAAqB;QACpD,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 { fromTransport } from \"./error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { Version } from \"./ietf/version.ts\";\nimport { TimeoutError, withTimeout } from \"./util/timeout.ts\";\nimport * as Varint from \"./varint.ts\";\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\nfunction isLeadingOnes(version?: IetfVersion): boolean {\n\treturn (\n\t\tversion !== undefined &&\n\t\tversion !== Version.DRAFT_14 &&\n\t\tversion !== Version.DRAFT_15 &&\n\t\tversion !== Version.DRAFT_16\n\t);\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 IETF version, which selects the varint encoding. */\n\tversion?: IetfVersion;\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 settles, however it settles. */\n\tcancel: Promise<unknown>;\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?: IetfVersion;\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?: IetfVersion;\n\t}) {\n\t\tconst writer = props.writer ?? (props.writable && new Writer(props.writable, props.version));\n\t\tconst reader = props.reader ?? (props.readable && new Reader(props.readable, undefined, props.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?: IetfVersion): 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\tthis.reader.stop(new Error(\"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#buffer: Uint8Array;\n\t#stream?: ReadableStream<Uint8Array>; // if undefined, the buffer is consumed then EOF\n\t#reader?: ReadableStreamDefaultReader<Uint8Array>;\n\t#closed?: Promise<void>;\n\tversion?: IetfVersion;\n\n\t// Either stream or buffer MUST be provided.\n\tconstructor(stream: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion);\n\tconstructor(stream: undefined, buffer: Uint8Array, version?: IetfVersion);\n\tconstructor(stream?: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion) {\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);\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\tconst buffer = new Uint8Array(result.value);\n\n\t\tif (this.#buffer.byteLength === 0) {\n\t\t\tthis.#buffer = buffer;\n\t\t} else {\n\t\t\tconst temp = new Uint8Array(this.#buffer.byteLength + buffer.byteLength);\n\t\t\ttemp.set(this.#buffer);\n\t\t\ttemp.set(buffer, this.#buffer.byteLength);\n\t\t\tthis.#buffer = temp;\n\t\t}\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\twhile (this.#buffer.byteLength < size) {\n\t\t\tif (!(await this.#fill())) {\n\t\t\t\tthrow new Error(\"unexpected end of stream\");\n\t\t\t}\n\t\t}\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\tasync read(size: number): Promise<Uint8Array> {\n\t\tif (size === 0) return new Uint8Array();\n\n\t\tawait this.#fillTo(size);\n\t\treturn this.#slice(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\treturn this.#slice(this.#buffer.byteLength);\n\t}\n\n\tasync string(): Promise<string> {\n\t\tconst length = await this.u53();\n\t\tconst buffer = await this.read(length);\n\t\treturn new TextDecoder().decode(buffer);\n\t}\n\n\tasync bool(): Promise<boolean> {\n\t\tconst v = await 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\tasync u8(): Promise<number> {\n\t\tawait this.#fillTo(1);\n\t\treturn this.#slice(1)[0];\n\t}\n\n\tasync u16(): Promise<number> {\n\t\tawait this.#fillTo(2);\n\t\tconst view = new DataView(this.#buffer.buffer, this.#buffer.byteOffset, 2);\n\t\tconst result = view.getUint16(0);\n\t\tthis.#slice(2);\n\t\treturn result;\n\t}\n\n\t// Returns a Number using 53-bits, the max Javascript can use for integer math.\n\t// Values > 2^53-1 are coerced to a Number (precision is lost) and logged. We\n\t// downgrade overflow from throw to warn so a stray u64 field on the wire (e.g.\n\t// a peer's session-level Origin id) doesn't tear down the whole stream/session.\n\tasync u53(): Promise<number> {\n\t\tconst v = await this.u62();\n\t\tif (v > Varint.MAX_U53) {\n\t\t\tconsole.warn(`value larger than 53-bits; use u62 instead (precision lost): ${v.toString()}`);\n\t\t}\n\n\t\treturn Number(v);\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\tif (isLeadingOnes(this.version)) {\n\t\t\treturn this.#readLeadingOnes();\n\t\t}\n\t\treturn this.#readQuicVarint();\n\t}\n\n\tasync #readQuicVarint(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst size = (this.#buffer[0] & 0xc0) >> 6;\n\n\t\tif (size === 0) {\n\t\t\tconst first = this.#slice(1)[0];\n\t\t\treturn BigInt(first) & 0x3fn;\n\t\t}\n\t\tif (size === 1) {\n\t\t\tawait this.#fillTo(2);\n\t\t\tconst slice = this.#slice(2);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint16(0)) & 0x3fffn;\n\t\t}\n\t\tif (size === 2) {\n\t\t\tawait this.#fillTo(4);\n\t\t\tconst slice = this.#slice(4);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint32(0)) & 0x3fffffffn;\n\t\t}\n\t\tawait this.#fillTo(8);\n\t\tconst slice = this.#slice(8);\n\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\treturn view.getBigUint64(0) & 0x3fffffffffffffffn;\n\t}\n\n\tasync #readLeadingOnes(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst b = this.#buffer[0];\n\n\t\t// Count leading 1-bits\n\t\tlet ones = 0;\n\t\tfor (let bit = 7; bit >= 0; bit--) {\n\t\t\tif (b & (1 << bit)) ones++;\n\t\t\telse break;\n\t\t}\n\n\t\t// 1111110x is a 7-byte form. Draft-17 rejects it; draft-18+ allows it per #1595.\n\t\tif (ones === 6 && this.version === Version.DRAFT_17) {\n\t\t\tthrow new Error(\"invalid leading-ones varint: 1111110x prefix is reserved on draft-17\");\n\t\t}\n\n\t\tlet totalSize: number;\n\t\tif (ones <= 5) totalSize = ones + 1;\n\t\telse if (ones === 6) totalSize = 7;\n\t\telse if (ones === 7) totalSize = 8;\n\t\telse totalSize = 9; // ones === 8\n\n\t\tawait this.#fillTo(totalSize);\n\t\tconst slice = this.#slice(totalSize);\n\n\t\tconst [value] = Varint.decodeLeadingOnes(slice);\n\t\treturn value;\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) return false;\n\t\treturn !(await this.#fill());\n\t}\n\n\tstop(reason: unknown) {\n\t\tthis.#reader?.cancel(reason).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);\n\t\t});\n\t\treturn this.#closed;\n\t}\n}\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 writing varints.\n\t// Fixed at 9 bytes (leading-ones max).\n\t#scratch: ArrayBuffer;\n\n\tversion?: IetfVersion;\n\n\tconstructor(stream: WritableStream<Uint8Array>, version?: IetfVersion) {\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\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 (v > Varint.MAX_U53) {\n\t\t\t// Number values above 2^53-1 have already lost precision before reaching\n\t\t\t// the wire, but downgrade overflow to warn so an upstream miscount\n\t\t\t// doesn't tear down the whole stream. The encoded varint will reflect\n\t\t\t// the truncated Number value.\n\t\t\tconsole.warn(`value larger than 53-bits; use u62 instead (precision lost): ${v.toString()}`);\n\t\t}\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync u62(v: bigint) {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\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);\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);\n\t\t});\n\t\treturn this.#closed;\n\t}\n\n\treset(reason: unknown) {\n\t\tthis.#writer.abort(reason).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// A rejected `cancel` (STOP_SENDING) means the peer is gone too, so both settle\n\t\t// paths mean \"give up\" and neither is left unhandled. Built before the open, and\n\t\t// raced ahead of it, so an already-cancelled caller wins even against a slot that\n\t\t// is free right now.\n\t\tconst cancelled = options.cancel.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tconst open = Writer.open(quic, options);\n\n\t\ttry {\n\t\t\tconst stream = await Promise.race([cancelled, 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)) throw err;\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst abandoned = new Error(\"abandoned waiting for a stream slot\");\n\t\topen.then((w) => w.reset(abandoned)).catch(() => void 0);\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?: IetfVersion;\n\n\tconstructor(quic: WebTransport, version?: IetfVersion) {\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
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC5B,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,8CAA8C;AAEtF;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAAqB;IAChD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,kBAAkB,IAAI,IAAI,EAAE,CAAC;AACnG,CAAC;AAED,wFAAwF;AACxF,wFAAwF;AACxF,yFAAyF;AACzF,gCAAgC;AAChC,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B;;;;GAIG;AACH,KAAK,UAAU,UAAU,CAAI,OAAmB,EAAE,OAAe,EAAE,OAA4B;IAC9F,IAAI,CAAC;QACJ,OAAO,MAAM,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,+BAA+B,OAAO,uBAAuB,CAAC,CAAC;IAC3G,CAAC;IAAC,O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AAI,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,QAAQ,CAAC,GAAgB,EAAE,CAAS;IAC5C,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,8CAA8C;AAC9C,MAAM,OAAO,OAAO;IACnB,OAAO,CAA0D;IACjE,QAAQ,CAAe;IAEvB,YAAY,IAAkB,EAAE,OAAqB;QACpD,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 { fromTransport } from \"./error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { Version } from \"./ietf/version.ts\";\nimport { TimeoutError, withTimeout } from \"./util/timeout.ts\";\nimport { decodeUtf8 } from \"./util/utf8.ts\";\nimport * as Varint from \"./varint.ts\";\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\nfunction isLeadingOnes(version?: IetfVersion): boolean {\n\treturn (\n\t\tversion !== undefined &&\n\t\tversion !== Version.DRAFT_14 &&\n\t\tversion !== Version.DRAFT_15 &&\n\t\tversion !== Version.DRAFT_16\n\t);\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 IETF version, which selects the varint encoding. */\n\tversion?: IetfVersion;\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 settles, however it settles. */\n\tcancel: Promise<unknown>;\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?: IetfVersion;\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?: IetfVersion;\n\t}) {\n\t\tconst writer = props.writer ?? (props.writable && new Writer(props.writable, props.version));\n\t\tconst reader = props.reader ?? (props.readable && new Reader(props.readable, undefined, props.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?: IetfVersion): 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\tthis.reader.stop(new Error(\"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#buffer: Uint8Array;\n\t#stream?: ReadableStream<Uint8Array>; // if undefined, the buffer is consumed then EOF\n\t#reader?: ReadableStreamDefaultReader<Uint8Array>;\n\t#closed?: Promise<void>;\n\tversion?: IetfVersion;\n\n\t// Either stream or buffer MUST be provided.\n\tconstructor(stream: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion);\n\tconstructor(stream: undefined, buffer: Uint8Array, version?: IetfVersion);\n\tconstructor(stream?: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion) {\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);\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\tconst buffer = new Uint8Array(result.value);\n\n\t\tif (this.#buffer.byteLength === 0) {\n\t\t\tthis.#buffer = buffer;\n\t\t} else {\n\t\t\tconst temp = new Uint8Array(this.#buffer.byteLength + buffer.byteLength);\n\t\t\ttemp.set(this.#buffer);\n\t\t\ttemp.set(buffer, this.#buffer.byteLength);\n\t\t\tthis.#buffer = temp;\n\t\t}\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\twhile (this.#buffer.byteLength < size) {\n\t\t\tif (!(await this.#fill())) {\n\t\t\t\tthrow new Error(\"unexpected end of stream\");\n\t\t\t}\n\t\t}\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\tasync read(size: number): Promise<Uint8Array> {\n\t\tif (size === 0) return new Uint8Array();\n\n\t\tawait this.#fillTo(size);\n\t\treturn this.#slice(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\treturn this.#slice(this.#buffer.byteLength);\n\t}\n\n\tasync string(): Promise<string> {\n\t\tconst length = await this.u53();\n\t\tconst buffer = await this.read(length);\n\t\treturn decodeUtf8(buffer);\n\t}\n\n\tasync bool(): Promise<boolean> {\n\t\tconst v = await 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\tasync u8(): Promise<number> {\n\t\tawait this.#fillTo(1);\n\t\treturn this.#slice(1)[0];\n\t}\n\n\tasync u16(): Promise<number> {\n\t\tawait this.#fillTo(2);\n\t\tconst view = new DataView(this.#buffer.buffer, this.#buffer.byteOffset, 2);\n\t\tconst result = view.getUint16(0);\n\t\tthis.#slice(2);\n\t\treturn result;\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\tconst v = await this.u62();\n\t\tif (v > Varint.MAX_U53) {\n\t\t\tthrow new Error(`value larger than 53-bits: ${v.toString()}`);\n\t\t}\n\n\t\treturn Number(v);\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\tif (isLeadingOnes(this.version)) {\n\t\t\treturn this.#readLeadingOnes();\n\t\t}\n\t\treturn this.#readQuicVarint();\n\t}\n\n\tasync #readQuicVarint(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst size = (this.#buffer[0] & 0xc0) >> 6;\n\n\t\tif (size === 0) {\n\t\t\tconst first = this.#slice(1)[0];\n\t\t\treturn BigInt(first) & 0x3fn;\n\t\t}\n\t\tif (size === 1) {\n\t\t\tawait this.#fillTo(2);\n\t\t\tconst slice = this.#slice(2);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint16(0)) & 0x3fffn;\n\t\t}\n\t\tif (size === 2) {\n\t\t\tawait this.#fillTo(4);\n\t\t\tconst slice = this.#slice(4);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint32(0)) & 0x3fffffffn;\n\t\t}\n\t\tawait this.#fillTo(8);\n\t\tconst slice = this.#slice(8);\n\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\treturn view.getBigUint64(0) & 0x3fffffffffffffffn;\n\t}\n\n\tasync #readLeadingOnes(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst b = this.#buffer[0];\n\n\t\t// Count leading 1-bits\n\t\tlet ones = 0;\n\t\tfor (let bit = 7; bit >= 0; bit--) {\n\t\t\tif (b & (1 << bit)) ones++;\n\t\t\telse break;\n\t\t}\n\n\t\t// 1111110x is a 7-byte form. Draft-17 rejects it; draft-18+ allows it per #1595.\n\t\tif (ones === 6 && this.version === Version.DRAFT_17) {\n\t\t\tthrow new Error(\"invalid leading-ones varint: 1111110x prefix is reserved on draft-17\");\n\t\t}\n\n\t\tlet totalSize: number;\n\t\tif (ones <= 5) totalSize = ones + 1;\n\t\telse if (ones === 6) totalSize = 7;\n\t\telse if (ones === 7) totalSize = 8;\n\t\telse totalSize = 9; // ones === 8\n\n\t\tawait this.#fillTo(totalSize);\n\t\tconst slice = this.#slice(totalSize);\n\n\t\tconst [value] = Varint.decodeLeadingOnes(slice);\n\t\treturn value;\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) return false;\n\t\treturn !(await this.#fill());\n\t}\n\n\tstop(reason: unknown) {\n\t\tthis.#reader?.cancel(reason).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);\n\t\t});\n\t\treturn this.#closed;\n\t}\n}\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 writing varints.\n\t// Fixed at 9 bytes (leading-ones max).\n\t#scratch: ArrayBuffer;\n\n\tversion?: IetfVersion;\n\n\tconstructor(stream: WritableStream<Uint8Array>, version?: IetfVersion) {\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\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 (v > Varint.MAX_U53) {\n\t\t\t// Number values above 2^53-1 have already lost precision before reaching\n\t\t\t// the wire, but downgrade overflow to warn so an upstream miscount\n\t\t\t// doesn't tear down the whole stream. The encoded varint will reflect\n\t\t\t// the truncated Number value.\n\t\t\tconsole.warn(`value larger than 53-bits; use u62 instead (precision lost): ${v.toString()}`);\n\t\t}\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync u62(v: bigint) {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\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);\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);\n\t\t});\n\t\treturn this.#closed;\n\t}\n\n\treset(reason: unknown) {\n\t\tthis.#writer.abort(reason).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// A rejected `cancel` (STOP_SENDING) means the peer is gone too, so both settle\n\t\t// paths mean \"give up\" and neither is left unhandled. Built before the open, and\n\t\t// raced ahead of it, so an already-cancelled caller wins even against a slot that\n\t\t// is free right now.\n\t\tconst cancelled = options.cancel.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tconst open = Writer.open(quic, options);\n\n\t\ttry {\n\t\t\tconst stream = await Promise.race([cancelled, 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)) throw err;\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst abandoned = new Error(\"abandoned waiting for a stream slot\");\n\t\topen.then((w) => w.reset(abandoned)).catch(() => void 0);\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?: IetfVersion;\n\n\tconstructor(quic: WebTransport, version?: IetfVersion) {\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"]}
package/track.d.ts CHANGED
@@ -10,6 +10,13 @@ import { Timescale, type Timestamp } from "./time";
10
10
  export type { Datagram } from "./datagram";
11
11
  /** Default {@link Info.latencyMax} window (milliseconds) when the publisher does not set one. */
12
12
  export declare const DEFAULT_LATENCY_MAX_MS = 5000;
13
+ /** A position within a track: a group's sequence and a frame's index inside it. */
14
+ export interface Location {
15
+ /** The group's sequence number within the track. */
16
+ group: number;
17
+ /** The frame's index within that group. */
18
+ frame: number;
19
+ }
13
20
  /**
14
21
  * A track's immutable publisher properties, fixed for the lifetime of the track.
15
22
  *
@@ -230,6 +237,27 @@ export declare class Subscriber {
230
237
  get subscription(): Getter<Subscription | undefined>;
231
238
  /** Return the latest group sequence observed on this track, if any. */
232
239
  latest(): number | undefined;
240
+ /**
241
+ * The newest frame this track has produced, or `undefined` while it has none.
242
+ *
243
+ * Read from the groups buffered for this subscriber, so nothing is consumed. A newest
244
+ * group that has no frames yet falls back to the newest older group that does. It
245
+ * reads as `undefined` once the newest group has been evicted or received: what is
246
+ * left can no longer say where the edge is.
247
+ */
248
+ largest(): Location | undefined;
249
+ /**
250
+ * An independent subscriber to the same track, with its own cursor and its own replay of
251
+ * the retained window.
252
+ *
253
+ * Reads here do not consume anything this one would deliver, which is what lets a
254
+ * publisher read the cache alongside the cursor it is serving from. Resolving the track
255
+ * again through the broadcast would not do: a dynamic serve is one request per peer
256
+ * subscription, so that mints a second producer the application has to answer separately.
257
+ *
258
+ * @internal Wire layers only.
259
+ */
260
+ fork(options?: Subscription): Subscriber;
233
261
  /** Start this subscriber's local read cursor at `sequence`, without changing its wire request. */
234
262
  startAt(sequence: number): void;
235
263
  /**
@@ -253,6 +281,16 @@ export declare class Subscriber {
253
281
  * after a clean close, without blocking in-range groups that arrive behind it.
254
282
  */
255
283
  recvGroup(): Promise<GroupConsumer | undefined>;
284
+ /**
285
+ * Take the next buffered group without blocking, honoring the same cursor bounds as
286
+ * {@link recvGroup}.
287
+ *
288
+ * Returns `undefined` when nothing is deliverable right now, which is not by itself the
289
+ * end of the track: a group may still arrive, or one may be parked beyond the
290
+ * {@link endAt} cap. Use it to drain what the retained window already holds, where
291
+ * waiting for a sequence nothing will republish would park forever.
292
+ */
293
+ tryRecvGroup(): GroupConsumer | undefined;
256
294
  /**
257
295
  * Receive the next datagram in arrival order.
258
296
  *
package/track.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAgB,MAAM,cAAc,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,IAAI,aAAa,EAAE,QAAQ,IAAI,aAAa,EAAU,MAAM,YAAY,CAAC;AAE3G,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,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AAgG;IAC1F,QAAQ,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAM7C;IAED;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,YAAY,QAE3B;CACD"}
package/track.js CHANGED
@@ -141,6 +141,8 @@ export class Consumer {
141
141
  // The shared state behind a Producer / Subscriber pair. Package-internal
142
142
  // wiring, unexported so it never appears in the published type declarations.
143
143
  class TrackState {
144
+ /** The producer fanning into this sink, so a subscriber can mint a sibling of itself. */
145
+ producer;
144
146
  groups = new Signal([]);
145
147
  /** Best-effort datagram channel, parallel to {@link groups}; an age-evicted send buffer per subscriber. */
146
148
  datagrams = new Signal([]);
@@ -285,6 +287,7 @@ export class Producer {
285
287
  // the track is open) mirror future groups into it. A late subscriber to a closed
286
288
  // track still drains the buffered groups before seeing the end.
287
289
  #addSink(sink) {
290
+ sink.producer = this;
288
291
  const info = this.#state.info.peek();
289
292
  if (info)
290
293
  sink.info.set(info);
@@ -549,6 +552,46 @@ export class Subscriber {
549
552
  latest() {
550
553
  return this.#state.latest;
551
554
  }
555
+ /**
556
+ * The newest frame this track has produced, or `undefined` while it has none.
557
+ *
558
+ * Read from the groups buffered for this subscriber, so nothing is consumed. A newest
559
+ * group that has no frames yet falls back to the newest older group that does. It
560
+ * reads as `undefined` once the newest group has been evicted or received: what is
561
+ * left can no longer say where the edge is.
562
+ */
563
+ largest() {
564
+ const latest = this.#state.latest;
565
+ if (latest === undefined)
566
+ return undefined;
567
+ const groups = this.#state.groups.peek();
568
+ const newest = groups[groups.length - 1];
569
+ if (!newest || newest.sequence !== latest)
570
+ return undefined;
571
+ for (let i = groups.length - 1; i >= 0; i--) {
572
+ const count = groups[i].frameCount;
573
+ if (count > 0)
574
+ return { group: groups[i].sequence, frame: count - 1 };
575
+ }
576
+ return undefined;
577
+ }
578
+ /**
579
+ * An independent subscriber to the same track, with its own cursor and its own replay of
580
+ * the retained window.
581
+ *
582
+ * Reads here do not consume anything this one would deliver, which is what lets a
583
+ * publisher read the cache alongside the cursor it is serving from. Resolving the track
584
+ * again through the broadcast would not do: a dynamic serve is one request per peer
585
+ * subscription, so that mints a second producer the application has to answer separately.
586
+ *
587
+ * @internal Wire layers only.
588
+ */
589
+ fork(options) {
590
+ const producer = this.#state.producer;
591
+ if (!producer)
592
+ throw new Error("track has no producer to fork from");
593
+ return producer.subscribe(options);
594
+ }
552
595
  /** Start this subscriber's local read cursor at `sequence`, without changing its wire request. */
553
596
  startAt(sequence) {
554
597
  this.#cursor.update((cursor) => ({ ...cursor, start: sequence }));
@@ -588,27 +631,42 @@ export class Subscriber {
588
631
  */
589
632
  async recvGroup() {
590
633
  for (;;) {
591
- const groups = this.#state.groups.peek();
592
- const { start, end } = this.#cursor.peek();
593
- while (groups.length > 0 && groups[0].sequence < start)
594
- groups.shift()?.close();
595
- // The buffer is sequence-sorted, so an in-range group that arrives behind a
596
- // beyond-cap one sorts in front of it and is never blocked by it.
597
- const group = groups[0];
598
- if (group && (end === undefined || group.sequence <= end)) {
599
- groups.shift();
634
+ const group = this.tryRecvGroup();
635
+ if (group)
600
636
  return group;
601
- }
602
637
  const closed = this.#state.closed.peek();
603
638
  if (closed instanceof Error)
604
639
  throw closed;
605
640
  // A group beyond the cap outlives a clean close: it becomes deliverable if
606
641
  // the cap rises, so the track isn't over while any are held.
607
- if (closed !== undefined && !group)
642
+ if (closed !== undefined && !this.#state.groups.peek()[0])
608
643
  return undefined;
609
644
  await Signal.race(this.#state.groups, this.#cursor, this.#state.closed);
610
645
  }
611
646
  }
647
+ /**
648
+ * Take the next buffered group without blocking, honoring the same cursor bounds as
649
+ * {@link recvGroup}.
650
+ *
651
+ * Returns `undefined` when nothing is deliverable right now, which is not by itself the
652
+ * end of the track: a group may still arrive, or one may be parked beyond the
653
+ * {@link endAt} cap. Use it to drain what the retained window already holds, where
654
+ * waiting for a sequence nothing will republish would park forever.
655
+ */
656
+ tryRecvGroup() {
657
+ const groups = this.#state.groups.peek();
658
+ const { start, end } = this.#cursor.peek();
659
+ while (groups.length > 0 && groups[0].sequence < start)
660
+ groups.shift()?.close();
661
+ // The buffer is sequence-sorted, so an in-range group that arrives behind a
662
+ // beyond-cap one sorts in front of it and is never blocked by it.
663
+ const group = groups[0];
664
+ if (group && (end === undefined || group.sequence <= end)) {
665
+ groups.shift();
666
+ return group;
667
+ }
668
+ return undefined;
669
+ }
612
670
  /**
613
671
  * Receive the next datagram in arrival order.
614
672
  *