@moq/net 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/announced.d.ts +40 -24
  2. package/announced.d.ts.map +1 -1
  3. package/announced.js +74 -40
  4. package/announced.js.map +1 -1
  5. package/announced.test.d.ts +2 -0
  6. package/announced.test.d.ts.map +1 -0
  7. package/announced.test.js +37 -0
  8. package/announced.test.js.map +1 -0
  9. package/broadcast.d.ts +80 -25
  10. package/broadcast.d.ts.map +1 -1
  11. package/broadcast.js +266 -49
  12. package/broadcast.js.map +1 -1
  13. package/broadcast.test.d.ts +2 -0
  14. package/broadcast.test.d.ts.map +1 -0
  15. package/broadcast.test.js +219 -0
  16. package/broadcast.test.js.map +1 -0
  17. package/connection/accept.d.ts +6 -0
  18. package/connection/accept.d.ts.map +1 -1
  19. package/connection/accept.js +30 -10
  20. package/connection/accept.js.map +1 -1
  21. package/connection/browser.d.ts +5 -0
  22. package/connection/browser.d.ts.map +1 -0
  23. package/connection/browser.js +25 -0
  24. package/connection/browser.js.map +1 -0
  25. package/connection/browser.test.d.ts +2 -0
  26. package/connection/browser.test.d.ts.map +1 -0
  27. package/connection/browser.test.js +29 -0
  28. package/connection/browser.test.js.map +1 -0
  29. package/connection/connect.d.ts +43 -1
  30. package/connection/connect.d.ts.map +1 -1
  31. package/connection/connect.js +96 -107
  32. package/connection/connect.js.map +1 -1
  33. package/connection/connect.test.d.ts +2 -0
  34. package/connection/connect.test.d.ts.map +1 -0
  35. package/connection/connect.test.js +118 -0
  36. package/connection/connect.test.js.map +1 -0
  37. package/connection/established.d.ts +29 -15
  38. package/connection/established.d.ts.map +1 -1
  39. package/connection/established.js.map +1 -1
  40. package/connection/index.d.ts +8 -0
  41. package/connection/index.d.ts.map +1 -1
  42. package/connection/index.js +6 -0
  43. package/connection/index.js.map +1 -1
  44. package/connection/reload.d.ts +43 -7
  45. package/connection/reload.d.ts.map +1 -1
  46. package/connection/reload.js +159 -62
  47. package/connection/reload.js.map +1 -1
  48. package/connection/reload.test.js +65 -0
  49. package/connection/reload.test.js.map +1 -1
  50. package/connection/stats.d.ts +92 -0
  51. package/connection/stats.d.ts.map +1 -0
  52. package/connection/stats.js +35 -0
  53. package/connection/stats.js.map +1 -0
  54. package/connection/stats.test.d.ts +2 -0
  55. package/connection/stats.test.d.ts.map +1 -0
  56. package/connection/stats.test.js +120 -0
  57. package/connection/stats.test.js.map +1 -0
  58. package/connection/transport.d.ts +10 -0
  59. package/connection/transport.d.ts.map +1 -0
  60. package/connection/transport.js +12 -0
  61. package/connection/transport.js.map +1 -0
  62. package/consume.d.ts +26 -0
  63. package/consume.d.ts.map +1 -0
  64. package/consume.js +40 -0
  65. package/consume.js.map +1 -0
  66. package/datagram.d.ts +23 -0
  67. package/datagram.d.ts.map +1 -0
  68. package/datagram.js +3 -0
  69. package/datagram.js.map +1 -0
  70. package/group.d.ts +125 -36
  71. package/group.d.ts.map +1 -1
  72. package/group.js +244 -67
  73. package/group.js.map +1 -1
  74. package/group.test.js +121 -35
  75. package/group.test.js.map +1 -1
  76. package/ietf/adapter.d.ts +2 -2
  77. package/ietf/adapter.d.ts.map +1 -1
  78. package/ietf/adapter.js +15 -5
  79. package/ietf/adapter.js.map +1 -1
  80. package/ietf/connection.d.ts +19 -6
  81. package/ietf/connection.d.ts.map +1 -1
  82. package/ietf/connection.js +23 -8
  83. package/ietf/connection.js.map +1 -1
  84. package/ietf/ietf.test.js +58 -1
  85. package/ietf/ietf.test.js.map +1 -1
  86. package/ietf/object.d.ts +12 -4
  87. package/ietf/object.d.ts.map +1 -1
  88. package/ietf/object.js +92 -9
  89. package/ietf/object.js.map +1 -1
  90. package/ietf/publisher.d.ts +2 -2
  91. package/ietf/publisher.d.ts.map +1 -1
  92. package/ietf/publisher.js +12 -12
  93. package/ietf/publisher.js.map +1 -1
  94. package/ietf/subscribe_namespace.d.ts +0 -4
  95. package/ietf/subscribe_namespace.d.ts.map +1 -1
  96. package/ietf/subscribe_namespace.js +0 -5
  97. package/ietf/subscribe_namespace.js.map +1 -1
  98. package/ietf/subscriber.d.ts +8 -4
  99. package/ietf/subscriber.d.ts.map +1 -1
  100. package/ietf/subscriber.js +171 -93
  101. package/ietf/subscriber.js.map +1 -1
  102. package/index.d.ts +8 -5
  103. package/index.d.ts.map +1 -1
  104. package/index.js +8 -5
  105. package/index.js.map +1 -1
  106. package/integration.test.js +598 -12
  107. package/integration.test.js.map +1 -1
  108. package/internal.d.ts +14 -0
  109. package/internal.d.ts.map +1 -0
  110. package/internal.js +8 -0
  111. package/internal.js.map +1 -0
  112. package/lite/announce.d.ts +55 -13
  113. package/lite/announce.d.ts.map +1 -1
  114. package/lite/announce.js +221 -68
  115. package/lite/announce.js.map +1 -1
  116. package/lite/announce.test.d.ts +2 -0
  117. package/lite/announce.test.d.ts.map +1 -0
  118. package/lite/announce.test.js +71 -0
  119. package/lite/announce.test.js.map +1 -0
  120. package/lite/connection.d.ts +45 -19
  121. package/lite/connection.d.ts.map +1 -1
  122. package/lite/connection.js +85 -80
  123. package/lite/connection.js.map +1 -1
  124. package/lite/datagram.d.ts +23 -0
  125. package/lite/datagram.d.ts.map +1 -0
  126. package/lite/datagram.js +57 -0
  127. package/lite/datagram.js.map +1 -0
  128. package/lite/datagram.test.d.ts +2 -0
  129. package/lite/datagram.test.d.ts.map +1 -0
  130. package/lite/datagram.test.js +26 -0
  131. package/lite/datagram.test.js.map +1 -0
  132. package/lite/datagram_stream.d.ts +8 -0
  133. package/lite/datagram_stream.d.ts.map +1 -0
  134. package/lite/datagram_stream.js +44 -0
  135. package/lite/datagram_stream.js.map +1 -0
  136. package/lite/datagram_stream.test.d.ts +2 -0
  137. package/lite/datagram_stream.test.d.ts.map +1 -0
  138. package/lite/datagram_stream.test.js +15 -0
  139. package/lite/datagram_stream.test.js.map +1 -0
  140. package/lite/fetch.d.ts.map +1 -1
  141. package/lite/fetch.js +2 -2
  142. package/lite/fetch.js.map +1 -1
  143. package/lite/fetch.test.d.ts +2 -0
  144. package/lite/fetch.test.d.ts.map +1 -0
  145. package/lite/fetch.test.js +41 -0
  146. package/lite/fetch.test.js.map +1 -0
  147. package/lite/index.d.ts +3 -0
  148. package/lite/index.d.ts.map +1 -1
  149. package/lite/index.js +3 -0
  150. package/lite/index.js.map +1 -1
  151. package/lite/publisher.d.ts +13 -6
  152. package/lite/publisher.d.ts.map +1 -1
  153. package/lite/publisher.js +274 -64
  154. package/lite/publisher.js.map +1 -1
  155. package/lite/publisher.test.d.ts +2 -0
  156. package/lite/publisher.test.d.ts.map +1 -0
  157. package/lite/publisher.test.js +65 -0
  158. package/lite/publisher.test.js.map +1 -0
  159. package/lite/setup.d.ts +72 -6
  160. package/lite/setup.d.ts.map +1 -1
  161. package/lite/setup.js +184 -31
  162. package/lite/setup.js.map +1 -1
  163. package/lite/setup.test.d.ts +2 -0
  164. package/lite/setup.test.d.ts.map +1 -0
  165. package/lite/setup.test.js +122 -0
  166. package/lite/setup.test.js.map +1 -0
  167. package/lite/stream.d.ts +12 -3
  168. package/lite/stream.d.ts.map +1 -1
  169. package/lite/stream.js +7 -4
  170. package/lite/stream.js.map +1 -1
  171. package/lite/subscribe.d.ts +37 -23
  172. package/lite/subscribe.d.ts.map +1 -1
  173. package/lite/subscribe.js +70 -55
  174. package/lite/subscribe.js.map +1 -1
  175. package/lite/subscribe.test.d.ts +2 -0
  176. package/lite/subscribe.test.d.ts.map +1 -0
  177. package/lite/subscribe.test.js +68 -0
  178. package/lite/subscribe.test.js.map +1 -0
  179. package/lite/subscriber.d.ts +24 -17
  180. package/lite/subscriber.d.ts.map +1 -1
  181. package/lite/subscriber.js +515 -90
  182. package/lite/subscriber.js.map +1 -1
  183. package/lite/subscriber.test.js +2 -2
  184. package/lite/subscriber.test.js.map +1 -1
  185. package/lite/track.d.ts +25 -13
  186. package/lite/track.d.ts.map +1 -1
  187. package/lite/track.js +60 -35
  188. package/lite/track.js.map +1 -1
  189. package/lite/track.test.js +12 -10
  190. package/lite/track.test.js.map +1 -1
  191. package/lite/version.d.ts +17 -4
  192. package/lite/version.d.ts.map +1 -1
  193. package/lite/version.js +88 -17
  194. package/lite/version.js.map +1 -1
  195. package/mock.d.ts +42 -3
  196. package/mock.d.ts.map +1 -1
  197. package/mock.js +88 -17
  198. package/mock.js.map +1 -1
  199. package/package.json +3 -3
  200. package/path.d.ts +30 -0
  201. package/path.d.ts.map +1 -1
  202. package/path.js +49 -0
  203. package/path.js.map +1 -1
  204. package/path.test.js +41 -0
  205. package/path.test.js.map +1 -1
  206. package/stream.test.js +10 -0
  207. package/stream.test.js.map +1 -1
  208. package/time.d.ts +109 -86
  209. package/time.d.ts.map +1 -1
  210. package/time.js +80 -30
  211. package/time.js.map +1 -1
  212. package/time.test.d.ts +2 -0
  213. package/time.test.d.ts.map +1 -0
  214. package/time.test.js +12 -0
  215. package/time.test.js.map +1 -0
  216. package/track.d.ts +225 -45
  217. package/track.d.ts.map +1 -1
  218. package/track.js +505 -93
  219. package/track.js.map +1 -1
  220. package/track.test.js +138 -29
  221. package/track.test.js.map +1 -1
  222. package/util/error.d.ts +9 -0
  223. package/util/error.d.ts.map +1 -1
  224. package/util/error.js +21 -0
  225. package/util/error.js.map +1 -1
  226. package/util/error.test.d.ts +2 -0
  227. package/util/error.test.d.ts.map +1 -0
  228. package/util/error.test.js +45 -0
  229. package/util/error.test.js.map +1 -0
  230. package/util/index.d.ts +1 -0
  231. package/util/index.d.ts.map +1 -1
  232. package/util/index.js +1 -0
  233. package/util/index.js.map +1 -1
  234. package/util/timeout.d.ts +5 -0
  235. package/util/timeout.d.ts.map +1 -0
  236. package/util/timeout.js +18 -0
  237. package/util/timeout.js.map +1 -0
  238. package/util/timeout.test.d.ts +2 -0
  239. package/util/timeout.test.d.ts.map +1 -0
  240. package/util/timeout.test.js +18 -0
  241. package/util/timeout.test.js.map +1 -0
  242. package/varint.d.ts +6 -0
  243. package/varint.d.ts.map +1 -1
  244. package/varint.js +6 -2
  245. package/varint.js.map +1 -1
  246. package/zod.d.ts +4 -4
  247. package/zod.d.ts.map +1 -1
  248. package/zod.js.map +1 -1
  249. package/bandwidth.d.ts +0 -11
  250. package/bandwidth.d.ts.map +0 -1
  251. package/bandwidth.js +0 -7
  252. package/bandwidth.js.map +0 -1
