@moq/net 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/README.md +70 -0
  2. package/announced.d.ts +41 -0
  3. package/announced.d.ts.map +1 -0
  4. package/announced.js +65 -0
  5. package/announced.js.map +1 -0
  6. package/bandwidth.d.ts +11 -0
  7. package/bandwidth.d.ts.map +1 -0
  8. package/bandwidth.js +6 -0
  9. package/bandwidth.js.map +1 -0
  10. package/broadcast.d.ts +35 -0
  11. package/broadcast.d.ts.map +1 -0
  12. package/broadcast.js +72 -0
  13. package/broadcast.js.map +1 -0
  14. package/connection/accept.d.ts +14 -0
  15. package/connection/accept.d.ts.map +1 -0
  16. package/connection/accept.js +133 -0
  17. package/connection/accept.js.map +1 -0
  18. package/connection/connect.d.ts +19 -0
  19. package/connection/connect.d.ts.map +1 -0
  20. package/connection/connect.js +284 -0
  21. package/connection/connect.js.map +1 -0
  22. package/connection/established.d.ts +22 -0
  23. package/connection/established.d.ts.map +1 -0
  24. package/connection/established.js +2 -0
  25. package/connection/established.js.map +1 -0
  26. package/connection/handshake.d.ts +10 -0
  27. package/connection/handshake.d.ts.map +1 -0
  28. package/connection/handshake.js +47 -0
  29. package/connection/handshake.js.map +1 -0
  30. package/connection/index.d.ts +5 -0
  31. package/connection/index.d.ts.map +1 -0
  32. package/connection/index.js +5 -0
  33. package/connection/index.js.map +1 -0
  34. package/connection/reload.d.ts +32 -0
  35. package/connection/reload.d.ts.map +1 -0
  36. package/connection/reload.js +127 -0
  37. package/connection/reload.js.map +1 -0
  38. package/group.d.ts +34 -0
  39. package/group.d.ts.map +1 -0
  40. package/group.js +92 -0
  41. package/group.js.map +1 -0
  42. package/ietf/adapter.d.ts +65 -0
  43. package/ietf/adapter.d.ts.map +1 -0
  44. package/ietf/adapter.js +625 -0
  45. package/ietf/adapter.js.map +1 -0
  46. package/ietf/connection.d.ts +65 -0
  47. package/ietf/connection.d.ts.map +1 -0
  48. package/ietf/connection.js +239 -0
  49. package/ietf/connection.js.map +1 -0
  50. package/ietf/control.d.ts +135 -0
  51. package/ietf/control.d.ts.map +1 -0
  52. package/ietf/control.js +237 -0
  53. package/ietf/control.js.map +1 -0
  54. package/ietf/fetch.d.ts +64 -0
  55. package/ietf/fetch.d.ts.map +1 -0
  56. package/ietf/fetch.js +99 -0
  57. package/ietf/fetch.js.map +1 -0
  58. package/ietf/goaway.d.ts +15 -0
  59. package/ietf/goaway.d.ts.map +1 -0
  60. package/ietf/goaway.js +33 -0
  61. package/ietf/goaway.js.map +1 -0
  62. package/ietf/ietf.test.d.ts +2 -0
  63. package/ietf/ietf.test.d.ts.map +1 -0
  64. package/ietf/ietf.test.js +800 -0
  65. package/ietf/ietf.test.js.map +1 -0
  66. package/ietf/index.d.ts +18 -0
  67. package/ietf/index.d.ts.map +1 -0
  68. package/ietf/index.js +18 -0
  69. package/ietf/index.js.map +1 -0
  70. package/ietf/message.d.ts +4 -0
  71. package/ietf/message.d.ts.map +1 -0
  72. package/ietf/message.js +53 -0
  73. package/ietf/message.js.map +1 -0
  74. package/ietf/namespace.d.ts +5 -0
  75. package/ietf/namespace.d.ts.map +1 -0
  76. package/ietf/namespace.js +21 -0
  77. package/ietf/namespace.js.map +1 -0
  78. package/ietf/object.d.ts +37 -0
  79. package/ietf/object.d.ts.map +1 -0
  80. package/ietf/object.js +129 -0
  81. package/ietf/object.js.map +1 -0
  82. package/ietf/parameters.d.ts +56 -0
  83. package/ietf/parameters.d.ts.map +1 -0
  84. package/ietf/parameters.js +336 -0
  85. package/ietf/parameters.js.map +1 -0
  86. package/ietf/properties.d.ts +4 -0
  87. package/ietf/properties.d.ts.map +1 -0
  88. package/ietf/properties.js +32 -0
  89. package/ietf/properties.js.map +1 -0
  90. package/ietf/publish.d.ts +68 -0
  91. package/ietf/publish.d.ts.map +1 -0
  92. package/ietf/publish.js +191 -0
  93. package/ietf/publish.js.map +1 -0
  94. package/ietf/publish_namespace.d.ts +68 -0
  95. package/ietf/publish_namespace.d.ts.map +1 -0
  96. package/ietf/publish_namespace.js +175 -0
  97. package/ietf/publish_namespace.js.map +1 -0
  98. package/ietf/publisher.d.ts +50 -0
  99. package/ietf/publisher.d.ts.map +1 -0
  100. package/ietf/publisher.js +329 -0
  101. package/ietf/publisher.js.map +1 -0
  102. package/ietf/request.d.ts +52 -0
  103. package/ietf/request.d.ts.map +1 -0
  104. package/ietf/request.js +118 -0
  105. package/ietf/request.js.map +1 -0
  106. package/ietf/setup.d.ts +38 -0
  107. package/ietf/setup.d.ts.map +1 -0
  108. package/ietf/setup.js +128 -0
  109. package/ietf/setup.js.map +1 -0
  110. package/ietf/subscribe.d.ts +66 -0
  111. package/ietf/subscribe.d.ts.map +1 -0
  112. package/ietf/subscribe.js +275 -0
  113. package/ietf/subscribe.js.map +1 -0
  114. package/ietf/subscribe_namespace.d.ts +89 -0
  115. package/ietf/subscribe_namespace.d.ts.map +1 -0
  116. package/ietf/subscribe_namespace.js +195 -0
  117. package/ietf/subscribe_namespace.js.map +1 -0
  118. package/ietf/subscriber.d.ts +53 -0
  119. package/ietf/subscriber.d.ts.map +1 -0
  120. package/ietf/subscriber.js +395 -0
  121. package/ietf/subscriber.js.map +1 -0
  122. package/ietf/track.d.ts +40 -0
  123. package/ietf/track.d.ts.map +1 -0
  124. package/ietf/track.js +107 -0
  125. package/ietf/track.js.map +1 -0
  126. package/ietf/version.d.ts +50 -0
  127. package/ietf/version.d.ts.map +1 -0
  128. package/ietf/version.js +55 -0
  129. package/ietf/version.js.map +1 -0
  130. package/index.d.ts +11 -0
  131. package/index.d.ts.map +1 -0
  132. package/index.js +16 -0
  133. package/index.js.map +1 -0
  134. package/integration.test.d.ts +2 -0
  135. package/integration.test.d.ts.map +1 -0
  136. package/integration.test.js +83 -0
  137. package/integration.test.js.map +1 -0
  138. package/lite/announce.d.ts +35 -0
  139. package/lite/announce.d.ts.map +1 -0
  140. package/lite/announce.js +165 -0
  141. package/lite/announce.js.map +1 -0
  142. package/lite/connection.d.ts +47 -0
  143. package/lite/connection.d.ts.map +1 -0
  144. package/lite/connection.js +218 -0
  145. package/lite/connection.js.map +1 -0
  146. package/lite/fetch.d.ts +14 -0
  147. package/lite/fetch.d.ts.map +1 -0
  148. package/lite/fetch.js +46 -0
  149. package/lite/fetch.js.map +1 -0
  150. package/lite/goaway.d.ts +10 -0
  151. package/lite/goaway.d.ts.map +1 -0
  152. package/lite/goaway.js +36 -0
  153. package/lite/goaway.js.map +1 -0
  154. package/lite/group.d.ts +18 -0
  155. package/lite/group.d.ts.map +1 -0
  156. package/lite/group.js +45 -0
  157. package/lite/group.js.map +1 -0
  158. package/lite/index.d.ts +11 -0
  159. package/lite/index.d.ts.map +1 -0
  160. package/lite/index.js +11 -0
  161. package/lite/index.js.map +1 -0
  162. package/lite/message.d.ts +5 -0
  163. package/lite/message.d.ts.map +1 -0
  164. package/lite/message.js +50 -0
  165. package/lite/message.js.map +1 -0
  166. package/lite/origin.d.ts +19 -0
  167. package/lite/origin.d.ts.map +1 -0
  168. package/lite/origin.js +28 -0
  169. package/lite/origin.js.map +1 -0
  170. package/lite/probe.d.ts +12 -0
  171. package/lite/probe.d.ts.map +1 -0
  172. package/lite/probe.js +59 -0
  173. package/lite/probe.js.map +1 -0
  174. package/lite/publisher.d.ts +56 -0
  175. package/lite/publisher.d.ts.map +1 -0
  176. package/lite/publisher.js +305 -0
  177. package/lite/publisher.js.map +1 -0
  178. package/lite/session.d.ts +36 -0
  179. package/lite/session.d.ts.map +1 -0
  180. package/lite/session.js +129 -0
  181. package/lite/session.js.map +1 -0
  182. package/lite/stream.d.ts +18 -0
  183. package/lite/stream.d.ts.map +1 -0
  184. package/lite/stream.js +11 -0
  185. package/lite/stream.js.map +1 -0
  186. package/lite/subscribe.d.ts +91 -0
  187. package/lite/subscribe.d.ts.map +1 -0
  188. package/lite/subscribe.js +267 -0
  189. package/lite/subscribe.js.map +1 -0
  190. package/lite/subscriber.d.ts +80 -0
  191. package/lite/subscriber.d.ts.map +1 -0
  192. package/lite/subscriber.js +245 -0
  193. package/lite/subscriber.js.map +1 -0
  194. package/lite/version.d.ts +12 -0
  195. package/lite/version.d.ts.map +1 -0
  196. package/lite/version.js +23 -0
  197. package/lite/version.js.map +1 -0
  198. package/mock.d.ts +16 -0
  199. package/mock.d.ts.map +1 -0
  200. package/mock.js +153 -0
  201. package/mock.js.map +1 -0
  202. package/package.json +27 -0
  203. package/path.d.ts +87 -0
  204. package/path.d.ts.map +1 -0
  205. package/path.js +98 -0
  206. package/path.js.map +1 -0
  207. package/path.test.d.ts +2 -0
  208. package/path.test.d.ts.map +1 -0
  209. package/path.test.js +153 -0
  210. package/path.test.js.map +1 -0
  211. package/stream.d.ts +57 -0
  212. package/stream.d.ts.map +1 -0
  213. package/stream.js +325 -0
  214. package/stream.js.map +1 -0
  215. package/stream.test.d.ts +2 -0
  216. package/stream.test.d.ts.map +1 -0
  217. package/stream.test.js +209 -0
  218. package/stream.test.js.map +1 -0
  219. package/time.d.ts +77 -0
  220. package/time.d.ts.map +1 -0
  221. package/time.js +65 -0
  222. package/time.js.map +1 -0
  223. package/track.d.ts +66 -0
  224. package/track.d.ts.map +1 -0
  225. package/track.js +203 -0
  226. package/track.js.map +1 -0
  227. package/track.test.d.ts +2 -0
  228. package/track.test.d.ts.map +1 -0
  229. package/track.test.js +39 -0
  230. package/track.test.js.map +1 -0
  231. package/util/error.d.ts +3 -0
  232. package/util/error.d.ts.map +1 -0
  233. package/util/error.js +8 -0
  234. package/util/error.js.map +1 -0
  235. package/util/hex.d.ts +2 -0
  236. package/util/hex.d.ts.map +1 -0
  237. package/util/hex.js +12 -0
  238. package/util/hex.js.map +1 -0
  239. package/util/index.d.ts +2 -0
  240. package/util/index.d.ts.map +1 -0
  241. package/util/index.js +2 -0
  242. package/util/index.js.map +1 -0
  243. package/varint.d.ts +28 -0
  244. package/varint.d.ts.map +1 -0
  245. package/varint.js +279 -0
  246. package/varint.js.map +1 -0
  247. package/varint.test.d.ts +2 -0
  248. package/varint.test.d.ts.map +1 -0
  249. package/varint.test.js +105 -0
  250. package/varint.test.js.map +1 -0
  251. package/zod.d.ts +6 -0
  252. package/zod.d.ts.map +1 -0
  253. package/zod.js +12 -0
  254. package/zod.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriber.js","sourceRoot":"","sources":["../../src/lite/subscriber.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAqB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGzE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAgBvC;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACtB,KAAK,CAAe;IAEpB,iCAAiC;IACxB,OAAO,CAAU;IAE1B,uEAAuE;IACvE,wEAAwE;IAC/D,MAAM,CAAS;IAExB,yBAAyB;IACzB,WAAW,GAAG,IAAI,GAAG,EAAiB,CAAC;IACvC,cAAc,GAAG,EAAE,CAAC;IAEpB,0CAA0C;IAC1C,cAAc,CAAa;IAE3B,+BAA+B;IAC/B,IAAI,CAAkC;IAEtC;;;;;;;;;OASG;IACH,YACC,IAAkB,EAClB,OAAgB,EAChB,MAAc,EACd,aAAyB,EACzB,GAAoC;QAEpC,IAAI,C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AAC,KAAK,EAAE,CAAC;QACf,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACD","sourcesContent":["import type { Signal } from \"@moq/signals\";\nimport { Announced } from \"../announced.ts\";\nimport type { Bandwidth } from \"../bandwidth.ts\";\nimport { Broadcast, type TrackRequest } from \"../broadcast.ts\";\nimport { Group } from \"../group.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Stream } from \"../stream.ts\";\nimport type * as Time from \"../time.ts\";\nimport type { Track } from \"../track.ts\";\nimport { error } from \"../util/error.ts\";\nimport { Announce, AnnounceInit, AnnounceInterest } from \"./announce.ts\";\nimport type { Group as GroupMessage } from \"./group.ts\";\nimport type { Origin } from \"./origin.ts\";\nimport { Probe } from \"./probe.ts\";\nimport { StreamId } from \"./stream.ts\";\nimport { decodeSubscribeResponse, Subscribe } from \"./subscribe.ts\";\nimport { Version } from \"./version.ts\";\n\n/**\n * Options accepted by {@link Subscriber.announced}.\n */\nexport interface AnnouncedOptions {\n\t/**\n\t * If true, skip announcements whose hop chain contains this connection's\n\t * own origin id — useful for meshes that reflect announces back. Defaults\n\t * to false for backwards compatibility: existing code (notably hang.live)\n\t * relies on seeing its own publishes as the signal that a namespace\n\t * published successfully.\n\t */\n\tignoreSelf?: boolean;\n}\n\n/**\n * Handles subscribing to broadcasts and managing their lifecycle.\n *\n * @internal\n */\nexport class Subscriber {\n\t#quic: WebTransport;\n\n\t// The version of the connection.\n\treadonly version: Version;\n\n\t// Shared with the Publisher so callers can optionally filter out their\n\t// own announcements on a per-call basis (see {@link AnnouncedOptions}).\n\treadonly origin: Origin;\n\n\t// Our subscribed tracks.\n\t#subscribes = new Map<bigint, Track>();\n\t#subscribeNext = 0n;\n\n\t// Recv bandwidth producer (Lite03+ only).\n\t#recvBandwidth?: Bandwidth;\n\n\t// RTT producer (Lite04+ only).\n\t#rtt?: Signal<Time.Milli | undefined>;\n\n\t/**\n\t * Creates a new Subscriber instance.\n\t * @param quic - The WebTransport session to use\n\t * @param version - The protocol version\n\t * @param origin - Origin id shared with the Publisher\n\t * @param recvBandwidth - Optional bandwidth producer for PROBE\n\t * @param rtt - Optional RTT signal for PROBE\n\t *\n\t * @internal\n\t */\n\tconstructor(\n\t\tquic: WebTransport,\n\t\tversion: Version,\n\t\torigin: Origin,\n\t\trecvBandwidth?: Bandwidth,\n\t\trtt?: Signal<Time.Milli | undefined>,\n\t) {\n\t\tthis.#quic = quic;\n\t\tthis.version = version;\n\t\tthis.origin = origin;\n\t\tthis.#recvBandwidth = recvBandwidth;\n\t\tthis.#rtt = rtt;\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements under `prefix`.\n\t *\n\t * Pass `{ ignoreSelf: true }` to skip announces that have already traversed\n\t * this connection's {@link origin}.\n\t */\n\tannounced(prefix = Path.empty(), options: AnnouncedOptions = {}): Announced {\n\t\tconst announced = new Announced();\n\t\tvoid this.#runAnnounced(announced, prefix, options);\n\t\treturn announced;\n\t}\n\n\tasync #runAnnounced(announced: Announced, prefix: Path.Valid, options: AnnouncedOptions): Promise<void> {\n\t\tconsole.debug(`announced: prefix=${prefix}`);\n\t\t// Send our own session-level origin id so the peer can skip announces\n\t\t// whose hop chain already passed through us. Matches the Rust subscriber's\n\t\t// `exclude_hop: self.self_origin.id` in `run_announce_prefix`.\n\t\tconst msg = new AnnounceInterest(prefix, this.origin);\n\n\t\ttry {\n\t\t\t// Open a stream and send the announce interest.\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Announce);\n\t\t\tawait msg.encode(stream.writer, this.version);\n\n\t\t\tswitch (this.version) {\n\t\t\t\tcase Version.DRAFT_01:\n\t\t\t\tcase Version.DRAFT_02: {\n\t\t\t\t\t// Receive ANNOUNCE_INIT first\n\t\t\t\t\tconst init = await AnnounceInit.decode(stream.reader, this.version);\n\n\t\t\t\t\t// Process initial announcements\n\t\t\t\t\tfor (const suffix of init.suffixes) {\n\t\t\t\t\t\tconst path = Path.join(prefix, suffix);\n\t\t\t\t\t\tconsole.debug(`announced: broadcast=${path} active=true`);\n\t\t\t\t\t\tannounced.append({ path, active: true });\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\t// Draft03+: no AnnounceInit, initial state comes via Announce messages.\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Receive announce updates (for Draft03, this includes initial state)\n\t\t\tfor (;;) {\n\t\t\t\tconst announce = await Promise.race([\n\t\t\t\t\tAnnounce.decodeMaybe(stream.reader, this.version),\n\t\t\t\t\tannounced.closed,\n\t\t\t\t]);\n\t\t\t\tif (!announce) break;\n\t\t\t\tif (announce instanceof Error) throw announce;\n\n\t\t\t\t// Optionally drop reflected announces so callers asking for\n\t\t\t\t// \"someone else's broadcasts\" don't re-see their own publishes.\n\t\t\t\tif (options.ignoreSelf && announce.hops.includes(this.origin)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst path = Path.join(prefix, announce.suffix);\n\n\t\t\t\tconsole.debug(`announced: broadcast=${path} active=${announce.active}`);\n\t\t\t\tannounced.append({ path, active: announce.active });\n\t\t\t}\n\n\t\t\tannounced.close();\n\t\t} catch (err: unknown) {\n\t\t\tannounced.close(error(err));\n\t\t}\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * @param name - The name of the broadcast to consume\n\t * @returns A Broadcast instance\n\t */\n\tconsume(path: Path.Valid): Broadcast {\n\t\tconst broadcast = new Broadcast();\n\n\t\t(async () => {\n\t\t\tfor (;;) {\n\t\t\t\tconst request = await broadcast.requested();\n\t\t\t\tif (!request) break;\n\t\t\t\tthis.#runSubscribe(path, request);\n\t\t\t}\n\t\t})();\n\n\t\treturn broadcast;\n\t}\n\n\tasync #runSubscribe(broadcast: Path.Valid, request: TrackRequest) {\n\t\tconst id = this.#subscribeNext++;\n\n\t\t// Save the writer so we can append groups to it.\n\t\tthis.#subscribes.set(id, request.track);\n\n\t\tconsole.debug(`subscribe start: id=${id} broadcast=${broadcast} track=${request.track.name}`);\n\n\t\tconst msg = new Subscribe({ id, broadcast, track: request.track.name, priority: request.priority });\n\n\t\tconst stream = await Stream.open(this.#quic);\n\t\tawait stream.writer.u53(StreamId.Subscribe);\n\t\tawait msg.encode(stream.writer, this.version);\n\n\t\ttry {\n\t\t\t// The first response MUST be a SUBSCRIBE_OK.\n\t\t\tconst resp = await decodeSubscribeResponse(stream.reader, this.version);\n\t\t\tif (!(\"ok\" in resp)) {\n\t\t\t\tthrow new Error(\"first subscribe response must be SUBSCRIBE_OK\");\n\t\t\t}\n\t\t\tconsole.debug(`subscribe ok: id=${id} broadcast=${broadcast} track=${request.track.name}`);\n\n\t\t\tawait Promise.race([stream.reader.closed, request.track.closed]);\n\n\t\t\trequest.track.close();\n\t\t\tstream.close();\n\t\t\tconsole.debug(`subscribe close: id=${id} broadcast=${broadcast} track=${request.track.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = error(err);\n\t\t\trequest.track.close(e);\n\t\t\tconsole.warn(\n\t\t\t\t`subscribe error: id=${id} broadcast=${broadcast} track=${request.track.name} error=${e.message}`,\n\t\t\t);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\tthis.#subscribes.delete(id);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a group message.\n\t * @param group - The group message\n\t * @param stream - The stream to read frames from\n\t *\n\t * @internal\n\t */\n\tasync runGroup(group: GroupMessage, stream: Reader) {\n\t\tconst subscribe = this.#subscribes.get(group.subscribe);\n\t\tif (!subscribe) {\n\t\t\tif (group.subscribe >= this.#subscribeNext) {\n\t\t\t\tthrow new Error(`unknown subscription: id=${group.subscribe}`);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst producer = new Group(group.sequence);\n\t\tsubscribe.writeGroup(producer);\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await Promise.race([stream.done(), subscribe.closed, producer.closed]);\n\t\t\t\tif (done !== false) break;\n\n\t\t\t\tconst size = await stream.u53();\n\t\t\t\tconst payload = await stream.read(size);\n\t\t\t\tif (!payload) break;\n\n\t\t\t\tproducer.writeFrame(payload);\n\t\t\t}\n\n\t\t\tproducer.close();\n\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tproducer.close(e);\n\t\t\tstream.stop(e);\n\t\t}\n\t}\n\n\t/**\n\t * Opens a PROBE bidi stream to receive bandwidth estimates from the publisher.\n\t * Returns immediately if recv bandwidth is not supported.\n\t *\n\t * Probe is best-effort telemetry: a stream-level failure (peer reset, FIN,\n\t * missing peer support, transport hiccup) is caught and logged, never\n\t * propagated to the connection. On exit the bandwidth/RTT signals are\n\t * cleared so consumers see them as stale.\n\t *\n\t * @internal\n\t */\n\tasync runProbe(): Promise<void> {\n\t\tif (!this.#recvBandwidth) return;\n\t\tif (this.version === Version.DRAFT_01 || this.version === Version.DRAFT_02) return;\n\n\t\t// Probe is best-effort: any failure (stream reset by peer, missing peer support,\n\t\t// transport hiccup) MUST NOT tear down the connection. On error, drop the\n\t\t// bandwidth/RTT estimates so consumers know they're stale.\n\t\ttry {\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Probe);\n\n\t\t\tfor (;;) {\n\t\t\t\tconst probe = await Probe.decodeMaybe(stream.reader, this.version);\n\t\t\t\tif (!probe) break;\n\t\t\t\tthis.#recvBandwidth.set(probe.bitrate ?? undefined);\n\t\t\t\tif (this.#rtt && probe.rtt !== undefined) {\n\t\t\t\t\tthis.#rtt.set(probe.rtt as Time.Milli);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconsole.warn(\"probe stream error\", err);\n\t\t} finally {\n\t\t\tthis.#recvBandwidth.set(undefined);\n\t\t\tthis.#rtt?.set(undefined);\n\t\t}\n\t}\n\n\tclose() {\n\t\tfor (const track of this.#subscribes.values()) {\n\t\t\ttrack.close();\n\t\t}\n\n\t\tthis.#subscribes.clear();\n\t}\n}\n"]}
