@moq/net 0.4.7 → 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 (664) 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 -2
  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 -32
  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 -139
  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 -2
  33. package/bandwidth_api.js.map +1 -1
  34. package/broadcast.d.ts +64 -38
  35. package/broadcast.d.ts.map +1 -1
  36. package/broadcast.js +556 -173
  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 +21 -13
  47. package/connection/accept.d.ts.map +1 -1
  48. package/connection/accept.js +97 -130
  49. package/connection/accept.js.map +1 -1
  50. package/connection/browser.d.ts.map +1 -1
  51. package/connection/browser.js +28 -20
  52. package/connection/browser.js.map +1 -1
  53. package/connection/connect.d.ts +120 -24
  54. package/connection/connect.d.ts.map +1 -1
  55. package/connection/connect.js +535 -217
  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 -81
  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 -95
  72. package/connection/goaway.js.map +1 -1
  73. package/connection/handshake.d.ts +34 -8
  74. package/connection/handshake.d.ts.map +1 -1
  75. package/connection/handshake.js +97 -21
  76. package/connection/handshake.js.map +1 -1
  77. package/connection/index.d.ts +4 -7
  78. package/connection/index.d.ts.map +1 -1
  79. package/connection/index.js +1 -3
  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 +142 -63
  86. package/connection/pool.d.ts.map +1 -1
  87. package/connection/pool.js +281 -118
  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 -234
  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 -9
  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 -5
  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 -47
  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 -2
  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 -38
  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 -3
  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 -308
  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 -65
  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 -36
  199. package/ietf/aliases.js.map +1 -1
  200. package/ietf/cluster.d.ts +3 -3
  201. package/ietf/cluster.js +14 -55
  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 -144
  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 -101
  213. package/ietf/error.js.map +1 -1
  214. package/ietf/fetch.d.ts +93 -37
  215. package/ietf/fetch.d.ts.map +1 -1
  216. package/ietf/fetch.js +172 -94
  217. package/ietf/fetch.js.map +1 -1
  218. package/ietf/filter.d.ts +21 -31
  219. package/ietf/filter.d.ts.map +1 -1
  220. package/ietf/filter.js +140 -172
  221. package/ietf/filter.js.map +1 -1
  222. package/ietf/goaway.d.ts +12 -10
  223. package/ietf/goaway.d.ts.map +1 -1
  224. package/ietf/goaway.js +22 -36
  225. package/ietf/goaway.js.map +1 -1
  226. package/ietf/hidden.js +1 -2
  227. package/ietf/hidden.js.map +1 -1
  228. package/ietf/index.d.ts +8 -20
  229. package/ietf/index.d.ts.map +1 -1
  230. package/ietf/index.js +4 -15
  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 -41
  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 +19 -5
  245. package/ietf/namespace.d.ts.map +1 -1
  246. package/ietf/namespace.js +78 -27
  247. package/ietf/namespace.js.map +1 -1
  248. package/ietf/object.d.ts +195 -33
  249. package/ietf/object.d.ts.map +1 -1
  250. package/ietf/object.js +405 -179
  251. package/ietf/object.js.map +1 -1
  252. package/ietf/parameters.d.ts +25 -45
  253. package/ietf/parameters.d.ts.map +1 -1
  254. package/ietf/parameters.js +260 -473
  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 -5
  259. package/ietf/priority.js.map +1 -1
  260. package/ietf/properties.d.ts +6 -5
  261. package/ietf/properties.d.ts.map +1 -1
  262. package/ietf/properties.js +78 -49
  263. package/ietf/properties.js.map +1 -1
  264. package/ietf/publish.d.ts +25 -33
  265. package/ietf/publish.d.ts.map +1 -1
  266. package/ietf/publish.js +45 -140
  267. package/ietf/publish.js.map +1 -1
  268. package/ietf/publish_namespace.d.ts +49 -72
  269. package/ietf/publish_namespace.d.ts.map +1 -1
  270. package/ietf/publish_namespace.js +66 -185
  271. package/ietf/publish_namespace.js.map +1 -1
  272. package/ietf/publisher.js +1800 -601
  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 +6 -30
  279. package/ietf/request.d.ts.map +1 -1
  280. package/ietf/request.js +41 -79
  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 -17
  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 +5 -30
  291. package/ietf/setup.d.ts.map +1 -1
  292. package/ietf/setup.js +6 -118
  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 -15
  299. package/ietf/solicit.js.map +1 -1
  300. package/ietf/subscribe.d.ts +52 -45
  301. package/ietf/subscribe.d.ts.map +1 -1
  302. package/ietf/subscribe.js +118 -240
  303. package/ietf/subscribe.js.map +1 -1
  304. package/ietf/subscribe_namespace.d.ts +16 -79
  305. package/ietf/subscribe_namespace.d.ts.map +1 -1
  306. package/ietf/subscribe_namespace.js +30 -202
  307. package/ietf/subscribe_namespace.js.map +1 -1
  308. package/ietf/subscriber.js +1839 -537
  309. package/ietf/subscriber.js.map +1 -1
  310. package/ietf/token.js +105 -28
  311. package/ietf/token.js.map +1 -1
  312. package/ietf/track.d.ts +27 -24
  313. package/ietf/track.d.ts.map +1 -1
  314. package/ietf/track.js +48 -62
  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 -49
  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 +34 -19
  325. package/index.d.ts.map +1 -1
  326. package/index.js +19 -7
  327. package/index.js.map +1 -1
  328. package/internal.d.ts +1515 -67
  329. package/internal.d.ts.map +1 -1
  330. package/internal.js +557 -80
  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 +127 -66
  341. package/lite/announce.d.ts.map +1 -1
  342. package/lite/announce.js +384 -159
  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 -78
  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 -10
  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 +2 -2
  389. package/lite/goaway.d.ts.map +1 -1
  390. package/lite/goaway.js +5 -14
  391. package/lite/goaway.js.map +1 -1
  392. package/lite/group.d.ts +67 -16
  393. package/lite/group.d.ts.map +1 -1
  394. package/lite/group.js +108 -31
  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 +14 -13
  401. package/lite/index.d.ts.map +1 -1
  402. package/lite/index.js +2 -2
  403. package/lite/index.js.map +1 -1
  404. package/lite/message.d.ts +10 -2
  405. package/lite/message.d.ts.map +1 -1
  406. package/lite/message.js +28 -45
  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 -106
  411. package/lite/priority.js.map +1 -1
  412. package/lite/probe.d.ts +2 -2
  413. package/lite/probe.d.ts.map +1 -1
  414. package/lite/probe.js +9 -1
  415. package/lite/probe.js.map +1 -1
  416. package/lite/publisher.d.ts +10 -1
  417. package/lite/publisher.d.ts.map +1 -1
  418. package/lite/publisher.js +2548 -438
  419. package/lite/publisher.js.map +1 -1
  420. package/lite/routed.d.ts +59 -0
  421. package/lite/routed.d.ts.map +1 -0
  422. package/lite/routed.js +564 -0
  423. package/lite/routed.js.map +1 -0
  424. package/lite/session.d.ts +2 -28
  425. package/lite/session.d.ts.map +1 -1
  426. package/lite/session.js +0 -100
  427. package/lite/session.js.map +1 -1
  428. package/lite/setup.d.ts +32 -5
  429. package/lite/setup.d.ts.map +1 -1
  430. package/lite/setup.js +95 -22
  431. package/lite/setup.js.map +1 -1
  432. package/lite/stream.d.ts +5 -11
  433. package/lite/stream.d.ts.map +1 -1
  434. package/lite/stream.js +5 -2
  435. package/lite/stream.js.map +1 -1
  436. package/lite/subscribe.d.ts +478 -78
  437. package/lite/subscribe.d.ts.map +1 -1
  438. package/lite/subscribe.js +1373 -143
  439. package/lite/subscribe.js.map +1 -1
  440. package/lite/subscriber.d.ts +7 -44
  441. package/lite/subscriber.d.ts.map +1 -1
  442. package/lite/subscriber.js +3290 -516
  443. package/lite/subscriber.js.map +1 -1
  444. package/lite/track.d.ts +27 -12
  445. package/lite/track.d.ts.map +1 -1
  446. package/lite/track.js +116 -38
  447. package/lite/track.js.map +1 -1
  448. package/lite/tracks.d.ts +55 -0
  449. package/lite/tracks.d.ts.map +1 -0
  450. package/lite/tracks.js +114 -0
  451. package/lite/tracks.js.map +1 -0
  452. package/lite/version.d.ts +132 -24
  453. package/lite/version.d.ts.map +1 -1
  454. package/lite/version.js +378 -34
  455. package/lite/version.js.map +1 -1
  456. package/meta.d.ts +77 -0
  457. package/meta.d.ts.map +1 -0
  458. package/meta.js +130 -0
  459. package/meta.js.map +1 -0
  460. package/meta_api.d.ts +7 -0
  461. package/meta_api.d.ts.map +1 -0
  462. package/meta_api.js +7 -0
  463. package/meta_api.js.map +1 -0
  464. package/mint.d.ts +28 -0
  465. package/mint.d.ts.map +1 -0
  466. package/mint.js +66 -0
  467. package/mint.js.map +1 -0
  468. package/open.d.ts +63 -0
  469. package/open.d.ts.map +1 -0
  470. package/open.js +250 -0
  471. package/open.js.map +1 -0
  472. package/origin.d.ts +394 -142
  473. package/origin.d.ts.map +1 -1
  474. package/origin.js +2533 -687
  475. package/origin.js.map +1 -1
  476. package/package.json +8 -13
  477. package/path.d.ts +51 -51
  478. package/path.d.ts.map +1 -1
  479. package/path.js +210 -58
  480. package/path.js.map +1 -1
  481. package/payload.d.ts +33 -0
  482. package/payload.d.ts.map +1 -0
  483. package/payload.js +65 -0
  484. package/payload.js.map +1 -0
  485. package/prefix.d.ts +152 -0
  486. package/prefix.d.ts.map +1 -0
  487. package/prefix.js +349 -0
  488. package/prefix.js.map +1 -0
  489. package/priority.d.ts +8 -0
  490. package/priority.d.ts.map +1 -0
  491. package/priority.js +185 -0
  492. package/priority.js.map +1 -0
  493. package/queue.d.ts +2 -0
  494. package/queue.d.ts.map +1 -0
  495. package/queue.js +46 -0
  496. package/queue.js.map +1 -0
  497. package/ranges.d.ts +36 -0
  498. package/ranges.d.ts.map +1 -0
  499. package/ranges.js +312 -0
  500. package/ranges.js.map +1 -0
  501. package/rescale.d.ts +24 -0
  502. package/rescale.d.ts.map +1 -0
  503. package/rescale.js +39 -0
  504. package/rescale.js.map +1 -0
  505. package/resume.d.ts +55 -0
  506. package/resume.d.ts.map +1 -0
  507. package/resume.js +4173 -0
  508. package/resume.js.map +1 -0
  509. package/resume.test-util.d.ts +2 -0
  510. package/resume.test-util.d.ts.map +1 -0
  511. package/resume.test-util.js +25 -0
  512. package/resume.test-util.js.map +1 -0
  513. package/skips.d.ts +48 -0
  514. package/skips.d.ts.map +1 -0
  515. package/skips.js +182 -0
  516. package/skips.js.map +1 -0
  517. package/stream.d.ts +78 -40
  518. package/stream.d.ts.map +1 -1
  519. package/stream.js +236 -93
  520. package/stream.js.map +1 -1
  521. package/subscription.test-util.d.ts +2 -0
  522. package/subscription.test-util.d.ts.map +1 -0
  523. package/subscription.test-util.js +49 -0
  524. package/subscription.test-util.js.map +1 -0
  525. package/tail.d.ts +23 -14
  526. package/tail.d.ts.map +1 -1
  527. package/tail.js +224 -98
  528. package/tail.js.map +1 -1
  529. package/time.d.ts +41 -102
  530. package/time.d.ts.map +1 -1
  531. package/time.js +129 -92
  532. package/time.js.map +1 -1
  533. package/timed.d.ts +21 -0
  534. package/timed.d.ts.map +1 -0
  535. package/timed.js +2 -0
  536. package/timed.js.map +1 -0
  537. package/track.d.ts +578 -246
  538. package/track.d.ts.map +1 -1
  539. package/track.js +7306 -772
  540. package/track.js.map +1 -1
  541. package/track_api.d.ts +7 -0
  542. package/track_api.d.ts.map +1 -0
  543. package/track_api.js +7 -0
  544. package/track_api.js.map +1 -0
  545. package/util/abort.d.ts +1 -0
  546. package/util/abort.d.ts.map +1 -1
  547. package/util/abort.js +23 -2
  548. package/util/abort.js.map +1 -1
  549. package/util/announce.d.ts +4 -0
  550. package/util/announce.d.ts.map +1 -0
  551. package/util/announce.js +11 -0
  552. package/util/announce.js.map +1 -0
  553. package/util/bigint.d.ts +3 -0
  554. package/util/bigint.d.ts.map +1 -0
  555. package/util/bigint.js +8 -0
  556. package/util/bigint.js.map +1 -0
  557. package/util/change.d.ts +12 -0
  558. package/util/change.d.ts.map +1 -0
  559. package/util/change.js +18 -0
  560. package/util/change.js.map +1 -0
  561. package/util/deadline.d.ts +2 -0
  562. package/util/deadline.d.ts.map +1 -0
  563. package/util/deadline.js +108 -0
  564. package/util/deadline.js.map +1 -0
  565. package/util/decode_error.d.ts +3 -0
  566. package/util/decode_error.d.ts.map +1 -0
  567. package/util/decode_error.js +11 -0
  568. package/util/decode_error.js.map +1 -0
  569. package/util/demand.d.ts +8 -0
  570. package/util/demand.d.ts.map +1 -0
  571. package/util/demand.js +24 -0
  572. package/util/demand.js.map +1 -0
  573. package/util/given_up.d.ts +2 -0
  574. package/util/given_up.d.ts.map +1 -0
  575. package/util/given_up.js +101 -0
  576. package/util/given_up.js.map +1 -0
  577. package/util/hex.d.ts +6 -0
  578. package/util/hex.d.ts.map +1 -1
  579. package/util/hex.js +19 -5
  580. package/util/hex.js.map +1 -1
  581. package/util/key.d.ts +15 -0
  582. package/util/key.d.ts.map +1 -0
  583. package/util/key.js +38 -0
  584. package/util/key.js.map +1 -0
  585. package/util/limits.d.ts +2 -0
  586. package/util/limits.d.ts.map +1 -0
  587. package/util/limits.js +76 -0
  588. package/util/limits.js.map +1 -0
  589. package/util/observed.d.ts +23 -0
  590. package/util/observed.d.ts.map +1 -0
  591. package/util/observed.js +122 -0
  592. package/util/observed.js.map +1 -0
  593. package/util/sorted.d.ts +2 -0
  594. package/util/sorted.d.ts.map +1 -0
  595. package/util/sorted.js +149 -0
  596. package/util/sorted.js.map +1 -0
  597. package/util/timeout.d.ts +2 -1
  598. package/util/timeout.d.ts.map +1 -1
  599. package/util/timeout.js +13 -10
  600. package/util/timeout.js.map +1 -1
  601. package/util/timer.d.ts +2 -0
  602. package/util/timer.d.ts.map +1 -0
  603. package/util/timer.js +19 -0
  604. package/util/timer.js.map +1 -0
  605. package/util/u64.js +0 -1
  606. package/util/utf8.d.ts +2 -0
  607. package/util/utf8.d.ts.map +1 -1
  608. package/util/utf8.js +7 -2
  609. package/util/utf8.js.map +1 -1
  610. package/util/varint.d.ts.map +1 -1
  611. package/util/varint.js +8 -2
  612. package/util/varint.js.map +1 -1
  613. package/util/watch.d.ts +8 -0
  614. package/util/watch.d.ts.map +1 -0
  615. package/util/watch.js +38 -0
  616. package/util/watch.js.map +1 -0
  617. package/util/yield.d.ts +2 -0
  618. package/util/yield.d.ts.map +1 -0
  619. package/util/yield.js +31 -0
  620. package/util/yield.js.map +1 -0
  621. package/varint.d.ts +0 -29
  622. package/varint.d.ts.map +1 -1
  623. package/varint.js +7 -29
  624. package/varint.js.map +1 -1
  625. package/varint_api.d.ts +7 -0
  626. package/varint_api.d.ts.map +1 -0
  627. package/varint_api.js +7 -0
  628. package/varint_api.js.map +1 -0
  629. package/version.d.ts +2 -0
  630. package/version.d.ts.map +1 -0
  631. package/version.js +4 -0
  632. package/version.js.map +1 -0
  633. package/window.d.ts +570 -0
  634. package/window.d.ts.map +1 -0
  635. package/window.js +1677 -0
  636. package/window.js.map +1 -0
  637. package/wire.d.ts +150 -35
  638. package/wire.d.ts.map +1 -1
  639. package/wire.js +27 -1
  640. package/wire.js.map +1 -1
  641. package/connection/established.d.ts +0 -53
  642. package/connection/established.d.ts.map +0 -1
  643. package/connection/established.js +0 -3
  644. package/connection/established.js.map +0 -1
  645. package/ietf/adapter.d.ts +0 -75
  646. package/ietf/adapter.d.ts.map +0 -1
  647. package/ietf/adapter.js +0 -700
  648. package/ietf/adapter.js.map +0 -1
  649. package/lite/datagram_stream.d.ts +0 -8
  650. package/lite/datagram_stream.d.ts.map +0 -1
  651. package/lite/datagram_stream.js +0 -44
  652. package/lite/datagram_stream.js.map +0 -1
  653. package/lite/fetch.d.ts +0 -28
  654. package/lite/fetch.d.ts.map +0 -1
  655. package/lite/fetch.js +0 -79
  656. package/lite/fetch.js.map +0 -1
  657. package/util/log.d.ts +0 -5
  658. package/util/log.d.ts.map +0 -1
  659. package/util/log.js +0 -17
  660. package/util/log.js.map +0 -1
  661. package/zod.d.ts +0 -13
  662. package/zod.d.ts.map +0 -1
  663. package/zod.js +0 -19
  664. package/zod.js.map +0 -1
