@moq/net 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/README.md +2 -2
  2. package/announce.d.ts +7 -0
  3. package/announce.d.ts.map +1 -0
  4. package/announce.js +8 -0
  5. package/announce.js.map +1 -0
  6. package/announced.d.ts +35 -91
  7. package/announced.d.ts.map +1 -1
  8. package/announced.js +21 -156
  9. package/announced.js.map +1 -1
  10. package/bandwidth.d.ts +163 -0
  11. package/bandwidth.d.ts.map +1 -0
  12. package/bandwidth.js +304 -0
  13. package/bandwidth.js.map +1 -0
  14. package/bandwidth_api.d.ts +7 -0
  15. package/bandwidth_api.d.ts.map +1 -0
  16. package/bandwidth_api.js +8 -0
  17. package/bandwidth_api.js.map +1 -0
  18. package/broadcast.d.ts +20 -28
  19. package/broadcast.d.ts.map +1 -1
  20. package/broadcast.js +60 -42
  21. package/broadcast.js.map +1 -1
  22. package/connection/accept.d.ts +16 -1
  23. package/connection/accept.d.ts.map +1 -1
  24. package/connection/accept.js +39 -24
  25. package/connection/accept.js.map +1 -1
  26. package/connection/browser.d.ts.map +1 -1
  27. package/connection/browser.js +9 -7
  28. package/connection/browser.js.map +1 -1
  29. package/connection/connect.d.ts +30 -6
  30. package/connection/connect.d.ts.map +1 -1
  31. package/connection/connect.js +97 -50
  32. package/connection/connect.js.map +1 -1
  33. package/connection/established.d.ts +16 -21
  34. package/connection/established.d.ts.map +1 -1
  35. package/connection/established.js.map +1 -1
  36. package/connection/forward.d.ts +2 -0
  37. package/connection/forward.d.ts.map +1 -0
  38. package/connection/forward.js +159 -0
  39. package/connection/forward.js.map +1 -0
  40. package/connection/handshake.d.ts.map +1 -1
  41. package/connection/handshake.js +2 -2
  42. package/connection/handshake.js.map +1 -1
  43. package/connection/index.d.ts +5 -5
  44. package/connection/index.d.ts.map +1 -1
  45. package/connection/index.js +4 -5
  46. package/connection/index.js.map +1 -1
  47. package/connection/pool.d.ts +188 -0
  48. package/connection/pool.d.ts.map +1 -0
  49. package/connection/pool.js +351 -0
  50. package/connection/pool.js.map +1 -0
  51. package/connection/reload.d.ts +14 -93
  52. package/connection/reload.d.ts.map +1 -1
  53. package/connection/reload.js +216 -80
  54. package/connection/reload.js.map +1 -1
  55. package/connection/stats.d.ts +3 -26
  56. package/connection/stats.d.ts.map +1 -1
  57. package/connection/stats.js.map +1 -1
  58. package/connection/transport.d.ts +0 -7
  59. package/connection/transport.d.ts.map +1 -1
  60. package/consume.d.ts +1 -43
  61. package/consume.d.ts.map +1 -1
  62. package/consume.js +1 -1
  63. package/consume.js.map +1 -1
  64. package/error.d.ts +180 -29
  65. package/error.d.ts.map +1 -1
  66. package/error.js +310 -16
  67. package/error.js.map +1 -1
  68. package/errors.d.ts +7 -0
  69. package/errors.d.ts.map +1 -0
  70. package/errors.js +8 -0
  71. package/errors.js.map +1 -0
  72. package/group.d.ts +9 -43
  73. package/group.d.ts.map +1 -1
  74. package/group.js +283 -69
  75. package/group.js.map +1 -1
  76. package/hop.d.ts +107 -0
  77. package/hop.d.ts.map +1 -0
  78. package/hop.js +103 -0
  79. package/hop.js.map +1 -0
  80. package/ietf/aliases.d.ts +1 -78
  81. package/ietf/aliases.d.ts.map +1 -1
  82. package/ietf/cluster.d.ts +6 -120
  83. package/ietf/cluster.d.ts.map +1 -1
  84. package/ietf/cluster.js +81 -41
  85. package/ietf/cluster.js.map +1 -1
  86. package/ietf/connection.d.ts +6 -72
  87. package/ietf/connection.d.ts.map +1 -1
  88. package/ietf/connection.js +11 -47
  89. package/ietf/connection.js.map +1 -1
  90. package/ietf/error.d.ts +11 -0
  91. package/ietf/error.d.ts.map +1 -0
  92. package/ietf/error.js +168 -0
  93. package/ietf/error.js.map +1 -0
  94. package/ietf/filter.d.ts.map +1 -1
  95. package/ietf/filter.js +6 -1
  96. package/ietf/filter.js.map +1 -1
  97. package/ietf/goaway.d.ts.map +1 -1
  98. package/ietf/goaway.js +22 -5
  99. package/ietf/goaway.js.map +1 -1
  100. package/ietf/parameters.d.ts +2 -2
  101. package/ietf/parameters.d.ts.map +1 -1
  102. package/ietf/parameters.js +15 -17
  103. package/ietf/parameters.js.map +1 -1
  104. package/ietf/publish_namespace.d.ts +25 -0
  105. package/ietf/publish_namespace.d.ts.map +1 -1
  106. package/ietf/publish_namespace.js +63 -0
  107. package/ietf/publish_namespace.js.map +1 -1
  108. package/ietf/publisher.d.ts +1 -82
  109. package/ietf/publisher.d.ts.map +1 -1
  110. package/ietf/publisher.js +219 -125
  111. package/ietf/publisher.js.map +1 -1
  112. package/ietf/solicit.d.ts +1 -40
  113. package/ietf/solicit.d.ts.map +1 -1
  114. package/ietf/subscribe.d.ts +1 -5
  115. package/ietf/subscribe.d.ts.map +1 -1
  116. package/ietf/subscribe.js +8 -9
  117. package/ietf/subscribe.js.map +1 -1
  118. package/ietf/subscriber.d.ts +1 -65
  119. package/ietf/subscriber.d.ts.map +1 -1
  120. package/ietf/subscriber.js +154 -73
  121. package/ietf/subscriber.js.map +1 -1
  122. package/ietf/version.d.ts +12 -1
  123. package/ietf/version.d.ts.map +1 -1
  124. package/ietf/version.js +13 -0
  125. package/ietf/version.js.map +1 -1
  126. package/index.d.ts +11 -6
  127. package/index.d.ts.map +1 -1
  128. package/index.js +10 -5
  129. package/index.js.map +1 -1
  130. package/internal.d.ts +99 -1
  131. package/internal.d.ts.map +1 -1
  132. package/internal.js +65 -0
  133. package/internal.js.map +1 -1
  134. package/lite/announce.d.ts +15 -9
  135. package/lite/announce.d.ts.map +1 -1
  136. package/lite/announce.js +47 -20
  137. package/lite/announce.js.map +1 -1
  138. package/lite/connection.d.ts +9 -59
  139. package/lite/connection.d.ts.map +1 -1
  140. package/lite/connection.js +20 -32
  141. package/lite/connection.js.map +1 -1
  142. package/lite/fetch.d.ts +15 -1
  143. package/lite/fetch.d.ts.map +1 -1
  144. package/lite/fetch.js +39 -7
  145. package/lite/fetch.js.map +1 -1
  146. package/lite/goaway.d.ts.map +1 -1
  147. package/lite/goaway.js +7 -1
  148. package/lite/goaway.js.map +1 -1
  149. package/lite/group.d.ts +18 -4
  150. package/lite/group.d.ts.map +1 -1
  151. package/lite/group.js +31 -10
  152. package/lite/group.js.map +1 -1
  153. package/lite/priority.d.ts +1 -61
  154. package/lite/priority.d.ts.map +1 -1
  155. package/lite/priority.js +4 -5
  156. package/lite/priority.js.map +1 -1
  157. package/lite/publisher.d.ts +1 -69
  158. package/lite/publisher.d.ts.map +1 -1
  159. package/lite/publisher.js +559 -232
  160. package/lite/publisher.js.map +1 -1
  161. package/lite/setup.d.ts +7 -7
  162. package/lite/setup.d.ts.map +1 -1
  163. package/lite/setup.js +13 -13
  164. package/lite/setup.js.map +1 -1
  165. package/lite/subscribe.d.ts +61 -13
  166. package/lite/subscribe.d.ts.map +1 -1
  167. package/lite/subscribe.js +186 -44
  168. package/lite/subscribe.js.map +1 -1
  169. package/lite/subscriber.d.ts +8 -57
  170. package/lite/subscriber.d.ts.map +1 -1
  171. package/lite/subscriber.js +179 -117
  172. package/lite/subscriber.js.map +1 -1
  173. package/lite/track.d.ts +4 -10
  174. package/lite/track.d.ts.map +1 -1
  175. package/lite/track.js +34 -29
  176. package/lite/track.js.map +1 -1
  177. package/lite/version.d.ts +31 -6
  178. package/lite/version.d.ts.map +1 -1
  179. package/lite/version.js +71 -11
  180. package/lite/version.js.map +1 -1
  181. package/origin.d.ts +229 -29
  182. package/origin.d.ts.map +1 -1
  183. package/origin.js +1087 -37
  184. package/origin.js.map +1 -1
  185. package/package.json +3 -2
  186. package/path.d.ts +25 -7
  187. package/path.d.ts.map +1 -1
  188. package/path.js +5 -3
  189. package/path.js.map +1 -1
  190. package/stream.d.ts.map +1 -1
  191. package/stream.js +25 -16
  192. package/stream.js.map +1 -1
  193. package/time.d.ts +15 -2
  194. package/time.d.ts.map +1 -1
  195. package/time.js +28 -9
  196. package/time.js.map +1 -1
  197. package/track.d.ts +171 -82
  198. package/track.d.ts.map +1 -1
  199. package/track.js +633 -184
  200. package/track.js.map +1 -1
  201. package/util/log.d.ts +5 -0
  202. package/util/log.d.ts.map +1 -0
  203. package/util/log.js +17 -0
  204. package/util/log.js.map +1 -0
  205. package/wire.d.ts +67 -0
  206. package/wire.d.ts.map +1 -0
  207. package/wire.js +32 -0
  208. package/wire.js.map +1 -0
  209. package/zod.d.ts +1 -1
  210. package/zod.d.ts.map +1 -1
  211. package/zod.js.map +1 -1
  212. package/mock.d.ts +0 -66
  213. package/mock.d.ts.map +0 -1
  214. package/mock.js +0 -243
  215. package/mock.js.map +0 -1