@@ -0,0 +1,12 @@
1
+ export declare const Version: {
2
+ readonly DRAFT_01: 4279086337;
3
+ readonly DRAFT_02: 4279086338;
4
+ readonly DRAFT_03: 4279086339;
5
+ readonly DRAFT_04: 4279086340;
6
+ };
7
+ export type Version = (typeof Version)[keyof typeof Version];
8
+ export declare const ALPN = "moql";
9
+ export declare const ALPN_03 = "moq-lite-03";
10
+ export declare const ALPN_04 = "moq-lite-04";
11
+ export declare function versionName(v: Version): string;
12
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/lite/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO;;;;;CAKV,CAAC;AAEX,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAI7D,eAAO,MAAM,IAAI,SAAS,CAAC;AAG3B,eAAO,MAAM,OAAO,gBAAgB,CAAC;AAGrC,eAAO,MAAM,OAAO,gBAAgB,CAAC;AASrC,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAE9C"}
@@ -0,0 +1,23 @@
1
+ export const Version = {
2
+ DRAFT_01: 0xff0dad01,
3
+ DRAFT_02: 0xff0dad02,
4
+ DRAFT_03: 0xff0dad03,
5
+ DRAFT_04: 0xff0dad04,
6
+ };
7
+ /// The WebTransport subprotocol identifier for moq-lite.
8
+ /// Version negotiation still happens via SETUP when this is used.
9
+ export const ALPN = "moql";
10
+ /// The ALPN string for Draft03, which uses ALPN-based version negotiation.
11
+ export const ALPN_03 = "moq-lite-03";
12
+ /// The ALPN string for Draft04, which uses ALPN-based version negotiation.
13
+ export const ALPN_04 = "moq-lite-04";
14
+ const VERSION_NAMES = {
15
+ [Version.DRAFT_01]: "moq-lite-01",
16
+ [Version.DRAFT_02]: "moq-lite-02",
17
+ [Version.DRAFT_03]: "moq-lite-03",
18
+ [Version.DRAFT_04]: "moq-lite-04",
19
+ };
20
+ export function versionName(v) {
21
+ return VERSION_NAMES[v] ?? `unknown(0x${v.toString(16)})`;
22
+ }
23
+ //# sourceMappingURL=version.js.map
@@ -0,0 +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;CACX,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,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;CACjC,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","sourcesContent":["export const Version = {\n\tDRAFT_01: 0xff0dad01,\n\tDRAFT_02: 0xff0dad02,\n\tDRAFT_03: 0xff0dad03,\n\tDRAFT_04: 0xff0dad04,\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\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};\n\nexport function versionName(v: Version): string {\n\treturn VERSION_NAMES[v] ?? `unknown(0x${v.toString(16)})`;\n}\n"]}
package/mock.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Mock WebTransport implementation for in-process testing.
3
+ *
4
+ * Creates paired client/server transports connected via TransformStreams.
5
+ */
6
+ /**
7
+ * Creates a pair of connected MockTransport instances.
8
+ *
9
+ * @param protocol - The WebTransport protocol identifier (e.g. "moqt-17", "moql", "")
10
+ * @returns An object containing `client` and `server` transports
11
+ */
12
+ export declare function createMockTransportPair(protocol?: string): {
13
+ client: WebTransport;
14
+ server: WebTransport;
15
+ };
16
+ //# sourceMappingURL=mock.d.ts.map
package/mock.d.ts.map ADDED
@@ -0,0 +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"}
package/mock.js ADDED
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Mock WebTransport implementation for in-process testing.
3
+ *
4
+ * Creates paired client/server transports connected via TransformStreams.
5
+ */
6
+ // High watermark to prevent writes from blocking on backpressure.
7
+ // Real WebTransport has kernel buffers; we simulate this with a large queue.
8
+ const WRITABLE_STRATEGY = { highWaterMark: 256 };
9
+ const READABLE_STRATEGY = { highWaterMark: 256 };
10
+ function newStream() {
11
+ return new TransformStream({
12
+ // Copy each chunk to simulate real WebTransport's kernel-boundary copy.
13
+ // Without this, Writer's scratch buffer reuse corrupts queued data.
14
+ transform(chunk, controller) {
15
+ controller.enqueue(new Uint8Array(chunk));
16
+ },
17
+ }, WRITABLE_STRATEGY, READABLE_STRATEGY);
18
+ }
19
+ class MockTransport {
20
+ protocol;
21
+ ready;
22
+ closed;
23
+ incomingBidirectionalStreams;
24
+ incomingUnidirectionalStreams;
25
+ datagrams;
26
+ congestionControl;
27
+ reliability;
28
+ #closeResolve;
29
+ #bidiController;
30
+ #uniController;
31
+ // Reference to the peer so we can enqueue streams to them
32
+ #peer;
33
+ constructor(protocol) {
34
+ this.protocol = protocol;
35
+ this.ready = Promise.resolve(undefined);
36
+ this.closed = new Promise((resolve) => {
37
+ this.#closeResolve = resolve;
38
+ });
39
+ this.incomingBidirectionalStreams = new ReadableStream({
40
+ start: (controller) => {
41
+ this.#bidiController = controller;
42
+ },
43
+ });
44
+ this.incomingUnidirectionalStreams = new ReadableStream({
45
+ start: (controller) => {
46
+ this.#uniController = controller;
47
+ },
48
+ });
49
+ this.congestionControl = "default";
50
+ this.reliability = "supports-unreliable";
51
+ // Stub datagrams
52
+ this.datagrams = {
53
+ readable: new ReadableStream(),
54
+ writable: new WritableStream(),
55
+ incomingHighWaterMark: 0,
56
+ outgoingHighWaterMark: 0,
57
+ incomingMaxAge: null,
58
+ outgoingMaxAge: null,
59
+ maxDatagramSize: 0,
60
+ };
61
+ }
62
+ setPeer(peer) {
63
+ this.#peer = peer;
64
+ }
65
+ async createBidirectionalStream(_options) {
66
+ const peer = this.#peer;
67
+ if (!peer)
68
+ throw new Error("no peer");
69
+ // Create two TransformStreams for the two directions
70
+ const c2s = newStream();
71
+ const s2c = newStream();
72
+ // Local side: writes to c2s, reads from s2c
73
+ const local = {
74
+ readable: s2c.readable,
75
+ writable: c2s.writable,
76
+ };
77
+ // Peer side: writes to s2c, reads from c2s
78
+ const remote = {
79
+ readable: c2s.readable,
80
+ writable: s2c.writable,
81
+ };
82
+ try {
83
+ peer.#bidiController.enqueue(remote);
84
+ }
85
+ catch {
86
+ // Peer closed
87
+ }
88
+ return local;
89
+ }
90
+ async createUnidirectionalStream(_options) {
91
+ const peer = this.#peer;
92
+ if (!peer)
93
+ throw new Error("no peer");
94
+ const c2s = newStream();
95
+ try {
96
+ peer.#uniController.enqueue(c2s.readable);
97
+ }
98
+ catch {
99
+ // Peer closed
100
+ }
101
+ return c2s.writable;
102
+ }
103
+ close(_closeInfo) {
104
+ const info = _closeInfo ?? { closeCode: 0, reason: "" };
105
+ this.#closeResolve(info);
106
+ try {
107
+ this.#bidiController.close();
108
+ }
109
+ catch {
110
+ // Already closed
111
+ }
112
+ try {
113
+ this.#uniController.close();
114
+ }
115
+ catch {
116
+ // Already closed
117
+ }
118
+ // Also close peer's incoming streams
119
+ if (this.#peer) {
120
+ try {
121
+ this.#peer.#bidiController.close();
122
+ }
123
+ catch {
124
+ // Already closed
125
+ }
126
+ try {
127
+ this.#peer.#uniController.close();
128
+ }
129
+ catch {
130
+ // Already closed
131
+ }
132
+ this.#peer.#closeResolve(info);
133
+ }
134
+ }
135
+ // biome-ignore lint/suspicious/noExplicitAny: WebTransportStats type not available in all TS libs
136
+ async getStats() {
137
+ return {};
138
+ }
139
+ }
140
+ /**
141
+ * Creates a pair of connected MockTransport instances.
142
+ *
143
+ * @param protocol - The WebTransport protocol identifier (e.g. "moqt-17", "moql", "")
144
+ * @returns An object containing `client` and `server` transports
145
+ */
146
+ export function createMockTransportPair(protocol = "") {
147
+ const client = new MockTransport(protocol);
148
+ const server = new MockTransport(protocol);
149
+ client.setPeer(server);
150
+ server.setPeer(client);
151
+ return { client, server };
152
+ }
153
+ //# sourceMappingURL=mock.js.map
package/mock.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAE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C;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"]}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@moq/net",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "Media over QUIC networking layer (negotiates moq-lite or moq-transport)",
6
+ "license": "(MIT OR Apache-2.0)",
7
+ "repository": "github:moq-dev/moq",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "default": "./index.js"
13
+ },
14
+ "./zod": {
15
+ "types": "./zod.d.ts",
16
+ "default": "./zod.js"
17
+ }
18
+ },
19
+ "dependencies": {
20
+ "@moq/qmux": "^0.0.6",
21
+ "@moq/signals": "^0.1.6",
22
+ "async-mutex": "^0.5.0"
23
+ },
24
+ "peerDependencies": {
25
+ "zod": "^4.0.0"
26
+ }
27
+ }
package/path.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * A broadcast path that provides safe prefix matching operations.
3
+ *
4
+ * This module provides path-aware operations that respect delimiter boundaries,
5
+ * preventing issues like "foo" matching "foobar".
6
+ *
7
+ * Paths are automatically trimmed of leading and trailing slashes on creation,
8
+ * making all slashes implicit at boundaries.
9
+ * All paths are RELATIVE; you cannot join with a leading slash to make an absolute path.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Creation automatically trims slashes
14
+ * const path1 = Path.from("/foo/bar/");
15
+ * const path2 = Path.from("foo/bar");
16
+ * console.log(path1 === path2); // true
17
+ *
18
+ * // Multiple arguments are joined with "/"
19
+ * const path3 = Path.from("api", "v1", "users");
20
+ * console.log(path3); // "api/v1/users"
21
+ *
22
+ * // Safe prefix matching
23
+ * const base = Path.from("api/v1");
24
+ * console.log(Path.hasPrefix(Path.from("api"), base)); // true
25
+ * console.log(Path.hasPrefix(Path.from("api/v1"), base)); // true
26
+ *
27
+ * const joined = Path.join(base, Path.from("users"));
28
+ * console.log(joined); // "api/v1/users"
29
+ * ```
30
+ */
31
+ export type Valid = string & {
32
+ __brand: "Name";
33
+ };
34
+ export declare function from(...paths: string[]): Valid;
35
+ /**
36
+ * Check if a path has the given prefix, respecting path boundaries.
37
+ *
38
+ * Unlike String.startsWith, this ensures that "foo" does not match "foobar".
39
+ * The prefix must either:
40
+ * - Be exactly equal to the path
41
+ * - Be followed by a '/' delimiter in the original path
42
+ * - Be empty (matches everything)
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const path = Path.from("foo/bar");
47
+ * console.log(Path.hasPrefix(Path.from("foo"), path)); // true
48
+ * console.log(Path.hasPrefix(Path.from("foo/"), path)); // true (trailing slash ignored)
49
+ * console.log(Path.hasPrefix(Path.from("fo"), path)); // false
50
+ *
51
+ * const path2 = Path.from("foobar");
52
+ * console.log(Path.hasPrefix(Path.from("foo"), path2)); // false
53
+ * ```
54
+ */
55
+ export declare function hasPrefix(prefix: Valid, path: Valid): boolean;
56
+ /**
57
+ * Strip the given prefix from a path, returning the suffix.
58
+ *
59
+ * Returns null if the prefix doesn't match according to hasPrefix rules.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const path = Path.from("foo/bar/baz");
64
+ * const suffix = Path.stripPrefix(Path.from("foo"), path);
65
+ * console.log(suffix); // "bar/baz"
66
+ *
67
+ * const suffix2 = Path.stripPrefix(Path.from("foo/"), path);
68
+ * console.log(suffix2); // "bar/baz"
69
+ *
70
+ * const noMatch = Path.stripPrefix(Path.from("notfound"), path);
71
+ * console.log(noMatch); // null
72
+ * ```
73
+ */
74
+ export declare function stripPrefix(prefix: Valid, path: Valid): Valid | null;
75
+ /**
76
+ * Join two path components together.
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const base = Path.from("foo");
81
+ * const joined = Path.join(base, Path.from("bar"));
82
+ * console.log(joined); // "foo/bar"
83
+ * ```
84
+ */
85
+ export declare function join(path: Valid, other: Valid): Valid;
86
+ export declare function empty(): Valid;
87
+ //# sourceMappingURL=path.d.ts.map
package/path.d.ts.map ADDED
@@ -0,0 +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,wBAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAI9C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO,CAgB7D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,CAiBpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CASrD;AAED,wBAAgB,KAAK,IAAI,KAAK,CAE7B"}
package/path.js ADDED
@@ -0,0 +1,98 @@
1
+ export function from(...paths) {
2
+ // Join paths with "/" and then remove leading and trailing slashes, and collapse multiple slashes into one.
3
+ const joined = paths.join("/");
4
+ return joined.replace(/\/+/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
5
+ }
6
+ /**
7
+ * Check if a path has the given prefix, respecting path boundaries.
8
+ *
9
+ * Unlike String.startsWith, this ensures that "foo" does not match "foobar".
10
+ * The prefix must either:
11
+ * - Be exactly equal to the path
12
+ * - Be followed by a '/' delimiter in the original path
13
+ * - Be empty (matches everything)
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const path = Path.from("foo/bar");
18
+ * console.log(Path.hasPrefix(Path.from("foo"), path)); // true
19
+ * console.log(Path.hasPrefix(Path.from("foo/"), path)); // true (trailing slash ignored)
20
+ * console.log(Path.hasPrefix(Path.from("fo"), path)); // false
21
+ *
22
+ * const path2 = Path.from("foobar");
23
+ * console.log(Path.hasPrefix(Path.from("foo"), path2)); // false
24
+ * ```
25
+ */
26
+ export function hasPrefix(prefix, path) {
27
+ if (prefix === "") {
28
+ return true;
29
+ }
30
+ if (!path.startsWith(prefix)) {
31
+ return false;
32
+ }
33
+ // Check if the prefix is the exact match
34
+ if (path.length === prefix.length) {
35
+ return true;
36
+ }
37
+ // Otherwise, ensure the character after the prefix is a delimiter
38
+ return path[prefix.length] === "/";
39
+ }
40
+ /**
41
+ * Strip the given prefix from a path, returning the suffix.
42
+ *
43
+ * Returns null if the prefix doesn't match according to hasPrefix rules.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const path = Path.from("foo/bar/baz");
48
+ * const suffix = Path.stripPrefix(Path.from("foo"), path);
49
+ * console.log(suffix); // "bar/baz"
50
+ *
51
+ * const suffix2 = Path.stripPrefix(Path.from("foo/"), path);
52
+ * console.log(suffix2); // "bar/baz"
53
+ *
54
+ * const noMatch = Path.stripPrefix(Path.from("notfound"), path);
55
+ * console.log(noMatch); // null
56
+ * ```
57
+ */
58
+ export function stripPrefix(prefix, path) {
59
+ if (!hasPrefix(prefix, path)) {
60
+ return null;
61
+ }
62
+ // Handle empty prefix case
63
+ if (prefix === "") {
64
+ return path;
65
+ }
66
+ // If prefix matches exactly, return empty
67
+ if (path.length === prefix.length) {
68
+ return "";
69
+ }
70
+ // For non-empty prefix that's shorter, skip the prefix and the following slash
71
+ return path.slice(prefix.length + 1);
72
+ }
73
+ /**
74
+ * Join two path components together.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const base = Path.from("foo");
79
+ * const joined = Path.join(base, Path.from("bar"));
80
+ * console.log(joined); // "foo/bar"
81
+ * ```
82
+ */
83
+ export function join(path, other) {
84
+ if (path === "") {
85
+ return other;
86
+ }
87
+ else if (other === "") {
88
+ return path;
89
+ }
90
+ else {
91
+ // Since paths are trimmed, we always need to add a slash
92
+ return `${path}/${other}`;
93
+ }
94
+ }
95
+ export function empty() {
96
+ return "";
97
+ }
98
+ //# sourceMappingURL=path.js.map
package/path.js.map ADDED
@@ -0,0 +1 @@
1
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,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAU,CAAC;AAC/C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,IAAI,CAAC,IAAW,EAAE,KAAY;IAC7C,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACd,CAAC;SAAM,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;SAAM,CAAC;QACP,yDAAyD;QACzD,OAAO,GAAG,IAAI,IAAI,KAAK,EAAW,CAAC;IACpC,CAAC;AACF,CAAC;AAED,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\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/**\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\nexport function empty(): Valid {\n\treturn \"\" as Valid;\n}\n"]}
package/path.test.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=path.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.test.d.ts","sourceRoot":"","sources":["../src/path.test.ts"],"names":[],"mappings":""}