@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/broadcast.js CHANGED
@@ -4,121 +4,363 @@
4
4
  * @module
5
5
  */
6
6
  import { Once, Signal } from "@moq/signals";
7
- import { NotFound } from "./error.js";
8
- import { Route } from "./hop.js";
9
- 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";
10
13
  import * as Path from "./path.js";
11
14
  import * as track from "./track.js";
12
15
  import { untilAborted } from "./util/abort.js";
13
- import { registerWire, trackOf } from "./wire.js";
14
- let attachAnnouncer;
16
+ import { checkName } from "./util/utf8.js";
17
+ import { registerWire, trackMetaOf, trackOf, wireOf } from "./wire.js";
18
+ export { Tracks } from "./listing.js";
15
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
+ }
16
25
  /** Reactive backing state shared by broadcast producers and consumers. */
17
26
  class BroadcastState {
18
27
  requested = new Signal([]);
28
+ datagramRequested = new Signal([]);
29
+ datagramPending = new Set();
30
+ datagrams = new Map();
31
+ datagramServed = false;
19
32
  pending = new Set();
20
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.
21
38
  tracks = new Map();
22
- sequences = new Map();
23
- // Live consumer handles sharing this state (see {@link Consumer.clone}). The broadcast
24
- // 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}).
25
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
+ }
26
157
  }
27
158
  function dequeueRequest(state) {
28
159
  const requested = state.requested.peek();
29
160
  requested.sort((a, b) => a.priority - b.priority);
30
161
  return requested.pop();
31
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
+ }
32
179
  // Close the broadcast and reject any requests still pending in the queue, so a
33
180
  // subscriber blocked on the track's info() or group reads is unblocked rather
34
181
  // than left waiting on a producer that will never be served.
35
182
  //
36
183
  // Once.set throws on a second settle, and the producer and each consumer handle close
37
184
  // independently, so this has to be idempotent.
38
- function closeState(state, abort) {
185
+ function closeState(state) {
39
186
  if (state.closed.peek() !== undefined)
40
187
  return;
41
- 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([]);
42
193
  for (const request of state.pending)
43
- request.reject(abort);
194
+ request.reject(new StreamError(StreamCode.Internal, {
195
+ message: `track request ${request.name} dropped before acceptance`,
196
+ }));
44
197
  state.requested.mutate((requests) => {
45
198
  requests.length = 0;
46
199
  });
200
+ for (const fn of state.closers)
201
+ fn();
202
+ state.closers.clear();
47
203
  }
48
- // `register` is set on the subscribing (consumer) side: the fresh producer is cached in
49
- // `state.tracks` so repeat subscriptions to the same track fan out from one upstream subscription
50
- // instead of opening a new one, mirroring the Rust `broadcast::Consumer::track` weak-dedup. The
51
- // consumer wire watches the producer's demand ({@link track.Producer.used}) and tears the upstream
52
- // down once its last subscriber leaves, closing the producer, which evicts the cache entry below.
53
- // The publishing side leaves `register` false: `state.tracks` there holds only the tracks the app
54
- // inserted, and a dynamic serve stays one request per peer subscription.
55
- function subscribe(state, name, options = {}, register = false) {
56
- if (state.closed.peek() !== undefined) {
57
- throw new Error(`broadcast is closed: ${state.closed.peek()}`);
58
- }
59
- const existing = state.tracks.get(name);
60
- if (existing) {
61
- if (existing.closed.peek() === undefined)
62
- 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;
63
211
  state.tracks.delete(name);
64
212
  }
65
- const producer = new track.Producer(name);
66
- const subscriber = producer.subscribe(options);
67
- if (register) {
68
- state.tracks.set(name, producer);
69
- // Drop the cache entry once the upstream closes (the wire tears it down when its last
70
- // subscriber leaves), so a later subscribe re-opens it.
71
- void producer.closed.then(() => {
72
- if (state.tracks.get(name) === producer)
73
- state.tracks.delete(name);
74
- });
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);
75
219
  }
76
- state.requested.mutate((requested) => {
77
- requested.push(hooks.makeRequest({ name, producer, sequences: state.sequences, pending: state.pending }));
78
- });
79
- return subscriber;
220
+ return undefined;
80
221
  }
81
- async function resolveTrackInfo(state, name) {
82
- const existing = state.tracks.get(name);
83
- if (existing && existing.closed.peek() === undefined) {
84
- return existing.info();
85
- }
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) {
86
237
  if (state.closed.peek() !== undefined) {
87
- 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 };
88
250
  }
89
- 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
+ });
90
259
  state.requested.mutate((requested) => {
91
- 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 }));
92
261
  });