package/broadcast.js CHANGED
@@ -1,125 +1,366 @@
1
- /* @ts-self-types="./broadcast.d.ts" */
2
1
  /**
3
2
  * Broadcast role handles: a named collection of tracks produced by a publisher.
4
3
  *
5
4
  * @module
6
5
  */
7
6
  import { Once, Signal } from "@moq/signals";
8
- import { NotFound } from "./error.js";
9
- import { Route } from "./hop.js";
10
- import { hooks } from "./internal.js";
7
+ import * as cache from "./cache.js";
8
+ import * as datagram from "./datagram.js";
9
+ import { NotFound, StreamCode, StreamError } from "./error.js";
10
+ import { holeError, hooks } from "./internal.js";
11
+ import { Listing, listTracks, makeLister } from "./listing.js";
12
+ import * as Meta from "./meta.js";
11
13
  import * as Path from "./path.js";
12
14
  import * as track from "./track.js";
13
15
  import { untilAborted } from "./util/abort.js";
14
- import { registerWire, trackOf } from "./wire.js";
15
- let attachAnnouncer;
16
+ import { checkName } from "./util/utf8.js";
17
+ import { registerWire, trackMetaOf, trackOf, wireOf } from "./wire.js";
18
+ export { Tracks } from "./listing.js";
16
19
  let stampProducer;
