@norskvideo/moq-net 0.1.8 → 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 (286) hide show
  1. package/README.md +2 -2
  2. package/announce.d.ts +7 -0
  3. package/announce.d.ts.map +1 -0
  4. package/announce.js +8 -0
  5. package/announce.js.map +1 -0
  6. package/announced.d.ts +49 -91
  7. package/announced.d.ts.map +1 -1
  8. package/announced.js +21 -156
  9. package/announced.js.map +1 -1
  10. package/bandwidth.d.ts +163 -0
  11. package/bandwidth.d.ts.map +1 -0
  12. package/bandwidth.js +304 -0
  13. package/bandwidth.js.map +1 -0
  14. package/bandwidth_api.d.ts +7 -0
  15. package/bandwidth_api.d.ts.map +1 -0
  16. package/bandwidth_api.js +8 -0
  17. package/bandwidth_api.js.map +1 -0
  18. package/broadcast.d.ts +44 -35
  19. package/broadcast.d.ts.map +1 -1
  20. package/broadcast.js +104 -60
  21. package/broadcast.js.map +1 -1
  22. package/connection/accept.d.ts +16 -1
  23. package/connection/accept.d.ts.map +1 -1
  24. package/connection/accept.js +52 -28
  25. package/connection/accept.js.map +1 -1
  26. package/connection/browser.d.ts.map +1 -1
  27. package/connection/browser.js +9 -7
  28. package/connection/browser.js.map +1 -1
  29. package/connection/connect.d.ts +30 -6
  30. package/connection/connect.d.ts.map +1 -1
  31. package/connection/connect.js +110 -54
  32. package/connection/connect.js.map +1 -1
  33. package/connection/established.d.ts +17 -21
  34. package/connection/established.d.ts.map +1 -1
  35. package/connection/established.js.map +1 -1
  36. package/connection/forward.d.ts +2 -0
  37. package/connection/forward.d.ts.map +1 -0
  38. package/connection/forward.js +173 -0
  39. package/connection/forward.js.map +1 -0
  40. package/connection/handshake.d.ts +1 -0
  41. package/connection/handshake.d.ts.map +1 -1
  42. package/connection/handshake.js +5 -2
  43. package/connection/handshake.js.map +1 -1
  44. package/connection/index.d.ts +5 -5
  45. package/connection/index.d.ts.map +1 -1
  46. package/connection/index.js +4 -5
  47. package/connection/index.js.map +1 -1
  48. package/connection/pool.d.ts +186 -0
  49. package/connection/pool.d.ts.map +1 -0
  50. package/connection/pool.js +361 -0
  51. package/connection/pool.js.map +1 -0
  52. package/connection/reload.d.ts +14 -93
  53. package/connection/reload.d.ts.map +1 -1
  54. package/connection/reload.js +217 -81
  55. package/connection/reload.js.map +1 -1
  56. package/connection/stats.d.ts +3 -26
  57. package/connection/stats.d.ts.map +1 -1
  58. package/connection/stats.js.map +1 -1
  59. package/connection/transport.d.ts +0 -7
  60. package/connection/transport.d.ts.map +1 -1
  61. package/consume.d.ts +1 -43
  62. package/consume.d.ts.map +1 -1
  63. package/consume.js +1 -1
  64. package/consume.js.map +1 -1
  65. package/error.d.ts +180 -29
  66. package/error.d.ts.map +1 -1
  67. package/error.js +331 -16
  68. package/error.js.map +1 -1
  69. package/errors.d.ts +7 -0
  70. package/errors.d.ts.map +1 -0
  71. package/errors.js +8 -0
  72. package/errors.js.map +1 -0
  73. package/group.d.ts +9 -43
  74. package/group.d.ts.map +1 -1
  75. package/group.js +284 -69
  76. package/group.js.map +1 -1
  77. package/hop.d.ts +115 -0
  78. package/hop.d.ts.map +1 -0
  79. package/hop.js +119 -0
  80. package/hop.js.map +1 -0
  81. package/ietf/adapter.d.ts +5 -1
  82. package/ietf/adapter.d.ts.map +1 -1
  83. package/ietf/adapter.js +105 -60
  84. package/ietf/adapter.js.map +1 -1
  85. package/ietf/aliases.d.ts +1 -78
  86. package/ietf/aliases.d.ts.map +1 -1
  87. package/ietf/cluster.d.ts +9 -123
  88. package/ietf/cluster.d.ts.map +1 -1
  89. package/ietf/cluster.js +84 -44
  90. package/ietf/cluster.js.map +1 -1
  91. package/ietf/connection.d.ts +6 -72
  92. package/ietf/connection.d.ts.map +1 -1
  93. package/ietf/connection.js +62 -56
  94. package/ietf/connection.js.map +1 -1
  95. package/ietf/error.d.ts +11 -0
  96. package/ietf/error.d.ts.map +1 -0
  97. package/ietf/error.js +193 -0
  98. package/ietf/error.js.map +1 -0
  99. package/ietf/fetch.d.ts +7 -20
  100. package/ietf/fetch.d.ts.map +1 -1
  101. package/ietf/fetch.js +52 -22
  102. package/ietf/fetch.js.map +1 -1
  103. package/ietf/filter.d.ts +2 -0
  104. package/ietf/filter.d.ts.map +1 -1
  105. package/ietf/filter.js +10 -1
  106. package/ietf/filter.js.map +1 -1
  107. package/ietf/goaway.d.ts.map +1 -1
  108. package/ietf/goaway.js +22 -5
  109. package/ietf/goaway.js.map +1 -1
  110. package/ietf/hidden.d.ts +2 -0
  111. package/ietf/hidden.d.ts.map +1 -0
  112. package/ietf/hidden.js +30 -0
  113. package/ietf/hidden.js.map +1 -0
  114. package/ietf/index.d.ts +2 -0
  115. package/ietf/index.d.ts.map +1 -1
  116. package/ietf/index.js +2 -0
  117. package/ietf/index.js.map +1 -1
  118. package/ietf/object.d.ts +15 -8
  119. package/ietf/object.d.ts.map +1 -1
  120. package/ietf/object.js +51 -36
  121. package/ietf/object.js.map +1 -1
  122. package/ietf/parameters.d.ts +14 -2
  123. package/ietf/parameters.d.ts.map +1 -1
  124. package/ietf/parameters.js +97 -29
  125. package/ietf/parameters.js.map +1 -1
  126. package/ietf/properties.d.ts +1 -0
  127. package/ietf/properties.d.ts.map +1 -1
  128. package/ietf/properties.js +14 -0
  129. package/ietf/properties.js.map +1 -1
  130. package/ietf/publish.d.ts +19 -2
  131. package/ietf/publish.d.ts.map +1 -1
  132. package/ietf/publish.js +40 -6
  133. package/ietf/publish.js.map +1 -1
  134. package/ietf/publish_namespace.d.ts +25 -0
  135. package/ietf/publish_namespace.d.ts.map +1 -1
  136. package/ietf/publish_namespace.js +63 -0
  137. package/ietf/publish_namespace.js.map +1 -1
  138. package/ietf/publisher.d.ts +1 -82
  139. package/ietf/publisher.d.ts.map +1 -1
  140. package/ietf/publisher.js +483 -235
  141. package/ietf/publisher.js.map +1 -1
  142. package/ietf/solicit.d.ts +1 -40
  143. package/ietf/solicit.d.ts.map +1 -1
  144. package/ietf/subscribe.d.ts +8 -6
  145. package/ietf/subscribe.d.ts.map +1 -1
  146. package/ietf/subscribe.js +33 -27
  147. package/ietf/subscribe.js.map +1 -1
  148. package/ietf/subscribe_namespace.d.ts +8 -2
  149. package/ietf/subscribe_namespace.d.ts.map +1 -1
  150. package/ietf/subscribe_namespace.js +18 -8
  151. package/ietf/subscribe_namespace.js.map +1 -1
  152. package/ietf/subscriber.d.ts +1 -65
  153. package/ietf/subscriber.d.ts.map +1 -1
  154. package/ietf/subscriber.js +337 -123
  155. package/ietf/subscriber.js.map +1 -1
  156. package/ietf/token.d.ts +2 -0
  157. package/ietf/token.d.ts.map +1 -0
  158. package/ietf/token.js +99 -0
  159. package/ietf/token.js.map +1 -0
  160. package/ietf/track.d.ts +4 -0
  161. package/ietf/track.d.ts.map +1 -1
  162. package/ietf/track.js +6 -20
  163. package/ietf/track.js.map +1 -1
  164. package/ietf/version.d.ts +12 -1
  165. package/ietf/version.d.ts.map +1 -1
  166. package/ietf/version.js +13 -0
  167. package/ietf/version.js.map +1 -1
  168. package/index.d.ts +12 -7
  169. package/index.d.ts.map +1 -1
  170. package/index.js +10 -5
  171. package/index.js.map +1 -1
  172. package/internal.d.ts +115 -1
  173. package/internal.d.ts.map +1 -1
  174. package/internal.js +108 -0
  175. package/internal.js.map +1 -1
  176. package/lite/announce.d.ts +60 -10
  177. package/lite/announce.d.ts.map +1 -1
  178. package/lite/announce.js +176 -31
  179. package/lite/announce.js.map +1 -1
  180. package/lite/connection.d.ts +9 -59
  181. package/lite/connection.d.ts.map +1 -1
  182. package/lite/connection.js +34 -35
  183. package/lite/connection.js.map +1 -1
  184. package/lite/datagram.d.ts +3 -2
  185. package/lite/datagram.d.ts.map +1 -1
  186. package/lite/datagram.js +7 -8
  187. package/lite/datagram.js.map +1 -1
  188. package/lite/fetch.d.ts +15 -1
  189. package/lite/fetch.d.ts.map +1 -1
  190. package/lite/fetch.js +39 -7
  191. package/lite/fetch.js.map +1 -1
  192. package/lite/goaway.d.ts.map +1 -1
  193. package/lite/goaway.js +7 -1
  194. package/lite/goaway.js.map +1 -1
  195. package/lite/group.d.ts +30 -12
  196. package/lite/group.d.ts.map +1 -1
  197. package/lite/group.js +68 -26
  198. package/lite/group.js.map +1 -1
  199. package/lite/message.d.ts +2 -2
  200. package/lite/message.d.ts.map +1 -1
  201. package/lite/message.js +14 -5
  202. package/lite/message.js.map +1 -1
  203. package/lite/priority.d.ts +1 -61
  204. package/lite/priority.d.ts.map +1 -1
  205. package/lite/priority.js +4 -5
  206. package/lite/priority.js.map +1 -1
  207. package/lite/publisher.d.ts +1 -69
  208. package/lite/publisher.d.ts.map +1 -1
  209. package/lite/publisher.js +630 -262
  210. package/lite/publisher.js.map +1 -1
  211. package/lite/setup.d.ts +8 -8
  212. package/lite/setup.d.ts.map +1 -1
  213. package/lite/setup.js +33 -30
  214. package/lite/setup.js.map +1 -1
  215. package/lite/subscribe.d.ts +71 -17
  216. package/lite/subscribe.d.ts.map +1 -1
  217. package/lite/subscribe.js +205 -53
  218. package/lite/subscribe.js.map +1 -1
  219. package/lite/subscriber.d.ts +15 -56
  220. package/lite/subscriber.d.ts.map +1 -1
  221. package/lite/subscriber.js +451 -247
  222. package/lite/subscriber.js.map +1 -1
  223. package/lite/track.d.ts +4 -10
  224. package/lite/track.d.ts.map +1 -1
  225. package/lite/track.js +34 -29
  226. package/lite/track.js.map +1 -1
  227. package/lite/version.d.ts +42 -6
  228. package/lite/version.d.ts.map +1 -1
  229. package/lite/version.js +126 -10
  230. package/lite/version.js.map +1 -1
  231. package/origin.d.ts +256 -29
  232. package/origin.d.ts.map +1 -1
  233. package/origin.js +1427 -37
  234. package/origin.js.map +1 -1
  235. package/package.json +8 -3
  236. package/path.d.ts +25 -7
  237. package/path.d.ts.map +1 -1
  238. package/path.js +5 -3
  239. package/path.js.map +1 -1
  240. package/stream.d.ts +73 -14
  241. package/stream.d.ts.map +1 -1
  242. package/stream.js +372 -141
  243. package/stream.js.map +1 -1
  244. package/tail.d.ts +18 -0
  245. package/tail.d.ts.map +1 -0
  246. package/tail.js +167 -0
  247. package/tail.js.map +1 -0
  248. package/time.d.ts +15 -2
  249. package/time.d.ts.map +1 -1
  250. package/time.js +28 -9
  251. package/time.js.map +1 -1
  252. package/track.d.ts +211 -83
  253. package/track.d.ts.map +1 -1
  254. package/track.js +816 -205
  255. package/track.js.map +1 -1
  256. package/util/abort.d.ts +2 -0
  257. package/util/abort.d.ts.map +1 -0
  258. package/util/abort.js +20 -0
  259. package/util/abort.js.map +1 -0
  260. package/util/log.d.ts +5 -0
  261. package/util/log.d.ts.map +1 -0
  262. package/util/log.js +17 -0
  263. package/util/log.js.map +1 -0
  264. package/util/u64.d.ts +39 -0
  265. package/util/u64.d.ts.map +1 -0
  266. package/util/u64.js +83 -0
  267. package/util/u64.js.map +1 -0
  268. package/util/varint.d.ts +29 -0
  269. package/util/varint.d.ts.map +1 -0
  270. package/util/varint.js +198 -0
  271. package/util/varint.js.map +1 -0
  272. package/varint.d.ts +10 -6
  273. package/varint.d.ts.map +1 -1
  274. package/varint.js +40 -237
  275. package/varint.js.map +1 -1
  276. package/wire.d.ts +80 -0
  277. package/wire.d.ts.map +1 -0
  278. package/wire.js +32 -0
  279. package/wire.js.map +1 -0
  280. package/zod.d.ts +1 -1
  281. package/zod.d.ts.map +1 -1
  282. package/zod.js.map +1 -1
  283. package/mock.d.ts +0 -66
  284. package/mock.d.ts.map +0 -1
  285. package/mock.js +0 -243
  286. package/mock.js.map +0 -1