package/lite/version.js CHANGED
@@ -4,10 +4,87 @@ export const Version = {
4
4
  DRAFT_02: 0xff0dad02,
5
5
  DRAFT_03: 0xff0dad03,
6
6
  DRAFT_04: 0xff0dad04,
7
- /// Work-in-progress placeholder for lite-05. Not advertised as a
8
- /// WebTransport subprotocol; callers must opt in explicitly.
9
- DRAFT_05_WIP: 0xff0dad05,
7
+ DRAFT_05: 0xff0dad05,
8
+ /// Work-in-progress lite-06, advertised as the preferred WebTransport subprotocol.
9
+ /// Adds announce ids: each active ANNOUNCE_BROADCAST implicitly assigns the next
10
+ /// ordinal, and ended/restart reference that id instead of repeating the path.
11
+ DRAFT_06: 0xff0dad06,
10
12
  };
13
+ /// Whether the session opens a unidirectional Setup Stream carrying a single SETUP message
14
+ /// (capabilities + optional Path). Added in lite-05; older drafts have no Setup Stream.
15
+ export function hasSetupStream(version) {
16
+ // Explicitly list older versions so future versions default to having the stream.
17
+ switch (version) {
18
+ case Version.DRAFT_01:
19
+ case Version.DRAFT_02:
20
+ case Version.DRAFT_03:
21
+ case Version.DRAFT_04:
22
+ return false;
23
+ default:
24
+ return true;
25
+ }
26
+ }
27
+ /// Whether the session may deliver groups over unreliable QUIC datagrams (lite-05 §6.4).
28
+ /// A datagram carries one single-frame group's `subscribe | sequence | timestamp | payload` and is
29
+ /// routed over the existing subscription. Added in lite-05; older versions never send/accept them.
30
+ export function hasDatagrams(version) {
31
+ // Explicitly list older versions so future versions default to having datagrams.
32
+ switch (version) {
33
+ case Version.DRAFT_01:
34
+ case Version.DRAFT_02:
35
+ case Version.DRAFT_03:
36
+ case Version.DRAFT_04:
37
+ return false;
38
+ default:
39
+ return true;
40
+ }
41
+ }
42
+ /** Whether announce streams begin with ANNOUNCE_OK and omit the sender's origin from each hop chain. */
43
+ export function hasAnnounceOk(version) {
44
+ // Explicitly list older versions so future versions keep the lite-05+ announce behavior.
45
+ switch (version) {
46
+ case Version.DRAFT_01:
47
+ case Version.DRAFT_02:
48
+ case Version.DRAFT_03:
49
+ case Version.DRAFT_04:
50
+ return false;
51
+ default:
52
+ return true;
53
+ }
54
+ }
55
+ /** Whether announcements carry implicit announce ids: each `active` assigns the next
56
+ * per-stream ordinal, and `ended`/`restart` reference that id instead of repeating the
57
+ * path. Added in lite-06. */
58
+ export function hasAnnounceId(version) {
59
+ // Explicitly list older versions so future versions keep the lite-06+ announce behavior.
60
+ switch (version) {
61
+ case Version.DRAFT_01:
62
+ case Version.DRAFT_02:
63
+ case Version.DRAFT_03:
64
+ case Version.DRAFT_04:
65
+ case Version.DRAFT_05:
66
+ return false;
67
+ default:
68
+ return true;
69
+ }
70
+ }
71
+ /** Whether announcements carry a route cost varint alongside the hop chain: the
72
+ * marginal cost of pulling the broadcast via this route, accumulated per link.
73
+ * Added in lite-06. Older versions carry nothing, so a received route stays at
74
+ * zero and routing falls back to the hop-count tie-break. */
75
+ export function hasRouteCost(version) {
76
+ // Explicitly list older versions so future versions keep the lite-06+ behavior.
77
+ switch (version) {
78
+ case Version.DRAFT_01:
79
+ case Version.DRAFT_02:
80
+ case Version.DRAFT_03:
81
+ case Version.DRAFT_04:
82
+ case Version.DRAFT_05:
83
+ return false;
84
+ default:
85
+ return true;
86
+ }
87
+ }
11
88
  /// The WebTransport subprotocol identifier for moq-lite.
12
89
  /// Version negotiation still happens via SETUP when this is used.
13
90
  export const ALPN = "moql";
@@ -15,27 +92,21 @@ export const ALPN = "moql";
15
92
  export const ALPN_03 = "moq-lite-03";
16
93
  /// The ALPN string for Draft04, which uses ALPN-based version negotiation.
17
94
  export const ALPN_04 = "moq-lite-04";
18
- /// The ALPN string for the work-in-progress Draft05. Intentionally not
19
- /// included in the default WebTransport `protocols` list.
20
- export const ALPN_05_WIP = "moq-lite-05-wip";
95
+ /// The ALPN string for Draft05, which uses ALPN-based version negotiation.
96
+ export const ALPN_05 = "moq-lite-05";
97
+ /// The ALPN string for the work-in-progress Draft06. It is NOT in the default
98
+ /// WebTransport `protocols` list, so lite-06 is never advertised or negotiated by
99
+ /// default; a peer only reaches it when both sides explicitly offer this ALPN.
100
+ export const ALPN_06_WIP = "moq-lite-06-wip";
21
101
  const VERSION_NAMES = {
22
102
  [Version.DRAFT_01]: "moq-lite-01",
23
103
  [Version.DRAFT_02]: "moq-lite-02",
24
104
  [Version.DRAFT_03]: "moq-lite-03",
25
105
  [Version.DRAFT_04]: "moq-lite-04",
26
- [Version.DRAFT_05_WIP]: "moq-lite-05-wip",
106
+ [Version.DRAFT_05]: "moq-lite-05",
107
+ [Version.DRAFT_06]: "moq-lite-06-wip",
27
108
  };
28
109
  export function versionName(v) {
29
110
  return VERSION_NAMES[v] ?? `unknown(0x${v.toString(16)})`;
30
111
  }
