@moq/net 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/connection/accept.js +8 -3
  2. package/connection/accept.js.map +1 -1
  3. package/connection/connect.d.ts.map +1 -1
  4. package/connection/connect.js +5 -2
  5. package/connection/connect.js.map +1 -1
  6. package/connection/handshake.d.ts +9 -1
  7. package/connection/handshake.d.ts.map +1 -1
  8. package/connection/handshake.js +18 -14
  9. package/connection/handshake.js.map +1 -1
  10. package/ietf/connection.d.ts +7 -1
  11. package/ietf/connection.d.ts.map +1 -1
  12. package/ietf/connection.js +23 -3
  13. package/ietf/connection.js.map +1 -1
  14. package/ietf/index.d.ts +1 -0
  15. package/ietf/index.d.ts.map +1 -1
  16. package/ietf/index.js +1 -0
  17. package/ietf/index.js.map +1 -1
  18. package/ietf/parameters.d.ts +1 -0
  19. package/ietf/parameters.d.ts.map +1 -1
  20. package/ietf/parameters.js +2 -0
  21. package/ietf/parameters.js.map +1 -1
  22. package/ietf/publisher.d.ts +22 -8
  23. package/ietf/publisher.d.ts.map +1 -1
  24. package/ietf/publisher.js +294 -77
  25. package/ietf/publisher.js.map +1 -1
  26. package/ietf/solicit.d.ts +41 -0
  27. package/ietf/solicit.d.ts.map +1 -0
  28. package/ietf/solicit.js +47 -0
  29. package/ietf/solicit.js.map +1 -0
  30. package/ietf/subscriber.d.ts +4 -0
  31. package/ietf/subscriber.d.ts.map +1 -1
  32. package/ietf/subscriber.js +122 -50
  33. package/ietf/subscriber.js.map +1 -1
  34. package/lite/publisher.d.ts.map +1 -1
  35. package/lite/publisher.js +43 -9
  36. package/lite/publisher.js.map +1 -1
  37. package/lite/subscriber.js +3 -3
  38. package/lite/subscriber.js.map +1 -1
  39. package/package.json +2 -2
  40. package/stream.d.ts +46 -2
  41. package/stream.d.ts.map +1 -1
  42. package/stream.js +71 -6
  43. package/stream.js.map +1 -1
  44. package/track.d.ts +20 -7
  45. package/track.d.ts.map +1 -1
  46. package/track.js +63 -27
  47. package/track.js.map +1 -1
  48. package/announced.test.d.ts +0 -2
  49. package/announced.test.d.ts.map +0 -1
  50. package/announced.test.js +0 -37
  51. package/announced.test.js.map +0 -1
  52. package/broadcast.test.d.ts +0 -2
  53. package/broadcast.test.d.ts.map +0 -1
  54. package/broadcast.test.js +0 -243
  55. package/broadcast.test.js.map +0 -1
  56. package/connection/browser.test.d.ts +0 -2
  57. package/connection/browser.test.d.ts.map +0 -1
  58. package/connection/browser.test.js +0 -29
  59. package/connection/browser.test.js.map +0 -1
  60. package/connection/cert.test.d.ts +0 -2
  61. package/connection/cert.test.d.ts.map +0 -1
  62. package/connection/cert.test.js +0 -26
  63. package/connection/cert.test.js.map +0 -1
  64. package/connection/connect.test.d.ts +0 -2
  65. package/connection/connect.test.d.ts.map +0 -1
  66. package/connection/connect.test.js +0 -118
  67. package/connection/connect.test.js.map +0 -1
  68. package/connection/reload.test.d.ts +0 -2
  69. package/connection/reload.test.d.ts.map +0 -1
  70. package/connection/reload.test.js +0 -160
  71. package/connection/reload.test.js.map +0 -1
  72. package/connection/stats.test.d.ts +0 -2
  73. package/connection/stats.test.d.ts.map +0 -1
  74. package/connection/stats.test.js +0 -120
  75. package/connection/stats.test.js.map +0 -1
  76. package/error.test.d.ts +0 -2
  77. package/error.test.d.ts.map +0 -1
  78. package/error.test.js +0 -89
  79. package/error.test.js.map +0 -1
  80. package/group.test.d.ts +0 -2
  81. package/group.test.d.ts.map +0 -1
  82. package/group.test.js +0 -152
  83. package/group.test.js.map +0 -1
  84. package/ietf/aliases.test.d.ts +0 -2
  85. package/ietf/aliases.test.d.ts.map +0 -1
  86. package/ietf/aliases.test.js +0 -30
  87. package/ietf/aliases.test.js.map +0 -1
  88. package/ietf/ietf.test.d.ts +0 -2
  89. package/ietf/ietf.test.d.ts.map +0 -1
  90. package/ietf/ietf.test.js +0 -983
  91. package/ietf/ietf.test.js.map +0 -1
  92. package/ietf/priority.test.d.ts +0 -2
  93. package/ietf/priority.test.d.ts.map +0 -1
  94. package/ietf/priority.test.js +0 -18
  95. package/ietf/priority.test.js.map +0 -1
  96. package/integration.test.d.ts +0 -2
  97. package/integration.test.d.ts.map +0 -1
  98. package/integration.test.js +0 -1006
  99. package/integration.test.js.map +0 -1
  100. package/lite/announce.test.d.ts +0 -2
  101. package/lite/announce.test.d.ts.map +0 -1
  102. package/lite/announce.test.js +0 -91
  103. package/lite/announce.test.js.map +0 -1
  104. package/lite/datagram.test.d.ts +0 -2
  105. package/lite/datagram.test.d.ts.map +0 -1
  106. package/lite/datagram.test.js +0 -26
  107. package/lite/datagram.test.js.map +0 -1
  108. package/lite/datagram_stream.test.d.ts +0 -2
  109. package/lite/datagram_stream.test.d.ts.map +0 -1
  110. package/lite/datagram_stream.test.js +0 -15
  111. package/lite/datagram_stream.test.js.map +0 -1
  112. package/lite/fetch.test.d.ts +0 -2
  113. package/lite/fetch.test.d.ts.map +0 -1
  114. package/lite/fetch.test.js +0 -41
  115. package/lite/fetch.test.js.map +0 -1
  116. package/lite/priority.test.d.ts +0 -2
  117. package/lite/priority.test.d.ts.map +0 -1
  118. package/lite/priority.test.js +0 -77
  119. package/lite/priority.test.js.map +0 -1
  120. package/lite/publisher.test.d.ts +0 -2
  121. package/lite/publisher.test.d.ts.map +0 -1
  122. package/lite/publisher.test.js +0 -334
  123. package/lite/publisher.test.js.map +0 -1
  124. package/lite/setup.test.d.ts +0 -2
  125. package/lite/setup.test.d.ts.map +0 -1
  126. package/lite/setup.test.js +0 -134
  127. package/lite/setup.test.js.map +0 -1
  128. package/lite/subscribe.test.d.ts +0 -2
  129. package/lite/subscribe.test.d.ts.map +0 -1
  130. package/lite/subscribe.test.js +0 -110
  131. package/lite/subscribe.test.js.map +0 -1
  132. package/lite/subscriber.test.d.ts +0 -2
  133. package/lite/subscriber.test.d.ts.map +0 -1
  134. package/lite/subscriber.test.js +0 -108
  135. package/lite/subscriber.test.js.map +0 -1
  136. package/lite/track.test.d.ts +0 -2
  137. package/lite/track.test.d.ts.map +0 -1
  138. package/lite/track.test.js +0 -55
  139. package/lite/track.test.js.map +0 -1
  140. package/path.test.d.ts +0 -2
  141. package/path.test.d.ts.map +0 -1
  142. package/path.test.js +0 -210
  143. package/path.test.js.map +0 -1
  144. package/stream.test.d.ts +0 -2
  145. package/stream.test.d.ts.map +0 -1
  146. package/stream.test.js +0 -252
  147. package/stream.test.js.map +0 -1
  148. package/time.test.d.ts +0 -2
  149. package/time.test.d.ts.map +0 -1
  150. package/time.test.js +0 -12
  151. package/time.test.js.map +0 -1
  152. package/track.test.d.ts +0 -2
  153. package/track.test.d.ts.map +0 -1
  154. package/track.test.js +0 -212
  155. package/track.test.js.map +0 -1
  156. package/util/timeout.test.d.ts +0 -2
  157. package/util/timeout.test.d.ts.map +0 -1
  158. package/util/timeout.test.js +0 -18
  159. package/util/timeout.test.js.map +0 -1
  160. package/varint.test.d.ts +0 -2
  161. package/varint.test.d.ts.map +0 -1
  162. package/varint.test.js +0 -106
  163. package/varint.test.js.map +0 -1
