@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/lite/fills.js ADDED
@@ -0,0 +1,486 @@
1
+ // Fills a copy asks of its upstream through a subscription: lite-07's own, or before it, one of its
2
+ // own per run. Mirrors the Rust `lite/subscriber/fills.rs`.
3
+ import { now, sleepUntil } from "@moq/clock";
4
+ import { race, Signal } from "@moq/signals";
5
+ import { NotFound } from "../error.js";
6
+ import { fillChanged, wantedRuns } from "../fill.js";
7
+ import { hooks, insertRun, removeRun, runGaps, subtractRuns } from "../internal.js";
8
+ import { GRACE } from "../ledger.js";
9
+ import { max, min } from "../util/key.js";
10
+ import { hasRanges } from "./version.js";
11
+ /** The lowest priority, which any fill's outranks. */
12
+ const NO_PRIORITY = -128;
13
+ /** The source does not have the groups, as past the track's end: lost, so the track records it. */
14
+ export function dropped(error) {
15
+ return { kind: "lost", error };
16
+ }
17
+ /** Not delivered on this subscription, which says nothing of the source. */
18
+ export function passing(error) {
19
+ return { kind: "passing", error };
20
+ }
21
+ /** Judged stale, so an asked fill is recovered once. */
22
+ export function stale(error) {
23
+ return { kind: "stale", error };
24
+ }
25
+ /** Dropped by a lite-07 subscription alone, so an asked fill is recovered once. */
26
+ export function scoped(error) {
27
+ return { kind: "scoped", error };
28
+ }
29
+ /** `runs` with `[start, end)` refused by `refusal` instead, so a repeated refusal costs nothing. */
30
+ export function refuseRun(runs, start, end, refusal) {
31
+ if (start >= end)
32
+ return [...runs];
33
+ return [...removeRun(runs, start, end), { start, end, refusal }].sort(byStart);
34
+ }
35
+ class Recovery {
36
+ handle;
37
+ refused;
38
+ // The groups it refused and handed over, which it no longer covers, so a later request for
39
+ // them asks again rather than waiting on its other streams.
40
+ released = [];
41
+ // `ended` is called once it is over, so a wait need not hold a reaction on `done`.
42
+ constructor(handle, ended) {
43
+ this.handle = handle;
44
+ void handle.done.then((refused) => {
45
+ this.refused = refused;
46
+ ended();
47
+ });
48
+ }
49
+ get groups() {
50
+ return this.handle.groups();
51
+ }
52
+ }
53
+ /**
54
+ * Fills a lite-07 upstream serves through the copy's subscription: each held fill's next owed run
55
+ * joins the subscription's ranges until its groups arrive or the publisher names them given up,
56
+ * and the fill answers itself from the cache.
57
+ *
58
+ * A fill is judged against the subscription that asked for it alone. The track's arrivals still
59
+ * account for a group an earlier subscription cut, which this one may still deliver, so only what
60
+ * this subscription says it will not deliver (a SUBSCRIBE_DROP, or a range start past the range)
61
+ * refuses a fill. A range start speaks only for its range: once the range retires, a later one
62
+ * asking for the same groups may start lower. A group it drops as stale is officially dropped,
63
+ * and one it already accounted for (delivered before and since evicted) it never sends again, so
64
+ * a recovery asks for either on its own history subscription: a stale run once, and an
65
+ * accounted group as often as it is evicted again before its fill answers. This cache evicts only
66
+ * groups idle past their expiry, so each recovery lands a group its fill answers. Nothing newer
67
+ * judges it stale there, so once every hop forgot a run, a narrow reader takes its stale groups.
68
+ *
69
+ * A group stays asked until its stream finishes, since narrowing the subscription under a stream
70
+ * still arriving would reset it.
71
+ *
72
+ * Before lite-07 a subscription carries one range, so each run goes out on a recovery of its own
73
+ * instead. Its publisher names no keys between two group starts (no GROUP_END or SUBSCRIBE_SKIP),
74
+ * and the keys of a timed track are its media time, so asking a run key by key would cost a
75
+ * round trip per microsecond. A SUBSCRIBE from the run's first key answers in one round trip
76
+ * instead: its start is the first group at or past that key, and nothing below it is delivered.
77
+ */
78
+ export class RangeFills {
79
+ #copy;
80
+ // Each run goes on its own subscription before lite-07 or after the original feed ends.
81
+ #perRun;
82
+ #recover;
83
+ #held = [];
84
+ /** What the subscription asks for the fills now. */
85
+ ask = { groups: [], priority: NO_PRIORITY, order: "ascending" };
86
+ // Bumped on every input `poll` reads that no other signal reports.
87
+ #bumped = new Signal(0);
88
+ // Asked groups no fill owes any more whose stream is still arriving, and how each ends.
89
+ #reading = new Map();
90
+ // Asked groups no fill owes any more, already searched for streams still arriving.
91
+ #draining = [];
92
+ // Groups the subscription said it will not deliver, and why.
93
+ #refused = [];
94
+ // Groups below where a fill's range starts, with the asked run that range carries, which stand
95
+ // only while that range is live.
96
+ #skipped = [];
97
+ // Groups dropped as stale, which a recovery has yet to ask for.
98
+ #toRecover = [];
99
+ // Groups a recovery asks for now, which the subscription leaves out meanwhile.
100
+ #recovering = [];
101
+ // Groups recovered once already, which a second stale drop refuses.
102
+ #recovered = [];
103
+ #recoveries = new Set();
104
+ #closed = false;
105
+ /** The fills of `copy`, whose upstream speaks `version`, each recovery opened by `recover`. */
106
+ constructor(copy, version, recover) {
107
+ this.#copy = copy;
108
+ this.#perRun = !hasRanges(version);
109
+ this.#recover = recover;
110
+ }
111
+ /** Whether no fill is held, asked for, or recovering. */
112
+ isEmpty() {
113
+ return this.#held.length === 0 && this.ask.groups.length === 0 && this.#recoveries.size === 0;
114
+ }
115
+ /** Whether a recovery is still out. */
116
+ get recovering() {
117
+ return this.#recoveries.size > 0;
118
+ }
119
+ /** Close the feed's fill ranges, keeping held fills and their separate recoveries. */
120
+ finishFeed() {
121
+ if (this.#perRun)
122
+ return;
123
+ this.#perRun = true;
124
+ this.ask = { groups: [], priority: NO_PRIORITY, order: "ascending" };
125
+ this.#reading.clear();
126
+ this.#draining = [];
127
+ this.#skipped = [];
128
+ this.#bump();
129
+ }
130
+ push(fill) {
131
+ this.#held.push(fill);
132
+ this.#bump();
133
+ }
134
+ /**
135
+ * The subscription will not deliver `[start, end)`: a fill owing one is answered with `refusal`,
136
+ * or recovered once first when the refusal says another request may still get it.
137
+ */
138
+ refuse(start, end, refusal) {
139
+ // Only what a fill asked for: a fill asks for nothing the subscription dropped before it.
140
+ for (const run of clip(this.ask.groups, start, end)) {
141
+ if (refusal.kind === "stale" || refusal.kind === "scoped") {
142
+ const done = clip(this.#recovered, run.start, run.end);
143
+ for (const fresh of runGaps(done, run.start, run.end))
144
+ insertRun(this.#toRecover, fresh.start, fresh.end);
145
+ // Recovered once already: this drop stands for the fills owing it now, except where a
146
+ // recovery still out asks for it, whose answer it waits on.
147
+ for (const again of done)
148
+ for (const stands of runGaps(this.#recovering, again.start, again.end))
149
+ this.#setRefused(stands.start, stands.end, refusal);
150
+ continue;
151
+ }
152
+ this.#setRefused(run.start, run.end, refusal);
153
+ }
154
+ this.#bump();
155
+ }
156
+ /**
157
+ * The subscription's range for the asked run `asked` starts past `[start, end)`, which it will
158
+ * not deliver while that range is live.
159
+ */
160
+ skip(asked, start, end) {
161
+ if (start >= end)
162
+ return;
163
+ this.#skipped = [...removeRun(this.#skipped, start, end), { start, end, asked: { ...asked } }].sort(byStart);
164
+ this.#bump();
165
+ }
166
+ /**
167
+ * Settle each held fill against what the subscription refused, open a recovery for each run it
168
+ * will not deliver, and recompute what to ask. `tail` is the subscription's, and `read` whether
169
+ * anyone still reads the track. Returns whether the ask changed, or whether it {@link isEmpty}:
170
+ * a subscription holding its FIN for the fills waits on either.
171
+ */
172
+ poll(tail, read) {
173
+ const empty = this.isEmpty();
174
+ // The groups the subscription already spent (accounted for, or forgot whether it did), which
175
+ // it never sends again, are
176
+ // recovered on their own, as often as the cache evicts them before a reader takes them: a key
177
+ // a reader is owed is never lost to the cache. Mirrors the Rust `RangeFills::poll`.
178
+ const asked = [];
179
+ for (const fill of this.#held) {
180
+ const run = nextRun(fill);
181
+ if (run)
182
+ insertRun(asked, run.start, run.end);
183
+ }
184
+ for (const run of asked) {
185
+ for (const gone of tail.spent(run.start, run.end)) {
186
+ for (const gap of runGaps(this.#recovering, gone.start, gone.end))
187
+ for (const owed of this.#unrefused(gap.start, gap.end))
188
+ insertRun(this.#toRecover, owed.start, owed.end);
189
+ }
190
+ }
191
+ // Each stale run goes out on its own history subscription, once, with the priority
192
+ // of the fills held now: the last ask may predate them.
193
+ let priority = this.ask.priority;
194
+ for (const fill of this.#held)
195
+ priority = Math.max(priority, fill.priority);
196
+ for (const run of this.#toRecover.splice(0)) {
197
+ insertRun(this.#recovered, run.start, run.end);
198
+ insertRun(this.#recovering, run.start, run.end);
199
+ this.#recoveries.add(new Recovery(this.#recover(run, priority), () => this.#bump()));
200
+ }
201
+ // What a finished recovery did not deliver stands refused.
202
+ for (const done of this.#recoveries) {
203
+ if (!done.refused)
204
+ continue;
205
+ this.#recoveries.delete(done);
206
+ for (const refused of done.refused)
207
+ this.#setRefused(refused.start, refused.end, refused.refusal);
208
+ }
209
+ // What a recovery still out refused since the last poll answers the fills owing it now,
210
+ // rather than waiting on its other streams. Taken once, so once those fills end, a later
211
+ // request for the same groups asks again rather than reading it back.
212
+ for (const recovery of this.#recoveries) {
213
+ for (const refused of recovery.handle.takeRefused()) {
214
+ this.#setRefused(refused.start, refused.end, refused.refusal);
215
+ insertRun(recovery.released, refused.start, refused.end);
216
+ }
217
+ }
218
+ // Rebuilt from those still out, so one ending leaves a later one's coverage of the same
219
+ // groups intact.
220
+ this.#cover();
221
+ // A run's own subscription answers only below its start, so what lies past it is asked
222
+ // again rather than counted recovered.
223
+ if (this.#perRun)
224
+ this.#recovered = [...this.#recovering];
225
+ const ask = { groups: [], priority: NO_PRIORITY, order: "ascending" };
226
+ // Every run a held fill still owes, recovered or not.
227
+ const owed = [];
228
+ const held = [];
229
+ // Not asked of the subscription: a run being recovered waits on its own, and a group already
230
+ // refused is answered once its fill reaches it.
231
+ const waiting = [...this.#recovering];
232
+ for (const refused of this.#refused)
233
+ insertRun(waiting, refused.start, refused.end);
234
+ for (const fill of this.#held) {
235
+ for (;;) {
236
+ const run = nextRun(fill);
237
+ if (!run) {
238
+ fill.close();
239
+ break;
240
+ }
241
+ // The run extends from the group owed first, which the subscription may have refused
242
+ // already. Refusing the run answers it, so the loop moves on.
243
+ const first = fill.order === "ascending" ? run.start : run.end - 1n;
244
+ const refused = this.#refusal(first);
245
+ if (refused) {
246
+ answer(refused.refusal, fill, max(run.start, refused.start), min(run.end, refused.end));
247
+ continue;
248
+ }
249
+ insertRun(owed, run.start, run.end);
250
+ for (const gap of runGaps(waiting, run.start, run.end))
251
+ insertRun(ask.groups, gap.start, gap.end);
252
+ ask.priority = Math.max(ask.priority, fill.priority);
253
+ if (fill.order === "descending")
254
+ ask.order = "descending";
255
+ held.push(fill);
256
+ break;
257
+ }
258
+ }
259
+ this.#held = held;
260
+ // A refusal answers only the fills owing it now: trimmed to the groups a held fill still
261
+ // covers, so a later request for the rest asks again, and a loss it named stays recorded on
262
+ // the track alone.
263
+ const covered = [];
264
+ for (const fill of held)
265
+ if (fill.start < fill.end)
266
+ insertRun(covered, fill.start, fill.end);
267
+ this.#refused = this.#refused.flatMap((run) => clip(covered, run.start, run.end).map((part) => ({ ...part, refusal: run.refusal })));
268
+ // Each run goes out on its own subscription, asked again by the next pass, which polls it.
269
+ if (this.#perRun && ask.groups.length > 0) {
270
+ this.#toRecover = ask.groups;
271
+ return this.poll(tail, read) || this.isEmpty() !== empty;
272
+ }
273
+ // A recovery no held fill owes any group of is cancelled, once none of its streams is still
274
+ // being read or nobody reads the track, and a group is recovered once for the fills owing it
275
+ // now: a later request for it may recover it again.
276
+ for (const recovery of this.#recoveries) {
277
+ const { start, end } = recovery.groups;
278
+ if (clip(owed, start, end).length > 0 || (read && recovery.handle.reading()))
279
+ continue;
280
+ recovery.handle.cancel();
281
+ this.#recoveries.delete(recovery);
282
+ }
283
+ this.#cover();
284
+ this.#recovered = this.#recovered.flatMap(({ start, end }) => clip(owed, start, end));
285
+ // A run stays asked whole while a fill still owes any of it, so the subscription changes once
286
+ // as a run is asked and once as it is done, and the streams of its answered groups keep
287
+ // arriving. One no fill owes stays while any of its streams is still arriving and someone
288
+ // reads the track, each group searched for once.
289
+ for (const [key, closed] of this.#reading)
290
+ if (closed.peek() !== undefined)
291
+ this.#reading.delete(key);
292
+ const groups = ask.groups.map((run) => ({ ...run }));
293
+ const draining = [];
294
+ for (const run of this.ask.groups) {
295
+ if (clip(ask.groups, run.start, run.end).length > 0) {
296
+ insertRun(groups, run.start, run.end);
297
+ continue;
298
+ }
299
+ if (!read)
300
+ continue;
301
+ // Only the groups the cache holds, so a wide run costs what it holds.
302
+ for (const gap of runGaps(this.#draining, run.start, run.end)) {
303
+ for (const key of hooks.arrivingIn(this.#copy, gap.start, gap.end)) {
304
+ // Only watched until it ends, never taken over, so it is not held.
305
+ const arriving = hooks.arrivingGroup(this.#copy, key);
306
+ arriving?.release();
307
+ if (arriving !== undefined)
308
+ this.#reading.set(key, arriving.settled);
309
+ }
310
+ }
311
+ if ([...this.#reading.keys()].some((key) => run.start <= key && key < run.end)) {
312
+ insertRun(groups, run.start, run.end);
313
+ insertRun(draining, run.start, run.end);
314
+ }
315
+ }
316
+ for (const key of this.#reading.keys())
317
+ if (!draining.some((run) => run.start <= key && key < run.end))
318
+ this.#reading.delete(key);
319
+ this.#draining = draining;
320
+ // A run being recovered leaves the subscription, even out of a run kept whole: the subscription
321
+ // dropped it for good, so asking it there again would never be answered.
322
+ const remaining = this.#recovering.reduce((runs, run) => removeRun(runs, run.start, run.end), groups);
323
+ // What finishes a stream still asks with what its fills asked.
324
+ if (this.#held.length === 0 && remaining.length > 0) {
325
+ ask.priority = this.ask.priority;
326
+ ask.order = this.ask.order;
327
+ }
328
+ ask.groups = remaining;
329
+ if (ask.priority === this.ask.priority && ask.order === this.ask.order && sameRuns(ask.groups, this.ask.groups))
330
+ return this.isEmpty() !== empty;
331
+ this.ask = ask;
332
+ return true;
333
+ }
334
+ /** Resolves once any input {@link poll} reads may have changed, whether `demand` reads among them. */
335
+ changed(tail, demand) {
336
+ const wakes = [
337
+ Signal.race(this.#bumped, tail.changed, demand.wanted, hooks.demandReleased(demand), ...[...this.#recoveries].flatMap((recovery) => [
338
+ recovery.handle.changed,
339
+ recovery.handle.readingChanged,
340
+ ])),
341
+ ];
342
+ for (const fill of this.#held)
343
+ wakes.push(fillChanged(fill));
344
+ for (const closed of this.#reading.values())
345
+ wakes.push(closed);
346
+ return race(wakes);
347
+ }
348
+ /** The copy closed: every held fill names what is left dropped, and every recovery stops. */
349
+ close() {
350
+ if (this.#closed)
351
+ return;
352
+ this.#closed = true;
353
+ for (const fill of this.#held.splice(0))
354
+ fill.close();
355
+ for (const recovery of this.#recoveries)
356
+ recovery.handle.cancel();
357
+ this.#recoveries.clear();
358
+ this.ask = { groups: [], priority: NO_PRIORITY, order: "ascending" };
359
+ this.#bump();
360
+ }
361
+ /** Whether {@link close} was called. */
362
+ get closed() {
363
+ return this.#closed;
364
+ }
365
+ // The keys of `[start, end)` neither the subscription nor a recovery said it will not deliver,
366
+ // nor the subscriber's own range starts past: a refusal answers only its own keys, so a group
367
+ // past a skipped run is still owed.
368
+ #unrefused(start, end) {
369
+ return subtractRuns(subtractRuns([{ start, end }], this.#refused), this.#skipped);
370
+ }
371
+ // Why the subscription or a recovery will not deliver the run of groups from `first`, if it
372
+ // said so.
373
+ #refusal(first) {
374
+ const refused = this.#refused.find((run) => run.start <= first && first < run.end);
375
+ if (refused)
376
+ return refused;
377
+ // The subscriber's own range starting past them says nothing of the source.
378
+ const skipped = this.#skipped.find((run) => run.start <= first && first < run.end);
379
+ if (!skipped)
380
+ return undefined;
381
+ return { start: skipped.start, end: skipped.end, refusal: passing(new NotFound(`group ${skipped.start}`)) };
382
+ }
383
+ // What the recoveries still out cover: each its groups less what it refused and handed over.
384
+ #cover() {
385
+ this.#recovering = [];
386
+ for (const { groups, released } of this.#recoveries)
387
+ for (const gap of runGaps(released, groups.start, groups.end))
388
+ insertRun(this.#recovering, gap.start, gap.end);
389
+ }
390
+ #setRefused(start, end, refusal) {
391
+ this.#refused = refuseRun(this.#refused, start, end, refusal);
392
+ }
393
+ /** The groups the ask leaves out on purpose: refused, or recovered on their own. */
394
+ avoid() {
395
+ const avoid = [...this.#recovering];
396
+ for (const refused of this.#refused)
397
+ insertRun(avoid, refused.start, refused.end);
398
+ return avoid;
399
+ }
400
+ /**
401
+ * Asking for `asked` from now on, the runs the subscription carries, retires the range of each
402
+ * run not asked whole any more, and what its start skipped with it.
403
+ */
404
+ retireSkipped(asked) {
405
+ this.#skipped = this.#skipped.filter((skipped) => asked.some((run) => run.start === skipped.asked.start && run.end === skipped.asked.end));
406
+ }
407
+ #bump() {
408
+ this.#bumped.update((revision) => revision + 1);
409
+ }
410
+ }
411
+ // The run `fill` owes first in its order, extending from the group it owes first.
412
+ function nextRun(fill) {
413
+ const owed = wantedRuns(fill);
414
+ return fill.order === "ascending" ? owed[0] : owed.at(-1);
415
+ }
416
+ /**
417
+ * TEMPORARY MIGRATION, delete at the next version cut, once no relay of the previous release is left:
418
+ * how long a capped recovery may go without progress before what it still owes is refused. Mirrors
419
+ * the Rust `Stall`.
420
+ *
421
+ * A relay of the previous release never answers the keys below the first group. A current one
422
+ * answers them once its own upstream does, which may take longer than the grace behind a slow or
423
+ * deep chain, so the grace restarts on every response and data stream instead of running from the
424
+ * cap.
425
+ */
426
+ export class Stall {
427
+ #timer = new AbortController();
428
+ #deadline;
429
+ // The tail's streams received and whether one is being read, when last seen.
430
+ #seen;
431
+ /** Settles once the grace may have passed, to wake whoever polls it. */
432
+ wake;
433
+ /** Start the grace for a recovery reading `tail`. */
434
+ constructor(tail) {
435
+ this.#seen = [tail.streams, tail.reading];
436
+ this.restart();
437
+ }
438
+ /** Restart the grace, as the publisher made progress. */
439
+ restart() {
440
+ this.#timer.abort();
441
+ this.#timer = new AbortController();
442
+ this.#deadline = now().saturatingAdd(GRACE);
443
+ // Only a wake: whether the grace passed is read from the clock, so a timer that fired just
444
+ // before a restart counts for nothing.
445
+ this.wake = sleepUntil(this.#deadline, { signal: this.#timer.signal }).catch(() => undefined);
446
+ }
447
+ /** Whether the grace passed with no stream arriving, being read, or finishing. */
448
+ poll(tail) {
449
+ const reading = tail.reading;
450
+ if (reading || tail.streams !== this.#seen[0] || reading !== this.#seen[1]) {
451
+ this.#seen = [tail.streams, reading];
452
+ this.restart();
453
+ }
454
+ return now().ge(this.#deadline);
455
+ }
456
+ /** Stop the timer. */
457
+ close() {
458
+ this.#timer.abort();
459
+ }
460
+ }
461
+ // Answer `[start, end)` of `fill`: a lost group is named dropped, and anything else is refused for
462
+ // now, recorded nowhere.
463
+ function answer(refusal, fill, start, end) {
464
+ if (refusal.kind === "lost")
465
+ fill.dropGroups(start, end);
466
+ else
467
+ fill.refuseGroups(start, end, refusal.error);
468
+ }
469
+ // The parts of `runs` inside `[start, end)`.
470
+ function clip(runs, start, end) {
471
+ const parts = [];
472
+ for (const run of runs) {
473
+ const from = max(run.start, start);
474
+ const to = min(run.end, end);
475
+ if (from < to)
476
+ parts.push({ start: from, end: to });
477
+ }
478
+ return parts;
479
+ }
480
+ function sameRuns(a, b) {
481
+ return a.length === b.length && a.every((run, i) => run.start === b[i].start && run.end === b[i].end);
482
+ }
483
+ function byStart(a, b) {
484
+ return a.start < b.start ? -1 : a.start > b.start ? 1 : 0;
485
+ }
486
+ //# sourceMappingURL=fills.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fills.js","sourceRoot":"","sources":["../../src/lite/fills.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,4DAA4D;AAE5D,OAAO,EAAgB,GAAG,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAY,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9F,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAGrC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAgB,MAAM,cAAc,CAAC;AAEvD,sDAAsD;AACtD,MAAM,WAAW,GAAG,CAAC,GAAG,CAAC;AA0BzB,mGAAmG;AACnG,MAAM,UAAU,OAAO,CAAC,KAAY;IACnC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAChC,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,OAAO,CAAC,KAAY;IACn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: lite-07's own, or before it, one of its\n// own per run. Mirrors the Rust `lite/subscriber/fills.rs`.\n\nimport { type Instant, now, sleepUntil } from \"@moq/clock\";\nimport { type GetPromise, type Getter, race, Signal } from \"@moq/signals\";\nimport { NotFound } from \"../error.ts\";\nimport { fillChanged, wantedRuns } from \"../fill.ts\";\nimport { hooks, insertRun, type Run, removeRun, runGaps, subtractRuns } from \"../internal.ts\";\nimport { GRACE } from \"../ledger.ts\";\nimport type { Tail } from \"../tail.ts\";\nimport type * as track from \"../track.ts\";\nimport { max, min } from \"../util/key.ts\";\nimport { hasRanges, type Version } from \"./version.ts\";\n\n/** The lowest priority, which any fill's outranks. */\nconst NO_PRIORITY = -128;\n\n/**\n * Why the subscription that asked for groups will not deliver them, and the error a reader asking\n * for them gets. Mirrors the Rust `Refusal`.\n *\n * - `lost`: the source can never have them, past the track's end, which the track records so no\n * reader asks again.\n * - `stale`: judged stale under a budget (a SUBSCRIBE_OLD, or any drop before lite-07).\n * - `scoped`: a lite-07 SUBSCRIBE_DROP, the subscription's alone.\n * - `passing`: not delivered on this subscription, which says nothing of the source.\n *\n * A fill that asked for `stale` or `scoped` groups is recovered once, since another request may\n * still get them. Anything but `lost` answers only the fills owing them now. A SUBSCRIBE_SKIP's\n * groups are `passing`: the skip the track records answers the fills owing them first.\n */\nexport interface Refusal {\n\tkind: \"lost\" | \"stale\" | \"scoped\" | \"passing\";\n\terror: Error;\n}\n\n/** Groups a subscription refused, and why. */\nexport interface Refused extends Run {\n\trefusal: Refusal;\n}\n\n/** The source does not have the groups, as past the track's end: lost, so the track records it. */\nexport function dropped(error: Error): Refusal {\n\treturn { kind: \"lost\", error };\n}\n\n/** Not delivered on this subscription, which says nothing of the source. */\nexport function passing(error: Error): Refusal {\n\treturn { kind: \"passing\", error };\n}\n\n/** Judged stale, so an asked fill is recovered once. */\nexport function stale(error: Error): Refusal {\n\treturn { kind: \"stale\", error };\n}\n\n/** Dropped by a lite-07 subscription alone, so an asked fill is recovered once. */\nexport function scoped(error: Error): Refusal {\n\treturn { kind: \"scoped\", error };\n}\n\n/** `runs` with `[start, end)` refused by `refusal` instead, so a repeated refusal costs nothing. */\nexport function refuseRun(runs: readonly Refused[], start: bigint, end: bigint, refusal: Refusal): Refused[] {\n\tif (start >= end) return [...runs];\n\treturn [...removeRun(runs, start, end), { start, end, refusal }].sort(byStart);\n}\n\n/**\n * A subscription asking again, as history that never goes stale, for groups another one dropped as stale or\n * already delivered, which a fill still owes: what the subscriber opens for a {@link RangeFills}.\n */\nexport interface RecoveryHandle {\n\t/** The groups it still asks for: before lite-07, only up to the group it starts at. */\n\tgroups(): Run;\n\t/** Resolves once it is over, with the groups it refused. */\n\tdone: Promise<Refused[]>;\n\t/**\n\t * The groups it refused since the last call, each handed over once, which answer the fills\n\t * owing them before it is over. Its {@link done} resolves with only those never taken.\n\t */\n\ttakeRefused(): Refused[];\n\t/** Bumped each time it refuses more. */\n\treadonly changed: Getter<number>;\n\t/** Bumped as its streams arrive and finish, which {@link reading} reports. */\n\treadonly readingChanged: Getter<unknown>;\n\t/** Whether a stream of it is still being read, which cancelling would cut. */\n\treading(): boolean;\n\t/** Stop asking: what is left is refused. */\n\tcancel(): void;\n}\n\nclass Recovery {\n\treadonly handle: RecoveryHandle;\n\trefused?: Refused[];\n\t// The groups it refused and handed over, which it no longer covers, so a later request for\n\t// them asks again rather than waiting on its other streams.\n\treadonly released: Run[] = [];\n\n\t// `ended` is called once it is over, so a wait need not hold a reaction on `done`.\n\tconstructor(handle: RecoveryHandle, ended: () => void) {\n\t\tthis.handle = handle;\n\t\tvoid handle.done.then((refused) => {\n\t\t\tthis.refused = refused;\n\t\t\tended();\n\t\t});\n\t}\n\n\tget groups(): Run {\n\t\treturn this.handle.groups();\n\t}\n}\n\n/** What a lite-07 copy's held fills ask of its upstream subscription, beside the demand. */\nexport interface FillAsk {\n\t/** The groups to ask for, empty when no fill is held. */\n\tgroups: Run[];\n\t/** The most urgent priority a held fill asks with, which the subscription takes if higher. */\n\tpriority: number;\n\t/** Oldest first, unless a held fill reads newest first. */\n\torder: track.Order;\n}\n\n/**\n * Fills a lite-07 upstream serves through the copy's subscription: each held fill's next owed run\n * joins the subscription's ranges until its groups arrive or the publisher names them given up,\n * and the fill answers itself from the cache.\n *\n * A fill is judged against the subscription that asked for it alone. The track's arrivals still\n * account for a group an earlier subscription cut, which this one may still deliver, so only what\n * this subscription says it will not deliver (a SUBSCRIBE_DROP, or a range start past the range)\n * refuses a fill. A range start speaks only for its range: once the range retires, a later one\n * asking for the same groups may start lower. A group it drops as stale is officially dropped,\n * and one it already accounted for (delivered before and since evicted) it never sends again, so\n * a recovery asks for either on its own history subscription: a stale run once, and an\n * accounted group as often as it is evicted again before its fill answers. This cache evicts only\n * groups idle past their expiry, so each recovery lands a group its fill answers. Nothing newer\n * judges it stale there, so once every hop forgot a run, a narrow reader takes its stale groups.\n *\n * A group stays asked until its stream finishes, since narrowing the subscription under a stream\n * still arriving would reset it.\n *\n * Before lite-07 a subscription carries one range, so each run goes out on a recovery of its own\n * instead. Its publisher names no keys between two group starts (no GROUP_END or SUBSCRIBE_SKIP),\n * and the keys of a timed track are its media time, so asking a run key by key would cost a\n * round trip per microsecond. A SUBSCRIBE from the run's first key answers in one round trip\n * instead: its start is the first group at or past that key, and nothing below it is delivered.\n */\nexport class RangeFills {\n\treadonly #copy: track.Producer;\n\t// Each run goes on its own subscription before lite-07 or after the original feed ends.\n\t#perRun: boolean;\n\treadonly #recover: (groups: Run, priority: number) => RecoveryHandle;\n\t#held: track.FillGroups[] = [];\n\t/** What the subscription asks for the fills now. */\n\task: FillAsk = { groups: [], priority: NO_PRIORITY, order: \"ascending\" };\n\t// Bumped on every input `poll` reads that no other signal reports.\n\treadonly #bumped = new Signal(0);\n\t// Asked groups no fill owes any more whose stream is still arriving, and how each ends.\n\t#reading = new Map<bigint, GetPromise<Error | null>>();\n\t// Asked groups no fill owes any more, already searched for streams still arriving.\n\t#draining: Run[] = [];\n\t// Groups the subscription said it will not deliver, and why.\n\t#refused: Refused[] = [];\n\t// Groups below where a fill's range starts, with the asked run that range carries, which stand\n\t// only while that range is live.\n\t#skipped: (Run & { asked: Run })[] = [];\n\t// Groups dropped as stale, which a recovery has yet to ask for.\n\t#toRecover: Run[] = [];\n\t// Groups a recovery asks for now, which the subscription leaves out meanwhile.\n\t#recovering: Run[] = [];\n\t// Groups recovered once already, which a second stale drop refuses.\n\t#recovered: Run[] = [];\n\t#recoveries = new Set<Recovery>();\n\t#closed = false;\n\n\t/** The fills of `copy`, whose upstream speaks `version`, each recovery opened by `recover`. */\n\tconstructor(copy: track.Producer, version: Version, recover: (groups: Run, priority: number) => RecoveryHandle) {\n\t\tthis.#copy = copy;\n\t\tthis.#perRun = !hasRanges(version);\n\t\tthis.#recover = recover;\n\t}\n\n\t/** Whether no fill is held, asked for, or recovering. */\n\tisEmpty(): boolean {\n\t\treturn this.#held.length === 0 && this.ask.groups.length === 0 && this.#recoveries.size === 0;\n\t}\n\n\t/** Whether a recovery is still out. */\n\tget recovering(): boolean {\n\t\treturn this.#recoveries.size > 0;\n\t}\n\n\t/** Close the feed's fill ranges, keeping held fills and their separate recoveries. */\n\tfinishFeed(): void {\n\t\tif (this.#perRun) return;\n\t\tthis.#perRun = true;\n\t\tthis.ask = { groups: [], priority: NO_PRIORITY, order: \"ascending\" };\n\t\tthis.#reading.clear();\n\t\tthis.#draining = [];\n\t\tthis.#skipped = [];\n\t\tthis.#bump();\n\t}\n\n\tpush(fill: track.FillGroups): void {\n\t\tthis.#held.push(fill);\n\t\tthis.#bump();\n\t}\n\n\t/**\n\t * The subscription will not deliver `[start, end)`: a fill owing one is answered with `refusal`,\n\t * or recovered once first when the refusal says another request may still get it.\n\t */\n\trefuse(start: bigint, end: bigint, refusal: Refusal): void {\n\t\t// Only what a fill asked for: a fill asks for nothing the subscription dropped before it.\n\t\tfor (const run of clip(this.ask.groups, start, end)) {\n\t\t\tif (refusal.kind === \"stale\" || refusal.kind === \"scoped\") {\n\t\t\t\tconst done = clip(this.#recovered, run.start, run.end);\n\t\t\t\tfor (const fresh of runGaps(done, run.start, run.end))\n\t\t\t\t\tinsertRun(this.#toRecover, fresh.start, fresh.end);\n\t\t\t\t// Recovered once already: this drop stands for the fills owing it now, except where a\n\t\t\t\t// recovery still out asks for it, whose answer it waits on.\n\t\t\t\tfor (const again of done)\n\t\t\t\t\tfor (const stands of runGaps(this.#recovering, again.start, again.end))\n\t\t\t\t\t\tthis.#setRefused(stands.start, stands.end, refusal);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#setRefused(run.start, run.end, refusal);\n\t\t}\n\t\tthis.#bump();\n\t}\n\n\t/**\n\t * The subscription's range for the asked run `asked` starts past `[start, end)`, which it will\n\t * not deliver while that range is live.\n\t */\n\tskip(asked: Run, start: bigint, end: bigint): void {\n\t\tif (start >= end) return;\n\t\tthis.#skipped = [...removeRun(this.#skipped, start, end), { start, end, asked: { ...asked } }].sort(byStart);\n\t\tthis.#bump();\n\t}\n\n\t/**\n\t * Settle each held fill against what the subscription refused, open a recovery for each run it\n\t * will not deliver, and recompute what to ask. `tail` is the subscription's, and `read` whether\n\t * anyone still reads the track. Returns whether the ask changed, or whether it {@link isEmpty}:\n\t * a subscription holding its FIN for the fills waits on either.\n\t */\n\tpoll(tail: Tail, read: boolean): boolean {\n\t\tconst empty = this.isEmpty();\n\t\t// The groups the subscription already spent (accounted for, or forgot whether it did), which\n\t\t// it never sends again, are\n\t\t// recovered on their own, as often as the cache evicts them before a reader takes them: a key\n\t\t// a reader is owed is never lost to the cache. Mirrors the Rust `RangeFills::poll`.\n\t\tconst asked: Run[] = [];\n\t\tfor (const fill of this.#held) {\n\t\t\tconst run = nextRun(fill);\n\t\t\tif (run) insertRun(asked, run.start, run.end);\n\t\t}\n\t\tfor (const run of asked) {\n\t\t\tfor (const gone of tail.spent(run.start, run.end)) {\n\t\t\t\tfor (const gap of runGaps(this.#recovering, gone.start, gone.end))\n\t\t\t\t\tfor (const owed of this.#unrefused(gap.start, gap.end))\n\t\t\t\t\t\tinsertRun(this.#toRecover, owed.start, owed.end);\n\t\t\t}\n\t\t}\n\t\t// Each stale run goes out on its own history subscription, once, with the priority\n\t\t// of the fills held now: the last ask may predate them.\n\t\tlet priority = this.ask.priority;\n\t\tfor (const fill of this.#held) priority = Math.max(priority, fill.priority);\n\t\tfor (const run of this.#toRecover.splice(0)) {\n\t\t\tinsertRun(this.#recovered, run.start, run.end);\n\t\t\tinsertRun(this.#recovering, run.start, run.end);\n\t\t\tthis.#recoveries.add(new Recovery(this.#recover(run, priority), () => this.#bump()));\n\t\t}\n\t\t// What a finished recovery did not deliver stands refused.\n\t\tfor (const done of this.#recoveries) {\n\t\t\tif (!done.refused) continue;\n\t\t\tthis.#recoveries.delete(done);\n\t\t\tfor (const refused of done.refused) this.#setRefused(refused.start, refused.end, refused.refusal);\n\t\t}\n\t\t// What a recovery still out refused since the last poll answers the fills owing it now,\n\t\t// rather than waiting on its other streams. Taken once, so once those fills end, a later\n\t\t// request for the same groups asks again rather than reading it back.\n\t\tfor (const recovery of this.#recoveries) {\n\t\t\tfor (const refused of recovery.handle.takeRefused()) {\n\t\t\t\tthis.#setRefused(refused.start, refused.end, refused.refusal);\n\t\t\t\tinsertRun(recovery.released, refused.start, refused.end);\n\t\t\t}\n\t\t}\n\t\t// Rebuilt from those still out, so one ending leaves a later one's coverage of the same\n\t\t// groups intact.\n\t\tthis.#cover();\n\t\t// A run's own subscription answers only below its start, so what lies past it is asked\n\t\t// again rather than counted recovered.\n\t\tif (this.#perRun) this.#recovered = [...this.#recovering];\n\n\t\tconst ask: FillAsk = { groups: [], priority: NO_PRIORITY, order: \"ascending\" };\n\t\t// Every run a held fill still owes, recovered or not.\n\t\tconst owed: Run[] = [];\n\t\tconst held: track.FillGroups[] = [];\n\t\t// Not asked of the subscription: a run being recovered waits on its own, and a group already\n\t\t// refused is answered once its fill reaches it.\n\t\tconst waiting = [...this.#recovering];\n\t\tfor (const refused of this.#refused) insertRun(waiting, refused.start, refused.end);\n\t\tfor (const fill of this.#held) {\n\t\t\tfor (;;) {\n\t\t\t\tconst run = nextRun(fill);\n\t\t\t\tif (!run) {\n\t\t\t\t\tfill.close();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// The run extends from the group owed first, which the subscription may have refused\n\t\t\t\t// already. Refusing the run answers it, so the loop moves on.\n\t\t\t\tconst first = fill.order === \"ascending\" ? run.start : run.end - 1n;\n\t\t\t\tconst refused = this.#refusal(first);\n\t\t\t\tif (refused) {\n\t\t\t\t\tanswer(refused.refusal, fill, max(run.start, refused.start), min(run.end, refused.end));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tinsertRun(owed, run.start, run.end);\n\t\t\t\tfor (const gap of runGaps(waiting, run.start, run.end)) insertRun(ask.groups, gap.start, gap.end);\n\t\t\t\task.priority = Math.max(ask.priority, fill.priority);\n\t\t\t\tif (fill.order === \"descending\") ask.order = \"descending\";\n\t\t\t\theld.push(fill);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tthis.#held = held;\n\n\t\t// A refusal answers only the fills owing it now: trimmed to the groups a held fill still\n\t\t// covers, so a later request for the rest asks again, and a loss it named stays recorded on\n\t\t// the track alone.\n\t\tconst covered: Run[] = [];\n\t\tfor (const fill of held) if (fill.start < fill.end) insertRun(covered, fill.start, fill.end);\n\t\tthis.#refused = this.#refused.flatMap((run) =>\n\t\t\tclip(covered, run.start, run.end).map((part) => ({ ...part, refusal: run.refusal })),\n\t\t);\n\n\t\t// Each run goes out on its own subscription, asked again by the next pass, which polls it.\n\t\tif (this.#perRun && ask.groups.length > 0) {\n\t\t\tthis.#toRecover = ask.groups;\n\t\t\treturn this.poll(tail, read) || this.isEmpty() !== empty;\n\t\t}\n\n\t\t// A recovery no held fill owes any group of is cancelled, once none of its streams is still\n\t\t// being read or nobody reads the track, and a group is recovered once for the fills owing it\n\t\t// now: a later request for it may recover it again.\n\t\tfor (const recovery of this.#recoveries) {\n\t\t\tconst { start, end } = recovery.groups;\n\t\t\tif (clip(owed, start, end).length > 0 || (read && recovery.handle.reading())) continue;\n\t\t\trecovery.handle.cancel();\n\t\t\tthis.#recoveries.delete(recovery);\n\t\t}\n\t\tthis.#cover();\n\t\tthis.#recovered = this.#recovered.flatMap(({ start, end }) => clip(owed, start, end));\n\n\t\t// A run stays asked whole while a fill still owes any of it, so the subscription changes once\n\t\t// as a run is asked and once as it is done, and the streams of its answered groups keep\n\t\t// arriving. One no fill owes stays while any of its streams is still arriving and someone\n\t\t// reads the track, each group searched for once.\n\t\tfor (const [key, closed] of this.#reading) if (closed.peek() !== undefined) this.#reading.delete(key);\n\t\tconst groups = ask.groups.map((run) => ({ ...run }));\n\t\tconst draining: Run[] = [];\n\t\tfor (const run of this.ask.groups) {\n\t\t\tif (clip(ask.groups, run.start, run.end).length > 0) {\n\t\t\t\tinsertRun(groups, run.start, run.end);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!read) continue;\n\t\t\t// Only the groups the cache holds, so a wide run costs what it holds.\n\t\t\tfor (const gap of runGaps(this.#draining, run.start, run.end)) {\n\t\t\t\tfor (const key of hooks.arrivingIn(this.#copy, gap.start, gap.end)) {\n\t\t\t\t\t// Only watched until it ends, never taken over, so it is not held.\n\t\t\t\t\tconst arriving = hooks.arrivingGroup(this.#copy, key);\n\t\t\t\t\tarriving?.release();\n\t\t\t\t\tif (arriving !== undefined) this.#reading.set(key, arriving.settled);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ([...this.#reading.keys()].some((key) => run.start <= key && key < run.end)) {\n\t\t\t\tinsertRun(groups, run.start, run.end);\n\t\t\t\tinsertRun(draining, run.start, run.end);\n\t\t\t}\n\t\t}\n\t\tfor (const key of this.#reading.keys())\n\t\t\tif (!draining.some((run) => run.start <= key && key < run.end)) this.#reading.delete(key);\n\t\tthis.#draining = draining;\n\t\t// A run being recovered leaves the subscription, even out of a run kept whole: the subscription\n\t\t// dropped it for good, so asking it there again would never be answered.\n\t\tconst remaining = this.#recovering.reduce((runs, run) => removeRun(runs, run.start, run.end), groups);\n\t\t// What finishes a stream still asks with what its fills asked.\n\t\tif (this.#held.length === 0 && remaining.length > 0) {\n\t\t\task.priority = this.ask.priority;\n\t\t\task.order = this.ask.order;\n\t\t}\n\t\task.groups = remaining;\n\t\tif (ask.priority === this.ask.priority && ask.order === this.ask.order && sameRuns(ask.groups, this.ask.groups))\n\t\t\treturn this.isEmpty() !== empty;\n\t\tthis.ask = ask;\n\t\treturn true;\n\t}\n\n\t/** Resolves once any input {@link poll} reads may have changed, whether `demand` reads among them. */\n\tchanged(tail: Tail, demand: track.Demand): Promise<unknown> {\n\t\tconst wakes: unknown[] = [\n\t\t\tSignal.race(\n\t\t\t\tthis.#bumped,\n\t\t\t\ttail.changed,\n\t\t\t\tdemand.wanted,\n\t\t\t\thooks.demandReleased(demand),\n\t\t\t\t...[...this.#recoveries].flatMap((recovery) => [\n\t\t\t\t\trecovery.handle.changed,\n\t\t\t\t\trecovery.handle.readingChanged,\n\t\t\t\t]),\n\t\t\t),\n\t\t];\n\t\tfor (const fill of this.#held) wakes.push(fillChanged(fill));\n\t\tfor (const closed of this.#reading.values()) wakes.push(closed);\n\t\treturn race(wakes);\n\t}\n\n\t/** The copy closed: every held fill names what is left dropped, and every recovery stops. */\n\tclose(): void {\n\t\tif (this.#closed) return;\n\t\tthis.#closed = true;\n\t\tfor (const fill of this.#held.splice(0)) fill.close();\n\t\tfor (const recovery of this.#recoveries) recovery.handle.cancel();\n\t\tthis.#recoveries.clear();\n\t\tthis.ask = { groups: [], priority: NO_PRIORITY, order: \"ascending\" };\n\t\tthis.#bump();\n\t}\n\n\t/** Whether {@link close} was called. */\n\tget closed(): boolean {\n\t\treturn this.#closed;\n\t}\n\n\t// The keys of `[start, end)` neither the subscription nor a recovery said it will not deliver,\n\t// nor the subscriber's own range starts past: a refusal answers only its own keys, so a group\n\t// past a skipped run is still owed.\n\t#unrefused(start: bigint, end: bigint): Run[] {\n\t\treturn subtractRuns(subtractRuns([{ start, end }], this.#refused), this.#skipped);\n\t}\n\n\t// Why the subscription or a recovery will not deliver the run of groups from `first`, if it\n\t// said so.\n\t#refusal(first: bigint): Refused | undefined {\n\t\tconst refused = this.#refused.find((run) => run.start <= first && first < run.end);\n\t\tif (refused) return refused;\n\t\t// The subscriber's own range starting past them says nothing of the source.\n\t\tconst skipped = this.#skipped.find((run) => run.start <= first && first < run.end);\n\t\tif (!skipped) return undefined;\n\t\treturn { start: skipped.start, end: skipped.end, refusal: passing(new NotFound(`group ${skipped.start}`)) };\n\t}\n\n\t// What the recoveries still out cover: each its groups less what it refused and handed over.\n\t#cover(): void {\n\t\tthis.#recovering = [];\n\t\tfor (const { groups, released } of this.#recoveries)\n\t\t\tfor (const gap of runGaps(released, groups.start, groups.end))\n\t\t\t\tinsertRun(this.#recovering, gap.start, gap.end);\n\t}\n\n\t#setRefused(start: bigint, end: bigint, refusal: Refusal): void {\n\t\tthis.#refused = refuseRun(this.#refused, start, end, refusal);\n\t}\n\n\t/** The groups the ask leaves out on purpose: refused, or recovered on their own. */\n\tavoid(): Run[] {\n\t\tconst avoid = [...this.#recovering];\n\t\tfor (const refused of this.#refused) insertRun(avoid, refused.start, refused.end);\n\t\treturn avoid;\n\t}\n\n\t/**\n\t * Asking for `asked` from now on, the runs the subscription carries, retires the range of each\n\t * run not asked whole any more, and what its start skipped with it.\n\t */\n\tretireSkipped(asked: readonly Run[]): void {\n\t\tthis.#skipped = this.#skipped.filter((skipped) =>\n\t\t\tasked.some((run) => run.start === skipped.asked.start && run.end === skipped.asked.end),\n\t\t);\n\t}\n\n\t#bump(): void {\n\t\tthis.#bumped.update((revision) => revision + 1);\n\t}\n}\n\n// The run `fill` owes first in its order, extending from the group it owes first.\nfunction nextRun(fill: track.FillGroups): Run | undefined {\n\tconst owed = wantedRuns(fill);\n\treturn fill.order === \"ascending\" ? owed[0] : owed.at(-1);\n}\n\n/**\n * TEMPORARY MIGRATION, delete at the next version cut, once no relay of the previous release is left:\n * how long a capped recovery may go without progress before what it still owes is refused. Mirrors\n * the Rust `Stall`.\n *\n * A relay of the previous release never answers the keys below the first group. A current one\n * answers them once its own upstream does, which may take longer than the grace behind a slow or\n * deep chain, so the grace restarts on every response and data stream instead of running from the\n * cap.\n */\nexport class Stall {\n\t#timer = new AbortController();\n\t#deadline!: Instant;\n\t// The tail's streams received and whether one is being read, when last seen.\n\t#seen: [number, boolean];\n\t/** Settles once the grace may have passed, to wake whoever polls it. */\n\twake!: Promise<void>;\n\n\t/** Start the grace for a recovery reading `tail`. */\n\tconstructor(tail: Tail) {\n\t\tthis.#seen = [tail.streams, tail.reading];\n\t\tthis.restart();\n\t}\n\n\t/** Restart the grace, as the publisher made progress. */\n\trestart(): void {\n\t\tthis.#timer.abort();\n\t\tthis.#timer = new AbortController();\n\t\tthis.#deadline = now().saturatingAdd(GRACE);\n\t\t// Only a wake: whether the grace passed is read from the clock, so a timer that fired just\n\t\t// before a restart counts for nothing.\n\t\tthis.wake = sleepUntil(this.#deadline, { signal: this.#timer.signal }).catch(() => undefined);\n\t}\n\n\t/** Whether the grace passed with no stream arriving, being read, or finishing. */\n\tpoll(tail: Tail): boolean {\n\t\tconst reading = tail.reading;\n\t\tif (reading || tail.streams !== this.#seen[0] || reading !== this.#seen[1]) {\n\t\t\tthis.#seen = [tail.streams, reading];\n\t\t\tthis.restart();\n\t\t}\n\t\treturn now().ge(this.#deadline);\n\t}\n\n\t/** Stop the timer. */\n\tclose(): void {\n\t\tthis.#timer.abort();\n\t}\n}\n\n// Answer `[start, end)` of `fill`: a lost group is named dropped, and anything else is refused for\n// now, recorded nowhere.\nfunction answer(refusal: Refusal, fill: track.FillGroups, start: bigint, end: bigint): void {\n\tif (refusal.kind === \"lost\") fill.dropGroups(start, end);\n\telse fill.refuseGroups(start, end, refusal.error);\n}\n\n// The parts of `runs` inside `[start, end)`.\nfunction clip(runs: readonly Run[], start: bigint, end: bigint): Run[] {\n\tconst parts: Run[] = [];\n\tfor (const run of runs) {\n\t\tconst from = max(run.start, start);\n\t\tconst to = min(run.end, end);\n\t\tif (from < to) parts.push({ start: from, end: to });\n\t}\n\treturn parts;\n}\n\nfunction sameRuns(a: readonly Run[], b: readonly Run[]): boolean {\n\treturn a.length === b.length && a.every((run, i) => run.start === b[i].start && run.end === b[i].end);\n}\n\nfunction byStart(a: Run, b: Run): number {\n\treturn a.start < b.start ? -1 : a.start > b.start ? 1 : 0;\n}\n"]}
package/lite/fit.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { type Run } from "../internal.ts";
2
+ import { type WireRange } from "./subscribe.ts";
3
+ /**
4
+ * The most a SUBSCRIBE_UPDATE's fields besides its ranges take, size prefix included: nine
5
+ * varints of at most nine bytes, and the priority byte.
6
+ */
7
+ export declare const UPDATE_FIELDS: number;
8
+ /** What lite-07 ranges may take on the wire. */
9
+ export interface Budget {
10
+ /** The bytes every range and its Range ID may take together. */
11
+ bytes: number;
12
+ /** The bytes the largest Range ID any of the ranges may take. */
13
+ id: number;
14
+ }
15
+ /**
16
+ * The budget for ranges a subscription takes Range IDs from `next` for, whose SUBSCRIBE carries
17
+ * `fields` bytes besides its ranges, `count` the most ranges it asks for.
18
+ *
19
+ * Half a message, so that the ranges sent last, retired by Range ID, and the ranges replacing
20
+ * them fit one SUBSCRIBE_UPDATE however little the two share: a relay never narrows its ask in
21
+ * between, which would reset group streams still arriving. Never more than leaves room in a
22
+ * SUBSCRIBE for one range past it, which {@link fitAfter} takes.
23
+ *
24
+ * A live range the update retunes instead, its policy or a live join's max changed in place,
25
+ * costs its Range ID, two bytes, and its max, never more than the range as the update asks for it:
26
+ * the ranges replacing the last pay for their retunes as they do for their additions.
27
+ */
28
+ export declare function budget(fields: number, next: bigint, count: number): Budget;
29
+ /**
30
+ * As many of `ranges`, in order, as fit `budget` beside the `spent` ones, at least the first: one
31
+ * range past them still fits the message, which the budget leaves room for. Mirrors the Rust
32
+ * `Budget::fit_after`.
33
+ */
34
+ export declare function fitAfter(budget: Budget, spent: readonly WireRange[], ranges: readonly WireRange[]): WireRange[];
35
+ /**
36
+ * `demand`'s ranges and the `fills` groups, each widened only as far as both must be to fit
37
+ * `budget`, as the same arrays when nothing must. A gap between fills closes across `avoid`,
38
+ * sorted, disjoint groups the fills leave out on purpose, only once every other gap has. A
39
+ * widened demand range names its groups by time, as the demand's own do, at the most urgent
40
+ * policy among the ranges it covers, so no group goes out later than one of them asked.
41
+ *
42
+ * Throws when even one range per kind of start would not fit, which only a broadcast path or
43
+ * track name filling the message leaves.
44
+ */
45
+ export declare function fit(demand: readonly WireRange[], fills: readonly Run[], avoid: readonly Run[], budget: Budget): {
46
+ ranges: readonly WireRange[];
47
+ fills: readonly Run[];
48
+ };
49
+ //# sourceMappingURL=fit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fit.d.ts","sourceRoot":"","sources":["../../src/lite/fit.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,gBAAgB,CAAC;AAGpD,OAAO,EAA0D,KAAK,SAAS,EAAc,MAAM,gBAAgB,CAAC;AAEpH;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAY,CAAC;AAQvC,gDAAgD;AAChD,MAAM,WAAW,MAAM;IACtB,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,EAAE,EAAE,MAAM,CAAC;CACX;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAS1E;AAYD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,CAS/G;AAgCD;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAClB,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,KAAK,EAAE,SAAS,GAAG,EAAE,EACrB,KAAK,EAAE,SAAS,GAAG,EAAE,EACrB,MAAM,EAAE,MAAM,GACZ;IAAE,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IAAC,KAAK,EAAE,SAAS,GAAG,EAAE,CAAA;CAAE,CAkDzD"}