@moq/net 0.4.8 → 0.22.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 (662) hide show
  1. package/README.md +7 -1
  2. package/announce.d.ts +1 -1
  3. package/announce.d.ts.map +1 -1
  4. package/announce.js +1 -1
  5. package/announce.js.map +1 -1
  6. package/announced.d.ts +51 -47
  7. package/announced.d.ts.map +1 -1
  8. package/announced.js +183 -31
  9. package/announced.js.map +1 -1
  10. package/announced.test-util.d.ts +2 -0
  11. package/announced.test-util.d.ts.map +1 -0
  12. package/announced.test-util.js +27 -0
  13. package/announced.test-util.js.map +1 -0
  14. package/auth.d.ts +64 -0
  15. package/auth.d.ts.map +1 -0
  16. package/auth.js +20 -0
  17. package/auth.js.map +1 -0
  18. package/auth_gate.d.ts +2 -0
  19. package/auth_gate.d.ts.map +1 -0
  20. package/auth_gate.js +24 -0
  21. package/auth_gate.js.map +1 -0
  22. package/auth_session.d.ts +49 -0
  23. package/auth_session.d.ts.map +1 -0
  24. package/auth_session.js +1097 -0
  25. package/auth_session.js.map +1 -0
  26. package/bandwidth.d.ts +129 -25
  27. package/bandwidth.d.ts.map +1 -1
  28. package/bandwidth.js +410 -138
  29. package/bandwidth.js.map +1 -1
  30. package/bandwidth_api.d.ts +1 -1
  31. package/bandwidth_api.d.ts.map +1 -1
  32. package/bandwidth_api.js +1 -1
  33. package/bandwidth_api.js.map +1 -1
  34. package/broadcast.d.ts +62 -36
  35. package/broadcast.d.ts.map +1 -1
  36. package/broadcast.js +556 -172
  37. package/broadcast.js.map +1 -1
  38. package/cache.d.ts +103 -0
  39. package/cache.d.ts.map +1 -0
  40. package/cache.js +254 -0
  41. package/cache.js.map +1 -0
  42. package/claim.test-util.d.ts +5 -0
  43. package/claim.test-util.d.ts.map +1 -0
  44. package/claim.test-util.js +13 -0
  45. package/claim.test-util.js.map +1 -0
  46. package/connection/accept.d.ts +20 -12
  47. package/connection/accept.d.ts.map +1 -1
  48. package/connection/accept.js +97 -129
  49. package/connection/accept.js.map +1 -1
  50. package/connection/browser.d.ts.map +1 -1
  51. package/connection/browser.js +28 -19
  52. package/connection/browser.js.map +1 -1
  53. package/connection/connect.d.ts +119 -23
  54. package/connection/connect.d.ts.map +1 -1
  55. package/connection/connect.js +535 -216
  56. package/connection/connect.js.map +1 -1
  57. package/connection/dials.d.ts +45 -0
  58. package/connection/dials.d.ts.map +1 -0
  59. package/connection/dials.js +109 -0
  60. package/connection/dials.js.map +1 -0
  61. package/connection/endpoint.d.ts +60 -0
  62. package/connection/endpoint.d.ts.map +1 -0
  63. package/connection/endpoint.js +114 -0
  64. package/connection/endpoint.js.map +1 -0
  65. package/connection/forward.d.ts +7 -1
  66. package/connection/forward.d.ts.map +1 -1
  67. package/connection/forward.js +265 -80
  68. package/connection/forward.js.map +1 -1
  69. package/connection/goaway.d.ts +16 -9
  70. package/connection/goaway.d.ts.map +1 -1
  71. package/connection/goaway.js +22 -108
  72. package/connection/goaway.js.map +1 -1
  73. package/connection/handshake.d.ts +32 -6
  74. package/connection/handshake.d.ts.map +1 -1
  75. package/connection/handshake.js +97 -20
  76. package/connection/handshake.js.map +1 -1
  77. package/connection/index.d.ts +3 -6
  78. package/connection/index.d.ts.map +1 -1
  79. package/connection/index.js +1 -2
  80. package/connection/index.js.map +1 -1
  81. package/connection/liveness.d.ts +14 -0
  82. package/connection/liveness.d.ts.map +1 -0
  83. package/connection/liveness.js +30 -0
  84. package/connection/liveness.js.map +1 -0
  85. package/connection/pool.d.ts +137 -58
  86. package/connection/pool.d.ts.map +1 -1
  87. package/connection/pool.js +281 -117
  88. package/connection/pool.js.map +1 -1
  89. package/connection/reload.d.ts +60 -12
  90. package/connection/reload.d.ts.map +1 -1
  91. package/connection/reload.js +859 -233
  92. package/connection/reload.js.map +1 -1
  93. package/connection/session.d.ts +91 -0
  94. package/connection/session.d.ts.map +1 -0
  95. package/connection/session.js +2 -0
  96. package/connection/session.js.map +1 -0
  97. package/connection/stats.d.ts +20 -11
  98. package/connection/stats.d.ts.map +1 -1
  99. package/connection/stats.js +64 -8
  100. package/connection/stats.js.map +1 -1
  101. package/connection/ticker.d.ts +4 -0
  102. package/connection/ticker.d.ts.map +1 -0
  103. package/connection/ticker.js +66 -0
  104. package/connection/ticker.js.map +1 -0
  105. package/connection/tokens.d.ts +2 -0
  106. package/connection/tokens.d.ts.map +1 -0
  107. package/connection/tokens.js +404 -0
  108. package/connection/tokens.js.map +1 -0
  109. package/connection/transport.d.ts.map +1 -1
  110. package/connection/transport.js +4 -4
  111. package/connection/transport.js.map +1 -1
  112. package/connection/withdrawal.d.ts +2 -0
  113. package/connection/withdrawal.d.ts.map +1 -0
  114. package/connection/withdrawal.js +23 -0
  115. package/connection/withdrawal.js.map +1 -0
  116. package/consume.js +213 -46
  117. package/consume.js.map +1 -1
  118. package/cover.d.ts +59 -0
  119. package/cover.d.ts.map +1 -0
  120. package/cover.js +375 -0
  121. package/cover.js.map +1 -0
  122. package/datagram.d.ts +70 -11
  123. package/datagram.d.ts.map +1 -1
  124. package/datagram.js +317 -1
  125. package/datagram.js.map +1 -1
  126. package/datagram_stream.d.ts +18 -0
  127. package/datagram_stream.d.ts.map +1 -0
  128. package/datagram_stream.js +67 -0
  129. package/datagram_stream.js.map +1 -0
  130. package/defined.test-util.d.ts +2 -0
  131. package/defined.test-util.d.ts.map +1 -0
  132. package/defined.test-util.js +7 -0
  133. package/defined.test-util.js.map +1 -0
  134. package/delivered.d.ts +75 -0
  135. package/delivered.d.ts.map +1 -0
  136. package/delivered.js +228 -0
  137. package/delivered.js.map +1 -0
  138. package/demand.d.ts +173 -0
  139. package/demand.d.ts.map +1 -0
  140. package/demand.js +582 -0
  141. package/demand.js.map +1 -0
  142. package/drops.d.ts +93 -0
  143. package/drops.d.ts.map +1 -0
  144. package/drops.js +283 -0
  145. package/drops.js.map +1 -0
  146. package/error.d.ts +120 -21
  147. package/error.d.ts.map +1 -1
  148. package/error.js +230 -37
  149. package/error.js.map +1 -1
  150. package/errors.d.ts +2 -2
  151. package/errors.d.ts.map +1 -1
  152. package/errors.js +2 -2
  153. package/errors.js.map +1 -1
  154. package/fill.d.ts +174 -0
  155. package/fill.d.ts.map +1 -0
  156. package/fill.js +760 -0
  157. package/fill.js.map +1 -0
  158. package/flate/decoder.d.ts +2 -0
  159. package/flate/decoder.d.ts.map +1 -0
  160. package/flate/decoder.js +63 -0
  161. package/flate/decoder.js.map +1 -0
  162. package/flate/encoder.d.ts +2 -0
  163. package/flate/encoder.d.ts.map +1 -0
  164. package/flate/encoder.js +64 -0
  165. package/flate/encoder.js.map +1 -0
  166. package/flate/group.d.ts +34 -0
  167. package/flate/group.d.ts.map +1 -0
  168. package/flate/group.js +140 -0
  169. package/flate/group.js.map +1 -0
  170. package/frame.d.ts +80 -0
  171. package/frame.d.ts.map +1 -0
  172. package/frame.js +296 -0
  173. package/frame.js.map +1 -0
  174. package/frame.test-util.d.ts +5 -0
  175. package/frame.test-util.d.ts.map +1 -0
  176. package/frame.test-util.js +9 -0
  177. package/frame.test-util.js.map +1 -0
  178. package/group.d.ts +108 -45
  179. package/group.d.ts.map +1 -1
  180. package/group.js +1616 -307
  181. package/group.js.map +1 -1
  182. package/group_api.d.ts +7 -0
  183. package/group_api.d.ts.map +1 -0
  184. package/group_api.js +7 -0
  185. package/group_api.js.map +1 -0
  186. package/hop.d.ts +62 -76
  187. package/hop.d.ts.map +1 -1
  188. package/hop.js +92 -64
  189. package/hop.js.map +1 -1
  190. package/identity.d.ts +39 -0
  191. package/identity.d.ts.map +1 -0
  192. package/identity.js +47 -0
  193. package/identity.js.map +1 -0
  194. package/ietf/active_count.d.ts +2 -0
  195. package/ietf/active_count.d.ts.map +1 -0
  196. package/ietf/active_count.js +30 -0
  197. package/ietf/active_count.js.map +1 -0
  198. package/ietf/aliases.js +69 -35
  199. package/ietf/aliases.js.map +1 -1
  200. package/ietf/cluster.d.ts +3 -3
  201. package/ietf/cluster.js +14 -62
  202. package/ietf/cluster.js.map +1 -1
  203. package/ietf/connection.d.ts +1 -31
  204. package/ietf/connection.d.ts.map +1 -1
  205. package/ietf/connection.js +305 -143
  206. package/ietf/connection.js.map +1 -1
  207. package/ietf/datagram.d.ts +60 -0
  208. package/ietf/datagram.d.ts.map +1 -0
  209. package/ietf/datagram.js +152 -0
  210. package/ietf/datagram.js.map +1 -0
  211. package/ietf/error.d.ts +3 -3
  212. package/ietf/error.js +82 -100
  213. package/ietf/error.js.map +1 -1
  214. package/ietf/fetch.d.ts +91 -35
  215. package/ietf/fetch.d.ts.map +1 -1
  216. package/ietf/fetch.js +172 -93
  217. package/ietf/fetch.js.map +1 -1
  218. package/ietf/filter.d.ts +20 -30
  219. package/ietf/filter.d.ts.map +1 -1
  220. package/ietf/filter.js +140 -171
  221. package/ietf/filter.js.map +1 -1
  222. package/ietf/goaway.d.ts +11 -9
  223. package/ietf/goaway.d.ts.map +1 -1
  224. package/ietf/goaway.js +22 -35
  225. package/ietf/goaway.js.map +1 -1
  226. package/ietf/hidden.js +1 -1
  227. package/ietf/hidden.js.map +1 -1
  228. package/ietf/index.d.ts +2 -14
  229. package/ietf/index.d.ts.map +1 -1
  230. package/ietf/index.js +4 -14
  231. package/ietf/index.js.map +1 -1
  232. package/ietf/join.d.ts +7 -0
  233. package/ietf/join.d.ts.map +1 -0
  234. package/ietf/join.js +234 -0
  235. package/ietf/join.js.map +1 -0
  236. package/ietf/message.d.ts +18 -2
  237. package/ietf/message.d.ts.map +1 -1
  238. package/ietf/message.js +60 -40
  239. package/ietf/message.js.map +1 -1
  240. package/ietf/message.test-util.d.ts +6 -0
  241. package/ietf/message.test-util.d.ts.map +1 -0
  242. package/ietf/message.test-util.js +13 -0
  243. package/ietf/message.test-util.js.map +1 -0
  244. package/ietf/namespace.d.ts +17 -3
  245. package/ietf/namespace.d.ts.map +1 -1
  246. package/ietf/namespace.js +78 -26
  247. package/ietf/namespace.js.map +1 -1
  248. package/ietf/object.d.ts +194 -32
  249. package/ietf/object.d.ts.map +1 -1
  250. package/ietf/object.js +405 -178
  251. package/ietf/object.js.map +1 -1
  252. package/ietf/parameters.d.ts +22 -42
  253. package/ietf/parameters.d.ts.map +1 -1
  254. package/ietf/parameters.js +260 -472
  255. package/ietf/parameters.js.map +1 -1
  256. package/ietf/priority.d.ts +17 -2
  257. package/ietf/priority.d.ts.map +1 -1
  258. package/ietf/priority.js +19 -4
  259. package/ietf/priority.js.map +1 -1
  260. package/ietf/properties.d.ts +5 -4
  261. package/ietf/properties.d.ts.map +1 -1
  262. package/ietf/properties.js +78 -48
  263. package/ietf/properties.js.map +1 -1
  264. package/ietf/publish.d.ts +22 -30
  265. package/ietf/publish.d.ts.map +1 -1
  266. package/ietf/publish.js +45 -139
  267. package/ietf/publish.js.map +1 -1
  268. package/ietf/publish_namespace.d.ts +46 -69
  269. package/ietf/publish_namespace.d.ts.map +1 -1
  270. package/ietf/publish_namespace.js +66 -184
  271. package/ietf/publish_namespace.js.map +1 -1
  272. package/ietf/publisher.js +1800 -600
  273. package/ietf/publisher.js.map +1 -1
  274. package/ietf/range.d.ts +2 -0
  275. package/ietf/range.d.ts.map +1 -0
  276. package/ietf/range.js +222 -0
  277. package/ietf/range.js.map +1 -0
  278. package/ietf/request.d.ts +3 -27
  279. package/ietf/request.d.ts.map +1 -1
  280. package/ietf/request.js +41 -78
  281. package/ietf/request.js.map +1 -1
  282. package/ietf/request_stream.d.ts +1 -6
  283. package/ietf/request_stream.d.ts.map +1 -1
  284. package/ietf/request_stream.js +306 -16
  285. package/ietf/request_stream.js.map +1 -1
  286. package/ietf/session.d.ts +41 -0
  287. package/ietf/session.d.ts.map +1 -0
  288. package/ietf/session.js +65 -0
  289. package/ietf/session.js.map +1 -0
  290. package/ietf/setup.d.ts +4 -29
  291. package/ietf/setup.d.ts.map +1 -1
  292. package/ietf/setup.js +6 -117
  293. package/ietf/setup.js.map +1 -1
  294. package/ietf/setup_options.d.ts +31 -0
  295. package/ietf/setup_options.d.ts.map +1 -0
  296. package/ietf/setup_options.js +138 -0
  297. package/ietf/setup_options.js.map +1 -0
  298. package/ietf/solicit.js +4 -14
  299. package/ietf/solicit.js.map +1 -1
  300. package/ietf/subscribe.d.ts +48 -41
  301. package/ietf/subscribe.d.ts.map +1 -1
  302. package/ietf/subscribe.js +118 -239
  303. package/ietf/subscribe.js.map +1 -1
  304. package/ietf/subscribe_namespace.d.ts +13 -76
  305. package/ietf/subscribe_namespace.d.ts.map +1 -1
  306. package/ietf/subscribe_namespace.js +30 -201
  307. package/ietf/subscribe_namespace.js.map +1 -1
  308. package/ietf/subscriber.js +1839 -536
  309. package/ietf/subscriber.js.map +1 -1
  310. package/ietf/token.js +105 -27
  311. package/ietf/token.js.map +1 -1
  312. package/ietf/track.d.ts +25 -22
  313. package/ietf/track.d.ts.map +1 -1
  314. package/ietf/track.js +48 -61
  315. package/ietf/track.js.map +1 -1
  316. package/ietf/version.d.ts +13 -42
  317. package/ietf/version.d.ts.map +1 -1
  318. package/ietf/version.js +22 -48
  319. package/ietf/version.js.map +1 -1
  320. package/implementation.d.ts +2 -0
  321. package/implementation.d.ts.map +1 -0
  322. package/implementation.js +5 -0
  323. package/implementation.js.map +1 -0
  324. package/index.d.ts +25 -10
  325. package/index.d.ts.map +1 -1
  326. package/index.js +19 -6
  327. package/index.js.map +1 -1
  328. package/internal.d.ts +1512 -64
  329. package/internal.d.ts.map +1 -1
  330. package/internal.js +557 -79
  331. package/internal.js.map +1 -1
  332. package/ledger.d.ts +23 -0
  333. package/ledger.d.ts.map +1 -0
  334. package/ledger.js +247 -0
  335. package/ledger.js.map +1 -0
  336. package/listing.d.ts +132 -0
  337. package/listing.d.ts.map +1 -0
  338. package/listing.js +486 -0
  339. package/listing.js.map +1 -0
  340. package/lite/announce.d.ts +124 -63
  341. package/lite/announce.d.ts.map +1 -1
  342. package/lite/announce.js +384 -158
  343. package/lite/announce.js.map +1 -1
  344. package/lite/announce_stream.d.ts +2 -0
  345. package/lite/announce_stream.d.ts.map +1 -0
  346. package/lite/announce_stream.js +92 -0
  347. package/lite/announce_stream.js.map +1 -0
  348. package/lite/answer.d.ts +22 -0
  349. package/lite/answer.d.ts.map +1 -0
  350. package/lite/answer.js +301 -0
  351. package/lite/answer.js.map +1 -0
  352. package/lite/auth.d.ts +45 -0
  353. package/lite/auth.d.ts.map +1 -0
  354. package/lite/auth.js +204 -0
  355. package/lite/auth.js.map +1 -0
  356. package/lite/compat.d.ts +31 -0
  357. package/lite/compat.d.ts.map +1 -0
  358. package/lite/compat.js +86 -0
  359. package/lite/compat.js.map +1 -0
  360. package/lite/connection.d.ts +1 -45
  361. package/lite/connection.d.ts.map +1 -1
  362. package/lite/connection.js +360 -77
  363. package/lite/connection.js.map +1 -1
  364. package/lite/datagram-end.d.ts +26 -0
  365. package/lite/datagram-end.d.ts.map +1 -0
  366. package/lite/datagram-end.js +30 -0
  367. package/lite/datagram-end.js.map +1 -0
  368. package/lite/datagram.d.ts +73 -8
  369. package/lite/datagram.d.ts.map +1 -1
  370. package/lite/datagram.js +144 -9
  371. package/lite/datagram.js.map +1 -1
  372. package/lite/duration.d.ts +6 -0
  373. package/lite/duration.d.ts.map +1 -0
  374. package/lite/duration.js +14 -0
  375. package/lite/duration.js.map +1 -0
  376. package/lite/error.d.ts +9 -0
  377. package/lite/error.d.ts.map +1 -0
  378. package/lite/error.js +24 -0
  379. package/lite/error.js.map +1 -0
  380. package/lite/fills.d.ts +162 -0
  381. package/lite/fills.d.ts.map +1 -0
  382. package/lite/fills.js +486 -0
  383. package/lite/fills.js.map +1 -0
  384. package/lite/fit.d.ts +49 -0
  385. package/lite/fit.d.ts.map +1 -0
  386. package/lite/fit.js +305 -0
  387. package/lite/fit.js.map +1 -0
  388. package/lite/goaway.d.ts +1 -1
  389. package/lite/goaway.d.ts.map +1 -1
  390. package/lite/goaway.js +5 -13
  391. package/lite/goaway.js.map +1 -1
  392. package/lite/group.d.ts +64 -13
  393. package/lite/group.d.ts.map +1 -1
  394. package/lite/group.js +108 -30
  395. package/lite/group.js.map +1 -1
  396. package/lite/identity.d.ts +25 -0
  397. package/lite/identity.d.ts.map +1 -0
  398. package/lite/identity.js +79 -0
  399. package/lite/identity.js.map +1 -0
  400. package/lite/index.d.ts +2 -1
  401. package/lite/index.d.ts.map +1 -1
  402. package/lite/index.js +2 -1
  403. package/lite/index.js.map +1 -1
  404. package/lite/message.d.ts +9 -1
  405. package/lite/message.d.ts.map +1 -1
  406. package/lite/message.js +28 -44
  407. package/lite/message.js.map +1 -1
  408. package/lite/priority.d.ts +9 -2
  409. package/lite/priority.d.ts.map +1 -1
  410. package/lite/priority.js +11 -105
  411. package/lite/priority.js.map +1 -1
  412. package/lite/probe.d.ts.map +1 -1
  413. package/lite/probe.js +9 -0
  414. package/lite/probe.js.map +1 -1
  415. package/lite/publisher.d.ts +10 -1
  416. package/lite/publisher.d.ts.map +1 -1
  417. package/lite/publisher.js +2548 -437
  418. package/lite/publisher.js.map +1 -1
  419. package/lite/routed.d.ts +59 -0
  420. package/lite/routed.d.ts.map +1 -0
  421. package/lite/routed.js +564 -0
  422. package/lite/routed.js.map +1 -0
  423. package/lite/session.d.ts +1 -27
  424. package/lite/session.d.ts.map +1 -1
  425. package/lite/session.js +0 -99
  426. package/lite/session.js.map +1 -1
  427. package/lite/setup.d.ts +29 -2
  428. package/lite/setup.d.ts.map +1 -1
  429. package/lite/setup.js +95 -21
  430. package/lite/setup.js.map +1 -1
  431. package/lite/stream.d.ts +5 -11
  432. package/lite/stream.d.ts.map +1 -1
  433. package/lite/stream.js +5 -1
  434. package/lite/stream.js.map +1 -1
  435. package/lite/subscribe.d.ts +475 -75
  436. package/lite/subscribe.d.ts.map +1 -1
  437. package/lite/subscribe.js +1373 -142
  438. package/lite/subscribe.js.map +1 -1
  439. package/lite/subscriber.d.ts +7 -44
  440. package/lite/subscriber.d.ts.map +1 -1
  441. package/lite/subscriber.js +3290 -515
  442. package/lite/subscriber.js.map +1 -1
  443. package/lite/track.d.ts +24 -9
  444. package/lite/track.d.ts.map +1 -1
  445. package/lite/track.js +116 -37
  446. package/lite/track.js.map +1 -1
  447. package/lite/tracks.d.ts +55 -0
  448. package/lite/tracks.d.ts.map +1 -0
  449. package/lite/tracks.js +114 -0
  450. package/lite/tracks.js.map +1 -0
  451. package/lite/version.d.ts +132 -24
  452. package/lite/version.d.ts.map +1 -1
  453. package/lite/version.js +378 -33
  454. package/lite/version.js.map +1 -1
  455. package/meta.d.ts +77 -0
  456. package/meta.d.ts.map +1 -0
  457. package/meta.js +130 -0
  458. package/meta.js.map +1 -0
  459. package/meta_api.d.ts +7 -0
  460. package/meta_api.d.ts.map +1 -0
  461. package/meta_api.js +7 -0
  462. package/meta_api.js.map +1 -0
  463. package/mint.d.ts +28 -0
  464. package/mint.d.ts.map +1 -0
  465. package/mint.js +66 -0
  466. package/mint.js.map +1 -0
  467. package/open.d.ts +63 -0
  468. package/open.d.ts.map +1 -0
  469. package/open.js +250 -0
  470. package/open.js.map +1 -0
  471. package/origin.d.ts +392 -140
  472. package/origin.d.ts.map +1 -1
  473. package/origin.js +2533 -686
  474. package/origin.js.map +1 -1
  475. package/package.json +8 -13
  476. package/path.d.ts +51 -51
  477. package/path.d.ts.map +1 -1
  478. package/path.js +210 -57
  479. package/path.js.map +1 -1
  480. package/payload.d.ts +33 -0
  481. package/payload.d.ts.map +1 -0
  482. package/payload.js +65 -0
  483. package/payload.js.map +1 -0
  484. package/prefix.d.ts +152 -0
  485. package/prefix.d.ts.map +1 -0
  486. package/prefix.js +349 -0
  487. package/prefix.js.map +1 -0
  488. package/priority.d.ts +8 -0
  489. package/priority.d.ts.map +1 -0
  490. package/priority.js +185 -0
  491. package/priority.js.map +1 -0
  492. package/queue.d.ts +2 -0
  493. package/queue.d.ts.map +1 -0
  494. package/queue.js +46 -0
  495. package/queue.js.map +1 -0
  496. package/ranges.d.ts +36 -0
  497. package/ranges.d.ts.map +1 -0
  498. package/ranges.js +312 -0
  499. package/ranges.js.map +1 -0
  500. package/rescale.d.ts +24 -0
  501. package/rescale.d.ts.map +1 -0
  502. package/rescale.js +39 -0
  503. package/rescale.js.map +1 -0
  504. package/resume.d.ts +55 -0
  505. package/resume.d.ts.map +1 -0
  506. package/resume.js +4173 -0
  507. package/resume.js.map +1 -0
  508. package/resume.test-util.d.ts +2 -0
  509. package/resume.test-util.d.ts.map +1 -0
  510. package/resume.test-util.js +25 -0
  511. package/resume.test-util.js.map +1 -0
  512. package/skips.d.ts +48 -0
  513. package/skips.d.ts.map +1 -0
  514. package/skips.js +182 -0
  515. package/skips.js.map +1 -0
  516. package/stream.d.ts +75 -37
  517. package/stream.d.ts.map +1 -1
  518. package/stream.js +236 -92
  519. package/stream.js.map +1 -1
  520. package/subscription.test-util.d.ts +2 -0
  521. package/subscription.test-util.d.ts.map +1 -0
  522. package/subscription.test-util.js +49 -0
  523. package/subscription.test-util.js.map +1 -0
  524. package/tail.d.ts +23 -14
  525. package/tail.d.ts.map +1 -1
  526. package/tail.js +224 -97
  527. package/tail.js.map +1 -1
  528. package/time.d.ts +41 -102
  529. package/time.d.ts.map +1 -1
  530. package/time.js +129 -91
  531. package/time.js.map +1 -1
  532. package/timed.d.ts +21 -0
  533. package/timed.d.ts.map +1 -0
  534. package/timed.js +2 -0
  535. package/timed.js.map +1 -0
  536. package/track.d.ts +577 -245
  537. package/track.d.ts.map +1 -1
  538. package/track.js +7306 -771
  539. package/track.js.map +1 -1
  540. package/track_api.d.ts +7 -0
  541. package/track_api.d.ts.map +1 -0
  542. package/track_api.js +7 -0
  543. package/track_api.js.map +1 -0
  544. package/util/abort.d.ts +1 -0
  545. package/util/abort.d.ts.map +1 -1
  546. package/util/abort.js +23 -1
  547. package/util/abort.js.map +1 -1
  548. package/util/announce.d.ts +4 -0
  549. package/util/announce.d.ts.map +1 -0
  550. package/util/announce.js +11 -0
  551. package/util/announce.js.map +1 -0
  552. package/util/bigint.d.ts +3 -0
  553. package/util/bigint.d.ts.map +1 -0
  554. package/util/bigint.js +8 -0
  555. package/util/bigint.js.map +1 -0
  556. package/util/change.d.ts +12 -0
  557. package/util/change.d.ts.map +1 -0
  558. package/util/change.js +18 -0
  559. package/util/change.js.map +1 -0
  560. package/util/deadline.d.ts +2 -0
  561. package/util/deadline.d.ts.map +1 -0
  562. package/util/deadline.js +108 -0
  563. package/util/deadline.js.map +1 -0
  564. package/util/decode_error.d.ts +3 -0
  565. package/util/decode_error.d.ts.map +1 -0
  566. package/util/decode_error.js +11 -0
  567. package/util/decode_error.js.map +1 -0
  568. package/util/demand.d.ts +8 -0
  569. package/util/demand.d.ts.map +1 -0
  570. package/util/demand.js +24 -0
  571. package/util/demand.js.map +1 -0
  572. package/util/given_up.d.ts +2 -0
  573. package/util/given_up.d.ts.map +1 -0
  574. package/util/given_up.js +101 -0
  575. package/util/given_up.js.map +1 -0
  576. package/util/hex.d.ts +6 -0
  577. package/util/hex.d.ts.map +1 -1
  578. package/util/hex.js +19 -4
  579. package/util/hex.js.map +1 -1
  580. package/util/key.d.ts +15 -0
  581. package/util/key.d.ts.map +1 -0
  582. package/util/key.js +38 -0
  583. package/util/key.js.map +1 -0
  584. package/util/limits.d.ts +2 -0
  585. package/util/limits.d.ts.map +1 -0
  586. package/util/limits.js +76 -0
  587. package/util/limits.js.map +1 -0
  588. package/util/observed.d.ts +23 -0
  589. package/util/observed.d.ts.map +1 -0
  590. package/util/observed.js +122 -0
  591. package/util/observed.js.map +1 -0
  592. package/util/sorted.d.ts +2 -0
  593. package/util/sorted.d.ts.map +1 -0
  594. package/util/sorted.js +149 -0
  595. package/util/sorted.js.map +1 -0
  596. package/util/timeout.d.ts +2 -1
  597. package/util/timeout.d.ts.map +1 -1
  598. package/util/timeout.js +13 -9
  599. package/util/timeout.js.map +1 -1
  600. package/util/timer.d.ts +2 -0
  601. package/util/timer.d.ts.map +1 -0
  602. package/util/timer.js +19 -0
  603. package/util/timer.js.map +1 -0
  604. package/util/utf8.d.ts +2 -0
  605. package/util/utf8.d.ts.map +1 -1
  606. package/util/utf8.js +7 -1
  607. package/util/utf8.js.map +1 -1
  608. package/util/varint.d.ts.map +1 -1
  609. package/util/varint.js +8 -1
  610. package/util/varint.js.map +1 -1
  611. package/util/watch.d.ts +8 -0
  612. package/util/watch.d.ts.map +1 -0
  613. package/util/watch.js +38 -0
  614. package/util/watch.js.map +1 -0
  615. package/util/yield.d.ts +2 -0
  616. package/util/yield.d.ts.map +1 -0
  617. package/util/yield.js +31 -0
  618. package/util/yield.js.map +1 -0
  619. package/varint.d.ts +0 -29
  620. package/varint.d.ts.map +1 -1
  621. package/varint.js +7 -28
  622. package/varint.js.map +1 -1
  623. package/varint_api.d.ts +7 -0
  624. package/varint_api.d.ts.map +1 -0
  625. package/varint_api.js +7 -0
  626. package/varint_api.js.map +1 -0
  627. package/version.d.ts +2 -0
  628. package/version.d.ts.map +1 -0
  629. package/version.js +4 -0
  630. package/version.js.map +1 -0
  631. package/window.d.ts +570 -0
  632. package/window.d.ts.map +1 -0
  633. package/window.js +1677 -0
  634. package/window.js.map +1 -0
  635. package/wire.d.ts +145 -30
  636. package/wire.d.ts.map +1 -1
  637. package/wire.js +27 -0
  638. package/wire.js.map +1 -1
  639. package/connection/established.d.ts +0 -53
  640. package/connection/established.d.ts.map +0 -1
  641. package/connection/established.js +0 -2
  642. package/connection/established.js.map +0 -1
  643. package/ietf/adapter.d.ts +0 -75
  644. package/ietf/adapter.d.ts.map +0 -1
  645. package/ietf/adapter.js +0 -699
  646. package/ietf/adapter.js.map +0 -1
  647. package/lite/datagram_stream.d.ts +0 -8
  648. package/lite/datagram_stream.d.ts.map +0 -1
  649. package/lite/datagram_stream.js +0 -43
  650. package/lite/datagram_stream.js.map +0 -1
  651. package/lite/fetch.d.ts +0 -28
  652. package/lite/fetch.d.ts.map +0 -1
  653. package/lite/fetch.js +0 -78
  654. package/lite/fetch.js.map +0 -1
  655. package/util/log.d.ts +0 -5
  656. package/util/log.d.ts.map +0 -1
  657. package/util/log.js +0 -16
  658. package/util/log.js.map +0 -1
  659. package/zod.d.ts +0 -13
  660. package/zod.d.ts.map +0 -1
  661. package/zod.js +0 -18
  662. package/zod.js.map +0 -1
