@moq/net 0.3.5 → 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.
- package/announce.d.ts +7 -0
- package/announce.d.ts.map +1 -0
- package/announce.js +8 -0
- package/announce.js.map +1 -0
- package/announced.d.ts +35 -91
- package/announced.d.ts.map +1 -1
- package/announced.js +21 -156
- package/announced.js.map +1 -1
- package/bandwidth.d.ts +163 -0
- package/bandwidth.d.ts.map +1 -0
- package/bandwidth.js +304 -0
- package/bandwidth.js.map +1 -0
- package/bandwidth_api.d.ts +7 -0
- package/bandwidth_api.d.ts.map +1 -0
- package/bandwidth_api.js +8 -0
- package/bandwidth_api.js.map +1 -0
- package/broadcast.d.ts +20 -28
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +55 -38
- package/broadcast.js.map +1 -1
- package/connection/accept.d.ts +16 -1
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +39 -24
- package/connection/accept.js.map +1 -1
- package/connection/browser.d.ts.map +1 -1
- package/connection/browser.js +9 -7
- package/connection/browser.js.map +1 -1
- package/connection/connect.d.ts +30 -6
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +85 -45
- package/connection/connect.js.map +1 -1
- package/connection/established.d.ts +16 -21
- package/connection/established.d.ts.map +1 -1
- package/connection/established.js.map +1 -1
- package/connection/forward.d.ts +2 -0
- package/connection/forward.d.ts.map +1 -0
- package/connection/forward.js +159 -0
- package/connection/forward.js.map +1 -0
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +2 -2
- package/connection/handshake.js.map +1 -1
- package/connection/index.d.ts +5 -5
- package/connection/index.d.ts.map +1 -1
- package/connection/index.js +4 -5
- package/connection/index.js.map +1 -1
- package/connection/pool.d.ts +188 -0
- package/connection/pool.d.ts.map +1 -0
- package/connection/pool.js +351 -0
- package/connection/pool.js.map +1 -0
- package/connection/reload.d.ts +14 -93
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +216 -80
- package/connection/reload.js.map +1 -1
- package/connection/stats.d.ts +3 -26
- package/connection/stats.d.ts.map +1 -1
- package/connection/stats.js.map +1 -1
- package/connection/transport.d.ts +0 -7
- package/connection/transport.d.ts.map +1 -1
- package/consume.d.ts +1 -43
- package/consume.d.ts.map +1 -1
- package/consume.js +1 -1
- package/consume.js.map +1 -1
- package/error.d.ts +180 -29
- package/error.d.ts.map +1 -1
- package/error.js +310 -16
- package/error.js.map +1 -1
- package/errors.d.ts +7 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +8 -0
- package/errors.js.map +1 -0
- package/group.d.ts +9 -43
- package/group.d.ts.map +1 -1
- package/group.js +283 -69
- package/group.js.map +1 -1
- package/hop.d.ts +107 -0
- package/hop.d.ts.map +1 -0
- package/hop.js +103 -0
- package/hop.js.map +1 -0
- package/ietf/aliases.d.ts +1 -78
- package/ietf/aliases.d.ts.map +1 -1
- package/ietf/cluster.d.ts +6 -120
- package/ietf/cluster.d.ts.map +1 -1
- package/ietf/cluster.js +81 -41
- package/ietf/cluster.js.map +1 -1
- package/ietf/connection.d.ts +6 -72
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +11 -47
- package/ietf/connection.js.map +1 -1
- package/ietf/error.d.ts +11 -0
- package/ietf/error.d.ts.map +1 -0
- package/ietf/error.js +168 -0
- package/ietf/error.js.map +1 -0
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +6 -1
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +22 -5
- package/ietf/goaway.js.map +1 -1
- package/ietf/parameters.d.ts +2 -2
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +15 -17
- package/ietf/parameters.js.map +1 -1
- package/ietf/publish_namespace.d.ts +25 -0
- package/ietf/publish_namespace.d.ts.map +1 -1
- package/ietf/publish_namespace.js +63 -0
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.d.ts +1 -82
- package/ietf/publisher.d.ts.map +1 -1
- package/ietf/publisher.js +203 -136
- package/ietf/publisher.js.map +1 -1
- package/ietf/solicit.d.ts +1 -40
- package/ietf/solicit.d.ts.map +1 -1
- package/ietf/subscribe.d.ts +1 -5
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +8 -9
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscriber.d.ts +1 -65
- package/ietf/subscriber.d.ts.map +1 -1
- package/ietf/subscriber.js +154 -73
- package/ietf/subscriber.js.map +1 -1
- package/ietf/version.d.ts +12 -1
- package/ietf/version.d.ts.map +1 -1
- package/ietf/version.js +13 -0
- package/ietf/version.js.map +1 -1
- package/index.d.ts +11 -6
- package/index.d.ts.map +1 -1
- package/index.js +10 -5
- package/index.js.map +1 -1
- package/internal.d.ts +97 -1
- package/internal.d.ts.map +1 -1
- package/internal.js +65 -0
- package/internal.js.map +1 -1
- package/lite/announce.d.ts +15 -9
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +47 -20
- package/lite/announce.js.map +1 -1
- package/lite/connection.d.ts +9 -59
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +20 -32
- package/lite/connection.js.map +1 -1
- package/lite/fetch.d.ts +15 -1
- package/lite/fetch.d.ts.map +1 -1
- package/lite/fetch.js +39 -7
- package/lite/fetch.js.map +1 -1
- package/lite/goaway.d.ts.map +1 -1
- package/lite/goaway.js +7 -1
- package/lite/goaway.js.map +1 -1
- package/lite/group.d.ts +18 -4
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +31 -10
- package/lite/group.js.map +1 -1
- package/lite/priority.d.ts +1 -61
- package/lite/priority.d.ts.map +1 -1
- package/lite/priority.js +4 -5
- package/lite/priority.js.map +1 -1
- package/lite/publisher.d.ts +1 -69
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +507 -200
- package/lite/publisher.js.map +1 -1
- package/lite/setup.d.ts +7 -7
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +13 -13
- package/lite/setup.js.map +1 -1
- package/lite/subscribe.d.ts +61 -13
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +186 -44
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts +8 -57
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +179 -117
- package/lite/subscriber.js.map +1 -1
- package/lite/track.d.ts +4 -10
- package/lite/track.d.ts.map +1 -1
- package/lite/track.js +34 -29
- package/lite/track.js.map +1 -1
- package/lite/version.d.ts +31 -6
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +71 -11
- package/lite/version.js.map +1 -1
- package/origin.d.ts +229 -29
- package/origin.d.ts.map +1 -1
- package/origin.js +1087 -37
- package/origin.js.map +1 -1
- package/package.json +3 -2
- package/path.d.ts +25 -7
- package/path.d.ts.map +1 -1
- package/path.js +5 -3
- package/path.js.map +1 -1
- package/stream.d.ts.map +1 -1
- package/stream.js +23 -14
- package/stream.js.map +1 -1
- package/time.d.ts +15 -2
- package/time.d.ts.map +1 -1
- package/time.js +28 -9
- package/time.js.map +1 -1
- package/track.d.ts +166 -83
- package/track.d.ts.map +1 -1
- package/track.js +617 -187
- package/track.js.map +1 -1
- package/wire.d.ts +67 -0
- package/wire.d.ts.map +1 -0
- package/wire.js +32 -0
- package/wire.js.map +1 -0
- package/zod.d.ts +1 -1
- package/zod.d.ts.map +1 -1
- package/zod.js.map +1 -1
- package/mock.d.ts +0 -66
- package/mock.d.ts.map +0 -1
- package/mock.js +0 -243
- package/mock.js.map +0 -1
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,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AC,CAAC;IAC5G,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAC5G,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;QACpB,uFAAuF;QACvF,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;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"]}
|