31
- /// Whether this version uses a unidirectional Setup stream (moq-lite-05+).
32
- export function hasSetupStream(v) {
33
- return v === Version.DRAFT_05_WIP;
34
- }
35
- /// Whether this version uses the moq-lite-05 framing bundle: the Track stream
36
- /// (TRACK/TRACK_INFO), a SUBSCRIBE_OK trimmed to the resolved start group plus a
37
- /// distinct SUBSCRIBE_END, and a per-frame timestamp delta.
38
- export function hasTrackStream(v) {
39
- return v === Version.DRAFT_05_WIP;
40
- }
41
112
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/lite/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG;IACtB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,iEAAiE;IACjE,6DAA6D;IAC7D,YAAY,EAAE,UAAU;CACf,CAAC;AAIX,yDAAyD;AACzD,kEAAkE;AAClE,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAE3B,2EAA2E;AAC3E,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AAErC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AAErC,uEAAuE;AACvE,0DAA0D;AAC1D,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE7C,MAAM,aAAa,GAA2B;IAC7C,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,iBAAiB;CACzC,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,CAAU;IACrC,OAAO,aAAa,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;AAC3D,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,cAAc,CAAC,CAAU;IACxC,OAAO,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC;AACnC,CAAC;AAED,8EAA8E;AAC9E,iFAAiF;AACjF,4DAA4D;AAC5D,MAAM,UAAU,cAAc,CAAC,CAAU;IACxC,OAAO,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC;AACnC,CAAC","sourcesContent":["export const Version = {\n\tDRAFT_01: 0xff0dad01,\n\tDRAFT_02: 0xff0dad02,\n\tDRAFT_03: 0xff0dad03,\n\tDRAFT_04: 0xff0dad04,\n\t/// Work-in-progress placeholder for lite-05. Not advertised as a\n\t/// WebTransport subprotocol; callers must opt in explicitly.\n\tDRAFT_05_WIP: 0xff0dad05,\n} as const;\n\nexport type Version = (typeof Version)[keyof typeof Version];\n\n/// The WebTransport subprotocol identifier for moq-lite.\n/// Version negotiation still happens via SETUP when this is used.\nexport const ALPN = \"moql\";\n\n/// The ALPN string for Draft03, which uses ALPN-based version negotiation.\nexport const ALPN_03 = \"moq-lite-03\";\n\n/// The ALPN string for Draft04, which uses ALPN-based version negotiation.\nexport const ALPN_04 = \"moq-lite-04\";\n\n/// The ALPN string for the work-in-progress Draft05. Intentionally not\n/// included in the default WebTransport `protocols` list.\nexport const ALPN_05_WIP = \"moq-lite-05-wip\";\n\nconst VERSION_NAMES: Record<number, string> = {\n\t[Version.DRAFT_01]: \"moq-lite-01\",\n\t[Version.DRAFT_02]: \"moq-lite-02\",\n\t[Version.DRAFT_03]: \"moq-lite-03\",\n\t[Version.DRAFT_04]: \"moq-lite-04\",\n\t[Version.DRAFT_05_WIP]: \"moq-lite-05-wip\",\n};\n\nexport function versionName(v: Version): string {\n\treturn VERSION_NAMES[v] ?? `unknown(0x${v.toString(16)})`;\n}\n\n/// Whether this version uses a unidirectional Setup stream (moq-lite-05+).\nexport function hasSetupStream(v: Version): boolean {\n\treturn v === Version.DRAFT_05_WIP;\n}\n\n/// Whether this version uses the moq-lite-05 framing bundle: the Track stream\n/// (TRACK/TRACK_INFO), a SUBSCRIBE_OK trimmed to the resolved start group plus a\n/// distinct SUBSCRIBE_END, and a per-frame timestamp delta.\nexport function hasTrackStream(v: Version): boolean {\n\treturn v === Version.DRAFT_05_WIP;\n}\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/lite/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG;IACtB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,mFAAmF;IACnF,iFAAiF;IACjF,+EAA+E;IAC/E,QAAQ,EAAE,UAAU;CACX,CAAC;AAIX,2FAA2F;AAC3F,wFAAwF;AACxF,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC9C,kFAAkF;I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cesContent":["export const Version = {\n\tDRAFT_01: 0xff0dad01,\n\tDRAFT_02: 0xff0dad02,\n\tDRAFT_03: 0xff0dad03,\n\tDRAFT_04: 0xff0dad04,\n\tDRAFT_05: 0xff0dad05,\n\t/// Work-in-progress lite-06, advertised as the preferred WebTransport subprotocol.\n\t/// Adds announce ids: each active ANNOUNCE_BROADCAST implicitly assigns the next\n\t/// ordinal, and ended/restart reference that id instead of repeating the path.\n\tDRAFT_06: 0xff0dad06,\n} as const;\n\nexport type Version = (typeof Version)[keyof typeof Version];\n\n/// Whether the session opens a unidirectional Setup Stream carrying a single SETUP message\n/// (capabilities + optional Path). Added in lite-05; older drafts have no Setup Stream.\nexport function hasSetupStream(version: Version): boolean {\n\t// Explicitly list older versions so future versions default to having the stream.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/// Whether the session may deliver groups over unreliable QUIC datagrams (lite-05 §6.4).\n/// A datagram carries one single-frame group's `subscribe | sequence | timestamp | payload` and is\n/// routed over the existing subscription. Added in lite-05; older versions never send/accept them.\nexport function hasDatagrams(version: Version): boolean {\n\t// Explicitly list older versions so future versions default to having datagrams.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether announce streams begin with ANNOUNCE_OK and omit the sender's origin from each hop chain. */\nexport function hasAnnounceOk(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-05+ announce behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether announcements carry implicit announce ids: each `active` assigns the next\n * per-stream ordinal, and `ended`/`restart` reference that id instead of repeating the\n * path. Added in lite-06. */\nexport function hasAnnounceId(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-06+ announce behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\tcase Version.DRAFT_05:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether announcements carry a route cost varint alongside the hop chain: the\n * marginal cost of pulling the broadcast via this route, accumulated per link.\n * Added in lite-06. Older versions carry nothing, so a received route stays at\n * zero and routing falls back to the hop-count tie-break. */\nexport function hasRouteCost(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-06+ behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\tcase Version.DRAFT_05:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/// The WebTransport subprotocol identifier for moq-lite.\n/// Version negotiation still happens via SETUP when this is used.\nexport const ALPN = \"moql\";\n\n/// The ALPN string for Draft03, which uses ALPN-based version negotiation.\nexport const ALPN_03 = \"moq-lite-03\";\n\n/// The ALPN string for Draft04, which uses ALPN-based version negotiation.\nexport const ALPN_04 = \"moq-lite-04\";\n\n/// The ALPN string for Draft05, which uses ALPN-based version negotiation.\nexport const ALPN_05 = \"moq-lite-05\";\n\n/// The ALPN string for the work-in-progress Draft06. It is NOT in the default\n/// WebTransport `protocols` list, so lite-06 is never advertised or negotiated by\n/// default; a peer only reaches it when both sides explicitly offer this ALPN.\nexport const ALPN_06_WIP = \"moq-lite-06-wip\";\n\nconst VERSION_NAMES: Record<number, string> = {\n\t[Version.DRAFT_01]: \"moq-lite-01\",\n\t[Version.DRAFT_02]: \"moq-lite-02\",\n\t[Version.DRAFT_03]: \"moq-lite-03\",\n\t[Version.DRAFT_04]: \"moq-lite-04\",\n\t[Version.DRAFT_05]: \"moq-lite-05\",\n\t[Version.DRAFT_06]: \"moq-lite-06-wip\",\n};\n\nexport function versionName(v: Version): string {\n\treturn VERSION_NAMES[v] ?? `unknown(0x${v.toString(16)})`;\n}\n"]}
package/mock.d.ts CHANGED
@@ -3,14 +3,53 @@
3
3
  *
4
4
  * Creates paired client/server transports connected via TransformStreams.
5
5
  */
6
+ import type { TransportStats } from "./connection/stats";
7
+ /** A fake {@link WebTransport} backed by TransformStreams, paired with a peer. */
8
+ export declare class MockTransport implements WebTransport {
9
+ #private;
10
+ readonly protocol: string;
11
+ readonly ready: Promise<undefined>;
12
+ readonly closed: Promise<WebTransportCloseInfo>;
13
+ readonly incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalStream>;
14
+ readonly incomingUnidirectionalStreams: ReadableStream<ReadableStream<Uint8Array>>;
15
+ readonly datagrams: WebTransportDatagramDuplexStream;
16
+ readonly congestionControl: WebTransportCongestionControl;
17
+ readonly reliability: string;
18
+ constructor(protocol: string, datagramsEnabled?: boolean, datagramWritable?: DatagramWritableApi, datagramReadable?: boolean);
19
+ setPeer(peer: MockTransport): void;
20
+ createBidirectionalStream(_options?: WebTransportSendStreamOptions): Promise<WebTransportBidirectionalStream>;
21
+ createUnidirectionalStream(_options?: WebTransportSendStreamOptions): Promise<WritableStream<Uint8Array>>;
22
+ close(_closeInfo?: WebTransportCloseInfo): void;
23
+ /** The snapshot {@link getStats} resolves with (default empty). */
24
+ stats: TransportStats;
25
+ getStats(): Promise<TransportStats>;
26
+ }
27
+ type DatagramWritableApi = "writable" | "createWritable" | "none";
28
+ /** Options for {@link createMockTransportPair}. */
29
+ export interface MockTransportOptions {
30
+ /**
31
+ * Whether the paired transports carry QUIC datagrams (default true). Set false to
32
+ * simulate a transport that reports `maxDatagramSize` 0 (e.g. a qmux/WebSocket
33
+ * session), so the wire layer must fall back to not sending datagrams.
34
+ */
35
+ datagrams?: boolean;
36
+ /** Which outgoing datagram API shape the mock exposes. */
37
+ datagramWritable?: DatagramWritableApi;
38
+ /** Whether the incoming datagram readable stream is exposed. */
39
+ datagramReadable?: boolean;
40
+ /** The snapshot `getStats()` resolves with on both transports (default empty). */
41
+ stats?: TransportStats;
42
+ }
6
43
  /**
7
44
  * Creates a pair of connected MockTransport instances.
8
45
  *
9
46
  * @param protocol - The WebTransport protocol identifier (e.g. "moqt-17", "moql", "")
47
+ * @param options - Optional behavior toggles for datagram availability
10
48
  * @returns An object containing `client` and `server` transports
11
49
  */
12
- export declare function createMockTransportPair(protocol?: string): {
13
- client: WebTransport;
14
- server: WebTransport;
50
+ export declare function createMockTransportPair(protocol?: string, options?: MockTransportOptions): {
51
+ client: MockTransport;
52
+ server: MockTransport;
15
53
  };
54
+ export {};
16
55
  //# sourceMappingURL=mock.d.ts.map
package/mock.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAiKH;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,SAAK,GAAG;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,CAMrG"}
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAqB5D,kFAAkF;AAClF,qBAAa,aAAc,YAAW,YAAY;;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAEhD,QAAQ,CAAC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,MAAM,EAAE,aAAa,CAAA;CAAE,CAYlD"}
package/mock.js CHANGED
@@ -17,7 +17,8 @@ function newStream() {
17
17
  },
18
18
  }, WRITABLE_STRATEGY, READABLE_STRATEGY);