20
+ // The info lookups on an on-demand track.
21
+ class Lookups {
22
+ // Whether a lookup opened the request, so the last lookup to end closes it unless subscribed.
23
+ opened = false;
24
+ }
17
25
  /** Reactive backing state shared by broadcast producers and consumers. */
18
26
  class BroadcastState {
19
27
  requested = new Signal([]);
28
+ datagramRequested = new Signal([]);
29
+ datagramPending = new Set();
30
+ datagrams = new Map();
31
+ datagramServed = false;
20
32
  pending = new Set();
21
33
  closed = new Once();
34
+ // The tracks the broadcast lists, and the readers listing them.
35
+ listing = new Listing(this.closed);
36
+ // The tracks the application inserted. A finished one stays and keeps serving its cache; only an
37
+ // abort or removeTrack drops it, the way only a dropped producer leaves a Rust broadcast.
22
38
  tracks = new Map();
23
- sequences = new Map();
24
- // Live consumer handles sharing this state (see {@link Consumer.clone}). The broadcast
25
- // closes once the last one closes, so a shared consumer can be handed to several callers.
39
+ // The on-demand producer for each name, shared by every subscription and info lookup until it closes.
40
+ requests = new Map();
41
+ // The same for each name's metadata copy, kept apart so no payload reader is ever handed one.
42
+ // Only filled while `meta` is set.
43
+ metaRequests = new Map();
44
+ // Whether its request handler fills a metadata copy apart from the payload one; see
45
+ // `hooks.serveMeta`. Otherwise a metadata reader takes the payload copy's headers.
46
+ meta = false;
47
+ lookups = new WeakMap();
48
+ // Whether something answers on-demand track requests: a wire layer's consumed broadcast, or a
49
+ // publisher that has started pulling them. The counterpart of a live Rust `broadcast::Requests`;
50
+ // without one, a track nobody publishes is `NotFound` rather than a request nobody will answer.
51
+ served = false;
52
+ // Live consumer handles sharing this state (see {@link Consumer.clone}).
26
53
  consumers = 0;
54
+ // A wire layer's broadcast, which has no producer: it ends once no consumer holds it, as a
55
+ // Rust session retires a source nothing holds. A produced broadcast ends only on its close.
56
+ unheld = false;
57
+ // Run synchronously once the broadcast closes, before `closed` notifies its observers.
58
+ closers = new Set();
59
+ // The cache pool every track of the broadcast caches into, defaulting as Rust's
60
+ // `broadcast::Info` does: no byte capacity, and the default idle window.
61
+ pool = new cache.Pool({ expiry: cache.DEFAULT_EXPIRY });
62
+ }
63
+ // A new track of the broadcast, caching into its pool: its metadata copy when `meta`.
64
+ function createProducer(state, name, meta = false) {
65
+ const producer = hooks.pendingTrack(name);
66
+ hooks.poolTrack(producer, state.pool);
67
+ if (meta)
68
+ hooks.metaTrack(producer);
69
+ return producer;
70
+ }
71
+ // Datagram tracks never enter the stream cache.
72
+ function liveDatagrams(state, name, passive = false) {
73
+ const producer = state.datagrams.get(name);
74
+ if (!producer)
75
+ return;
76
+ if (producer.closed.peek() !== undefined) {
77
+ state.datagrams.delete(name);
78
+ return;
79
+ }
80
+ return passive ? hooks.observeDatagrams(producer) : producer.consume();
81
+ }
82
+ // Create the datagram track `name`, listed until it ends unless `listed` is false: a session's
83
+ // datagram track riding a stream track's subscription serves a request, not the inventory.
84
+ function createDatagrams(state, name, info, listed = true) {
85
+ if (state.closed.peek() !== undefined)
86
+ throw new Error("broadcast is closed");
87
+ // A request its readers closed waits for async cleanup; serve the name fresh instead.
88
+ const queued = state.datagramRequested
89
+ .peek()
90
+ .find((request) => request.name === name && request.closed.peek() === undefined);
91
+ let producer;
92
+ if (queued) {
93
+ state.datagramRequested.mutate((requests) => requests.splice(requests.indexOf(queued), 1));
94
+ producer = queued.accept(info);
95
+ }
96
+ else {
97
+ const existing = state.datagrams.get(name);
98
+ if (existing?.closed.peek() === undefined && existing)
99
+ return undefined;
100
+ producer = new datagram.Producer(name, info);
101
+ state.datagrams.set(name, producer);
102
+ void producer.closed.then(() => {
103
+ if (state.datagrams.get(name) === producer)
104
+ state.datagrams.delete(name);
105
+ });
106
+ }
107
+ if (listed) {
108
+ const accepted = hooks.datagramInfo(producer);
109
+ if (!accepted)
110
+ throw new Error("datagram track has not been accepted");
111
+ state.listing.listDatagrams(producer, accepted);
112
+ hooks.onDatagramsEnd(producer, (finished) => state.listing.unlistOwn(producer, "datagrams", finished));
113
+ }
114
+ return producer;
115
+ }
116
+ function datagrams(state, name) {
117
+ if (state.closed.peek() !== undefined)
118
+ throw new Error("broadcast is closed");
119
+ const existing = liveDatagrams(state, name);
120
+ if (existing)
121
+ return existing;
122
+ const producer = hooks.pendingDatagrams(name);
123
+ const consumer = producer.consume();
124
+ if (!state.datagramServed) {
125
+ hooks.abortDatagrams(producer, new NotFound(`datagram track ${name}`));
126
+ return consumer;
127
+ }
128
+ const request = hooks.datagramRequest(producer, state.datagramPending);
129
+ state.datagrams.set(name, producer);
130
+ state.datagramRequested.mutate((requests) => requests.push(request));
131
+ void producer.closed.then(() => {
132
+ state.datagramPending.delete(request);
133
+ if (state.datagrams.get(name) === producer)
134
+ state.datagrams.delete(name);
135
+ state.datagramRequested.mutate((requests) => {
136
+ const index = requests.indexOf(request);
137
+ if (index !== -1)
138
+ requests.splice(index, 1);
139
+ });
140
+ });
141
+ return consumer;
142
+ }
143
+ async function requestedDatagrams(state) {
144
+ state.datagramServed = true;
145
+ for (;;) {
146
+ const requests = state.datagramRequested.peek();
147
+ requests.sort((a, b) => (a.priority.peek() ?? -128) - (b.priority.peek() ?? -128));
148
+ const request = requests.pop();
149
+ if (request && request.closed.peek() === undefined)
150
+ return request;
151
+ if (request)
152
+ continue;
153
+ if (state.closed.peek() !== undefined)
154
+ return;
155
+ await Signal.race(state.datagramRequested, state.closed);
156
+ }
27
157
  }