package/mock.d.ts DELETED
@@ -1,66 +0,0 @@
1
- /**
2
- * Mock WebTransport implementation for in-process testing.
3
- *
4
- * Creates paired client/server transports connected via TransformStreams.
5
- */
6
- import type { TransportStats } from "./connection/stats";
7
- import type { SendStream } from "./stream";
8
- /** A fake {@link WebTransport} backed by TransformStreams, paired with a peer. */
9
- export declare class MockTransport implements WebTransport {
10
- #private;
11
- readonly protocol: string;
12
- readonly ready: Promise<undefined>;
13
- readonly closed: Promise<WebTransportCloseInfo>;
14
- readonly incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalStream>;
15
- readonly incomingUnidirectionalStreams: ReadableStream<ReadableStream<Uint8Array>>;
16
- readonly datagrams: WebTransportDatagramDuplexStream;
17
- readonly congestionControl: WebTransportCongestionControl;
18
- readonly reliability: string;
19
- /**
20
- * Every outgoing stream this transport opened, in call order, split by stream kind. Each
21
- * carries a live {@link SendStream.sendOrder} (set when it opened, and by any later
22
- * re-rank), so a test can assert how the wire layer prioritized it. The mock always
23
- * delivers in creation order, so nothing else observes it.
24
- */
25
- readonly sendStreams: {
26
- uni: SendStream[];
27
- bidi: SendStream[];
28
- };
29
- constructor(protocol: string, datagramsEnabled?: boolean, datagramWritable?: DatagramWritableApi, datagramReadable?: boolean);
30
- setPeer(peer: MockTransport): void;
31
- createBidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WebTransportBidirectionalStream>;
32
- createUnidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WritableStream<Uint8Array>>;
33
- close(_closeInfo?: WebTransportCloseInfo): void;
34
- /** The snapshot {@link getStats} resolves with (default empty). */
35
- stats: TransportStats;
36
- getStats(): Promise<TransportStats>;
37
- }
38
- type DatagramWritableApi = "writable" | "createWritable" | "none";
39
- /** Options for {@link createMockTransportPair}. */
40
- export interface MockTransportOptions {
41
- /**
42
- * Whether the paired transports carry QUIC datagrams (default true). Set false to
43
- * simulate a transport that reports `maxDatagramSize` 0 (e.g. a qmux/WebSocket
44
- * session), so the wire layer must fall back to not sending datagrams.
45
- */
46
- datagrams?: boolean;
47
- /** Which outgoing datagram API shape the mock exposes. */
48
- datagramWritable?: DatagramWritableApi;
49
- /** Whether the incoming datagram readable stream is exposed. */
50
- datagramReadable?: boolean;
51
- /** The snapshot `getStats()` resolves with on both transports (default empty). */
52
- stats?: TransportStats;
53
- }
54
- /**
55
- * Creates a pair of connected MockTransport instances.
56
- *
57
- * @param protocol - The WebTransport protocol identifier (e.g. "moqt-17", "moql", "")
58
- * @param options - Optional behavior toggles for datagram availability
59
- * @returns An object containing `client` and `server` transports
60
- */
61
- export declare function createMockTransportPair(protocol?: string, options?: MockTransportOptions): {
62
- client: MockTransport;
63
- server: MockTransport;
64
- };
65
- export {};
66
- //# sourceMappingURL=mock.d.ts.map
package/mock.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqB9C,kFAAkF;AAClF,qBAAa,aAAc,YAAW,YAAY;;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,O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,kFAAkF;IAClF,KAAK,CAAC,EAAE,cAAc,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACtC,QAAQ,SAAK,EACb,OAAO,CAAC,EAAE,oBAAoB,GAC5B;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAYlD"}
package/mock.js DELETED
@@ -1,243 +0,0 @@
1
- /* @ts-self-types="./mock.d.ts" */
2
- /**
3
- * Mock WebTransport implementation for in-process testing.
4
- *
5
- * Creates paired client/server transports connected via TransformStreams.
6
- */
7
- // High watermark to prevent writes from blocking on backpressure.
8
- // Real WebTransport has kernel buffers; we simulate this with a large queue.
9
- const WRITABLE_STRATEGY = { highWaterMark: 256 };
10
- const READABLE_STRATEGY = { highWaterMark: 256 };
11
- function newStream() {
12
- return new TransformStream({
13
- // Copy each chunk to simulate real WebTransport's kernel-boundary copy.
14
- // Without this, Writer's scratch buffer reuse corrupts queued data.
15
- transform(chunk, controller) {
16
- controller.enqueue(new Uint8Array(chunk));
17
- },
18
- }, WRITABLE_STRATEGY, READABLE_STRATEGY);
19
- }
20
- /** A fake {@link WebTransport} backed by TransformStreams, paired with a peer. */
21
- export class MockTransport {
22
- protocol;
23
- ready;
24
- closed;
25
- incomingBidirectionalStreams;
26
- incomingUnidirectionalStreams;
27
- datagrams;
28
- congestionControl;
29
- reliability;
30
- /**
31
- * Every outgoing stream this transport opened, in call order, split by stream kind. Each
32
- * carries a live {@link SendStream.sendOrder} (set when it opened, and by any later
33
- * re-rank), so a test can assert how the wire layer prioritized it. The mock always
34
- * delivers in creation order, so nothing else observes it.
35
- */
36
- sendStreams = { uni: [], bidi: [] };
37
- #closeResolve;
38
- #bidiController;
39
- #uniController;
40
- // Incoming-datagram controller (only set when datagrams are enabled); the peer's
41
- // writable enqueues into it.
42
- #datagramController;
43
- // Reference to the peer so we can enqueue streams to them
44
- #peer;
45
- constructor(protocol, datagramsEnabled = true, datagramWritable = "writable", datagramReadable = true) {
46
- this.protocol = protocol;
47
- this.ready = Promise.resolve(undefined);
48
- this.closed = new Promise((resolve) => {
49
- this.#closeResolve = resolve;
50
- });
51
- this.incomingBidirectionalStreams = new ReadableStream({
52
- start: (controller) => {
53
- this.#bidiController = controller;
54
- },
55
- });
56
- this.incomingUnidirectionalStreams = new ReadableStream({
57
- start: (controller) => {
58
- this.#uniController = controller;
59
- },
60
- });
61
- this.congestionControl = "default";
62
- this.reliability = "supports-unreliable";
63
- if (datagramsEnabled) {
64
- // A real datagram duplex: writes enqueue into the peer's incoming readable,
65
- // so a peer pair actually exchanges datagrams (unlike a real qmux Session,
66
- // whose datagram streams are inert stubs).
67
- const readable = datagramReadable
68
- ? new ReadableStream({
69
- start: (controller) => {
70
- this.#datagramController = controller;
71
- },
72
- })
73
- : undefined;
74
- const writable = new WritableStream({
75
- write: (chunk) => {
76
- const peer = this.#peer;
77
- if (!peer)
78
- return;
79
- const controller = peer.#datagramController;
80
- if (!controller)
81
- return;
82
- try {
83
- // Copy so the caller's scratch buffer reuse can't corrupt queued data.
84
- controller.enqueue(new Uint8Array(chunk));
85
- }
86
- catch {
87
- // Peer closed; drop (datagrams are best-effort).
88
- }
89
- },
90
- });
91
- const datagrams = {
92
- readable,
93
- incomingHighWaterMark: 0,
94
- outgoingHighWaterMark: 0,
95
- incomingMaxAge: null,
96
- outgoingMaxAge: null,
97
- maxDatagramSize: 1200,
98
- };
99
- if (datagramWritable === "writable") {
100
- datagrams.writable = writable;
101
- }
102
- else if (datagramWritable === "createWritable") {
103
- datagrams.createWritable = () => writable;
104
- }
105
- this.datagrams = datagrams;
106
- }
107
- else {
108
- // Simulate a transport that doesn't carry datagrams (maxDatagramSize 0): the
109
- // wire layer must fall back to not sending, with no group fallback.
110
- this.datagrams = {
111
- readable: new ReadableStream(),
112
- writable: new WritableStream(),
113
- incomingHighWaterMark: 0,
114
- outgoingHighWaterMark: 0,
115
- incomingMaxAge: null,
116
- outgoingMaxAge: null,
117
- maxDatagramSize: 0,
118
- };
119
- }
120
- }
121
- setPeer(peer) {
122
- this.#peer = peer;
123
- }
124
- async createBidirectionalStream(options) {
125
- const peer = this.#peer;
126
- if (!peer)
127
- throw new Error("no peer");
128
- // Create two TransformStreams for the two directions
129
- const c2s = newStream();
130
- const s2c = newStream();
131
- // Local side: writes to c2s, reads from s2c
132
- const local = {
133
- readable: s2c.readable,
134
- writable: this.#sendStream(c2s.writable, this.sendStreams.bidi, options),
135
- };
136
- // Peer side: writes to s2c, reads from c2s
137
- const remote = {
138
- readable: c2s.readable,
139
- writable: s2c.writable,
140
- };
141
- try {
142
- peer.#bidiController.enqueue(remote);
143
- }
144
- catch {
145
- // Peer closed
146
- }
147
- return local;
148
- }
149
- async createUnidirectionalStream(options) {
150
- const peer = this.#peer;
151
- if (!peer)
152
- throw new Error("no peer");
153
- const c2s = newStream();
154
- // Record before handing the peer its end, so a peer that waits for the stream to arrive
155
- // always finds it here.
156
- const stream = this.#sendStream(c2s.writable, this.sendStreams.uni, options);
157
- try {
158
- peer.#uniController.enqueue(c2s.readable);
159
- }
160
- catch {
161
- // Peer closed
162
- }
163
- return stream;
164
- }
165
- // Give a writable the send order it opened with and record it, so a test sees both that
166
- // order and any later re-rank (which assigns the same property, as on a real send stream).
167
- #sendStream(writable, log, options) {
168
- const stream = writable;
169
- stream.sendOrder = options?.sendOrder;
170
- log.push(stream);
171
- return stream;
172
- }
173
- close(_closeInfo) {
174
- const info = _closeInfo ?? { closeCode: 0, reason: "" };
175
- this.#closeResolve(info);
176
- try {
177
- this.#bidiController.close();
178
- }
179
- catch {
180
- // Already closed
181
- }
182
- try {
183
- this.#uniController.close();
184
- }
185
- catch {
186
- // Already closed
187
- }
188
- try {
189
- this.#datagramController?.close();
190
- }
191
- catch {
192
- // Already closed
193
- }
194
- // Also close peer's incoming streams
195
- if (this.#peer) {
196
- try {
197
- this.#peer.#bidiController.close();
198
- }
199
- catch {
200
- // Already closed
201
- }
202
- try {
203
- this.#peer.#uniController.close();
204
- }
205
- catch {
206
- // Already closed
207
- }
208
- try {
209
- this.#peer.#datagramController?.close();
210
- }
211
- catch {
212
- // Already closed
213
- }
214
- this.#peer.#closeResolve(info);
215
- }
216
- }
217
- /** The snapshot {@link getStats} resolves with (default empty). */
218
- stats = {};
219
- async getStats() {
220
- return this.stats;
221
- }
222
- }
223
- /**
224
- * Creates a pair of connected MockTransport instances.
225
- *
226
- * @param protocol - The WebTransport protocol identifier (e.g. "moqt-17", "moql", "")
227
- * @param options - Optional behavior toggles for datagram availability
228
- * @returns An object containing `client` and `server` transports
229
- */
230
- export function createMockTransportPair(protocol = "", options) {
231
- const datagrams = options?.datagrams ?? true;
232
- const client = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);
233
- const server = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);
234
- if (options?.stats) {
235
- // Copy per side so a test advancing one transport's counters doesn't move the other's.
236
- client.stats = { ...options.stats };
237
- server.stats = { ...options.stats };
238
- }
239
- client.setPeer(server);
240
- server.setPeer(client);
241
- return { client, server };
242
- }
243
- //# sourceMappingURL=mock.js.map
package/mock.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,kEAAkE;AAClE,6EAA6E;AAC7E,MAAM,iBAAiB,GAAgC,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC;AAC9E,MAAM,iBAAiB,GAAgC,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC;AAE9E,SAAS,SAAS;IACjB,OAAO,IAAI,eAAe,CACzB;QACC,wEAAwE;QACxE,oEAAoE;QACpE,SAAS,CAAC,KAAK,EAAE,UAAU;YAC1B,UAAU,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC;KACD,EACD,iBAAiB,EACjB,iBAAiB,CACjB,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,MAAM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C;IACrC,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Mock WebTransport implementation for in-process testing.\n *\n * Creates paired client/server transports connected via TransformStreams.\n */\n\nimport type { TransportStats } from \"./connection/stats.ts\";\nimport type { SendStream } from \"./stream.ts\";\n\n// High watermark to prevent writes from blocking on backpressure.\n// Real WebTransport has kernel buffers; we simulate this with a large queue.\nconst WRITABLE_STRATEGY: QueuingStrategy<Uint8Array> = { highWaterMark: 256 };\nconst READABLE_STRATEGY: QueuingStrategy<Uint8Array> = { highWaterMark: 256 };\n\nfunction newStream(): TransformStream<Uint8Array, Uint8Array> {\n\treturn new TransformStream(\n\t\t{\n\t\t\t// Copy each chunk to simulate real WebTransport's kernel-boundary copy.\n\t\t\t// Without this, Writer's scratch buffer reuse corrupts queued data.\n\t\t\ttransform(chunk, controller) {\n\t\t\t\tcontroller.enqueue(new Uint8Array(chunk));\n\t\t\t},\n\t\t},\n\t\tWRITABLE_STRATEGY,\n\t\tREADABLE_STRATEGY,\n\t);\n}\n\n/** A fake {@link WebTransport} backed by TransformStreams, paired with a peer. */\nexport class MockTransport implements WebTransport {\n\treadonly protocol: string;\n\treadonly ready: Promise<undefined>;\n\treadonly closed: Promise<WebTransportCloseInfo>;\n\n\treadonly incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalStream>;\n\treadonly incomingUnidirectionalStreams: ReadableStream<ReadableStream<Uint8Array>>;\n\n\treadonly datagrams: WebTransportDatagramDuplexStream;\n\treadonly congestionControl: WebTransportCongestionControl;\n\treadonly reliability: string;\n\n\t/**\n\t * Every outgoing stream this transport opened, in call order, split by stream kind. Each\n\t * carries a live {@link SendStream.sendOrder} (set when it opened, and by any later\n\t * re-rank), so a test can assert how the wire layer prioritized it. The mock always\n\t * delivers in creation order, so nothing else observes it.\n\t */\n\treadonly sendStreams: { uni: SendStream[]; bidi: SendStream[] } = { uni: [], bidi: [] };\n\n\t#closeResolve!: (info: WebTransportCloseInfo) => void;\n\t#bidiController!: ReadableStreamDefaultController<WebTransportBidirectionalStream>;\n\t#uniController!: ReadableStreamDefaultController<ReadableStream<Uint8Array>>;\n\t// Incoming-datagram controller (only set when datagrams are enabled); the peer's\n\t// writable enqueues into it.\n\t#datagramController?: ReadableStreamDefaultController<Uint8Array>;\n\n\t// Reference to the peer so we can enqueue streams to them\n\t#peer?: MockTransport;\n\n\tconstructor(\n\t\tprotocol: string,\n\t\tdatagramsEnabled = true,\n\t\tdatagramWritable: DatagramWritableApi = \"writable\",\n\t\tdatagramReadable = true,\n\t) {\n\t\tthis.protocol = protocol;\n\t\tthis.ready = Promise.resolve(undefined);\n\t\tthis.closed = new Promise((resolve) => {\n\t\t\tthis.#closeResolve = resolve;\n\t\t});\n\n\t\tthis.incomingBidirectionalStreams = new ReadableStream({\n\t\t\tstart: (controller) => {\n\t\t\t\tthis.#bidiController = controller;\n\t\t\t},\n\t\t});\n\n\t\tthis.incomingUnidirectionalStreams = new ReadableStream({\n\t\t\tstart: (controller) => {\n\t\t\t\tthis.#uniController = controller;\n\t\t\t},\n\t\t});\n\n\t\tthis.congestionControl = \"default\";\n\t\tthis.reliability = \"supports-unreliable\";\n\n\t\tif (datagramsEnabled) {\n\t\t\t// A real datagram duplex: writes enqueue into the peer's incoming readable,\n\t\t\t// so a peer pair actually exchanges datagrams (unlike a real qmux Session,\n\t\t\t// whose datagram streams are inert stubs).\n\t\t\tconst readable = datagramReadable\n\t\t\t\t? new ReadableStream<Uint8Array>({\n\t\t\t\t\t\tstart: (controller) => {\n\t\t\t\t\t\t\tthis.#datagramController = controller;\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t: undefined;\n\t\t\tconst writable = new WritableStream<Uint8Array>({\n\t\t\t\twrite: (chunk) => {\n\t\t\t\t\tconst peer = this.#peer;\n\t\t\t\t\tif (!peer) return;\n\t\t\t\t\tconst controller = peer.#datagramController;\n\t\t\t\t\tif (!controller) return;\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Copy so the caller's scratch buffer reuse can't corrupt queued data.\n\t\t\t\t\t\tcontroller.enqueue(new Uint8Array(chunk));\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Peer closed; drop (datagrams are best-effort).\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst datagrams: {\n\t\t\t\treadable?: ReadableStream<Uint8Array>;\n\t\t\t\twritable?: WritableStream<Uint8Array>;\n\t\t\t\tmaxDatagramSize: number;\n\t\t\t\tincomingHighWaterMark: number;\n\t\t\t\toutgoingHighWaterMark: number;\n\t\t\t\tincomingMaxAge: null;\n\t\t\t\toutgoingMaxAge: null;\n\t\t\t\tcreateWritable?: () => WritableStream<Uint8Array>;\n\t\t\t} = {\n\t\t\t\treadable,\n\t\t\t\tincomingHighWaterMark: 0,\n\t\t\t\toutgoingHighWaterMark: 0,\n\t\t\t\tincomingMaxAge: null,\n\t\t\t\toutgoingMaxAge: null,\n\t\t\t\tmaxDatagramSize: 1200,\n\t\t\t};\n\t\t\tif (datagramWritable === \"writable\") {\n\t\t\t\tdatagrams.writable = writable;\n\t\t\t} else if (datagramWritable === \"createWritable\") {\n\t\t\t\tdatagrams.createWritable = () => writable;\n\t\t\t}\n\t\t\tthis.datagrams = datagrams as WebTransportDatagramDuplexStream;\n\t\t} else {\n\t\t\t// Simulate a transport that doesn't carry datagrams (maxDatagramSize 0): the\n\t\t\t// wire layer must fall back to not sending, with no group fallback.\n\t\t\tthis.datagrams = {\n\t\t\t\treadable: new ReadableStream(),\n\t\t\t\twritable: new WritableStream(),\n\t\t\t\tincomingHighWaterMark: 0,\n\t\t\t\toutgoingHighWaterMark: 0,\n\t\t\t\tincomingMaxAge: null,\n\t\t\t\toutgoingMaxAge: null,\n\t\t\t\tmaxDatagramSize: 0,\n\t\t\t};\n\t\t}\n\t}\n\n\tsetPeer(peer: MockTransport) {\n\t\tthis.#peer = peer;\n\t}\n\n\tasync createBidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WebTransportBidirectionalStream> {\n\t\tconst peer = this.#peer;\n\t\tif (!peer) throw new Error(\"no peer\");\n\n\t\t// Create two TransformStreams for the two directions\n\t\tconst c2s = newStream();\n\t\tconst s2c = newStream();\n\n\t\t// Local side: writes to c2s, reads from s2c\n\t\tconst local = {\n\t\t\treadable: s2c.readable,\n\t\t\twritable: this.#sendStream(c2s.writable, this.sendStreams.bidi, options),\n\t\t} as WebTransportBidirectionalStream;\n\n\t\t// Peer side: writes to s2c, reads from c2s\n\t\tconst remote = {\n\t\t\treadable: c2s.readable,\n\t\t\twritable: s2c.writable,\n\t\t} as WebTransportBidirectionalStream;\n\n\t\ttry {\n\t\t\tpeer.#bidiController.enqueue(remote);\n\t\t} catch {\n\t\t\t// Peer closed\n\t\t}\n\n\t\treturn local;\n\t}\n\n\tasync createUnidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WritableStream<Uint8Array>> {\n\t\tconst peer = this.#peer;\n\t\tif (!peer) throw new Error(\"no peer\");\n\n\t\tconst c2s = newStream();\n\n\t\t// Record before handing the peer its end, so a peer that waits for the stream to arrive\n\t\t// always finds it here.\n\t\tconst stream = this.#sendStream(c2s.writable, this.sendStreams.uni, options);\n\n\t\ttry {\n\t\t\tpeer.#uniController.enqueue(c2s.readable);\n\t\t} catch {\n\t\t\t// Peer closed\n\t\t}\n\n\t\treturn stream;\n\t}\n\n\t// Give a writable the send order it opened with and record it, so a test sees both that\n\t// order and any later re-rank (which assigns the same property, as on a real send stream).\n\t#sendStream(\n\t\twritable: WritableStream<Uint8Array>,\n\t\tlog: SendStream[],\n\t\toptions?: WebTransportSendStreamOptions,\n\t): SendStream {\n\t\tconst stream = writable as SendStream;\n\t\tstream.sendOrder = options?.sendOrder;\n\t\tlog.push(stream);\n\t\treturn stream;\n\t}\n\n\tclose(_closeInfo?: WebTransportCloseInfo): void {\n\t\tconst info = _closeInfo ?? { closeCode: 0, reason: \"\" };\n\t\tthis.#closeResolve(info);\n\n\t\ttry {\n\t\t\tthis.#bidiController.close();\n\t\t} catch {\n\t\t\t// Already closed\n\t\t}\n\t\ttry {\n\t\t\tthis.#uniController.close();\n\t\t} catch {\n\t\t\t// Already closed\n\t\t}\n\n\t\ttry {\n\t\t\tthis.#datagramController?.close();\n\t\t} catch {\n\t\t\t// Already closed\n\t\t}\n\n\t\t// Also close peer's incoming streams\n\t\tif (this.#peer) {\n\t\t\ttry {\n\t\t\t\tthis.#peer.#bidiController.close();\n\t\t\t} catch {\n\t\t\t\t// Already closed\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.#peer.#uniController.close();\n\t\t\t} catch {\n\t\t\t\t// Already closed\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.#peer.#datagramController?.close();\n\t\t\t} catch {\n\t\t\t\t// Already closed\n\t\t\t}\n\t\t\tthis.#peer.#closeResolve(info);\n\t\t}\n\t}\n\n\t/** The snapshot {@link getStats} resolves with (default empty). */\n\tstats: TransportStats = {};\n\n\tasync getStats(): Promise<TransportStats> {\n\t\treturn this.stats;\n\t}\n}\n\ntype DatagramWritableApi = \"writable\" | \"createWritable\" | \"none\";\n\n/** Options for {@link createMockTransportPair}. */\nexport interface MockTransportOptions {\n\t/**\n\t * Whether the paired transports carry QUIC datagrams (default true). Set false to\n\t * simulate a transport that reports `maxDatagramSize` 0 (e.g. a qmux/WebSocket\n\t * session), so the wire layer must fall back to not sending datagrams.\n\t */\n\tdatagrams?: boolean;\n\n\t/** Which outgoing datagram API shape the mock exposes. */\n\tdatagramWritable?: DatagramWritableApi;\n\n\t/** Whether the incoming datagram readable stream is exposed. */\n\tdatagramReadable?: boolean;\n\n\t/** The snapshot `getStats()` resolves with on both transports (default empty). */\n\tstats?: TransportStats;\n}\n\n/**\n * Creates a pair of connected MockTransport instances.\n *\n * @param protocol - The WebTransport protocol identifier (e.g. \"moqt-17\", \"moql\", \"\")\n * @param options - Optional behavior toggles for datagram availability\n * @returns An object containing `client` and `server` transports\n */\nexport function createMockTransportPair(\n\tprotocol = \"\",\n\toptions?: MockTransportOptions,\n): { client: MockTransport; server: MockTransport } {\n\tconst datagrams = options?.datagrams ?? true;\n\tconst client = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);\n\tconst server = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);\n\tif (options?.stats) {\n\t\t// Copy per side so a test advancing one transport's counters doesn't move the other's.\n\t\tclient.stats = { ...options.stats };\n\t\tserver.stats = { ...options.stats };\n\t}\n\tclient.setPeer(server);\n\tserver.setPeer(client);\n\treturn { client, server };\n}\n"]}