93
- try {
94
- return await producer.info();
95
- }
96
- finally {
97
- 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
+ }
98
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);
99
310
  }
100
- // Serve a group from the local retained window by subscribing and scanning to the
101
- // requested sequence. The default for a produced broadcast; the consuming wire layer
102
- // overrides it to fetch over the network (or to reject when the transport has no FETCH).
103
- 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) {
104
318
  options.signal?.throwIfAborted();
105
- const subscriber = subscribe(state, name, { priority: options.priority });
106
- 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);
107
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}`);
108
335
  for (;;) {
109
- const group = await untilAborted(subscriber.recvGroup(), options.signal);
110
- if (!group)
111
- throw new NotFound(`group ${sequence}`);
112
- if (group.sequence === sequence) {
113
- // Close the subscription when the returned group finishes, not now: an
114
- // in-progress group must keep receiving frames for its lifetime (mirrors
115
- // Rust poll_fetch). Also fires if the caller closes the group early.
116
- void group.closed.then(() => subscriber.close());
117
- 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}`);
118
362
  }
119
- group.close();
120
- if (group.sequence > sequence)
121
- throw new NotFound(`group ${sequence}`);
363
+ await untilAborted(changed(subscriber), options.signal);
122
364
  }
123
365
  }
124
366
  catch (err) {
@@ -126,6 +368,50 @@ async function fetchGroup(state, name, sequence, options = {}) {
126
368
  throw err;
127
369
  }
128
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
+ }
129
415
  /**
130
416
  * The write side of a broadcast.
131
417
  *
@@ -133,22 +419,54 @@ async function fetchGroup(state, name, sequence, options = {}) {
133
419
  */
134
420
  export class Producer {
135
421
  #state = new BroadcastState();
136
- #announcer;
137
422
  #path = Path.empty();
138
423
  constructor() {
139
- 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) });
140
441
  }
141
442
  static {
142
- attachAnnouncer = (producer, announcer) => {
143
- 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);
144
463
  };
145
- hooks.attachAnnouncer = attachAnnouncer;
146
464
  stampProducer = (producer, path) => {
147
465
  producer.#path = path;
148
466
  };
149
467
  }
150
468
  /**
151
- * 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.
152
470
  * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
153
471
  */