package/ietf/aliases.js CHANGED
@@ -1,4 +1,5 @@
1
- const TRACK_ALIAS_TIMEOUT_MS = 1000;
1
+ import { Duration, Elapsed, timeout } from "@moq/clock";
2
+ const TRACK_ALIAS_TIMEOUT = Duration.millis(1000);
2
3
  /**
3
4
  * How many cancelled aliases to remember. Objects keep arriving for about a round trip
4
5
  * after we cancel, so a handful covers the window, while the cap keeps a long session with
@@ -18,7 +19,7 @@ function sameTrack(a, b) {
18
19
  * Thrown when a group arrives for a subscription we already cancelled.
19
20
  *
20
21
  * The publisher only stops once our cancellation reaches it, so objects keep arriving for
21
- * at least a round trip afterwards. Draft-19 section 11.1 asks us to keep enough state to
22
+ * at least a round trip afterwards. Draft-22 section 3.1.3 asks us to keep enough state to
22
23
  * discard them quickly "rather than treating them as belonging to an unknown Track Alias".
23
24
  *
24
25
  * This makes the window quiet, not safe. Once a publisher reassigns the alias the tombstone
@@ -35,7 +36,7 @@ export class RetiredTrackAlias extends Error {
35
36
  /**
36
37
  * Thrown when a publisher gives one alias to two subscriptions of the same track.
37
38
  *
38
- * Draft-19 section 5.1 permits this and expects the subscriber to demux by re-applying
39
+ * Draft-22 section 3.1.3 permits this and expects the subscriber to demux by re-applying
39
40
  * each subscription's filter. Ours are all LargestObject, so they are indistinguishable and
40
41
  * we cannot, which costs the one subscription. It is not a protocol error, so it must not
41
42
  * take the session down with it.
@@ -49,7 +50,7 @@ export class SharedTrackAlias extends Error {
49
50
  }
50
51
  /**
51
52
  * Thrown when a publisher points one alias at two different tracks at once, which
52
- * draft-19 section 11.1 makes fatal to the session.
53
+ * draft-22 section 3.1.3 makes fatal to the session.
53
54
  * @internal
54
55
  */
