@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/tail.js CHANGED
@@ -1,21 +1,13 @@
1
+ import { now, sleep } from "@moq/clock";
1
2
  import { Signal } from "@moq/signals";
2
- import { Milli } from "./time.js";
3
- /**
4
- * How long a subscriber waits for a group stream it cannot account for once the publisher
5
- * has ended the subscription.
6
- *
7
- * A group reset before its header arrived leaves no trace, and QUIC does not order streams,
8
- * so a stream opened before the end can still be in flight after it. This bounds the wait on
9
- * IETF, and on moq-lite when the subscription has no max age to bound it with.
10
- */
11
- export const TAIL_GRACE_MS = Milli(1000);
12
- // setTimeout truncates a longer delay to a signed 32-bit int and fires at once.
13
- const MAX_TIMEOUT_MS = 2 ** 31 - 1;
3
+ import { insertRun, runGaps, runsFrom } from "./internal.js";
4
+ import { GRACE, Ledger, MAX_RUNS } from "./ledger.js";
5
+ import { max, min } from "./util/key.js";
14
6
  /**
15
7
  * The group streams a subscription has received, so its end can wait for the ones still owed.
16
8
  *
17
9
  * A publisher ends a subscription before every group stream it opened has necessarily
18
- * arrived. This records which sequences are accounted for (a stream's header arrived, or
10
+ * arrived. This records which keys are accounted for (a stream's header arrived, or
19
11
  * the publisher dropped them) and how many streams are still being read, and {@link settle}
20
12
  * waits on them.
21
13
  *
@@ -25,140 +17,275 @@ const MAX_TIMEOUT_MS = 2 ** 31 - 1;
25
17
  * @internal
26
18
  */
