@moq/net 0.1.9 → 0.2.1
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/announced.d.ts +40 -24
- package/announced.d.ts.map +1 -1
- package/announced.js +74 -40
- package/announced.js.map +1 -1
- package/announced.test.d.ts +2 -0
- package/announced.test.d.ts.map +1 -0
- package/announced.test.js +37 -0
- package/announced.test.js.map +1 -0
- package/broadcast.d.ts +80 -25
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +266 -49
- package/broadcast.js.map +1 -1
- package/broadcast.test.d.ts +2 -0
- package/broadcast.test.d.ts.map +1 -0
- package/broadcast.test.js +219 -0
- package/broadcast.test.js.map +1 -0
- package/connection/accept.d.ts +6 -0
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +30 -10
- 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 +25 -0
- package/connection/browser.js.map +1 -0
- package/connection/browser.test.d.ts +2 -0
- package/connection/browser.test.d.ts.map +1 -0
- package/connection/browser.test.js +29 -0
- package/connection/browser.test.js.map +1 -0
- package/connection/connect.d.ts +43 -1
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +96 -107
- package/connection/connect.js.map +1 -1
- package/connection/connect.test.d.ts +2 -0
- package/connection/connect.test.d.ts.map +1 -0
- package/connection/connect.test.js +118 -0
- package/connection/connect.test.js.map +1 -0
- package/connection/established.d.ts +29 -15
- package/connection/established.d.ts.map +1 -1
- package/connection/established.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 +43 -7
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +159 -62
- package/connection/reload.js.map +1 -1
- package/connection/reload.test.js +65 -0
- package/connection/reload.test.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/stats.test.d.ts +2 -0
- package/connection/stats.test.d.ts.map +1 -0
- package/connection/stats.test.js +120 -0
- package/connection/stats.test.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 +26 -0
- package/consume.d.ts.map +1 -0
- package/consume.js +40 -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 +62 -0
- package/error.d.ts.map +1 -0
- package/error.js +92 -0
- package/error.js.map +1 -0
- package/error.test.d.ts +2 -0
- package/error.test.d.ts.map +1 -0
- package/error.test.js +89 -0
- package/error.test.js.map +1 -0
- package/group.d.ts +125 -36
- package/group.d.ts.map +1 -1
- package/group.js +244 -67
- package/group.js.map +1 -1
- package/group.test.js +121 -35
- package/group.test.js.map +1 -1
- package/ietf/adapter.d.ts +2 -2
- package/ietf/adapter.d.ts.map +1 -1
- package/ietf/adapter.js +15 -5
- package/ietf/adapter.js.map +1 -1
- package/ietf/connection.d.ts +19 -6
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +23 -8
- package/ietf/connection.js.map +1 -1
- package/ietf/ietf.test.js +58 -1
- package/ietf/ietf.test.js.map +1 -1
- package/ietf/object.d.ts +12 -4
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +92 -9
- package/ietf/object.js.map +1 -1
- package/ietf/publisher.d.ts +2 -2
- package/ietf/publisher.d.ts.map +1 -1
- package/ietf/publisher.js +12 -12
- package/ietf/publisher.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts +0 -4
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +0 -5
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.d.ts +8 -4
- package/ietf/subscriber.d.ts.map +1 -1
- package/ietf/subscriber.js +171 -93
- package/ietf/subscriber.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/integration.test.js +634 -12
- package/integration.test.js.map +1 -1
- package/internal.d.ts +14 -0
- package/internal.d.ts.map +1 -0
- package/internal.js +8 -0
- package/internal.js.map +1 -0
- package/lite/announce.d.ts +55 -13
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +221 -68
- package/lite/announce.js.map +1 -1
- package/lite/announce.test.d.ts +2 -0
- package/lite/announce.test.d.ts.map +1 -0
- package/lite/announce.test.js +71 -0
- package/lite/announce.test.js.map +1 -0
- package/lite/connection.d.ts +45 -19
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +85 -80
- 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.test.d.ts +2 -0
- package/lite/datagram.test.d.ts.map +1 -0
- package/lite/datagram.test.js +26 -0
- package/lite/datagram.test.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/datagram_stream.test.d.ts +2 -0
- package/lite/datagram_stream.test.d.ts.map +1 -0
- package/lite/datagram_stream.test.js +15 -0
- package/lite/datagram_stream.test.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/fetch.test.d.ts +2 -0
- package/lite/fetch.test.d.ts.map +1 -0
- package/lite/fetch.test.js +41 -0
- package/lite/fetch.test.js.map +1 -0
- 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/publisher.d.ts +13 -6
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +274 -64
- package/lite/publisher.js.map +1 -1
- package/lite/publisher.test.d.ts +2 -0
- package/lite/publisher.test.d.ts.map +1 -0
- package/lite/publisher.test.js +65 -0
- package/lite/publisher.test.js.map +1 -0
- package/lite/setup.d.ts +72 -6
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +184 -31
- package/lite/setup.js.map +1 -1
- package/lite/setup.test.d.ts +2 -0
- package/lite/setup.test.d.ts.map +1 -0
- package/lite/setup.test.js +122 -0
- package/lite/setup.test.js.map +1 -0
- 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/subscribe.test.d.ts +2 -0
- package/lite/subscribe.test.d.ts.map +1 -0
- package/lite/subscribe.test.js +68 -0
- package/lite/subscribe.test.js.map +1 -0
- package/lite/subscriber.d.ts +24 -17
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +515 -90
- package/lite/subscriber.js.map +1 -1
- package/lite/subscriber.test.js +2 -2
- package/lite/subscriber.test.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/track.test.js +12 -10
- package/lite/track.test.js.map +1 -1
- package/lite/version.d.ts +17 -4
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +88 -17
- package/lite/version.js.map +1 -1
- package/mock.d.ts +42 -3
- package/mock.d.ts.map +1 -1
- package/mock.js +88 -17
- package/mock.js.map +1 -1
- package/package.json +3 -3
- package/path.d.ts +30 -0
- package/path.d.ts.map +1 -1
- package/path.js +49 -0
- package/path.js.map +1 -1
- package/path.test.js +41 -0
- package/path.test.js.map +1 -1
- package/stream.d.ts.map +1 -1
- package/stream.js +25 -4
- package/stream.js.map +1 -1
- package/stream.test.js +42 -0
- package/stream.test.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/time.test.d.ts +2 -0
- package/time.test.d.ts.map +1 -0
- package/time.test.js +12 -0
- package/time.test.js.map +1 -0
- package/track.d.ts +225 -45
- package/track.d.ts.map +1 -1
- package/track.js +505 -93
- package/track.js.map +1 -1
- package/track.test.js +138 -29
- package/track.test.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/timeout.test.d.ts +2 -0
- package/util/timeout.test.d.ts.map +1 -0
- package/util/timeout.test.js +18 -0
- package/util/timeout.test.js.map +1 -0
- package/varint.d.ts +6 -0
- package/varint.d.ts.map +1 -1
- package/varint.js +6 -2
- package/varint.js.map +1 -1
- package/zod.d.ts +4 -4
- 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/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/error.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/* @ts-self-types="./error.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* Errors, including the code a peer reports when it resets a stream.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* An error the peer reported by resetting a stream, carrying the raw code it sent.
|
|
9
|
+
*
|
|
10
|
+
* The codes are not standardized, so this deliberately does not translate one into a local
|
|
11
|
+
* error: the number means whatever the peer's implementation says it means. A read or write
|
|
12
|
+
* rejects with this on every transport, so branch on {@link code} rather than feature-detecting
|
|
13
|
+
* `WebTransportError`, which a non-browser runtime never defines and the WebSocket fallback
|
|
14
|
+
* never throws.
|
|
15
|
+
*
|
|
16
|
+
* Code 0 is what a transport sends when a stream is dropped or aborted with no code of its own.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* try {
|
|
20
|
+
* frame = await group.readFrame();
|
|
21
|
+
* } catch (err) {
|
|
22
|
+
* // Whatever this peer's code 2 means to it.
|
|
23
|
+
* if (err instanceof RemoteError && err.code === 2) return;
|
|
24
|
+
* throw err;
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export class RemoteError extends Error {
|
|
31
|
+
/** The code the peer sent, verbatim. */
|
|
32
|
+
code;
|
|
33
|
+
constructor(code, options) {
|
|
34
|
+
super(`remote error: ${code}`, options);
|
|
35
|
+
this.name = "RemoteError";
|
|
36
|
+
this.code = code;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function streamCode(err) {
|
|
40
|
+
if (typeof err !== "object" || err === null)
|
|
41
|
+
return undefined;
|
|
42
|
+
const { source, streamErrorCode } = err;
|
|
43
|
+
if (source !== "stream" || typeof streamErrorCode !== "number")
|
|
44
|
+
return undefined;
|
|
45
|
+
return streamErrorCode;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decode a transport failure into a {@link RemoteError} error when it carries a stream reset code,
|
|
49
|
+
* otherwise pass it through.
|
|
50
|
+
*
|
|
51
|
+
* Native WebTransport rejects with a `WebTransportError`; the WebSocket fallback mints an error
|
|
52
|
+
* with the same `source`/`streamErrorCode` fields. Reading the fields rather than the class
|
|
53
|
+
* covers both, and works in a runtime with no `WebTransportError` at all.
|
|
54
|
+
*
|
|
55
|
+
* @internal Called at the transport boundary so the raw error never reaches an application.
|
|
56
|
+
*/
|
|
57
|
+
export function fromTransport(err) {
|
|
58
|
+
const code = streamCode(err);
|
|
59
|
+
if (code === undefined)
|
|
60
|
+
return error(err);
|
|
61
|
+
return new RemoteError(code, { cause: err });
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Coerce an unknown thrown value into an `Error`.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export function error(err) {
|
|
69
|
+
return err instanceof Error ? err : new Error(String(err));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Format an error into a non-empty, human-readable string for logging.
|
|
73
|
+
*
|
|
74
|
+
* Safari always leaves `WebTransportError.message` blank, so a bare `err.message` degrades to
|
|
75
|
+
* an empty string and the reason is lost. This falls back to the error type name and appends
|
|
76
|
+
* the WebTransport `source` and application `streamErrorCode`, so the log line always says
|
|
77
|
+
* something.
|
|
78
|
+
*/
|
|
79
|
+
export function reason(err) {
|
|
80
|
+
const e = error(err);
|
|
81
|
+
// WebTransportError carries the failure origin and the peer's application error code,
|
|
82
|
+
// often the only identifying detail since WebKit leaves `message` empty.
|
|
83
|
+
if (typeof WebTransportError !== "undefined" && e instanceof WebTransportError) {
|
|
84
|
+
const parts = [`source=${e.source}`];
|
|
85
|
+
if (e.streamErrorCode !== null)
|
|
86
|
+
parts.push(`code=${e.streamErrorCode}`);
|
|
87
|
+
const detail = parts.join(" ");
|
|
88
|
+
return e.message ? `${e.message} (${detail})` : `WebTransportError: ${detail}`;
|
|
89
|
+
}
|
|
90
|
+
return e.message || e.name || "unknown error";
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=error.js.map
|
package/error.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACrC,wCAAwC;IAC/B,IAAI,CAAS;IAEtB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EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,CAAC,eAAe,KAAK,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,sBAAsB,MAAM,EAAE,CAAC;IAChF,CAAC;IAED,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,eAAe,CAAC;AAC/C,CAAC","sourcesContent":["/**\n * Errors, including the code a peer reports when it resets a stream.\n *\n * @module\n */\n\n/**\n * An error the peer reported by resetting a stream, carrying the raw code it sent.\n *\n * The codes are not standardized, so this deliberately does not translate one into a local\n * error: the number means whatever the peer's implementation says it means. A read or write\n * rejects with this on every transport, so branch on {@link code} rather than feature-detecting\n * `WebTransportError`, which a non-browser runtime never defines and the WebSocket fallback\n * never throws.\n *\n * Code 0 is what a transport sends when a stream is dropped or aborted with no code of its own.\n *\n * ```ts\n * try {\n * frame = await group.readFrame();\n * } catch (err) {\n * // Whatever this peer's code 2 means to it.\n * if (err instanceof RemoteError && err.code === 2) return;\n * throw err;\n * }\n * ```\n *\n * @public\n */\nexport class RemoteError extends Error {\n\t/** The code the peer sent, verbatim. */\n\treadonly code: number;\n\n\tconstructor(code: number, options?: { cause?: unknown }) {\n\t\tsuper(`remote error: ${code}`, options);\n\t\tthis.name = \"RemoteError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** The WebTransport-shaped fields a stream reset code arrives in. */\ntype StreamErrorLike = { source?: unknown; streamErrorCode?: unknown };\n\nfunction streamCode(err: unknown): number | undefined {\n\tif (typeof err !== \"object\" || err === null) return undefined;\n\n\tconst { source, streamErrorCode } = err as StreamErrorLike;\n\tif (source !== \"stream\" || typeof streamErrorCode !== \"number\") return undefined;\n\n\treturn streamErrorCode;\n}\n\n/**\n * Decode a transport failure into a {@link RemoteError} error when it carries a stream reset code,\n * otherwise pass it through.\n *\n * Native WebTransport rejects with a `WebTransportError`; the WebSocket fallback mints an error\n * with the same `source`/`streamErrorCode` fields. Reading the fields rather than the class\n * covers both, and works in a runtime with no `WebTransportError` at all.\n *\n * @internal Called at the transport boundary so the raw error never reaches an application.\n */\nexport function fromTransport(err: unknown): Error {\n\tconst code = streamCode(err);\n\tif (code === undefined) return error(err);\n\treturn new RemoteError(code, { cause: err });\n}\n\n/**\n * Coerce an unknown thrown value into an `Error`.\n *\n * @internal\n */\nexport function error(err: unknown): Error {\n\treturn err instanceof Error ? err : new Error(String(err));\n}\n\n/**\n * Format an error into a non-empty, human-readable string for logging.\n *\n * Safari always leaves `WebTransportError.message` blank, so a bare `err.message` degrades to\n * an empty string and the reason is lost. This falls back to the error type name and appends\n * the WebTransport `source` and application `streamErrorCode`, so the log line always says\n * something.\n */\nexport function reason(err: unknown): string {\n\tconst e = error(err);\n\n\t// WebTransportError carries the failure origin and the peer's application error code,\n\t// often the only identifying detail since WebKit leaves `message` empty.\n\tif (typeof WebTransportError !== \"undefined\" && e instanceof WebTransportError) {\n\t\tconst parts = [`source=${e.source}`];\n\t\tif (e.streamErrorCode !== null) parts.push(`code=${e.streamErrorCode}`);\n\t\tconst detail = parts.join(\" \");\n\t\treturn e.message ? `${e.message} (${detail})` : `WebTransportError: ${detail}`;\n\t}\n\n\treturn e.message || e.name || \"unknown error\";\n}\n"]}
|
package/error.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.test.d.ts","sourceRoot":"","sources":["../src/error.test.ts"],"names":[],"mappings":""}
|
package/error.test.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* @ts-self-types="./error.test.d.ts" */
|
|
2
|
+
import { afterEach, beforeEach, expect, test } from "bun:test";
|
|
3
|
+
import { StreamError } from "@moq/qmux";
|
|
4
|
+
import { fromTransport, RemoteError, reason } from "./error.js";
|
|
5
|
+
// Minimal stand-in for the DOM WebTransportError, which the test runtime may not define.
|
|
6
|
+
class FakeWebTransportError extends Error {
|
|
7
|
+
source;
|
|
8
|
+
streamErrorCode;
|
|
9
|
+
constructor(source, streamErrorCode, message = "") {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "WebTransportError";
|
|
12
|
+
this.source = source;
|
|
13
|
+
this.streamErrorCode = streamErrorCode;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const globals = globalThis;
|
|
17
|
+
let originalWebTransportError;
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
// Force `instanceof WebTransportError` in reason() to match our stand-in.
|
|
20
|
+
originalWebTransportError = globals.WebTransportError;
|
|
21
|
+
globals.WebTransportError = FakeWebTransportError;
|
|
22
|
+
});
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
globals.WebTransportError = originalWebTransportError;
|
|
25
|
+
});
|
|
26
|
+
test("fromTransport: a stream reset keeps the peer's code verbatim", () => {
|
|
27
|
+
const src = new FakeWebTransportError("stream", 2);
|
|
28
|
+
const err = fromTransport(src);
|
|
29
|
+
expect(err).toBeInstanceOf(RemoteError);
|
|
30
|
+
expect(err.code).toBe(2);
|
|
31
|
+
expect(err.message).toBe("remote error: 2");
|
|
32
|
+
// The original error stays reachable for logging.
|
|
33
|
+
expect(err.cause).toBe(src);
|
|
34
|
+
});
|
|
35
|
+
test("fromTransport: code 0 is a code like any other", () => {
|
|
36
|
+
// 0 is what a transport sends for a stream dropped with no code of its own. What it
|
|
37
|
+
// means is up to the peer, so it gets no special treatment here.
|
|
38
|
+
expect(fromTransport(new FakeWebTransportError("stream", 0)).code).toBe(0);
|
|
39
|
+
});
|
|
40
|
+
test("fromTransport: decodes a fallback error with no WebTransportError global", () => {
|
|
41
|
+
// The WebSocket fallback runs where the browser has no WebTransport, so the decode must
|
|
42
|
+
// read the fields rather than the class.
|
|
43
|
+
globals.WebTransportError = undefined;
|
|
44
|
+
const err = fromTransport({ source: "stream", streamErrorCode: 31, message: "" });
|
|
45
|
+
expect(err).toBeInstanceOf(RemoteError);
|
|
46
|
+
expect(err.code).toBe(31);
|
|
47
|
+
});
|
|
48
|
+
test("fromTransport: a session failure has no stream code, so it passes through", () => {
|
|
49
|
+
const src = new FakeWebTransportError("session", null, "connection lost");
|
|
50
|
+
expect(fromTransport(src)).toBe(src);
|
|
51
|
+
});
|
|
52
|
+
test("fromTransport: a local error passes through and a non-error is coerced", () => {
|
|
53
|
+
// Our own messages are better than a code, so they survive untouched.
|
|
54
|
+
const src = new Error("unexpected end of stream");
|
|
55
|
+
expect(fromTransport(src)).toBe(src);
|
|
56
|
+
expect(fromTransport("nope").message).toBe("nope");
|
|
57
|
+
});
|
|
58
|
+
test("reason: plain Error keeps its message", () => {
|
|
59
|
+
expect(reason(new Error("boom"))).toBe("boom");
|
|
60
|
+
});
|
|
61
|
+
test("reason: non-Error value is stringified", () => {
|
|
62
|
+
expect(reason("nope")).toBe("nope");
|
|
63
|
+
});
|
|
64
|
+
test("reason: empty message falls back to the type name", () => {
|
|
65
|
+
// Safari's WebTransportError.message is always blank; the reason must never be empty.
|
|
66
|
+
expect(reason(new Error(""))).toBe("Error");
|
|
67
|
+
});
|
|
68
|
+
test("reason: WebTransportError with a blank message surfaces source and code", () => {
|
|
69
|
+
// The Safari case from the bug report: a RESET_STREAM with no message.
|
|
70
|
+
expect(reason(new FakeWebTransportError("stream", 0))).toBe("WebTransportError: source=stream code=0");
|
|
71
|
+
});
|
|
72
|
+
test("reason: WebTransportError omits a null stream error code", () => {
|
|
73
|
+
expect(reason(new FakeWebTransportError("session", null))).toBe("WebTransportError: source=session");
|
|
74
|
+
});
|
|
75
|
+
test("reason: WebTransportError keeps a populated message and appends details", () => {
|
|
76
|
+
expect(reason(new FakeWebTransportError("stream", 42, "Received RESET_STREAM."))).toBe("Received RESET_STREAM. (source=stream code=42)");
|
|
77
|
+
});
|
|
78
|
+
test("reason: a decoded remote error names its code", () => {
|
|
79
|
+
expect(reason(new RemoteError(31))).toBe("remote error: 31");
|
|
80
|
+
});
|
|
81
|
+
test("fromTransport: decodes a real qmux stream reset", () => {
|
|
82
|
+
// The WebSocket fallback's actual error type, not a stand-in: this is the contract the
|
|
83
|
+
// fallback path depends on, and it only holds from @moq/qmux 0.3.2 on. Before that, qmux
|
|
84
|
+
// formatted the code into an Error message and this silently decoded nothing.
|
|
85
|
+
const err = fromTransport(new StreamError(2, "RESET_STREAM"));
|
|
86
|
+
expect(err).toBeInstanceOf(RemoteError);
|
|
87
|
+
expect(err.code).toBe(2);
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=error.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.test.js","sourceRoot":"","sources":["../src/error.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEhE,yFAAyF;AACzF,MAAM,qBAAsB,SAAQ,KAAK;IAC/B,MAAM,CAAS;IACf,eAAe,CAAgB;IAExC,YAAY,MAAc,EAAE,eAA8B,EAAE,OAAO,GAAG,EAAE;QACvE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACxC,CAAC;CACD;AAED,MAAM,OAAO,GAAG,UAA6C,CAAC;AAC9D,IAAI,yBAAkC,CAAC;AAEvC,UAAU,CAAC,GAAG,EAAE;IACf,0EAA0E;IAC1E,yBAAyB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACtD,OAAO,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,EAAE;IACpF,uEAAuE;IACvE,MAAM,CAAC,MAAM,CAAC,IAAI,qBAAqB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;AACxG,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0DAA0D,EAAE,GAAG,EAAE;IACrE,MAAM,CAAC,MAAM,CAAC,IAAI,qBAAqB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;AACtG,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,yEAAyE,EAAE,GAAG,EAAE;IACpF,MAAM,CAAC,MAAM,CAAC,IAAI,qBAAqB,CAAC,QAAQ,EAAE,EAAE,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,IAAI,CACrF,gDAAgD,CAChD,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,+CAA+C,EAAE,GAAG,EAAE;IAC1D,MAAM,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AAC9D,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,iDAAiD,EAAE,GAAG,EAAE;IAC5D,uFAAuF;IACvF,yFAAyF;IACzF,8EAA8E;IAC9E,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;IAC9D,MAAM,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IACxC,MAAM,CAAE,GAAmB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, expect, test } from \"bun:test\";\nimport { StreamError } from \"@moq/qmux\";\nimport { fromTransport, RemoteError, reason } from \"./error.ts\";\n\n// Minimal stand-in for the DOM WebTransportError, which the test runtime may not define.\nclass FakeWebTransportError extends Error {\n\treadonly source: string;\n\treadonly streamErrorCode: number | null;\n\n\tconstructor(source: string, streamErrorCode: number | null, message = \"\") {\n\t\tsuper(message);\n\t\tthis.name = \"WebTransportError\";\n\t\tthis.source = source;\n\t\tthis.streamErrorCode = streamErrorCode;\n\t}\n}\n\nconst globals = globalThis as { WebTransportError?: unknown };\nlet originalWebTransportError: unknown;\n\nbeforeEach(() => {\n\t// Force `instanceof WebTransportError` in reason() to match our stand-in.\n\toriginalWebTransportError = globals.WebTransportError;\n\tglobals.WebTransportError = FakeWebTransportError;\n});\n\nafterEach(() => {\n\tglobals.WebTransportError = originalWebTransportError;\n});\n\ntest(\"fromTransport: a stream reset keeps the peer's code verbatim\", () => {\n\tconst src = new FakeWebTransportError(\"stream\", 2);\n\tconst err = fromTransport(src);\n\texpect(err).toBeInstanceOf(RemoteError);\n\texpect((err as RemoteError).code).toBe(2);\n\texpect(err.message).toBe(\"remote error: 2\");\n\t// The original error stays reachable for logging.\n\texpect(err.cause).toBe(src);\n});\n\ntest(\"fromTransport: code 0 is a code like any other\", () => {\n\t// 0 is what a transport sends for a stream dropped with no code of its own. What it\n\t// means is up to the peer, so it gets no special treatment here.\n\texpect((fromTransport(new FakeWebTransportError(\"stream\", 0)) as RemoteError).code).toBe(0);\n});\n\ntest(\"fromTransport: decodes a fallback error with no WebTransportError global\", () => {\n\t// The WebSocket fallback runs where the browser has no WebTransport, so the decode must\n\t// read the fields rather than the class.\n\tglobals.WebTransportError = undefined;\n\tconst err = fromTransport({ source: \"stream\", streamErrorCode: 31, message: \"\" });\n\texpect(err).toBeInstanceOf(RemoteError);\n\texpect((err as RemoteError).code).toBe(31);\n});\n\ntest(\"fromTransport: a session failure has no stream code, so it passes through\", () => {\n\tconst src = new FakeWebTransportError(\"session\", null, \"connection lost\");\n\texpect(fromTransport(src)).toBe(src);\n});\n\ntest(\"fromTransport: a local error passes through and a non-error is coerced\", () => {\n\t// Our own messages are better than a code, so they survive untouched.\n\tconst src = new Error(\"unexpected end of stream\");\n\texpect(fromTransport(src)).toBe(src);\n\texpect(fromTransport(\"nope\").message).toBe(\"nope\");\n});\n\ntest(\"reason: plain Error keeps its message\", () => {\n\texpect(reason(new Error(\"boom\"))).toBe(\"boom\");\n});\n\ntest(\"reason: non-Error value is stringified\", () => {\n\texpect(reason(\"nope\")).toBe(\"nope\");\n});\n\ntest(\"reason: empty message falls back to the type name\", () => {\n\t// Safari's WebTransportError.message is always blank; the reason must never be empty.\n\texpect(reason(new Error(\"\"))).toBe(\"Error\");\n});\n\ntest(\"reason: WebTransportError with a blank message surfaces source and code\", () => {\n\t// The Safari case from the bug report: a RESET_STREAM with no message.\n\texpect(reason(new FakeWebTransportError(\"stream\", 0))).toBe(\"WebTransportError: source=stream code=0\");\n});\n\ntest(\"reason: WebTransportError omits a null stream error code\", () => {\n\texpect(reason(new FakeWebTransportError(\"session\", null))).toBe(\"WebTransportError: source=session\");\n});\n\ntest(\"reason: WebTransportError keeps a populated message and appends details\", () => {\n\texpect(reason(new FakeWebTransportError(\"stream\", 42, \"Received RESET_STREAM.\"))).toBe(\n\t\t\"Received RESET_STREAM. (source=stream code=42)\",\n\t);\n});\n\ntest(\"reason: a decoded remote error names its code\", () => {\n\texpect(reason(new RemoteError(31))).toBe(\"remote error: 31\");\n});\n\ntest(\"fromTransport: decodes a real qmux stream reset\", () => {\n\t// The WebSocket fallback's actual error type, not a stand-in: this is the contract the\n\t// fallback path depends on, and it only holds from @moq/qmux 0.3.2 on. Before that, qmux\n\t// formatted the code into an Error message and this silently decoded nothing.\n\tconst err = fromTransport(new StreamError(2, \"RESET_STREAM\"));\n\texpect(err).toBeInstanceOf(RemoteError);\n\texpect((err as RemoteError).code).toBe(2);\n});\n"]}
|
package/group.d.ts
CHANGED
|
@@ -1,64 +1,153 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Group role handles: an ordered stream of frames within a track, delivered over one QUIC stream.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type GetPromise, type Getter } from "@moq/signals";
|
|
7
|
+
import { Timestamp } from "./time";
|
|
8
|
+
/** Maximum bytes of frames cached in a group before old frames are evicted from the front. */
|
|
9
|
+
export declare const MAX_GROUP_CACHE_BYTES: number;
|
|
10
|
+
/** Maximum number of frames cached in a group before old frames are evicted from the front. */
|
|
11
|
+
export declare const MAX_GROUP_FRAMES = 1024;
|
|
12
|
+
/**
|
|
13
|
+
* A frame buffered in a group: its presentation {@link Timestamp} and payload bytes.
|
|
14
|
+
*
|
|
15
|
+
* The timestamp carries its own scale, so a track can pick its units; the wire layer
|
|
16
|
+
* converts it into the track's negotiated timescale.
|
|
17
|
+
*/
|
|
18
|
+
export interface Frame {
|
|
19
|
+
/** The frame payload. */
|
|
20
|
+
payload: Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* Presentation timestamp. Required: for a payload with no presentation time of its own
|
|
23
|
+
* (a JSON catalog, control state) pass {@link Timestamp.now} explicitly.
|
|
24
|
+
*/
|
|
25
|
+
timestamp: Timestamp;
|
|
26
|
+
}
|
|
27
|
+
/** Immutable group metadata. */
|
|
28
|
+
export interface Info {
|
|
29
|
+
/** Sequence number of this group within its track. */
|
|
30
|
+
sequence: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown by a frame read when the reader fell behind the group's eviction window: frames
|
|
34
|
+
* it had not yet read were dropped to stay under the cache cap, so the stream has a gap.
|
|
35
|
+
*/
|
|
36
|
+
export declare class Lagged extends Error {
|
|
37
|
+
constructor();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The write side of an ordered stream of frames within a track.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare class Producer {
|
|
3
45
|
#private;
|
|
4
46
|
/** Sequence number of this group within its track. */
|
|
5
47
|
readonly sequence: number;
|
|
6
|
-
/** Resolves with the abort error (or undefined) once closed. */
|
|
7
|
-
readonly closed: Promise<Error | undefined>;
|
|
8
48
|
constructor(sequence: number);
|
|
9
49
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
50
|
+
* Settles once the group closes: `null` on a clean close, or the abort {@link Error}.
|
|
51
|
+
* Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
|
|
52
|
+
*/
|
|
53
|
+
get closed(): GetPromise<Error | null>;
|
|
54
|
+
/** A read handle for this group. */
|
|
55
|
+
consume(): Consumer;
|
|
56
|
+
/**
|
|
57
|
+
* Create an independent read handle that receives every frame written here.
|
|
58
|
+
*
|
|
59
|
+
* Frames written so far are replayed synchronously; later writes and close are teed
|
|
60
|
+
* in as they happen.
|
|
61
|
+
*
|
|
62
|
+
* @internal Track fan-out and fetch coalescing only. Use {@link consume} instead.
|
|
63
|
+
*/
|
|
64
|
+
mirror(): Consumer;
|
|
65
|
+
/**
|
|
66
|
+
* Whether any mirror reader is currently attached.
|
|
67
|
+
*
|
|
68
|
+
* Pairs with {@link unused}. Fetch coalescing watches it to cancel a download once every reader
|
|
69
|
+
* has gone: a group can stay open indefinitely (a catalog track, a JSON stream), so it can't
|
|
70
|
+
* rely on the stream ending on its own.
|
|
71
|
+
*
|
|
72
|
+
* @internal Track fan-out and fetch coalescing only.
|
|
12
73
|
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
74
|
+
get used(): Getter<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Resolves once no mirror reader remains (or the group closes).
|
|
77
|
+
*
|
|
78
|
+
* @internal Track fan-out and fetch coalescing only.
|
|
79
|
+
*/
|
|
80
|
+
unused(): Promise<void>;
|
|
81
|
+
/** Writes a frame to the group. */
|
|
82
|
+
writeFrame(frame: Frame): void;
|
|
83
|
+
/** Write a string as a single UTF-8 encoded frame, stamped with {@link Timestamp.now}. */
|
|
15
84
|
writeString(str: string): void;
|
|
16
|
-
/** Write a value as a single JSON-encoded frame. */
|
|
85
|
+
/** Write a value as a single JSON-encoded frame, stamped with {@link Timestamp.now}. */
|
|
17
86
|
writeJson(json: unknown): void;
|
|
18
|
-
/** Write a boolean as a single one-byte frame. */
|
|
87
|
+
/** Write a boolean as a single one-byte frame, stamped with {@link Timestamp.now}. */
|
|
19
88
|
writeBool(bool: boolean): void;
|
|
89
|
+
/** True once the group has been closed. */
|
|
90
|
+
get isClosed(): boolean;
|
|
91
|
+
/** Closes the group, optionally with an error to abort readers. */
|
|
92
|
+
close(abort?: Error): void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The read side of an ordered stream of frames within a track.
|
|
96
|
+
*
|
|
97
|
+
* Created internally: obtain one from {@link Producer.consume} or a track subscriber's
|
|
98
|
+
* group reads.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export declare class Consumer {
|
|
103
|
+
#private;
|
|
104
|
+
/** Sequence number of this group within its track. */
|
|
105
|
+
readonly sequence: number;
|
|
106
|
+
private constructor();
|
|
107
|
+
/**
|
|
108
|
+
* Settles once the group closes: `null` on a clean close, or the abort {@link Error}.
|
|
109
|
+
* Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
|
|
110
|
+
*/
|
|
111
|
+
get closed(): GetPromise<Error | null>;
|
|
20
112
|
/** True once no further frames can be read: the group has closed and every buffered frame is read. */
|
|
21
113
|
get done(): boolean;
|
|
114
|
+
/** True once the group has been closed, regardless of whether buffered frames remain unread. Synchronous complement to the {@link closed} promise. */
|
|
115
|
+
get isClosed(): boolean;
|
|
116
|
+
/** True if frames were evicted from the front of this group before being read. */
|
|
117
|
+
get skipped(): boolean;
|
|
22
118
|
/**
|
|
23
119
|
* Reads the next already-buffered frame without blocking.
|
|
120
|
+
* Treat the returned frame bytes as read-only; they are shared with other consumers.
|
|
24
121
|
*
|
|
25
|
-
* Returns `undefined` when nothing is buffered right now. That is
|
|
26
|
-
* check {@link done} to tell "no frame buffered yet"
|
|
27
|
-
* Drain a backlog by looping until this returns `undefined`, then branch on {@link done}: if not
|
|
28
|
-
* done, {@link readable} resolves when the next frame arrives.
|
|
122
|
+
* Returns `undefined` when nothing is buffered right now. That is not by itself
|
|
123
|
+
* end-of-group: check {@link done} to tell "no frame buffered yet" from "finished".
|
|
29
124
|
*/
|
|
30
|
-
tryReadFrame():
|
|
125
|
+
tryReadFrame(): Frame | undefined;
|
|
31
126
|
/** Like {@link tryReadFrame} but also reports the frame's sequence number within the group. */
|
|
32
|
-
tryReadFrameSequence(): {
|
|
127
|
+
tryReadFrameSequence(): ({
|
|
33
128
|
sequence: number;
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Resolves once {@link readFrame} would not block: a frame is buffered, or the group has closed.
|
|
38
|
-
* Always settles (never hangs), so on a finished group it resolves immediately; pair it with
|
|
39
|
-
* {@link done} to avoid re-waiting on a group that has nothing left.
|
|
40
|
-
*
|
|
41
|
-
* Lets a caller fold "this group has a frame" into a larger wait (e.g. racing it against a new
|
|
42
|
-
* group arriving) without touching the group's internal signals.
|
|
43
|
-
*/
|
|
129
|
+
} & Frame) | undefined;
|
|
130
|
+
/** Resolves once {@link readFrame} would not block. */
|
|
44
131
|
readable(): Promise<void>;
|
|
45
132
|
/**
|
|
46
133
|
* Reads the next frame from the group.
|
|
47
|
-
*
|
|
134
|
+
* Treat the returned frame bytes as read-only; they are shared with other consumers.
|
|
48
135
|
*/
|
|
49
|
-
readFrame(): Promise<
|
|
50
|
-
/**
|
|
51
|
-
|
|
136
|
+
readFrame(): Promise<Frame | undefined>;
|
|
137
|
+
/**
|
|
138
|
+
* Reads the next frame along with its sequence number within the group.
|
|
139
|
+
* Treat the returned frame bytes as read-only; they are shared with other consumers.
|
|
140
|
+
*/
|
|
141
|
+
readFrameSequence(): Promise<({
|
|
52
142
|
sequence: number;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/** Reads the next frame and decodes it as a UTF-8 string. */
|
|
143
|
+
} & Frame) | undefined>;
|
|
144
|
+
/** Reads the next frame and decodes its payload as a UTF-8 string. */
|
|
56
145
|
readString(): Promise<string | undefined>;
|
|
57
|
-
/** Reads the next frame and parses
|
|
146
|
+
/** Reads the next frame and parses its payload as JSON. */
|
|
58
147
|
readJson(): Promise<unknown | undefined>;
|
|
59
|
-
/** Reads the next frame and decodes
|
|
148
|
+
/** Reads the next frame and decodes its payload as a one-byte boolean. */
|
|
60
149
|
readBool(): Promise<boolean | undefined>;
|
|
61
|
-
/** Closes the group, optionally with an error to abort readers. */
|
|
150
|
+
/** Closes the group, optionally with an error to abort readers. Idempotent. */
|
|
62
151
|
close(abort?: Error): void;
|
|
63
152
|
}
|
|
64
153
|
//# sourceMappingURL=group.d.ts.map
|
package/group.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAgB,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,8FAA8F;AAC9F,eAAO,MAAM,qBAAqB,QAAmB,CAAC;AAEtD,+FAA+F;AAC/F,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC;;;;;GAKG;AACH,MAAM,WAAW,KAAK;IACrB,yBAAyB;IACzB,OAAO,EAAE,UAAU,CAAC;IACpB;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC;CACrB;AAED,gCAAgC;AAChC,MAAM,WAAW,IAAI;IACpB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,MAAO,SAAQ,KAAK;IAChC,cAGC;CACD;AAqCD;;;;GAIG;AACH,qBAAa,QAAQ;;IACpB,sDAAsD;IACtD,QAAQ,CAAC,QAAQ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