@norskvideo/moq-net 0.1.3 → 0.1.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.
- package/README.md +1 -0
- package/announced.d.ts +111 -21
- package/announced.d.ts.map +1 -1
- package/announced.js +213 -40
- package/announced.js.map +1 -1
- package/broadcast.d.ts +80 -25
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +270 -49
- package/broadcast.js.map +1 -1
- package/connection/accept.d.ts +6 -0
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +42 -13
- package/connection/accept.js.map +1 -1
- package/connection/browser.d.ts +5 -0
- package/connection/browser.d.ts.map +1 -0
- package/connection/browser.js +31 -0
- package/connection/browser.js.map +1 -0
- package/connection/connect.d.ts +43 -1
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +118 -123
- package/connection/connect.js.map +1 -1
- package/connection/established.d.ts +43 -16
- package/connection/established.d.ts.map +1 -1
- package/connection/established.js.map +1 -1
- package/connection/handshake.d.ts +12 -1
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +30 -14
- package/connection/handshake.js.map +1 -1
- package/connection/index.d.ts +8 -0
- package/connection/index.d.ts.map +1 -1
- package/connection/index.js +6 -0
- package/connection/index.js.map +1 -1
- package/connection/reload.d.ts +66 -9
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +192 -66
- package/connection/reload.js.map +1 -1
- package/connection/stats.d.ts +92 -0
- package/connection/stats.d.ts.map +1 -0
- package/connection/stats.js +35 -0
- package/connection/stats.js.map +1 -0
- package/connection/transport.d.ts +10 -0
- package/connection/transport.d.ts.map +1 -0
- package/connection/transport.js +12 -0
- package/connection/transport.js.map +1 -0
- package/consume.d.ts +44 -0
- package/consume.d.ts.map +1 -0
- package/consume.js +60 -0
- package/consume.js.map +1 -0
- package/datagram.d.ts +23 -0
- package/datagram.d.ts.map +1 -0
- package/datagram.js +3 -0
- package/datagram.js.map +1 -0
- package/error.d.ts +76 -0
- package/error.d.ts.map +1 -0
- package/error.js +107 -0
- package/error.js.map +1 -0
- package/group.d.ts +143 -38
- package/group.d.ts.map +1 -1
- package/group.js +270 -68
- package/group.js.map +1 -1
- package/ietf/adapter.d.ts +2 -2
- package/ietf/adapter.d.ts.map +1 -1
- package/ietf/adapter.js +20 -10
- package/ietf/adapter.js.map +1 -1
- package/ietf/aliases.d.ts +73 -5
- package/ietf/aliases.d.ts.map +1 -1
- package/ietf/aliases.js +121 -14
- package/ietf/aliases.js.map +1 -1
- package/ietf/cluster.d.ts +141 -0
- package/ietf/cluster.d.ts.map +1 -0
- package/ietf/cluster.js +204 -0
- package/ietf/cluster.js.map +1 -0
- package/ietf/connection.d.ts +39 -6
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +73 -12
- package/ietf/connection.js.map +1 -1
- package/ietf/fetch.d.ts +17 -0
- package/ietf/fetch.d.ts.map +1 -1
- package/ietf/fetch.js +21 -0
- package/ietf/fetch.js.map +1 -1
- package/ietf/filter.d.ts +87 -0
- package/ietf/filter.d.ts.map +1 -0
- package/ietf/filter.js +292 -0
- package/ietf/filter.js.map +1 -0
- package/ietf/index.d.ts +2 -0
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +3 -0
- package/ietf/index.js.map +1 -1
- package/ietf/namespace.d.ts +6 -0
- package/ietf/namespace.d.ts.map +1 -1
- package/ietf/namespace.js +27 -2
- package/ietf/namespace.js.map +1 -1
- package/ietf/object.d.ts +54 -6
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +178 -25
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +35 -10
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +236 -45
- package/ietf/parameters.js.map +1 -1
- package/ietf/priority.d.ts +5 -0
- package/ietf/priority.d.ts.map +1 -0
- package/ietf/priority.js +10 -0
- package/ietf/priority.js.map +1 -0
- package/ietf/properties.d.ts +13 -2
- package/ietf/properties.d.ts.map +1 -1
- package/ietf/properties.js +65 -8
- package/ietf/properties.js.map +1 -1
- package/ietf/publish.d.ts.map +1 -1
- package/ietf/publish.js +13 -3
- package/ietf/publish.js.map +1 -1
- package/ietf/publish_namespace.d.ts +16 -2
- package/ietf/publish_namespace.d.ts.map +1 -1
- package/ietf/publish_namespace.js +25 -6
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.d.ts +40 -7
- package/ietf/publisher.d.ts.map +1 -1
- package/ietf/publisher.js +751 -134
- package/ietf/publisher.js.map +1 -1
- package/ietf/request.js +1 -1
- package/ietf/request.js.map +1 -1
- package/ietf/solicit.d.ts +41 -0
- package/ietf/solicit.d.ts.map +1 -0
- package/ietf/solicit.js +47 -0
- package/ietf/solicit.js.map +1 -0
- package/ietf/subscribe.d.ts +41 -2
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +103 -22
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts +21 -7
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +31 -14
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.d.ts +20 -7
- package/ietf/subscriber.d.ts.map +1 -1
- package/ietf/subscriber.js +512 -142
- package/ietf/subscriber.js.map +1 -1
- package/ietf/version.d.ts +7 -1
- package/ietf/version.d.ts.map +1 -1
- package/ietf/version.js +7 -0
- package/ietf/version.js.map +1 -1
- package/index.d.ts +10 -5
- package/index.d.ts.map +1 -1
- package/index.js +10 -5
- package/index.js.map +1 -1
- package/internal.d.ts +29 -0
- package/internal.d.ts.map +1 -0
- package/internal.js +8 -0
- package/internal.js.map +1 -0
- package/lite/announce.d.ts +62 -15
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +230 -94
- package/lite/announce.js.map +1 -1
- package/lite/connection.d.ts +69 -20
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +128 -81
- package/lite/connection.js.map +1 -1
- package/lite/datagram.d.ts +23 -0
- package/lite/datagram.d.ts.map +1 -0
- package/lite/datagram.js +57 -0
- package/lite/datagram.js.map +1 -0
- package/lite/datagram_stream.d.ts +8 -0
- package/lite/datagram_stream.d.ts.map +1 -0
- package/lite/datagram_stream.js +44 -0
- package/lite/datagram_stream.js.map +1 -0
- package/lite/fetch.d.ts.map +1 -1
- package/lite/fetch.js +2 -2
- package/lite/fetch.js.map +1 -1
- package/lite/index.d.ts +3 -0
- package/lite/index.d.ts.map +1 -1
- package/lite/index.js +3 -0
- package/lite/index.js.map +1 -1
- package/lite/priority.d.ts +67 -0
- package/lite/priority.d.ts.map +1 -0
- package/lite/priority.js +114 -0
- package/lite/priority.js.map +1 -0
- package/lite/probe.d.ts +18 -2
- package/lite/probe.d.ts.map +1 -1
- package/lite/probe.js +24 -22
- package/lite/probe.js.map +1 -1
- package/lite/publisher.d.ts +14 -7
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +406 -84
- package/lite/publisher.js.map +1 -1
- package/lite/setup.d.ts +83 -6
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +203 -31
- package/lite/setup.js.map +1 -1
- package/lite/stream.d.ts +12 -3
- package/lite/stream.d.ts.map +1 -1
- package/lite/stream.js +7 -4
- package/lite/stream.js.map +1 -1
- package/lite/subscribe.d.ts +37 -23
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +70 -55
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts +29 -23
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +689 -112
- package/lite/subscriber.js.map +1 -1
- package/lite/track.d.ts +25 -13
- package/lite/track.d.ts.map +1 -1
- package/lite/track.js +60 -35
- package/lite/track.js.map +1 -1
- package/lite/version.d.ts +39 -4
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +139 -17
- package/lite/version.js.map +1 -1
- package/mock.d.ts +53 -3
- package/mock.d.ts.map +1 -1
- package/mock.js +110 -21
- package/mock.js.map +1 -1
- package/{lite/origin.d.ts → origin.d.ts} +25 -1
- package/origin.d.ts.map +1 -0
- package/{lite/origin.js → origin.js} +25 -1
- package/origin.js.map +1 -0
- package/package.json +6 -4
- package/path.d.ts +67 -0
- package/path.d.ts.map +1 -1
- package/path.js +128 -0
- package/path.js.map +1 -1
- package/stream.d.ts +94 -4
- package/stream.d.ts.map +1 -1
- package/stream.js +128 -17
- package/stream.js.map +1 -1
- package/time.d.ts +109 -86
- package/time.d.ts.map +1 -1
- package/time.js +80 -30
- package/time.js.map +1 -1
- package/track.d.ts +298 -47
- package/track.d.ts.map +1 -1
- package/track.js +721 -109
- package/track.js.map +1 -1
- package/util/timeout.d.ts +5 -0
- package/util/timeout.d.ts.map +1 -0
- package/util/timeout.js +18 -0
- package/util/timeout.js.map +1 -0
- package/util/utf8.d.ts +3 -0
- package/util/utf8.d.ts.map +1 -0
- package/util/utf8.js +7 -0
- package/util/utf8.js.map +1 -0
- package/varint.d.ts +14 -3
- package/varint.d.ts.map +1 -1
- package/varint.js +23 -12
- package/varint.js.map +1 -1
- package/zod.d.ts +5 -5
- package/zod.d.ts.map +1 -1
- package/zod.js.map +1 -1
- package/bandwidth.d.ts +0 -11
- package/bandwidth.d.ts.map +0 -1
- package/bandwidth.js +0 -7
- package/bandwidth.js.map +0 -1
- package/connection/cert.test.d.ts +0 -2
- package/connection/cert.test.d.ts.map +0 -1
- package/connection/cert.test.js +0 -26
- package/connection/cert.test.js.map +0 -1
- package/connection/reload.test.d.ts +0 -2
- package/connection/reload.test.d.ts.map +0 -1
- package/connection/reload.test.js +0 -39
- package/connection/reload.test.js.map +0 -1
- package/group.test.d.ts +0 -2
- package/group.test.d.ts.map +0 -1
- package/group.test.js +0 -66
- package/group.test.js.map +0 -1
- package/ietf/aliases.test.d.ts +0 -2
- package/ietf/aliases.test.d.ts.map +0 -1
- package/ietf/aliases.test.js +0 -30
- package/ietf/aliases.test.js.map +0 -1
- package/ietf/ietf.test.d.ts +0 -2
- package/ietf/ietf.test.d.ts.map +0 -1
- package/ietf/ietf.test.js +0 -873
- package/ietf/ietf.test.js.map +0 -1
- package/integration.test.d.ts +0 -2
- package/integration.test.d.ts.map +0 -1
- package/integration.test.js +0 -90
- package/integration.test.js.map +0 -1
- package/lite/origin.d.ts.map +0 -1
- package/lite/origin.js.map +0 -1
- package/lite/subscriber.test.d.ts +0 -2
- package/lite/subscriber.test.d.ts.map +0 -1
- package/lite/subscriber.test.js +0 -30
- package/lite/subscriber.test.js.map +0 -1
- package/lite/track.test.d.ts +0 -2
- package/lite/track.test.d.ts.map +0 -1
- package/lite/track.test.js +0 -53
- package/lite/track.test.js.map +0 -1
- package/path.test.d.ts +0 -2
- package/path.test.d.ts.map +0 -1
- package/path.test.js +0 -169
- package/path.test.js.map +0 -1
- package/stream.test.d.ts +0 -2
- package/stream.test.d.ts.map +0 -1
- package/stream.test.js +0 -210
- package/stream.test.js.map +0 -1
- package/track.test.d.ts +0 -2
- package/track.test.d.ts.map +0 -1
- package/track.test.js +0 -56
- package/track.test.js.map +0 -1
- package/util/error.d.ts +0 -3
- package/util/error.d.ts.map +0 -1
- package/util/error.js +0 -9
- package/util/error.js.map +0 -1
- package/util/index.d.ts +0 -2
- package/util/index.d.ts.map +0 -1
- package/util/index.js +0 -3
- package/util/index.js.map +0 -1
- package/varint.test.d.ts +0 -2
- package/varint.test.d.ts.map +0 -1
- package/varint.test.js +0 -106
- package/varint.test.js.map +0 -1
package/track.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"track.js","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,iHAAiH;AACjH,MAAM,OAAO,UAAU;IACtB,MAAM,GAAG,IAAI,MAAM,CAAU,EAAE,CAAC,CAAC;IACjC,MAAM,GAAG,IAAI,MAAM,CAAkB,KAAK,CAAC,CAAC;IAC5C,QAAQ,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KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,gGAAgG;IAChG,KAAK,CAAC,QAAQ;QACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,IAAI,IAAI,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACtG,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,QAAgB;QAC9B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAa;QAClB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;QAErC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9C,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;CACD","sourcesContent":["import { Signal } from \"@moq/signals\";\nimport { Group } from \"./group.ts\";\n\n/** Reactive backing state for a {@link Track}: buffered groups, a closed flag, and the subscription priority. */\nexport class TrackState {\n\tgroups = new Signal<Group[]>([]);\n\tclosed = new Signal<boolean | Error>(false);\n\tpriority = new Signal<number | undefined>(undefined);\n}\n\n/** A live stream of groups within a broadcast, identified by name. */\nexport class Track {\n\t/** Name of this track within its broadcast. */\n\treadonly name: string;\n\n\t/** Reactive backing state. */\n\tstate = new TrackState();\n\t#next?: number;\n\t#nextSequence = 0;\n\n\t/** Resolves with the abort error (or undefined) once closed. */\n\treadonly closed: Promise<Error | undefined>;\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\n\t\tthis.closed = new Promise((resolve) => {\n\t\t\tconst dispose = this.state.closed.subscribe((closed) => {\n\t\t\t\tif (!closed) return;\n\t\t\t\tresolve(closed instanceof Error ? closed : undefined);\n\t\t\t\tdispose();\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Appends a new group to the track.\n\t * @returns A GroupProducer for the new group\n\t */\n\tappendGroup(): Group {\n\t\tif (this.state.closed.peek()) throw new Error(\"track is closed\");\n\n\t\tconst group = new Group(this.#next ?? 0);\n\n\t\tthis.#next = group.sequence + 1;\n\t\tthis.state.groups.mutate((groups) => {\n\t\t\tgroups.push(group);\n\t\t\tgroups.sort((a, b) => a.sequence - b.sequence);\n\t\t});\n\n\t\treturn group;\n\t}\n\n\t/**\n\t * Inserts an existing group into the track.\n\t * @param group - The group to insert\n\t */\n\twriteGroup(group: Group) {\n\t\tif (this.state.closed.peek()) throw new Error(\"track is closed\");\n\n\t\t// Only advance #next upward (for appendGroup auto-increment).\n\t\tif (group.sequence >= (this.#next ?? 0)) {\n\t\t\tthis.#next = group.sequence + 1;\n\t\t}\n\n\t\tthis.state.groups.mutate((groups) => {\n\t\t\tgroups.push(group);\n\t\t\tgroups.sort((a, b) => a.sequence - b.sequence);\n\t\t});\n\t}\n\n\t/**\n\t * Appends a frame to the track in its own group.\n\t *\n\t * @param frame - The frame to append\n\t */\n\twriteFrame(frame: Uint8Array) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeFrame(frame);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a string to the track as its own single-frame group. */\n\twriteString(str: string) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeString(str);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a JSON value to the track as its own single-frame group. */\n\twriteJson(json: unknown) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeJson(json);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a boolean to the track as its own single-frame group. */\n\twriteBool(bool: boolean) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeBool(bool);\n\t\tgroup.close();\n\t}\n\n\t/**\n\t * Receive the next group available on this track, in arrival order.\n\t *\n\t * Groups may arrive out of order or with gaps due to network conditions.\n\t * Use {@link nextGroupOrdered} if you need groups in sequence order,\n\t * skipping those that arrive too late.\n\t */\n\tasync recvGroup(): Promise<Group | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.state.groups.peek();\n\t\t\tif (groups.length > 0) {\n\t\t\t\treturn groups.shift();\n\t\t\t}\n\n\t\t\tconst closed = this.state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed) return undefined;\n\n\t\t\tawait Signal.race(this.state.groups, this.state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * @deprecated Use {@link recvGroup} for arrival order, or {@link nextGroupOrdered} for sequence order.\n\t */\n\tasync nextGroup(): Promise<Group | undefined> {\n\t\treturn this.recvGroup();\n\t}\n\n\t/**\n\t * Return the next group with a strictly-greater sequence number than the last returned.\n\t *\n\t * Late arrivals (with a sequence number at or below the last one returned) are silently skipped.\n\t *\n\t * NOTE: This will be renamed to `nextGroup` in the next major version.\n\t */\n\tasync nextGroupOrdered(): Promise<Group | undefined> {\n\t\tfor (;;) {\n\t\t\tconst group = await this.recvGroup();\n\t\t\tif (!group) return undefined;\n\t\t\tif (group.sequence < this.#nextSequence) {\n\t\t\t\tgroup.close();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#nextSequence = group.sequence + 1;\n\t\t\treturn group;\n\t\t}\n\t}\n\n\t/** Reads the next frame across all groups, discarding older groups. */\n\tasync readFrame(): Promise<Uint8Array | undefined> {\n\t\treturn (await this.readFrameSequence())?.data;\n\t}\n\n\t/** Reads the next frame along with its group and frame sequence numbers. */\n\tasync readFrameSequence(): Promise<{ group: number; frame: number; data: Uint8Array } | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.state.groups.peek();\n\n\t\t\t// Discard old groups.\n\t\t\twhile (groups.length > 1) {\n\t\t\t\tconst next = groups[0].tryReadFrameSequence();\n\t\t\t\tif (next) {\n\t\t\t\t\treturn { group: groups[0].sequence, frame: next.sequence, data: next.data };\n\t\t\t\t}\n\n\t\t\t\t// Skip this old group\n\t\t\t\tgroups.shift()?.close();\n\t\t\t}\n\n\t\t\t// If there's no groups, wait for a new one.\n\t\t\tif (groups.length === 0) {\n\t\t\t\tconst closed = this.state.closed.peek();\n\t\t\t\tif (closed instanceof Error) throw closed;\n\t\t\t\tif (closed) return undefined;\n\n\t\t\t\tawait Signal.race(this.state.groups, this.state.closed);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// If there's a group, wait for a frame.\n\t\t\tconst group = groups[0];\n\t\t\tconst next = group.tryReadFrameSequence();\n\t\t\tif (next) {\n\t\t\t\treturn { group: group.sequence, frame: next.sequence, data: next.data };\n\t\t\t}\n\n\t\t\t// If the track is closed, return undefined.\n\t\t\tconst closed = this.state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed) return undefined;\n\n\t\t\t// Wake on a new group or the track closing. Only fold in the current group's readability\n\t\t\t// while it can still deliver frames: a finished group's readable() resolves immediately, so\n\t\t\t// racing it would busy-loop until a newer group arrives instead of waiting.\n\t\t\tif (group.done) {\n\t\t\t\tawait Signal.race(this.state.groups, this.state.closed);\n\t\t\t} else {\n\t\t\t\tawait Promise.race([Signal.race(this.state.groups, this.state.closed), group.readable()]);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Reads the next frame and decodes it as a UTF-8 string. */\n\tasync readString(): Promise<string | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\treturn new TextDecoder().decode(next);\n\t}\n\n\t/** Reads the next frame and parses it as JSON. */\n\tasync readJson(): Promise<unknown | undefined> {\n\t\tconst next = await this.readString();\n\t\tif (!next) return undefined;\n\t\treturn JSON.parse(next);\n\t}\n\n\t/** Reads the next frame and decodes it as a one-byte boolean, throwing on a malformed frame. */\n\tasync readBool(): Promise<boolean | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\tif (next.byteLength !== 1 || !(next[0] === 0 || next[0] === 1)) throw new Error(\"invalid bool frame\");\n\t\treturn next[0] === 1;\n\t}\n\n\t/**\n\t * Update the subscription priority. Triggers a SUBSCRIBE_UPDATE\n\t * to the publisher when used on a subscribed track.\n\t */\n\tupdatePriority(priority: number) {\n\t\tthis.state.priority.set(priority, true);\n\t}\n\n\t/**\n\t * Closes the publisher and all associated groups.\n\t */\n\tclose(abort?: Error) {\n\t\tthis.state.closed.set(abort ?? true);\n\n\t\tfor (const group of this.state.groups.peek()) {\n\t\t\tgroup.close(abort);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"track.js","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAA8C,QAAQ,IAAI,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,KAAK,EAAqE,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,SAAS,EAAkB,MAAM,WAAW,CAAC;AAItD,iGAAiG;AACjG,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAK/B;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAuCjC,iEAAiE;AACjE,MAAM,UAAU,YAAY,CAAC,IAAI,GAAkB,EAAE;IACpD,OAAO;QACN,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,KAAK;QAC5C,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,sBAAsB;QACrD,QAAQ,EAAE,IAAI,CAAC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GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,kDAAkD;IAClD,KAAK,CAAC,QAAQ;QACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,gGAAgG;IAChG,KAAK,CAAC,QAAQ;QACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,OAAO,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC/G,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAqB;QAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC;CACD","sourcesContent":["/**\n * Track role handles: a live stream of groups (and best-effort datagrams) within a broadcast.\n *\n * @module\n */\nimport { type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport type { Datagram } from \"./datagram.ts\";\nimport { type Frame, type Consumer as GroupConsumer, Producer as GroupProducer, Lagged } from \"./group.ts\";\nimport { hooks, type TrackRequestOptions, type TrackSequence, type TrackSequences } from \"./internal.ts\";\nimport { Timescale, type Timestamp } from \"./time.ts\";\n\nexport type { Datagram } from \"./datagram.ts\";\n\n/** Default {@link Info.latencyMax} window (milliseconds) when the publisher does not set one. */\nexport const DEFAULT_LATENCY_MAX_MS = 5000;\n\n/**\n * How long (milliseconds) a datagram stays in the per-subscriber buffer before it is dropped.\n *\n * Datagrams are a best-effort send buffer, not a replay cache (unlike groups): only the last few\n * tens of milliseconds are kept, so a consumer that stalls loses stale datagrams instead of\n * replaying them. Mirrors the Rust `MAX_DATAGRAM_AGE`.\n */\nconst MAX_DATAGRAM_AGE_MS = 50;\n\n/** A datagram buffered with its arrival time, so the send buffer can evict by age. */\ntype BufferedDatagram = { datagram: Datagram; time: number };\n\n/**\n * Sanity cap on a datagram payload: the QUIC DATAGRAM frame ceiling. The real limit is\n * per-hop (the negotiated transport datagram size minus a small header) and oversize\n * datagrams are dropped there; a payload above this cap could never fit anywhere.\n */\nconst MAX_DATAGRAM_BYTES = 65535;\n\n/** A position within a track: a group's sequence and a frame's index inside it. */\nexport interface Location {\n\t/** The group's sequence number within the track. */\n\tgroup: number;\n\t/** The frame's index within that group. */\n\tframe: number;\n}\n\n/**\n * A track's immutable publisher properties, fixed for the lifetime of the track.\n *\n * A producer declares these once (via {@link Request.accept} or\n * {@link Producer.accept}); a consumer awaits them via {@link Subscriber.info}\n * (resolved from the wire TRACK_INFO on lite-05+). They map 1:1 onto TRACK_INFO.\n */\nexport interface Info {\n\t/**\n\t * Units per second for this track's frame timestamps (reported in TRACK_INFO on\n\t * Lite05+). Defaults to milliseconds; set it finer (e.g. {@link Timescale.MICRO})\n\t * for media that needs sub-millisecond timing.\n\t */\n\ttimescale: Timescale;\n\t/**\n\t * Publisher Max Latency: the maximum age (milliseconds) of a non-latest group before\n\t * the publisher evicts it. Reported in TRACK_INFO (Lite05+) so relays re-serve with the\n\t * same bound. The publisher-side half of the budget a subscriber sets for itself.\n\t */\n\tlatencyMax: number;\n\t/** Tie-break priority between subscriptions of equal subscriber priority. */\n\tpriority: number;\n\t/**\n\t * Whether groups are prioritized in sequence order. Groups may always arrive\n\t * out-of-order (or not at all) over the network. Defaults to `false` (newest-first).\n\t */\n\tordered: boolean;\n}\n\n/** Fill in any unset {@link Info} fields with their defaults. */\nexport function infoDefaults(info: Partial<Info> = {}): Info {\n\treturn {\n\t\ttimescale: info.timescale ?? Timescale.MILLI,\n\t\tlatencyMax: info.latencyMax ?? DEFAULT_LATENCY_MAX_MS,\n\t\tpriority: info.priority ?? 0,\n\t\tordered: info.ordered ?? false,\n\t};\n}\n\n/**\n * Per-subscription options, requested when a subscription opens and adjustable later via\n * {@link Subscriber.update}. Mirrors the Rust `Subscription`.\n */\nexport interface Subscription {\n\t/** Delivery priority relative to this session's other subscriptions. Defaults to `0`. */\n\tpriority?: number;\n\t/** Whether groups are prioritized in sequence order. Defaults to `false` (newest-first). */\n\tordered?: boolean;\n\t/** Maximum age (milliseconds) of a non-latest group before it is skipped. Defaults to `0`. */\n\tlatencyMax?: number;\n\t/** First group the publisher should deliver, or omit to start at the latest group. */\n\tstartGroup?: number;\n\t/** Last group the publisher should deliver (inclusive), or omit for no end. */\n\tendGroup?: number;\n}\n\n// Materialize the defaults at the model boundary so every layer observes a complete\n// subscription rather than interpreting an omitted field differently.\nfunction subscriptionDefaults(subscription: Subscription = {}): Subscription {\n\treturn {\n\t\tpriority: subscription.priority ?? 0,\n\t\tordered: subscription.ordered ?? false,\n\t\tlatencyMax: subscription.latencyMax ?? 0,\n\t\tstartGroup: subscription.startGroup,\n\t\tendGroup: subscription.endGroup,\n\t};\n}\n\n// Aggregate the preferences of every live subscriber, matching Rust's Subscription::poll_combined.\nfunction combineSubscriptions(states: Iterable<TrackState>): Subscription | undefined {\n\tlet combined: Subscription | undefined;\n\tfor (const state of states) {\n\t\tconst subscription = state.update.peek();\n\t\tif (!subscription) continue;\n\t\tif (!combined) {\n\t\t\tcombined = { ...subscription };\n\t\t\tcontinue;\n\t\t}\n\n\t\tcombined.priority = Math.max(combined.priority ?? 0, subscription.priority ?? 0);\n\t\tcombined.ordered = (combined.ordered ?? false) && (subscription.ordered ?? false);\n\t\tcombined.latencyMax = Math.max(combined.latencyMax ?? 0, subscription.latencyMax ?? 0);\n\n\t\tif (subscription.startGroup !== undefined) {\n\t\t\tcombined.startGroup =\n\t\t\t\tcombined.startGroup === undefined\n\t\t\t\t\t? subscription.startGroup\n\t\t\t\t\t: Math.min(combined.startGroup, subscription.startGroup);\n\t\t}\n\n\t\tif (combined.endGroup === undefined || subscription.endGroup === undefined) {\n\t\t\tcombined.endGroup = undefined;\n\t\t} else {\n\t\t\tcombined.endGroup = Math.max(combined.endGroup, subscription.endGroup);\n\t\t}\n\t}\n\treturn combined;\n}\n\n/**\n * A request for a track the peer wants, yielded by `Broadcast.Producer.requested`.\n *\n * Created internally by the broadcast when a subscription (or info lookup) needs a track\n * served; answer it with {@link accept} or {@link reject}.\n *\n * @public\n */\nexport class Request {\n\t/** The requested track name. */\n\treadonly name: string;\n\n\t#producer: Producer;\n\t#sequences: TrackSequences;\n\n\tprivate constructor(options: TrackRequestOptions) {\n\t\tthis.name = options.name;\n\t\tthis.#producer = options.producer;\n\t\tthis.#sequences = options.sequences;\n\t}\n\n\tstatic {\n\t\thooks.makeRequest = (options) => new Request(options);\n\t}\n\n\t/** The aggregate subscription requested for this track. */\n\tget subscription(): Readonly<Subscription> {\n\t\treturn this.#producer.subscription.peek() ?? subscriptionDefaults();\n\t}\n\n\t/** The subscriber's priority for this track. */\n\tget priority(): number {\n\t\treturn this.subscription.priority ?? 0;\n\t}\n\n\t/** Accept the request, committing the track's immutable {@link Info}. */\n\taccept(info: Partial<Info> = {}): Producer {\n\t\tbindProducer(this.name, this.#producer, this.#sequences);\n\t\treturn this.#producer.accept(info);\n\t}\n\n\t/** Reject the request, closing the track optionally with an error. */\n\treject(err?: Error): void {\n\t\tthis.#producer.close(err);\n\t}\n}\n\n/** Options for {@link Consumer.fetchGroup}. */\nexport interface FetchGroupOptions {\n\t/** Delivery priority for the fetch stream. Defaults to `0`. */\n\tpriority?: number;\n}\n\n/**\n * The per-track operations a lazy {@link Consumer} delegates to the broadcast it came from.\n *\n * Implemented by `broadcast.Producer` / `broadcast.Consumer` (and the wire-layer subclasses\n * that resolve them over the network), so a track handle holds a reference to its broadcast\n * and calls methods on it rather than capturing a bag of callbacks.\n */\nexport interface Broadcast {\n\t/** Open a live subscription to the named track. */\n\tsubscribe(name: string, options?: Subscription): Subscriber;\n\t/** Resolve the named track's immutable info. */\n\tresolveTrackInfo(name: string): Promise<Info>;\n\t/** Fetch a single group of the named track by sequence. */\n\tfetchGroup(name: string, sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer>;\n}\n\n/**\n * A lazy handle to a track on a consumed broadcast.\n *\n * @public\n */\nexport class Consumer {\n\t/** The track name. */\n\treadonly name: string;\n\n\t#broadcast: Broadcast;\n\n\tconstructor(name: string, broadcast: Broadcast) {\n\t\tthis.name = name;\n\t\tthis.#broadcast = broadcast;\n\t}\n\n\t/** Open a live subscription to the track. */\n\tsubscribe(options?: Subscription): Subscriber {\n\t\treturn this.#broadcast.subscribe(this.name, options);\n\t}\n\n\t/** Fetch the track's immutable publisher properties without subscribing. */\n\tinfo(): Promise<Info> {\n\t\treturn this.#broadcast.resolveTrackInfo(this.name);\n\t}\n\n\t/** Fetch a single group by sequence without holding a live subscription. */\n\tfetchGroup(sequence: number, options?: FetchGroupOptions): Promise<GroupConsumer> {\n\t\treturn this.#broadcast.fetchGroup(this.name, sequence, options);\n\t}\n}\n\n// The shared state behind a Producer / Subscriber pair. Package-internal\n// wiring, unexported so it never appears in the published type declarations.\nclass TrackState {\n\t/** The producer fanning into this sink, so a subscriber can mint a sibling of itself. */\n\tproducer?: Producer;\n\tgroups = new Signal<GroupConsumer[]>([]);\n\t/** Best-effort datagram channel, parallel to {@link groups}; an age-evicted send buffer per subscriber. */\n\tdatagrams = new Signal<BufferedDatagram[]>([]);\n\tlatest?: number;\n\tclosed = new Once<Error | null>();\n\tupdate: Signal<Subscription | undefined>;\n\t/** Resolved once the producer commits the immutable properties. */\n\tinfo = new Signal<Info | undefined>(undefined);\n\n\tconstructor(subscription?: Subscription) {\n\t\tthis.update = new Signal(subscription === undefined ? undefined : subscriptionDefaults(subscription));\n\t}\n}\n\n// Settle a track state's closed Once. Idempotent: Once.set throws on a second settle, and a\n// Producer closing its sinks races the Subscriber closing itself (the sink is only removed from\n// #sinks a microtask later, via the closed subscription below).\nfunction closeTrackState(state: TrackState, abort?: Error): boolean {\n\tif (state.closed.peek() !== undefined) return false;\n\tstate.closed.set(abort ?? null);\n\treturn true;\n}\n\n// Resolve the track's immutable publisher properties, or reject if it closes first.\n// On a producer this resolves once info is committed (at accept time); on a consumer\n// once the wire layer commits the TRACK_INFO it received (lite-05+) or defaults (older\n// drafts), so awaiting it never yields a placeholder.\nasync function resolveInfo(state: TrackState): Promise<Info> {\n\tfor (;;) {\n\t\tconst info = state.info.peek();\n\t\tif (info) return info;\n\n\t\tconst closed = state.closed.peek();\n\t\tif (closed instanceof Error) throw closed;\n\t\tif (closed !== undefined) throw new Error(\"track closed before info was known\");\n\n\t\tawait Signal.race(state.info, state.closed);\n\t}\n}\n\n// A source group retained in the producer cache, with the mirror handed to each sink\n// so eviction can drop them together.\ntype CachedGroup = { group: GroupProducer; time: number; mirrors: Map<TrackState, GroupConsumer> };\n\nfunction bindProducer(name: string, producer: Producer, sequences: TrackSequences): void {\n\tlet shared = sequences.get(name);\n\tif (!shared) {\n\t\tshared = { next: 0 };\n\t\tsequences.set(name, shared);\n\t}\n\tbindProducerSequence(producer, shared);\n}\n\nlet bindProducerSequence: (producer: Producer, sequence: TrackSequence) => void;\n\n// Constructs a Subscriber from within this module without exposing a public\n// constructor that would leak the unexported TrackState. Assigned in the class's\n// static block.\nlet makeSubscriber: (name: string, state: TrackState) => Subscriber;\n\n/**\n * The write side of a track, mirroring the Rust `Producer`.\n *\n * A producer is a fan-out source: every {@link subscribe} (including each wire\n * subscription the publisher serves from it) gets an independent\n * {@link Subscriber} that receives a full copy of the groups, each with its own\n * read cursor. Groups are mirrored into every live subscriber and retained for the\n * track's `latencyMax` window so a late subscriber replays the recent groups.\n *\n * Obtained from {@link Request.accept} (the wire asks the application for a track to\n * serve) or constructed directly for an in-process track.\n */\nexport class Producer {\n\t/** The track name. */\n\treadonly name: string;\n\n\t// The producer's own state is the source of truth (info/closed); subscribers\n\t// read mirrored sinks, never this state directly.\n\t#state = new TrackState();\n\t#sequence: TrackSequence = { next: 0 };\n\n\t// Recently written source groups, retained for replay to late subscribers and\n\t// pruned once closed and older than the cache window. Each entry tracks the mirror\n\t// it handed to every sink so eviction can drop them too: otherwise a slow consumer\n\t// that never reads would pin old groups (and their frame bytes) forever.\n\t#cache: CachedGroup[] = [];\n\n\t// One independent downstream state per live subscriber.\n\t#sinks = new Set<TrackState>();\n\n\t// Whether any subscriber is currently attached. Exposed as {@link used}; the consumer wire\n\t// watches it to tear down an idle upstream, and a publisher can watch it for on-demand capture.\n\t#used = new Signal<boolean>(false);\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\t}\n\n\tstatic {\n\t\tbindProducerSequence = (producer, sequence) => {\n\t\t\tproducer.#sequence = sequence;\n\t\t};\n\t}\n\n\t/**\n\t * Resolve this track's immutable publisher properties, committed at accept time.\n\t * Rejects if the track is closed before the properties are known.\n\t */\n\tinfo(): Promise<Info> {\n\t\treturn resolveInfo(this.#state);\n\t}\n\n\t/**\n\t * Settles once the track closes: `null` on a clean close, or the abort {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/**\n\t * The aggregate subscription across live subscribers, or `undefined` when there are none.\n\t * The wire layer watches this to emit SUBSCRIBE_UPDATE.\n\t */\n\tget subscription(): Getter<Subscription | undefined> {\n\t\treturn this.#state.update;\n\t}\n\n\t/** Commit the immutable publisher properties, resolving {@link info}. Returns `this`. */\n\taccept(info: Partial<Info> = {}): this {\n\t\tconst resolved = infoDefaults(info);\n\t\tthis.#state.info.set(resolved);\n\t\t// Propagate to any sink handed out before accept (the on-demand path).\n\t\tfor (const sink of this.#sinks) sink.info.set(resolved);\n\t\treturn this;\n\t}\n\n\t/** An independent {@link Subscriber} receiving a full copy of this track's groups. */\n\tsubscribe(options: Subscription = {}): Subscriber {\n\t\tconst sink = new TrackState(options);\n\t\tthis.#addSink(sink);\n\t\treturn makeSubscriber(this.name, sink);\n\t}\n\n\t/**\n\t * Whether the track currently has any subscribers.\n\t *\n\t * Watch it (`effect.get` / `.peek()`) to drive on-demand work: a publisher can start and stop\n\t * capture with demand, and the consumer wire watches it to tear an idle upstream subscription\n\t * down instead of downloading to nobody. Pairs with {@link unused}. Mirrors the Rust `Demand`.\n\t */\n\tget used(): Getter<boolean> {\n\t\treturn this.#used;\n\t}\n\n\t/** Resolves once the track has no subscribers (or has closed). Await it to react to demand ending. */\n\tasync unused(): Promise<void> {\n\t\twhile (this.#used.peek() && this.#state.closed.peek() === undefined) {\n\t\t\tawait Signal.race(this.#used, this.#state.closed);\n\t\t}\n\t}\n\n\t// Register a downstream sink: seed its info, replay the retained window, and (while\n\t// the track is open) mirror future groups into it. A late subscriber to a closed\n\t// track still drains the buffered groups before seeing the end.\n\t#addSink(sink: TrackState): void {\n\t\tsink.producer = this;\n\t\tconst info = this.#state.info.peek();\n\t\tif (info) sink.info.set(info);\n\n\t\tconst closed = this.#state.closed.peek();\n\t\tif (closed === undefined) {\n\t\t\tthis.#sinks.add(sink);\n\t\t\tthis.#used.set(true);\n\n\t\t\t// Forward subscription updates from the sink's Subscriber to the producer's own\n\t\t\t// state, which the wire layer (or the serving application) watches.\n\t\t\tconst forward = sink.update.subscribe(() => this.#updateSubscription());\n\t\t\tthis.#updateSubscription();\n\n\t\t\t// Drop the sink once its consumer goes away, closing its mirrors so source\n\t\t\t// groups stop teeing into them, so a long-lived producer doesn't leak. This\n\t\t\t// covers mirrors already handed out via recvGroup (no longer in sink.groups)\n\t\t\t// by closing them through the cache's per-sink tracking.\n\t\t\tconst dispose = sink.closed.subscribe((c) => {\n\t\t\t\tif (c === undefined) return;\n\t\t\t\tconst abort = c instanceof Error ? c : undefined;\n\t\t\t\tforward();\n\t\t\t\tthis.#sinks.delete(sink);\n\t\t\t\tthis.#updateSubscription();\n\t\t\t\tfor (const entry of this.#cache) {\n\t\t\t\t\tconst mirror = entry.mirrors.get(sink);\n\t\t\t\t\tif (mirror) {\n\t\t\t\t\t\tmirror.close(abort);\n\t\t\t\t\t\tentry.mirrors.delete(sink);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const group of sink.groups.peek()) group.close(abort);\n\t\t\t\tdispose();\n\n\t\t\t\t// Update demand: once the last subscriber leaves, the consumer wire (watching\n\t\t\t\t// {@link unused}) tears the upstream down instead of downloading to nobody.\n\t\t\t\tthis.#used.set(this.#sinks.size > 0);\n\t\t\t});\n\t\t}\n\n\t\tthis.#prune();\n\t\tfor (const entry of this.#cache) this.#mirror(entry, sink);\n\n\t\tif (closed !== undefined) closeTrackState(sink, closed instanceof Error ? closed : undefined);\n\t}\n\n\t// Recompute from every live sink because an update or close can narrow as well as widen\n\t// the aggregate. The wire layer observes this signal and emits SUBSCRIBE_UPDATE.\n\t#updateSubscription(): void {\n\t\tthis.#state.update.set(combineSubscriptions(this.#sinks));\n\t}\n\n\t// Mirror a cached source group into a sink. The mirror fills synchronously as the\n\t// source is written and keeps its own read cursor; frame bytes are shared by\n\t// reference. Tracked on the entry so eviction can drop it from the sink.\n\t#mirror(entry: CachedGroup, sink: TrackState): void {\n\t\tconst dst = entry.group.mirror();\n\t\tentry.mirrors.set(sink, dst);\n\t\tsink.latest = Math.max(sink.latest ?? 0, dst.sequence);\n\t\tsink.groups.mutate((groups) => {\n\t\t\tgroups.push(dst);\n\t\t\tgroups.sort((a, b) => a.sequence - b.sequence);\n\t\t});\n\t}\n\n\t// Drop a cached group's mirror from every sink so no consumer can pin it.\n\t#evict(entry: CachedGroup): void {\n\t\tfor (const [sink, mirror] of entry.mirrors) {\n\t\t\tsink.groups.mutate((groups) => {\n\t\t\t\tconst i = groups.indexOf(mirror);\n\t\t\t\tif (i >= 0) groups.splice(i, 1);\n\t\t\t});\n\t\t\tmirror.close();\n\t\t}\n\t\tentry.mirrors.clear();\n\t}\n\n\t// Evict cached groups that are closed and older than the cache window.\n\t#prune(): void {\n\t\tconst latencyMaxMs = this.#state.info.peek()?.latencyMax ?? DEFAULT_LATENCY_MAX_MS;\n\t\tconst cutoff = Date.now() - latencyMaxMs;\n\n\t\tconst retained: CachedGroup[] = [];\n\t\tfor (const entry of this.#cache) {\n\t\t\tif (entry.time > cutoff || entry.group.closed.peek() === undefined) {\n\t\t\t\tretained.push(entry);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#evict(entry);\n\t\t}\n\t\tthis.#cache = retained;\n\t}\n\n\t// Retain a source group and fan it out to every live sink.\n\t#publish(group: GroupProducer): void {\n\t\tconst entry: CachedGroup = { group, time: Date.now(), mirrors: new Map<TrackState, GroupConsumer>() };\n\t\tthis.#cache.push(entry);\n\t\tthis.#prune();\n\t\tfor (const sink of this.#sinks) this.#mirror(entry, sink);\n\t}\n\n\t/** Append a new group with the next sequence number. */\n\tappendGroup(): GroupProducer {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\n\t\tconst sequence = this.#sequence;\n\t\tconst group = new GroupProducer(sequence.next);\n\t\tsequence.next = group.sequence + 1;\n\t\tthis.#publish(group);\n\n\t\treturn group;\n\t}\n\n\t/**\n\t * Insert an existing group into the track.\n\t *\n\t * Throws on a sequence that is still cached: a live duplicate would fan out to every\n\t * subscriber twice. An aborted incarnation is evicted so a fresh group can serve the\n\t * sequence again. Best effort (mirrors Rust): nothing remembers a sequence whose cache\n\t * entry is already gone, so a long-evicted sequence is accepted as new.\n\t */\n\twriteGroup(group: GroupProducer) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\n\t\tconst existing = this.#cache.findIndex((entry) => entry.group.sequence === group.sequence);\n\t\tif (existing >= 0) {\n\t\t\tconst entry = this.#cache[existing];\n\t\t\tif (!(entry.group.closed.peek() instanceof Error)) {\n\t\t\t\tthrow new Error(`duplicate group: sequence=${group.sequence}`);\n\t\t\t}\n\t\t\tthis.#evict(entry);\n\t\t\tthis.#cache.splice(existing, 1);\n\t\t}\n\n\t\t// Only advance the shared counter upward (for appendGroup auto-increment).\n\t\tconst sequence = this.#sequence;\n\t\tif (group.sequence >= sequence.next) {\n\t\t\tsequence.next = group.sequence + 1;\n\t\t}\n\n\t\tthis.#publish(group);\n\t}\n\n\t// Fan a datagram out to every live subscriber, dropping the oldest once the ring is full.\n\t// Late subscribers do NOT replay old datagrams (best-effort, unlike the group cache).\n\t#publishDatagram(datagram: Datagram): void {\n\t\tconst now = performance.now();\n\t\tfor (const sink of this.#sinks) {\n\t\t\tsink.datagrams.mutate((list) => {\n\t\t\t\tlist.push({ datagram, time: now });\n\t\t\t\t// Drop anything older than the send-buffer window.\n\t\t\t\twhile (list.length > 0 && now - list[0].time > MAX_DATAGRAM_AGE_MS) list.shift();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Append a datagram with the next sequence number, returning the assigned sequence.\n\t *\n\t * A datagram is delivered best-effort over a single QUIC datagram, parallel to the track's\n\t * groups but drawing from the same sequence namespace (interleaving with {@link appendGroup}\n\t * never reuses a number). The payload must fit the negotiated transport datagram size minus\n\t * a small header; an oversize payload is dropped at each hop (there is no group fallback), so\n\t * keep datagram payloads small (e.g. a single audio frame). Datagrams are never delivered\n\t * over IETF moq-transport or stream-only transports (the WebSocket fallback). A payload over\n\t * 65535 bytes (the QUIC datagram frame ceiling) throws. An origin publisher uses this; a\n\t * relay preserving upstream numbering uses {@link writeDatagram}.\n\t */\n\tappendDatagram(timestamp: Timestamp, payload: Uint8Array): number {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\t\tif (payload.byteLength > MAX_DATAGRAM_BYTES) throw new Error(\"datagram payload too large\");\n\n\t\tconst counter = this.#sequence;\n\t\tconst sequence = counter.next;\n\t\tcounter.next = sequence + 1;\n\t\tthis.#publishDatagram({ sequence, timestamp, payload });\n\t\treturn sequence;\n\t}\n\n\t/**\n\t * Write a datagram with an explicit sequence number.\n\t *\n\t * Preserves the supplied sequence (advancing the shared counter if needed) so a relay can\n\t * forward a datagram without renumbering it. The size limits of {@link appendDatagram}\n\t * apply. Most origin publishers want {@link appendDatagram} instead.\n\t */\n\twriteDatagram(datagram: Datagram) {\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"track is closed\");\n\t\tif (datagram.payload.byteLength > MAX_DATAGRAM_BYTES) throw new Error(\"datagram payload too large\");\n\n\t\tconst sequence = this.#sequence;\n\t\tif (datagram.sequence >= sequence.next) {\n\t\t\tsequence.next = datagram.sequence + 1;\n\t\t}\n\t\tthis.#publishDatagram(datagram);\n\t}\n\n\t/** Close the track and every subscriber, mirroring the abort to their groups. Idempotent. */\n\tclose(abort?: Error) {\n\t\tcloseTrackState(this.#state, abort);\n\t\tfor (const { group } of this.#cache) group.close(abort);\n\t\tfor (const sink of this.#sinks) {\n\t\t\tfor (const group of sink.groups.peek()) group.close(abort);\n\t\t\tcloseTrackState(sink, abort);\n\t\t}\n\t\tthis.#sinks.clear();\n\t}\n\n\t/** Append a frame as its own single-frame group. */\n\twriteFrame(frame: Frame) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeFrame(frame);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a string to the track as its own single-frame group. */\n\twriteString(str: string) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeString(str);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a JSON value to the track as its own single-frame group. */\n\twriteJson(json: unknown) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeJson(json);\n\t\tgroup.close();\n\t}\n\n\t/** Appends a boolean to the track as its own single-frame group. */\n\twriteBool(bool: boolean) {\n\t\tconst group = this.appendGroup();\n\t\tgroup.writeBool(bool);\n\t\tgroup.close();\n\t}\n}\n\n/**\n * The read side of a live track subscription, mirroring the Rust `Subscriber`.\n *\n * Obtained from `Broadcast.Consumer.subscribe` / `Track.Consumer.subscribe`, or from\n * {@link Producer.subscribe} for an in-process track. Reads the groups a\n * {@link Producer} on the same underlying state writes.\n */\nexport class Subscriber {\n\t/** The track name. */\n\treadonly name: string;\n\n\t#state: TrackState;\n\t#nextSequence = 0;\n\t#cursor = new Signal<{ start: number; end?: number }>({ start: 0 });\n\n\tprivate constructor(name: string, state: TrackState) {\n\t\tthis.name = name;\n\t\tthis.#state = state;\n\t}\n\n\tstatic {\n\t\tmakeSubscriber = (name, state) => new Subscriber(name, state);\n\t}\n\n\t/**\n\t * Resolve this track's immutable publisher properties.\n\t *\n\t * Resolves once the wire layer commits the TRACK_INFO it received (lite-05+) or\n\t * defaults (older drafts), so awaiting it never yields a placeholder. Rejects if\n\t * the track is closed before the properties are known (e.g. a rejected subscription).\n\t */\n\tinfo(): Promise<Info> {\n\t\treturn resolveInfo(this.#state);\n\t}\n\n\t/** Settles once the track closes; see {@link Producer.closed}. */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/** This subscriber's current options, including defaults and the last {@link update}. */\n\tget subscription(): Getter<Subscription | undefined> {\n\t\treturn this.#state.update;\n\t}\n\n\t/** Return the latest group sequence observed on this track, if any. */\n\tlatest(): number | undefined {\n\t\treturn this.#state.latest;\n\t}\n\n\t/**\n\t * The newest frame this track has produced, or `undefined` while it has none.\n\t *\n\t * Read from the groups buffered for this subscriber, so nothing is consumed. A newest\n\t * group that has no frames yet falls back to the newest older group that does. It\n\t * reads as `undefined` once the newest group has been evicted or received: what is\n\t * left can no longer say where the edge is.\n\t */\n\tlargest(): Location | undefined {\n\t\tconst latest = this.#state.latest;\n\t\tif (latest === undefined) return undefined;\n\n\t\tconst groups = this.#state.groups.peek();\n\t\tconst newest = groups[groups.length - 1];\n\t\tif (!newest || newest.sequence !== latest) return undefined;\n\n\t\tfor (let i = groups.length - 1; i >= 0; i--) {\n\t\t\tconst count = groups[i].frameCount;\n\t\t\tif (count > 0) return { group: groups[i].sequence, frame: count - 1 };\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * An independent subscriber to the same track, with its own cursor and its own replay of\n\t * the retained window.\n\t *\n\t * Reads here do not consume anything this one would deliver, which is what lets a\n\t * publisher read the cache alongside the cursor it is serving from. Resolving the track\n\t * again through the broadcast would not do: a dynamic serve is one request per peer\n\t * subscription, so that mints a second producer the application has to answer separately.\n\t *\n\t * @internal Wire layers only.\n\t */\n\tfork(options?: Subscription): Subscriber {\n\t\tconst producer = this.#state.producer;\n\t\tif (!producer) throw new Error(\"track has no producer to fork from\");\n\t\treturn producer.subscribe(options);\n\t}\n\n\t/** Start this subscriber's local read cursor at `sequence`, without changing its wire request. */\n\tstartAt(sequence: number): void {\n\t\tthis.#cursor.update((cursor) => ({ ...cursor, start: sequence }));\n\t}\n\n\t/**\n\t * Cap {@link nextGroup} and {@link recvGroup} at `sequence` inclusively, or omit it to\n\t * remove the cap. Groups above the cap remain buffered and become readable if the cap\n\t * is raised. This local cursor does not change the subscription's wire request.\n\t */\n\tendAt(sequence?: number): void {\n\t\tthis.#cursor.update((cursor) => ({ ...cursor, end: sequence }));\n\t}\n\n\t/** Close the track (optionally with an error), closing any pending groups. Idempotent. */\n\tclose(abort?: Error) {\n\t\t// Settle if we're first (the producer may already have); either way drop anything\n\t\t// still buffered. Groups parked at the endAt cap deliberately outlive a clean\n\t\t// producer close, so the subscriber leaving is what must release them: closing\n\t\t// and clearing wakes a pending read to observe the end instead of hanging.\n\t\tcloseTrackState(this.#state, abort);\n\t\tthis.#state.groups.mutate((groups) => {\n\t\t\tfor (const group of groups) group.close(abort);\n\t\t\tgroups.length = 0;\n\t\t});\n\t}\n\n\t/**\n\t * Receive every group on this track exactly once, as it becomes available.\n\t *\n\t * Groups may arrive out of order or with gaps due to network conditions; unlike\n\t * {@link nextGroup}, one that arrives after a newer group was already returned is\n\t * still delivered. When several groups are buffered, the lowest sequence is\n\t * returned first.\n\t *\n\t * Honors the floor set by {@link startAt} and the cap set by {@link endAt}: a group\n\t * beyond the cap stays buffered (not dropped) and is offered once the cap rises, even\n\t * after a clean close, without blocking in-range groups that arrive behind it.\n\t */\n\tasync recvGroup(): Promise<GroupConsumer | undefined> {\n\t\tfor (;;) {\n\t\t\tconst group = this.tryRecvGroup();\n\t\t\tif (group) return group;\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\t// A group beyond the cap outlives a clean close: it becomes deliverable if\n\t\t\t// the cap rises, so the track isn't over while any are held.\n\t\t\tif (closed !== undefined && !this.#state.groups.peek()[0]) return undefined;\n\n\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Take the next buffered group without blocking, honoring the same cursor bounds as\n\t * {@link recvGroup}.\n\t *\n\t * Returns `undefined` when nothing is deliverable right now, which is not by itself the\n\t * end of the track: a group may still arrive, or one may be parked beyond the\n\t * {@link endAt} cap. Use it to drain what the retained window already holds, where\n\t * waiting for a sequence nothing will republish would park forever.\n\t */\n\ttryRecvGroup(): GroupConsumer | undefined {\n\t\tconst groups = this.#state.groups.peek();\n\t\tconst { start, end } = this.#cursor.peek();\n\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\n\t\t// The buffer is sequence-sorted, so an in-range group that arrives behind a\n\t\t// beyond-cap one sorts in front of it and is never blocked by it.\n\t\tconst group = groups[0];\n\t\tif (group && (end === undefined || group.sequence <= end)) {\n\t\t\tgroups.shift();\n\t\t\treturn group;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Receive the next datagram in arrival order.\n\t *\n\t * Datagrams are a separate best-effort channel from groups (see\n\t * {@link Producer.appendDatagram}); they share only the sequence namespace. A consumer\n\t * that falls too far behind silently loses the oldest datagrams. Read this alongside\n\t * {@link recvGroup} (e.g. in a separate loop) to receive both channels concurrently. Returning\n\t * a datagram advances {@link nextGroup} past that sequence.\n\t */\n\tasync recvDatagram(): Promise<Datagram | undefined> {\n\t\tfor (;;) {\n\t\t\tconst datagrams = this.#state.datagrams.peek();\n\n\t\t\t// Evict datagrams older than the send-buffer window (also enforced on write), so a\n\t\t\t// reader that stalled skips stale datagrams instead of replaying them.\n\t\t\tconst cutoff = performance.now() - MAX_DATAGRAM_AGE_MS;\n\t\t\twhile (datagrams.length > 0 && datagrams[0].time < cutoff) datagrams.shift();\n\n\t\t\tif (datagrams.length > 0) {\n\t\t\t\tconst datagram = datagrams.shift()?.datagram;\n\t\t\t\tif (datagram) {\n\t\t\t\t\tthis.#nextSequence = Math.max(this.#nextSequence, datagram.sequence + 1);\n\t\t\t\t}\n\t\t\t\treturn datagram;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\tawait Signal.race(this.#state.datagrams, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Return the next group with a strictly-greater sequence number than the last returned.\n\t *\n\t * Late arrivals (sequence at or below the last returned) are silently skipped.\n\t * Use {@link recvGroup} to see every group in arrival order instead.\n\t */\n\tasync nextGroup(): Promise<GroupConsumer | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tconst cursor = this.#cursor.peek();\n\t\t\tconst start = Math.max(cursor.start, this.#nextSequence);\n\t\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\n\t\t\tconst group = groups[0];\n\t\t\tif (group && (cursor.end === undefined || group.sequence <= cursor.end)) {\n\t\t\t\tgroups.shift();\n\t\t\t\tthis.#nextSequence = group.sequence + 1;\n\t\t\t\treturn group;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined && !group) return undefined;\n\n\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t}\n\t}\n\n\t/**\n\t * Reads the next frame across all groups, discarding older groups.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrame(): Promise<Frame | undefined> {\n\t\tconst next = await this.readFrameSequence();\n\t\treturn next ? { payload: next.payload, timestamp: next.timestamp } : undefined;\n\t}\n\n\t/**\n\t * Reads the next frame along with its group and frame sequence numbers.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrameSequence(): Promise<({ group: number; frame: number } & Frame) | undefined> {\n\t\tfor (;;) {\n\t\t\tconst groups = this.#state.groups.peek();\n\t\t\tconst { start } = this.#cursor.peek();\n\t\t\twhile (groups.length > 0 && groups[0].sequence < start) groups.shift()?.close();\n\n\t\t\t// Drain older groups first, dropping each once empty.\n\t\t\twhile (groups.length > 1) {\n\t\t\t\tif (groups[0].skipped) {\n\t\t\t\t\t// The reader fell behind this group's eviction window. Drop it and\n\t\t\t\t\t// signal the gap; the next read resyncs from the following group.\n\t\t\t\t\tgroups.shift()?.close();\n\t\t\t\t\tthrow new Lagged();\n\t\t\t\t}\n\t\t\t\tconst next = groups[0].tryReadFrameSequence();\n\t\t\t\tif (next) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tgroup: groups[0].sequence,\n\t\t\t\t\t\tframe: next.sequence,\n\t\t\t\t\t\tpayload: next.payload,\n\t\t\t\t\t\ttimestamp: next.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tgroups.shift()?.close();\n\t\t\t}\n\n\t\t\tif (groups.length === 0) {\n\t\t\t\tconst closed = this.#state.closed.peek();\n\t\t\t\tif (closed instanceof Error) throw closed;\n\t\t\t\tif (closed !== undefined) return undefined;\n\t\t\t\tawait Signal.race(this.#state.groups, this.#cursor, this.#state.closed);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst group = groups[0];\n\t\t\tif (group.skipped) {\n\t\t\t\t// Fell behind this group's eviction window. Drop it and signal the gap;\n\t\t\t\t// the next read resyncs from the following group.\n\t\t\t\tgroups.shift()?.close();\n\t\t\t\tthrow new Lagged();\n\t\t\t}\n\t\t\tconst next = group.tryReadFrameSequence();\n\t\t\tif (next)\n\t\t\t\treturn {\n\t\t\t\t\tgroup: group.sequence,\n\t\t\t\t\tframe: next.sequence,\n\t\t\t\t\tpayload: next.payload,\n\t\t\t\t\ttimestamp: next.timestamp,\n\t\t\t\t};\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) return undefined;\n\n\t\t\t// A finished (drained + closed) group has nothing left: drop it and loop, rather than\n\t\t\t// busy-waiting on its already-resolved readable() (which would livelock and starve the\n\t\t\t// macrotask that delivers the next group).\n\t\t\tif (group.done) {\n\t\t\t\tgroups.shift()?.close();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Lone open group with nothing buffered yet: wait for a frame on it, a new group, or\n\t\t\t// the track closing.\n\t\t\tawait Promise.race([Signal.race(this.#state.groups, this.#cursor, this.#state.closed), group.readable()]);\n\t\t}\n\t}\n\n\t/** Reads the next frame and decodes it as a UTF-8 string. */\n\tasync readString(): Promise<string | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\treturn new TextDecoder().decode(next.payload);\n\t}\n\n\t/** Reads the next frame and parses it as JSON. */\n\tasync readJson(): Promise<unknown | undefined> {\n\t\tconst next = await this.readString();\n\t\tif (!next) return undefined;\n\t\treturn JSON.parse(next);\n\t}\n\n\t/** Reads the next frame and decodes it as a one-byte boolean, throwing on a malformed frame. */\n\tasync readBool(): Promise<boolean | undefined> {\n\t\tconst next = await this.readFrame();\n\t\tif (!next) return undefined;\n\t\tconst payload = next.payload;\n\t\tif (payload.byteLength !== 1 || !(payload[0] === 0 || payload[0] === 1)) throw new Error(\"invalid bool frame\");\n\t\treturn payload[0] === 1;\n\t}\n\n\t/**\n\t * Update this subscription's options (e.g. priority), triggering a SUBSCRIBE_UPDATE to the\n\t * publisher. Mirrors the Rust `Subscriber::update`.\n\t */\n\tupdate(options: Subscription) {\n\t\tthis.#state.update.set(subscriptionDefaults(options));\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAKD,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAM3F"}
|
package/util/timeout.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* @ts-self-types="./timeout.d.ts" */
|
|
2
|
+
export class TimeoutError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "TimeoutError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
// Race `promise` against a timeout. There's no cancellation; if `promise`
|
|
9
|
+
// settles after the timeout fires the caller is responsible for cleaning up
|
|
10
|
+
// any side effects (open streams, etc.) it may produce.
|
|
11
|
+
export function withTimeout(promise, ms, message) {
|
|
12
|
+
let timer;
|
|
13
|
+
const timeout = new Promise((_, reject) => {
|
|
14
|
+
timer = setTimeout(() => reject(new TimeoutError(message)), ms);
|
|
15
|
+
});
|
|
16
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC5B,CAAC;CACD;AAED,0EAA0E;AAC1E,4EAA4E;AAC5E,wDAAwD;AACxD,MAAM,UAAU,WAAW,CAAI,OAAmB,EAAE,EAAU,EAAE,OAAe;IAC9E,IAAI,KAAoC,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAChD,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["export class TimeoutError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"TimeoutError\";\n\t}\n}\n\n// Race `promise` against a timeout. There's no cancellation; if `promise`\n// settles after the timeout fires the caller is responsible for cleaning up\n// any side effects (open streams, etc.) it may produce.\nexport function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {\n\tlet timer: ReturnType<typeof setTimeout>;\n\tconst timeout = new Promise<never>((_, reject) => {\n\t\ttimer = setTimeout(() => reject(new TimeoutError(message)), ms);\n\t});\n\treturn Promise.race([promise, timeout]).finally(() => clearTimeout(timer));\n}\n"]}
|
package/util/utf8.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../../src/util/utf8.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAErD"}
|
package/util/utf8.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* @ts-self-types="./utf8.d.ts" */
|
|
2
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
3
|
+
/** Decode a protocol string, rejecting bytes that are not valid UTF-8. */
|
|
4
|
+
export function decodeUtf8(buffer) {
|
|
5
|
+
return decoder.decode(buffer);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=utf8.js.map
|
package/util/utf8.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8.js","sourceRoot":"","sources":["../../src/util/utf8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1D,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC5C,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["const decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\n/** Decode a protocol string, rejecting bytes that are not valid UTF-8. */\nexport function decodeUtf8(buffer: Uint8Array): string {\n\treturn decoder.decode(buffer);\n}\n"]}
|
package/varint.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QUIC variable-length integer encoding and decoding.
|
|
3
|
+
* https://www.rfc-editor.org/rfc/rfc9000#section-16
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
/** Largest value that fits in a 1-byte varint (6 bits). */
|
|
2
8
|
export declare const MAX_U6: number;
|
|
3
9
|
/** Largest value that fits in a 2-byte varint (14 bits). */
|
|
@@ -24,13 +30,18 @@ export declare function size(v: number): number;
|
|
|
24
30
|
*/
|
|
25
31
|
export declare function encodeTo(dst: ArrayBuffer, v: number | bigint): Uint8Array;
|
|
26
32
|
/**
|
|
27
|
-
* Encodes a number as a QUIC variable-length integer.
|
|
33
|
+
* Encodes a number or bigint as a QUIC variable-length integer.
|
|
28
34
|
* Returns a new Uint8Array containing the encoded bytes.
|
|
29
35
|
*/
|
|
30
|
-
export declare function encode(v: number): Uint8Array;
|
|
36
|
+
export declare function encode(v: number | bigint): Uint8Array;
|
|
31
37
|
/**
|
|
32
|
-
* Decodes a QUIC variable-length integer from a buffer.
|
|
38
|
+
* Decodes a QUIC variable-length integer exactly from a buffer.
|
|
33
39
|
* Returns a tuple of [value, remaining buffer].
|
|
34
40
|
*/
|
|
41
|
+
export declare function decodeBigInt(buf: Uint8Array): [bigint, Uint8Array];
|
|
42
|
+
/**
|
|
43
|
+
* Decodes a QUIC variable-length integer from a buffer.
|
|
44
|
+
* Values above 53 bits lose precision; use {@link decodeBigInt} for exact decoding.
|
|
45
|
+
*/
|
|
35
46
|
export declare function decode(buf: Uint8Array): [number, Uint8Array];
|
|
36
47
|
//# sourceMappingURL=varint.d.ts.map
|
package/varint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../src/varint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../src/varint.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,2DAA2D;AAC3D,eAAO,MAAM,MAAM,QAAa,CAAC;AACjC,4DAA4D;AAC5D,eAAO,MAAM,OAAO,QAAc,CAAC;AACnC,4DAA4D;AAC5D,eAAO,MAAM,OAAO,QAAc,CAAC;AACnC,+FAA+F;AAC/F,eAAO,MAAM,OAAO,QAA0B,CAAC;AAgB/C,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAY1D;AAED,6GAA6G;AAC7G,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAkDpF;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAEhE;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAmFvE;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAMtC;AA6BD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAmBzE;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAErD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CA6BlE;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAG5D"}
|
package/varint.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/* @ts-self-types="./varint.d.ts" */
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* QUIC variable-length integer encoding and decoding.
|
|
4
|
+
* https://www.rfc-editor.org/rfc/rfc9000#section-16
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
4
8
|
/** Largest value that fits in a 1-byte varint (6 bits). */
|
|
5
9
|
export const MAX_U6 = 2 ** 6 - 1;
|
|
6
10
|
/** Largest value that fits in a 2-byte varint (14 bits). */
|
|
@@ -246,17 +250,17 @@ export function encodeTo(dst, v) {
|
|
|
246
250
|
return setUint64(dst, b | 0xc000000000000000n);
|
|
247
251
|
}
|
|
248
252
|
/**
|
|
249
|
-
* Encodes a number as a QUIC variable-length integer.
|
|
253
|
+
* Encodes a number or bigint as a QUIC variable-length integer.
|
|
250
254
|
* Returns a new Uint8Array containing the encoded bytes.
|
|
251
255
|
*/
|
|
252
256
|
export function encode(v) {
|
|
253
257
|
return encodeTo(new ArrayBuffer(8), v);
|
|
254
258
|
}
|
|
255
259
|
/**
|
|
256
|
-
* Decodes a QUIC variable-length integer from a buffer.
|
|
260
|
+
* Decodes a QUIC variable-length integer exactly from a buffer.
|
|
257
261
|
* Returns a tuple of [value, remaining buffer].
|
|
258
262
|
*/
|
|
259
|
-
export function
|
|
263
|
+
export function decodeBigInt(buf) {
|
|
260
264
|
if (buf.length === 0) {
|
|
261
265
|
throw new Error("buffer is empty");
|
|
262
266
|
}
|
|
@@ -266,23 +270,30 @@ export function decode(buf) {
|
|
|
266
270
|
}
|
|
267
271
|
const view = new DataView(buf.buffer, buf.byteOffset, size);
|
|
268
272
|
const remain = buf.subarray(size);
|
|
269
|
-
let
|
|
273
|
+
let value;
|
|
270
274
|
if (size === 1) {
|
|
271
|
-
|
|
275
|
+
value = BigInt(buf[0] & 0x3f);
|
|
272
276
|
}
|
|
273
277
|
else if (size === 2) {
|
|
274
|
-
|
|
278
|
+
value = BigInt(view.getUint16(0) & 0x3fff);
|
|
275
279
|
}
|
|
276
280
|
else if (size === 4) {
|
|
277
|
-
|
|
281
|
+
value = BigInt(view.getUint32(0) & 0x3fffffff);
|
|
278
282
|
}
|
|
279
283
|
else if (size === 8) {
|
|
280
|
-
|
|
281
|
-
v = Number(view.getBigUint64(0) & 0x3fffffffffffffffn);
|
|
284
|
+
value = view.getBigUint64(0) & 0x3fffffffffffffffn;
|
|
282
285
|
}
|
|
283
286
|
else {
|
|
284
287
|
throw new Error("impossible");
|
|
285
288
|
}
|
|
286
|
-
return [
|
|
289
|
+
return [value, remain];
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Decodes a QUIC variable-length integer from a buffer.
|
|
293
|
+
* Values above 53 bits lose precision; use {@link decodeBigInt} for exact decoding.
|
|
294
|
+
*/
|
|
295
|
+
export function decode(buf) {
|
|
296
|
+
const [value, remain] = decodeBigInt(buf);
|
|
297
|
+
return [Number(value), remain];
|
|
287
298
|
}
|
|
288
299
|
//# sourceMappingURL=varint.js.map
|
package/varint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"varint.js","sourceRoot":"","sources":["../src/varint.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,oDAAoD;AAEpD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAE/C,iEAAiE;AACjE,mBAAmB;AACnB,qCAAqC;AACrC,sCAAsC;AACtC,sCAAsC;AACtC,sCAAsC;AACtC,sCAAsC;AACtC,sCAAsC;AACtC,sFAAsF;AACtF,sCAAsC;AACtC,sCAAsC;AAEtC,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AAEjC,kFAAkF;AAClF,MAAM,UAAU,eAAe,CAAC,CAAkB;IACjD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC;IAC5D,IAAI,CAAC,GAAG,OAAO;QAAE,MAAM,IAAI,UAAU,CAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC;IACrE,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE;QAAE,OAAO,CAAC,CAAC;IAC3B,IAAI,CA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C;SAAM,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QACvB,+DAA+D;QAC/D,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC;IACxD,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACpB,CAAC","sourcesContent":["// QUIC variable-length integer encoding/decoding\n// https://www.rfc-editor.org/rfc/rfc9000#section-16\n\n/** Largest value that fits in a 1-byte varint (6 bits). */\nexport const MAX_U6 = 2 ** 6 - 1;\n/** Largest value that fits in a 2-byte varint (14 bits). */\nexport const MAX_U14 = 2 ** 14 - 1;\n/** Largest value that fits in a 4-byte varint (30 bits). */\nexport const MAX_U30 = 2 ** 30 - 1;\n/** Largest value representable without precision loss (`Number.MAX_SAFE_INTEGER`, 53 bits). */\nexport const MAX_U53 = Number.MAX_SAFE_INTEGER;\n\n// Leading-ones varint encoding/decoding (draft-17 Section 1.4.1)\n// Encoding scheme:\n// 0xxxxxxx → 1 byte (7 bits)\n// 10xxxxxx + 1B → 2 bytes (14 bits)\n// 110xxxxx + 2B → 3 bytes (21 bits)\n// 1110xxxx + 3B → 4 bytes (28 bits)\n// 11110xxx + 4B → 5 bytes (35 bits)\n// 111110xx + 5B → 6 bytes (42 bits)\n// 1111110x + 6B → 7 bytes (49 bits), draft-18+ only (invalid in draft-17 per #1595)\n// 11111110 + 7B → 8 bytes (56 bits)\n// 11111111 + 8B → 9 bytes (64 bits)\n\nconst MAX_U64 = (1n << 64n) - 1n;\n\n/** Number of bytes needed to encode a value in the leading-ones varint format. */\nexport function sizeLeadingOnes(v: number | bigint): number {\n\tconst b = BigInt(v);\n\tif (b < 0n) throw new RangeError(`value is negative: ${v}`);\n\tif (b > MAX_U64) throw new RangeError(`value exceeds 64 bits: ${v}`);\n\tif (b < 1n << 7n) return 1;\n\tif (b < 1n << 14n) return 2;\n\tif (b < 1n << 21n) return 3;\n\tif (b < 1n << 28n) return 4;\n\tif (b < 1n << 35n) return 5;\n\tif (b < 1n << 42n) return 6;\n\tif (b < 1n << 56n) return 8;\n\treturn 9;\n}\n\n/** Encode a value in leading-ones varint format into the provided buffer, returning the written subarray. */\nexport function encodeLeadingOnesTo(dst: ArrayBuffer, v: number | bigint): Uint8Array {\n\tconst x = BigInt(v);\n\tif (x < 0n) throw new RangeError(`underflow, value is negative: ${v}`);\n\tif (x > MAX_U64) throw new RangeError(`value exceeds 64 bits: ${v}`);\n\n\tconst view = new DataView(dst);\n\n\tif (x < 1n << 7n) {\n\t\tview.setUint8(0, Number(x));\n\t\treturn new Uint8Array(dst, 0, 1);\n\t}\n\tif (x < 1n << 14n) {\n\t\tview.setUint8(0, 0x80 | Number(x >> 8n));\n\t\tview.setUint8(1, Number(x & 0xffn));\n\t\treturn new Uint8Array(dst, 0, 2);\n\t}\n\tif (x < 1n << 21n) {\n\t\tview.setUint8(0, 0xc0 | Number(x >> 16n));\n\t\tview.setUint16(1, Number(x & 0xffffn));\n\t\treturn new Uint8Array(dst, 0, 3);\n\t}\n\tif (x < 1n << 28n) {\n\t\tview.setUint8(0, 0xe0 | Number(x >> 24n));\n\t\tview.setUint8(1, Number((x >> 16n) & 0xffn));\n\t\tview.setUint16(2, Number(x & 0xffffn));\n\t\treturn new Uint8Array(dst, 0, 4);\n\t}\n\tif (x < 1n << 35n) {\n\t\tview.setUint8(0, 0xf0 | Number(x >> 32n));\n\t\tview.setUint32(1, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 5);\n\t}\n\tif (x < 1n << 42n) {\n\t\tview.setUint8(0, 0xf8 | Number(x >> 40n));\n\t\tview.setUint8(1, Number((x >> 32n) & 0xffn));\n\t\tview.setUint32(2, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 6);\n\t}\n\tif (x < 1n << 56n) {\n\t\t// 11111110 + 7 bytes\n\t\tview.setUint8(0, 0xfe);\n\t\tview.setUint8(1, Number((x >> 48n) & 0xffn));\n\t\tview.setUint16(2, Number((x >> 32n) & 0xffffn));\n\t\tview.setUint32(4, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 8);\n\t}\n\t// 11111111 + 8 bytes\n\tview.setUint8(0, 0xff);\n\tview.setBigUint64(1, x);\n\treturn new Uint8Array(dst, 0, 9);\n}\n\n/** Encode a value in leading-ones varint format into a freshly allocated buffer. */\nexport function encodeLeadingOnes(v: number | bigint): Uint8Array {\n\treturn encodeLeadingOnesTo(new ArrayBuffer(9), v);\n}\n\n/** Decode a leading-ones varint, returning the value and the remaining buffer. */\nexport function decodeLeadingOnes(buf: Uint8Array): [bigint, Uint8Array] {\n\tif (buf.length === 0) throw new Error(\"buffer is empty\");\n\n\tconst b = buf[0];\n\t// Count leading 1-bits\n\tlet ones = 0;\n\tfor (let bit = 7; bit >= 0; bit--) {\n\t\tif (b & (1 << bit)) ones++;\n\t\telse break;\n\t}\n\n\t// 1111110x is a 7-byte form: invalid on draft-17, allowed on draft-18+ per #1595.\n\t// This standalone decoder is permissive (Postel-style) since we lack version context here.\n\n\tlet totalSize: number;\n\tif (ones <= 5) totalSize = ones + 1;\n\telse if (ones === 6) totalSize = 7;\n\telse if (ones === 7) totalSize = 8;\n\telse totalSize = 9; // ones === 8\n\n\tif (buf.length < totalSize) {\n\t\tthrow new Error(`buffer too short: need ${totalSize} bytes, have ${buf.length}`);\n\t}\n\n\tconst view = new DataView(buf.buffer, buf.byteOffset, totalSize);\n\tconst remain = buf.subarray(totalSize);\n\tlet value: bigint;\n\n\tswitch (ones) {\n\t\tcase 0:\n\t\t\tvalue = BigInt(b);\n\t\t\tbreak;\n\t\tcase 1:\n\t\t\tvalue = (BigInt(b & 0x3f) << 8n) | BigInt(buf[1]);\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tvalue = (BigInt(b & 0x1f) << 16n) | BigInt(view.getUint16(1));\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tvalue = (BigInt(b & 0x0f) << 24n) | (BigInt(buf[1]) << 16n) | (BigInt(buf[2]) << 8n) | BigInt(buf[3]);\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tvalue = (BigInt(b & 0x07) << 32n) | BigInt(view.getUint32(1));\n\t\t\tbreak;\n\t\tcase 5:\n\t\t\tvalue =\n\t\t\t\t(BigInt(b & 0x03) << 40n) |\n\t\t\t\t(BigInt(buf[1]) << 32n) |\n\t\t\t\t(BigInt(buf[2]) << 24n) |\n\t\t\t\t(BigInt(buf[3]) << 16n) |\n\t\t\t\t(BigInt(buf[4]) << 8n) |\n\t\t\t\tBigInt(buf[5]);\n\t\t\tbreak;\n\t\tcase 6: {\n\t\t\t// 1111110x + 6 bytes = 49 bits (draft-18+)\n\t\t\tvalue =\n\t\t\t\t(BigInt(b & 0x01) << 48n) |\n\t\t\t\t(BigInt(buf[1]) << 40n) |\n\t\t\t\t(BigInt(buf[2]) << 32n) |\n\t\t\t\t(BigInt(buf[3]) << 24n) |\n\t\t\t\t(BigInt(buf[4]) << 16n) |\n\t\t\t\t(BigInt(buf[5]) << 8n) |\n\t\t\t\tBigInt(buf[6]);\n\t\t\tbreak;\n\t\t}\n\t\tcase 7: {\n\t\t\t// 11111110 + 7 bytes = 56 usable bits\n\t\t\tconst hi = new Uint8Array(8);\n\t\t\thi[0] = 0;\n\t\t\thi.set(buf.subarray(1, 8), 1);\n\t\t\tvalue = new DataView(hi.buffer).getBigUint64(0);\n\t\t\tbreak;\n\t\t}\n\t\tcase 8: {\n\t\t\t// 11111111 + 8 bytes = 64 bits\n\t\t\tvalue = new DataView(buf.buffer, buf.byteOffset + 1, 8).getBigUint64(0);\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(\"impossible\");\n\t}\n\n\treturn [value, remain];\n}\n\n/**\n * Returns the number of bytes needed to encode a value as a varint.\n */\nexport function size(v: number): number {\n\tif (v <= MAX_U6) return 1;\n\tif (v <= MAX_U14) return 2;\n\tif (v <= MAX_U30) return 4;\n\tif (v <= MAX_U53) return 8;\n\tthrow new Error(`overflow, value larger than 53-bits: ${v}`);\n}\n\n// Helper functions for writing to an ArrayBuffer\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 setUint32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setUint32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setUint64(dst: ArrayBuffer, v: bigint): Uint8Array {\n\tconst view = new DataView(dst, 0, 8);\n\tview.setBigUint64(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nconst MAX_U62 = 2n ** 62n - 1n;\n\n/**\n * Encodes a number or bigint into a scratch buffer.\n * Used by stream.ts to avoid allocations.\n */\nexport function encodeTo(dst: ArrayBuffer, v: number | bigint): Uint8Array {\n\tconst b = BigInt(v);\n\tif (b < 0n) {\n\t\tthrow new Error(`underflow, value is negative: ${v}`);\n\t}\n\tif (b > MAX_U62) {\n\t\tthrow new Error(`overflow, value larger than 62-bits: ${v}`);\n\t}\n\tconst n = Number(b);\n\tif (n <= MAX_U6) {\n\t\treturn setUint8(dst, n);\n\t}\n\tif (n <= MAX_U14) {\n\t\treturn setUint16(dst, n | 0x4000);\n\t}\n\tif (n <= MAX_U30) {\n\t\treturn setUint32(dst, n | 0x80000000);\n\t}\n\treturn setUint64(dst, b | 0xc000000000000000n);\n}\n\n/**\n * Encodes a number as a QUIC variable-length integer.\n * Returns a new Uint8Array containing the encoded bytes.\n */\nexport function encode(v: number): Uint8Array {\n\treturn encodeTo(new ArrayBuffer(8), v);\n}\n\n/**\n * Decodes a QUIC variable-length integer from a buffer.\n * Returns a tuple of [value, remaining buffer].\n */\nexport function decode(buf: Uint8Array): [number, Uint8Array] {\n\tif (buf.length === 0) {\n\t\tthrow new Error(\"buffer is empty\");\n\t}\n\n\tconst size = 1 << ((buf[0] & 0xc0) >> 6);\n\n\tif (buf.length < size) {\n\t\tthrow new Error(`buffer too short: need ${size} bytes, have ${buf.length}`);\n\t}\n\n\tconst view = new DataView(buf.buffer, buf.byteOffset, size);\n\tconst remain = buf.subarray(size);\n\n\tlet v: number;\n\n\tif (size === 1) {\n\t\tv = buf[0] & 0x3f;\n\t} else if (size === 2) {\n\t\tv = view.getUint16(0) & 0x3fff;\n\t} else if (size === 4) {\n\t\tv = view.getUint32(0) & 0x3fffffff;\n\t} else if (size === 8) {\n\t\t// NOTE: Precision loss above 2^53, but we're using number type\n\t\tv = Number(view.getBigUint64(0) & 0x3fffffffffffffffn);\n\t} else {\n\t\tthrow new Error(\"impossible\");\n\t}\n\n\treturn [v, remain];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"varint.js","sourceRoot":"","sources":["../src/varint.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAE/C,iEAAiE;AACjE,mBAAmB;AACnB,qCAAqC;AACrC,sCAAsC;AACtC,sCAAsC;AACtC,sCAAsC;AACtC,sCAAsC;AACtC,sCAAsC;AACtC,sFAAsF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AAE,IAAI,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAElC,IAAI,KAAa,CAAC;IAElB,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QAChB,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC/B,CAAC;SAAM,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QACvB,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;IAC5C,CAAC;SAAM,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QACvB,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IAChD,CAAC;SAAM,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QACvB,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;IACpD,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAe;IACrC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/**\n * QUIC variable-length integer encoding and decoding.\n * https://www.rfc-editor.org/rfc/rfc9000#section-16\n *\n * @module\n */\n\n/** Largest value that fits in a 1-byte varint (6 bits). */\nexport const MAX_U6 = 2 ** 6 - 1;\n/** Largest value that fits in a 2-byte varint (14 bits). */\nexport const MAX_U14 = 2 ** 14 - 1;\n/** Largest value that fits in a 4-byte varint (30 bits). */\nexport const MAX_U30 = 2 ** 30 - 1;\n/** Largest value representable without precision loss (`Number.MAX_SAFE_INTEGER`, 53 bits). */\nexport const MAX_U53 = Number.MAX_SAFE_INTEGER;\n\n// Leading-ones varint encoding/decoding (draft-17 Section 1.4.1)\n// Encoding scheme:\n// 0xxxxxxx → 1 byte (7 bits)\n// 10xxxxxx + 1B → 2 bytes (14 bits)\n// 110xxxxx + 2B → 3 bytes (21 bits)\n// 1110xxxx + 3B → 4 bytes (28 bits)\n// 11110xxx + 4B → 5 bytes (35 bits)\n// 111110xx + 5B → 6 bytes (42 bits)\n// 1111110x + 6B → 7 bytes (49 bits), draft-18+ only (invalid in draft-17 per #1595)\n// 11111110 + 7B → 8 bytes (56 bits)\n// 11111111 + 8B → 9 bytes (64 bits)\n\nconst MAX_U64 = (1n << 64n) - 1n;\n\n/** Number of bytes needed to encode a value in the leading-ones varint format. */\nexport function sizeLeadingOnes(v: number | bigint): number {\n\tconst b = BigInt(v);\n\tif (b < 0n) throw new RangeError(`value is negative: ${v}`);\n\tif (b > MAX_U64) throw new RangeError(`value exceeds 64 bits: ${v}`);\n\tif (b < 1n << 7n) return 1;\n\tif (b < 1n << 14n) return 2;\n\tif (b < 1n << 21n) return 3;\n\tif (b < 1n << 28n) return 4;\n\tif (b < 1n << 35n) return 5;\n\tif (b < 1n << 42n) return 6;\n\tif (b < 1n << 56n) return 8;\n\treturn 9;\n}\n\n/** Encode a value in leading-ones varint format into the provided buffer, returning the written subarray. */\nexport function encodeLeadingOnesTo(dst: ArrayBuffer, v: number | bigint): Uint8Array {\n\tconst x = BigInt(v);\n\tif (x < 0n) throw new RangeError(`underflow, value is negative: ${v}`);\n\tif (x > MAX_U64) throw new RangeError(`value exceeds 64 bits: ${v}`);\n\n\tconst view = new DataView(dst);\n\n\tif (x < 1n << 7n) {\n\t\tview.setUint8(0, Number(x));\n\t\treturn new Uint8Array(dst, 0, 1);\n\t}\n\tif (x < 1n << 14n) {\n\t\tview.setUint8(0, 0x80 | Number(x >> 8n));\n\t\tview.setUint8(1, Number(x & 0xffn));\n\t\treturn new Uint8Array(dst, 0, 2);\n\t}\n\tif (x < 1n << 21n) {\n\t\tview.setUint8(0, 0xc0 | Number(x >> 16n));\n\t\tview.setUint16(1, Number(x & 0xffffn));\n\t\treturn new Uint8Array(dst, 0, 3);\n\t}\n\tif (x < 1n << 28n) {\n\t\tview.setUint8(0, 0xe0 | Number(x >> 24n));\n\t\tview.setUint8(1, Number((x >> 16n) & 0xffn));\n\t\tview.setUint16(2, Number(x & 0xffffn));\n\t\treturn new Uint8Array(dst, 0, 4);\n\t}\n\tif (x < 1n << 35n) {\n\t\tview.setUint8(0, 0xf0 | Number(x >> 32n));\n\t\tview.setUint32(1, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 5);\n\t}\n\tif (x < 1n << 42n) {\n\t\tview.setUint8(0, 0xf8 | Number(x >> 40n));\n\t\tview.setUint8(1, Number((x >> 32n) & 0xffn));\n\t\tview.setUint32(2, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 6);\n\t}\n\tif (x < 1n << 56n) {\n\t\t// 11111110 + 7 bytes\n\t\tview.setUint8(0, 0xfe);\n\t\tview.setUint8(1, Number((x >> 48n) & 0xffn));\n\t\tview.setUint16(2, Number((x >> 32n) & 0xffffn));\n\t\tview.setUint32(4, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 8);\n\t}\n\t// 11111111 + 8 bytes\n\tview.setUint8(0, 0xff);\n\tview.setBigUint64(1, x);\n\treturn new Uint8Array(dst, 0, 9);\n}\n\n/** Encode a value in leading-ones varint format into a freshly allocated buffer. */\nexport function encodeLeadingOnes(v: number | bigint): Uint8Array {\n\treturn encodeLeadingOnesTo(new ArrayBuffer(9), v);\n}\n\n/** Decode a leading-ones varint, returning the value and the remaining buffer. */\nexport function decodeLeadingOnes(buf: Uint8Array): [bigint, Uint8Array] {\n\tif (buf.length === 0) throw new Error(\"buffer is empty\");\n\n\tconst b = buf[0];\n\t// Count leading 1-bits\n\tlet ones = 0;\n\tfor (let bit = 7; bit >= 0; bit--) {\n\t\tif (b & (1 << bit)) ones++;\n\t\telse break;\n\t}\n\n\t// 1111110x is a 7-byte form: invalid on draft-17, allowed on draft-18+ per #1595.\n\t// This standalone decoder is permissive (Postel-style) since we lack version context here.\n\n\tlet totalSize: number;\n\tif (ones <= 5) totalSize = ones + 1;\n\telse if (ones === 6) totalSize = 7;\n\telse if (ones === 7) totalSize = 8;\n\telse totalSize = 9; // ones === 8\n\n\tif (buf.length < totalSize) {\n\t\tthrow new Error(`buffer too short: need ${totalSize} bytes, have ${buf.length}`);\n\t}\n\n\tconst view = new DataView(buf.buffer, buf.byteOffset, totalSize);\n\tconst remain = buf.subarray(totalSize);\n\tlet value: bigint;\n\n\tswitch (ones) {\n\t\tcase 0:\n\t\t\tvalue = BigInt(b);\n\t\t\tbreak;\n\t\tcase 1:\n\t\t\tvalue = (BigInt(b & 0x3f) << 8n) | BigInt(buf[1]);\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tvalue = (BigInt(b & 0x1f) << 16n) | BigInt(view.getUint16(1));\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tvalue = (BigInt(b & 0x0f) << 24n) | (BigInt(buf[1]) << 16n) | (BigInt(buf[2]) << 8n) | BigInt(buf[3]);\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tvalue = (BigInt(b & 0x07) << 32n) | BigInt(view.getUint32(1));\n\t\t\tbreak;\n\t\tcase 5:\n\t\t\tvalue =\n\t\t\t\t(BigInt(b & 0x03) << 40n) |\n\t\t\t\t(BigInt(buf[1]) << 32n) |\n\t\t\t\t(BigInt(buf[2]) << 24n) |\n\t\t\t\t(BigInt(buf[3]) << 16n) |\n\t\t\t\t(BigInt(buf[4]) << 8n) |\n\t\t\t\tBigInt(buf[5]);\n\t\t\tbreak;\n\t\tcase 6: {\n\t\t\t// 1111110x + 6 bytes = 49 bits (draft-18+)\n\t\t\tvalue =\n\t\t\t\t(BigInt(b & 0x01) << 48n) |\n\t\t\t\t(BigInt(buf[1]) << 40n) |\n\t\t\t\t(BigInt(buf[2]) << 32n) |\n\t\t\t\t(BigInt(buf[3]) << 24n) |\n\t\t\t\t(BigInt(buf[4]) << 16n) |\n\t\t\t\t(BigInt(buf[5]) << 8n) |\n\t\t\t\tBigInt(buf[6]);\n\t\t\tbreak;\n\t\t}\n\t\tcase 7: {\n\t\t\t// 11111110 + 7 bytes = 56 usable bits\n\t\t\tconst hi = new Uint8Array(8);\n\t\t\thi[0] = 0;\n\t\t\thi.set(buf.subarray(1, 8), 1);\n\t\t\tvalue = new DataView(hi.buffer).getBigUint64(0);\n\t\t\tbreak;\n\t\t}\n\t\tcase 8: {\n\t\t\t// 11111111 + 8 bytes = 64 bits\n\t\t\tvalue = new DataView(buf.buffer, buf.byteOffset + 1, 8).getBigUint64(0);\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(\"impossible\");\n\t}\n\n\treturn [value, remain];\n}\n\n/**\n * Returns the number of bytes needed to encode a value as a varint.\n */\nexport function size(v: number): number {\n\tif (v <= MAX_U6) return 1;\n\tif (v <= MAX_U14) return 2;\n\tif (v <= MAX_U30) return 4;\n\tif (v <= MAX_U53) return 8;\n\tthrow new Error(`overflow, value larger than 53-bits: ${v}`);\n}\n\n// Helper functions for writing to an ArrayBuffer\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 setUint32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setUint32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setUint64(dst: ArrayBuffer, v: bigint): Uint8Array {\n\tconst view = new DataView(dst, 0, 8);\n\tview.setBigUint64(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nconst MAX_U62 = 2n ** 62n - 1n;\n\n/**\n * Encodes a number or bigint into a scratch buffer.\n * Used by stream.ts to avoid allocations.\n */\nexport function encodeTo(dst: ArrayBuffer, v: number | bigint): Uint8Array {\n\tconst b = BigInt(v);\n\tif (b < 0n) {\n\t\tthrow new Error(`underflow, value is negative: ${v}`);\n\t}\n\tif (b > MAX_U62) {\n\t\tthrow new Error(`overflow, value larger than 62-bits: ${v}`);\n\t}\n\tconst n = Number(b);\n\tif (n <= MAX_U6) {\n\t\treturn setUint8(dst, n);\n\t}\n\tif (n <= MAX_U14) {\n\t\treturn setUint16(dst, n | 0x4000);\n\t}\n\tif (n <= MAX_U30) {\n\t\treturn setUint32(dst, n | 0x80000000);\n\t}\n\treturn setUint64(dst, b | 0xc000000000000000n);\n}\n\n/**\n * Encodes a number or bigint as a QUIC variable-length integer.\n * Returns a new Uint8Array containing the encoded bytes.\n */\nexport function encode(v: number | bigint): Uint8Array {\n\treturn encodeTo(new ArrayBuffer(8), v);\n}\n\n/**\n * Decodes a QUIC variable-length integer exactly from a buffer.\n * Returns a tuple of [value, remaining buffer].\n */\nexport function decodeBigInt(buf: Uint8Array): [bigint, Uint8Array] {\n\tif (buf.length === 0) {\n\t\tthrow new Error(\"buffer is empty\");\n\t}\n\n\tconst size = 1 << ((buf[0] & 0xc0) >> 6);\n\n\tif (buf.length < size) {\n\t\tthrow new Error(`buffer too short: need ${size} bytes, have ${buf.length}`);\n\t}\n\n\tconst view = new DataView(buf.buffer, buf.byteOffset, size);\n\tconst remain = buf.subarray(size);\n\n\tlet value: bigint;\n\n\tif (size === 1) {\n\t\tvalue = BigInt(buf[0] & 0x3f);\n\t} else if (size === 2) {\n\t\tvalue = BigInt(view.getUint16(0) & 0x3fff);\n\t} else if (size === 4) {\n\t\tvalue = BigInt(view.getUint32(0) & 0x3fffffff);\n\t} else if (size === 8) {\n\t\tvalue = view.getBigUint64(0) & 0x3fffffffffffffffn;\n\t} else {\n\t\tthrow new Error(\"impossible\");\n\t}\n\n\treturn [value, remain];\n}\n\n/**\n * Decodes a QUIC variable-length integer from a buffer.\n * Values above 53 bits lose precision; use {@link decodeBigInt} for exact decoding.\n */\nexport function decode(buf: Uint8Array): [number, Uint8Array] {\n\tconst [value, remain] = decodeBigInt(buf);\n\treturn [Number(value), remain];\n}\n"]}
|
package/zod.d.ts
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type * as z from "zod/mini";
|
|
7
|
-
import type
|
|
8
|
-
import type
|
|
6
|
+
import type * as z from "@zod/mini";
|
|
7
|
+
import type * as group from "./group";
|
|
8
|
+
import type * as track from "./track";
|
|
9
9
|
/** Read the next JSON frame and validate it against the schema. Returns undefined at end of stream. */
|
|
10
|
-
export declare function read<T = unknown>(source:
|
|
10
|
+
export declare function read<T = unknown>(source: track.Subscriber | group.Consumer, schema: z.ZodMiniType<T>): Promise<T | undefined>;
|
|
11
11
|
/** Validate a value against the schema, then write it as a JSON frame. */
|
|
12
|
-
export declare function write<T = unknown>(source:
|
|
12
|
+
export declare function write<T = unknown>(source: track.Producer | group.Producer, value: T, schema: z.ZodMiniType<T>): void;
|
|
13
13
|
//# sourceMappingURL=zod.d.ts.map
|
package/zod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,CAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AAEzC,uGAAuG;AACvG,wBAAsB,IAAI,CAAC,CAAC,GAAG,OAAO,EACrC,MAAM,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,QAAQ,EACzC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAIxB;AAED,0EAA0E;AAC1E,wBAAgB,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAG7G"}
|
package/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,IAAI,
|
|
1
|
+
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,IAAI,CACzB,MAAyC,EACzC,MAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;IACrC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,CAAC,sDAAsD;IAChG,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,KAAK,CAAc,MAAuC,EAAE,KAAQ,EAAE,MAAwB;IAC7G,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * Helpers for reading and writing Zod-validated JSON frames on a track or group.\n *\n * @module\n */\n\nimport type * as z from \"@zod/mini\";\nimport type * as group from \"./group.ts\";\nimport type * as track from \"./track.ts\";\n\n/** Read the next JSON frame and validate it against the schema. Returns undefined at end of stream. */\nexport async function read<T = unknown>(\n\tsource: track.Subscriber | group.Consumer,\n\tschema: z.ZodMiniType<T>,\n): Promise<T | undefined> {\n\tconst next = await source.readJson();\n\tif (next === undefined) return undefined; // only treat undefined as EOF, not other falsy values\n\treturn schema.parse(next);\n}\n\n/** Validate a value against the schema, then write it as a JSON frame. */\nexport function write<T = unknown>(source: track.Producer | group.Producer, value: T, schema: z.ZodMiniType<T>) {\n\tconst valid = schema.parse(value);\n\tsource.writeJson(valid);\n}\n"]}
|
package/bandwidth.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Signal } from "@norskvideo/moq-signals";
|
|
2
|
-
/**
|
|
3
|
-
* A bandwidth estimate in bits per second, or undefined if unknown.
|
|
4
|
-
*
|
|
5
|
-
* This is a Signal that can be read synchronously via `peek()`,
|
|
6
|
-
* observed reactively via `effect.get()`, or updated via `set()`.
|
|
7
|
-
*/
|
|
8
|
-
export type Bandwidth = Signal<number | undefined>;
|
|
9
|
-
/** Create a new bandwidth signal. */
|
|
10
|
-
export declare function createBandwidth(): Bandwidth;
|
|
11
|
-
//# sourceMappingURL=bandwidth.d.ts.map
|
package/bandwidth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bandwidth.d.ts","sourceRoot":"","sources":["../src/bandwidth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAEnD,qCAAqC;AACrC,wBAAgB,eAAe,IAAI,SAAS,CAE3C"}
|
package/bandwidth.js
DELETED
package/bandwidth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bandwidth.js","sourceRoot":"","sources":["../src/bandwidth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAUtC,qCAAqC;AACrC,MAAM,UAAU,eAAe;IAC9B,OAAO,IAAI,MAAM,CAAqB,SAAS,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import { Signal } from \"@moq/signals\";\n\n/**\n * A bandwidth estimate in bits per second, or undefined if unknown.\n *\n * This is a Signal that can be read synchronously via `peek()`,\n * observed reactively via `effect.get()`, or updated via `set()`.\n */\nexport type Bandwidth = Signal<number | undefined>;\n\n/** Create a new bandwidth signal. */\nexport function createBandwidth(): Bandwidth {\n\treturn new Signal<number | undefined>(undefined);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cert.test.d.ts","sourceRoot":"","sources":["../../src/connection/cert.test.ts"],"names":[],"mappings":""}
|
package/connection/cert.test.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./cert.test.d.ts" */
|
|
2
|
-
import { expect, test } from "bun:test";
|
|
3
|
-
import * as Hex from "../util/hex.js";
|
|
4
|
-
import { certificateHash } from "./connect.js";
|
|
5
|
-
// SHA-256("abc"), a well-known test vector. We feed "abc" as the cert bytes so
|
|
6
|
-
// the expected digest is independent of our own implementation.
|
|
7
|
-
const ABC = new TextEncoder().encode("abc");
|
|
8
|
-
const ABC_SHA256 = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
|
|
9
|
-
test("certificateHash hashes raw DER bytes", async () => {
|
|
10
|
-
const hash = await certificateHash(ABC);
|
|
11
|
-
expect(Hex.fromBytes(hash)).toBe(ABC_SHA256);
|
|
12
|
-
});
|
|
13
|
-
test("certificateHash decodes PEM armor before hashing", async () => {
|
|
14
|
-
// base64("abc") === "YWJj"
|
|
15
|
-
const pem = "-----BEGIN CERTIFICATE-----\nYWJj\n-----END CERTIFICATE-----\n";
|
|
16
|
-
const hash = await certificateHash(pem);
|
|
17
|
-
expect(Hex.fromBytes(hash)).toBe(ABC_SHA256);
|
|
18
|
-
});
|
|
19
|
-
test("certificateHash rejects a PEM string without armor", async () => {
|
|
20
|
-
// Valid base64, but no -----BEGIN CERTIFICATE----- wrapper.
|
|
21
|
-
await expect(certificateHash("YWJj")).rejects.toThrow(/armor/);
|
|
22
|
-
});
|
|
23
|
-
test("hex round-trips through fromBytes/toBytes", () => {
|
|
24
|
-
expect(Hex.fromBytes(Hex.toBytes(ABC_SHA256))).toBe(ABC_SHA256);
|
|
25
|
-
});
|
|
26
|
-
//# sourceMappingURL=cert.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cert.test.js","sourceRoot":"","sources":["../../src/connection/cert.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,+EAA+E;AAC/E,gEAAgE;AAChE,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5C,MAAM,UAAU,GAAG,kEAAkE,CAAC;AAEtF,IAAI,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;IACvD,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;IACnE,2BAA2B;IAC3B,MAAM,GAAG,GAAG,gEAAgE,CAAC;IAC7E,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,oDAAoD,EAAE,KAAK,IAAI,EAAE;IACrE,4DAA4D;IAC5D,MAAM,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACtD,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACjE,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Hex from \"../util/hex.ts\";\nimport { certificateHash } from \"./connect.ts\";\n\n// SHA-256(\"abc\"), a well-known test vector. We feed \"abc\" as the cert bytes so\n// the expected digest is independent of our own implementation.\nconst ABC = new TextEncoder().encode(\"abc\");\nconst ABC_SHA256 = \"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\";\n\ntest(\"certificateHash hashes raw DER bytes\", async () => {\n\tconst hash = await certificateHash(ABC);\n\texpect(Hex.fromBytes(hash)).toBe(ABC_SHA256);\n});\n\ntest(\"certificateHash decodes PEM armor before hashing\", async () => {\n\t// base64(\"abc\") === \"YWJj\"\n\tconst pem = \"-----BEGIN CERTIFICATE-----\\nYWJj\\n-----END CERTIFICATE-----\\n\";\n\tconst hash = await certificateHash(pem);\n\texpect(Hex.fromBytes(hash)).toBe(ABC_SHA256);\n});\n\ntest(\"certificateHash rejects a PEM string without armor\", async () => {\n\t// Valid base64, but no -----BEGIN CERTIFICATE----- wrapper.\n\tawait expect(certificateHash(\"YWJj\")).rejects.toThrow(/armor/);\n});\n\ntest(\"hex round-trips through fromBytes/toBytes\", () => {\n\texpect(Hex.fromBytes(Hex.toBytes(ABC_SHA256))).toBe(ABC_SHA256);\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reload.test.d.ts","sourceRoot":"","sources":["../../src/connection/reload.test.ts"],"names":[],"mappings":""}
|