27
19
  export class Tail {
28
- // Disjoint, sorted, non-adjacent runs of accounted sequences. A gap older than the grace
29
- // can no longer be waited for, so it folds into the runs around it, which bounds this by
30
- // the gaps opened within the grace rather than every gap in the subscription. A fold is
31
- // final: a later, longer grace or a lowered floor cannot reopen it.
32
- #runs = [];
33
- // Group streams whose header arrived, and those still being read.
20
+ // The keys accounted for, whose gaps fold once the grace stops waiting for them.
21
+ #ledger;
22
+ // Group streams whose header arrived, and those still being read and holding the end.
34
23
  #streams = 0;
35
24
  #active = 0;
25
+ // The counted streams holding the end open, which a settle gives up on once they go quiet.
26
+ #held = new Set();
27
+ // The lowest group a stream's header named, which proves the group exists.
28
+ #first;
36
29
  #changed = new Signal(0);
37
30
  #grace;
38
- #now;
31
+ // Keys a drop named, so a stream whose header the drop overtook can be told from one
32
+ // whose gap the grace gave up on.
33
+ #dropped = [];
39
34
  constructor(options = {}) {
40
- this.#grace = options.grace ?? (() => TAIL_GRACE_MS);
41
- this.#now = options.now ?? (() => performance.now());
35
+ this.#grace = options.grace ?? (() => GRACE);
36
+ this.#ledger = new Ledger({ proven: options.proven });
37
+ }
38
+ /** Release what the tail keeps beside its ledger, once its subscription ended. */
39
+ close() {
40
+ this.#dropped = [];
41
+ this.#held.clear();
42
42
  }
43
43
  /** Group streams whose header arrived, whether they finished or were reset. */
44
44
  get streams() {
45
45
  return this.#streams;
46
46
  }
47
+ /** The lowest group whose stream's header arrived. */
48
+ get first() {
49
+ return this.#first;
50
+ }
47
51
  /**
48
- * Record a group stream whose header arrived. Returns the call that marks it read to
49
- * its end, which is idempotent.
52
+ * Record a group stream whose header arrived, held until it is read to its end. `last` says
53
+ * when it last delivered data, so a settle can give up on a quiet one; without it the stream is
54
+ * waited for until it ends, which is what a reader that cannot tell its stream is lost wants.
50
55
  */
51
- open(sequence) {
56
+ open(key, last) {
52
57
  this.#streams += 1;
58
+ if (this.#first === undefined || key < this.#first)
59
+ this.#first = key;
60
+ this.#active += 1;
61
+ this.#account(key, key + 1n);
62
+ let stall;
63
+ const stalled = new Promise((resolve) => {
64
+ stall = resolve;
65
+ });
66
+ const held = last && { last, since: now(), stalled: false, stall };
67
+ if (held)
68
+ this.#held.add(held);
69
+ // Parked holds nothing.
70
+ let state = "held";
71
+ return {
72
+ stalled,
73
+ done: () => {
74
+ if (state === "done")
75
+ return;
76
+ if (state === "held")
77
+ this.#active -= 1;
78
+ if (held)
79
+ this.#held.delete(held);
80
+ state = "done";
81
+ this.#bump();
82
+ },
83
+ park: () => {
84
+ if (state !== "held")
85
+ return;
86
+ state = "parked";
87
+ this.#active -= 1;
88
+ if (held)
89
+ this.#held.delete(held);
90
+ this.#bump();
91
+ },
92
+ resume: () => {
93
+ if (state !== "parked")
94
+ return;
95
+ state = "held";
96
+ this.#active += 1;
97
+ if (held && !held.stalled) {
98
+ held.since = now();
99
+ this.#held.add(held);
100
+ }
101
+ this.#bump();
102
+ },
103
+ };
104
+ }
105
+ /**
106
+ * Hold the end open for something being read that is not one of the counted streams,
107
+ * such as a joining FETCH's head, or let go of a counted stream while it waits on one.
108
+ * Returns the call that lets go, which is idempotent.
109
+ */
110
+ hold() {
53
111
  this.#active += 1;
54
- this.#account(sequence, sequence + 1);
55
- let closed = false;
112
+ let released = false;
56
113
  return () => {
57
- if (closed)
114
+ if (released)
58
115
  return;
59
- closed = true;
116
+ released = true;
60
117
  this.#active -= 1;
61
118
  this.#bump();
62
119
  };
63
120
  }
64
- /** Record sequences `[start, end)` as accounted for without a stream: dropped, or a datagram. */
121
+ /**
122
+ * Stop holding the end open for a counted stream while it waits on something that holds
123
+ * it instead. Returns the call that holds it again, which must come before the stream's
124
+ * own close.
125
+ */
126
+ suspend() {
127
+ this.#active -= 1;
128
+ this.#bump();
129
+ let resumed = false;
130
+ return () => {
131
+ if (resumed)
132
+ return;
133
+ resumed = true;
134
+ this.#active += 1;
135
+ };
136
+ }
137
+ /** Re-check what {@link settle} waits on, after something outside the ledger changed. */
138
+ touch() {
139
+ this.#bump();
140
+ }
141
+ /** Record keys `[start, end)` as accounted for without a stream: dropped, or a datagram. */
65
142
  account(start, end) {
66
143
  this.#account(start, end);
67
144
  }
145
+ /** Record `[start, end)` as given up by a drop, accounting for it. */
146
+ drop(start, end) {
147
+ insertRun(this.#dropped, start, end);
148
+ while (this.#dropped.length > MAX_RUNS)
149
+ this.#dropped.shift();
150
+ this.#account(start, end);
151
+ }
152
+ /** Whether a drop named `key`. */
153
+ dropped(key) {
154
+ const run = this.#dropped[runsFrom(this.#dropped, key)];
155
+ return run !== undefined && run.start <= key;
156
+ }
68
157
  /** Restart the age of every gap reaching into `[start, end)`, which the demand newly asks for. */
69
158
  demand(start, end) {
70
- if (start >= end)
71
- return;
72
- const now = this.#now();
73
- let below = 0;
74
- this.#runs = this.#runs.map((run) => {
75
- const reached = below < end && start < run.start;
76
- below = run.end;
77
- return reached ? { ...run, since: now } : run;
78
- });
159
+ this.#ledger.demand(start, end, now());
160
+ }
161
+ /** The parts of `[start, end)` accounted for: a stream arrived, a drop named them, or the grace gave up. */
162
+ accounted(start, end) {
163
+ return runGaps(this.#ledger.gaps(start, end), start, end);
164
+ }
165
+ /** Whether a group stream is still being read. */
166
+ get reading() {
167
+ return this.#active > 0;
79
168
  }
80
- /** Whether every sequence in `[start, end)` is accounted for. */
169
+ /** Bumped on every change {@link settle} watches. */
170
+ get changed() {
171
+ return this.#changed;
172
+ }
173
+ /** Whether every key in `[start, end)` is accounted for. */
81
174
  covers(start, end) {
82
- if (start >= end)
83
- return true;
84
- // Runs are merged on insert, so one run covers the span or none does.
85
- return this.#runs.some((run) => run.start <= start && end <= run.end);
175
+ return this.#ledger.covers(start, end);
176
+ }
177
+ /**
178
+ * Whether a proven tail lost the proof for `owed`: a run it does not cover reaches below what
179
+ * its ledger forgot, so it cannot tell a group still owed from one it forgot was accounted for.
180
+ * What it owes above that is still waited for, since the wire can yet account for it. Mirrors the
181
+ * Rust `Tail::lost`.
182
+ */
183
+ lost(owed) {
184
+ const below = this.#ledger.forgotten;
185
+ return (below !== undefined && owed.some((run) => run.start < below && !this.covers(run.start, min(run.end, below))));
186
+ }
187
+ /**
188
+ * Whether nothing still on the wire can change what `[start, end)` gets: every group at or above
189
+ * what the ledger forgot is accounted for. Below that, {@link lost} says whether proof was lost.
190
+ * Mirrors the Rust `Tail::answered`.
191
+ */
192
+ answered(start, end) {
193
+ return this.covers(max(start, this.#ledger.forgotten ?? 0n), end);
194
+ }
195
+ /**
196
+ * What of `[start, end)` this tail spent on its subscription: what it accounts for, and everything
197
+ * below what it forgot, which it may have been told of. A fill for any of it needs a fresh
198
+ * subscription, since this one never reopens a group it delivered or dropped. Mirrors the Rust
199
+ * `Tail::spent`.
200
+ */
201
+ spent(start, end) {
202
+ const below = this.#ledger.forgotten ?? 0n;
203
+ const forgotten = min(end, below);
204
+ const spent = start < forgotten ? [{ start, end: forgotten }] : [];
205
+ return [...spent, ...this.accounted(max(start, below), end)];
86
206
  }
87
207
  /**
88
208
  * Wait until every stream is read to its end and `complete()` holds, or the grace passes
89
209
  * with nothing left being read, or `closed` settles.
90
210
  *
91
- * A stream still being read is always waited for: a group ends on its own stream's FIN
92
- * or reset, never because its track ended. The grace only gives up on streams that never
93
- * arrived.
211
+ * A stream still being read is waited for, until its own FIN or reset, or until a drop naming
212
+ * its group lets go of it (see {@link Counted.done}). The grace gives up on streams that never
213
+ * arrived, and `limit` caps it. With no grace nothing is timed: every start waits for the wire
214
+ * to account for it.
94
215
  */
95
- async settle(complete, closed) {
216
+ settle(complete, closed, limit) {
217
+ return this.#settle(complete, closed, limit, false);
218
+ }
219
+ /**
220
+ * {@link settle} (with the same `limit`) once the publisher ended the subscription, which also gives up on a stream that
221
+ * delivered nothing for {@link GRACE} since (see {@link Counted.stalled}): a browser can lose a
222
+ * stream's reset, leaving it open forever. Not with no grace, where the wire names every group.
223
+ */
224
+ drain(complete, closed, limit) {
225
+ return this.#settle(complete, closed, limit, true);
226
+ }
227
+ async #settle(complete, closed, limit, drain) {
96
228
  // A gap that aged past the grace since the last insert is no longer waited for either.
97
- this.#expire(this.#now());
229
+ const grace = this.#grace();
230
+ const from = now();
231
+ this.#ledger.expire(from, grace);
232
+ const wait = grace === undefined ? undefined : limit === undefined ? grace : grace.min(limit);
98
233
  let expired = false;
99
- const timer = setTimeout(() => {
100
- expired = true;
101
- this.#bump();
102
- }, Math.min(this.#grace(), MAX_TIMEOUT_MS));
234
+ const timer = new AbortController();
235
+ if (wait !== undefined) {
236
+ void sleep(wait, { signal: timer.signal }).then(() => {
237
+ expired = true;
238
+ this.#bump();
239
+ }, () => { });
240
+ }
241
+ // Wakes the loop when the quietest stream's time is up, one at a time.
242
+ let wake;
103
243
  try {
104
244
  while (closed.peek() === undefined) {
105
245
  if (this.#active === 0 && (expired || complete()))
106
246
  return;
247
+ if (drain && grace !== undefined) {
248
+ wake?.abort();
249
+ const next = this.#quiet(GRACE, from);
250
+ if (next !== undefined) {
251
+ wake = new AbortController();
252
+ void sleep(next, { signal: wake.signal }).then(() => this.#bump(), () => { });
253
+ }
254
+ }
107
255
  await Signal.race(this.#changed, closed);
108
256
  }
109
257
  }
110
258
  finally {
111
- clearTimeout(timer);
259
+ timer.abort();
260
+ wake?.abort();
261
+ }
262
+ }
263
+ // Give up on each held stream that delivered nothing for `window` since `from`, and return how
264
+ // long until the next one would have, or undefined with none held.
265
+ #quiet(window, from) {
266
+ const at = now();
267
+ let next;
268
+ for (const held of this.#held) {
269
+ const quiet = at.since(held.last().max(held.since).max(from));
270
+ if (quiet.ge(window)) {
271
+ this.#held.delete(held);
272
+ held.stalled = true;
273
+ held.stall();
274
+ continue;
275
+ }
276
+ const left = window.sub(quiet);
277
+ next = next === undefined ? left : next.min(left);
112
278
  }
279
+ return next;
113
280
  }
114
281
  #account(start, end) {
115
282
  if (start >= end)
116
283
  return;
117
- const now = this.#now();
118
- const runs = [];
119
- let merged;
120
- let placed = false;
121
- for (const run of this.#runs) {
122
- if (run.end < start) {
123
- runs.push(run);
124
- }
125
- else if (end < run.start) {
126
- // Splitting a gap leaves both halves as late as it was.
127
- if (!placed)
128
- runs.push(merged ?? { start, end, since: run.since });
129
- placed = true;
130
- runs.push(run);
131
- }
132
- else {
133
- merged = {
134
- start: Math.min(merged?.start ?? start, run.start),
135
- end: Math.max(merged?.end ?? end, run.end),
136
- since: merged?.since ?? run.since,
137
- };
138
- }
139
- }
140
- // A run past every other one opens a new gap.
141
- if (!placed)
142
- runs.push(merged ?? { start, end, since: now });
143
- this.#runs = runs;
144
- this.#expire(now);
284
+ const at = now();
285
+ this.#ledger.account(start, end, at);
286
+ this.#ledger.expire(at, this.#grace());
145
287
  this.#bump();
146
288
  }
147
- // Fold every gap older than the grace into the runs around it.
148
- #expire(now) {
149
- const grace = this.#grace();
150
- const runs = [];
151
- for (const run of this.#runs) {
152
- const below = runs.at(-1);
153
- if (below && now - run.since >= grace) {
154
- runs[runs.length - 1] = { ...below, end: run.end };
155
- }
156
- else {
157
- runs.push(run);
158
- }
159
- }
160
- this.#runs = runs;
161
- }
162
289
  #bump() {
163
290
  this.#changed.update((revision) => revision + 1);
164
291
  }
package/tail.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tail.js","sourceRoot":"","sources":["../src/tail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AAEzC,gFAAgF;AAChF,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAcnC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,IAAI;IAChB,yFAAyF;IACzF,yFAAyF;IACzF,wFAAwF;IACxF,oEAAoE;IACpE,KAAK,GAAU,EAAE,CAAC;IAClB,kEAAkE;IAClE,QAAQ,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,CAAC,CAAC;IACZ,QAAQ,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;IACzB,MAAM,CAAc;IACpB,IAAI,CAAe;IAEnB,YAAY,OAAO,GAAgB,EAAE;QACpC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,+EAA+E;IAC/E,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,C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GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,KAAK,IAAI,GAAG,GAAG,GAAG,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC;gBACvC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;YACpD,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;QACF,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC;CACD","sourcesContent":["import { type GetPromise, Signal } from \"@moq/signals\";\nimport { Milli } from \"./time.ts\";\n\n/**\n * How long a subscriber waits for a group stream it cannot account for once the publisher\n * has ended the subscription.\n *\n * A group reset before its header arrived leaves no trace, and QUIC does not order streams,\n * so a stream opened before the end can still be in flight after it. This bounds the wait on\n * IETF, and on moq-lite when the subscription has no max age to bound it with.\n */\nexport const TAIL_GRACE_MS = Milli(1000);\n\n// setTimeout truncates a longer delay to a signed 32-bit int and fires at once.\nconst MAX_TIMEOUT_MS = 2 ** 31 - 1;\n\n// A run of accounted sequences `[start, end)`, and when the gap below it opened (in\n// `performance.now()` milliseconds), which is when its missing groups became late.\ntype Run = { start: number; end: number; since: number };\n\n/** How a {@link Tail} measures its grace. */\nexport interface TailOptions {\n\t/** How long to wait for a group that cannot be accounted for. Read each time it is needed. */\n\tgrace?: () => Milli;\n\t/** The clock, in `performance.now()` milliseconds. */\n\tnow?: () => number;\n}\n\n/**\n * The group streams a subscription has received, so its end can wait for the ones still owed.\n *\n * A publisher ends a subscription before every group stream it opened has necessarily\n * arrived. This records which sequences are accounted for (a stream's header arrived, or\n * the publisher dropped them) and how many streams are still being read, and {@link settle}\n * waits on them.\n *\n * A lost datagram is not owed: it leaves a hole that waits out the grace like a stream reset\n * before its header.\n *\n * @internal\n */\nexport class Tail {\n\t// Disjoint, sorted, non-adjacent runs of accounted sequences. A gap older than the grace\n\t// can no longer be waited for, so it folds into the runs around it, which bounds this by\n\t// the gaps opened within the grace rather than every gap in the subscription. A fold is\n\t// final: a later, longer grace or a lowered floor cannot reopen it.\n\t#runs: Run[] = [];\n\t// Group streams whose header arrived, and those still being read.\n\t#streams = 0;\n\t#active = 0;\n\t#changed = new Signal(0);\n\t#grace: () => Milli;\n\t#now: () => number;\n\n\tconstructor(options: TailOptions = {}) {\n\t\tthis.#grace = options.grace ?? (() => TAIL_GRACE_MS);\n\t\tthis.#now = options.now ?? (() => performance.now());\n\t}\n\n\t/** Group streams whose header arrived, whether they finished or were reset. */\n\tget streams(): number {\n\t\treturn this.#streams;\n\t}\n\n\t/**\n\t * Record a group stream whose header arrived. Returns the call that marks it read to\n\t * its end, which is idempotent.\n\t */\n\topen(sequence: number): () => void {\n\t\tthis.#streams += 1;\n\t\tthis.#active += 1;\n\t\tthis.#account(sequence, sequence + 1);\n\n\t\tlet closed = false;\n\t\treturn () => {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\tthis.#active -= 1;\n\t\t\tthis.#bump();\n\t\t};\n\t}\n\n\t/** Record sequences `[start, end)` as accounted for without a stream: dropped, or a datagram. */\n\taccount(start: number, end: number): void {\n\t\tthis.#account(start, end);\n\t}\n\n\t/** Restart the age of every gap reaching into `[start, end)`, which the demand newly asks for. */\n\tdemand(start: number, end: number): void {\n\t\tif (start >= end) return;\n\t\tconst now = this.#now();\n\t\tlet below = 0;\n\t\tthis.#runs = this.#runs.map((run) => {\n\t\t\tconst reached = below < end && start < run.start;\n\t\t\tbelow = run.end;\n\t\t\treturn reached ? { ...run, since: now } : run;\n\t\t});\n\t}\n\n\t/** Whether every sequence in `[start, end)` is accounted for. */\n\tcovers(start: number, end: number): boolean {\n\t\tif (start >= end) return true;\n\t\t// Runs are merged on insert, so one run covers the span or none does.\n\t\treturn this.#runs.some((run) => run.start <= start && end <= run.end);\n\t}\n\n\t/**\n\t * Wait until every stream is read to its end and `complete()` holds, or the grace passes\n\t * with nothing left being read, or `closed` settles.\n\t *\n\t * A stream still being read is always waited for: a group ends on its own stream's FIN\n\t * or reset, never because its track ended. The grace only gives up on streams that never\n\t * arrived.\n\t */\n\tasync settle(complete: () => boolean, closed: GetPromise<unknown>): Promise<void> {\n\t\t// A gap that aged past the grace since the last insert is no longer waited for either.\n\t\tthis.#expire(this.#now());\n\n\t\tlet expired = false;\n\t\tconst timer = setTimeout(\n\t\t\t() => {\n\t\t\t\texpired = true;\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t\tMath.min(this.#grace(), MAX_TIMEOUT_MS),\n\t\t);\n\t\ttry {\n\t\t\twhile (closed.peek() === undefined) {\n\t\t\t\tif (this.#active === 0 && (expired || complete())) return;\n\t\t\t\tawait Signal.race(this.#changed, closed);\n\t\t\t}\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t#account(start: number, end: number): void {\n\t\tif (start >= end) return;\n\n\t\tconst now = this.#now();\n\t\tconst runs: Run[] = [];\n\t\tlet merged: Run | undefined;\n\t\tlet placed = false;\n\t\tfor (const run of this.#runs) {\n\t\t\tif (run.end < start) {\n\t\t\t\truns.push(run);\n\t\t\t} else if (end < run.start) {\n\t\t\t\t// Splitting a gap leaves both halves as late as it was.\n\t\t\t\tif (!placed) runs.push(merged ?? { start, end, since: run.since });\n\t\t\t\tplaced = true;\n\t\t\t\truns.push(run);\n\t\t\t} else {\n\t\t\t\tmerged = {\n\t\t\t\t\tstart: Math.min(merged?.start ?? start, run.start),\n\t\t\t\t\tend: Math.max(merged?.end ?? end, run.end),\n\t\t\t\t\tsince: merged?.since ?? run.since,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\t// A run past every other one opens a new gap.\n\t\tif (!placed) runs.push(merged ?? { start, end, since: now });\n\t\tthis.#runs = runs;\n\t\tthis.#expire(now);\n\t\tthis.#bump();\n\t}\n\n\t// Fold every gap older than the grace into the runs around it.\n\t#expire(now: number): void {\n\t\tconst grace = this.#grace();\n\t\tconst runs: Run[] = [];\n\t\tfor (const run of this.#runs) {\n\t\t\tconst below = runs.at(-1);\n\t\t\tif (below && now - run.since >= grace) {\n\t\t\t\truns[runs.length - 1] = { ...below, end: run.end };\n\t\t\t} else {\n\t\t\t\truns.push(run);\n\t\t\t}\n\t\t}\n\t\tthis.#runs = runs;\n\t}\n\n\t#bump(): void {\n\t\tthis.#changed.update((revision) => revision + 1);\n\t}\n}\n"]}
1
+ {"version":3,"file":"tail.js","sourceRoot":"","sources":["../src/tail.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,GAAG,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAgC,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,SAAS,EAAY,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAwCzC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,IAAI;IAChB,iFAAiF;IACjF,OAAO,CAAS;IAChB,sFAAsF;IACtF,QAAQ,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,CAAC,CAAC;IACZ,2FAA2F;IAC3F,KAAK,GAAG,IAAI,GAAG,EAAQ,CAAC;IACxB,2EAA2E;IAC3E,MAAM,CAAqB;IAC3B,QAAQ,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;IACzB,MAAM,CAA6B;IACnC,qFAAqF;IACrF,kCAAkC;IAClC,QAAQ,GAAU,EAAE,CAAC;IAErB,YAAY,OAAO,G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","sourcesContent":["import { type Duration, type Instant, now, sleep } from \"@moq/clock\";\nimport { type GetPromise, type Getter, Signal } from \"@moq/signals\";\nimport { insertRun, type Run, runGaps, runsFrom } from \"./internal.ts\";\nimport { GRACE, Ledger, MAX_RUNS } from \"./ledger.ts\";\nimport { max, min } from \"./util/key.ts\";\n\n/** How a {@link Tail} measures its grace. */\nexport interface TailOptions {\n\t/**\n\t * How long to wait for a group that cannot be accounted for, or `undefined` to wait until the\n\t * wire accounts for it (lite-07, which names every start). Read each time it is needed.\n\t */\n\tgrace?: () => Duration | undefined;\n\t/** Lite-07: the publisher names every start, so the ledger never folds a gap (see {@link Tail.lost}). */\n\tproven?: boolean;\n}\n\n/** A group stream a {@link Tail} counts, from its header until it is read to its end. */\nexport interface Counted {\n\t/** Stop holding the end open for it: read to its end, or a drop accounted for its group. Idempotent. */\n\tdone(): void;\n\t/** Stop holding the end open while it waits, unread, on a copy another stream delivers. Idempotent. */\n\tpark(): void;\n\t/** Hold the end open again once it reads the group itself. Idempotent. */\n\tresume(): void;\n\t/**\n\t * Settles once {@link Tail.drain} gave up on it: the subscription ended and it delivered nothing\n\t * for the grace, as a stream whose reset the browser lost does. It stays counted\n\t * until the reader ends it with {@link done}.\n\t */\n\treadonly stalled: Promise<void>;\n}\n\n// A stream the end is held open for.\ninterface Held {\n\t// When it last delivered data.\n\tlast: () => Instant;\n\t// When it began being held, since a resumed stream's wait on a copy is not its quiet time.\n\tsince: Instant;\n\t// Given up on, so it is not watched again.\n\tstalled: boolean;\n\tstall: () => void;\n}\n\n/**\n * The group streams a subscription has received, so its end can wait for the ones still owed.\n *\n * A publisher ends a subscription before every group stream it opened has necessarily\n * arrived. This records which keys are accounted for (a stream's header arrived, or\n * the publisher dropped them) and how many streams are still being read, and {@link settle}\n * waits on them.\n *\n * A lost datagram is not owed: it leaves a hole that waits out the grace like a stream reset\n * before its header.\n *\n * @internal\n */\nexport class Tail {\n\t// The keys accounted for, whose gaps fold once the grace stops waiting for them.\n\t#ledger: Ledger;\n\t// Group streams whose header arrived, and those still being read and holding the end.\n\t#streams = 0;\n\t#active = 0;\n\t// The counted streams holding the end open, which a settle gives up on once they go quiet.\n\t#held = new Set<Held>();\n\t// The lowest group a stream's header named, which proves the group exists.\n\t#first: bigint | undefined;\n\t#changed = new Signal(0);\n\t#grace: () => Duration | undefined;\n\t// Keys a drop named, so a stream whose header the drop overtook can be told from one\n\t// whose gap the grace gave up on.\n\t#dropped: Run[] = [];\n\n\tconstructor(options: TailOptions = {}) {\n\t\tthis.#grace = options.grace ?? (() => GRACE);\n\t\tthis.#ledger = new Ledger({ proven: options.proven });\n\t}\n\n\t/** Release what the tail keeps beside its ledger, once its subscription ended. */\n\tclose(): void {\n\t\tthis.#dropped = [];\n\t\tthis.#held.clear();\n\t}\n\n\t/** Group streams whose header arrived, whether they finished or were reset. */\n\tget streams(): number {\n\t\treturn this.#streams;\n\t}\n\n\t/** The lowest group whose stream's header arrived. */\n\tget first(): bigint | undefined {\n\t\treturn this.#first;\n\t}\n\n\t/**\n\t * Record a group stream whose header arrived, held until it is read to its end. `last` says\n\t * when it last delivered data, so a settle can give up on a quiet one; without it the stream is\n\t * waited for until it ends, which is what a reader that cannot tell its stream is lost wants.\n\t */\n\topen(key: bigint, last?: () => Instant): Counted {\n\t\tthis.#streams += 1;\n\t\tif (this.#first === undefined || key < this.#first) this.#first = key;\n\t\tthis.#active += 1;\n\t\tthis.#account(key, key + 1n);\n\n\t\tlet stall!: () => void;\n\t\tconst stalled = new Promise<void>((resolve) => {\n\t\t\tstall = resolve;\n\t\t});\n\t\tconst held: Held | undefined = last && { last, since: now(), stalled: false, stall };\n\t\tif (held) this.#held.add(held);\n\n\t\t// Parked holds nothing.\n\t\tlet state: \"held\" | \"parked\" | \"done\" = \"held\";\n\t\treturn {\n\t\t\tstalled,\n\t\t\tdone: () => {\n\t\t\t\tif (state === \"done\") return;\n\t\t\t\tif (state === \"held\") this.#active -= 1;\n\t\t\t\tif (held) this.#held.delete(held);\n\t\t\t\tstate = \"done\";\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t\tpark: () => {\n\t\t\t\tif (state !== \"held\") return;\n\t\t\t\tstate = \"parked\";\n\t\t\t\tthis.#active -= 1;\n\t\t\t\tif (held) this.#held.delete(held);\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t\tresume: () => {\n\t\t\t\tif (state !== \"parked\") return;\n\t\t\t\tstate = \"held\";\n\t\t\t\tthis.#active += 1;\n\t\t\t\tif (held && !held.stalled) {\n\t\t\t\t\theld.since = now();\n\t\t\t\t\tthis.#held.add(held);\n\t\t\t\t}\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Hold the end open for something being read that is not one of the counted streams,\n\t * such as a joining FETCH's head, or let go of a counted stream while it waits on one.\n\t * Returns the call that lets go, which is idempotent.\n\t */\n\thold(): () => void {\n\t\tthis.#active += 1;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tthis.#active -= 1;\n\t\t\tthis.#bump();\n\t\t};\n\t}\n\n\t/**\n\t * Stop holding the end open for a counted stream while it waits on something that holds\n\t * it instead. Returns the call that holds it again, which must come before the stream's\n\t * own close.\n\t */\n\tsuspend(): () => void {\n\t\tthis.#active -= 1;\n\t\tthis.#bump();\n\t\tlet resumed = false;\n\t\treturn () => {\n\t\t\tif (resumed) return;\n\t\t\tresumed = true;\n\t\t\tthis.#active += 1;\n\t\t};\n\t}\n\n\t/** Re-check what {@link settle} waits on, after something outside the ledger changed. */\n\ttouch(): void {\n\t\tthis.#bump();\n\t}\n\n\t/** Record keys `[start, end)` as accounted for without a stream: dropped, or a datagram. */\n\taccount(start: bigint, end: bigint): void {\n\t\tthis.#account(start, end);\n\t}\n\n\t/** Record `[start, end)` as given up by a drop, accounting for it. */\n\tdrop(start: bigint, end: bigint): void {\n\t\tinsertRun(this.#dropped, start, end);\n\t\twhile (this.#dropped.length > MAX_RUNS) this.#dropped.shift();\n\t\tthis.#account(start, end);\n\t}\n\n\t/** Whether a drop named `key`. */\n\tdropped(key: bigint): boolean {\n\t\tconst run = this.#dropped[runsFrom(this.#dropped, key)];\n\t\treturn run !== undefined && run.start <= key;\n\t}\n\n\t/** Restart the age of every gap reaching into `[start, end)`, which the demand newly asks for. */\n\tdemand(start: bigint, end: bigint): void {\n\t\tthis.#ledger.demand(start, end, now());\n\t}\n\n\t/** The parts of `[start, end)` accounted for: a stream arrived, a drop named them, or the grace gave up. */\n\taccounted(start: bigint, end: bigint): Run[] {\n\t\treturn runGaps(this.#ledger.gaps(start, end), start, end);\n\t}\n\n\t/** Whether a group stream is still being read. */\n\tget reading(): boolean {\n\t\treturn this.#active > 0;\n\t}\n\n\t/** Bumped on every change {@link settle} watches. */\n\tget changed(): Getter<number> {\n\t\treturn this.#changed;\n\t}\n\n\t/** Whether every key in `[start, end)` is accounted for. */\n\tcovers(start: bigint, end: bigint): boolean {\n\t\treturn this.#ledger.covers(start, end);\n\t}\n\n\t/**\n\t * Whether a proven tail lost the proof for `owed`: a run it does not cover reaches below what\n\t * its ledger forgot, so it cannot tell a group still owed from one it forgot was accounted for.\n\t * What it owes above that is still waited for, since the wire can yet account for it. Mirrors the\n\t * Rust `Tail::lost`.\n\t */\n\tlost(owed: { start: bigint; end: bigint }[]): boolean {\n\t\tconst below = this.#ledger.forgotten;\n\t\treturn (\n\t\t\tbelow !== undefined && owed.some((run) => run.start < below && !this.covers(run.start, min(run.end, below)))\n\t\t);\n\t}\n\n\t/**\n\t * Whether nothing still on the wire can change what `[start, end)` gets: every group at or above\n\t * what the ledger forgot is accounted for. Below that, {@link lost} says whether proof was lost.\n\t * Mirrors the Rust `Tail::answered`.\n\t */\n\tanswered(start: bigint, end: bigint): boolean {\n\t\treturn this.covers(max(start, this.#ledger.forgotten ?? 0n), end);\n\t}\n\n\t/**\n\t * What of `[start, end)` this tail spent on its subscription: what it accounts for, and everything\n\t * below what it forgot, which it may have been told of. A fill for any of it needs a fresh\n\t * subscription, since this one never reopens a group it delivered or dropped. Mirrors the Rust\n\t * `Tail::spent`.\n\t */\n\tspent(start: bigint, end: bigint): Run[] {\n\t\tconst below = this.#ledger.forgotten ?? 0n;\n\t\tconst forgotten = min(end, below);\n\t\tconst spent: Run[] = start < forgotten ? [{ start, end: forgotten }] : [];\n\t\treturn [...spent, ...this.accounted(max(start, below), end)];\n\t}\n\n\t/**\n\t * Wait until every stream is read to its end and `complete()` holds, or the grace passes\n\t * with nothing left being read, or `closed` settles.\n\t *\n\t * A stream still being read is waited for, until its own FIN or reset, or until a drop naming\n\t * its group lets go of it (see {@link Counted.done}). The grace gives up on streams that never\n\t * arrived, and `limit` caps it. With no grace nothing is timed: every start waits for the wire\n\t * to account for it.\n\t */\n\tsettle(complete: () => boolean, closed: GetPromise<unknown>, limit?: Duration): Promise<void> {\n\t\treturn this.#settle(complete, closed, limit, false);\n\t}\n\n\t/**\n\t * {@link settle} (with the same `limit`) once the publisher ended the subscription, which also gives up on a stream that\n\t * delivered nothing for {@link GRACE} since (see {@link Counted.stalled}): a browser can lose a\n\t * stream's reset, leaving it open forever. Not with no grace, where the wire names every group.\n\t */\n\tdrain(complete: () => boolean, closed: GetPromise<unknown>, limit?: Duration): Promise<void> {\n\t\treturn this.#settle(complete, closed, limit, true);\n\t}\n\n\tasync #settle(\n\t\tcomplete: () => boolean,\n\t\tclosed: GetPromise<unknown>,\n\t\tlimit: Duration | undefined,\n\t\tdrain: boolean,\n\t): Promise<void> {\n\t\t// A gap that aged past the grace since the last insert is no longer waited for either.\n\t\tconst grace = this.#grace();\n\t\tconst from = now();\n\t\tthis.#ledger.expire(from, grace);\n\n\t\tconst wait = grace === undefined ? undefined : limit === undefined ? grace : grace.min(limit);\n\t\tlet expired = false;\n\t\tconst timer = new AbortController();\n\t\tif (wait !== undefined) {\n\t\t\tvoid sleep(wait, { signal: timer.signal }).then(\n\t\t\t\t() => {\n\t\t\t\t\texpired = true;\n\t\t\t\t\tthis.#bump();\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t);\n\t\t}\n\t\t// Wakes the loop when the quietest stream's time is up, one at a time.\n\t\tlet wake: AbortController | undefined;\n\t\ttry {\n\t\t\twhile (closed.peek() === undefined) {\n\t\t\t\tif (this.#active === 0 && (expired || complete())) return;\n\t\t\t\tif (drain && grace !== undefined) {\n\t\t\t\t\twake?.abort();\n\t\t\t\t\tconst next = this.#quiet(GRACE, from);\n\t\t\t\t\tif (next !== undefined) {\n\t\t\t\t\t\twake = new AbortController();\n\t\t\t\t\t\tvoid sleep(next, { signal: wake.signal }).then(\n\t\t\t\t\t\t\t() => this.#bump(),\n\t\t\t\t\t\t\t() => {},\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tawait Signal.race(this.#changed, closed);\n\t\t\t}\n\t\t} finally {\n\t\t\ttimer.abort();\n\t\t\twake?.abort();\n\t\t}\n\t}\n\n\t// Give up on each held stream that delivered nothing for `window` since `from`, and return how\n\t// long until the next one would have, or undefined with none held.\n\t#quiet(window: Duration, from: Instant): Duration | undefined {\n\t\tconst at = now();\n\t\tlet next: Duration | undefined;\n\t\tfor (const held of this.#held) {\n\t\t\tconst quiet = at.since(held.last().max(held.since).max(from));\n\t\t\tif (quiet.ge(window)) {\n\t\t\t\tthis.#held.delete(held);\n\t\t\t\theld.stalled = true;\n\t\t\t\theld.stall();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst left = window.sub(quiet);\n\t\t\tnext = next === undefined ? left : next.min(left);\n\t\t}\n\t\treturn next;\n\t}\n\n\t#account(start: bigint, end: bigint): void {\n\t\tif (start >= end) return;\n\t\tconst at = now();\n\t\tthis.#ledger.account(start, end, at);\n\t\tthis.#ledger.expire(at, this.#grace());\n\t\tthis.#bump();\n\t}\n\n\t#bump(): void {\n\t\tthis.#changed.update((revision) => revision + 1);\n\t}\n}\n"]}
package/time.d.ts CHANGED
@@ -1,72 +1,3 @@
1
- /**
2
- * Branded time types (nanoseconds, microseconds, milliseconds, seconds) with conversions,
3
- * plus {@link Timescale} and {@link Timestamp} for presentation timing.
4
- *
5
- * @module
6
- */
7
- /** A duration in nanoseconds, branded so it can't be mixed with other units. */
8
- export type Nano = number & {
9
- readonly _brand: "nano";
10
- };
11
- /** Constructors, conversions, and arithmetic for {@link Nano} values. */
12
- export declare const Nano: ((value: number) => Nano) & {
13
- zero: Nano;
14
- fromMicro: (us: Micro) => Nano;
15
- fromMilli: (ms: Milli) => Nano;
16
- fromSecond: (s: Second) => Nano;
17
- toMicro: (ns: Nano) => Micro;
18
- toMilli: (ns: Nano) => Milli;
19
- toSecond: (ns: Nano) => Second;
20
- now: () => Nano;
21
- add: (a: Nano, b: Nano) => Nano;
22
- sub: (a: Nano, b: Nano) => Nano;
23
- mul: (a: Nano, b: number) => Nano;
24
- div: (a: Nano, b: number) => Nano;
25
- max: (a: Nano, b: Nano) => Nano;
26
- min: (a: Nano, b: Nano) => Nano;
27
- };
28
- /** A duration in microseconds, branded so it can't be mixed with other units. */
29
- export type Micro = number & {
30
- readonly _brand: "micro";
31
- };
32
- /** Constructors, conversions, and arithmetic for {@link Micro} values. */
33
- export declare const Micro: ((value: number) => Micro) & {
34
- zero: Micro;
35
- fromNano: (ns: Nano) => Micro;
36
- fromMilli: (ms: Milli) => Micro;
37
- fromSecond: (s: Second) => Micro;
38
- toNano: (us: Micro) => Nano;
39
- toMilli: (us: Micro) => Milli;
40
- toSecond: (us: Micro) => Second;
41
- now: () => Micro;
42
- add: (a: Micro, b: Micro) => Micro;
43
- sub: (a: Micro, b: Micro) => Micro;
44
- mul: (a: Micro, b: number) => Micro;
45
- div: (a: Micro, b: number) => Micro;
46
- max: (a: Micro, b: Micro) => Micro;
47
- min: (a: Micro, b: Micro) => Micro;
48
- };
49
- /** A duration in milliseconds, branded so it can't be mixed with other units. */
50
- export type Milli = number & {
51
- readonly _brand: "milli";
52
- };
53
- /** Constructors, conversions, and arithmetic for {@link Milli} values. */
54
- export declare const Milli: ((value: number) => Milli) & {
55
- zero: Milli;
56
- fromNano: (ns: Nano) => Milli;
57
- fromMicro: (us: Micro) => Milli;
58
- fromSecond: (s: Second) => Milli;
59
- toNano: (ms: Milli) => Nano;
60
- toMicro: (ms: Milli) => Micro;
61
- toSecond: (ms: Milli) => Second;
62
- now: () => Milli;
63
- add: (a: Milli, b: Milli) => Milli;
64
- sub: (a: Milli, b: Milli) => Milli;
65
- mul: (a: Milli, b: number) => Milli;
66
- div: (a: Milli, b: number) => Milli;
67
- max: (a: Milli, b: Milli) => Milli;
68
- min: (a: Milli, b: Milli) => Milli;
69
- };
70
1
  /** Units per second for a {@link Timestamp}'s value, e.g. `1000` for milliseconds. */
71
2
  export type Timescale = number & {
72
3
  readonly _brand: "timescale";
@@ -89,57 +20,65 @@ export declare const Timescale: ((unitsPerSecond: number) => Timescale) & {
89
20
  NANO: Timescale;
90
21
  };
91
22
  /**
92
- * A presentation timestamp: a raw value in a given {@link Timescale}.
23
+ * A presentation timestamp: a raw value in a given {@link Timescale}, or a scale-less track's
24
+ * group key.
93
25
  *
94
- * Mirrors the Rust `Timestamp`. Unlike the bare `Milli`/`Micro` aliases it carries its
26
+ * Mirrors the Rust `Timestamp`. Unlike a `@moq/clock` `Duration` it carries its
95
27
  * own scale, so a track can pick its units and conversions can't silently mix them up.
96
28
  *
97
- * The value must be finite and in `[0, Number.MAX_SAFE_INTEGER]`. Fractions are allowed
98
- * (`performance.now()`, scale conversion). Encoding rounds to the nearest integer at the
99
- * track timescale. Integer timestamps are exact through `2^53 - 1` units; this package
29
+ * A scaled value must be finite and in `[0, Number.MAX_SAFE_INTEGER]`. Fractions are allowed
30
+ * ({@link Timestamp.now}, scale conversion). Encoding rounds down to an integer at the
31
+ * track timescale, as the Rust `Timestamp::convert` does. Integer timestamps are exact through `2^53 - 1` units; this package
100
32
  * does not use BigInt for timestamps. {@link Timestamp.as} also refuses a converted
101
33
  * value that leaves that range, so a legal source timestamp cannot become an unencodable
102
34
  * wire timestamp after a scale change.
35
+ *
36
+ * A scale-less track has no time: each frame's timestamp is {@link Timestamp.unscaled}, whose
37
+ * {@link value} is its group's key and whose {@link scale} is `undefined`, as Rust's
38
+ * `Timestamp::unscaled(key)`. A key past `Number.MAX_SAFE_INTEGER` is refused, so such a group's
39
+ * frames cannot be read here. Anything that needs a scale ({@link as}, {@link asMillis},
40
+ * {@link asMicros}) throws a `RangeError` on one, and {@link isBefore} orders it against no
41
+ * scaled timestamp.
103
42
  */
104
43
  export declare class Timestamp {
105
- /** The raw value, in `scale` units. */
44
+ /** The raw value in `scale` units, or an unscaled timestamp's group key. */
106
45
  readonly value: number;
107
- /** Units per second the {@link value} is measured in. */
108
- readonly scale: Timescale;
46
+ /** Units per second the {@link value} is measured in, or `undefined` when unscaled. */
47
+ readonly scale: Timescale | undefined;
109
48
  /** Build a timestamp of `value` units at `scale`. */
110
49
  constructor(value: number, scale: Timescale);
111
- /** Monotonic now (`performance.now()`, milliseconds since page load), not wall-clock time. */
50
+ /**
51
+ * A scale-less track's timestamp: `key` is its group's key (or a datagram's key), with no
52
+ * time. Throws a `RangeError` past `Number.MAX_SAFE_INTEGER`, which a `number` cannot hold.
53
+ */
54
+ static unscaled(key: bigint | number): Timestamp;
55
+ /** The installed clock's monotonic instant in milliseconds, not wall-clock time. */
112
56
  static now(): Timestamp;
57
+ /** A timestamp of `secs` seconds. */
58
+ static fromSecs(secs: number): Timestamp;
113
59
  /** A timestamp of `ms` milliseconds. */
114
60
  static fromMillis(ms: number): Timestamp;
115
61
  /** A timestamp of `us` microseconds. */
116
62
  static fromMicros(us: number): Timestamp;
117
- /** This timestamp's value re-expressed at `scale`; throws if the result is not in the safe range. */
63
+ /** A timestamp of `ns` nanoseconds. */
64
+ static fromNanos(ns: number): Timestamp;
65
+ /**
66
+ * This timestamp's value re-expressed at `scale`; throws a `RangeError` if it is unscaled or
67
+ * the result is not in the safe range.
68
+ */
118
69
  as(scale: Timescale): number;
119
- /** The value in milliseconds. */
70
+ /** The value in seconds; throws a `RangeError` if it is unscaled. */
71
+ asSecs(): number;
72
+ /** The value in milliseconds; throws a `RangeError` if it is unscaled. */
120
73
  asMillis(): number;
121
- /** The value in microseconds. */
74
+ /** The value in microseconds; throws a `RangeError` if it is unscaled. */
122
75
  asMicros(): number;
76
+ /** The value in nanoseconds; throws a `RangeError` if it is unscaled or past the safe range. */
77
+ asNanos(): number;
78
+ /**
79
+ * Whether this presents before `other`, whatever their scales. Two unscaled timestamps order
80
+ * by key; a scaled and an unscaled one don't order, so neither is before the other.
81
+ */
82
+ isBefore(other: Timestamp): boolean;
123
83
  }
124
- /** A duration in seconds, branded so it can't be mixed with other units. */
125
- export type Second = number & {
126
- readonly _brand: "second";
127
- };
128
- /** Constructors, conversions, and arithmetic for {@link Second} values. */
129
- export declare const Second: ((value: number) => Second) & {
130
- zero: Second;
131
- fromNano: (ns: Nano) => Second;
132
- fromMicro: (us: Micro) => Second;
133
- fromMilli: (ms: Milli) => Second;
134
- toNano: (s: Second) => Nano;
135
- toMicro: (s: Second) => Micro;
136
- toMilli: (s: Second) => Milli;
137
- now: () => Second;
138
- add: (a: Second, b: Second) => Second;
139
- sub: (a: Second, b: Second) => Second;
140
- mul: (a: Second, b: number) => Second;
141
- div: (a: Second, b: number) => Second;
142
- max: (a: Second, b: Second) => Second;
143
- min: (a: Second, b: Second) => Second;
144
- };
145
84
  //# sourceMappingURL=time.d.ts.map
package/time.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gFAAgF;AAChF,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,yEAAyE;AAGzE,eAAO,MAAM,IAAI,WAAyB,MAAM,KAAG,IAAI;UAC3C,IAAI;oBACC,KAAK,KAAG,IAAI;oBACZ,KAAK,KAAG,IAAI;oBACZ,MAAM,KAAG,IAA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