package/varint.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"varint.js","sourceRoot":"","sources":["../src/varint.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO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CAAC,CAAC;AAChC,CAAC","sourcesContent":["/**\n * QUIC variable-length integer encoding and decoding.\n * https://www.rfc-editor.org/rfc/rfc9000#section-16\n *\n * @module\n */\n\n/** Largest value that fits in a 1-byte varint (6 bits). */\nexport const MAX_U6 = 2 ** 6 - 1;\n/** Largest value that fits in a 2-byte varint (14 bits). */\nexport const MAX_U14 = 2 ** 14 - 1;\n/** Largest value that fits in a 4-byte varint (30 bits). */\nexport const MAX_U30 = 2 ** 30 - 1;\n/** Largest value representable without precision loss (`Number.MAX_SAFE_INTEGER`, 53 bits). */\nexport const MAX_U53 = Number.MAX_SAFE_INTEGER;\n\n// Leading-ones varint encoding/decoding (draft-17 Section 1.4.1)\n// Encoding scheme:\n// 0xxxxxxx → 1 byte (7 bits)\n// 10xxxxxx + 1B → 2 bytes (14 bits)\n// 110xxxxx + 2B → 3 bytes (21 bits)\n// 1110xxxx + 3B → 4 bytes (28 bits)\n// 11110xxx + 4B → 5 bytes (35 bits)\n// 111110xx + 5B → 6 bytes (42 bits)\n// 1111110x + 6B → 7 bytes (49 bits), draft-18+ only (invalid in draft-17 per #1595)\n// 11111110 + 7B → 8 bytes (56 bits)\n// 11111111 + 8B → 9 bytes (64 bits)\n\nconst MAX_U64 = (1n << 64n) - 1n;\n\n/** Number of bytes needed to encode a value in the leading-ones varint format. */\nexport function sizeLeadingOnes(v: number | bigint): number {\n\tconst b = BigInt(v);\n\tif (b < 0n) throw new RangeError(`value is negative: ${v}`);\n\tif (b > MAX_U64) throw new RangeError(`value exceeds 64 bits: ${v}`);\n\tif (b < 1n << 7n) return 1;\n\tif (b < 1n << 14n) return 2;\n\tif (b < 1n << 21n) return 3;\n\tif (b < 1n << 28n) return 4;\n\tif (b < 1n << 35n) return 5;\n\tif (b < 1n << 42n) return 6;\n\tif (b < 1n << 56n) return 8;\n\treturn 9;\n}\n\n/** Encode a value in leading-ones varint format into the provided buffer, returning the written subarray. */\nexport function encodeLeadingOnesTo(dst: ArrayBuffer, v: number | bigint): Uint8Array {\n\tconst x = BigInt(v);\n\tif (x < 0n) throw new RangeError(`underflow, value is negative: ${v}`);\n\tif (x > MAX_U64) throw new RangeError(`value exceeds 64 bits: ${v}`);\n\n\tconst view = new DataView(dst);\n\n\tif (x < 1n << 7n) {\n\t\tview.setUint8(0, Number(x));\n\t\treturn new Uint8Array(dst, 0, 1);\n\t}\n\tif (x < 1n << 14n) {\n\t\tview.setUint8(0, 0x80 | Number(x >> 8n));\n\t\tview.setUint8(1, Number(x & 0xffn));\n\t\treturn new Uint8Array(dst, 0, 2);\n\t}\n\tif (x < 1n << 21n) {\n\t\tview.setUint8(0, 0xc0 | Number(x >> 16n));\n\t\tview.setUint16(1, Number(x & 0xffffn));\n\t\treturn new Uint8Array(dst, 0, 3);\n\t}\n\tif (x < 1n << 28n) {\n\t\tview.setUint8(0, 0xe0 | Number(x >> 24n));\n\t\tview.setUint8(1, Number((x >> 16n) & 0xffn));\n\t\tview.setUint16(2, Number(x & 0xffffn));\n\t\treturn new Uint8Array(dst, 0, 4);\n\t}\n\tif (x < 1n << 35n) {\n\t\tview.setUint8(0, 0xf0 | Number(x >> 32n));\n\t\tview.setUint32(1, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 5);\n\t}\n\tif (x < 1n << 42n) {\n\t\tview.setUint8(0, 0xf8 | Number(x >> 40n));\n\t\tview.setUint8(1, Number((x >> 32n) & 0xffn));\n\t\tview.setUint32(2, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 6);\n\t}\n\tif (x < 1n << 56n) {\n\t\t// 11111110 + 7 bytes\n\t\tview.setUint8(0, 0xfe);\n\t\tview.setUint8(1, Number((x >> 48n) & 0xffn));\n\t\tview.setUint16(2, Number((x >> 32n) & 0xffffn));\n\t\tview.setUint32(4, Number(x & 0xffffffffn));\n\t\treturn new Uint8Array(dst, 0, 8);\n\t}\n\t// 11111111 + 8 bytes\n\tview.setUint8(0, 0xff);\n\tview.setBigUint64(1, x);\n\treturn new Uint8Array(dst, 0, 9);\n}\n\n/** Encode a value in leading-ones varint format into a freshly allocated buffer. */\nexport function encodeLeadingOnes(v: number | bigint): Uint8Array {\n\treturn encodeLeadingOnesTo(new ArrayBuffer(9), v);\n}\n\n/** Decode a leading-ones varint, returning the value and the remaining buffer. */\nexport function decodeLeadingOnes(buf: Uint8Array): [bigint, Uint8Array] {\n\tif (buf.length === 0) throw new Error(\"buffer is empty\");\n\n\tconst b = buf[0];\n\t// Count leading 1-bits\n\tlet ones = 0;\n\tfor (let bit = 7; bit >= 0; bit--) {\n\t\tif (b & (1 << bit)) ones++;\n\t\telse break;\n\t}\n\n\t// 1111110x is a 7-byte form: invalid on draft-17, allowed on draft-18+ per #1595.\n\t// This standalone decoder is permissive (Postel-style) since we lack version context here.\n\n\tlet totalSize: number;\n\tif (ones <= 5) totalSize = ones + 1;\n\telse if (ones === 6) totalSize = 7;\n\telse if (ones === 7) totalSize = 8;\n\telse totalSize = 9; // ones === 8\n\n\tif (buf.length < totalSize) {\n\t\tthrow new Error(`buffer too short: need ${totalSize} bytes, have ${buf.length}`);\n\t}\n\n\tconst view = new DataView(buf.buffer, buf.byteOffset, totalSize);\n\tconst remain = buf.subarray(totalSize);\n\tlet value: bigint;\n\n\tswitch (ones) {\n\t\tcase 0:\n\t\t\tvalue = BigInt(b);\n\t\t\tbreak;\n\t\tcase 1:\n\t\t\tvalue = (BigInt(b & 0x3f) << 8n) | BigInt(buf[1]);\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tvalue = (BigInt(b & 0x1f) << 16n) | BigInt(view.getUint16(1));\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tvalue = (BigInt(b & 0x0f) << 24n) | (BigInt(buf[1]) << 16n) | (BigInt(buf[2]) << 8n) | BigInt(buf[3]);\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tvalue = (BigInt(b & 0x07) << 32n) | BigInt(view.getUint32(1));\n\t\t\tbreak;\n\t\tcase 5:\n\t\t\tvalue =\n\t\t\t\t(BigInt(b & 0x03) << 40n) |\n\t\t\t\t(BigInt(buf[1]) << 32n) |\n\t\t\t\t(BigInt(buf[2]) << 24n) |\n\t\t\t\t(BigInt(buf[3]) << 16n) |\n\t\t\t\t(BigInt(buf[4]) << 8n) |\n\t\t\t\tBigInt(buf[5]);\n\t\t\tbreak;\n\t\tcase 6: {\n\t\t\t// 1111110x + 6 bytes = 49 bits (draft-18+)\n\t\t\tvalue =\n\t\t\t\t(BigInt(b & 0x01) << 48n) |\n\t\t\t\t(BigInt(buf[1]) << 40n) |\n\t\t\t\t(BigInt(buf[2]) << 32n) |\n\t\t\t\t(BigInt(buf[3]) << 24n) |\n\t\t\t\t(BigInt(buf[4]) << 16n) |\n\t\t\t\t(BigInt(buf[5]) << 8n) |\n\t\t\t\tBigInt(buf[6]);\n\t\t\tbreak;\n\t\t}\n\t\tcase 7: {\n\t\t\t// 11111110 + 7 bytes = 56 usable bits\n\t\t\tconst hi = new Uint8Array(8);\n\t\t\thi[0] = 0;\n\t\t\thi.set(buf.subarray(1, 8), 1);\n\t\t\tvalue = new DataView(hi.buffer).getBigUint64(0);\n\t\t\tbreak;\n\t\t}\n\t\tcase 8: {\n\t\t\t// 11111111 + 8 bytes = 64 bits\n\t\t\tvalue = new DataView(buf.buffer, buf.byteOffset + 1, 8).getBigUint64(0);\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(\"impossible\");\n\t}\n\n\treturn [value, remain];\n}\n\n/**\n * Returns the number of bytes needed to encode a value as a varint.\n */\nexport function size(v: number): number {\n\tif (v <= MAX_U6) return 1;\n\tif (v <= MAX_U14) return 2;\n\tif (v <= MAX_U30) return 4;\n\tif (v <= MAX_U53) return 8;\n\tthrow new Error(`overflow, value larger than 53-bits: ${v}`);\n}\n\n// Helper functions for writing to an ArrayBuffer\nfunction setUint8(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst buffer = new Uint8Array(dst, 0, 1);\n\tbuffer[0] = v;\n\treturn buffer;\n}\n\nfunction setUint16(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 2);\n\tview.setUint16(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setUint32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setUint32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setUint64(dst: ArrayBuffer, v: bigint): Uint8Array {\n\tconst view = new DataView(dst, 0, 8);\n\tview.setBigUint64(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nconst MAX_U62 = 2n ** 62n - 1n;\n\n/**\n * Encodes a number or bigint into a scratch buffer.\n * Used by stream.ts to avoid allocations.\n */\nexport function encodeTo(dst: ArrayBuffer, v: number | bigint): Uint8Array {\n\tconst b = BigInt(v);\n\tif (b < 0n) {\n\t\tthrow new Error(`underflow, value is negative: ${v}`);\n\t}\n\tif (b > MAX_U62) {\n\t\tthrow new Error(`overflow, value larger than 62-bits: ${v}`);\n\t}\n\tconst n = Number(b);\n\tif (n <= MAX_U6) {\n\t\treturn setUint8(dst, n);\n\t}\n\tif (n <= MAX_U14) {\n\t\treturn setUint16(dst, n | 0x4000);\n\t}\n\tif (n <= MAX_U30) {\n\t\treturn setUint32(dst, n | 0x80000000);\n\t}\n\treturn setUint64(dst, b | 0xc000000000000000n);\n}\n\n/**\n * Encodes a number or bigint as a QUIC variable-length integer.\n * Returns a new Uint8Array containing the encoded bytes.\n */\nexport function encode(v: number | bigint): Uint8Array {\n\treturn encodeTo(new ArrayBuffer(8), v);\n}\n\n/**\n * Decodes a QUIC variable-length integer exactly from a buffer.\n * Returns a tuple of [value, remaining buffer].\n */\nexport function decodeBigInt(buf: Uint8Array): [bigint, Uint8Array] {\n\tif (buf.length === 0) {\n\t\tthrow new Error(\"buffer is empty\");\n\t}\n\n\tconst size = 1 << ((buf[0] & 0xc0) >> 6);\n\n\tif (buf.length < size) {\n\t\tthrow new Error(`buffer too short: need ${size} bytes, have ${buf.length}`);\n\t}\n\n\tconst view = new DataView(buf.buffer, buf.byteOffset, size);\n\tconst remain = buf.subarray(size);\n\n\tlet value: bigint;\n\n\tif (size === 1) {\n\t\tvalue = BigInt(buf[0] & 0x3f);\n\t} else if (size === 2) {\n\t\tvalue = BigInt(view.getUint16(0) & 0x3fff);\n\t} else if (size === 4) {\n\t\tvalue = BigInt(view.getUint32(0) & 0x3fffffff);\n\t} else if (size === 8) {\n\t\tvalue = view.getBigUint64(0) & 0x3fffffffffffffffn;\n\t} else {\n\t\tthrow new Error(\"impossible\");\n\t}\n\n\treturn [value, remain];\n}\n\n/**\n * Decodes a QUIC variable-length integer from a buffer.\n * Values above 53 bits lose precision; use {@link decodeBigInt} for exact decoding.\n */\nexport function decode(buf: Uint8Array): [number, Uint8Array] {\n\tconst [value, remain] = decodeBigInt(buf);\n\treturn [Number(value), remain];\n}\n"]}
1
+ {"version":3,"file":"varint.js","sourceRoot":"","sources":["../src/varint.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACN,iBAAiB,EACjB,UAAU,EACV,KAAK,EACL,eAAe,EACf,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,KAAK,EACL,gBAAgB,EAChB,SAAS,GACT,MAAM,kBAAkB,CAAC;AAE1B,2DAA2D;AAC3D,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACnC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,gBAA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AAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAe;IACrC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/**\n * Variable-length integers: QUIC's (RFC 9000 Section 16) and moq-transport's leading-ones form.\n * https://www.rfc-editor.org/rfc/rfc9000#section-16\n *\n * @module\n */\n\nimport { toBigInt, toNumber } from \"./util/u64.ts\";\nimport {\n\tlengthLeadingOnes,\n\tlengthQuic,\n\tparts,\n\tpeekLeadingOnes,\n\tpeekQuic,\n\treadLeadingOnes,\n\treadQuic,\n\tsplit,\n\twriteLeadingOnes,\n\twriteQuic,\n} from \"./util/varint.ts\";\n\n/** Largest value that fits in a 1-byte varint (6 bits). */\nexport const MAX_U6 = 2 ** 6 - 1;\n/** Largest value that fits in a 2-byte varint (14 bits). */\nexport const MAX_U14 = 2 ** 14 - 1;\n/** Largest value that fits in a 4-byte varint (30 bits). */\nexport const MAX_U30 = 2 ** 30 - 1;\n/** Largest value representable without precision loss (`Number.MAX_SAFE_INTEGER`, 53 bits). */\nexport const MAX_U53 = Number.MAX_SAFE_INTEGER;\n\n// The size of the varint at the start of `buf`, throwing unless all of it is there.\nfunction sizeOf(buf: Uint8Array, size: (first: number) => number): number {\n\tif (buf.length === 0) throw new Error(\"buffer is empty\");\n\tconst n = size(buf[0]);\n\tif (buf.length < n) throw new Error(`buffer too short: need ${n} bytes, have ${buf.length}`);\n\treturn n;\n}\n\n/** Number of bytes needed to encode a value in the leading-ones varint format. */\nexport function sizeLeadingOnes(v: number | bigint): number {\n\tconst lo = split(v);\n\treturn lengthLeadingOnes(parts.hi, lo);\n}\n\n/** Encode a value in leading-ones varint format into the provided buffer, returning the written subarray. */\nexport function encodeLeadingOnesTo(dst: ArrayBuffer, v: number | bigint): Uint8Array {\n\tconst lo = split(v);\n\tconst buf = new Uint8Array(dst, 0, lengthLeadingOnes(parts.hi, lo));\n\twriteLeadingOnes(buf, parts.hi, lo, buf.length);\n\treturn buf;\n}\n\n/** Encode a value in leading-ones varint format into a freshly allocated buffer. */\nexport function encodeLeadingOnes(v: number | bigint): Uint8Array {\n\treturn encodeLeadingOnesTo(new ArrayBuffer(9), v);\n}\n\n/**\n * Decode a leading-ones varint, returning the value and the remaining buffer.\n *\n * Accepts the 7-byte form, which only draft-18+ allows, since there is no version here to check.\n */\nexport function decodeLeadingOnes(buf: Uint8Array): [bigint, Uint8Array] {\n\tconst size = sizeOf(buf, peekLeadingOnes);\n\tconst lo = readLeadingOnes(buf, 0, size);\n\treturn [toBigInt(parts.hi, lo), buf.subarray(size)];\n}\n\n/**\n * Returns the number of bytes needed to encode a value as a varint.\n */\nexport function size(v: number): number {\n\tif (v <= MAX_U6) return 1;\n\tif (v <= MAX_U14) return 2;\n\tif (v <= MAX_U30) return 4;\n\tif (v <= MAX_U53) return 8;\n\tthrow new Error(`overflow, value larger than 53-bits: ${v}`);\n}\n\n/**\n * Encodes a value as a QUIC variable-length integer into the provided buffer,\n * returning the written subarray.\n */\nexport function encodeTo(dst: ArrayBuffer, v: number | bigint): Uint8Array {\n\tconst lo = split(v);\n\tconst buf = new Uint8Array(dst, 0, lengthQuic(parts.hi, lo));\n\twriteQuic(buf, parts.hi, lo, buf.length);\n\treturn buf;\n}\n\n/**\n * Encodes a value as a QUIC variable-length integer.\n * Returns a new Uint8Array containing the encoded bytes.\n */\nexport function encode(v: number | bigint): Uint8Array {\n\treturn encodeTo(new ArrayBuffer(8), v);\n}\n\n/**\n * Decodes a QUIC variable-length integer exactly from a buffer.\n * Returns a tuple of [value, remaining buffer].\n */\nexport function decodeBigInt(buf: Uint8Array): [bigint, Uint8Array] {\n\tconst size = sizeOf(buf, peekQuic);\n\tconst lo = readQuic(buf, 0, size);\n\treturn [toBigInt(parts.hi, lo), buf.subarray(size)];\n}\n\n/**\n * Decodes a QUIC variable-length integer from a buffer.\n * Throws above `Number.MAX_SAFE_INTEGER` rather than rounding; use {@link decodeBigInt} for those.\n */\nexport function decode(buf: Uint8Array): [number, Uint8Array] {\n\tconst size = sizeOf(buf, peekQuic);\n\tconst lo = readQuic(buf, 0, size);\n\treturn [toNumber(parts.hi, lo), buf.subarray(size)];\n}\n"]}
package/wire.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Package-private capabilities used by the protocol implementations.
3
+ *
4
+ * Public handles register their wire view when they are constructed. Keeping the view in a
5
+ * WeakMap means applications cannot call transport-facing operations on the handles they own,
6
+ * while the protocol layers still share one implementation.
7
+ *
8
+ * @module
9
+ */
10
+ import type { Dispose, Getter } from "@norskvideo/moq-signals";
11
+ import type * as broadcast from "./broadcast";
12
+ import type { Consumer as GroupConsumer } from "./group";
13
+ import type { Route } from "./hop";
14
+ import type * as origin from "./origin";
15
+ import type * as Path from "./path";
16
+ import type * as track from "./track";
17
+ /** The protocol-facing operations behind a broadcast handle. */
18
+ export interface Broadcast {
19
+ subscribe(name: string, options?: track.Subscription): track.Subscriber;
20
+ resolveTrackInfo(name: string): Promise<track.Info>;
21
+ fetchGroup(name: string, sequence: number, options?: track.FetchGroupOptions): Promise<GroupConsumer>;
22
+ requested(): Promise<track.Request | undefined>;
23
+ }
24
+ /** The protocol-facing operations behind an origin producer. */
25
+ export interface OriginProducer {
26
+ /** Minimal root-relative namespace prefixes that cover this origin scope. */
27
+ interests(): readonly Path.Valid[];
28
+ /** Whether an advertised prefix overlaps the handle's allowed paths. */
29
+ accepts(prefix: Path.Valid): boolean;
30
+ receive(prefix: Path.Valid, route?: Route | {
31
+ hops?: Route["hops"];
32
+ cost?: Route["cost"] | bigint;
33
+ }): origin.Dynamic;
34
+ attach(discovery: boolean): Dispose;
35
+ expect(): Dispose;
36
+ readonly requests: Getter<ReadonlyMap<Path.Valid, origin.RequestSlot> | undefined>;
37
+ changed(): Promise<unknown>;
38
+ answer(path: Path.Valid, front: broadcast.Consumer): Dispose | undefined;
39
+ routes(path: Path.Valid): boolean;
40
+ }
41
+ /** The protocol-facing operations behind an origin consumer. */
42
+ export interface OriginConsumer {
43
+ routes(path: Path.Valid): boolean;
44
+ readonly broadcasts: Getter<ReadonlyMap<Path.Valid, broadcast.Consumer> | undefined>;
45
+ readonly advertised: Getter<Advertisements | undefined>;
46
+ /** The announced local broadcast at `path`, when it is the route peers are offered there. */
47
+ local(path: Path.Valid): broadcast.Consumer | undefined;
48
+ demand(path: Path.Valid): Promise<broadcast.Consumer | undefined>;
49
+ }
50
+ /** One originated advertisement exposed to the publishing wire. */
51
+ export interface Advertised {
52
+ readonly identity: object;
53
+ readonly route: Route;
54
+ /** The paths a scoped route may serve beneath its prefix, relative like its key; unset for the whole subtree. */
55
+ readonly claim?: Path.Patterns;
56
+ }
57
+ /**
58
+ * Every originated advertisement per prefix, most preferred first. A reader takes the first
59
+ * one its scope admits, so a cheaper route it cannot use never hides one it can.
60
+ */
61
+ export type Advertisements = ReadonlyMap<Path.Valid, readonly Advertised[]>;
62
+ /** The protocol-facing operation behind an established session. */
63
+ export interface Established {
64
+ consume(path: Path.Valid): broadcast.Consumer;
65
+ }
66
+ type View = Broadcast | OriginProducer | OriginConsumer | Established;
67
+ /** Register the package-private view for a handle. */
68
+ export declare function registerWire(handle: object, view: View): void;
69
+ /** Replace selected operations on a broadcast's package-private view. */
70
+ export declare function overrideBroadcastWire(handle: broadcast.Consumer, overrides: Partial<Pick<Broadcast, "resolveTrackInfo" | "fetchGroup">>): void;
71
+ export declare function wireOf(handle: broadcast.Producer | broadcast.Consumer): Broadcast;
72
+ export declare function wireOf(handle: origin.Producer): OriginProducer;
73
+ export declare function wireOf(handle: origin.Consumer): OriginConsumer;
74
+ export declare function wireOf(handle: import("./connection/established.ts").Established): Established;
75
+ /** Install the private Track.Consumer constructor. */
76
+ export declare function registerTrackConsumer(factory: (name: string, source: Broadcast) => track.Consumer): void;
77
+ /** Create a track handle backed by a broadcast's private wire view. */
78
+ export declare function trackOf(name: string, source: broadcast.Producer | broadcast.Consumer): track.Consumer;
79
+ export {};
80
+ //# sourceMappingURL=wire.d.ts.map
package/wire.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,KAAK,SAAS,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AAEzC,gEAAgE;AAChE,MAAM,WAAW,SAAS;IACzB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC;IACxE,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpD,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC,iB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AE,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAC;AAChE,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAC;AAChE,wBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,6BAA6B,EAAE,WAAW,GAAG,WAAW,CAAC;AAU/F,sDAAsD;AACtD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,KAAK,KAAK,CAAC,QAAQ,GAAG,IAAI,CAExG;AAED,uEAAuE;AACvE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAGrG"}
package/wire.js ADDED
@@ -0,0 +1,32 @@
1
+ /* @ts-self-types="./wire.d.ts" */
2
+ const views = new WeakMap();
3
+ /** Register the package-private view for a handle. */
4
+ export function registerWire(handle, view) {
5
+ views.set(handle, view);
6
+ }
7
+ /** Replace selected operations on a broadcast's package-private view. */
8
+ export function overrideBroadcastWire(handle, overrides) {
9
+ const view = views.get(handle);
10
+ if (!view)
11
+ throw new Error("broadcast has no wire view");
12
+ views.set(handle, { ...view, ...overrides });
13
+ }
14
+ /** Return the package-private view for a handle. */
15
+ export function wireOf(handle) {
16
+ const view = views.get(handle);
17
+ if (!view)
18
+ throw new Error("handle has no wire view");
19
+ return view;
20
+ }
21
+ let makeTrack;
22
+ /** Install the private Track.Consumer constructor. */
23
+ export function registerTrackConsumer(factory) {
24
+ makeTrack = factory;
25
+ }
26
+ /** Create a track handle backed by a broadcast's private wire view. */
27
+ export function trackOf(name, source) {
28
+ if (!makeTrack)
29
+ throw new Error("track module is not loaded");
30
+ return makeTrack(name, wireOf(source));
31
+ }
32
+ //# sourceMappingURL=wire.js.map
package/wire.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAyEA,MAAM,KAAK,GAAG,IAAI,OAAO,EAAgB,CAAC;AAE1C,sDAAsD;AACtD,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,IAAU;IACtD,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,qBAAqB,CACpC,MAA0B,EAC1B,SAAsE;IAEtE,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACzD,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,GAAI,IAAkB,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;AAC7D,CAAC;AAMD,oDAAoD;AACpD,MAAM,UAAU,MAAM,CAAC,MAAc;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACtD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,IAAI,SAA4E,CAAC;AAEjF,sDAAsD;AACtD,MAAM,UAAU,qBAAqB,CAAC,OAA4D;IACjG,SAAS,GAAG,OAAO,CAAC;AACrB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,MAA+C;IACpF,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC9D,OAAO,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AACxC,CAAC","sourcesContent":["/**\n * Package-private capabilities used by the protocol implementations.\n *\n * Public handles register their wire view when they are constructed. Keeping the view in a\n * WeakMap means applications cannot call transport-facing operations on the handles they own,\n * while the protocol layers still share one implementation.\n *\n * @module\n */\nimport type { Dispose, Getter } from \"@moq/signals\";\nimport type * as broadcast from \"./broadcast.ts\";\nimport type { Consumer as GroupConsumer } from \"./group.ts\";\nimport type { Route } from \"./hop.ts\";\nimport type * as origin from \"./origin.ts\";\nimport type * as Path from \"./path.ts\";\nimport type * as track from \"./track.ts\";\n\n/** The protocol-facing operations behind a broadcast handle. */\nexport interface Broadcast {\n\tsubscribe(name: string, options?: track.Subscription): track.Subscriber;\n\tresolveTrackInfo(name: string): Promise<track.Info>;\n\tfetchGroup(name: string, sequence: number, options?: track.FetchGroupOptions): Promise<GroupConsumer>;\n\trequested(): Promise<track.Request | undefined>;\n}\n\n/** The protocol-facing operations behind an origin producer. */\nexport interface OriginProducer {\n\t/** Minimal root-relative namespace prefixes that cover this origin scope. */\n\tinterests(): readonly Path.Valid[];\n\t/** Whether an advertised prefix overlaps the handle's allowed paths. */\n\taccepts(prefix: Path.Valid): boolean;\n\treceive(\n\t\tprefix: Path.Valid,\n\t\troute?: Route | { hops?: Route[\"hops\"]; cost?: Route[\"cost\"] | bigint },\n\t): origin.Dynamic;\n\tattach(discovery: boolean): Dispose;\n\texpect(): Dispose;\n\treadonly requests: Getter<ReadonlyMap<Path.Valid, origin.RequestSlot> | undefined>;\n\tchanged(): Promise<unknown>;\n\tanswer(path: Path.Valid, front: broadcast.Consumer): Dispose | undefined;\n\troutes(path: Path.Valid): boolean;\n}\n\n/** The protocol-facing operations behind an origin consumer. */\nexport interface OriginConsumer {\n\troutes(path: Path.Valid): boolean;\n\treadonly broadcasts: Getter<ReadonlyMap<Path.Valid, broadcast.Consumer> | undefined>;\n\treadonly advertised: Getter<Advertisements | undefined>;\n\t/** The announced local broadcast at `path`, when it is the route peers are offered there. */\n\tlocal(path: Path.Valid): broadcast.Consumer | undefined;\n\tdemand(path: Path.Valid): Promise<broadcast.Consumer | undefined>;\n}\n\n/** One originated advertisement exposed to the publishing wire. */\nexport interface Advertised {\n\treadonly identity: object;\n\treadonly route: Route;\n\t/** The paths a scoped route may serve beneath its prefix, relative like its key; unset for the whole subtree. */\n\treadonly claim?: Path.Patterns;\n}\n\n/**\n * Every originated advertisement per prefix, most preferred first. A reader takes the first\n * one its scope admits, so a cheaper route it cannot use never hides one it can.\n */\nexport type Advertisements = ReadonlyMap<Path.Valid, readonly Advertised[]>;\n\n/** The protocol-facing operation behind an established session. */\nexport interface Established {\n\tconsume(path: Path.Valid): broadcast.Consumer;\n}\n\ntype View = Broadcast | OriginProducer | OriginConsumer | Established;\nconst views = new WeakMap<object, View>();\n\n/** Register the package-private view for a handle. */\nexport function registerWire(handle: object, view: View): void {\n\tviews.set(handle, view);\n}\n\n/** Replace selected operations on a broadcast's package-private view. */\nexport function overrideBroadcastWire(\n\thandle: broadcast.Consumer,\n\toverrides: Partial<Pick<Broadcast, \"resolveTrackInfo\" | \"fetchGroup\">>,\n): void {\n\tconst view = views.get(handle);\n\tif (!view) throw new Error(\"broadcast has no wire view\");\n\tviews.set(handle, { ...(view as Broadcast), ...overrides });\n}\n\nexport function wireOf(handle: broadcast.Producer | broadcast.Consumer): Broadcast;\nexport function wireOf(handle: origin.Producer): OriginProducer;\nexport function wireOf(handle: origin.Consumer): OriginConsumer;\nexport function wireOf(handle: import(\"./connection/established.ts\").Established): Established;\n/** Return the package-private view for a handle. */\nexport function wireOf(handle: object): View {\n\tconst view = views.get(handle);\n\tif (!view) throw new Error(\"handle has no wire view\");\n\treturn view;\n}\n\nlet makeTrack: ((name: string, source: Broadcast) => track.Consumer) | undefined;\n\n/** Install the private Track.Consumer constructor. */\nexport function registerTrackConsumer(factory: (name: string, source: Broadcast) => track.Consumer): void {\n\tmakeTrack = factory;\n}\n\n/** Create a track handle backed by a broadcast's private wire view. */\nexport function trackOf(name: string, source: broadcast.Producer | broadcast.Consumer): track.Consumer {\n\tif (!makeTrack) throw new Error(\"track module is not loaded\");\n\treturn makeTrack(name, wireOf(source));\n}\n"]}
package/zod.d.ts CHANGED
@@ -7,7 +7,7 @@ import type * as z from "zod/mini";
7
7
  import type * as group from "./group";