55
56
  export class DuplicateTrackAlias extends Error {
@@ -62,9 +63,11 @@ export class DuplicateTrackAlias extends Error {
62
63
  export class TrackAliases {
63
64
  #active = new Map();
64
65
  #pending = new Map();
65
- /** Aliases whose subscription we cancelled, in retirement order so the oldest is forgotten first. */
66
- #retired = [];
67
- #retiredSet = new Set();
66
+ /**
67
+ * Aliases whose subscription we cancelled, with the track each served, in retirement order
68
+ * (a Map iterates by insertion) so the oldest is forgotten first.
69
+ */
70
+ #retired = new Map();
68
71
  /**
69
72
  * Waits briefly for an alias to be established by SUBSCRIBE_OK or PUBLISH.
70
73
  *
@@ -75,29 +78,34 @@ export class TrackAliases {
75
78
  const bound = this.#active.get(alias);
76
79
  if (bound !== undefined)
77
80
  return bound.value;
78
- if (this.#retiredSet.has(alias))
81
+ if (this.#retired.has(alias))
79
82
  throw new RetiredTrackAlias(alias);
80
- const { promise, resolve } = Promise.withResolvers();
83
+ const { promise, resolve, reject } = Promise.withResolvers();
84
+ const waiter = { resolve, reject };
81
85
  let resolvers = this.#pending.get(alias);
82
86
  if (!resolvers) {
83
87
  resolvers = new Set();
84
88
  this.#pending.set(alias, resolvers);
85
89
  }
86
- resolvers.add(resolve);
87
- let timer;
88
- const timeout = new Promise((_, reject) => {
89
- timer = setTimeout(() => reject(new Error(`unknown track alias: ${alias}`)), TRACK_ALIAS_TIMEOUT_MS);
90
- });
90
+ resolvers.add(waiter);
91
91
  try {
92
- return await Promise.race([promise, timeout]);
92
+ return await timeout(TRACK_ALIAS_TIMEOUT, promise);
93
+ }
94
+ catch (err) {
95
+ if (err instanceof Elapsed)
96
+ throw new Error(`unknown track alias: ${alias}`);
97
+ throw err;
93
98
  }
94
99
  finally {
95
- clearTimeout(timer);
96
- resolvers.delete(resolve);
100
+ resolvers.delete(waiter);
97
101
  if (this.#pending.get(alias) === resolvers && resolvers.size === 0)
98
102
  this.#pending.delete(alias);
99
103
  }
100
104
  }
105
+ /** The alias's binding right now, without waiting for one. */
106
+ peek(alias) {
107
+ return this.#active.get(alias)?.value;
108
+ }
101
109
  /**
102
110
  * Establishes an alias and releases any data streams waiting for it.
103
111
  *
@@ -115,12 +123,12 @@ export class TrackAliases {
115
123
  }
116
124
  // Our subscription is gone, so the publisher is free to point the alias somewhere
117
125
  // new. Reclaiming it also drops the tombstone early.
118
- this.#forget(alias);
126
+ this.#retired.delete(alias);
119
127
  this.#active.set(alias, { value, track });
120
128
  const resolvers = this.#pending.get(alias);
121
129
  this.#pending.delete(alias);
122
- for (const resolve of resolvers ?? [])
123
- resolve(value);
130
+ for (const waiter of resolvers ?? [])
131
+ waiter.resolve(value);
124
132
  }
125
133
  /**
126
134
  * Retires an alias whose subscription was cancelled, so groups still in flight for it
@@ -133,26 +141,52 @@ export class TrackAliases {
133
141
  * only torn down by the owner and never out from under whoever reclaimed it.
134
142
  */
135
143
  retire(alias, value) {
136
- if (this.#active.get(alias)?.value !== value)
144
+ const active = this.#active.get(alias);
145
+ if (active?.value !== value)
137
146
  return false;
138
147
  this.#active.delete(alias);
139
- if (this.#retiredSet.has(alias))
140
- return true;
141
- this.#retiredSet.add(alias);
142
- this.#retired.push(alias);
143
- while (this.#retired.length > RETIRED_ALIAS_CAPACITY) {
144
- const oldest = this.#retired.shift();
145
- if (oldest !== undefined)
146
- this.#retiredSet.delete(oldest);
147
- }
148
+ this.#tombstone(alias, active.track);
148
149
  return true;
149
150
  }
150
- #forget(alias) {
151
- if (!this.#retiredSet.delete(alias))
151
+ /**
152
+ * Retires an alias whose SUBSCRIBE_OK we refused before binding it, so groups that overtook
153
+ * the answer are discarded, now and later, rather than left waiting for a binding that never
154
+ * comes, or handed to whichever track the publisher reuses the alias for next.
155
+ *
156
+ * A live binding outranks the refusal: the publisher may share the alias with a subscription
157
+ * we kept.
158
+ */
159
+ refuse(alias, track) {
160
+ if (this.#active.has(alias))
152
161
  return;
153
- const at = this.#retired.indexOf(alias);
154
- if (at !== -1)
155
- this.#retired.splice(at, 1);
162
+ this.#tombstone(alias, track);
163
+ const waiters = this.#pending.get(alias);
164
+ this.#pending.delete(alias);
165
+ for (const waiter of waiters ?? [])
166
+ waiter.reject(new RetiredTrackAlias(alias));
167
+ }
168
+ #tombstone(alias, track) {
169
+ this.#retired.delete(alias);
170
+ this.#retired.set(alias, track);
171
+ for (const oldest of this.#retired.keys()) {
172
+ if (this.#retired.size <= RETIRED_ALIAS_CAPACITY)
173
+ break;
174
+ this.#retired.delete(oldest);
175
+ }
176
+ }
177
+ /**
178
+ * Forgets the tombstones of a track we are subscribing to again.
179
+ *
180
+ * The publisher may answer the new SUBSCRIBE with the alias it used before (draft-22
181
+ * section 3.1.3), and the first group can overtake that SUBSCRIBE_OK. Without its tombstone
182
+ * the alias reads as unknown, so that group waits on the binding instead of being dropped as
183
+ * a straggler. Other tracks' tombstones stay, so their stragglers are still dropped at once.
184
+ */
185
+ resubscribe(track) {
186
+ for (const [alias, retired] of this.#retired) {
187
+ if (sameTrack(retired, track))
188
+ this.#retired.delete(alias);
189
+ }
156
190
  }
157
191
  }
158
192
  //# sourceMappingURL=aliases.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aliases.js","sourceRoot":"","sources":["../../src/ietf/aliases.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC;;;;;;;;;;GAUG;AACH,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAclC,SAAS,SAAS,CAAC,CAAgB,EAAE,CAAgB;IACpD,OAAO,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,KAAa;QACxB,KAAK,CAAC,wBAAwB,KAAK,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAC1C,YAAY,KAAa;QACxB,KAAK,CAAC,+CAA+C,KAAK,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IAChC,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,OAA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QAC5B,KAAK,MAAM,OAAO,IAAI,SAAS,IAAI,EAAE;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAa,EAAE,KAAQ;QAC7B,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC;QAC3D,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE3B,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAC7C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE1B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,sBAAsB,EAAE,CAAC;YACtD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACrC,IAAI,MAAM,KAAK,SAAS;gBAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO,CAAC,KAAa;QACpB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,OAAO;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACxC,IAAI,EAAE,KAAK,CAAC,CAAC;YAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;CACD","sourcesContent":["const TRACK_ALIAS_TIMEOUT_MS = 1000;\n\n/**\n * How many cancelled aliases to remember. Objects keep arriving for about a round trip\n * after we cancel, so a handful covers the window, while the cap keeps a long session with\n * heavy subscription churn from accumulating tombstones for its whole lifetime.\n *\n * The bound is a count rather than a deadline, so eviction stays synchronous with\n * retirement instead of needing a timer. The trade is that a session cancelling more than\n * this many distinct aliases inside one round trip evicts a tombstone whose objects are\n * still arriving; those fall back to the unknown-alias wait, which is the old behavior\n * rather than a new failure.\n */\nconst RETIRED_ALIAS_CAPACITY = 64;\n\ntype Resolver<T> = PromiseWithResolvers<T>[\"resolve\"];\n\n/**\n * The full track name an alias is bound to.\n *\n * Kept as two components rather than one joined string: a track name may contain the same\n * separator a broadcast path uses, so `a` + `b/c` and `a/b` + `c` would otherwise compare\n * equal and turn a genuine collision into apparent sharing.\n * @internal\n */\nexport type TrackIdentity = { broadcast: string; name: string };\n\nfunction sameTrack(a: TrackIdentity, b: TrackIdentity): boolean {\n\treturn a.broadcast === b.broadcast && a.name === b.name;\n}\n\n/**\n * Thrown when a group arrives for a subscription we already cancelled.\n *\n * The publisher only stops once our cancellation reaches it, so objects keep arriving for\n * at least a round trip afterwards. Draft-19 section 11.1 asks us to keep enough state to\n * discard them quickly \"rather than treating them as belonging to an unknown Track Alias\".\n *\n * This makes the window quiet, not safe. Once a publisher reassigns the alias the tombstone\n * is reclaimed, and nothing on a group stream distinguishes the old subscription's objects\n * from the new one's. Cancelling promptly is what bounds the exposure to a round trip.\n * @internal\n */\nexport class RetiredTrackAlias extends Error {\n\tconstructor(alias: bigint) {\n\t\tsuper(`track alias retired: ${alias}`);\n\t\tthis.name = \"RetiredTrackAlias\";\n\t}\n}\n\n/**\n * Thrown when a publisher gives one alias to two subscriptions of the same track.\n *\n * Draft-19 section 5.1 permits this and expects the subscriber to demux by re-applying\n * each subscription's filter. Ours are all LargestObject, so they are indistinguishable and\n * we cannot, which costs the one subscription. It is not a protocol error, so it must not\n * take the session down with it.\n * @internal\n */\nexport class SharedTrackAlias extends Error {\n\tconstructor(alias: bigint) {\n\t\tsuper(`track alias shared by another subscription: ${alias}`);\n\t\tthis.name = \"SharedTrackAlias\";\n\t}\n}\n\n/**\n * Thrown when a publisher points one alias at two different tracks at once, which\n * draft-19 section 11.1 makes fatal to the session.\n * @internal\n */\nexport class DuplicateTrackAlias extends Error {\n\tconstructor(alias: bigint) {\n\t\tsuper(`duplicate track alias: ${alias}`);\n\t\tthis.name = \"DuplicateTrackAlias\";\n\t}\n}\n\n/** Resolves publisher-chosen track aliases after control/data stream reordering. @internal */\nexport class TrackAliases<T> {\n\t#active = new Map<bigint, { value: T; track: TrackIdentity }>();\n\t#pending = new Map<bigint, Set<Resolver<T>>>();\n\n\t/** Aliases whose subscription we cancelled, in retirement order so the oldest is forgotten first. */\n\t#retired: bigint[] = [];\n\t#retiredSet = new Set<bigint>();\n\n\t/**\n\t * Waits briefly for an alias to be established by SUBSCRIBE_OK or PUBLISH.\n\t *\n\t * Throws {@link RetiredTrackAlias} at once for an alias we cancelled, rather than\n\t * waiting out the timeout for a binding that is never coming.\n\t */\n\tasync get(alias: bigint): Promise<T> {\n\t\tconst bound = this.#active.get(alias);\n\t\tif (bound !== undefined) return bound.value;\n\t\tif (this.#retiredSet.has(alias)) throw new RetiredTrackAlias(alias);\n\n\t\tconst { promise, resolve } = Promise.withResolvers<T>();\n\t\tlet resolvers = this.#pending.get(alias);\n\t\tif (!resolvers) {\n\t\t\tresolvers = new Set();\n\t\t\tthis.#pending.set(alias, resolvers);\n\t\t}\n\t\tresolvers.add(resolve);\n\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst timeout = new Promise<never>((_, reject) => {\n\t\t\ttimer = setTimeout(() => reject(new Error(`unknown track alias: ${alias}`)), TRACK_ALIAS_TIMEOUT_MS);\n\t\t});\n\n\t\ttry {\n\t\t\treturn await Promise.race([promise, timeout]);\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t\tresolvers.delete(resolve);\n\t\t\tif (this.#pending.get(alias) === resolvers && resolvers.size === 0) this.#pending.delete(alias);\n\t\t}\n\t}\n\n\t/**\n\t * Establishes an alias and releases any data streams waiting for it.\n\t *\n\t * `track` is the full track name the alias was bound to, which is what decides whether a\n\t * repeat is the legal sharing of an alias across subscriptions to one track\n\t * ({@link SharedTrackAlias}) or the collision that must fail the session\n\t * ({@link DuplicateTrackAlias}).\n\t */\n\tset(alias: bigint, value: T, track: TrackIdentity) {\n\t\tconst active = this.#active.get(alias);\n\t\tif (active !== undefined) {\n\t\t\tif (active.value === value) return;\n\t\t\tthrow sameTrack(active.track, track) ? new SharedTrackAlias(alias) : new DuplicateTrackAlias(alias);\n\t\t}\n\n\t\t// Our subscription is gone, so the publisher is free to point the alias somewhere\n\t\t// new. Reclaiming it also drops the tombstone early.\n\t\tthis.#forget(alias);\n\n\t\tthis.#active.set(alias, { value, track });\n\t\tconst resolvers = this.#pending.get(alias);\n\t\tthis.#pending.delete(alias);\n\t\tfor (const resolve of resolvers ?? []) resolve(value);\n\t}\n\n\t/**\n\t * Retires an alias whose subscription was cancelled, so groups still in flight for it\n\t * are discarded promptly instead of reported as unknown.\n\t *\n\t * Only retires an alias that still belongs to the supplied value: a later subscription\n\t * may already have reclaimed it, and that binding outranks a departing owner.\n\t *\n\t * Returns whether this caller still owned the binding, so metadata keyed by the alias is\n\t * only torn down by the owner and never out from under whoever reclaimed it.\n\t */\n\tretire(alias: bigint, value: T): boolean {\n\t\tif (this.#active.get(alias)?.value !== value) return false;\n\t\tthis.#active.delete(alias);\n\n\t\tif (this.#retiredSet.has(alias)) return true;\n\t\tthis.#retiredSet.add(alias);\n\t\tthis.#retired.push(alias);\n\n\t\twhile (this.#retired.length > RETIRED_ALIAS_CAPACITY) {\n\t\t\tconst oldest = this.#retired.shift();\n\t\t\tif (oldest !== undefined) this.#retiredSet.delete(oldest);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t#forget(alias: bigint) {\n\t\tif (!this.#retiredSet.delete(alias)) return;\n\t\tconst at = this.#retired.indexOf(alias);\n\t\tif (at !== -1) this.#retired.splice(at, 1);\n\t}\n}\n"]}
1
+ {"version":3,"file":"aliases.js","s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;CACD","sourcesContent":["import { Duration, Elapsed, timeout } from \"@moq/clock\";\n\nconst TRACK_ALIAS_TIMEOUT = Duration.millis(1000);\n\n/**\n * How many cancelled aliases to remember. Objects keep arriving for about a round trip\n * after we cancel, so a handful covers the window, while the cap keeps a long session with\n * heavy subscription churn from accumulating tombstones for its whole lifetime.\n *\n * The bound is a count rather than a deadline, so eviction stays synchronous with\n * retirement instead of needing a timer. The trade is that a session cancelling more than\n * this many distinct aliases inside one round trip evicts a tombstone whose objects are\n * still arriving; those fall back to the unknown-alias wait, which is the old behavior\n * rather than a new failure.\n */\nconst RETIRED_ALIAS_CAPACITY = 64;\n\ntype Waiter<T> = Pick<PromiseWithResolvers<T>, \"resolve\" | \"reject\">;\n\n/**\n * The full track name an alias is bound to.\n *\n * Kept as two components rather than one joined string: a track name may contain the same\n * separator a broadcast path uses, so `a` + `b/c` and `a/b` + `c` would otherwise compare\n * equal and turn a genuine collision into apparent sharing.\n * @internal\n */\nexport type TrackIdentity = { broadcast: string; name: string };\n\nfunction sameTrack(a: TrackIdentity, b: TrackIdentity): boolean {\n\treturn a.broadcast === b.broadcast && a.name === b.name;\n}\n\n/**\n * Thrown when a group arrives for a subscription we already cancelled.\n *\n * The publisher only stops once our cancellation reaches it, so objects keep arriving for\n * at least a round trip afterwards. Draft-22 section 3.1.3 asks us to keep enough state to\n * discard them quickly \"rather than treating them as belonging to an unknown Track Alias\".\n *\n * This makes the window quiet, not safe. Once a publisher reassigns the alias the tombstone\n * is reclaimed, and nothing on a group stream distinguishes the old subscription's objects\n * from the new one's. Cancelling promptly is what bounds the exposure to a round trip.\n * @internal\n */\nexport class RetiredTrackAlias extends Error {\n\tconstructor(alias: bigint) {\n\t\tsuper(`track alias retired: ${alias}`);\n\t\tthis.name = \"RetiredTrackAlias\";\n\t}\n}\n\n/**\n * Thrown when a publisher gives one alias to two subscriptions of the same track.\n *\n * Draft-22 section 3.1.3 permits this and expects the subscriber to demux by re-applying\n * each subscription's filter. Ours are all LargestObject, so they are indistinguishable and\n * we cannot, which costs the one subscription. It is not a protocol error, so it must not\n * take the session down with it.\n * @internal\n */\nexport class SharedTrackAlias extends Error {\n\tconstructor(alias: bigint) {\n\t\tsuper(`track alias shared by another subscription: ${alias}`);\n\t\tthis.name = \"SharedTrackAlias\";\n\t}\n}\n\n/**\n * Thrown when a publisher points one alias at two different tracks at once, which\n * draft-22 section 3.1.3 makes fatal to the session.\n * @internal\n */\nexport class DuplicateTrackAlias extends Error {\n\tconstructor(alias: bigint) {\n\t\tsuper(`duplicate track alias: ${alias}`);\n\t\tthis.name = \"DuplicateTrackAlias\";\n\t}\n}\n\n/** Resolves publisher-chosen track aliases after control/data stream reordering. @internal */\nexport class TrackAliases<T> {\n\t#active = new Map<bigint, { value: T; track: TrackIdentity }>();\n\t#pending = new Map<bigint, Set<Waiter<T>>>();\n\n\t/**\n\t * Aliases whose subscription we cancelled, with the track each served, in retirement order\n\t * (a Map iterates by insertion) so the oldest is forgotten first.\n\t */\n\t#retired = new Map<bigint, TrackIdentity>();\n\n\t/**\n\t * Waits briefly for an alias to be established by SUBSCRIBE_OK or PUBLISH.\n\t *\n\t * Throws {@link RetiredTrackAlias} at once for an alias we cancelled, rather than\n\t * waiting out the timeout for a binding that is never coming.\n\t */\n\tasync get(alias: bigint): Promise<T> {\n\t\tconst bound = this.#active.get(alias);\n\t\tif (bound !== undefined) return bound.value;\n\t\tif (this.#retired.has(alias)) throw new RetiredTrackAlias(alias);\n\n\t\tconst { promise, resolve, reject } = Promise.withResolvers<T>();\n\t\tconst waiter = { resolve, reject };\n\t\tlet resolvers = this.#pending.get(alias);\n\t\tif (!resolvers) {\n\t\t\tresolvers = new Set();\n\t\t\tthis.#pending.set(alias, resolvers);\n\t\t}\n\t\tresolvers.add(waiter);\n\n\t\ttry {\n\t\t\treturn await timeout(TRACK_ALIAS_TIMEOUT, promise);\n\t\t} catch (err) {\n\t\t\tif (err instanceof Elapsed) throw new Error(`unknown track alias: ${alias}`);\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tresolvers.delete(waiter);\n\t\t\tif (this.#pending.get(alias) === resolvers && resolvers.size === 0) this.#pending.delete(alias);\n\t\t}\n\t}\n\n\t/** The alias's binding right now, without waiting for one. */\n\tpeek(alias: bigint): T | undefined {\n\t\treturn this.#active.get(alias)?.value;\n\t}\n\n\t/**\n\t * Establishes an alias and releases any data streams waiting for it.\n\t *\n\t * `track` is the full track name the alias was bound to, which is what decides whether a\n\t * repeat is the legal sharing of an alias across subscriptions to one track\n\t * ({@link SharedTrackAlias}) or the collision that must fail the session\n\t * ({@link DuplicateTrackAlias}).\n\t */\n\tset(alias: bigint, value: T, track: TrackIdentity) {\n\t\tconst active = this.#active.get(alias);\n\t\tif (active !== undefined) {\n\t\t\tif (active.value === value) return;\n\t\t\tthrow sameTrack(active.track, track) ? new SharedTrackAlias(alias) : new DuplicateTrackAlias(alias);\n\t\t}\n\n\t\t// Our subscription is gone, so the publisher is free to point the alias somewhere\n\t\t// new. Reclaiming it also drops the tombstone early.\n\t\tthis.#retired.delete(alias);\n\n\t\tthis.#active.set(alias, { value, track });\n\t\tconst resolvers = this.#pending.get(alias);\n\t\tthis.#pending.delete(alias);\n\t\tfor (const waiter of resolvers ?? []) waiter.resolve(value);\n\t}\n\n\t/**\n\t * Retires an alias whose subscription was cancelled, so groups still in flight for it\n\t * are discarded promptly instead of reported as unknown.\n\t *\n\t * Only retires an alias that still belongs to the supplied value: a later subscription\n\t * may already have reclaimed it, and that binding outranks a departing owner.\n\t *\n\t * Returns whether this caller still owned the binding, so metadata keyed by the alias is\n\t * only torn down by the owner and never out from under whoever reclaimed it.\n\t */\n\tretire(alias: bigint, value: T): boolean {\n\t\tconst active = this.#active.get(alias);\n\t\tif (active?.value !== value) return false;\n\t\tthis.#active.delete(alias);\n\t\tthis.#tombstone(alias, active.track);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Retires an alias whose SUBSCRIBE_OK we refused before binding it, so groups that overtook\n\t * the answer are discarded, now and later, rather than left waiting for a binding that never\n\t * comes, or handed to whichever track the publisher reuses the alias for next.\n\t *\n\t * A live binding outranks the refusal: the publisher may share the alias with a subscription\n\t * we kept.\n\t */\n\trefuse(alias: bigint, track: TrackIdentity) {\n\t\tif (this.#active.has(alias)) return;\n\t\tthis.#tombstone(alias, track);\n\t\tconst waiters = this.#pending.get(alias);\n\t\tthis.#pending.delete(alias);\n\t\tfor (const waiter of waiters ?? []) waiter.reject(new RetiredTrackAlias(alias));\n\t}\n\n\t#tombstone(alias: bigint, track: TrackIdentity) {\n\t\tthis.#retired.delete(alias);\n\t\tthis.#retired.set(alias, track);\n\t\tfor (const oldest of this.#retired.keys()) {\n\t\t\tif (this.#retired.size <= RETIRED_ALIAS_CAPACITY) break;\n\t\t\tthis.#retired.delete(oldest);\n\t\t}\n\t}\n\n\t/**\n\t * Forgets the tombstones of a track we are subscribing to again.\n\t *\n\t * The publisher may answer the new SUBSCRIBE with the alias it used before (draft-22\n\t * section 3.1.3), and the first group can overtake that SUBSCRIBE_OK. Without its tombstone\n\t * the alias reads as unknown, so that group waits on the binding instead of being dropped as\n\t * a straggler. Other tracks' tombstones stay, so their stragglers are still dropped at once.\n\t */\n\tresubscribe(track: TrackIdentity) {\n\t\tfor (const [alias, retired] of this.#retired) {\n\t\t\tif (sameTrack(retired, track)) this.#retired.delete(alias);\n\t\t}\n\t}\n}\n"]}
package/ietf/cluster.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The MoQ Cluster extension (draft-lcurley-moq-cluster-01).
2
+ * The MoQ Cluster extension (draft-lcurley-moq-cluster).
3
3
  *
4
4
  * moq-transport carries no routing information, so a peer cannot tell whether an
5
5
  * advertisement already passed through us. This extension adds it:
@@ -11,11 +11,11 @@
11
11
  * and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.
12
12
  *
13
13
  * These are the semantics moq-lite carries natively on every announcement (see
14
- * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+
14
+ * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-18+
15
15
  * only, where SETUP is a Key-Value-Pair block.
16
16
  *
17
17
  * A broadcast we produce carries a single-entry HOP_PATH and a cost of 0, and a route we
18
- * forward carries its own hop chain and warm cost with our id appended. What we get out of
18
+ * forward carries its own hop chain and static cost with our id appended. What we get out of
19
19
  * declaring is also the other direction. A relay that knows our Hop ID withholds the advertisements that already flowed
20
20
  * through us, so publishing a broadcast no longer announces it back to us, which is what
21
21
  * moq-lite has always done with its own hop chain.
package/ietf/cluster.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The MoQ Cluster extension (draft-lcurley-moq-cluster-01).
2
+ * The MoQ Cluster extension (draft-lcurley-moq-cluster).
3
3
  *
4
4
  * moq-transport carries no routing information, so a peer cannot tell whether an
5
5
  * advertisement already passed through us. This extension adds it:
@@ -11,11 +11,11 @@
11
11
  * and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.
12
12
  *
13
13
  * These are the semantics moq-lite carries natively on every announcement (see
14
- * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+
14
+ * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-18+
15
15
  * only, where SETUP is a Key-Value-Pair block.
16
16
  *
17
17
  * A broadcast we produce carries a single-entry HOP_PATH and a cost of 0, and a route we
18
- * forward carries its own hop chain and warm cost with our id appended. What we get out of
18
+ * forward carries its own hop chain and static cost with our id appended. What we get out of
19
19
  * declaring is also the other direction. A relay that knows our Hop ID withholds the advertisements that already flowed
20
20
  * through us, so publishing a broadcast no longer announces it back to us, which is what
21
21
  * moq-lite has always done with its own hop chain.
@@ -24,44 +24,27 @@
24
24
  * @internal
25
25
  */
26
26
  import { ProtocolViolation, reason } from "../error.js";
27
- import { HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.js";
27
+ import { MAX_HOPS, toHop, UNKNOWN_HOP } from "../hop.js";
28
28
  import * as Varint from "../varint.js";
29
- import { Parameters, SetupOption } from "./parameters.js";
30
- import { Version } from "./version.js";
31
- /**
32
- * Whether a version can negotiate the extension.
33
- *
34
- * Draft-17 is the first with the unified SETUP: a bare Key-Value-Pair block that a new
35
- * option slots into without touching the message shape. Earlier drafts exchange SETUP over
36
- * the legacy control stream, which this extension does not cover.
37
- *
38
- * @internal
39
- */
40
- export function supported(version) {
41
- return version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16;
42
- }
29
+ import { SetupOption } from "./setup_options.js";
43
30
  /**
44
31
  * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.
45
32
  *
46
33
  * @internal
47
34
  */
48
- export function fromSetup(params, version) {
49
- if (!supported(version))
50
- return undefined;
35
+ export function fromSetup(params) {
51
36
  // 0 is legal: the peer speaks the extension but withholds its identity.
52
37
  const value = params.getVarint(SetupOption.HopId);
53
38
  if (value === undefined)
54
39
  return undefined;
55
- return fromWire(value);
40
+ return toHop(value);
56
41
  }
57
42
  /**
58
43
  * Declare our own Hop ID, which is also what negotiates the extension.
59
44
  *
60
45
  * @internal
61
46
  */
62
- export function intoSetup(params, self, version) {
63
- if (!supported(version))
64
- return;
47
+ export function intoSetup(params, self) {
65
48
  params.setVarint(SetupOption.HopId, self);
66
49
  }
67
50
  /**
@@ -102,31 +85,27 @@ export function loops(advert, self) {
102
85
  return self !== UNKNOWN_HOP && advert.hops.includes(self);
103
86
  }
104
87
  /**
105
- * Write an advertisement's parameters, ready to encode onto the wire.
88
+ * Write an advertisement's parameters into `params`, ready to encode onto the wire.
106
89
  *
107
90
  * @internal
108
91
  */
109
- export function intoParams(advert) {
110
- const params = new Parameters();
92
+ export function intoParams(advert, params) {
111
93
  params.hopPath = encodeHops(advert.hops);
112
94
  // Absent means 0, so a free path sends nothing.
113
95
  if (advert.cost !== 0n)
114
96
  params.routeCost = advert.cost;
115
- return params;
116
97
  }
117
98
  /**
118
- * Write a REQUEST_UPDATE's parameters: only what changed, and a cost of 0 explicitly,
119
- * since an omitted parameter keeps its value.
99
+ * Write a REQUEST_UPDATE's parameters into `params`: only what changed, and a cost of 0
100
+ * explicitly, since an omitted parameter keeps its value.
120
101
  *
121
102
  * @internal
122
103
  */
123
- export function updateIntoParams(update) {
124
- const params = new Parameters();
104
+ export function updateIntoParams(update, params) {
125
105
  if (update.hops !== undefined)
126
106
  params.hopPath = encodeHops(update.hops);
127
107
  if (update.cost !== undefined)
128
108
  params.routeCost = update.cost;
129
- return params;
130
109
  }
131
110
  /** Write a HOP_PATH value: the entries fill it with no count of their own, framed by the
132
111
  * parameter's own length prefix. */
@@ -141,25 +120,6 @@ function encodeHops(hops) {
141
120
  }
142
121
  return value;
143
122
  }
144
- /**
145
- * Read the parameters a negotiated session puts on every advertisement.
146
- *
147
- * The parameter block is mandatory there, so a message that ends before it (the base form)
148
- * or one whose block does not parse is the peer's violation, same as a block that parses but
149
- * carries no HOP_PATH.
150
- *
151
- * @internal
152
- */
153
- export async function decodeParams(r, version) {
154
- let params;
155
- try {
156
- params = await Parameters.decode(r, version);
157
- }
158
- catch (err) {
159
- throw new ProtocolViolation(reason(err), { cause: err });
160
- }
161
- return fromParams(params);
162
- }
163
123
  /**
164
124
  * Read an advertisement out of a decoded parameter block.
165
125
  *
@@ -204,14 +164,6 @@ export function updateFromParams(params) {
204
164
  export function apply(held, update) {
205
165
  return { hops: update.hops ?? held.hops, cost: update.cost ?? held.cost };
206
166
  }
207
- /**
208
- * Read a Hop ID off the wire. The draft gives it the full 64-bit varint range, but a
209
- * {@link Hop} on this release line is 62 bits, so a wider id reads as {@link UNKNOWN_HOP}:
210
- * it identifies nothing, which costs loop detection through that hop instead of the session.
211
- */
212
- function fromWire(value) {
213
- return value >= 1n << 62n ? UNKNOWN_HOP : HopSchema.parse(value);
214
- }
215
167
  /** Read a HOP_PATH value: bare varints filling the parameter, with no count of their own. */
216
168
  function decodeHops(value) {
217
169
  const hops = [];
@@ -219,7 +171,7 @@ function decodeHops(value) {
219
171
  while (rest.length > 0) {
220
172
  // A short read here means the entries did not exactly fill the length.
221
173
  const [hop, remain] = Varint.decodeLeadingOnes(rest);
222
- hops.push(fromWire(hop));
174
+ hops.push(toHop(hop));
223
175
  rest = remain;
224
176
  // Bail before the buffer does: a hostile length would otherwise cost us one
225
177
  // allocation per entry all the way to 64KB of parameter value.
@@ -1 +1 @@
1
- {"version":3,"file":"cluster.js","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAY,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEvE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAqB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAoB,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,OAAoB;IAC7C,OAAO,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC;AACrG,CAAC;AAuDD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,OAAoB;IACnE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAE1C,wEAAwE;IACxE,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,IAAS,EAAE,OAAoB;IAC9E,IAAI,CAAC,SAAS,CA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C;IAClG,CAAC;AACF,CAAC","sourcesContent":["/**\n * The MoQ Cluster extension (draft-lcurley-moq-cluster-01).\n *\n * moq-transport carries no routing information, so a peer cannot tell whether an\n * advertisement already passed through us. This extension adds it:\n *\n * - each endpoint declares its own Hop ID via the HOP_ID Setup Option, which is also what\n * negotiates the extension;\n * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST\n * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE,\n * and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.\n *\n * These are the semantics moq-lite carries natively on every announcement (see\n * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+\n * only, where SETUP is a Key-Value-Pair block.\n *\n * A broadcast we produce carries a single-entry HOP_PATH and a cost of 0, and a route we\n * forward carries its own hop chain and warm cost with our id appended. What we get out of\n * declaring is also the other direction. A relay that knows our Hop ID withholds the advertisements that already flowed\n * through us, so publishing a broadcast no longer announces it back to us, which is what\n * moq-lite has always done with its own hop chain.\n *\n * @module\n * @internal\n */\n\nimport { ProtocolViolation, reason } from \"../error.ts\";\nimport { type Hop, HopSchema, MAX_HOPS, UNKNOWN_HOP } from \"../hop.ts\";\nimport type { Reader } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { Parameters, SetupOption, type SetupOptions } from \"./parameters.ts\";\nimport { type IetfVersion, Version } from \"./version.ts\";\n\n/**\n * Whether a version can negotiate the extension.\n *\n * Draft-17 is the first with the unified SETUP: a bare Key-Value-Pair block that a new\n * option slots into without touching the message shape. Earlier drafts exchange SETUP over\n * the legacy control stream, which this extension does not cover.\n *\n * @internal\n */\nexport function supported(version: IetfVersion): boolean {\n\treturn version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16;\n}\n\n/**\n * The Hop IDs this session declared, one per direction.\n *\n * @internal\n */\nexport interface Hops {\n\t/** Our own Hop ID, declared in SETUP and stamped onto every advertisement we send. */\n\tself: Hop;\n\n\t/**\n\t * The peer's Hop ID, or `undefined` when it declared no HOP_ID.\n\t *\n\t * This is what decides whether advertisements carry the parameters at all, in both\n\t * directions: a peer that declared nothing has not read ours either, so sending it a\n\t * HOP_PATH would be a protocol violation and expecting one back would reject a legal\n\t * message. A peer that declared the reserved 0 negotiated the extension but withheld its\n\t * identity, so the parameters flow and there is simply nothing to exclude.\n\t */\n\tpeer?: Hop;\n}\n\n/**\n * The cluster parameters carried on one advertisement.\n *\n * Present on every PUBLISH_NAMESPACE and NAMESPACE of a session that negotiated the\n * extension, and on none of a session that did not.\n *\n * @internal\n */\nexport interface Advert {\n\t/** HOP_PATH: the path this advertisement traversed, publisher first, sender last. */\n\thops: Hop[];\n\n\t/** ROUTE_COST: the marginal cost of subscribing via this advertisement. Absent on the\n\t * wire means 0, so an endpoint that prices nothing sends nothing. */\n\tcost: bigint;\n}\n\n/**\n * The cluster parameters a REQUEST_UPDATE on a PUBLISH_NAMESPACE carries: only what\n * changed, since an omitted parameter keeps its value.\n *\n * @internal\n */\nexport interface Update {\n\t/** HOP_PATH, when the route changed. */\n\thops?: Hop[];\n\n\t/** ROUTE_COST, when the cost changed. A cost that dropped to 0 arrives as an explicit\n\t * 0 here, unlike the advertisement itself where absent means 0. */\n\tcost?: bigint;\n}\n\n/**\n * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.\n *\n * @internal\n */\nexport function fromSetup(params: SetupOptions, version: IetfVersion): Hop | undefined {\n\tif (!supported(version)) return undefined;\n\n\t// 0 is legal: the peer speaks the extension but withholds its identity.\n\tconst value = params.getVarint(SetupOption.HopId);\n\tif (value === undefined) return undefined;\n\treturn fromWire(value);\n}\n\n/**\n * Declare our own Hop ID, which is also what negotiates the extension.\n *\n * @internal\n */\nexport function intoSetup(params: SetupOptions, self: Hop, version: IetfVersion) {\n\tif (!supported(version)) return;\n\tparams.setVarint(SetupOption.HopId, self);\n}\n\n/**\n * Whether the session negotiated the extension, which is what decides whether an\n * advertisement carries the parameters in either direction.\n *\n * @internal\n */\nexport function negotiated(ids: Hops | undefined): boolean {\n\treturn ids?.peer !== undefined;\n}\n\n/**\n * The advertisement to send for one of our own broadcasts, or `undefined` on a session\n * that negotiated nothing.\n *\n * The sender's own Hop ID is always the last entry, so a receiver reconstructs the full\n * path without the sender restating it. We originate everything we advertise, so the path\n * is just us and the cost is 0: a subscription costs the peer nothing but the transfer,\n * since we are already producing the content.\n *\n * @internal\n */\nexport function advertise(ids: Hops | undefined): Advert | undefined {\n\tif (ids === undefined || ids.peer === undefined) return undefined;\n\treturn { hops: [ids.self], cost: 0n };\n}\n\n/**\n * Whether this advertisement looped back through `self`.\n *\n * A receiver discards such an advertisement: forwarding it would extend the loop, and\n * subscribing through it would route the receiver back to itself. Hop ID 0 identifies\n * nothing, so a receiver that withheld its own identity detects nothing.\n *\n * @internal\n */\nexport function loops(advert: Advert, self: Hop): boolean {\n\treturn self !== UNKNOWN_HOP && advert.hops.includes(self);\n}\n\n/**\n * Write an advertisement's parameters, ready to encode onto the wire.\n *\n * @internal\n */\nexport function intoParams(advert: Advert): Parameters {\n\tconst params = new Parameters();\n\tparams.hopPath = encodeHops(advert.hops);\n\n\t// Absent means 0, so a free path sends nothing.\n\tif (advert.cost !== 0n) params.routeCost = advert.cost;\n\n\treturn params;\n}\n\n/**\n * Write a REQUEST_UPDATE's parameters: only what changed, and a cost of 0 explicitly,\n * since an omitted parameter keeps its value.\n *\n * @internal\n */\nexport function updateIntoParams(update: Update): Parameters {\n\tconst params = new Parameters();\n\tif (update.hops !== undefined) params.hopPath = encodeHops(update.hops);\n\tif (update.cost !== undefined) params.routeCost = update.cost;\n\treturn params;\n}\n\n/** Write a HOP_PATH value: the entries fill it with no count of their own, framed by the\n * parameter's own length prefix. */\nfunction encodeHops(hops: Hop[]): Uint8Array {\n\tvalidate(hops);\n\n\tconst encoded = hops.map((hop) => Varint.encodeLeadingOnes(hop));\n\tconst value = new Uint8Array(encoded.reduce((total, hop) => total + hop.length, 0));\n\tlet offset = 0;\n\tfor (const hop of encoded) {\n\t\tvalue.set(hop, offset);\n\t\toffset += hop.length;\n\t}\n\treturn value;\n}\n\n/**\n * Read the parameters a negotiated session puts on every advertisement.\n *\n * The parameter block is mandatory there, so a message that ends before it (the base form)\n * or one whose block does not parse is the peer's violation, same as a block that parses but\n * carries no HOP_PATH.\n *\n * @internal\n */\nexport async function decodeParams(r: Reader, version: IetfVersion): Promise<Advert> {\n\tlet params: Parameters;\n\ttry {\n\t\tparams = await Parameters.decode(r, version);\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n\n\treturn fromParams(params);\n}\n\n/**\n * Read an advertisement out of a decoded parameter block.\n *\n * Every way this fails is one the draft says to close the session over: a negotiated session\n * that omits HOP_PATH, entries that do not exactly fill the parameter, an empty list, or a\n * non-zero Hop ID appearing twice. So they all surface as one {@link ProtocolViolation},\n * which the session dispatch acts on.\n *\n * @internal\n */\nexport function fromParams(params: Parameters): Advert {\n\ttry {\n\t\tconst value = params.hopPath;\n\t\tif (value === undefined) throw new Error(\"advertisement is missing HOP_PATH\");\n\t\treturn { hops: decodeHops(value), cost: params.routeCost ?? 0n };\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n}\n\n/**\n * Read a REQUEST_UPDATE's parameters: each is optional, and a malformed HOP_PATH is the\n * same violation it is on an advertisement.\n *\n * @internal\n */\nexport function updateFromParams(params: Parameters): Update {\n\ttry {\n\t\tconst value = params.hopPath;\n\t\treturn { hops: value === undefined ? undefined : decodeHops(value), cost: params.routeCost };\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n}\n\n/**\n * The advertisement after `update` lands on `held`: an omitted parameter keeps its value.\n *\n * @internal\n */\nexport function apply(held: Advert, update: Update): Advert {\n\treturn { hops: update.hops ?? held.hops, cost: update.cost ?? held.cost };\n}\n\n/**\n * Read a Hop ID off the wire. The draft gives it the full 64-bit varint range, but a\n * {@link Hop} on this release line is 62 bits, so a wider id reads as {@link UNKNOWN_HOP}:\n * it identifies nothing, which costs loop detection through that hop instead of the session.\n */\nfunction fromWire(value: bigint): Hop {\n\treturn value >= 1n << 62n ? UNKNOWN_HOP : HopSchema.parse(value);\n}\n\n/** Read a HOP_PATH value: bare varints filling the parameter, with no count of their own. */\nfunction decodeHops(value: Uint8Array): Hop[] {\n\tconst hops: Hop[] = [];\n\tlet rest = value;\n\twhile (rest.length > 0) {\n\t\t// A short read here means the entries did not exactly fill the length.\n\t\tconst [hop, remain] = Varint.decodeLeadingOnes(rest);\n\t\thops.push(fromWire(hop));\n\t\trest = remain;\n\n\t\t// Bail before the buffer does: a hostile length would otherwise cost us one\n\t\t// allocation per entry all the way to 64KB of parameter value.\n\t\tif (hops.length > MAX_HOPS) throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);\n\t}\n\n\tvalidate(hops);\n\treturn hops;\n}\n\n/**\n * Reject a path that cannot have come from a conforming sender: an empty list, one longer\n * than we accept, or a non-zero Hop ID appearing twice (a loop). Duplicate zeros are legal,\n * since 0 identifies nothing.\n */\nfunction validate(hops: Hop[]) {\n\tif (hops.length === 0) throw new Error(\"hop path is empty\");\n\tif (hops.length > MAX_HOPS) throw new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\n\t// MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.\n\tfor (let i = 0; i < hops.length; i++) {\n\t\tconst hop = hops[i];\n\t\tif (hop === UNKNOWN_HOP) continue;\n\t\tif (hops.indexOf(hop, i + 1) !== -1) throw new Error(`hop ${hop} appears twice in the hop path`);\n\t}\n}\n"]}
1
+ {"version":3,"file":"cluster.js","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAY,QAAQ,EAAE,KAAK,EAAE,WAAW,EA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,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QACtB,IAAI,GAAG,MAAM,CAAC;QAEd,4EAA4E;QAC5E,+DAA+D;QAC/D,IAAI,IAAI,CAAC,MAAM,GAAG,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;IACtF,CAAC;IAED,QAAQ,CAAC,IAAI,CAAC,CAAC;IACf,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAW;IAC5B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC5D,IAAI,IAAI,CAAC,MAAM,GAAG,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,MAAM,oBAAoB,QAAQ,EAAE,CAAC,CAAC;IAEpG,0EAA0E;IAC1E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,GAAG,KAAK,WAAW;YAAE,SAAS;QAClC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,gCAAgC,CAAC,CAAC;IAClG,CAAC;AACF,CAAC","sourcesContent":["/**\n * The MoQ Cluster extension (draft-lcurley-moq-cluster).\n *\n * moq-transport carries no routing information, so a peer cannot tell whether an\n * advertisement already passed through us. This extension adds it:\n *\n * - each endpoint declares its own Hop ID via the HOP_ID Setup Option, which is also what\n * negotiates the extension;\n * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST\n * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE,\n * and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.\n *\n * These are the semantics moq-lite carries natively on every announcement (see\n * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-18+\n * only, where SETUP is a Key-Value-Pair block.\n *\n * A broadcast we produce carries a single-entry HOP_PATH and a cost of 0, and a route we\n * forward carries its own hop chain and static cost with our id appended. What we get out of\n * declaring is also the other direction. A relay that knows our Hop ID withholds the advertisements that already flowed\n * through us, so publishing a broadcast no longer announces it back to us, which is what\n * moq-lite has always done with its own hop chain.\n *\n * @module\n * @internal\n */\n\nimport { ProtocolViolation, reason } from \"../error.ts\";\nimport { type Hop, MAX_HOPS, toHop, UNKNOWN_HOP } from \"../hop.ts\";\nimport * as Varint from \"../varint.ts\";\n// Type-only: SETUP loads eagerly and must not pull in the message parameter codec.\nimport type { Parameters } from \"./parameters.ts\";\nimport { SetupOption, type SetupOptions } from \"./setup_options.ts\";\n\n/**\n * The Hop IDs this session declared, one per direction.\n *\n * @internal\n */\nexport interface Hops {\n\t/** Our own Hop ID, declared in SETUP and stamped onto every advertisement we send. */\n\tself: Hop;\n\n\t/**\n\t * The peer's Hop ID, or `undefined` when it declared no HOP_ID.\n\t *\n\t * This is what decides whether advertisements carry the parameters at all, in both\n\t * directions: a peer that declared nothing has not read ours either, so sending it a\n\t * HOP_PATH would be a protocol violation and expecting one back would reject a legal\n\t * message. A peer that declared the reserved 0 negotiated the extension but withheld its\n\t * identity, so the parameters flow and there is simply nothing to exclude.\n\t */\n\tpeer?: Hop;\n}\n\n/**\n * The cluster parameters carried on one advertisement.\n *\n * Present on every PUBLISH_NAMESPACE and NAMESPACE of a session that negotiated the\n * extension, and on none of a session that did not.\n *\n * @internal\n */\nexport interface Advert {\n\t/** HOP_PATH: the path this advertisement traversed, publisher first, sender last. */\n\thops: Hop[];\n\n\t/** ROUTE_COST: the marginal cost of subscribing via this advertisement. Absent on the\n\t * wire means 0, so an endpoint that prices nothing sends nothing. */\n\tcost: bigint;\n}\n\n/**\n * The cluster parameters a REQUEST_UPDATE on a PUBLISH_NAMESPACE carries: only what\n * changed, since an omitted parameter keeps its value.\n *\n * @internal\n */\nexport interface Update {\n\t/** HOP_PATH, when the route changed. */\n\thops?: Hop[];\n\n\t/** ROUTE_COST, when the cost changed. A cost that dropped to 0 arrives as an explicit\n\t * 0 here, unlike the advertisement itself where absent means 0. */\n\tcost?: bigint;\n}\n\n/**\n * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.\n *\n * @internal\n */\nexport function fromSetup(params: SetupOptions): Hop | undefined {\n\t// 0 is legal: the peer speaks the extension but withholds its identity.\n\tconst value = params.getVarint(SetupOption.HopId);\n\tif (value === undefined) return undefined;\n\treturn toHop(value);\n}\n\n/**\n * Declare our own Hop ID, which is also what negotiates the extension.\n *\n * @internal\n */\nexport function intoSetup(params: SetupOptions, self: Hop) {\n\tparams.setVarint(SetupOption.HopId, self);\n}\n\n/**\n * Whether the session negotiated the extension, which is what decides whether an\n * advertisement carries the parameters in either direction.\n *\n * @internal\n */\nexport function negotiated(ids: Hops | undefined): boolean {\n\treturn ids?.peer !== undefined;\n}\n\n/**\n * The advertisement to send for one of our own broadcasts, or `undefined` on a session\n * that negotiated nothing.\n *\n * The sender's own Hop ID is always the last entry, so a receiver reconstructs the full\n * path without the sender restating it. We originate everything we advertise, so the path\n * is just us and the cost is 0: a subscription costs the peer nothing but the transfer,\n * since we are already producing the content.\n *\n * @internal\n */\nexport function advertise(ids: Hops | undefined): Advert | undefined {\n\tif (ids === undefined || ids.peer === undefined) return undefined;\n\treturn { hops: [ids.self], cost: 0n };\n}\n\n/**\n * Whether this advertisement looped back through `self`.\n *\n * A receiver discards such an advertisement: forwarding it would extend the loop, and\n * subscribing through it would route the receiver back to itself. Hop ID 0 identifies\n * nothing, so a receiver that withheld its own identity detects nothing.\n *\n * @internal\n */\nexport function loops(advert: Advert, self: Hop): boolean {\n\treturn self !== UNKNOWN_HOP && advert.hops.includes(self);\n}\n\n/**\n * Write an advertisement's parameters into `params`, ready to encode onto the wire.\n *\n * @internal\n */\nexport function intoParams(advert: Advert, params: Parameters) {\n\tparams.hopPath = encodeHops(advert.hops);\n\n\t// Absent means 0, so a free path sends nothing.\n\tif (advert.cost !== 0n) params.routeCost = advert.cost;\n}\n\n/**\n * Write a REQUEST_UPDATE's parameters into `params`: only what changed, and a cost of 0\n * explicitly, since an omitted parameter keeps its value.\n *\n * @internal\n */\nexport function updateIntoParams(update: Update, params: Parameters) {\n\tif (update.hops !== undefined) params.hopPath = encodeHops(update.hops);\n\tif (update.cost !== undefined) params.routeCost = update.cost;\n}\n\n/** Write a HOP_PATH value: the entries fill it with no count of their own, framed by the\n * parameter's own length prefix. */\nfunction encodeHops(hops: Hop[]): Uint8Array {\n\tvalidate(hops);\n\n\tconst encoded = hops.map((hop) => Varint.encodeLeadingOnes(hop));\n\tconst value = new Uint8Array(encoded.reduce((total, hop) => total + hop.length, 0));\n\tlet offset = 0;\n\tfor (const hop of encoded) {\n\t\tvalue.set(hop, offset);\n\t\toffset += hop.length;\n\t}\n\treturn value;\n}\n\n/**\n * Read an advertisement out of a decoded parameter block.\n *\n * Every way this fails is one the draft says to close the session over: a negotiated session\n * that omits HOP_PATH, entries that do not exactly fill the parameter, an empty list, or a\n * non-zero Hop ID appearing twice. So they all surface as one {@link ProtocolViolation},\n * which the session dispatch acts on.\n *\n * @internal\n */\nexport function fromParams(params: Parameters): Advert {\n\ttry {\n\t\tconst value = params.hopPath;\n\t\tif (value === undefined) throw new Error(\"advertisement is missing HOP_PATH\");\n\t\treturn { hops: decodeHops(value), cost: params.routeCost ?? 0n };\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n}\n\n/**\n * Read a REQUEST_UPDATE's parameters: each is optional, and a malformed HOP_PATH is the\n * same violation it is on an advertisement.\n *\n * @internal\n */\nexport function updateFromParams(params: Parameters): Update {\n\ttry {\n\t\tconst value = params.hopPath;\n\t\treturn { hops: value === undefined ? undefined : decodeHops(value), cost: params.routeCost };\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n}\n\n/**\n * The advertisement after `update` lands on `held`: an omitted parameter keeps its value.\n *\n * @internal\n */\nexport function apply(held: Advert, update: Update): Advert {\n\treturn { hops: update.hops ?? held.hops, cost: update.cost ?? held.cost };\n}\n\n/** Read a HOP_PATH value: bare varints filling the parameter, with no count of their own. */\nfunction decodeHops(value: Uint8Array): Hop[] {\n\tconst hops: Hop[] = [];\n\tlet rest = value;\n\twhile (rest.length > 0) {\n\t\t// A short read here means the entries did not exactly fill the length.\n\t\tconst [hop, remain] = Varint.decodeLeadingOnes(rest);\n\t\thops.push(toHop(hop));\n\t\trest = remain;\n\n\t\t// Bail before the buffer does: a hostile length would otherwise cost us one\n\t\t// allocation per entry all the way to 64KB of parameter value.\n\t\tif (hops.length > MAX_HOPS) throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);\n\t}\n\n\tvalidate(hops);\n\treturn hops;\n}\n\n/**\n * Reject a path that cannot have come from a conforming sender: an empty list, one longer\n * than we accept, or a non-zero Hop ID appearing twice (a loop). Duplicate zeros are legal,\n * since 0 identifies nothing.\n */\nfunction validate(hops: Hop[]) {\n\tif (hops.length === 0) throw new Error(\"hop path is empty\");\n\tif (hops.length > MAX_HOPS) throw new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\n\t// MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.\n\tfor (let i = 0; i < hops.length; i++) {\n\t\tconst hop = hops[i];\n\t\tif (hop === UNKNOWN_HOP) continue;\n\t\tif (hops.indexOf(hop, i + 1) !== -1) throw new Error(`hop ${hop} appears twice in the hop path`);\n\t}\n}\n"]}
@@ -1,32 +1,2 @@
1
- import { type Getter } from "@moq/signals";
2
- import type * as announce from "../announced.ts";
3
- import type { Established } from "../connection/established.ts";
4
- import { type Probe, type Stats } from "../connection/stats.ts";
5
- import { type Transport } from "../connection/transport.ts";
6
- import type * as Path from "../path.ts";
7
- /**
8
- * Represents a connection to a MoQ server using moq-transport protocol.
9
- *
10
- * @public
11
- */
12
- export declare class Connection implements Established {
13
- #private;
14
- readonly url: URL;
15
- readonly version: string;
16
- readonly transport: Transport;
17
- /** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */
18
- readonly discovery: boolean;
19
- /** moq-transport has no PROBE, so this stays empty; see {@link Established.probe}. */
20
- readonly probe: Getter<Probe>;
21
- /** Snapshot the transport's counters; see {@link Established.stats}. */
22
- stats(): Promise<Stats>;
23
- /**
24
- * Closes the connection.
25
- */
26
- close(): void;
27
- /** Gets an announced reader for `scope`; see {@link Established.announced}. */
28
- announced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer;
29
- /** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */
30
- get closed(): Promise<Error | null>;
31
- }
1
+ export {};
32
2
  //# sourceMappingURL=connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/ietf/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,KAAK,EAAkB,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,4BAA4B,CAAC;AAGzE,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAC;AAoBxC;;;;GAIG;AACH,qBAAa,UAAW,YAAW,WAAW;;IAE7C,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAGlB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAGzB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,sFAAsF;IACtF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAyB;IAyHtD,wEAAwE;IAClE,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAE5B;IAED;;OAEG;IACH,KAAK,SAIJ;IAoCD,+EAA+E;IAC/E,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAE7E;IA0MD,wGAAwG;IACxG,IAAI,MAAM,IAAI,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAElC;CACD"}
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/ietf/connection.ts"],"names":[],"mappings":""}