19
19
  }
20
- class MockTransport {
20
+ /** A fake {@link WebTransport} backed by TransformStreams, paired with a peer. */
21
+ export class MockTransport {
21
22
  protocol;
22
23
  ready;
23
24
  closed;
@@ -29,9 +30,12 @@ class MockTransport {
29
30
  #closeResolve;
30
31
  #bidiController;
31
32
  #uniController;
33
+ // Incoming-datagram controller (only set when datagrams are enabled); the peer's
34
+ // writable enqueues into it.
35
+ #datagramController;
32
36
  // Reference to the peer so we can enqueue streams to them
33
37
  #peer;
34
- constructor(protocol) {
38
+ constructor(protocol, datagramsEnabled = true, datagramWritable = "writable", datagramReadable = true) {
35
39
  this.protocol = protocol;
36
40
  this.ready = Promise.resolve(undefined);
37
41
  this.closed = new Promise((resolve) => {
@@ -49,16 +53,63 @@ class MockTransport {
49
53
  });
50
54
  this.congestionControl = "default";
51
55
  this.reliability = "supports-unreliable";
52
- // Stub datagrams
53
- this.datagrams = {
54
- readable: new ReadableStream(),
55
- writable: new WritableStream(),
56
- incomingHighWaterMark: 0,
57
- outgoingHighWaterMark: 0,
58
- incomingMaxAge: null,
59
- outgoingMaxAge: null,
60
- maxDatagramSize: 0,
61
- };
56
+ if (datagramsEnabled) {
57
+ // A real datagram duplex: writes enqueue into the peer's incoming readable,
58
+ // so a peer pair actually exchanges datagrams (unlike a real qmux Session,
59
+ // whose datagram streams are inert stubs).
60
+ const readable = datagramReadable
61
+ ? new ReadableStream({
62
+ start: (controller) => {
63
+ this.#datagramController = controller;
64
+ },
65
+ })
66
+ : undefined;
67
+ const writable = new WritableStream({
68
+ write: (chunk) => {
69
+ const peer = this.#peer;
70
+ if (!peer)
71
+ return;
72
+ const controller = peer.#datagramController;
73
+ if (!controller)
74
+ return;
75
+ try {
76
+ // Copy so the caller's scratch buffer reuse can't corrupt queued data.
77
+ controller.enqueue(new Uint8Array(chunk));
78
+ }
79
+ catch {
80
+ // Peer closed; drop (datagrams are best-effort).
81
+ }
82
+ },
83
+ });
84
+ const datagrams = {
85
+ readable,
86
+ incomingHighWaterMark: 0,
87
+ outgoingHighWaterMark: 0,
88
+ incomingMaxAge: null,
89
+ outgoingMaxAge: null,
90
+ maxDatagramSize: 1200,
91
+ };
92
+ if (datagramWritable === "writable") {
93
+ datagrams.writable = writable;
94
+ }
95
+ else if (datagramWritable === "createWritable") {
96
+ datagrams.createWritable = () => writable;
97
+ }
98
+ this.datagrams = datagrams;
99
+ }
100
+ else {
101
+ // Simulate a transport that doesn't carry datagrams (maxDatagramSize 0): the
102
+ // wire layer must fall back to not sending, with no group fallback.
103
+ this.datagrams = {
104
+ readable: new ReadableStream(),
105
+ writable: new WritableStream(),
106
+ incomingHighWaterMark: 0,
107
+ outgoingHighWaterMark: 0,
108
+ incomingMaxAge: null,
109
+ outgoingMaxAge: null,
110
+ maxDatagramSize: 0,
111
+ };
112
+ }
62
113
  }
63
114
  setPeer(peer) {
64
115
  this.#peer = peer;
@@ -116,6 +167,12 @@ class MockTransport {
116
167
  catch {
117
168
  // Already closed
118
169
  }
170
+ try {
171
+ this.#datagramController?.close();
172
+ }
173
+ catch {
174
+ // Already closed
175
+ }
119
176
  // Also close peer's incoming streams
120
177
  if (this.#peer) {
121
178
  try {
@@ -130,23 +187,37 @@ class MockTransport {
130
187
  catch {
131
188
  // Already closed
132
189
  }
190
+ try {
191
+ this.#peer.#datagramController?.close();
192
+ }
193
+ catch {
194
+ // Already closed
195
+ }
133
196
  this.#peer.#closeResolve(info);
134
197
  }
135
198
  }
136
- // biome-ignore lint/suspicious/noExplicitAny: WebTransportStats type not available in all TS libs
199
+ /** The snapshot {@link getStats} resolves with (default empty). */
200
+ stats = {};
137
201
  async getStats() {
138
- return {};
202
+ return this.stats;
139
203
  }
140
204
  }
141
205
  /**
142
206
  * Creates a pair of connected MockTransport instances.
143
207
  *
144
208
  * @param protocol - The WebTransport protocol identifier (e.g. "moqt-17", "moql", "")
209
+ * @param options - Optional behavior toggles for datagram availability
145
210
  * @returns An object containing `client` and `server` transports
146
211
  */
147
- export function createMockTransportPair(protocol = "") {
148
- const client = new MockTransport(protocol);
149
- const server = new MockTransport(protocol);
212
+ export function createMockTransportPair(protocol = "", options) {
213
+ const datagrams = options?.datagrams ?? true;
214
+ const client = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);
215
+ const server = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);
216
+ if (options?.stats) {
217
+ // Copy per side so a test advancing one transport's counters doesn't move the other's.
218
+ client.stats = { ...options.stats };
219
+ server.stats = { ...options.stats };
220
+ }
150
221
  client.setPeer(server);
151
222
  server.setPeer(client);
152
223
  return { client, server };
package/mock.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kEAAkE;AAClE,6EAA6E;AAC7E,MAAM,iBAAiB,GAAgC,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC;AAC9E,MAAM,iBAAiB,GAAgC,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC;AAE9E,SAAS,SAAS;IACjB,OAAO,IAAI,eAAe,CACzB;QACC,wEAAwE;QACxE,oEAAoE;QACpE,SAAS,CAAC,KAAK,EAAE,UAAU;YAC1B,UAAU,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC;KACD,EACD,iBAAiB,EACjB,iBAAiB,CACjB,CAAC;AACH,CAAC;AAED,MAAM,aAAa;IACT,QAAQ,CAAS;IACjB,KAAK,CAAqB;IAC1B,MAAM,CAAiC;IAEvC,4BAA4B,CAAkD;IAC9E,6BAA6B,CAA6C;IAE1E,SAAS,CAAmC;IAC5C,iBAAiB,CAAgC;IACjD,WAAW,CAAS;IAE7B,aAAa,CAAyC;IACtD,eAAe,CAAoE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C;QACD,IAAI,CAAC;YACJ,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACR,iBAAiB;QAClB,CAAC;QAED,qCAAqC;QACrC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC;gBACJ,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;YACpC,CAAC;YAAC,MAAM,CAAC;gBACR,iBAAiB;YAClB,CAAC;YACD,IAAI,CAAC;gBACJ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;YACnC,CAAC;YAAC,MAAM,CAAC;gBACR,iBAAiB;YAClB,CAAC;YACD,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;IAED,kGAAkG;IAClG,KAAK,CAAC,QAAQ;QACb,OAAO,EAAE,CAAC;IACX,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAQ,GAAG,EAAE;IACpD,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Mock WebTransport implementation for in-process testing.\n *\n * Creates paired client/server transports connected via TransformStreams.\n */\n\n// High watermark to prevent writes from blocking on backpressure.\n// Real WebTransport has kernel buffers; we simulate this with a large queue.\nconst WRITABLE_STRATEGY: QueuingStrategy<Uint8Array> = { highWaterMark: 256 };\nconst READABLE_STRATEGY: QueuingStrategy<Uint8Array> = { highWaterMark: 256 };\n\nfunction newStream(): TransformStream<Uint8Array, Uint8Array> {\n\treturn new TransformStream(\n\t\t{\n\t\t\t// Copy each chunk to simulate real WebTransport's kernel-boundary copy.\n\t\t\t// Without this, Writer's scratch buffer reuse corrupts queued data.\n\t\t\ttransform(chunk, controller) {\n\t\t\t\tcontroller.enqueue(new Uint8Array(chunk));\n\t\t\t},\n\t\t},\n\t\tWRITABLE_STRATEGY,\n\t\tREADABLE_STRATEGY,\n\t);\n}\n\nclass MockTransport implements WebTransport {\n\treadonly protocol: string;\n\treadonly ready: Promise<undefined>;\n\treadonly closed: Promise<WebTransportCloseInfo>;\n\n\treadonly incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalStream>;\n\treadonly incomingUnidirectionalStreams: ReadableStream<ReadableStream<Uint8Array>>;\n\n\treadonly datagrams: WebTransportDatagramDuplexStream;\n\treadonly congestionControl: WebTransportCongestionControl;\n\treadonly reliability: string;\n\n\t#closeResolve!: (info: WebTransportCloseInfo) => void;\n\t#bidiController!: ReadableStreamDefaultController<WebTransportBidirectionalStream>;\n\t#uniController!: ReadableStreamDefaultController<ReadableStream<Uint8Array>>;\n\n\t// Reference to the peer so we can enqueue streams to them\n\t#peer?: MockTransport;\n\n\tconstructor(protocol: string) {\n\t\tthis.protocol = protocol;\n\t\tthis.ready = Promise.resolve(undefined);\n\t\tthis.closed = new Promise((resolve) => {\n\t\t\tthis.#closeResolve = resolve;\n\t\t});\n\n\t\tthis.incomingBidirectionalStreams = new ReadableStream({\n\t\t\tstart: (controller) => {\n\t\t\t\tthis.#bidiController = controller;\n\t\t\t},\n\t\t});\n\n\t\tthis.incomingUnidirectionalStreams = new ReadableStream({\n\t\t\tstart: (controller) => {\n\t\t\t\tthis.#uniController = controller;\n\t\t\t},\n\t\t});\n\n\t\tthis.congestionControl = \"default\";\n\t\tthis.reliability = \"supports-unreliable\";\n\n\t\t// Stub datagrams\n\t\tthis.datagrams = {\n\t\t\treadable: new ReadableStream(),\n\t\t\twritable: new WritableStream(),\n\t\t\tincomingHighWaterMark: 0,\n\t\t\toutgoingHighWaterMark: 0,\n\t\t\tincomingMaxAge: null,\n\t\t\toutgoingMaxAge: null,\n\t\t\tmaxDatagramSize: 0,\n\t\t};\n\t}\n\n\tsetPeer(peer: MockTransport) {\n\t\tthis.#peer = peer;\n\t}\n\n\tasync createBidirectionalStream(\n\t\t_options?: WebTransportSendStreamOptions,\n\t): Promise<WebTransportBidirectionalStream> {\n\t\tconst peer = this.#peer;\n\t\tif (!peer) throw new Error(\"no peer\");\n\n\t\t// Create two TransformStreams for the two directions\n\t\tconst c2s = newStream();\n\t\tconst s2c = newStream();\n\n\t\t// Local side: writes to c2s, reads from s2c\n\t\tconst local = {\n\t\t\treadable: s2c.readable,\n\t\t\twritable: c2s.writable,\n\t\t} as WebTransportBidirectionalStream;\n\n\t\t// Peer side: writes to s2c, reads from c2s\n\t\tconst remote = {\n\t\t\treadable: c2s.readable,\n\t\t\twritable: s2c.writable,\n\t\t} as WebTransportBidirectionalStream;\n\n\t\ttry {\n\t\t\tpeer.#bidiController.enqueue(remote);\n\t\t} catch {\n\t\t\t// Peer closed\n\t\t}\n\n\t\treturn local;\n\t}\n\n\tasync createUnidirectionalStream(_options?: WebTransportSendStreamOptions): Promise<WritableStream<Uint8Array>> {\n\t\tconst peer = this.#peer;\n\t\tif (!peer) throw new Error(\"no peer\");\n\n\t\tconst c2s = newStream();\n\n\t\ttry {\n\t\t\tpeer.#uniController.enqueue(c2s.readable);\n\t\t} catch {\n\t\t\t// Peer closed\n\t\t}\n\n\t\treturn c2s.writable;\n\t}\n\n\tclose(_closeInfo?: WebTransportCloseInfo): void {\n\t\tconst info = _closeInfo ?? { closeCode: 0, reason: \"\" };\n\t\tthis.#closeResolve(info);\n\n\t\ttry {\n\t\t\tthis.#bidiController.close();\n\t\t} catch {\n\t\t\t// Already closed\n\t\t}\n\t\ttry {\n\t\t\tthis.#uniController.close();\n\t\t} catch {\n\t\t\t// Already closed\n\t\t}\n\n\t\t// Also close peer's incoming streams\n\t\tif (this.#peer) {\n\t\t\ttry {\n\t\t\t\tthis.#peer.#bidiController.close();\n\t\t\t} catch {\n\t\t\t\t// Already closed\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.#peer.#uniController.close();\n\t\t\t} catch {\n\t\t\t\t// Already closed\n\t\t\t}\n\t\t\tthis.#peer.#closeResolve(info);\n\t\t}\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: WebTransportStats type not available in all TS libs\n\tasync getStats(): Promise<any> {\n\t\treturn {};\n\t}\n}\n\n/**\n * Creates a pair of connected MockTransport instances.\n *\n * @param protocol - The WebTransport protocol identifier (e.g. \"moqt-17\", \"moql\", \"\")\n * @returns An object containing `client` and `server` transports\n */\nexport function createMockTransportPair(protocol = \"\"): { client: WebTransport; server: WebTransport } {\n\tconst client = new MockTransport(protocol);\n\tconst server = new MockTransport(protocol);\n\tclient.setPeer(server);\n\tserver.setPeer(client);\n\treturn { client, server };\n}\n"]}
1
+ {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,kEAAkE;AAClE,6EAA6E;AAC7E,MAAM,iBAAiB,GAAgC,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC;AAC9E,MAAM,iBAAiB,GAAgC,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC;AAE9E,SAAS,SAAS;IACjB,OAAO,IAAI,eAAe,CACzB;QACC,wEAAwE;QACxE,oEAAoE;QACpE,SAAS,CAAC,KAAK,EAAE,UAAU;YAC1B,UAAU,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC;KACD,EACD,iBAAiB,EACjB,iBAAiB,CACjB,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,MAAM,OAAO,aAAa;IAChB,QAAQ,CAAS;IACjB,KAAK,CAAqB;IAC1B,MAAM,CAAiC;IAEvC,4BAA4B,CAAkD;IAC9E,6BAA6B,CAA6C;IAE1E,SAAS,CA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ACb,OAA8B;IAE9B,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,IAAI,CAAC;IAC7C,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAC5G,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAC5G,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;QACpB,uFAAuF;QACvF,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Mock WebTransport implementation for in-process testing.\n *\n * Creates paired client/server transports connected via TransformStreams.\n */\n\nimport type { TransportStats } from \"./connection/stats.ts\";\n\n// High watermark to prevent writes from blocking on backpressure.\n// Real WebTransport has kernel buffers; we simulate this with a large queue.\nconst WRITABLE_STRATEGY: QueuingStrategy<Uint8Array> = { highWaterMark: 256 };\nconst READABLE_STRATEGY: QueuingStrategy<Uint8Array> = { highWaterMark: 256 };\n\nfunction newStream(): TransformStream<Uint8Array, Uint8Array> {\n\treturn new TransformStream(\n\t\t{\n\t\t\t// Copy each chunk to simulate real WebTransport's kernel-boundary copy.\n\t\t\t// Without this, Writer's scratch buffer reuse corrupts queued data.\n\t\t\ttransform(chunk, controller) {\n\t\t\t\tcontroller.enqueue(new Uint8Array(chunk));\n\t\t\t},\n\t\t},\n\t\tWRITABLE_STRATEGY,\n\t\tREADABLE_STRATEGY,\n\t);\n}\n\n/** A fake {@link WebTransport} backed by TransformStreams, paired with a peer. */\nexport class MockTransport implements WebTransport {\n\treadonly protocol: string;\n\treadonly ready: Promise<undefined>;\n\treadonly closed: Promise<WebTransportCloseInfo>;\n\n\treadonly incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalStream>;\n\treadonly incomingUnidirectionalStreams: ReadableStream<ReadableStream<Uint8Array>>;\n\n\treadonly datagrams: WebTransportDatagramDuplexStream;\n\treadonly congestionControl: WebTransportCongestionControl;\n\treadonly reliability: string;\n\n\t#closeResolve!: (info: WebTransportCloseInfo) => void;\n\t#bidiController!: ReadableStreamDefaultController<WebTransportBidirectionalStream>;\n\t#uniController!: ReadableStreamDefaultController<ReadableStream<Uint8Array>>;\n\t// Incoming-datagram controller (only set when datagrams are enabled); the peer's\n\t// writable enqueues into it.\n\t#datagramController?: ReadableStreamDefaultController<Uint8Array>;\n\n\t// Reference to the peer so we can enqueue streams to them\n\t#peer?: MockTransport;\n\n\tconstructor(\n\t\tprotocol: string,\n\t\tdatagramsEnabled = true,\n\t\tdatagramWritable: DatagramWritableApi = \"writable\",\n\t\tdatagramReadable = true,\n\t) {\n\t\tthis.protocol = protocol;\n\t\tthis.ready = Promise.resolve(undefined);\n\t\tthis.closed = new Promise((resolve) => {\n\t\t\tthis.#closeResolve = resolve;\n\t\t});\n\n\t\tthis.incomingBidirectionalStreams = new ReadableStream({\n\t\t\tstart: (controller) => {\n\t\t\t\tthis.#bidiController = controller;\n\t\t\t},\n\t\t});\n\n\t\tthis.incomingUnidirectionalStreams = new ReadableStream({\n\t\t\tstart: (controller) => {\n\t\t\t\tthis.#uniController = controller;\n\t\t\t},\n\t\t});\n\n\t\tthis.congestionControl = \"default\";\n\t\tthis.reliability = \"supports-unreliable\";\n\n\t\tif (datagramsEnabled) {\n\t\t\t// A real datagram duplex: writes enqueue into the peer's incoming readable,\n\t\t\t// so a peer pair actually exchanges datagrams (unlike a real qmux Session,\n\t\t\t// whose datagram streams are inert stubs).\n\t\t\tconst readable = datagramReadable\n\t\t\t\t? new ReadableStream<Uint8Array>({\n\t\t\t\t\t\tstart: (controller) => {\n\t\t\t\t\t\t\tthis.#datagramController = controller;\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t: undefined;\n\t\t\tconst writable = new WritableStream<Uint8Array>({\n\t\t\t\twrite: (chunk) => {\n\t\t\t\t\tconst peer = this.#peer;\n\t\t\t\t\tif (!peer) return;\n\t\t\t\t\tconst controller = peer.#datagramController;\n\t\t\t\t\tif (!controller) return;\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Copy so the caller's scratch buffer reuse can't corrupt queued data.\n\t\t\t\t\t\tcontroller.enqueue(new Uint8Array(chunk));\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Peer closed; drop (datagrams are best-effort).\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst datagrams: {\n\t\t\t\treadable?: ReadableStream<Uint8Array>;\n\t\t\t\twritable?: WritableStream<Uint8Array>;\n\t\t\t\tmaxDatagramSize: number;\n\t\t\t\tincomingHighWaterMark: number;\n\t\t\t\toutgoingHighWaterMark: number;\n\t\t\t\tincomingMaxAge: null;\n\t\t\t\toutgoingMaxAge: null;\n\t\t\t\tcreateWritable?: () => WritableStream<Uint8Array>;\n\t\t\t} = {\n\t\t\t\treadable,\n\t\t\t\tincomingHighWaterMark: 0,\n\t\t\t\toutgoingHighWaterMark: 0,\n\t\t\t\tincomingMaxAge: null,\n\t\t\t\toutgoingMaxAge: null,\n\t\t\t\tmaxDatagramSize: 1200,\n\t\t\t};\n\t\t\tif (datagramWritable === \"writable\") {\n\t\t\t\tdatagrams.writable = writable;\n\t\t\t} else if (datagramWritable === \"createWritable\") {\n\t\t\t\tdatagrams.createWritable = () => writable;\n\t\t\t}\n\t\t\tthis.datagrams = datagrams as WebTransportDatagramDuplexStream;\n\t\t} else {\n\t\t\t// Simulate a transport that doesn't carry datagrams (maxDatagramSize 0): the\n\t\t\t// wire layer must fall back to not sending, with no group fallback.\n\t\t\tthis.datagrams = {\n\t\t\t\treadable: new ReadableStream(),\n\t\t\t\twritable: new WritableStream(),\n\t\t\t\tincomingHighWaterMark: 0,\n\t\t\t\toutgoingHighWaterMark: 0,\n\t\t\t\tincomingMaxAge: null,\n\t\t\t\toutgoingMaxAge: null,\n\t\t\t\tmaxDatagramSize: 0,\n\t\t\t};\n\t\t}\n\t}\n\n\tsetPeer(peer: MockTransport) {\n\t\tthis.#peer = peer;\n\t}\n\n\tasync createBidirectionalStream(\n\t\t_options?: WebTransportSendStreamOptions,\n\t): Promise<WebTransportBidirectionalStream> {\n\t\tconst peer = this.#peer;\n\t\tif (!peer) throw new Error(\"no peer\");\n\n\t\t// Create two TransformStreams for the two directions\n\t\tconst c2s = newStream();\n\t\tconst s2c = newStream();\n\n\t\t// Local side: writes to c2s, reads from s2c\n\t\tconst local = {\n\t\t\treadable: s2c.readable,\n\t\t\twritable: c2s.writable,\n\t\t} as WebTransportBidirectionalStream;\n\n\t\t// Peer side: writes to s2c, reads from c2s\n\t\tconst remote = {\n\t\t\treadable: c2s.readable,\n\t\t\twritable: s2c.writable,\n\t\t} as WebTransportBidirectionalStream;\n\n\t\ttry {\n\t\t\tpeer.#bidiController.enqueue(remote);\n\t\t} catch {\n\t\t\t// Peer closed\n\t\t}\n\n\t\treturn local;\n\t}\n\n\tasync createUnidirectionalStream(_options?: WebTransportSendStreamOptions): Promise<WritableStream<Uint8Array>> {\n\t\tconst peer = this.#peer;\n\t\tif (!peer) throw new Error(\"no peer\");\n\n\t\tconst c2s = newStream();\n\n\t\ttry {\n\t\t\tpeer.#uniController.enqueue(c2s.readable);\n\t\t} catch {\n\t\t\t// Peer closed\n\t\t}\n\n\t\treturn c2s.writable;\n\t}\n\n\tclose(_closeInfo?: WebTransportCloseInfo): void {\n\t\tconst info = _closeInfo ?? { closeCode: 0, reason: \"\" };\n\t\tthis.#closeResolve(info);\n\n\t\ttry {\n\t\t\tthis.#bidiController.close();\n\t\t} catch {\n\t\t\t// Already closed\n\t\t}\n\t\ttry {\n\t\t\tthis.#uniController.close();\n\t\t} catch {\n\t\t\t// Already closed\n\t\t}\n\n\t\ttry {\n\t\t\tthis.#datagramController?.close();\n\t\t} catch {\n\t\t\t// Already closed\n\t\t}\n\n\t\t// Also close peer's incoming streams\n\t\tif (this.#peer) {\n\t\t\ttry {\n\t\t\t\tthis.#peer.#bidiController.close();\n\t\t\t} catch {\n\t\t\t\t// Already closed\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.#peer.#uniController.close();\n\t\t\t} catch {\n\t\t\t\t// Already closed\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.#peer.#datagramController?.close();\n\t\t\t} catch {\n\t\t\t\t// Already closed\n\t\t\t}\n\t\t\tthis.#peer.#closeResolve(info);\n\t\t}\n\t}\n\n\t/** The snapshot {@link getStats} resolves with (default empty). */\n\tstats: TransportStats = {};\n\n\tasync getStats(): Promise<TransportStats> {\n\t\treturn this.stats;\n\t}\n}\n\ntype DatagramWritableApi = \"writable\" | \"createWritable\" | \"none\";\n\n/** Options for {@link createMockTransportPair}. */\nexport interface MockTransportOptions {\n\t/**\n\t * Whether the paired transports carry QUIC datagrams (default true). Set false to\n\t * simulate a transport that reports `maxDatagramSize` 0 (e.g. a qmux/WebSocket\n\t * session), so the wire layer must fall back to not sending datagrams.\n\t */\n\tdatagrams?: boolean;\n\n\t/** Which outgoing datagram API shape the mock exposes. */\n\tdatagramWritable?: DatagramWritableApi;\n\n\t/** Whether the incoming datagram readable stream is exposed. */\n\tdatagramReadable?: boolean;\n\n\t/** The snapshot `getStats()` resolves with on both transports (default empty). */\n\tstats?: TransportStats;\n}\n\n/**\n * Creates a pair of connected MockTransport instances.\n *\n * @param protocol - The WebTransport protocol identifier (e.g. \"moqt-17\", \"moql\", \"\")\n * @param options - Optional behavior toggles for datagram availability\n * @returns An object containing `client` and `server` transports\n */\nexport function createMockTransportPair(\n\tprotocol = \"\",\n\toptions?: MockTransportOptions,\n): { client: MockTransport; server: MockTransport } {\n\tconst datagrams = options?.datagrams ?? true;\n\tconst client = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);\n\tconst server = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);\n\tif (options?.stats) {\n\t\t// Copy per side so a test advancing one transport's counters doesn't move the other's.\n\t\tclient.stats = { ...options.stats };\n\t\tserver.stats = { ...options.stats };\n\t}\n\tclient.setPeer(server);\n\tserver.setPeer(client);\n\treturn { client, server };\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moq/net",
3
3
  "type": "module",
4
- "version": "0.1.9",
4
+ "version": "0.2.0",
5
5
  "description": "The networking layer for Media over QUIC: real-time pub/sub with built-in caching, fan-out, and prioritization.",
6
6
  "license": "(MIT OR Apache-2.0)",
7
7
  "repository": "github:moq-dev/moq",
@@ -17,8 +17,8 @@
17
17
  }
18
18
  },
19
19
  "dependencies": {
20
- "@moq/qmux": "^0.1.3",
21
- "@moq/signals": "^0.1.10",
20
+ "@moq/qmux": "^0.3.1",
21
+ "@moq/signals": "^0.2.0",
22
22
  "async-mutex": "^0.5.0"
23
23
  },
24
24
  "peerDependencies": {
package/path.d.ts CHANGED
@@ -108,4 +108,34 @@ export declare function stripPrefix(prefix: Valid, path: Valid): Valid | null;
108
108
  export declare function join(path: Valid, other: Valid): Valid;
109
109
  /** The empty path, which is a prefix of every path. */
110
110
  export declare function empty(): Valid;
111
+ /**
112
+ * Normalize a relative path reference: trim leading/trailing slashes, drop empty
113
+ * segments, and drop `.` segments (no-ops, matching POSIX). `..` is preserved and
114
+ * only interpreted by {@link resolve}.
115
+ *
116
+ * Mirrors the Rust `PathRelative::new` normalization, so JS and Rust agree
117
+ * byte-for-byte on the stored form. Two callers comparing normalized strings can
118
+ * detect that `""`, `"."`, `"/./"` etc. all mean "no reference".
119
+ */
120
+ export declare function normalizeRelative(rel: string): string;
121
+ /**
122
+ * Resolve a relative path reference against a base path.
123
+ *
124
+ * `..` segments pop the last segment of the base; other segments are appended.
125
+ * `.` and empty segments are no-ops. Excess `..` once the base is empty is also a
126
+ * no-op (subsequent named segments still append). An empty / normalized-empty `rel`
127
+ * returns the base path unchanged.
128
+ *
129
+ * Mirrors the Rust `Path::resolve`, used by hang catalogs to express
130
+ * cross-broadcast track references (a rendition's `broadcast` field).
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * Path.resolve(Path.from("a/b/c"), "../source"); // "a/b/source"
135
+ * Path.resolve(Path.from("a/b"), "x/y"); // "a/b/x/y"
136
+ * Path.resolve(Path.from("a"), "../../x"); // "x"
137
+ * Path.resolve(Path.from("a/b"), "./c"); // "a/b/c"
138
+ * ```
139
+ */
140
+ export declare function resolve(base: Valid, rel: string): Valid;
111
141
  //# sourceMappingURL=path.d.ts.map
package/path.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,iGAAiG;AACjG,wBAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAI9C;AAED,gFAAgF;AAChF,wBAAgB,KAAK,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,EAAE,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAGzC;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAKzC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EA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KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CASrD;AAED,uDAAuD;AACvD,wBAAgB,KAAK,IAAI,KAAK,CAE7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,CAevD"}
package/path.js CHANGED
@@ -130,4 +130,53 @@ export function join(path, other) {
130
130
  export function empty() {
131
131
  return "";
132
132
  }
133
+ /**
134
+ * Normalize a relative path reference: trim leading/trailing slashes, drop empty
135
+ * segments, and drop `.` segments (no-ops, matching POSIX). `..` is preserved and
136
+ * only interpreted by {@link resolve}.
137
+ *
138
+ * Mirrors the Rust `PathRelative::new` normalization, so JS and Rust agree
139
+ * byte-for-byte on the stored form. Two callers comparing normalized strings can
140
+ * detect that `""`, `"."`, `"/./"` etc. all mean "no reference".
141
+ */
142
+ export function normalizeRelative(rel) {
143
+ return rel
144
+ .split("/")
145
+ .filter((s) => s !== "" && s !== ".")
146
+ .join("/");
147
+ }
148
+ /**
149
+ * Resolve a relative path reference against a base path.
150
+ *
151
+ * `..` segments pop the last segment of the base; other segments are appended.
152
+ * `.` and empty segments are no-ops. Excess `..` once the base is empty is also a
153
+ * no-op (subsequent named segments still append). An empty / normalized-empty `rel`
154
+ * returns the base path unchanged.
155
+ *
156
+ * Mirrors the Rust `Path::resolve`, used by hang catalogs to express
157
+ * cross-broadcast track references (a rendition's `broadcast` field).
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * Path.resolve(Path.from("a/b/c"), "../source"); // "a/b/source"
162
+ * Path.resolve(Path.from("a/b"), "x/y"); // "a/b/x/y"
163
+ * Path.resolve(Path.from("a"), "../../x"); // "x"
164
+ * Path.resolve(Path.from("a/b"), "./c"); // "a/b/c"
165
+ * ```
166
+ */
167
+ export function resolve(base, rel) {
168
+ const segments = base === "" ? [] : base.split("/");
169
+ for (const seg of rel.split("/")) {
170
+ if (seg === "" || seg === ".") {
171
+ continue;
172
+ }
173
+ if (seg === "..") {
174
+ segments.pop();
175
+ }
176
+ else {
177
+ segments.push(seg);
178
+ }
179
+ }
180
+ return segments.join("/");
181
+ }
133
182
  //# sourceMappingURL=path.js.map
package/path.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAgCA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAE5B,iGAAiG;AACjG,MAAM,UAAU,IAAI,CAAC,GAAG,KAAe;IACtC,4GAA4G;IAC5G,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAU,CAAC;AACrF,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,KAAK,CAAC,IAAW;IAChC,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW;IACjC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,IAAW;IACjC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,gBAAgB,SAAS,QAAQ,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,IAAI,CA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GAAG,IAAI,IAAI,KAAK,EAAW,CAAC;IACpC,CAAC;AACF,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,KAAK;IACpB,OAAO,EAAW,CAAC;AACpB,CAAC","sourcesContent":["/**\n * A broadcast path that provides safe prefix matching operations.\n *\n * This module provides path-aware operations that respect delimiter boundaries,\n * preventing issues like \"foo\" matching \"foobar\".\n *\n * Paths are automatically trimmed of leading and trailing slashes on creation,\n * making all slashes implicit at boundaries.\n * All paths are RELATIVE; you cannot join with a leading slash to make an absolute path.\n *\n * @example\n * ```typescript\n * // Creation automatically trims slashes\n * const path1 = Path.from(\"/foo/bar/\");\n * const path2 = Path.from(\"foo/bar\");\n * console.log(path1 === path2); // true\n *\n * // Multiple arguments are joined with \"/\"\n * const path3 = Path.from(\"api\", \"v1\", \"users\");\n * console.log(path3); // \"api/v1/users\"\n *\n * // Safe prefix matching\n * const base = Path.from(\"api/v1\");\n * console.log(Path.hasPrefix(Path.from(\"api\"), base)); // true\n * console.log(Path.hasPrefix(Path.from(\"api/v1\"), base)); // true\n *\n * const joined = Path.join(base, Path.from(\"users\"));\n * console.log(joined); // \"api/v1/users\"\n * ```\n */\nexport type Valid = string & { __brand: \"Name\" };\n\n/**\n * Maximum number of slash-separated parts in a path.\n *\n * Matches the IETF moq-transport limit of 32 fields in a namespace tuple.\n * moq-lite enforces the same bound when decoding paths off the wire.\n */\nexport const MAX_PARTS = 32;\n\n/** Build a path from one or more components, joining with \"/\" and trimming redundant slashes. */\nexport function from(...paths: string[]): Valid {\n\t// Join paths with \"/\" and then remove leading and trailing slashes, and collapse multiple slashes into one.\n\tconst joined = paths.join(\"/\");\n\treturn joined.replace(/\\/+/g, \"/\").replace(/^\\/+/, \"\").replace(/\\/+$/, \"\") as Valid;\n}\n\n/** Split a path into its slash-separated parts. The empty path has no parts. */\nexport function parts(path: Valid): string[] {\n\treturn path === \"\" ? [] : path.split(\"/\");\n}\n\n/**\n * Validate an untrusted wire string as a path, enforcing {@link MAX_PARTS}.\n *\n * Throws when the path has too many parts; use at wire decode sites.\n */\nexport function decode(raw: string): Valid {\n\tconst path = from(raw);\n\treturn encode(path);\n}\n\n/**\n * Validate a path before writing it to the wire, enforcing {@link MAX_PARTS}.\n *\n * Throws when the path has too many parts; use at wire encode sites so we never\n * emit a path the remote side is required to reject.\n */\nexport function encode(path: Valid): Valid {\n\tif (parts(path).length > MAX_PARTS) {\n\t\tthrow new Error(`path exceeds ${MAX_PARTS} parts`);\n\t}\n\treturn path;\n}\n\n/**\n * Check if a path has the given prefix, respecting path boundaries.\n *\n * Unlike String.startsWith, this ensures that \"foo\" does not match \"foobar\".\n * The prefix must either:\n * - Be exactly equal to the path\n * - Be followed by a '/' delimiter in the original path\n * - Be empty (matches everything)\n *\n * @example\n * ```typescript\n * const path = Path.from(\"foo/bar\");\n * console.log(Path.hasPrefix(Path.from(\"foo\"), path)); // true\n * console.log(Path.hasPrefix(Path.from(\"foo/\"), path)); // true (trailing slash ignored)\n * console.log(Path.hasPrefix(Path.from(\"fo\"), path)); // false\n *\n * const path2 = Path.from(\"foobar\");\n * console.log(Path.hasPrefix(Path.from(\"foo\"), path2)); // false\n * ```\n */\nexport function hasPrefix(prefix: Valid, path: Valid): boolean {\n\tif (prefix === \"\") {\n\t\treturn true;\n\t}\n\n\tif (!path.startsWith(prefix)) {\n\t\treturn false;\n\t}\n\n\t// Check if the prefix is the exact match\n\tif (path.length === prefix.length) {\n\t\treturn true;\n\t}\n\n\t// Otherwise, ensure the character after the prefix is a delimiter\n\treturn path[prefix.length] === \"/\";\n}\n\n/**\n * Strip the given prefix from a path, returning the suffix.\n *\n * Returns null if the prefix doesn't match according to hasPrefix rules.\n *\n * @example\n * ```typescript\n * const path = Path.from(\"foo/bar/baz\");\n * const suffix = Path.stripPrefix(Path.from(\"foo\"), path);\n * console.log(suffix); // \"bar/baz\"\n *\n * const suffix2 = Path.stripPrefix(Path.from(\"foo/\"), path);\n * console.log(suffix2); // \"bar/baz\"\n *\n * const noMatch = Path.stripPrefix(Path.from(\"notfound\"), path);\n * console.log(noMatch); // null\n * ```\n */\nexport function stripPrefix(prefix: Valid, path: Valid): Valid | null {\n\tif (!hasPrefix(prefix, path)) {\n\t\treturn null;\n\t}\n\n\t// Handle empty prefix case\n\tif (prefix === \"\") {\n\t\treturn path;\n\t}\n\n\t// If prefix matches exactly, return empty\n\tif (path.length === prefix.length) {\n\t\treturn \"\" as Valid;\n\t}\n\n\t// For non-empty prefix that's shorter, skip the prefix and the following slash\n\treturn path.slice(prefix.length + 1) as Valid;\n}\n\n/**\n * Join two path components together.\n *\n * @example\n * ```typescript\n * const base = Path.from(\"foo\");\n * const joined = Path.join(base, Path.from(\"bar\"));\n * console.log(joined); // \"foo/bar\"\n * ```\n */\nexport function join(path: Valid, other: Valid): Valid {\n\tif (path === \"\") {\n\t\treturn other;\n\t} else if (other === \"\") {\n\t\treturn path;\n\t} else {\n\t\t// Since paths are trimmed, we always need to add a slash\n\t\treturn `${path}/${other}` as Valid;\n\t}\n}\n\n/** The empty path, which is a prefix of every path. */\nexport function empty(): Valid {\n\treturn \"\" as Valid;\n}\n"]}
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAgCA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAE5B,iGAAiG;AACjG,MAAM,UAAU,IAAI,CAAC,GAAG,KAAe;IACtC,4GAA4G;IAC5G,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAU,CAAC;AACrF,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,KAAK,CAAC,IAAW;IAChC,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,C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,CAAC;YAClB,QAAQ,CAAC,GAAG,EAAE,CAAC;QAChB,CAAC;aAAM,CAAC;YACP,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAU,CAAC;AACpC,CAAC","sourcesContent":["/**\n * A broadcast path that provides safe prefix matching operations.\n *\n * This module provides path-aware operations that respect delimiter boundaries,\n * preventing issues like \"foo\" matching \"foobar\".\n *\n * Paths are automatically trimmed of leading and trailing slashes on creation,\n * making all slashes implicit at boundaries.\n * All paths are RELATIVE; you cannot join with a leading slash to make an absolute path.\n *\n * @example\n * ```typescript\n * // Creation automatically trims slashes\n * const path1 = Path.from(\"/foo/bar/\");\n * const path2 = Path.from(\"foo/bar\");\n * console.log(path1 === path2); // true\n *\n * // Multiple arguments are joined with \"/\"\n * const path3 = Path.from(\"api\", \"v1\", \"users\");\n * console.log(path3); // \"api/v1/users\"\n *\n * // Safe prefix matching\n * const base = Path.from(\"api/v1\");\n * console.log(Path.hasPrefix(Path.from(\"api\"), base)); // true\n * console.log(Path.hasPrefix(Path.from(\"api/v1\"), base)); // true\n *\n * const joined = Path.join(base, Path.from(\"users\"));\n * console.log(joined); // \"api/v1/users\"\n * ```\n */\nexport type Valid = string & { __brand: \"Name\" };\n\n/**\n * Maximum number of slash-separated parts in a path.\n *\n * Matches the IETF moq-transport limit of 32 fields in a namespace tuple.\n * moq-lite enforces the same bound when decoding paths off the wire.\n */\nexport const MAX_PARTS = 32;\n\n/** Build a path from one or more components, joining with \"/\" and trimming redundant slashes. */\nexport function from(...paths: string[]): Valid {\n\t// Join paths with \"/\" and then remove leading and trailing slashes, and collapse multiple slashes into one.\n\tconst joined = paths.join(\"/\");\n\treturn joined.replace(/\\/+/g, \"/\").replace(/^\\/+/, \"\").replace(/\\/+$/, \"\") as Valid;\n}\n\n/** Split a path into its slash-separated parts. The empty path has no parts. */\nexport function parts(path: Valid): string[] {\n\treturn path === \"\" ? [] : path.split(\"/\");\n}\n\n/**\n * Validate an untrusted wire string as a path, enforcing {@link MAX_PARTS}.\n *\n * Throws when the path has too many parts; use at wire decode sites.\n */\nexport function decode(raw: string): Valid {\n\tconst path = from(raw);\n\treturn encode(path);\n}\n\n/**\n * Validate a path before writing it to the wire, enforcing {@link MAX_PARTS}.\n *\n * Throws when the path has too many parts; use at wire encode sites so we never\n * emit a path the remote side is required to reject.\n */\nexport function encode(path: Valid): Valid {\n\tif (parts(path).length > MAX_PARTS) {\n\t\tthrow new Error(`path exceeds ${MAX_PARTS} parts`);\n\t}\n\treturn path;\n}\n\n/**\n * Check if a path has the given prefix, respecting path boundaries.\n *\n * Unlike String.startsWith, this ensures that \"foo\" does not match \"foobar\".\n * The prefix must either:\n * - Be exactly equal to the path\n * - Be followed by a '/' delimiter in the original path\n * - Be empty (matches everything)\n *\n * @example\n * ```typescript\n * const path = Path.from(\"foo/bar\");\n * console.log(Path.hasPrefix(Path.from(\"foo\"), path)); // true\n * console.log(Path.hasPrefix(Path.from(\"foo/\"), path)); // true (trailing slash ignored)\n * console.log(Path.hasPrefix(Path.from(\"fo\"), path)); // false\n *\n * const path2 = Path.from(\"foobar\");\n * console.log(Path.hasPrefix(Path.from(\"foo\"), path2)); // false\n * ```\n */\nexport function hasPrefix(prefix: Valid, path: Valid): boolean {\n\tif (prefix === \"\") {\n\t\treturn true;\n\t}\n\n\tif (!path.startsWith(prefix)) {\n\t\treturn false;\n\t}\n\n\t// Check if the prefix is the exact match\n\tif (path.length === prefix.length) {\n\t\treturn true;\n\t}\n\n\t// Otherwise, ensure the character after the prefix is a delimiter\n\treturn path[prefix.length] === \"/\";\n}\n\n/**\n * Strip the given prefix from a path, returning the suffix.\n *\n * Returns null if the prefix doesn't match according to hasPrefix rules.\n *\n * @example\n * ```typescript\n * const path = Path.from(\"foo/bar/baz\");\n * const suffix = Path.stripPrefix(Path.from(\"foo\"), path);\n * console.log(suffix); // \"bar/baz\"\n *\n * const suffix2 = Path.stripPrefix(Path.from(\"foo/\"), path);\n * console.log(suffix2); // \"bar/baz\"\n *\n * const noMatch = Path.stripPrefix(Path.from(\"notfound\"), path);\n * console.log(noMatch); // null\n * ```\n */\nexport function stripPrefix(prefix: Valid, path: Valid): Valid | null {\n\tif (!hasPrefix(prefix, path)) {\n\t\treturn null;\n\t}\n\n\t// Handle empty prefix case\n\tif (prefix === \"\") {\n\t\treturn path;\n\t}\n\n\t// If prefix matches exactly, return empty\n\tif (path.length === prefix.length) {\n\t\treturn \"\" as Valid;\n\t}\n\n\t// For non-empty prefix that's shorter, skip the prefix and the following slash\n\treturn path.slice(prefix.length + 1) as Valid;\n}\n\n/**\n * Join two path components together.\n *\n * @example\n * ```typescript\n * const base = Path.from(\"foo\");\n * const joined = Path.join(base, Path.from(\"bar\"));\n * console.log(joined); // \"foo/bar\"\n * ```\n */\nexport function join(path: Valid, other: Valid): Valid {\n\tif (path === \"\") {\n\t\treturn other;\n\t} else if (other === \"\") {\n\t\treturn path;\n\t} else {\n\t\t// Since paths are trimmed, we always need to add a slash\n\t\treturn `${path}/${other}` as Valid;\n\t}\n}\n\n/** The empty path, which is a prefix of every path. */\nexport function empty(): Valid {\n\treturn \"\" as Valid;\n}\n\n/**\n * Normalize a relative path reference: trim leading/trailing slashes, drop empty\n * segments, and drop `.` segments (no-ops, matching POSIX). `..` is preserved and\n * only interpreted by {@link resolve}.\n *\n * Mirrors the Rust `PathRelative::new` normalization, so JS and Rust agree\n * byte-for-byte on the stored form. Two callers comparing normalized strings can\n * detect that `\"\"`, `\".\"`, `\"/./\"` etc. all mean \"no reference\".\n */\nexport function normalizeRelative(rel: string): string {\n\treturn rel\n\t\t.split(\"/\")\n\t\t.filter((s) => s !== \"\" && s !== \".\")\n\t\t.join(\"/\");\n}\n\n/**\n * Resolve a relative path reference against a base path.\n *\n * `..` segments pop the last segment of the base; other segments are appended.\n * `.` and empty segments are no-ops. Excess `..` once the base is empty is also a\n * no-op (subsequent named segments still append). An empty / normalized-empty `rel`\n * returns the base path unchanged.\n *\n * Mirrors the Rust `Path::resolve`, used by hang catalogs to express\n * cross-broadcast track references (a rendition's `broadcast` field).\n *\n * @example\n * ```typescript\n * Path.resolve(Path.from(\"a/b/c\"), \"../source\"); // \"a/b/source\"\n * Path.resolve(Path.from(\"a/b\"), \"x/y\"); // \"a/b/x/y\"\n * Path.resolve(Path.from(\"a\"), \"../../x\"); // \"x\"\n * Path.resolve(Path.from(\"a/b\"), \"./c\"); // \"a/b/c\"\n * ```\n */\nexport function resolve(base: Valid, rel: string): Valid {\n\tconst segments = base === \"\" ? [] : base.split(\"/\");\n\n\tfor (const seg of rel.split(\"/\")) {\n\t\tif (seg === \"\" || seg === \".\") {\n\t\t\tcontinue;\n\t\t}\n\t\tif (seg === \"..\") {\n\t\t\tsegments.pop();\n\t\t} else {\n\t\t\tsegments.push(seg);\n\t\t}\n\t}\n\n\treturn segments.join(\"/\") as Valid;\n}\n"]}