154
472
  get closed() {
@@ -158,84 +476,64 @@ export class Producer {
158
476
  consume() {
159
477
  return makeConsumer({ state: this.#state, path: this.#path });
160
478
  }
161
- async #requested() {
162
- for (;;) {
163
- const request = dequeueRequest(this.#state);
164
- if (request)
165
- return request;
166
- const closed = this.#state.closed.peek();
167
- if (closed instanceof Error)
168
- throw closed;
169
- if (closed !== undefined)
170
- return undefined;
171
- await Signal.race(this.#state.requested, this.#state.closed);
172
- }
173
- }
174
- /** Insert a track that is served directly, without an on-demand request round-trip. */
175
- 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 = {}) {
176
491
  if (this.#state.closed.peek() !== undefined) {
177
- throw new Error(`broadcast is closed: ${this.#state.closed.peek()}`);
492
+ throw new Error("broadcast is closed");
178
493
  }
179
- const existing = this.#state.tracks.get(track.name);
180
- if (existing && existing.closed.peek() === undefined) {
181
- 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;
182
501
  }
183
- this.#state.tracks.set(track.name, track);
184
- void track.closed.then(() => {
185
- if (this.#state.tracks.get(track.name) === track) {
186
- this.#state.tracks.delete(track.name);
187
- }
188
- });
189
- }
190
- /** Create a track, insert it into the broadcast, and return its producer. */
191
- createTrack(name, info = {}) {
192
- const producer = new track.Producer(name).accept(info);
193
- 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));
194
510
  return producer;
195
511
  }
196
- /** 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
+ */
197
523
  removeTrack(name) {
524
+ const track = this.#state.tracks.get(name);
525
+ if (!track)
526
+ return;
198
527
  this.#state.tracks.delete(name);
528
+ this.#state.listing.unlistOwn(track);
199
529
  }
200
530
  /** A lazy read handle for a track on this broadcast. */
201
531
  track(name) {
202
532
  return trackOf(name, this);
203
533
  }
204
- #wire(register) {
205
- return {
206
- subscribe: (name, options) => subscribe(this.#state, name, options, register),
207
- resolveTrackInfo: (name) => resolveTrackInfo(this.#state, name),
208
- fetchGroup: (name, sequence, options) => fetchGroup(this.#state, name, sequence, options),
209
- requested: () => this.#requested(),
210
- };
211
- }
212
- /**
213
- * Advertise this broadcast's exact path, or re-price a standing advertisement in place.
214
- *
215
- * Call it once the tracks a subscriber needs first (a catalog) exist. Until then the
216
- * broadcast exists for nobody, on its own origin or at a peer. Retracts on
217
- * {@link unannounce} or {@link close}. Throws if this producer was not created through an
218
- * origin, or if the broadcast is already closed.
219
- */
220
- announce(route = Route.default) {
221
- if (this.#state.closed.peek() !== undefined) {
222
- throw new Error(`broadcast is closed: ${this.#state.closed.peek()}`);
223
- }
224
- if (!this.#announcer)
225
- throw new Error("broadcast is not attached to an origin");
226
- this.#announcer.announce(Route.normalize(route));
227
- }
228
- /**
229
- * Retract the advertisement of this broadcast's path, if any, from local consumers and
230
- * peers alike. {@link announce} brings it back.
231
- */
232
- unannounce() {
233
- this.#announcer?.unannounce();
234
- }
235
- close(abort) {
236
- this.#announcer?.unannounce();
237
- this.#announcer = undefined;
238
- closeState(this.#state, abort);
534
+ /** End the broadcast for good: serve no new tracks. Idempotent. */
535
+ close() {
536
+ closeState(this.#state);
239
537
  }
240
538
  }
241
539
  // Constructs a Consumer from within this module without exposing a public constructor
@@ -252,18 +550,43 @@ let makeConsumer;
252
550
  export class Consumer {
253
551
  #state;
254
552
  #path;
553
+ #identity;
554
+ // Served on request through a route claiming a shorter prefix, which names no broadcast to list.
555
+ #unlisted;
255
556
  // Guards against a double close() on this handle over-decrementing the consumer count.
256
557
  #closed = false;
257
558
  constructor(shared) {
258
- this.#state = shared?.state ?? new BroadcastState();
259
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
+ }
260
572
  this.#state.consumers++;
261
- registerWire(this, {
262
- subscribe: (name, options) => subscribe(this.#state, name, options, true),
263
- resolveTrackInfo: (name) => resolveTrackInfo(this.#state, name),
264
- fetchGroup: (name, sequence, options) => fetchGroup(this.#state, name, sequence, options),
265
- requested: () => this.#requested(),
266
- });
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) });
267
590
  }
268
591
  static {
269
592
  makeConsumer = (shared) => new Consumer(shared);
@@ -273,6 +596,25 @@ export class Consumer {
273
596
  else
274
597
  stampProducer(target, path);
275
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
+ };
276
618
  }
277
619
  /**
278
620
  * The path this handle names the broadcast by, which relative references in its catalog
@@ -286,11 +628,22 @@ export class Consumer {
286
628
  return this.#path;
287
629
  }
288
630
  /**
289
- * 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.
290
642
  * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.
291
643
  *
292
- * Shared by every {@link clone}: it settles once the last handle closes. The subscribing
293
- * 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.
294
647
  */
295
648
  get closed() {
296
649
  return this.#state.closed;
@@ -299,42 +652,73 @@ export class Consumer {
299
652
  * Return another handle to the same broadcast, reference-counted with this one.
300
653
  *
301
654
  * Both handles read the same tracks, carry the same {@link path}, and share one {@link closed}
302
- * 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
303
656
  * consume cache to share one subscription across callers. Subclasses that resolve info over
304
657
  * the wire override this to preserve their type (see the wire layer's consumed broadcast).
305
658
  */
306
659
  clone() {
307
660
  return new Consumer(this.shareState());
308
661
  }
309
- // Hand this consumer's backing state and path to a clone. Opaque (`never`) so the state type
310
- // 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
+ */
311
668
  shareState() {
312
- 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);
313
680
  }
314
681
  /** Get a lazy handle for a track on this broadcast. Repeat subscriptions dedupe onto one upstream subscription. */
315
682
  track(name) {
316
683
  return trackOf(name, this);
317
684
  }
318
- async #requested() {
319
- for (;;) {
320
- const request = dequeueRequest(this.#state);
321
- if (request)
322
- return request;
323
- const closed = this.#state.closed.peek();
324
- if (closed instanceof Error)
325
- throw closed;
326
- if (closed !== undefined)
327
- return undefined;
328
- await Signal.race(this.#state.requested, this.#state.closed);
329
- }
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));
330
691
  }
331
- 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() {
332
716
  if (this.#closed)
333
717
  return;
334
718
  this.#closed = true;
335
- if (--this.#state.consumers > 0)
719
+ if (--this.#state.consumers > 0 || !this.#state.unheld)
336
720
  return;
337
- closeState(this.#state, abort);
721
+ closeState(this.#state);
338
722
  }
339
723
  }
340
724
  //# sourceMappingURL=broadcast.js.map