8
8
  import type * as track from "./track";
9
9
  /** Read the next JSON frame and validate it against the schema. Returns undefined at end of stream. */
10
- export declare function read<T = unknown>(source: track.Subscriber | group.Consumer, schema: z.ZodMiniType<T>): Promise<T | undefined>;
10
+ export declare function read<T = unknown>(source: track.Ordered | group.Consumer, schema: z.ZodMiniType<T>): Promise<T | undefined>;
11
11
  /** Validate a value against the schema, then write it as a JSON frame. */
12
12
  export declare function write<T = unknown>(source: track.Producer | group.Producer, value: T, schema: z.ZodMiniType<T>): void;
13
13
  //# sourceMappingURL=zod.d.ts.map
package/zod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,CAAC,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AAEzC,uGAAuG;AACvG,wBAAsB,IAAI,CAAC,CAAC,GAAG,OAAO,EACrC,MAAM,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,QAAQ,EACzC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAIxB;AAED,0EAA0E;AAC1E,wBAAgB,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAG7G"}
1
+ {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,CAAC,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AAEzC,uGAAuG;AACvG,wBAAsB,IAAI,CAAC,CAAC,GAAG,OAAO,EACrC,MAAM,EAAE,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,EACtC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAIxB;AAED,0EAA0E;AAC1E,wBAAgB,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAG7G"}
package/zod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"zod.js","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,IAAI,CACzB,MAAyC,EACzC,MAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;IACrC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,CAAC,sDAAsD;IAChG,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,KAAK,CAAc,MAAuC,EAAE,KAAQ,EAAE,MAAwB;IAC7G,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * Helpers for reading and writing Zod-validated JSON frames on a track or group.\n *\n * @module\n */\n\nimport type * as z from \"zod/mini\";\nimport type * as group from \"./group.ts\";\nimport type * as track from \"./track.ts\";\n\n/** Read the next JSON frame and validate it against the schema. Returns undefined at end of stream. */\nexport async function read<T = unknown>(\n\tsource: track.Subscriber | group.Consumer,\n\tschema: z.ZodMiniType<T>,\n): Promise<T | undefined> {\n\tconst next = await source.readJson();\n\tif (next === undefined) return undefined; // only treat undefined as EOF, not other falsy values\n\treturn schema.parse(next);\n}\n\n/** Validate a value against the schema, then write it as a JSON frame. */\nexport function write<T = unknown>(source: track.Producer | group.Producer, value: T, schema: z.ZodMiniType<T>) {\n\tconst valid = schema.parse(value);\n\tsource.writeJson(valid);\n}\n"]}
1
+ {"version":3,"file":"zod.js","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,IAAI,CACzB,MAAsC,EACtC,MAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;IACrC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,CAAC,sDAAsD;IAChG,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,KAAK,CAAc,MAAuC,EAAE,KAAQ,EAAE,MAAwB;IAC7G,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * Helpers for reading and writing Zod-validated JSON frames on a track or group.\n *\n * @module\n */\n\nimport type * as z from \"zod/mini\";\nimport type * as group from \"./group.ts\";\nimport type * as track from \"./track.ts\";\n\n/** Read the next JSON frame and validate it against the schema. Returns undefined at end of stream. */\nexport async function read<T = unknown>(\n\tsource: track.Ordered | group.Consumer,\n\tschema: z.ZodMiniType<T>,\n): Promise<T | undefined> {\n\tconst next = await source.readJson();\n\tif (next === undefined) return undefined; // only treat undefined as EOF, not other falsy values\n\treturn schema.parse(next);\n}\n\n/** Validate a value against the schema, then write it as a JSON frame. */\nexport function write<T = unknown>(source: track.Producer | group.Producer, value: T, schema: z.ZodMiniType<T>) {\n\tconst valid = schema.parse(value);\n\tsource.writeJson(valid);\n}\n"]}
package/mock.d.ts DELETED
@@ -1,66 +0,0 @@
1
- /**
2
- * Mock WebTransport implementation for in-process testing.
3
- *
4
- * Creates paired client/server transports connected via TransformStreams.
5
- */
6
- import type { TransportStats } from "./connection/stats";
7
- import type { SendStream } from "./stream";
8
- /** A fake {@link WebTransport} backed by TransformStreams, paired with a peer. */
9
- export declare class MockTransport implements WebTransport {
10
- #private;
11
- readonly protocol: string;
12
- readonly ready: Promise<undefined>;
13
- readonly closed: Promise<WebTransportCloseInfo>;
14
- readonly incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalStream>;
15
- readonly incomingUnidirectionalStreams: ReadableStream<ReadableStream<Uint8Array>>;
16
- readonly datagrams: WebTransportDatagramDuplexStream;
17
- readonly congestionControl: WebTransportCongestionControl;
18
- readonly reliability: string;
19
- /**
20
- * Every outgoing stream this transport opened, in call order, split by stream kind. Each
21
- * carries a live {@link SendStream.sendOrder} (set when it opened, and by any later
22
- * re-rank), so a test can assert how the wire layer prioritized it. The mock always
23
- * delivers in creation order, so nothing else observes it.
24
- */
25
- readonly sendStreams: {
26
- uni: SendStream[];
27
- bidi: SendStream[];
28
- };
29
- constructor(protocol: string, datagramsEnabled?: boolean, datagramWritable?: DatagramWritableApi, datagramReadable?: boolean);
30
- setPeer(peer: MockTransport): void;
31
- createBidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WebTransportBidirectionalStream>;
32
- createUnidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WritableStream<Uint8Array>>;
33
- close(_closeInfo?: WebTransportCloseInfo): void;
34
- /** The snapshot {@link getStats} resolves with (default empty). */
35
- stats: TransportStats;
36
- getStats(): Promise<TransportStats>;
37
- }
38
- type DatagramWritableApi = "writable" | "createWritable" | "none";
39
- /** Options for {@link createMockTransportPair}. */
40
- export interface MockTransportOptions {
41
- /**
42
- * Whether the paired transports carry QUIC datagrams (default true). Set false to
43
- * simulate a transport that reports `maxDatagramSize` 0 (e.g. a qmux/WebSocket
44
- * session), so the wire layer must fall back to not sending datagrams.
45
- */
46
- datagrams?: boolean;
47
- /** Which outgoing datagram API shape the mock exposes. */
48
- datagramWritable?: DatagramWritableApi;
49
- /** Whether the incoming datagram readable stream is exposed. */
50
- datagramReadable?: boolean;
51
- /** The snapshot `getStats()` resolves with on both transports (default empty). */
52
- stats?: TransportStats;
53
- }
54
- /**
55
- * Creates a pair of connected MockTransport instances.
56
- *
57
- * @param protocol - The WebTransport protocol identifier (e.g. "moqt-17", "moql", "")
58
- * @param options - Optional behavior toggles for datagram availability
59
- * @returns An object containing `client` and `server` transports
60
- */
61
- export declare function createMockTransportPair(protocol?: string, options?: MockTransportOptions): {
62
- client: MockTransport;
63
- server: MockTransport;
64
- };
65
- export {};
66
- //# sourceMappingURL=mock.d.ts.map
package/mock.d.ts.map DELETED
@@ -1 +0,0 @@
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;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqB9C,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,4BAA4B,EAAE,cAAc,CAAC,+BAA+B,CAAC,CAAC;IACvF,QAAQ,CAAC,6BAA6B,EAAE,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IAEnF,QAAQ,CA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AAa,CAAA;CAAE,CAYlD"}
package/mock.js DELETED
@@ -1,243 +0,0 @@
1
- /* @ts-self-types="./mock.d.ts" */
2
- /**
3
- * Mock WebTransport implementation for in-process testing.
4
- *
5
- * Creates paired client/server transports connected via TransformStreams.
6
- */
7
- // High watermark to prevent writes from blocking on backpressure.
8
- // Real WebTransport has kernel buffers; we simulate this with a large queue.
9
- const WRITABLE_STRATEGY = { highWaterMark: 256 };
10
- const READABLE_STRATEGY = { highWaterMark: 256 };
11
- function newStream() {
12
- return new TransformStream({
13
- // Copy each chunk to simulate real WebTransport's kernel-boundary copy.
14
- // Without this, Writer's scratch buffer reuse corrupts queued data.
15
- transform(chunk, controller) {
16
- controller.enqueue(new Uint8Array(chunk));
17
- },
18
- }, WRITABLE_STRATEGY, READABLE_STRATEGY);
19
- }
20
- /** A fake {@link WebTransport} backed by TransformStreams, paired with a peer. */
21
- export class MockTransport {
22
- protocol;
23
- ready;
24
- closed;
25
- incomingBidirectionalStreams;
26
- incomingUnidirectionalStreams;
27
- datagrams;
28
- congestionControl;
29
- reliability;
30
- /**
31
- * Every outgoing stream this transport opened, in call order, split by stream kind. Each
32
- * carries a live {@link SendStream.sendOrder} (set when it opened, and by any later
33
- * re-rank), so a test can assert how the wire layer prioritized it. The mock always
34
- * delivers in creation order, so nothing else observes it.
35
- */
36
- sendStreams = { uni: [], bidi: [] };
37
- #closeResolve;
38
- #bidiController;
39
- #uniController;
40
- // Incoming-datagram controller (only set when datagrams are enabled); the peer's
41
- // writable enqueues into it.
42
- #datagramController;
43
- // Reference to the peer so we can enqueue streams to them
44
- #peer;
45
- constructor(protocol, datagramsEnabled = true, datagramWritable = "writable", datagramReadable = true) {
46
- this.protocol = protocol;
47
- this.ready = Promise.resolve(undefined);
48
- this.closed = new Promise((resolve) => {
49
- this.#closeResolve = resolve;
50
- });
51
- this.incomingBidirectionalStreams = new ReadableStream({
52
- start: (controller) => {
53
- this.#bidiController = controller;
54
- },
55
- });
56
- this.incomingUnidirectionalStreams = new ReadableStream({
57
- start: (controller) => {
58
- this.#uniController = controller;
59
- },
60
- });
61
- this.congestionControl = "default";
62
- this.reliability = "supports-unreliable";
63
- if (datagramsEnabled) {
64
- // A real datagram duplex: writes enqueue into the peer's incoming readable,
65
- // so a peer pair actually exchanges datagrams (unlike a real qmux Session,
66
- // whose datagram streams are inert stubs).
67
- const readable = datagramReadable
68
- ? new ReadableStream({
69
- start: (controller) => {
70
- this.#datagramController = controller;
71
- },
72
- })
73
- : undefined;
74
- const writable = new WritableStream({
75
- write: (chunk) => {
76
- const peer = this.#peer;
77
- if (!peer)
78
- return;
79
- const controller = peer.#datagramController;
80
- if (!controller)
81
- return;
82
- try {
83
- // Copy so the caller's scratch buffer reuse can't corrupt queued data.
84
- controller.enqueue(new Uint8Array(chunk));
85
- }
86
- catch {
87
- // Peer closed; drop (datagrams are best-effort).
88
- }
89
- },
90
- });
91
- const datagrams = {
92
- readable,
93
- incomingHighWaterMark: 0,
94
- outgoingHighWaterMark: 0,
95
- incomingMaxAge: null,
96
- outgoingMaxAge: null,
97
- maxDatagramSize: 1200,
98
- };
99
- if (datagramWritable === "writable") {
100
- datagrams.writable = writable;
101
- }
102
- else if (datagramWritable === "createWritable") {
103
- datagrams.createWritable = () => writable;
104
- }
105
- this.datagrams = datagrams;
106
- }
107
- else {
108
- // Simulate a transport that doesn't carry datagrams (maxDatagramSize 0): the
109
- // wire layer must fall back to not sending, with no group fallback.
110
- this.datagrams = {
111
- readable: new ReadableStream(),
112
- writable: new WritableStream(),
113
- incomingHighWaterMark: 0,
114
- outgoingHighWaterMark: 0,
115
- incomingMaxAge: null,
116
- outgoingMaxAge: null,
117
- maxDatagramSize: 0,
118
- };
119
- }
120
- }
121
- setPeer(peer) {
122
- this.#peer = peer;
123
- }
124
- async createBidirectionalStream(options) {
125
- const peer = this.#peer;
126
- if (!peer)
127
- throw new Error("no peer");
128
- // Create two TransformStreams for the two directions
129
- const c2s = newStream();
130
- const s2c = newStream();
131
- // Local side: writes to c2s, reads from s2c
132
- const local = {
133
- readable: s2c.readable,
134
- writable: this.#sendStream(c2s.writable, this.sendStreams.bidi, options),
135
- };
136
- // Peer side: writes to s2c, reads from c2s
137
- const remote = {
138
- readable: c2s.readable,
139
- writable: s2c.writable,
140
- };
141
- try {
142
- peer.#bidiController.enqueue(remote);
143
- }
144
- catch {
145
- // Peer closed
146
- }
147
- return local;
148
- }
149
- async createUnidirectionalStream(options) {
150
- const peer = this.#peer;
151
- if (!peer)
152
- throw new Error("no peer");
153
- const c2s = newStream();
154
- // Record before handing the peer its end, so a peer that waits for the stream to arrive
155
- // always finds it here.
156
- const stream = this.#sendStream(c2s.writable, this.sendStreams.uni, options);
157
- try {
158
- peer.#uniController.enqueue(c2s.readable);
159
- }
160
- catch {
161
- // Peer closed
162
- }
163
- return stream;
164
- }
165
- // Give a writable the send order it opened with and record it, so a test sees both that
166
- // order and any later re-rank (which assigns the same property, as on a real send stream).
167
- #sendStream(writable, log, options) {
168
- const stream = writable;
169
- stream.sendOrder = options?.sendOrder;
170
- log.push(stream);
171
- return stream;
172
- }
173
- close(_closeInfo) {
174
- const info = _closeInfo ?? { closeCode: 0, reason: "" };
175
- this.#closeResolve(info);
176
- try {
177
- this.#bidiController.close();
178
- }
179
- catch {
180
- // Already closed
181
- }
182
- try {
183
- this.#uniController.close();
184
- }
185
- catch {
186
- // Already closed
187
- }
188
- try {
189
- this.#datagramController?.close();
190
- }
191
- catch {
192
- // Already closed
193
- }
194
- // Also close peer's incoming streams
195
- if (this.#peer) {
196
- try {
197
- this.#peer.#bidiController.close();
198
- }
199
- catch {
200
- // Already closed
201
- }
202
- try {
203
- this.#peer.#uniController.close();
204
- }
205
- catch {
206
- // Already closed
207
- }
208
- try {
209
- this.#peer.#datagramController?.close();
210
- }
211
- catch {
212
- // Already closed
213
- }
214
- this.#peer.#closeResolve(info);
215
- }
216
- }
217
- /** The snapshot {@link getStats} resolves with (default empty). */
218
- stats = {};
219
- async getStats() {
220
- return this.stats;
221
- }
222
- }
223
- /**
224
- * Creates a pair of connected MockTransport instances.
225
- *
226
- * @param protocol - The WebTransport protocol identifier (e.g. "moqt-17", "moql", "")
227
- * @param options - Optional behavior toggles for datagram availability
228
- * @returns An object containing `client` and `server` transports
229
- */
230
- export function createMockTransportPair(protocol = "", options) {
231
- const datagrams = options?.datagrams ?? true;
232
- const client = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);
233
- const server = new MockTransport(protocol, datagrams, options?.datagramWritable, options?.datagramReadable);
234
- if (options?.stats) {
235
- // Copy per side so a test advancing one transport's counters doesn't move the other's.
236
- client.stats = { ...options.stats };
237
- server.stats = { ...options.stats };
238
- }
239
- client.setPeer(server);
240
- server.setPeer(client);
241
- return { client, server };
242
- }
243
- //# sourceMappingURL=mock.js.map
package/mock.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,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,CAAmC;IAC5C,iBAAiB,CAAgC;IACjD,WAAW,CAAS;IAE7B;;;;;OAKG;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ementation for in-process testing.\n *\n * Creates paired client/server transports connected via TransformStreams.\n */\n\nimport type { TransportStats } from \"./connection/stats.ts\";\nimport type { SendStream } from \"./stream.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/**\n\t * Every outgoing stream this transport opened, in call order, split by stream kind. Each\n\t * carries a live {@link SendStream.sendOrder} (set when it opened, and by any later\n\t * re-rank), so a test can assert how the wire layer prioritized it. The mock always\n\t * delivers in creation order, so nothing else observes it.\n\t */\n\treadonly sendStreams: { uni: SendStream[]; bidi: SendStream[] } = { uni: [], bidi: [] };\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(options?: WebTransportSendStreamOptions): 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: this.#sendStream(c2s.writable, this.sendStreams.bidi, options),\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\t// Record before handing the peer its end, so a peer that waits for the stream to arrive\n\t\t// always finds it here.\n\t\tconst stream = this.#sendStream(c2s.writable, this.sendStreams.uni, options);\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 stream;\n\t}\n\n\t// Give a writable the send order it opened with and record it, so a test sees both that\n\t// order and any later re-rank (which assigns the same property, as on a real send stream).\n\t#sendStream(\n\t\twritable: WritableStream<Uint8Array>,\n\t\tlog: SendStream[],\n\t\toptions?: WebTransportSendStreamOptions,\n\t): SendStream {\n\t\tconst stream = writable as SendStream;\n\t\tstream.sendOrder = options?.sendOrder;\n\t\tlog.push(stream);\n\t\treturn stream;\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"]}