@moq/net 0.1.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/README.md +70 -0
- package/announced.d.ts +41 -0
- package/announced.d.ts.map +1 -0
- package/announced.js +65 -0
- package/announced.js.map +1 -0
- package/bandwidth.d.ts +11 -0
- package/bandwidth.d.ts.map +1 -0
- package/bandwidth.js +6 -0
- package/bandwidth.js.map +1 -0
- package/broadcast.d.ts +35 -0
- package/broadcast.d.ts.map +1 -0
- package/broadcast.js +72 -0
- package/broadcast.js.map +1 -0
- package/connection/accept.d.ts +14 -0
- package/connection/accept.d.ts.map +1 -0
- package/connection/accept.js +133 -0
- package/connection/accept.js.map +1 -0
- package/connection/connect.d.ts +19 -0
- package/connection/connect.d.ts.map +1 -0
- package/connection/connect.js +284 -0
- package/connection/connect.js.map +1 -0
- package/connection/established.d.ts +22 -0
- package/connection/established.d.ts.map +1 -0
- package/connection/established.js +2 -0
- package/connection/established.js.map +1 -0
- package/connection/handshake.d.ts +10 -0
- package/connection/handshake.d.ts.map +1 -0
- package/connection/handshake.js +47 -0
- package/connection/handshake.js.map +1 -0
- package/connection/index.d.ts +5 -0
- package/connection/index.d.ts.map +1 -0
- package/connection/index.js +5 -0
- package/connection/index.js.map +1 -0
- package/connection/reload.d.ts +32 -0
- package/connection/reload.d.ts.map +1 -0
- package/connection/reload.js +127 -0
- package/connection/reload.js.map +1 -0
- package/group.d.ts +34 -0
- package/group.d.ts.map +1 -0
- package/group.js +92 -0
- package/group.js.map +1 -0
- package/ietf/adapter.d.ts +65 -0
- package/ietf/adapter.d.ts.map +1 -0
- package/ietf/adapter.js +625 -0
- package/ietf/adapter.js.map +1 -0
- package/ietf/connection.d.ts +65 -0
- package/ietf/connection.d.ts.map +1 -0
- package/ietf/connection.js +239 -0
- package/ietf/connection.js.map +1 -0
- package/ietf/control.d.ts +135 -0
- package/ietf/control.d.ts.map +1 -0
- package/ietf/control.js +237 -0
- package/ietf/control.js.map +1 -0
- package/ietf/fetch.d.ts +64 -0
- package/ietf/fetch.d.ts.map +1 -0
- package/ietf/fetch.js +99 -0
- package/ietf/fetch.js.map +1 -0
- package/ietf/goaway.d.ts +15 -0
- package/ietf/goaway.d.ts.map +1 -0
- package/ietf/goaway.js +33 -0
- package/ietf/goaway.js.map +1 -0
- package/ietf/ietf.test.d.ts +2 -0
- package/ietf/ietf.test.d.ts.map +1 -0
- package/ietf/ietf.test.js +800 -0
- package/ietf/ietf.test.js.map +1 -0
- package/ietf/index.d.ts +18 -0
- package/ietf/index.d.ts.map +1 -0
- package/ietf/index.js +18 -0
- package/ietf/index.js.map +1 -0
- package/ietf/message.d.ts +4 -0
- package/ietf/message.d.ts.map +1 -0
- package/ietf/message.js +53 -0
- package/ietf/message.js.map +1 -0
- package/ietf/namespace.d.ts +5 -0
- package/ietf/namespace.d.ts.map +1 -0
- package/ietf/namespace.js +21 -0
- package/ietf/namespace.js.map +1 -0
- package/ietf/object.d.ts +37 -0
- package/ietf/object.d.ts.map +1 -0
- package/ietf/object.js +129 -0
- package/ietf/object.js.map +1 -0
- package/ietf/parameters.d.ts +56 -0
- package/ietf/parameters.d.ts.map +1 -0
- package/ietf/parameters.js +336 -0
- package/ietf/parameters.js.map +1 -0
- package/ietf/properties.d.ts +4 -0
- package/ietf/properties.d.ts.map +1 -0
- package/ietf/properties.js +32 -0
- package/ietf/properties.js.map +1 -0
- package/ietf/publish.d.ts +68 -0
- package/ietf/publish.d.ts.map +1 -0
- package/ietf/publish.js +191 -0
- package/ietf/publish.js.map +1 -0
- package/ietf/publish_namespace.d.ts +68 -0
- package/ietf/publish_namespace.d.ts.map +1 -0
- package/ietf/publish_namespace.js +175 -0
- package/ietf/publish_namespace.js.map +1 -0
- package/ietf/publisher.d.ts +50 -0
- package/ietf/publisher.d.ts.map +1 -0
- package/ietf/publisher.js +329 -0
- package/ietf/publisher.js.map +1 -0
- package/ietf/request.d.ts +52 -0
- package/ietf/request.d.ts.map +1 -0
- package/ietf/request.js +118 -0
- package/ietf/request.js.map +1 -0
- package/ietf/setup.d.ts +38 -0
- package/ietf/setup.d.ts.map +1 -0
- package/ietf/setup.js +128 -0
- package/ietf/setup.js.map +1 -0
- package/ietf/subscribe.d.ts +66 -0
- package/ietf/subscribe.d.ts.map +1 -0
- package/ietf/subscribe.js +275 -0
- package/ietf/subscribe.js.map +1 -0
- package/ietf/subscribe_namespace.d.ts +89 -0
- package/ietf/subscribe_namespace.d.ts.map +1 -0
- package/ietf/subscribe_namespace.js +195 -0
- package/ietf/subscribe_namespace.js.map +1 -0
- package/ietf/subscriber.d.ts +53 -0
- package/ietf/subscriber.d.ts.map +1 -0
- package/ietf/subscriber.js +395 -0
- package/ietf/subscriber.js.map +1 -0
- package/ietf/track.d.ts +40 -0
- package/ietf/track.d.ts.map +1 -0
- package/ietf/track.js +107 -0
- package/ietf/track.js.map +1 -0
- package/ietf/version.d.ts +50 -0
- package/ietf/version.d.ts.map +1 -0
- package/ietf/version.js +55 -0
- package/ietf/version.js.map +1 -0
- package/index.d.ts +11 -0
- package/index.d.ts.map +1 -0
- package/index.js +16 -0
- package/index.js.map +1 -0
- package/integration.test.d.ts +2 -0
- package/integration.test.d.ts.map +1 -0
- package/integration.test.js +83 -0
- package/integration.test.js.map +1 -0
- package/lite/announce.d.ts +35 -0
- package/lite/announce.d.ts.map +1 -0
- package/lite/announce.js +165 -0
- package/lite/announce.js.map +1 -0
- package/lite/connection.d.ts +47 -0
- package/lite/connection.d.ts.map +1 -0
- package/lite/connection.js +218 -0
- package/lite/connection.js.map +1 -0
- package/lite/fetch.d.ts +14 -0
- package/lite/fetch.d.ts.map +1 -0
- package/lite/fetch.js +46 -0
- package/lite/fetch.js.map +1 -0
- package/lite/goaway.d.ts +10 -0
- package/lite/goaway.d.ts.map +1 -0
- package/lite/goaway.js +36 -0
- package/lite/goaway.js.map +1 -0
- package/lite/group.d.ts +18 -0
- package/lite/group.d.ts.map +1 -0
- package/lite/group.js +45 -0
- package/lite/group.js.map +1 -0
- package/lite/index.d.ts +11 -0
- package/lite/index.d.ts.map +1 -0
- package/lite/index.js +11 -0
- package/lite/index.js.map +1 -0
- package/lite/message.d.ts +5 -0
- package/lite/message.d.ts.map +1 -0
- package/lite/message.js +50 -0
- package/lite/message.js.map +1 -0
- package/lite/origin.d.ts +19 -0
- package/lite/origin.d.ts.map +1 -0
- package/lite/origin.js +28 -0
- package/lite/origin.js.map +1 -0
- package/lite/probe.d.ts +12 -0
- package/lite/probe.d.ts.map +1 -0
- package/lite/probe.js +59 -0
- package/lite/probe.js.map +1 -0
- package/lite/publisher.d.ts +56 -0
- package/lite/publisher.d.ts.map +1 -0
- package/lite/publisher.js +305 -0
- package/lite/publisher.js.map +1 -0
- package/lite/session.d.ts +36 -0
- package/lite/session.d.ts.map +1 -0
- package/lite/session.js +129 -0
- package/lite/session.js.map +1 -0
- package/lite/stream.d.ts +18 -0
- package/lite/stream.d.ts.map +1 -0
- package/lite/stream.js +11 -0
- package/lite/stream.js.map +1 -0
- package/lite/subscribe.d.ts +91 -0
- package/lite/subscribe.d.ts.map +1 -0
- package/lite/subscribe.js +267 -0
- package/lite/subscribe.js.map +1 -0
- package/lite/subscriber.d.ts +80 -0
- package/lite/subscriber.d.ts.map +1 -0
- package/lite/subscriber.js +245 -0
- package/lite/subscriber.js.map +1 -0
- package/lite/version.d.ts +12 -0
- package/lite/version.d.ts.map +1 -0
- package/lite/version.js +23 -0
- package/lite/version.js.map +1 -0
- package/mock.d.ts +16 -0
- package/mock.d.ts.map +1 -0
- package/mock.js +153 -0
- package/mock.js.map +1 -0
- package/package.json +27 -0
- package/path.d.ts +87 -0
- package/path.d.ts.map +1 -0
- package/path.js +98 -0
- package/path.js.map +1 -0
- package/path.test.d.ts +2 -0
- package/path.test.d.ts.map +1 -0
- package/path.test.js +153 -0
- package/path.test.js.map +1 -0
- package/stream.d.ts +57 -0
- package/stream.d.ts.map +1 -0
- package/stream.js +325 -0
- package/stream.js.map +1 -0
- package/stream.test.d.ts +2 -0
- package/stream.test.d.ts.map +1 -0
- package/stream.test.js +209 -0
- package/stream.test.js.map +1 -0
- package/time.d.ts +77 -0
- package/time.d.ts.map +1 -0
- package/time.js +65 -0
- package/time.js.map +1 -0
- package/track.d.ts +66 -0
- package/track.d.ts.map +1 -0
- package/track.js +203 -0
- package/track.js.map +1 -0
- package/track.test.d.ts +2 -0
- package/track.test.d.ts.map +1 -0
- package/track.test.js +39 -0
- package/track.test.js.map +1 -0
- package/util/error.d.ts +3 -0
- package/util/error.d.ts.map +1 -0
- package/util/error.js +8 -0
- package/util/error.js.map +1 -0
- package/util/hex.d.ts +2 -0
- package/util/hex.d.ts.map +1 -0
- package/util/hex.js +12 -0
- package/util/hex.js.map +1 -0
- package/util/index.d.ts +2 -0
- package/util/index.d.ts.map +1 -0
- package/util/index.js +2 -0
- package/util/index.js.map +1 -0
- package/varint.d.ts +28 -0
- package/varint.d.ts.map +1 -0
- package/varint.js +279 -0
- package/varint.js.map +1 -0
- package/varint.test.d.ts +2 -0
- package/varint.test.d.ts.map +1 -0
- package/varint.test.js +105 -0
- package/varint.test.js.map +1 -0
- package/zod.d.ts +6 -0
- package/zod.d.ts.map +1 -0
- package/zod.js +12 -0
- package/zod.js.map +1 -0
package/lite/group.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as Message from "./message.js";
|
|
2
|
+
export class Group {
|
|
3
|
+
subscribe;
|
|
4
|
+
sequence;
|
|
5
|
+
constructor(subscribe, sequence) {
|
|
6
|
+
this.subscribe = subscribe;
|
|
7
|
+
this.sequence = sequence;
|
|
8
|
+
}
|
|
9
|
+
async #encode(w) {
|
|
10
|
+
await w.u62(this.subscribe);
|
|
11
|
+
await w.u53(this.sequence);
|
|
12
|
+
}
|
|
13
|
+
static async #decode(r) {
|
|
14
|
+
return new Group(await r.u62(), await r.u53());
|
|
15
|
+
}
|
|
16
|
+
async encode(w) {
|
|
17
|
+
return Message.encode(w, this.#encode.bind(this));
|
|
18
|
+
}
|
|
19
|
+
static async decode(r) {
|
|
20
|
+
return Message.decode(r, Group.#decode);
|
|
21
|
+
}
|
|
22
|
+
static async decodeMaybe(r) {
|
|
23
|
+
return Message.decodeMaybe(r, Group.#decode);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class Frame {
|
|
27
|
+
payload;
|
|
28
|
+
constructor(payload) {
|
|
29
|
+
this.payload = payload;
|
|
30
|
+
}
|
|
31
|
+
async #encode(w) {
|
|
32
|
+
await w.write(this.payload);
|
|
33
|
+
}
|
|
34
|
+
static async #decode(r) {
|
|
35
|
+
const payload = await r.readAll();
|
|
36
|
+
return new Frame(payload);
|
|
37
|
+
}
|
|
38
|
+
async encode(w) {
|
|
39
|
+
return Message.encode(w, this.#encode.bind(this));
|
|
40
|
+
}
|
|
41
|
+
static async decode(r) {
|
|
42
|
+
return Message.decode(r, Frame.#decode);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/lite/group.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,MAAM,OAAO,KAAK;IACjB,SAAS,CAAS;IAClB,QAAQ,CAAS;IAEjB,YAAY,SAAiB,EAAE,QAAgB;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5B,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAA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port * as Message from \"./message.ts\";\n\nexport class Group {\n\tsubscribe: bigint;\n\tsequence: number;\n\n\tconstructor(subscribe: bigint, sequence: number) {\n\t\tthis.subscribe = subscribe;\n\t\tthis.sequence = sequence;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u62(this.subscribe);\n\t\tawait w.u53(this.sequence);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Group> {\n\t\treturn new Group(await r.u62(), await r.u53());\n\t}\n\n\tasync encode(w: Writer): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader): Promise<Group> {\n\t\treturn Message.decode(r, Group.#decode);\n\t}\n\n\tstatic async decodeMaybe(r: Reader): Promise<Group | undefined> {\n\t\treturn Message.decodeMaybe(r, Group.#decode);\n\t}\n}\n\nexport class Frame {\n\tpayload: Uint8Array;\n\n\tconstructor(payload: Uint8Array) {\n\t\tthis.payload = payload;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.write(this.payload);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Frame> {\n\t\tconst payload = await r.readAll();\n\t\treturn new Frame(payload);\n\t}\n\n\tasync encode(w: Writer): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader): Promise<Frame> {\n\t\treturn Message.decode(r, Frame.#decode);\n\t}\n}\n"]}
|
package/lite/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./announce.ts";
|
|
2
|
+
export * from "./connection.ts";
|
|
3
|
+
export * from "./fetch.ts";
|
|
4
|
+
export * from "./goaway.ts";
|
|
5
|
+
export * from "./group.ts";
|
|
6
|
+
export * from "./probe.ts";
|
|
7
|
+
export * from "./session.ts";
|
|
8
|
+
export * from "./stream.ts";
|
|
9
|
+
export * from "./subscribe.ts";
|
|
10
|
+
export * from "./version.ts";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lite/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
package/lite/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./announce.js";
|
|
2
|
+
export * from "./connection.js";
|
|
3
|
+
export * from "./fetch.js";
|
|
4
|
+
export * from "./goaway.js";
|
|
5
|
+
export * from "./group.js";
|
|
6
|
+
export * from "./probe.js";
|
|
7
|
+
export * from "./session.js";
|
|
8
|
+
export * from "./stream.js";
|
|
9
|
+
export * from "./subscribe.js";
|
|
10
|
+
export * from "./version.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lite/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./announce.ts\";\nexport * from \"./connection.ts\";\nexport * from \"./fetch.ts\";\nexport * from \"./goaway.ts\";\nexport * from \"./group.ts\";\nexport * from \"./probe.ts\";\nexport * from \"./session.ts\";\nexport * from \"./stream.ts\";\nexport * from \"./subscribe.ts\";\nexport * from \"./version.ts\";\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Reader, Writer } from "../stream.ts";
|
|
2
|
+
export declare function encode(writer: Writer, f: (w: Writer) => Promise<void>): Promise<void>;
|
|
3
|
+
export declare function decode<T>(reader: Reader, f: (r: Reader) => Promise<T>): Promise<T>;
|
|
4
|
+
export declare function decodeMaybe<T>(reader: Reader, f: (r: Reader) => Promise<T>): Promise<T | undefined>;
|
|
5
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/lite/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE9C,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,iBAqC3E;AAGD,wBAAsB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAaxF;AAED,wBAAsB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAGzG"}
|
package/lite/message.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Reader, Writer } from "../stream.js";
|
|
2
|
+
export async function encode(writer, f) {
|
|
3
|
+
let scratch = new Uint8Array();
|
|
4
|
+
const temp = new Writer(new WritableStream({
|
|
5
|
+
write(chunk) {
|
|
6
|
+
const needed = scratch.byteLength + chunk.byteLength;
|
|
7
|
+
if (needed > scratch.buffer.byteLength) {
|
|
8
|
+
// Resize the buffer to the needed size.
|
|
9
|
+
const capacity = Math.max(needed, scratch.buffer.byteLength * 2);
|
|
10
|
+
const newBuffer = new ArrayBuffer(capacity);
|
|
11
|
+
const newScratch = new Uint8Array(newBuffer, 0, needed);
|
|
12
|
+
// Copy the old data into the new buffer.
|
|
13
|
+
newScratch.set(scratch);
|
|
14
|
+
// Copy the new chunk into the new buffer.
|
|
15
|
+
newScratch.set(chunk, scratch.byteLength);
|
|
16
|
+
scratch = newScratch;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// Copy chunk data into buffer
|
|
20
|
+
scratch = new Uint8Array(scratch.buffer, 0, needed);
|
|
21
|
+
scratch.set(chunk, needed - chunk.byteLength);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
await f(temp);
|
|
26
|
+
temp.close();
|
|
27
|
+
await temp.closed;
|
|
28
|
+
await writer.u53(scratch.byteLength);
|
|
29
|
+
if (scratch.byteLength > 0) {
|
|
30
|
+
await writer.write(scratch);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Reads a message with a varint size prefix.
|
|
34
|
+
export async function decode(reader, f) {
|
|
35
|
+
const size = await reader.u53();
|
|
36
|
+
const data = await reader.read(size);
|
|
37
|
+
const limit = new Reader(undefined, data);
|
|
38
|
+
const msg = await f(limit);
|
|
39
|
+
// Check that we consumed exactly the right number of bytes
|
|
40
|
+
if (!(await limit.done())) {
|
|
41
|
+
throw new Error("Message decoding consumed too few bytes");
|
|
42
|
+
}
|
|
43
|
+
return msg;
|
|
44
|
+
}
|
|
45
|
+
export async function decodeMaybe(reader, f) {
|
|
46
|
+
if (await reader.done())
|
|
47
|
+
return;
|
|
48
|
+
return await decode(reader, f);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/lite/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAA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CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;AACF,CAAC;AAED,6CAA6C;AAC7C,MAAM,CAAC,KAAK,UAAU,MAAM,CAAI,MAAc,EAAE,CAA4B;IAC3E,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAErC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IAE3B,2DAA2D;IAC3D,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAI,MAAc,EAAE,CAA4B;IAChF,IAAI,MAAM,MAAM,CAAC,IAAI,EAAE;QAAE,OAAO;IAChC,OAAO,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { Reader, Writer } from \"../stream.ts\";\n\nexport async function encode(writer: Writer, f: (w: Writer) => Promise<void>) {\n\tlet scratch = new Uint8Array();\n\n\tconst temp = new Writer(\n\t\tnew WritableStream({\n\t\t\twrite(chunk: Uint8Array) {\n\t\t\t\tconst needed = scratch.byteLength + chunk.byteLength;\n\t\t\t\tif (needed > scratch.buffer.byteLength) {\n\t\t\t\t\t// Resize the buffer to the needed size.\n\t\t\t\t\tconst capacity = Math.max(needed, scratch.buffer.byteLength * 2);\n\t\t\t\t\tconst newBuffer = new ArrayBuffer(capacity);\n\t\t\t\t\tconst newScratch = new Uint8Array(newBuffer, 0, needed);\n\n\t\t\t\t\t// Copy the old data into the new buffer.\n\t\t\t\t\tnewScratch.set(scratch);\n\n\t\t\t\t\t// Copy the new chunk into the new buffer.\n\t\t\t\t\tnewScratch.set(chunk, scratch.byteLength);\n\n\t\t\t\t\tscratch = newScratch;\n\t\t\t\t} else {\n\t\t\t\t\t// Copy chunk data into buffer\n\t\t\t\t\tscratch = new Uint8Array(scratch.buffer, 0, needed);\n\t\t\t\t\tscratch.set(chunk, needed - chunk.byteLength);\n\t\t\t\t}\n\t\t\t},\n\t\t}),\n\t);\n\n\tawait f(temp);\n\ttemp.close();\n\tawait temp.closed;\n\n\tawait writer.u53(scratch.byteLength);\n\tif (scratch.byteLength > 0) {\n\t\tawait writer.write(scratch);\n\t}\n}\n\n// Reads a message with a varint size prefix.\nexport async function decode<T>(reader: Reader, f: (r: Reader) => Promise<T>): Promise<T> {\n\tconst size = await reader.u53();\n\tconst data = await reader.read(size);\n\n\tconst limit = new Reader(undefined, data);\n\tconst msg = await f(limit);\n\n\t// Check that we consumed exactly the right number of bytes\n\tif (!(await limit.done())) {\n\t\tthrow new Error(\"Message decoding consumed too few bytes\");\n\t}\n\n\treturn msg;\n}\n\nexport async function decodeMaybe<T>(reader: Reader, f: (r: Reader) => Promise<T>): Promise<T | undefined> {\n\tif (await reader.done()) return;\n\treturn await decode(reader, f);\n}\n"]}
|
package/lite/origin.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
/**
|
|
3
|
+
* A relay origin id, encoded as a 62-bit varint on the wire.
|
|
4
|
+
*
|
|
5
|
+
* The {@link OriginSchema} validates any incoming value and brands it so the
|
|
6
|
+
* type system enforces "only validated origins flow into hop lists." Internal
|
|
7
|
+
* code that synthesizes an id (e.g. {@link randomOrigin}) uses
|
|
8
|
+
* `OriginSchema.parse(...)` to produce a branded value from the raw bigint.
|
|
9
|
+
*/
|
|
10
|
+
export declare const OriginSchema: z.core.$ZodBranded<z.ZodMiniBigInt<bigint>, "Origin", "out">;
|
|
11
|
+
export type Origin = z.infer<typeof OriginSchema>;
|
|
12
|
+
/**
|
|
13
|
+
* Generate a fresh origin with a random non-zero 62-bit id.
|
|
14
|
+
*
|
|
15
|
+
* `crypto.getRandomValues` is overkill for best-effort loop detection, but
|
|
16
|
+
* used for slightly better distribution than `Math.random` at negligible cost.
|
|
17
|
+
*/
|
|
18
|
+
export declare function randomOrigin(): Origin;
|
|
19
|
+
//# sourceMappingURL=origin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin.d.ts","sourceRoot":"","sources":["../../src/lite/origin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,8DAGR,CAAC;AAElB,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAOrC"}
|
package/lite/origin.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
/**
|
|
3
|
+
* A relay origin id, encoded as a 62-bit varint on the wire.
|
|
4
|
+
*
|
|
5
|
+
* The {@link OriginSchema} validates any incoming value and brands it so the
|
|
6
|
+
* type system enforces "only validated origins flow into hop lists." Internal
|
|
7
|
+
* code that synthesizes an id (e.g. {@link randomOrigin}) uses
|
|
8
|
+
* `OriginSchema.parse(...)` to produce a branded value from the raw bigint.
|
|
9
|
+
*/
|
|
10
|
+
export const OriginSchema = z
|
|
11
|
+
.bigint()
|
|
12
|
+
.check(z.refine((value) => value >= 0n && value < 1n << 62n, "Origin must be a non-negative 62-bit integer"))
|
|
13
|
+
.brand("Origin");
|
|
14
|
+
/**
|
|
15
|
+
* Generate a fresh origin with a random non-zero 62-bit id.
|
|
16
|
+
*
|
|
17
|
+
* `crypto.getRandomValues` is overkill for best-effort loop detection, but
|
|
18
|
+
* used for slightly better distribution than `Math.random` at negligible cost.
|
|
19
|
+
*/
|
|
20
|
+
export function randomOrigin() {
|
|
21
|
+
const buf = new BigUint64Array(1);
|
|
22
|
+
crypto.getRandomValues(buf);
|
|
23
|
+
// Mask to 62 bits.
|
|
24
|
+
const raw = buf[0] & 0x3fffffffffffffffn;
|
|
25
|
+
// Guard against the (astronomically unlikely) zero draw.
|
|
26
|
+
return OriginSchema.parse(raw === 0n ? 1n : raw);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=origin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin.js","sourceRoot":"","sources":["../../src/lite/origin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC;KAC3B,MAAM,EAAE;KACR,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,IAAI,KAAK,GAAG,EAAE,IAAI,GAAG,EAAE,8CAA8C,CAAC,CAAC;KAC5G,KAAK,CAAC,QAAQ,CAAC,CAAC;AAIlB;;;;;GAKG;AACH,MAAM,UAAU,YAAY;IAC3B,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IAC5B,mBAAmB;IACnB,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,mBAAsB,CAAC;IAC5C,yDAAyD;IACzD,OAAO,YAAY,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import * as z from \"zod/mini\";\n\n/**\n * A relay origin id, encoded as a 62-bit varint on the wire.\n *\n * The {@link OriginSchema} validates any incoming value and brands it so the\n * type system enforces \"only validated origins flow into hop lists.\" Internal\n * code that synthesizes an id (e.g. {@link randomOrigin}) uses\n * `OriginSchema.parse(...)` to produce a branded value from the raw bigint.\n */\nexport const OriginSchema = z\n\t.bigint()\n\t.check(z.refine((value) => value >= 0n && value < 1n << 62n, \"Origin must be a non-negative 62-bit integer\"))\n\t.brand(\"Origin\");\n\nexport type Origin = z.infer<typeof OriginSchema>;\n\n/**\n * Generate a fresh origin with a random non-zero 62-bit id.\n *\n * `crypto.getRandomValues` is overkill for best-effort loop detection, but\n * used for slightly better distribution than `Math.random` at negligible cost.\n */\nexport function randomOrigin(): Origin {\n\tconst buf = new BigUint64Array(1);\n\tcrypto.getRandomValues(buf);\n\t// Mask to 62 bits.\n\tconst raw = buf[0] & 0x3fff_ffff_ffff_ffffn;\n\t// Guard against the (astronomically unlikely) zero draw.\n\treturn OriginSchema.parse(raw === 0n ? 1n : raw);\n}\n"]}
|
package/lite/probe.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Reader, Writer } from "../stream.ts";
|
|
2
|
+
import { Version } from "./version.ts";
|
|
3
|
+
export declare class Probe {
|
|
4
|
+
#private;
|
|
5
|
+
bitrate: number;
|
|
6
|
+
rtt?: number;
|
|
7
|
+
constructor(bitrate: number, rtt?: number);
|
|
8
|
+
encode(w: Writer, version: Version): Promise<void>;
|
|
9
|
+
static decode(r: Reader, version: Version): Promise<Probe>;
|
|
10
|
+
static decodeMaybe(r: Reader, version: Version): Promise<Probe | undefined>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=probe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe.d.ts","sourceRoot":"","sources":["../../src/lite/probe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAYvC,qBAAa,KAAK;;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;gBAED,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAkCnC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;WAK3C,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;WAKnD,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;CAIjF"}
|
package/lite/probe.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as Message from "./message.js";
|
|
2
|
+
import { Version } from "./version.js";
|
|
3
|
+
function guardProbe(version) {
|
|
4
|
+
switch (version) {
|
|
5
|
+
case Version.DRAFT_01:
|
|
6
|
+
case Version.DRAFT_02:
|
|
7
|
+
throw new Error("probe not supported for this version");
|
|
8
|
+
default:
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class Probe {
|
|
13
|
+
bitrate;
|
|
14
|
+
rtt;
|
|
15
|
+
constructor(bitrate, rtt) {
|
|
16
|
+
this.bitrate = bitrate;
|
|
17
|
+
this.rtt = rtt;
|
|
18
|
+
}
|
|
19
|
+
async #encode(w, version) {
|
|
20
|
+
await w.u53(this.bitrate);
|
|
21
|
+
switch (version) {
|
|
22
|
+
case Version.DRAFT_03:
|
|
23
|
+
break;
|
|
24
|
+
default: {
|
|
25
|
+
// 0 means unknown; round Some(0) up to 1.
|
|
26
|
+
const wire = this.rtt !== undefined ? Math.max(this.rtt, 1) : 0;
|
|
27
|
+
await w.u53(wire);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static async #decode(r, version) {
|
|
33
|
+
const bitrate = await r.u53();
|
|
34
|
+
let rtt;
|
|
35
|
+
switch (version) {
|
|
36
|
+
case Version.DRAFT_03:
|
|
37
|
+
break;
|
|
38
|
+
default: {
|
|
39
|
+
const wire = await r.u53();
|
|
40
|
+
rtt = wire === 0 ? undefined : wire;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return new Probe(bitrate, rtt);
|
|
45
|
+
}
|
|
46
|
+
async encode(w, version) {
|
|
47
|
+
guardProbe(version);
|
|
48
|
+
return Message.encode(w, (w) => this.#encode(w, version));
|
|
49
|
+
}
|
|
50
|
+
static async decode(r, version) {
|
|
51
|
+
guardProbe(version);
|
|
52
|
+
return Message.decode(r, (r) => Probe.#decode(r, version));
|
|
53
|
+
}
|
|
54
|
+
static async decodeMaybe(r, version) {
|
|
55
|
+
guardProbe(version);
|
|
56
|
+
return Message.decodeMaybe(r, (r) => Probe.#decode(r, version));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=probe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe.js","sourceRoot":"","sources":["../../src/lite/probe.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,UAAU,CAAC,OAAgB;IACnC,QAAQ,OAAO,EAAE,CAAC;QACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ;YACpB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QACzD;YACC,MAAM;IACR,CAAC;AACF,CAAC;AAED,MAAM,OAAO,KAAK;IACjB,OAAO,CAAS;IAChB,GAAG,CAAU;IAEb,YAAY,OAAe,EAAE,GAAY;QACxC,IAAI,CAAC,OAAO,GAAG,O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E,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,UAAU,CAAC,OAAO,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAS,EAAE,OAAgB;QACnD,UAAU,CAAC,OAAO,CAAC,CAAC;QACpB,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;CACD","sourcesContent":["import type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction guardProbe(version: Version) {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\tthrow new Error(\"probe not supported for this version\");\n\t\tdefault:\n\t\t\tbreak;\n\t}\n}\n\nexport class Probe {\n\tbitrate: number;\n\trtt?: number;\n\n\tconstructor(bitrate: number, rtt?: number) {\n\t\tthis.bitrate = bitrate;\n\t\tthis.rtt = rtt;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.u53(this.bitrate);\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_03:\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\t// 0 means unknown; round Some(0) up to 1.\n\t\t\t\tconst wire = this.rtt !== undefined ? Math.max(this.rtt, 1) : 0;\n\t\t\t\tawait w.u53(wire);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<Probe> {\n\t\tconst bitrate = await r.u53();\n\t\tlet rtt: number | undefined;\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_03:\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst wire = await r.u53();\n\t\t\t\trtt = wire === 0 ? undefined : wire;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn new Probe(bitrate, rtt);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardProbe(version);\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<Probe> {\n\t\tguardProbe(version);\n\t\treturn Message.decode(r, (r) => Probe.#decode(r, version));\n\t}\n\n\tstatic async decodeMaybe(r: Reader, version: Version): Promise<Probe | undefined> {\n\t\tguardProbe(version);\n\t\treturn Message.decodeMaybe(r, (r) => Probe.#decode(r, version));\n\t}\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Broadcast } from "../broadcast.ts";
|
|
2
|
+
import * as Path from "../path.ts";
|
|
3
|
+
import { type Stream } from "../stream.ts";
|
|
4
|
+
import { type AnnounceInterest } from "./announce.ts";
|
|
5
|
+
import type { Origin } from "./origin.ts";
|
|
6
|
+
import { type Subscribe } from "./subscribe.ts";
|
|
7
|
+
import { Version } from "./version.ts";
|
|
8
|
+
/**
|
|
9
|
+
* Handles publishing broadcasts and managing their lifecycle.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare class Publisher {
|
|
14
|
+
#private;
|
|
15
|
+
readonly version: Version;
|
|
16
|
+
readonly origin: Origin;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new Publisher instance.
|
|
19
|
+
* @param quic - The WebTransport session to use
|
|
20
|
+
* @param version - Negotiated protocol version
|
|
21
|
+
* @param origin - Origin id shared with the Subscriber
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
constructor(quic: WebTransport, version: Version, origin: Origin);
|
|
26
|
+
/**
|
|
27
|
+
* Publishes a broadcast with any associated tracks.
|
|
28
|
+
* @param name - The broadcast to publish
|
|
29
|
+
*/
|
|
30
|
+
publish(path: Path.Valid, broadcast: Broadcast): void;
|
|
31
|
+
/**
|
|
32
|
+
* Handles an announce interest message.
|
|
33
|
+
* @param msg - The announce interest message
|
|
34
|
+
* @param stream - The stream to write announcements to
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
runAnnounce(msg: AnnounceInterest, stream: Stream): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Handles a subscribe message.
|
|
41
|
+
* @param msg - The subscribe message
|
|
42
|
+
* @param stream - The stream to write track data to
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
runSubscribe(msg: Subscribe, stream: Stream): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Handles a probe stream by periodically reporting estimated bitrate.
|
|
49
|
+
* @param stream - The probe bidi stream
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
runProbe(stream: Stream): Promise<void>;
|
|
54
|
+
close(): void;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=publisher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publisher.d.ts","sourceRoot":"","sources":["../../src/lite/publisher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,MAAM,EAAU,MAAM,cAAc,CAAC;AAGnD,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAA2B,KAAK,SAAS,EAAgC,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAMvC;;;;GAIG;AACH,qBAAa,SAAS;;IAErB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAM1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAQxB;;;;;;;OAOG;gBACS,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;IAMhE;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS;IAc9C;;;;;;OAMG;IACG,WAAW,CAAC,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM;IA4EvD;;;;;;OAMG;IACG,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;IA8GjD;;;;;OAKG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM;IAqD7B,KAAK;CAQL"}
|