@@ -1,110 +0,0 @@
1
- /* @ts-self-types="./subscribe.test.d.ts" */
2
- import { expect, test } from "bun:test";
3
- import * as Path from "../path.js";
4
- import { Reader, Writer } from "../stream.js";
5
- import { decodeSubscribeResponse, encodeSubscribeResponse, Subscribe, SubscribeDrop, SubscribeEnd, SubscribeOk, SubscribeStart, SubscribeUpdate, } from "./subscribe.js";
6
- import { Version } from "./version.js";
7
- function concat(chunks) {
8
- const total = chunks.reduce((sum, c) => sum + c.byteLength, 0);
9
- const out = new Uint8Array(total);
10
- let offset = 0;
11
- for (const c of chunks) {
12
- out.set(c, offset);
13
- offset += c.byteLength;
14
- }
15
- return out;
16
- }
17
- async function encode(version, resp) {
18
- const written = [];
19
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
20
- await encodeSubscribeResponse(writer, resp, version);
21
- writer.close();
22
- await writer.closed;
23
- return concat(written);
24
- }
25
- async function responseRoundtrip(version, resp) {
26
- const reader = new Reader(undefined, await encode(version, resp));
27
- return decodeSubscribeResponse(reader, version);
28
- }
29
- async function encodeMessage(version, message) {
30
- const written = [];
31
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
32
- await message.encode(writer, version);
33
- writer.close();
34
- await writer.closed;
35
- return concat(written);
36
- }
37
- test("SubscribeOk round-trips priority/ordered/groups on draft-04", async () => {
38
- const got = await responseRoundtrip(Version.DRAFT_04, {
39
- ok: new SubscribeOk({ priority: 7, ordered: true, maxLatency: 250, startGroup: 3 }),
40
- });
41
- expect("ok" in got).toBe(true);
42
- if (!("ok" in got))
43
- throw new Error("expected ok");
44
- expect(got.ok.priority).toBe(7);
45
- expect(got.ok.ordered).toBe(true);
46
- expect(got.ok.startGroup).toBe(3);
47
- });
48
- test("Subscribe round-trips every option including startGroup 0", async () => {
49
- const message = new Subscribe({
50
- id: 4n,
51
- broadcast: Path.from("test"),
52
- track: "video",
53
- priority: 7,
54
- ordered: true,
55
- maxLatency: 250,
56
- startGroup: 0,
57
- endGroup: 9,
58
- });
59
- const got = await Subscribe.decode(new Reader(undefined, await encodeMessage(Version.DRAFT_05, message)), Version.DRAFT_05);
60
- expect(got.priority).toBe(7);
61
- expect(got.ordered).toBe(true);
62
- expect(got.maxLatency).toBe(250);
63
- expect(got.startGroup).toBe(0);
64
- expect(got.endGroup).toBe(9);
65
- });
66
- test("SubscribeUpdate round-trips every option including startGroup 0", async () => {
67
- const message = new SubscribeUpdate({
68
- priority: 8,
69
- ordered: true,
70
- maxLatency: 500,
71
- startGroup: 0,
72
- endGroup: 12,
73
- });
74
- const got = await SubscribeUpdate.decode(new Reader(undefined, await encodeMessage(Version.DRAFT_05, message)), Version.DRAFT_05);
75
- expect(got.priority).toBe(8);
76
- expect(got.ordered).toBe(true);
77
- expect(got.maxLatency).toBe(500);
78
- expect(got.startGroup).toBe(0);
79
- expect(got.endGroup).toBe(12);
80
- });
81
- test("SubscribeStart round-trips on draft-05", async () => {
82
- const got = await responseRoundtrip(Version.DRAFT_05, { start: new SubscribeStart(42) });
83
- expect("start" in got).toBe(true);
84
- if (!("start" in got))
85
- throw new Error("expected start");
86
- expect(got.start.group).toBe(42);
87
- });
88
- test("SubscribeEnd round-trips on draft-05", async () => {
89
- const got = await responseRoundtrip(Version.DRAFT_05, { end: new SubscribeEnd(7) });
90
- expect("end" in got).toBe(true);
91
- if (!("end" in got))
92
- throw new Error("expected end");
93
- expect(got.end.group).toBe(7);
94
- });
95
- test("SubscribeDrop is type 0x2 on draft-05 and 0x1 on draft-04", async () => {
96
- const drop = { drop: new SubscribeDrop({ start: 1, end: 3, error: 0 }) };
97
- const wire05 = await encode(Version.DRAFT_05, drop);
98
- expect(wire05[0]).toBe(2);
99
- const wire04 = await encode(Version.DRAFT_04, drop);
100
- expect(wire04[0]).toBe(1);
101
- const got = await responseRoundtrip(Version.DRAFT_05, drop);
102
- expect("drop" in got).toBe(true);
103
- if (!("drop" in got))
104
- throw new Error("expected drop");
105
- expect([got.drop.start, got.drop.end]).toEqual([1, 3]);
106
- });
107
- test("SUBSCRIBE_OK is rejected on draft-05", async () => {
108
- await expect(encode(Version.DRAFT_05, { ok: new SubscribeOk({ priority: 1 }) })).rejects.toThrow();
109
- });
110
- //# sourceMappingURL=subscribe.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscribe.test.js","sourceRoot":"","sources":["../../src/lite/subscribe.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,WAAW,EAEX,cAAc,EACd,eAAe,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,E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H,IAAI,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;IACvD,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,IAAI,WAAW,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AACpG,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport {\n\tdecodeSubscribeResponse,\n\tencodeSubscribeResponse,\n\tSubscribe,\n\tSubscribeDrop,\n\tSubscribeEnd,\n\tSubscribeOk,\n\ttype SubscribeResponse,\n\tSubscribeStart,\n\tSubscribeUpdate,\n} from \"./subscribe.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function encode(version: Version, resp: SubscribeResponse): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait encodeSubscribeResponse(writer, resp, version);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function responseRoundtrip(version: Version, resp: SubscribeResponse): Promise<SubscribeResponse> {\n\tconst reader = new Reader(undefined, await encode(version, resp));\n\treturn decodeSubscribeResponse(reader, version);\n}\n\nasync function encodeMessage(\n\tversion: Version,\n\tmessage: { encode(writer: Writer, version: Version): Promise<void> },\n): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait message.encode(writer, version);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\ntest(\"SubscribeOk round-trips priority/ordered/groups on draft-04\", async () => {\n\tconst got = await responseRoundtrip(Version.DRAFT_04, {\n\t\tok: new SubscribeOk({ priority: 7, ordered: true, maxLatency: 250, startGroup: 3 }),\n\t});\n\texpect(\"ok\" in got).toBe(true);\n\tif (!(\"ok\" in got)) throw new Error(\"expected ok\");\n\texpect(got.ok.priority).toBe(7);\n\texpect(got.ok.ordered).toBe(true);\n\texpect(got.ok.startGroup).toBe(3);\n});\n\ntest(\"Subscribe round-trips every option including startGroup 0\", async () => {\n\tconst message = new Subscribe({\n\t\tid: 4n,\n\t\tbroadcast: Path.from(\"test\"),\n\t\ttrack: \"video\",\n\t\tpriority: 7,\n\t\tordered: true,\n\t\tmaxLatency: 250,\n\t\tstartGroup: 0,\n\t\tendGroup: 9,\n\t});\n\tconst got = await Subscribe.decode(\n\t\tnew Reader(undefined, await encodeMessage(Version.DRAFT_05, message)),\n\t\tVersion.DRAFT_05,\n\t);\n\texpect(got.priority).toBe(7);\n\texpect(got.ordered).toBe(true);\n\texpect(got.maxLatency).toBe(250);\n\texpect(got.startGroup).toBe(0);\n\texpect(got.endGroup).toBe(9);\n});\n\ntest(\"SubscribeUpdate round-trips every option including startGroup 0\", async () => {\n\tconst message = new SubscribeUpdate({\n\t\tpriority: 8,\n\t\tordered: true,\n\t\tmaxLatency: 500,\n\t\tstartGroup: 0,\n\t\tendGroup: 12,\n\t});\n\tconst got = await SubscribeUpdate.decode(\n\t\tnew Reader(undefined, await encodeMessage(Version.DRAFT_05, message)),\n\t\tVersion.DRAFT_05,\n\t);\n\texpect(got.priority).toBe(8);\n\texpect(got.ordered).toBe(true);\n\texpect(got.maxLatency).toBe(500);\n\texpect(got.startGroup).toBe(0);\n\texpect(got.endGroup).toBe(12);\n});\n\ntest(\"SubscribeStart round-trips on draft-05\", async () => {\n\tconst got = await responseRoundtrip(Version.DRAFT_05, { start: new SubscribeStart(42) });\n\texpect(\"start\" in got).toBe(true);\n\tif (!(\"start\" in got)) throw new Error(\"expected start\");\n\texpect(got.start.group).toBe(42);\n});\n\ntest(\"SubscribeEnd round-trips on draft-05\", async () => {\n\tconst got = await responseRoundtrip(Version.DRAFT_05, { end: new SubscribeEnd(7) });\n\texpect(\"end\" in got).toBe(true);\n\tif (!(\"end\" in got)) throw new Error(\"expected end\");\n\texpect(got.end.group).toBe(7);\n});\n\ntest(\"SubscribeDrop is type 0x2 on draft-05 and 0x1 on draft-04\", async () => {\n\tconst drop: SubscribeResponse = { drop: new SubscribeDrop({ start: 1, end: 3, error: 0 }) };\n\n\tconst wire05 = await encode(Version.DRAFT_05, drop);\n\texpect(wire05[0]).toBe(2);\n\n\tconst wire04 = await encode(Version.DRAFT_04, drop);\n\texpect(wire04[0]).toBe(1);\n\n\tconst got = await responseRoundtrip(Version.DRAFT_05, drop);\n\texpect(\"drop\" in got).toBe(true);\n\tif (!(\"drop\" in got)) throw new Error(\"expected drop\");\n\texpect([got.drop.start, got.drop.end]).toEqual([1, 3]);\n});\n\ntest(\"SUBSCRIBE_OK is rejected on draft-05\", async () => {\n\tawait expect(encode(Version.DRAFT_05, { ok: new SubscribeOk({ priority: 1 }) })).rejects.toThrow();\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=subscriber.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscriber.test.d.ts","sourceRoot":"","sources":["../../src/lite/subscriber.test.ts"],"names":[],"mappings":""}
@@ -1,108 +0,0 @@
1
- /* @ts-self-types="./subscriber.test.d.ts" */
2
- import { expect, spyOn, test } from "bun:test";
3
- import { Signal } from "@moq/signals";
4
- import * as Path from "../path.js";
5
- import { Writer } from "../stream.js";
6
- import { AnnounceOk, encodeAnnounceBroadcast } from "./announce.js";
7
- import { OriginSchema } from "./origin.js";
8
- import { Subscriber } from "./subscriber.js";
9
- import { Version } from "./version.js";
10
- test("closing the subscriber suppresses probe stream warnings", async () => {
11
- let readable;
12
- const quic = {
13
- createBidirectionalStream: async () => ({
14
- readable: new ReadableStream({ start: (controller) => (readable = controller) }),
15
- writable: new WritableStream(),
16
- }),
17
- };
18
- const subscriber = new Subscriber(quic, Version.DRAFT_03, OriginSchema.parse(1n), new Signal({}));
19
- const warn = spyOn(console, "warn").mockImplementation(() => { });
20
- try {
21
- const probe = subscriber.runProbe();
22
- await Promise.resolve();
23
- await Promise.resolve();
24
- subscriber.close();
25
- readable.error(new Error("session closed"));
26
- await probe;
27
- expect(warn).not.toHaveBeenCalled();
28
- }
29
- finally {
30
- warn.mockRestore();
31
- }
32
- });
33
- // Drives a Subscriber's announce stream directly: the harness plays the peer, writing
34
- // forged announce messages into the stream the subscriber opens.
35
- function announceHarness(version, origin = 1n) {
36
- let inbound;
37
- const quic = {
38
- createBidirectionalStream: async () => ({
39
- readable: new ReadableStream({ start: (controller) => (inbound = controller) }),
40
- writable: new WritableStream(),
41
- }),
42
- };
43
- const subscriber = new Subscriber(quic, version, OriginSchema.parse(origin));
44
- const send = async (f) => {
45
- const written = [];
46
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
47
- await f(writer);
48
- writer.close();
49
- await writer.closed;
50
- const total = written.reduce((sum, c) => sum + c.byteLength, 0);
51
- const out = new Uint8Array(total);
52
- let offset = 0;
53
- for (const chunk of written) {
54
- out.set(chunk, offset);
55
- offset += chunk.byteLength;
56
- }
57
- inbound.enqueue(out);
58
- };
59
- return { subscriber, send, settle: () => new Promise((resolve) => setTimeout(resolve, 0)) };
60
- }
61
- const PUBLISHER_A = OriginSchema.parse(7n);
62
- const PUBLISHER_B = OriginSchema.parse(8n);
63
- const PUBLISHER_C = OriginSchema.parse(9n);
64
- const PEER = OriginSchema.parse(2n);
65
- test("a restart from the same publisher is a route change, not a republish", async () => {
66
- const { subscriber, send, settle } = announceHarness(Version.DRAFT_06);
67
- const announced = subscriber.announced(Path.empty());
68
- await settle();
69
- await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06));
70
- await send((w) => encodeAnnounceBroadcast(w, { status: "active", suffix: Path.from("room"), hops: [PUBLISHER_A] }, Version.DRAFT_06));
71
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
72
- // Same publisher over a new route. In-flight subscriptions resume across it, so the
73
- // subscriber must not surface anything that would make a consumer re-subscribe.
74
- await send((w) => encodeAnnounceBroadcast(w, { status: "restart", id: 0n, hops: [PUBLISHER_A] }, Version.DRAFT_06));
75
- // A different publisher took the path: nothing carries over, so this one does surface,
76
- // as an end before the start. Reaching it proves the reroute above emitted nothing.
77
- await send((w) => encodeAnnounceBroadcast(w, { status: "restart", id: 0n, hops: [PUBLISHER_B] }, Version.DRAFT_06));
78
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: false });
79
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
80
- // A third publisher takes over. The replacement above has to leave its own publisher on
81
- // record, or this one reads as a first announcement and skips the end.
82
- await send((w) => encodeAnnounceBroadcast(w, { status: "restart", id: 0n, hops: [PUBLISHER_C] }, Version.DRAFT_06));
83
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: false });
84
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
85
- // And the new owner's own reroute is still transparent.
86
- await send((w) => encodeAnnounceBroadcast(w, { status: "restart", id: 0n, hops: [PUBLISHER_C] }, Version.DRAFT_06));
87
- await send((w) => encodeAnnounceBroadcast(w, { status: "endedId", id: 0n }, Version.DRAFT_06));
88
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: false });
89
- announced.close();
90
- subscriber.close();
91
- });
92
- test("a lite-05 duplicate announce follows the same restart rule", async () => {
93
- const { subscriber, send, settle } = announceHarness(Version.DRAFT_05);
94
- const announced = subscriber.announced(Path.empty());
95
- await settle();
96
- await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_05));
97
- const active = (hops) => (w) => encodeAnnounceBroadcast(w, { status: "active", suffix: Path.from("room"), hops }, Version.DRAFT_05);
98
- await send(active([PUBLISHER_A]));
99
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
100
- // On lite-05 a restart travels as a duplicate ANNOUNCE rather than its own message.
101
- await send(active([PUBLISHER_A]));
102
- await send(active([PUBLISHER_B]));
103
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: false });
104
- expect(await announced.next()).toEqual({ path: Path.from("room"), active: true });
105
- announced.close();
106
- subscriber.close();
107
- });
108
- //# sourceMappingURL=subscriber.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subscriber.test.js","sourceRoot":"","sources":["../../src/lite/subscriber.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;IAC1E,IAAI,QAAsD,CAAC;IAC3D,MAAM,IAAI,GAAG;QACZ,yBAAyB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACvC,QAAQ,EAAE,IAAI,cAAc,CAAa,EAAE,KAAK,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,QAAQ,GAAG,UAAU,CAAC,EAAE,CAAC;YAC5F,QAAQ,EAAE,IAAI,cAAc,EAAc;SAC1C,CAAC;KACyB,CAAC;IAC7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AC;IAErG,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAElF,oFAAoF;IACpF,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACnF,MAAM,CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAElF,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,UAAU,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC,CAAC,CAAC","sourcesContent":["import { expect, spyOn, test } from \"bun:test\";\nimport { Signal } from \"@moq/signals\";\nimport type { Probe } from \"../connection/stats.ts\";\nimport * as Path from \"../path.ts\";\nimport { Writer } from \"../stream.ts\";\nimport { AnnounceOk, encodeAnnounceBroadcast } from \"./announce.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Version } from \"./version.ts\";\n\ntest(\"closing the subscriber suppresses probe stream warnings\", async () => {\n\tlet readable!: ReadableStreamDefaultController<Uint8Array>;\n\tconst quic = {\n\t\tcreateBidirectionalStream: async () => ({\n\t\t\treadable: new ReadableStream<Uint8Array>({ start: (controller) => (readable = controller) }),\n\t\t\twritable: new WritableStream<Uint8Array>(),\n\t\t}),\n\t} as unknown as WebTransport;\n\tconst subscriber = new Subscriber(quic, Version.DRAFT_03, OriginSchema.parse(1n), new Signal<Probe>({}));\n\tconst warn = spyOn(console, \"warn\").mockImplementation(() => {});\n\n\ttry {\n\t\tconst probe = subscriber.runProbe();\n\n\t\tawait Promise.resolve();\n\t\tawait Promise.resolve();\n\t\tsubscriber.close();\n\t\treadable.error(new Error(\"session closed\"));\n\t\tawait probe;\n\n\t\texpect(warn).not.toHaveBeenCalled();\n\t} finally {\n\t\twarn.mockRestore();\n\t}\n});\n\n// Drives a Subscriber's announce stream directly: the harness plays the peer, writing\n// forged announce messages into the stream the subscriber opens.\nfunction announceHarness(version: Version, origin = 1n) {\n\tlet inbound!: ReadableStreamDefaultController<Uint8Array>;\n\tconst quic = {\n\t\tcreateBidirectionalStream: async () => ({\n\t\t\treadable: new ReadableStream<Uint8Array>({ start: (controller) => (inbound = controller) }),\n\t\t\twritable: new WritableStream<Uint8Array>(),\n\t\t}),\n\t} as unknown as WebTransport;\n\n\tconst subscriber = new Subscriber(quic, version, OriginSchema.parse(origin));\n\n\tconst send = async (f: (w: Writer) => Promise<void>) => {\n\t\tconst written: Uint8Array[] = [];\n\t\tconst writer = new Writer(\n\t\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t\t);\n\t\tawait f(writer);\n\t\twriter.close();\n\t\tawait writer.closed;\n\n\t\tconst total = written.reduce((sum, c) => sum + c.byteLength, 0);\n\t\tconst out = new Uint8Array(total);\n\t\tlet offset = 0;\n\t\tfor (const chunk of written) {\n\t\t\tout.set(chunk, offset);\n\t\t\toffset += chunk.byteLength;\n\t\t}\n\t\tinbound.enqueue(out);\n\t};\n\n\treturn { subscriber, send, settle: () => new Promise((resolve) => setTimeout(resolve, 0)) };\n}\n\nconst PUBLISHER_A = OriginSchema.parse(7n);\nconst PUBLISHER_B = OriginSchema.parse(8n);\nconst PUBLISHER_C = OriginSchema.parse(9n);\nconst PEER = OriginSchema.parse(2n);\n\ntest(\"a restart from the same publisher is a route change, not a republish\", async () => {\n\tconst { subscriber, send, settle } = announceHarness(Version.DRAFT_06);\n\tconst announced = subscriber.announced(Path.empty());\n\tawait settle();\n\n\tawait send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06));\n\tawait send((w) =>\n\t\tencodeAnnounceBroadcast(\n\t\t\tw,\n\t\t\t{ status: \"active\", suffix: Path.from(\"room\"), hops: [PUBLISHER_A] },\n\t\t\tVersion.DRAFT_06,\n\t\t),\n\t);\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\t// Same publisher over a new route. In-flight subscriptions resume across it, so the\n\t// subscriber must not surface anything that would make a consumer re-subscribe.\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 0n, hops: [PUBLISHER_A] }, Version.DRAFT_06));\n\n\t// A different publisher took the path: nothing carries over, so this one does surface,\n\t// as an end before the start. Reaching it proves the reroute above emitted nothing.\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 0n, hops: [PUBLISHER_B] }, Version.DRAFT_06));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: false });\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\t// A third publisher takes over. The replacement above has to leave its own publisher on\n\t// record, or this one reads as a first announcement and skips the end.\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 0n, hops: [PUBLISHER_C] }, Version.DRAFT_06));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: false });\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\t// And the new owner's own reroute is still transparent.\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 0n, hops: [PUBLISHER_C] }, Version.DRAFT_06));\n\tawait send((w) => encodeAnnounceBroadcast(w, { status: \"endedId\", id: 0n }, Version.DRAFT_06));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: false });\n\n\tannounced.close();\n\tsubscriber.close();\n});\n\ntest(\"a lite-05 duplicate announce follows the same restart rule\", async () => {\n\tconst { subscriber, send, settle } = announceHarness(Version.DRAFT_05);\n\tconst announced = subscriber.announced(Path.empty());\n\tawait settle();\n\n\tawait send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_05));\n\tconst active = (hops: ReturnType<typeof OriginSchema.parse>[]) => (w: Writer) =>\n\t\tencodeAnnounceBroadcast(w, { status: \"active\", suffix: Path.from(\"room\"), hops }, Version.DRAFT_05);\n\n\tawait send(active([PUBLISHER_A]));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\t// On lite-05 a restart travels as a duplicate ANNOUNCE rather than its own message.\n\tawait send(active([PUBLISHER_A]));\n\tawait send(active([PUBLISHER_B]));\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: false });\n\texpect(await announced.next()).toEqual({ path: Path.from(\"room\"), active: true });\n\n\tannounced.close();\n\tsubscriber.close();\n});\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=track.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"track.test.d.ts","sourceRoot":"","sources":["../../src/lite/track.test.ts"],"names":[],"mappings":""}
@@ -1,55 +0,0 @@
1
- /* @ts-self-types="./track.test.d.ts" */
2
- import { expect, test } from "bun:test";
3
- import * as Path from "../path.js";
4
- import { Reader, Writer } from "../stream.js";
5
- import { infoDefaults } from "../track.js";
6
- import { Track, TrackInfo } from "./track.js";
7
- import { Version } from "./version.js";
8
- function concat(chunks) {
9
- const total = chunks.reduce((sum, c) => sum + c.byteLength, 0);
10
- const out = new Uint8Array(total);
11
- let offset = 0;
12
- for (const c of chunks) {
13
- out.set(c, offset);
14
- offset += c.byteLength;
15
- }
16
- return out;
17
- }
18
- async function bytes(f) {
19
- const written = [];
20
- const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
21
- await f(writer);
22
- writer.close();
23
- await writer.closed;
24
- return concat(written);
25
- }
26
- test("TrackInfo round-trips on draft-05", async () => {
27
- const info = new TrackInfo({
28
- priority: 7,
29
- ordered: false,
30
- latencyMax: 2000,
31
- timescale: 90000,
32
- });
33
- const reader = new Reader(undefined, await bytes((w) => info.encode(w, Version.DRAFT_05)));
34
- const got = await TrackInfo.decode(reader, Version.DRAFT_05);
35
- expect(got.priority).toBe(7);
36
- expect(got.ordered).toBe(false);
37
- expect(got.latencyMax).toBe(2000);
38
- expect(got.timescale).toBe(90000);
39
- });
40
- test("TrackInfo defaults match cross-language wire bytes", async () => {
41
- const info = new TrackInfo(infoDefaults());
42
- expect(await bytes((w) => info.encode(w, Version.DRAFT_05))).toEqual(new Uint8Array([0x06, 0x00, 0x00, 0x53, 0x88, 0x43, 0xe8]));
43
- });
44
- test("Track request round-trips on draft-05", async () => {
45
- const msg = new Track(Path.from("room"), "video");
46
- const reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));
47
- const got = await Track.decode(reader, Version.DRAFT_05);
48
- expect(got.broadcast).toBe(Path.from("room"));
49
- expect(got.track).toBe("video");
50
- });
51
- test("TRACK_INFO is rejected before draft-05", async () => {
52
- const info = new TrackInfo({ timescale: 90000 });
53
- await expect(bytes((w) => info.encode(w, Version.DRAFT_04))).rejects.toThrow();
54
- });
55
- //# sourceMappingURL=track.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"track.test.js","sourceRoot":"","sources":["../../src/lite/track.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;A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,SAAS,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1F,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzD,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;IACzD,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAChF,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport { infoDefaults } from \"../track.ts\";\nimport { Track, TrackInfo } from \"./track.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function bytes(f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\ntest(\"TrackInfo round-trips on draft-05\", async () => {\n\tconst info = new TrackInfo({\n\t\tpriority: 7,\n\t\tordered: false,\n\t\tlatencyMax: 2000,\n\t\ttimescale: 90000,\n\t});\n\tconst reader = new Reader(undefined, await bytes((w) => info.encode(w, Version.DRAFT_05)));\n\tconst got = await TrackInfo.decode(reader, Version.DRAFT_05);\n\texpect(got.priority).toBe(7);\n\texpect(got.ordered).toBe(false);\n\texpect(got.latencyMax).toBe(2000);\n\texpect(got.timescale).toBe(90000);\n});\n\ntest(\"TrackInfo defaults match cross-language wire bytes\", async () => {\n\tconst info = new TrackInfo(infoDefaults());\n\texpect(await bytes((w) => info.encode(w, Version.DRAFT_05))).toEqual(\n\t\tnew Uint8Array([0x06, 0x00, 0x00, 0x53, 0x88, 0x43, 0xe8]),\n\t);\n});\n\ntest(\"Track request round-trips on draft-05\", async () => {\n\tconst msg = new Track(Path.from(\"room\"), \"video\");\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));\n\tconst got = await Track.decode(reader, Version.DRAFT_05);\n\texpect(got.broadcast).toBe(Path.from(\"room\"));\n\texpect(got.track).toBe(\"video\");\n});\n\ntest(\"TRACK_INFO is rejected before draft-05\", async () => {\n\tconst info = new TrackInfo({ timescale: 90000 });\n\tawait expect(bytes((w) => info.encode(w, Version.DRAFT_04))).rejects.toThrow();\n});\n"]}
package/path.test.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=path.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path.test.d.ts","sourceRoot":"","sources":["../src/path.test.ts"],"names":[],"mappings":""}
package/path.test.js DELETED
@@ -1,210 +0,0 @@
1
- /* @ts-self-types="./path.test.d.ts" */
2
- import { expect, test } from "bun:test";
3
- import * as Path from "./path.js";
4
- test("Path constructor trims leading and trailing slashes", () => {
5
- expect(Path.from("/foo/bar/")).toBe("foo/bar");
6
- expect(Path.from("///foo/bar///")).toBe("foo/bar");
7
- expect(Path.from("foo/bar")).toBe("foo/bar");
8
- });
9
- test("Path constructor handles empty paths", () => {
10
- expect(Path.from("")).toBe("");
11
- expect(Path.from("/")).toBe("");
12
- expect(Path.from("///")).toBe("");
13
- });
14
- test("hasPrefix matches exact paths", () => {
15
- const path = Path.from("foo/bar");
16
- expect(Path.hasPrefix(Path.from("foo/bar"), path)).toBe(true);
17
- });
18
- test("hasPrefix matches proper prefixes", () => {
19
- const path = Path.from("foo/bar/baz");
20
- expect(Path.hasPrefix(Path.from("foo"), path)).toBe(true);
21
- expect(Path.hasPrefix(Path.from("foo/bar"), path)).toBe(true);
22
- });
23
- test("hasPrefix does not match partial segment prefixes", () => {
24
- const path = Path.from("foobar");
25
- expect(Path.hasPrefix(Path.from("foo"), path)).toBe(false);
26
- const path2 = Path.from("foo/bar");
27
- expect(Path.hasPrefix(Path.from("fo"), path2)).toBe(false);
28
- });
29
- test("hasPrefix handles empty prefix", () => {
30
- const path = Path.from("foo/bar");
31
- expect(Path.hasPrefix(Path.empty(), path)).toBe(true);
32
- });
33
- test("hasPrefix ignores trailing slashes in prefix", () => {
34
- const path = Path.from("foo/bar");
35
- expect(Path.hasPrefix(Path.from("foo/"), path)).toBe(true);
36
- expect(Path.hasPrefix(Path.from("foo/bar/"), path)).toBe(true);
37
- });
38
- test("stripPrefix strips valid prefixes", () => {
39
- const path = Path.from("foo/bar/baz");
40
- const suffix1 = Path.stripPrefix(Path.from("foo"), path);
41
- expect(suffix1).toBe("bar/baz");
42
- const suffix2 = Path.stripPrefix(Path.from("foo/bar"), path);
43
- expect(suffix2).toBe("baz");
44
- const suffix3 = Path.stripPrefix(Path.from("foo/bar/baz"), path);
45
- expect(suffix3).toBe("");
46
- });
47
- test("stripPrefix returns null for invalid prefixes", () => {
48
- const path = Path.from("foo/bar");
49
- expect(Path.stripPrefix(Path.from("notfound"), path)).toBe(null);
50
- expect(Path.stripPrefix(Path.from("fo"), path)).toBe(null);
51
- });
52
- test("stripPrefix handles empty prefix", () => {
53
- const path = Path.from("foo/bar");
54
- const result = Path.stripPrefix(Path.empty(), path);
55
- expect(result).toBe("foo/bar");
56
- });
57
- test("stripPrefix accepts Path instances", () => {
58
- const path = Path.from("foo/bar/baz");
59
- const prefix = Path.from("foo/bar");
60
- const result = Path.stripPrefix(prefix, path);
61
- expect(result).toBe("baz");
62
- });
63
- test("join paths with slashes", () => {
64
- const base = Path.from("foo");
65
- const joined = Path.join(base, Path.from("bar"));
66
- expect(joined).toBe("foo/bar");
67
- });
68
- test("join handles empty base", () => {
69
- const base = Path.empty();
70
- const joined = Path.join(base, Path.from("bar"));
71
- expect(joined).toBe("bar");
72
- });
73
- test("join handles empty suffix", () => {
74
- const base = Path.from("foo");
75
- const joined = Path.join(base, Path.empty());
76
- expect(joined).toBe("foo");
77
- });
78
- test("join accepts Path instances", () => {
79
- const base = Path.from("foo");
80
- const suffix = Path.from("bar");
81
- const joined = Path.join(base, suffix);
82
- expect(joined).toBe("foo/bar");
83
- });
84
- test("join handles multiple joins", () => {
85
- const path = Path.join(Path.join(Path.join(Path.from("api"), Path.from("v1")), Path.from("users")), Path.from("123"));
86
- expect(path).toBe("api/v1/users/123");
87
- });
88
- test("isEmpty checks correctly", () => {
89
- expect(Path.from("") === "").toBe(true);
90
- expect(Path.from("foo") === "").toBe(false);
91
- expect(Path.empty() === "").toBe(true);
92
- });
93
- test("length property works correctly", () => {
94
- expect(Path.from("foo").length).toBe(3);
95
- expect(Path.from("foo/bar").length).toBe(7);
96
- expect(Path.empty().length).toBe(0);
97
- });
98
- test("equals checks correctly", () => {
99
- const path1 = Path.from("foo/bar");
100
- const path2 = Path.from("/foo/bar/");
101
- const path3 = Path.from("foo/baz");
102
- expect(path1 === path2).toBe(true);
103
- expect(path1 === path3).toBe(false);
104
- });
105
- test("JSON serialization works", () => {
106
- const path = Path.from("foo/bar");
107
- expect(JSON.stringify(path)).toBe('"foo/bar"');
108
- });
109
- test("handles paths with multiple consecutive slashes", () => {
110
- const path = Path.from("foo//bar///baz");
111
- // Multiple consecutive slashes are collapsed to single slashes
112
- expect(path).toBe("foo/bar/baz");
113
- });
114
- test("removes multiple slashes comprehensively", () => {
115
- // Test various multiple slash scenarios
116
- expect(Path.from("foo//bar")).toBe("foo/bar");
117
- expect(Path.from("foo///bar")).toBe("foo/bar");
118
- expect(Path.from("foo////bar")).toBe("foo/bar");
119
- // Multiple occurrences of double slashes
120
- expect(Path.from("foo//bar//baz")).toBe("foo/bar/baz");
121
- expect(Path.from("a//b//c//d")).toBe("a/b/c/d");
122
- // Mixed slash counts
123
- expect(Path.from("foo//bar///baz////qux")).toBe("foo/bar/baz/qux");
124
- // With leading and trailing slashes
125
- expect(Path.from("//foo//bar//")).toBe("foo/bar");
126
- expect(Path.from("///foo///bar///")).toBe("foo/bar");
127
- // Edge case: only slashes
128
- expect(Path.from("//")).toBe("");
129
- expect(Path.from("////")).toBe("");
130
- // Test that operations work correctly with normalized paths
131
- const pathWithSlashes = Path.from("foo//bar///baz");
132
- expect(Path.hasPrefix(Path.from("foo/bar"), pathWithSlashes)).toBe(true);
133
- expect(Path.stripPrefix(Path.from("foo"), pathWithSlashes)).toBe("bar/baz");
134
- expect(Path.join(pathWithSlashes, Path.from("qux"))).toBe("foo/bar/baz/qux");
135
- });
136
- test("handles special characters", () => {
137
- const path = Path.from("foo-bar_baz.txt");
138
- expect(path).toBe("foo-bar_baz.txt");
139
- expect(Path.hasPrefix(Path.from("foo-bar"), path)).toBe(false);
140
- expect(Path.hasPrefix(Path.from("foo-bar_baz.txt"), path)).toBe(true);
141
- });
142
- test("from accepts multiple arguments", () => {
143
- expect(Path.from("foo", "bar", "baz")).toBe("foo/bar/baz");
144
- expect(Path.from("api", "v1", "users")).toBe("api/v1/users");
145
- });
146
- test("from handles empty strings in arguments", () => {
147
- expect(Path.from("foo", "", "bar")).toBe("foo/bar");
148
- expect(Path.from("", "foo", "bar", "")).toBe("foo/bar");
149
- });
150
- test("from sanitizes multiple arguments with slashes", () => {
151
- expect(Path.from("/foo/", "/bar/", "/baz/")).toBe("foo/bar/baz");
152
- expect(Path.from("foo//", "//bar", "baz")).toBe("foo/bar/baz");
153
- });
154
- test("resolve appends named segments", () => {
155
- expect(Path.resolve(Path.from("a/b"), "c")).toBe(Path.from("a/b/c"));
156
- expect(Path.resolve(Path.from("a/b"), "c/d")).toBe(Path.from("a/b/c/d"));
157
- });
158
- test("resolve with empty rel returns base", () => {
159
- expect(Path.resolve(Path.from("a/b"), "")).toBe(Path.from("a/b"));
160
- });
161
- test("resolve single dotdot pops one segment", () => {
162
- expect(Path.resolve(Path.from("a/b/c"), "../d")).toBe(Path.from("a/b/d"));
163
- expect(Path.resolve(Path.from("a/b/c"), "..")).toBe(Path.from("a/b"));
164
- });
165
- test("resolve multiple dotdot pops multiple segments", () => {
166
- expect(Path.resolve(Path.from("a/b/c"), "../../x")).toBe(Path.from("a/x"));
167
- expect(Path.resolve(Path.from("a/b/c"), "../../../x")).toBe(Path.from("x"));
168
- });
169
- test("resolve excess dotdot clamps at empty", () => {
170
- expect(Path.resolve(Path.from("a"), "../../../foo")).toBe(Path.from("foo"));
171
- expect(Path.resolve(Path.from("a"), "..")).toBe(Path.from(""));
172
- });
173
- test("resolve with empty base", () => {
174
- expect(Path.resolve(Path.empty(), "foo")).toBe(Path.from("foo"));
175
- expect(Path.resolve(Path.empty(), "..")).toBe(Path.from(""));
176
- });
177
- test("resolve treats dot as a no-op", () => {
178
- expect(Path.resolve(Path.from("a/b"), ".")).toBe(Path.from("a/b"));
179
- expect(Path.resolve(Path.from("a/b"), "./c")).toBe(Path.from("a/b/c"));
180
- expect(Path.resolve(Path.from("a/b"), "./../c")).toBe(Path.from("a/c"));
181
- expect(Path.resolve(Path.from("a/b"), "foo/./bar")).toBe(Path.from("a/b/foo/bar"));
182
- });
183
- test("resolve self-reference via dotdot equals base", () => {
184
- expect(Path.resolve(Path.from("a/b"), "../b")).toBe(Path.from("a/b"));
185
- });
186
- test("normalizeRelative drops empty and dot segments", () => {
187
- expect(Path.normalizeRelative("")).toBe("");
188
- expect(Path.normalizeRelative(".")).toBe("");
189
- expect(Path.normalizeRelative("./foo")).toBe("foo");
190
- expect(Path.normalizeRelative("foo//bar")).toBe("foo/bar");
191
- expect(Path.normalizeRelative("foo/./bar")).toBe("foo/bar");
192
- expect(Path.normalizeRelative("/foo/")).toBe("foo");
193
- expect(Path.normalizeRelative("../foo")).toBe("../foo");
194
- });
195
- test("parts splits a path into its components", () => {
196
- expect(Path.parts(Path.from(""))).toEqual([]);
197
- expect(Path.parts(Path.from("foo"))).toEqual(["foo"]);
198
- expect(Path.parts(Path.from("/foo//bar/"))).toEqual(["foo", "bar"]);
199
- });
200
- test("decode enforces the max part count", () => {
201
- const atLimit = Array.from({ length: Path.MAX_PARTS }, (_, i) => `${i}`).join("/");
202
- expect(Path.decode(atLimit)).toBe(atLimit);
203
- expect(() => Path.decode(`${atLimit}/extra`)).toThrow();
204
- });
205
- test("encode enforces the max part count", () => {
206
- const atLimit = Array.from({ length: Path.MAX_PARTS }, (_, i) => `${i}`).join("/");
207
- expect(Path.encode(atLimit)).toBe(atLimit);
208
- expect(() => Path.encode(`${atLimit}/extra`)).toThrow();
209
- });
210
- //# sourceMappingURL=path.test.js.map