28
158
  function dequeueRequest(state) {
29
159
  const requested = state.requested.peek();
30
160
  requested.sort((a, b) => a.priority - b.priority);
31
161
  return requested.pop();
32
162
  }
163
+ // The next on-demand track request, or undefined once the broadcast closes.
164
+ async function requested(state) {
165
+ // Pulling requests is what makes a broadcast serve tracks on demand, and it latches for the
166
+ // broadcast's lifetime since JS has no drop to mark the handler gone. A subscribe before the first
167
+ // pull is answered NotFound, so an on-demand publisher starts pulling before it publishes and keeps
168
+ // pulling until the broadcast closes.
169
+ state.served = true;
170
+ for (;;) {
171
+ const request = dequeueRequest(state);
172
+ if (request)
173
+ return request;
174
+ if (state.closed.peek() !== undefined)
175
+ return undefined;
176
+ await Signal.race(state.requested, state.closed);
177
+ }
178
+ }
33
179
  // Close the broadcast and reject any requests still pending in the queue, so a
34
180
  // subscriber blocked on the track's info() or group reads is unblocked rather
35
181
  // than left waiting on a producer that will never be served.
36
182
  //
37
183
  // Once.set throws on a second settle, and the producer and each consumer handle close
38
184
  // independently, so this has to be idempotent.
39
- function closeState(state, abort) {
185
+ function closeState(state) {
40
186
  if (state.closed.peek() !== undefined)
41
187
  return;
42
- state.closed.set(abort ?? null);
188
+ state.closed.set(null);
189
+ state.listing.close();
190
+ for (const request of state.datagramPending)
191
+ request.reject(new StreamError(StreamCode.Cancel));
192
+ state.datagramRequested.set([]);
43
193
  for (const request of state.pending)
44
- request.reject(abort);
194
+ request.reject(new StreamError(StreamCode.Internal, {
195
+ message: `track request ${request.name} dropped before acceptance`,
196
+ }));
45
197
  state.requested.mutate((requests) => {
46
198
  requests.length = 0;
47
199
  });
200
+ for (const fn of state.closers)
201
+ fn();
202
+ state.closers.clear();
48
203
  }
49
- // `register` is set on the subscribing (consumer) side: the fresh producer is cached in
50
- // `state.tracks` so repeat subscriptions to the same track fan out from one upstream subscription
51
- // instead of opening a new one, mirroring the Rust `broadcast::Consumer::track` weak-dedup. The
52
- // consumer wire watches the producer's demand ({@link track.Producer.used}) and tears the upstream
53
- // down once its last subscriber leaves, closing the producer, which evicts the cache entry below.
54
- // The publishing side leaves `register` false: `state.tracks` there holds only the tracks the app
55
- // inserted, and a dynamic serve stays one request per peer subscription.
56
- function subscribe(state, name, options = {}, register = false) {
57
- if (state.closed.peek() !== undefined) {
58
- throw new Error(`broadcast is closed: ${state.closed.peek()}`);
59
- }
60
- const existing = state.tracks.get(name);
61
- if (existing) {
62
- if (existing.closed.peek() === undefined)
63
- return existing.subscribe(options);
204
+ // The producer already serving `name`, or its metadata copy when `meta`, evicting entries that can
205
+ // no longer serve it. The application inserts payload tracks alone.
206
+ function lookup(state, name, meta = false) {
207
+ const inserted = meta ? undefined : state.tracks.get(name);
208
+ if (inserted) {
209
+ if (!(hooks.trackReleased(inserted).peek() instanceof Error))
210
+ return inserted;
64
211
  state.tracks.delete(name);
65
212
  }
66
- const producer = new track.Producer(name);
67
- const subscriber = producer.subscribe(options);
68
- if (register) {
69
- state.tracks.set(name, producer);
70
- // Drop the cache entry once the upstream closes (the wire tears it down when its last
71
- // subscriber leaves), so a later subscribe re-opens it.
72
- void producer.closed.then(() => {
73
- if (state.tracks.get(name) === producer)
74
- state.tracks.delete(name);
75
- });
213
+ const requests = requestsOf(state, meta);
214
+ const requested = requests.get(name);
215
+ if (requested) {
216
+ if (hooks.trackReleased(requested).peek() === undefined)
217
+ return requested;
218
+ requests.delete(name);
76
219
  }
77
- state.requested.mutate((requested) => {
78
- requested.push(hooks.makeRequest({ name, producer, sequences: state.sequences, pending: state.pending }));
79
- });
80
- return subscriber;
220
+ return undefined;
81
221
  }
82
- async function resolveTrackInfo(state, name) {
83
- const existing = state.tracks.get(name);
84
- if (existing && existing.closed.peek() === undefined) {
85
- return existing.info();
86
- }
222
+ // The on-demand producers for payload copies, or for metadata copies when `meta`.
223
+ function requestsOf(state, meta) {
224
+ return meta ? state.metaRequests : state.requests;
225
+ }
226
+ // The producer serving `name`, or a new one with a request queued for it.
227
+ //
228
+ // A broadcast has one logical track per name, mirroring the Rust `broadcast::Consumer::track`
229
+ // weak-dedup: a requested producer is cached in `state.requests` so every subscription and info
230
+ // lookup fans out from one request instead of opening another. Whoever serves it closes it once
231
+ // unused (the consuming wire tears the upstream down when its last subscriber leaves), which evicts
232
+ // the entry so a later subscribe requests the track again.
233
+ //
234
+ // A metadata reader (`meta`) gets a logical track of its own only where the handler fills one
235
+ // (`state.meta`), and the payload one otherwise, whose headers it takes.
236
+ function logical(state, name, meta = false) {
87
237
  if (state.closed.peek() !== undefined) {
88
- return Promise.reject(new Error(`broadcast is closed: ${state.closed.peek()}`));
238
+ throw new Error("broadcast is closed");
239
+ }
240
+ const copy = meta && state.meta;
241
+ const existing = lookup(state, name, copy);
242
+ if (existing)
243
+ return { producer: existing, requested: false };
244
+ const producer = createProducer(state, name, copy);
245
+ if (!state.served) {
246
+ // Answer through the track rather than throwing, so a peer's subscribe is refused with
247
+ // the code instead of an unhandled error.
248
+ hooks.abortTrack(producer, new NotFound(`track ${name}`));
249
+ return { producer, requested: false };
89
250
  }
90
- const producer = new track.Producer(name);
251
+ const lookups = new Lookups();
252
+ state.lookups.set(producer, lookups);
253
+ const requests = requestsOf(state, copy);
254
+ requests.set(name, producer);
255
+ void hooks.trackReleased(producer).then(() => {
256
+ if (requests.get(name) === producer)
257
+ requests.delete(name);
258
+ });
91
259
  state.requested.mutate((requested) => {
92
- requested.push(hooks.makeRequest({ name, producer, sequences: state.sequences, pending: state.pending }));
260
+ requested.push(hooks.makeRequest({ name, producer, pending: state.pending, lookups, meta: copy }));
93
261
  });
94
- try {
95
- return await producer.info();
96
- }
97
- finally {
98
- producer.close();
262
+ return { producer, requested: true };
263
+ }
264
+ function subscribe(state, name, options, meta = false) {
265
+ return logical(state, name, meta).producer.subscribe(options);
266
+ }
267
+ // A lookup counts as the track's demand until `hold` aborts (without one, until the answer), before
268
+ // and after acceptance, as a Rust `Resolving` does while held. An unanswered request stays open for its handler; after
269
+ // acceptance, the last holder of a request a lookup opened releases it.
270
+ async function resolveTrackInfo(state, name, hold, meta = false) {
271
+ hold?.throwIfAborted();
272
+ const { producer, requested } = logical(state, name, meta);
273
+ const lookups = state.lookups.get(producer);
274
+ if (lookups && requested)
275
+ lookups.opened = true;
276
+ const unhold = hooks.holdTrack(producer);
277
+ const info = producer.info();
278
+ let answered = false;
279
+ let ended = false;
280
+ const release = () => {
281
+ if (lookups?.opened && !producer.demand().wanted.peek())
282
+ hooks.releaseTrack(producer);
283
+ };
284
+ info.then(() => {
285
+ answered = true;
286
+ if (ended)
287
+ release();
288
+ }, () => { });
289
+ const end = () => {
290
+ ended = true;
291
+ unhold();
292
+ if (answered)
293
+ release();
294
+ };
295
+ if (!hold) {
296
+ try {
297
+ return await info;
298
+ }
299
+ finally {
300
+ end();
301
+ }
99
302
  }
303
+ hold.addEventListener("abort", end, { once: true });
304
+ return untilAborted(info, hold);
305
+ }
306
+ // The newest frame cached for `name`, without subscribing: undefined when nobody serves it yet.
307
+ function largest(state, name, meta = false, timescale) {
308
+ const producer = lookup(state, name, meta && state.meta);
309
+ return producer && hooks.cachedLargest(producer, timescale);
100
310
  }
101
- // Serve a group from the local retained window by subscribing and scanning to the
102
- // requested sequence. The default for a produced broadcast; the consuming wire layer
103
- // overrides it to fetch over the network (or to reject when the transport has no FETCH).
104
- async function fetchGroup(state, name, sequence, options = {}) {
311
+ // Fetch one group as a one-range subscription: the cached group at once, or else one the track's
312
+ // {@link track.Requests} handler answers, asked at once whether the group was written yet or not,
313
+ // as the Rust `fetch_group` does. A group the producer writes meanwhile answers it too. With no
314
+ // handler open, a miss fails at once with `NotFound`. The default for a produced broadcast and a
315
+ // lite-05/06 session's, whose copies ask their misses upstream; other wire layers override it to
316
+ // fetch over the network, or to reject on a version that cannot fetch.
317
+ async function fetchGroup(state, name, key, options = {}, meta = false) {
105
318
  options.signal?.throwIfAborted();
106
- const subscriber = subscribe(state, name, { priority: options.priority });
107
- hooks.exemptFetch(subscriber);
319
+ const range = { start: key, end: key };
320
+ if (options.priority !== undefined)
321
+ range.priority = options.priority;
322
+ const subscriber = subscribe(state, name, { ranges: [range], placed: new Map([[0, key]]) }, meta);
323
+ hooks.asFetch(subscriber);
108
324
  try {
325
+ // Judged in this turn when the track is known, so a cached group is taken before anything
326
+ // else can change it. A track requested on demand opens its handler once accepted, so its
327
+ // miss is judged then.
328
+ let asked = hooks.askFetch(subscriber, key);
329
+ if (asked === "pending") {
330
+ await untilAborted(subscriber.info(), options.signal);
331
+ asked = hooks.askFetch(subscriber, key);
332
+ }
333
+ if (asked !== true)
334
+ throw new NotFound(`group ${key}`);
109
335
  for (;;) {
110
- const group = await untilAborted(subscriber.recvGroup(), options.signal);
111
- if (!group)
112
- throw new NotFound(`group ${sequence}`);
113
- if (group.sequence === sequence) {
114
- // Close the subscription when the returned group finishes, not now: an
115
- // in-progress group must keep receiving frames for its lifetime (mirrors
116
- // Rust poll_fetch). Also fires if the caller closes the group early.
117
- void group.closed.then(() => subscriber.close());
118
- return group;
336
+ const recv = hooks.tryRecvGroup(subscriber, true);
337
+ switch (recv.kind) {
338
+ case "group":
339
+ // Close the subscription once the caller has read or released the group, not
340
+ // now: an in-progress group must keep receiving frames for its lifetime
341
+ // (mirrors Rust poll_fetch), and a failed group's unread frames stay in the
342
+ // cache's reach, expirable, until the caller lets them go.
343
+ void hooks.groupDone(recv.group).then(() => subscriber.close());
344
+ return recv.group;
345
+ case "drop":
346
+ // A copy that failed for no verdict of its own (not stale, not skipped) says nothing of
347
+ // the group, so a caller may ask again or elsewhere.
348
+ if (recv.failed && recv.reason === "drop")
349
+ throw new StreamError(StreamCode.Cancel, { message: `group ${key} copy failed` });
350
+ // Rethrown with its own reason, so a stale verdict stays OLD.
351
+ if (recv.refusal) {
352
+ // A wire-backed fill can return a delivery failure through the same path.
353
+ if (!state.unheld)
354
+ options.refused?.(recv.refusal);
355
+ throw recv.refusal;
356
+ }
357
+ throw holeError(recv);
358
+ case "error":
359
+ throw recv.error;
360
+ case "done":
361
+ throw new NotFound(`group ${key}`);
119
362
  }
120
- group.close();
121
- if (group.sequence > sequence)
122
- throw new NotFound(`group ${sequence}`);
363
+ await untilAborted(changed(subscriber), options.signal);
123
364
  }
124
365
  }
125
366
  catch (err) {
@@ -127,6 +368,50 @@ async function fetchGroup(state, name, sequence, options = {}) {
127
368
  throw err;
128
369
  }
129
370
  }
371
+ // Settles once a read of `subscriber` may go differently.
372
+ function changed(subscriber) {
373
+ return new Promise((resolve) => {
374
+ const dispose = hooks.groupChanged(subscriber, () => {
375
+ dispose();
376
+ resolve();
377
+ });
378
+ });
379
+ }
380
+ // Remove and return the payload request queued for `name`, if no handler has taken it yet.
381
+ function takeQueued(state, name) {
382
+ const queued = state.requested.peek().find((request) => request.name === name && !request.meta);
383
+ if (!queued)
384
+ return undefined;
385
+ state.requested.mutate((requests) => {
386
+ requests.splice(requests.indexOf(queued), 1);
387
+ });
388
+ return queued;
389
+ }
390
+ // What a metadata reader resolves names through where the handler fills metadata copies apart
391
+ // (`state.meta`): undefined elsewhere, where it reads the payload copies through `view` itself.
392
+ function metaView(state, view) {
393
+ const meta = {
394
+ ...view,
395
+ subscribe: (name, options) => subscribe(state, name, options, true),
396
+ resolveTrackInfo: (name, hold) => resolveTrackInfo(state, name, hold, true),
397
+ largest: (name) => largest(state, name, true),
398
+ fetchGroup: (name, key, options) => fetchGroup(state, name, key, options, true),
399
+ };
400
+ return () => (state.meta ? meta : undefined);
401
+ }
402
+ // Serve `producer` as the broadcast's track for its name, listed with `info`.
403
+ function adopt(state, producer, info) {
404
+ state.tracks.set(producer.name, producer);
405
+ state.listing.listTrack(producer, info);
406
+ // Released, it leaves the listing at once, finished if it declared its end, as a dropped Rust
407
+ // producer does.
408
+ hooks.onTrackRelease(producer, (finished) => state.listing.unlistOwn(producer, "track", finished));
409
+ // A finished track keeps serving its cache, so only an abort evicts it from the table.
410
+ void hooks.trackReleased(producer).then((closed) => {
411
+ if (closed instanceof Error && state.tracks.get(producer.name) === producer)
412
+ state.tracks.delete(producer.name);
413
+ });
414
+ }
130
415
  /**
131
416
  * The write side of a broadcast.
132
417
  *
@@ -134,22 +419,54 @@ async function fetchGroup(state, name, sequence, options = {}) {
134
419
  */
135
420
  export class Producer {
136
421
  #state = new BroadcastState();
137
- #announcer;
138
422
  #path = Path.empty();
139
423
  constructor() {
140
- registerWire(this, this.#wire(false));
424
+ const view = {
425
+ localDatagrams: !this.#state.unheld,
426
+ distinguishesKinds: !this.#state.unheld,
427
+ subscribe: (name, options) => subscribe(this.#state, name, options),
428
+ resolveTrackInfo: (name, hold) => resolveTrackInfo(this.#state, name, hold),
429
+ largest: (name, timescale) => largest(this.#state, name, false, timescale),
430
+ fetchGroup: (name, key, options) => fetchGroup(this.#state, name, key, options),
431
+ requested: () => requested(this.#state),
432
+ datagrams: (name) => datagrams(this.#state, name),
433
+ liveDatagrams: (name) => liveDatagrams(this.#state, name, true),
434
+ publishesTrack: (name) => this.#state.tracks.has(name),
435
+ createDatagrams: (name, info, listed) => createDatagrams(this.#state, name, info, listed),
436
+ requestedDatagrams: () => requestedDatagrams(this.#state),
437
+ tracks: (owner) => listTracks(this.#state.listing, owner),
438
+ lister: () => makeLister(this.#state.listing),
439
+ };
440
+ registerWire(this, { ...view, meta: metaView(this.#state, view) });
141
441
  }
142
442
  static {
143
- attachAnnouncer = (producer, announcer) => {
144
- producer.#announcer = announcer;
443
+ hooks.reserveUnlistedTrack = (broadcast, name) => {
444
+ const state = broadcast.#state;
445
+ if (state.closed.peek() !== undefined)
446
+ throw new Error("broadcast is closed");
447
+ if (lookup(state, name))
448
+ throw new Error("duplicate reserved track");
449
+ const producer = createProducer(state, name);
450
+ const lookups = new Lookups();
451
+ state.lookups.set(producer, lookups);
452
+ state.requests.set(name, producer);
453
+ void hooks.trackReleased(producer).then(() => {
454
+ if (state.requests.get(name) === producer)
455
+ state.requests.delete(name);
456
+ });
457
+ return hooks.makeRequest({ name, producer, pending: state.pending, lookups });
458
+ };
459
+ hooks.onClosed = (producer, fn) => {
460
+ const closers = producer.#state.closers;
461
+ closers.add(fn);
462
+ return () => closers.delete(fn);
145
463
  };
146
- hooks.attachAnnouncer = attachAnnouncer;
147
464
  stampProducer = (producer, path) => {
148
465
  producer.#path = path;
149
466
  };
150
467
  }
151
468
  /**
152
- * Settles once the broadcast closes: `null` on a clean close, or the abort {@link Error}.
469
+ * Settles with `null` once the broadcast closes; a broadcast end carries no cause.
153
470
  * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
154
471
  */
155
472
  get closed() {
@@ -159,84 +476,64 @@ export class Producer {
159
476
  consume() {
160
477
  return makeConsumer({ state: this.#state, path: this.#path });
161
478
  }
162
- async #requested() {
163
- for (;;) {
164
- const request = dequeueRequest(this.#state);
165
- if (request)
166
- return request;
167
- const closed = this.#state.closed.peek();
168
- if (closed instanceof Error)
169
- throw closed;
170
- if (closed !== undefined)
171
- return undefined;
172
- await Signal.race(this.#state.requested, this.#state.closed);
173
- }
174
- }
175
- /** Insert a track that is served directly, without an on-demand request round-trip. */
176
- insertTrack(track) {
479
+ /**
480
+ * Create a track, insert it into the broadcast, and return its producer, or `undefined` while
481
+ * an open track or a live request holds the name.
482
+ *
483
+ * A request still queued for the name is answered with this track, so its subscribers read
484
+ * from the returned producer. A request a handler has already taken stays a duplicate.
485
+ * An append on the track throws if it would reuse a key an earlier track of the name
486
+ * wrote in this broadcast, so a replacement writes its first group explicitly. Throws if the
487
+ * broadcast is closed, or if the name holds a lone surrogate, which UTF-8 cannot carry. An omitted
488
+ * `maxAge` in `info` is zero, the live edge only.
489
+ */
490
+ createTrack(name, info = {}) {
177
491
  if (this.#state.closed.peek() !== undefined) {
178
- throw new Error(`broadcast is closed: ${this.#state.closed.peek()}`);
492
+ throw new Error("broadcast is closed");
179
493
  }
180
- const existing = this.#state.tracks.get(track.name);
181
- if (existing && existing.closed.peek() === undefined) {
182
- throw new Error(`duplicate track: ${track.name}`);
494
+ const request = takeQueued(this.#state, name);
495
+ if (request) {
496
+ const producer = request.accept(info);
497
+ hooks.keepRequest(request);
498
+ this.#state.requests.delete(name);
499
+ adopt(this.#state, producer, track.authoredInfo(info));
500
+ return producer;
183
501
  }
184
- this.#state.tracks.set(track.name, track);
185
- void track.closed.then(() => {
186
- if (this.#state.tracks.get(track.name) === track) {
187
- this.#state.tracks.delete(track.name);
188
- }
189
- });
190
- }
191
- /** Create a track, insert it into the broadcast, and return its producer. */
192
- createTrack(name, info = {}) {
193
- const producer = new track.Producer(name).accept(info);
194
- this.insertTrack(producer);
502
+ // One logical track per name: an open track or a live request already serves it.
503
+ // A request a handler already pulled stays duplicate, as in Rust.
504
+ const live = [this.#state.tracks.get(name), this.#state.requests.get(name)];
505
+ if (live.some((existing) => existing && hooks.trackReleased(existing).peek() === undefined)) {
506
+ return undefined;
507
+ }
508
+ const producer = createProducer(this.#state, name).accept(info);
509
+ adopt(this.#state, producer, track.authoredInfo(info));
195
510
  return producer;
196
511
  }
197
- /** Remove a statically inserted track by name. */
512
+ /**
513
+ * Create a live datagram track in a namespace separate from stream tracks, or `undefined`
514
+ * while a live datagram track holds the name.
515
+ */
516
+ createDatagrams(name, info = {}) {
517
+ return createDatagrams(this.#state, name, info);
518
+ }
519
+ /**
520
+ * Remove a statically inserted track, including a finished cached one, and stop listing it
521
+ * at once.
522
+ */
198
523
  removeTrack(name) {
524
+ const track = this.#state.tracks.get(name);
525
+ if (!track)
526
+ return;
199
527
  this.#state.tracks.delete(name);
528
+ this.#state.listing.unlistOwn(track);
200
529
  }
201
530
  /** A lazy read handle for a track on this broadcast. */
202
531
  track(name) {
203
532
  return trackOf(name, this);
204
533
  }
205
- #wire(register) {
206
- return {
207
- subscribe: (name, options) => subscribe(this.#state, name, options, register),
208
- resolveTrackInfo: (name) => resolveTrackInfo(this.#state, name),
209
- fetchGroup: (name, sequence, options) => fetchGroup(this.#state, name, sequence, options),
210
- requested: () => this.#requested(),
211
- };
212
- }
213
- /**
214
- * Advertise this broadcast's exact path, or re-price a standing advertisement in place.
215
- *
216
- * Call it once the tracks a subscriber needs first (a catalog) exist. Until then the
217
- * broadcast exists for nobody, on its own origin or at a peer. Retracts on
218
- * {@link unannounce} or {@link close}. Throws if this producer was not created through an
219
- * origin, or if the broadcast is already closed.
220
- */
221
- announce(route = Route.default) {
222
- if (this.#state.closed.peek() !== undefined) {
223
- throw new Error(`broadcast is closed: ${this.#state.closed.peek()}`);
224
- }
225
- if (!this.#announcer)
226
- throw new Error("broadcast is not attached to an origin");
227
- this.#announcer.announce(Route.normalize(route));
228
- }
229
- /**
230
- * Retract the advertisement of this broadcast's path, if any, from local consumers and
231
- * peers alike. {@link announce} brings it back.
232
- */
233
- unannounce() {
234
- this.#announcer?.unannounce();
235
- }
236
- close(abort) {
237
- this.#announcer?.unannounce();
238
- this.#announcer = undefined;
239
- closeState(this.#state, abort);
534
+ /** End the broadcast for good: serve no new tracks. Idempotent. */
535
+ close() {
536
+ closeState(this.#state);
240
537
  }
241
538
  }
242
539
  // Constructs a Consumer from within this module without exposing a public constructor
@@ -253,18 +550,43 @@ let makeConsumer;
253
550
  export class Consumer {
254
551
  #state;
255
552
  #path;
553
+ #identity;
554
+ // Served on request through a route claiming a shorter prefix, which names no broadcast to list.
555
+ #unlisted;
256
556
  // Guards against a double close() on this handle over-decrementing the consumer count.
257
557
  #closed = false;
258
558
  constructor(shared) {
259
- this.#state = shared?.state ?? new BroadcastState();
260
559
  this.#path = shared?.path ?? Path.empty();
560
+ this.#identity = shared?.identity;
561
+ this.#unlisted = shared?.unlisted ?? false;
562
+ if (shared) {
563
+ this.#state = shared.state;
564
+ }
565
+ else {
566
+ // A standalone consumer is a wire layer's, which serves every track on demand.
567
+ this.#state = new BroadcastState();
568
+ this.#state.served = true;
569
+ this.#state.datagramServed = true;
570
+ this.#state.unheld = true;
571
+ }
261
572
  this.#state.consumers++;
262
- registerWire(this, {
263
- subscribe: (name, options) => subscribe(this.#state, name, options, true),
264
- resolveTrackInfo: (name) => resolveTrackInfo(this.#state, name),
265
- fetchGroup: (name, sequence, options) => fetchGroup(this.#state, name, sequence, options),
266
- requested: () => this.#requested(),
267
- });
573
+ const view = {
574
+ localDatagrams: !this.#state.unheld,
575
+ distinguishesKinds: !this.#state.unheld,
576
+ subscribe: (name, options) => subscribe(this.#state, name, options),
577
+ resolveTrackInfo: (name, hold) => resolveTrackInfo(this.#state, name, hold),
578
+ largest: (name, timescale) => largest(this.#state, name, false, timescale),
579
+ fetchGroup: (name, key, options) => fetchGroup(this.#state, name, key, options),
580
+ requested: () => requested(this.#state),
581
+ datagrams: (name) => datagrams(this.#state, name),
582
+ liveDatagrams: (name) => liveDatagrams(this.#state, name, true),
583
+ publishesTrack: (name) => this.#state.tracks.has(name),
584
+ createDatagrams: (name, info, listed) => createDatagrams(this.#state, name, info, listed),
585
+ requestedDatagrams: () => requestedDatagrams(this.#state),
586
+ tracks: (owner) => this.#tracks(owner),
587
+ lister: () => makeLister(this.#state.listing),
588
+ };
589
+ registerWire(this, { ...view, meta: metaView(this.#state, view) });
268
590
  }
269
591
  static {
270
592
  makeConsumer = (shared) => new Consumer(shared);
@@ -274,6 +596,25 @@ export class Consumer {
274
596
  else
275
597
  stampProducer(target, path);
276
598
  };
599
+ hooks.stampIdentity = (target, identity) => {
600
+ target.#identity = identity;
601
+ };
602
+ hooks.stampUnlisted = (target) => {
603
+ target.#unlisted = true;
604
+ };
605
+ hooks.unlisted = (target) => target.#unlisted;
606
+ hooks.serveMeta = (target) => {
607
+ target.#state.meta = true;
608
+ };
609
+ hooks.resolveHeld = (target, name, hold) => {
610
+ const state = target.#state;
611
+ if (state.closed.peek() !== undefined)
612
+ return undefined;
613
+ const producer = lookup(state, name);
614
+ if (!producer || !hooks.acceptedInfo(producer))
615
+ return undefined;
616
+ return resolveTrackInfo(state, name, hold);
617
+ };
277
618
  }
278
619
  /**
279
620
  * The path this handle names the broadcast by, which relative references in its catalog
@@ -287,11 +628,22 @@ export class Consumer {
287
628
  return this.#path;
288
629
  }
289
630
  /**
290
- * Settles once the broadcast closes: `null` on a clean close, or the abort {@link Error}.
631
+ * The identity of the route an origin resolved this handle through: the stream it reads.
632
+ *
633
+ * An origin stamps it with each request's result, so it names the stream actually serving
634
+ * this handle even when the request named none. `undefined` for a handle not handed out by
635
+ * an origin.
636
+ */
637
+ get identity() {
638
+ return this.#identity;
639
+ }
640
+ /**
641
+ * Settles with `null` once the broadcast closes; a broadcast end carries no cause.
291
642
  * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
292
643
  *
293
- * Shared by every {@link clone}: it settles once the last handle closes. The subscribing
294
- * wire layer peeks it to evict a closed entry from its per-path consume cache.
644
+ * Shared by every {@link clone}. A produced broadcast settles once its producer closes; a
645
+ * broadcast consumed from a session, once the session ends it or the last handle closes.
646
+ * The subscribing wire layer peeks it to evict a closed entry from its per-path consume cache.
295
647
  */
296
648
  get closed() {
297
649
  return this.#state.closed;
@@ -300,42 +652,73 @@ export class Consumer {
300
652
  * Return another handle to the same broadcast, reference-counted with this one.
301
653
  *
302
654
  * Both handles read the same tracks, carry the same {@link path}, and share one {@link closed}
303
- * state; the broadcast closes only once *every* handle has {@link close}d. Used by the connection's per-path
655
+ * state. Used by the connection's per-path
304
656
  * consume cache to share one subscription across callers. Subclasses that resolve info over
305
657
  * the wire override this to preserve their type (see the wire layer's consumed broadcast).
306
658
  */
307
659
  clone() {
308
660
  return new Consumer(this.shareState());
309
661
  }
310
- // Hand this consumer's backing state and path to a clone. Opaque (`never`) so the state type
311
- // stays unexported; a subclass passes it straight back into its own `super(...)`.
662
+ /**
663
+ * This consumer's backing state and path, for a clone. Opaque (`never`) so the state type
664
+ * stays unexported; a subclass passes it straight back into its own `super(...)`.
665
+ *
666
+ * @internal
667
+ */
312
668
  shareState() {
313
- return { state: this.#state, path: this.#path };
669
+ return {
670
+ state: this.#state,
671
+ path: this.#path,
672
+ identity: this.#identity,
673
+ unlisted: this.#unlisted,
674
+ };
675
+ }
676
+ /** Read a datagram track live from now, independently of any same-name stream track. */
677
+ datagrams(name) {
678
+ checkName(name);
679
+ return wireOf(this).datagrams(name);
314
680
  }
315
681
  /** Get a lazy handle for a track on this broadcast. Repeat subscriptions dedupe onto one upstream subscription. */
316
682
  track(name) {
317
683
  return trackOf(name, this);
318
684
  }
319
- async #requested() {
320
- for (;;) {
321
- const request = dequeueRequest(this.#state);
322
- if (request)
323
- return request;
324
- const closed = this.#state.closed.peek();
325
- if (closed instanceof Error)
326
- throw closed;
327
- if (closed !== undefined)
328
- return undefined;
329
- await Signal.race(this.#state.requested, this.#state.closed);
330
- }
685
+ /**
686
+ * Get a lazy handle to a track's metadata: its groups and each frame's header, without the
687
+ * payload. See {@link Meta}.
688
+ */
689
+ meta(name) {
690
+ return Meta.consumerOf(trackMetaOf(name, this));
331
691
  }
332
- close(abort) {
692
+ /**
693
+ * List the broadcast's tracks: each one with its info, then `synced`, then changes as they
694
+ * happen, until the broadcast ends.
695
+ *
696
+ * Lists the tracks its producer created (until they are released, abort, or are removed) and, for a
697
+ * broadcast consumed from a session, the tracks the peer lists. Through a session the
698
+ * peer's tracks arrive as they come and the listing syncs when the peer does; every
699
+ * listing of one broadcast shares one request to the peer. A track served only
700
+ * on request is never listed, and listing never requests one. Throws once the broadcast
701
+ * has closed.
702
+ */
703
+ tracks() {
704
+ return this.#tracks();
705
+ }
706
+ #tracks(owner) {
707
+ if (this.#unlisted)
708
+ throw new NotFound("a route claiming a prefix lists no tracks");
709
+ return listTracks(this.#state.listing, owner);
710
+ }
711
+ /**
712
+ * Release this handle, like dropping a Rust handle. A produced broadcast stays open until
713
+ * its producer closes; one consumed from a session ends once no {@link clone} holds it.
714
+ */
715
+ close() {
333
716
  if (this.#closed)
334
717
  return;
335
718
  this.#closed = true;
336
- if (--this.#state.consumers > 0)
719
+ if (--this.#state.consumers > 0 || !this.#state.unheld)
337
720
  return;
338
- closeState(this.#state, abort);
721
+ closeState(this.#state);
339
722
  }
340
723
  }
341
724
  //# sourceMappingURL=broadcast.js.map