@moq/net 0.4.7 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (664) hide show
  1. package/README.md +7 -1
  2. package/announce.d.ts +1 -1
  3. package/announce.d.ts.map +1 -1
  4. package/announce.js +1 -2
  5. package/announce.js.map +1 -1
  6. package/announced.d.ts +51 -47
  7. package/announced.d.ts.map +1 -1
  8. package/announced.js +183 -32
  9. package/announced.js.map +1 -1
  10. package/announced.test-util.d.ts +2 -0
  11. package/announced.test-util.d.ts.map +1 -0
  12. package/announced.test-util.js +27 -0
  13. package/announced.test-util.js.map +1 -0
  14. package/auth.d.ts +64 -0
  15. package/auth.d.ts.map +1 -0
  16. package/auth.js +20 -0
  17. package/auth.js.map +1 -0
  18. package/auth_gate.d.ts +2 -0
  19. package/auth_gate.d.ts.map +1 -0
  20. package/auth_gate.js +24 -0
  21. package/auth_gate.js.map +1 -0
  22. package/auth_session.d.ts +49 -0
  23. package/auth_session.d.ts.map +1 -0
  24. package/auth_session.js +1097 -0
  25. package/auth_session.js.map +1 -0
  26. package/bandwidth.d.ts +129 -25
  27. package/bandwidth.d.ts.map +1 -1
  28. package/bandwidth.js +410 -139
  29. package/bandwidth.js.map +1 -1
  30. package/bandwidth_api.d.ts +1 -1
  31. package/bandwidth_api.d.ts.map +1 -1
  32. package/bandwidth_api.js +1 -2
  33. package/bandwidth_api.js.map +1 -1
  34. package/broadcast.d.ts +64 -38
  35. package/broadcast.d.ts.map +1 -1
  36. package/broadcast.js +556 -173
  37. package/broadcast.js.map +1 -1
  38. package/cache.d.ts +103 -0
  39. package/cache.d.ts.map +1 -0
  40. package/cache.js +254 -0
  41. package/cache.js.map +1 -0
  42. package/claim.test-util.d.ts +5 -0
  43. package/claim.test-util.d.ts.map +1 -0
  44. package/claim.test-util.js +13 -0
  45. package/claim.test-util.js.map +1 -0
  46. package/connection/accept.d.ts +21 -13
  47. package/connection/accept.d.ts.map +1 -1
  48. package/connection/accept.js +97 -130
  49. package/connection/accept.js.map +1 -1
  50. package/connection/browser.d.ts.map +1 -1
  51. package/connection/browser.js +28 -20
  52. package/connection/browser.js.map +1 -1
  53. package/connection/connect.d.ts +120 -24
  54. package/connection/connect.d.ts.map +1 -1
  55. package/connection/connect.js +535 -217
  56. package/connection/connect.js.map +1 -1
  57. package/connection/dials.d.ts +45 -0
  58. package/connection/dials.d.ts.map +1 -0
  59. package/connection/dials.js +109 -0
  60. package/connection/dials.js.map +1 -0
  61. package/connection/endpoint.d.ts +60 -0
  62. package/connection/endpoint.d.ts.map +1 -0
  63. package/connection/endpoint.js +114 -0
  64. package/connection/endpoint.js.map +1 -0
  65. package/connection/forward.d.ts +7 -1
  66. package/connection/forward.d.ts.map +1 -1
  67. package/connection/forward.js +265 -81
  68. package/connection/forward.js.map +1 -1
  69. package/connection/goaway.d.ts +16 -9
  70. package/connection/goaway.d.ts.map +1 -1
  71. package/connection/goaway.js +22 -95
  72. package/connection/goaway.js.map +1 -1
  73. package/connection/handshake.d.ts +34 -8
  74. package/connection/handshake.d.ts.map +1 -1
  75. package/connection/handshake.js +97 -21
  76. package/connection/handshake.js.map +1 -1
  77. package/connection/index.d.ts +4 -7
  78. package/connection/index.d.ts.map +1 -1
  79. package/connection/index.js +1 -3
  80. package/connection/index.js.map +1 -1
  81. package/connection/liveness.d.ts +14 -0
  82. package/connection/liveness.d.ts.map +1 -0
  83. package/connection/liveness.js +30 -0
  84. package/connection/liveness.js.map +1 -0
  85. package/connection/pool.d.ts +142 -63
  86. package/connection/pool.d.ts.map +1 -1
  87. package/connection/pool.js +281 -118
  88. package/connection/pool.js.map +1 -1
  89. package/connection/reload.d.ts +60 -12
  90. package/connection/reload.d.ts.map +1 -1
  91. package/connection/reload.js +859 -234
  92. package/connection/reload.js.map +1 -1
  93. package/connection/session.d.ts +91 -0
  94. package/connection/session.d.ts.map +1 -0
  95. package/connection/session.js +2 -0
  96. package/connection/session.js.map +1 -0
  97. package/connection/stats.d.ts +20 -11
  98. package/connection/stats.d.ts.map +1 -1
  99. package/connection/stats.js +64 -9
  100. package/connection/stats.js.map +1 -1
  101. package/connection/ticker.d.ts +4 -0
  102. package/connection/ticker.d.ts.map +1 -0
  103. package/connection/ticker.js +66 -0
  104. package/connection/ticker.js.map +1 -0
  105. package/connection/tokens.d.ts +2 -0
  106. package/connection/tokens.d.ts.map +1 -0
  107. package/connection/tokens.js +404 -0
  108. package/connection/tokens.js.map +1 -0
  109. package/connection/transport.d.ts.map +1 -1
  110. package/connection/transport.js +4 -5
  111. package/connection/transport.js.map +1 -1
  112. package/connection/withdrawal.d.ts +2 -0
  113. package/connection/withdrawal.d.ts.map +1 -0
  114. package/connection/withdrawal.js +23 -0
  115. package/connection/withdrawal.js.map +1 -0
  116. package/consume.js +213 -47
  117. package/consume.js.map +1 -1
  118. package/cover.d.ts +59 -0
  119. package/cover.d.ts.map +1 -0
  120. package/cover.js +375 -0
  121. package/cover.js.map +1 -0
  122. package/datagram.d.ts +70 -11
  123. package/datagram.d.ts.map +1 -1
  124. package/datagram.js +317 -2
  125. package/datagram.js.map +1 -1
  126. package/datagram_stream.d.ts +18 -0
  127. package/datagram_stream.d.ts.map +1 -0
  128. package/datagram_stream.js +67 -0
  129. package/datagram_stream.js.map +1 -0
  130. package/defined.test-util.d.ts +2 -0
  131. package/defined.test-util.d.ts.map +1 -0
  132. package/defined.test-util.js +7 -0
  133. package/defined.test-util.js.map +1 -0
  134. package/delivered.d.ts +75 -0
  135. package/delivered.d.ts.map +1 -0
  136. package/delivered.js +228 -0
  137. package/delivered.js.map +1 -0
  138. package/demand.d.ts +173 -0
  139. package/demand.d.ts.map +1 -0
  140. package/demand.js +582 -0
  141. package/demand.js.map +1 -0
  142. package/drops.d.ts +93 -0
  143. package/drops.d.ts.map +1 -0
  144. package/drops.js +283 -0
  145. package/drops.js.map +1 -0
  146. package/error.d.ts +120 -21
  147. package/error.d.ts.map +1 -1
  148. package/error.js +230 -38
  149. package/error.js.map +1 -1
  150. package/errors.d.ts +2 -2
  151. package/errors.d.ts.map +1 -1
  152. package/errors.js +2 -3
  153. package/errors.js.map +1 -1
  154. package/fill.d.ts +174 -0
  155. package/fill.d.ts.map +1 -0
  156. package/fill.js +760 -0
  157. package/fill.js.map +1 -0
  158. package/flate/decoder.d.ts +2 -0
  159. package/flate/decoder.d.ts.map +1 -0
  160. package/flate/decoder.js +63 -0
  161. package/flate/decoder.js.map +1 -0
  162. package/flate/encoder.d.ts +2 -0
  163. package/flate/encoder.d.ts.map +1 -0
  164. package/flate/encoder.js +64 -0
  165. package/flate/encoder.js.map +1 -0
  166. package/flate/group.d.ts +34 -0
  167. package/flate/group.d.ts.map +1 -0
  168. package/flate/group.js +140 -0
  169. package/flate/group.js.map +1 -0
  170. package/frame.d.ts +80 -0
  171. package/frame.d.ts.map +1 -0
  172. package/frame.js +296 -0
  173. package/frame.js.map +1 -0
  174. package/frame.test-util.d.ts +5 -0
  175. package/frame.test-util.d.ts.map +1 -0
  176. package/frame.test-util.js +9 -0
  177. package/frame.test-util.js.map +1 -0
  178. package/group.d.ts +108 -45
  179. package/group.d.ts.map +1 -1
  180. package/group.js +1616 -308
  181. package/group.js.map +1 -1
  182. package/group_api.d.ts +7 -0
  183. package/group_api.d.ts.map +1 -0
  184. package/group_api.js +7 -0
  185. package/group_api.js.map +1 -0
  186. package/hop.d.ts +62 -76
  187. package/hop.d.ts.map +1 -1
  188. package/hop.js +92 -65
  189. package/hop.js.map +1 -1
  190. package/identity.d.ts +39 -0
  191. package/identity.d.ts.map +1 -0
  192. package/identity.js +47 -0
  193. package/identity.js.map +1 -0
  194. package/ietf/active_count.d.ts +2 -0
  195. package/ietf/active_count.d.ts.map +1 -0
  196. package/ietf/active_count.js +30 -0
  197. package/ietf/active_count.js.map +1 -0
  198. package/ietf/aliases.js +69 -36
  199. package/ietf/aliases.js.map +1 -1
  200. package/ietf/cluster.d.ts +3 -3
  201. package/ietf/cluster.js +14 -55
  202. package/ietf/cluster.js.map +1 -1
  203. package/ietf/connection.d.ts +1 -31
  204. package/ietf/connection.d.ts.map +1 -1
  205. package/ietf/connection.js +305 -144
  206. package/ietf/connection.js.map +1 -1
  207. package/ietf/datagram.d.ts +60 -0
  208. package/ietf/datagram.d.ts.map +1 -0
  209. package/ietf/datagram.js +152 -0
  210. package/ietf/datagram.js.map +1 -0
  211. package/ietf/error.d.ts +3 -3
  212. package/ietf/error.js +82 -101
  213. package/ietf/error.js.map +1 -1
  214. package/ietf/fetch.d.ts +93 -37
  215. package/ietf/fetch.d.ts.map +1 -1
  216. package/ietf/fetch.js +172 -94
  217. package/ietf/fetch.js.map +1 -1
  218. package/ietf/filter.d.ts +21 -31
  219. package/ietf/filter.d.ts.map +1 -1
  220. package/ietf/filter.js +140 -172
  221. package/ietf/filter.js.map +1 -1
  222. package/ietf/goaway.d.ts +12 -10
  223. package/ietf/goaway.d.ts.map +1 -1
  224. package/ietf/goaway.js +22 -36
  225. package/ietf/goaway.js.map +1 -1
  226. package/ietf/hidden.js +1 -2
  227. package/ietf/hidden.js.map +1 -1
  228. package/ietf/index.d.ts +8 -20
  229. package/ietf/index.d.ts.map +1 -1
  230. package/ietf/index.js +4 -15
  231. package/ietf/index.js.map +1 -1
  232. package/ietf/join.d.ts +7 -0
  233. package/ietf/join.d.ts.map +1 -0
  234. package/ietf/join.js +234 -0
  235. package/ietf/join.js.map +1 -0
  236. package/ietf/message.d.ts +18 -2
  237. package/ietf/message.d.ts.map +1 -1
  238. package/ietf/message.js +60 -41
  239. package/ietf/message.js.map +1 -1
  240. package/ietf/message.test-util.d.ts +6 -0
  241. package/ietf/message.test-util.d.ts.map +1 -0
  242. package/ietf/message.test-util.js +13 -0
  243. package/ietf/message.test-util.js.map +1 -0
  244. package/ietf/namespace.d.ts +19 -5
  245. package/ietf/namespace.d.ts.map +1 -1
  246. package/ietf/namespace.js +78 -27
  247. package/ietf/namespace.js.map +1 -1
  248. package/ietf/object.d.ts +195 -33
  249. package/ietf/object.d.ts.map +1 -1
  250. package/ietf/object.js +405 -179
  251. package/ietf/object.js.map +1 -1
  252. package/ietf/parameters.d.ts +25 -45
  253. package/ietf/parameters.d.ts.map +1 -1
  254. package/ietf/parameters.js +260 -473
  255. package/ietf/parameters.js.map +1 -1
  256. package/ietf/priority.d.ts +17 -2
  257. package/ietf/priority.d.ts.map +1 -1
  258. package/ietf/priority.js +19 -5
  259. package/ietf/priority.js.map +1 -1
  260. package/ietf/properties.d.ts +6 -5
  261. package/ietf/properties.d.ts.map +1 -1
  262. package/ietf/properties.js +78 -49
  263. package/ietf/properties.js.map +1 -1
  264. package/ietf/publish.d.ts +25 -33
  265. package/ietf/publish.d.ts.map +1 -1
  266. package/ietf/publish.js +45 -140
  267. package/ietf/publish.js.map +1 -1
  268. package/ietf/publish_namespace.d.ts +49 -72
  269. package/ietf/publish_namespace.d.ts.map +1 -1
  270. package/ietf/publish_namespace.js +66 -185
  271. package/ietf/publish_namespace.js.map +1 -1
  272. package/ietf/publisher.js +1800 -601
  273. package/ietf/publisher.js.map +1 -1
  274. package/ietf/range.d.ts +2 -0
  275. package/ietf/range.d.ts.map +1 -0
  276. package/ietf/range.js +222 -0
  277. package/ietf/range.js.map +1 -0
  278. package/ietf/request.d.ts +6 -30
  279. package/ietf/request.d.ts.map +1 -1
  280. package/ietf/request.js +41 -79
  281. package/ietf/request.js.map +1 -1
  282. package/ietf/request_stream.d.ts +1 -6
  283. package/ietf/request_stream.d.ts.map +1 -1
  284. package/ietf/request_stream.js +306 -17
  285. package/ietf/request_stream.js.map +1 -1
  286. package/ietf/session.d.ts +41 -0
  287. package/ietf/session.d.ts.map +1 -0
  288. package/ietf/session.js +65 -0
  289. package/ietf/session.js.map +1 -0
  290. package/ietf/setup.d.ts +5 -30
  291. package/ietf/setup.d.ts.map +1 -1
  292. package/ietf/setup.js +6 -118
  293. package/ietf/setup.js.map +1 -1
  294. package/ietf/setup_options.d.ts +31 -0
  295. package/ietf/setup_options.d.ts.map +1 -0
  296. package/ietf/setup_options.js +138 -0
  297. package/ietf/setup_options.js.map +1 -0
  298. package/ietf/solicit.js +4 -15
  299. package/ietf/solicit.js.map +1 -1
  300. package/ietf/subscribe.d.ts +52 -45
  301. package/ietf/subscribe.d.ts.map +1 -1
  302. package/ietf/subscribe.js +118 -240
  303. package/ietf/subscribe.js.map +1 -1
  304. package/ietf/subscribe_namespace.d.ts +16 -79
  305. package/ietf/subscribe_namespace.d.ts.map +1 -1
  306. package/ietf/subscribe_namespace.js +30 -202
  307. package/ietf/subscribe_namespace.js.map +1 -1
  308. package/ietf/subscriber.js +1839 -537
  309. package/ietf/subscriber.js.map +1 -1
  310. package/ietf/token.js +105 -28
  311. package/ietf/token.js.map +1 -1
  312. package/ietf/track.d.ts +27 -24
  313. package/ietf/track.d.ts.map +1 -1
  314. package/ietf/track.js +48 -62
  315. package/ietf/track.js.map +1 -1
  316. package/ietf/version.d.ts +13 -42
  317. package/ietf/version.d.ts.map +1 -1
  318. package/ietf/version.js +22 -49
  319. package/ietf/version.js.map +1 -1
  320. package/implementation.d.ts +2 -0
  321. package/implementation.d.ts.map +1 -0
  322. package/implementation.js +5 -0
  323. package/implementation.js.map +1 -0
  324. package/index.d.ts +34 -19
  325. package/index.d.ts.map +1 -1
  326. package/index.js +19 -7
  327. package/index.js.map +1 -1
  328. package/internal.d.ts +1515 -67
  329. package/internal.d.ts.map +1 -1
  330. package/internal.js +557 -80
  331. package/internal.js.map +1 -1
  332. package/ledger.d.ts +23 -0
  333. package/ledger.d.ts.map +1 -0
  334. package/ledger.js +247 -0
  335. package/ledger.js.map +1 -0
  336. package/listing.d.ts +132 -0
  337. package/listing.d.ts.map +1 -0
  338. package/listing.js +486 -0
  339. package/listing.js.map +1 -0
  340. package/lite/announce.d.ts +127 -66
  341. package/lite/announce.d.ts.map +1 -1
  342. package/lite/announce.js +384 -159
  343. package/lite/announce.js.map +1 -1
  344. package/lite/announce_stream.d.ts +2 -0
  345. package/lite/announce_stream.d.ts.map +1 -0
  346. package/lite/announce_stream.js +92 -0
  347. package/lite/announce_stream.js.map +1 -0
  348. package/lite/answer.d.ts +22 -0
  349. package/lite/answer.d.ts.map +1 -0
  350. package/lite/answer.js +301 -0
  351. package/lite/answer.js.map +1 -0
  352. package/lite/auth.d.ts +45 -0
  353. package/lite/auth.d.ts.map +1 -0
  354. package/lite/auth.js +204 -0
  355. package/lite/auth.js.map +1 -0
  356. package/lite/compat.d.ts +31 -0
  357. package/lite/compat.d.ts.map +1 -0
  358. package/lite/compat.js +86 -0
  359. package/lite/compat.js.map +1 -0
  360. package/lite/connection.d.ts +1 -45
  361. package/lite/connection.d.ts.map +1 -1
  362. package/lite/connection.js +360 -78
  363. package/lite/connection.js.map +1 -1
  364. package/lite/datagram-end.d.ts +26 -0
  365. package/lite/datagram-end.d.ts.map +1 -0
  366. package/lite/datagram-end.js +30 -0
  367. package/lite/datagram-end.js.map +1 -0
  368. package/lite/datagram.d.ts +73 -8
  369. package/lite/datagram.d.ts.map +1 -1
  370. package/lite/datagram.js +144 -10
  371. package/lite/datagram.js.map +1 -1
  372. package/lite/duration.d.ts +6 -0
  373. package/lite/duration.d.ts.map +1 -0
  374. package/lite/duration.js +14 -0
  375. package/lite/duration.js.map +1 -0
  376. package/lite/error.d.ts +9 -0
  377. package/lite/error.d.ts.map +1 -0
  378. package/lite/error.js +24 -0
  379. package/lite/error.js.map +1 -0
  380. package/lite/fills.d.ts +162 -0
  381. package/lite/fills.d.ts.map +1 -0
  382. package/lite/fills.js +486 -0
  383. package/lite/fills.js.map +1 -0
  384. package/lite/fit.d.ts +49 -0
  385. package/lite/fit.d.ts.map +1 -0
  386. package/lite/fit.js +305 -0
  387. package/lite/fit.js.map +1 -0
  388. package/lite/goaway.d.ts +2 -2
  389. package/lite/goaway.d.ts.map +1 -1
  390. package/lite/goaway.js +5 -14
  391. package/lite/goaway.js.map +1 -1
  392. package/lite/group.d.ts +67 -16
  393. package/lite/group.d.ts.map +1 -1
  394. package/lite/group.js +108 -31
  395. package/lite/group.js.map +1 -1
  396. package/lite/identity.d.ts +25 -0
  397. package/lite/identity.d.ts.map +1 -0
  398. package/lite/identity.js +79 -0
  399. package/lite/identity.js.map +1 -0
  400. package/lite/index.d.ts +14 -13
  401. package/lite/index.d.ts.map +1 -1
  402. package/lite/index.js +2 -2
  403. package/lite/index.js.map +1 -1
  404. package/lite/message.d.ts +10 -2
  405. package/lite/message.d.ts.map +1 -1
  406. package/lite/message.js +28 -45
  407. package/lite/message.js.map +1 -1
  408. package/lite/priority.d.ts +9 -2
  409. package/lite/priority.d.ts.map +1 -1
  410. package/lite/priority.js +11 -106
  411. package/lite/priority.js.map +1 -1
  412. package/lite/probe.d.ts +2 -2
  413. package/lite/probe.d.ts.map +1 -1
  414. package/lite/probe.js +9 -1
  415. package/lite/probe.js.map +1 -1
  416. package/lite/publisher.d.ts +10 -1
  417. package/lite/publisher.d.ts.map +1 -1
  418. package/lite/publisher.js +2548 -438
  419. package/lite/publisher.js.map +1 -1
  420. package/lite/routed.d.ts +59 -0
  421. package/lite/routed.d.ts.map +1 -0
  422. package/lite/routed.js +564 -0
  423. package/lite/routed.js.map +1 -0
  424. package/lite/session.d.ts +2 -28
  425. package/lite/session.d.ts.map +1 -1
  426. package/lite/session.js +0 -100
  427. package/lite/session.js.map +1 -1
  428. package/lite/setup.d.ts +32 -5
  429. package/lite/setup.d.ts.map +1 -1
  430. package/lite/setup.js +95 -22
  431. package/lite/setup.js.map +1 -1
  432. package/lite/stream.d.ts +5 -11
  433. package/lite/stream.d.ts.map +1 -1
  434. package/lite/stream.js +5 -2
  435. package/lite/stream.js.map +1 -1
  436. package/lite/subscribe.d.ts +478 -78
  437. package/lite/subscribe.d.ts.map +1 -1
  438. package/lite/subscribe.js +1373 -143
  439. package/lite/subscribe.js.map +1 -1
  440. package/lite/subscriber.d.ts +7 -44
  441. package/lite/subscriber.d.ts.map +1 -1
  442. package/lite/subscriber.js +3290 -516
  443. package/lite/subscriber.js.map +1 -1
  444. package/lite/track.d.ts +27 -12
  445. package/lite/track.d.ts.map +1 -1
  446. package/lite/track.js +116 -38
  447. package/lite/track.js.map +1 -1
  448. package/lite/tracks.d.ts +55 -0
  449. package/lite/tracks.d.ts.map +1 -0
  450. package/lite/tracks.js +114 -0
  451. package/lite/tracks.js.map +1 -0
  452. package/lite/version.d.ts +132 -24
  453. package/lite/version.d.ts.map +1 -1
  454. package/lite/version.js +378 -34
  455. package/lite/version.js.map +1 -1
  456. package/meta.d.ts +77 -0
  457. package/meta.d.ts.map +1 -0
  458. package/meta.js +130 -0
  459. package/meta.js.map +1 -0
  460. package/meta_api.d.ts +7 -0
  461. package/meta_api.d.ts.map +1 -0
  462. package/meta_api.js +7 -0
  463. package/meta_api.js.map +1 -0
  464. package/mint.d.ts +28 -0
  465. package/mint.d.ts.map +1 -0
  466. package/mint.js +66 -0
  467. package/mint.js.map +1 -0
  468. package/open.d.ts +63 -0
  469. package/open.d.ts.map +1 -0
  470. package/open.js +250 -0
  471. package/open.js.map +1 -0
  472. package/origin.d.ts +394 -142
  473. package/origin.d.ts.map +1 -1
  474. package/origin.js +2533 -687
  475. package/origin.js.map +1 -1
  476. package/package.json +8 -13
  477. package/path.d.ts +51 -51
  478. package/path.d.ts.map +1 -1
  479. package/path.js +210 -58
  480. package/path.js.map +1 -1
  481. package/payload.d.ts +33 -0
  482. package/payload.d.ts.map +1 -0
  483. package/payload.js +65 -0
  484. package/payload.js.map +1 -0
  485. package/prefix.d.ts +152 -0
  486. package/prefix.d.ts.map +1 -0
  487. package/prefix.js +349 -0
  488. package/prefix.js.map +1 -0
  489. package/priority.d.ts +8 -0
  490. package/priority.d.ts.map +1 -0
  491. package/priority.js +185 -0
  492. package/priority.js.map +1 -0
  493. package/queue.d.ts +2 -0
  494. package/queue.d.ts.map +1 -0
  495. package/queue.js +46 -0
  496. package/queue.js.map +1 -0
  497. package/ranges.d.ts +36 -0
  498. package/ranges.d.ts.map +1 -0
  499. package/ranges.js +312 -0
  500. package/ranges.js.map +1 -0
  501. package/rescale.d.ts +24 -0
  502. package/rescale.d.ts.map +1 -0
  503. package/rescale.js +39 -0
  504. package/rescale.js.map +1 -0
  505. package/resume.d.ts +55 -0
  506. package/resume.d.ts.map +1 -0
  507. package/resume.js +4173 -0
  508. package/resume.js.map +1 -0
  509. package/resume.test-util.d.ts +2 -0
  510. package/resume.test-util.d.ts.map +1 -0
  511. package/resume.test-util.js +25 -0
  512. package/resume.test-util.js.map +1 -0
  513. package/skips.d.ts +48 -0
  514. package/skips.d.ts.map +1 -0
  515. package/skips.js +182 -0
  516. package/skips.js.map +1 -0
  517. package/stream.d.ts +78 -40
  518. package/stream.d.ts.map +1 -1
  519. package/stream.js +236 -93
  520. package/stream.js.map +1 -1
  521. package/subscription.test-util.d.ts +2 -0
  522. package/subscription.test-util.d.ts.map +1 -0
  523. package/subscription.test-util.js +49 -0
  524. package/subscription.test-util.js.map +1 -0
  525. package/tail.d.ts +23 -14
  526. package/tail.d.ts.map +1 -1
  527. package/tail.js +224 -98
  528. package/tail.js.map +1 -1
  529. package/time.d.ts +41 -102
  530. package/time.d.ts.map +1 -1
  531. package/time.js +129 -92
  532. package/time.js.map +1 -1
  533. package/timed.d.ts +21 -0
  534. package/timed.d.ts.map +1 -0
  535. package/timed.js +2 -0
  536. package/timed.js.map +1 -0
  537. package/track.d.ts +578 -246
  538. package/track.d.ts.map +1 -1
  539. package/track.js +7306 -772
  540. package/track.js.map +1 -1
  541. package/track_api.d.ts +7 -0
  542. package/track_api.d.ts.map +1 -0
  543. package/track_api.js +7 -0
  544. package/track_api.js.map +1 -0
  545. package/util/abort.d.ts +1 -0
  546. package/util/abort.d.ts.map +1 -1
  547. package/util/abort.js +23 -2
  548. package/util/abort.js.map +1 -1
  549. package/util/announce.d.ts +4 -0
  550. package/util/announce.d.ts.map +1 -0
  551. package/util/announce.js +11 -0
  552. package/util/announce.js.map +1 -0
  553. package/util/bigint.d.ts +3 -0
  554. package/util/bigint.d.ts.map +1 -0
  555. package/util/bigint.js +8 -0
  556. package/util/bigint.js.map +1 -0
  557. package/util/change.d.ts +12 -0
  558. package/util/change.d.ts.map +1 -0
  559. package/util/change.js +18 -0
  560. package/util/change.js.map +1 -0
  561. package/util/deadline.d.ts +2 -0
  562. package/util/deadline.d.ts.map +1 -0
  563. package/util/deadline.js +108 -0
  564. package/util/deadline.js.map +1 -0
  565. package/util/decode_error.d.ts +3 -0
  566. package/util/decode_error.d.ts.map +1 -0
  567. package/util/decode_error.js +11 -0
  568. package/util/decode_error.js.map +1 -0
  569. package/util/demand.d.ts +8 -0
  570. package/util/demand.d.ts.map +1 -0
  571. package/util/demand.js +24 -0
  572. package/util/demand.js.map +1 -0
  573. package/util/given_up.d.ts +2 -0
  574. package/util/given_up.d.ts.map +1 -0
  575. package/util/given_up.js +101 -0
  576. package/util/given_up.js.map +1 -0
  577. package/util/hex.d.ts +6 -0
  578. package/util/hex.d.ts.map +1 -1
  579. package/util/hex.js +19 -5
  580. package/util/hex.js.map +1 -1
  581. package/util/key.d.ts +15 -0
  582. package/util/key.d.ts.map +1 -0
  583. package/util/key.js +38 -0
  584. package/util/key.js.map +1 -0
  585. package/util/limits.d.ts +2 -0
  586. package/util/limits.d.ts.map +1 -0
  587. package/util/limits.js +76 -0
  588. package/util/limits.js.map +1 -0
  589. package/util/observed.d.ts +23 -0
  590. package/util/observed.d.ts.map +1 -0
  591. package/util/observed.js +122 -0
  592. package/util/observed.js.map +1 -0
  593. package/util/sorted.d.ts +2 -0
  594. package/util/sorted.d.ts.map +1 -0
  595. package/util/sorted.js +149 -0
  596. package/util/sorted.js.map +1 -0
  597. package/util/timeout.d.ts +2 -1
  598. package/util/timeout.d.ts.map +1 -1
  599. package/util/timeout.js +13 -10
  600. package/util/timeout.js.map +1 -1
  601. package/util/timer.d.ts +2 -0
  602. package/util/timer.d.ts.map +1 -0
  603. package/util/timer.js +19 -0
  604. package/util/timer.js.map +1 -0
  605. package/util/u64.js +0 -1
  606. package/util/utf8.d.ts +2 -0
  607. package/util/utf8.d.ts.map +1 -1
  608. package/util/utf8.js +7 -2
  609. package/util/utf8.js.map +1 -1
  610. package/util/varint.d.ts.map +1 -1
  611. package/util/varint.js +8 -2
  612. package/util/varint.js.map +1 -1
  613. package/util/watch.d.ts +8 -0
  614. package/util/watch.d.ts.map +1 -0
  615. package/util/watch.js +38 -0
  616. package/util/watch.js.map +1 -0
  617. package/util/yield.d.ts +2 -0
  618. package/util/yield.d.ts.map +1 -0
  619. package/util/yield.js +31 -0
  620. package/util/yield.js.map +1 -0
  621. package/varint.d.ts +0 -29
  622. package/varint.d.ts.map +1 -1
  623. package/varint.js +7 -29
  624. package/varint.js.map +1 -1
  625. package/varint_api.d.ts +7 -0
  626. package/varint_api.d.ts.map +1 -0
  627. package/varint_api.js +7 -0
  628. package/varint_api.js.map +1 -0
  629. package/version.d.ts +2 -0
  630. package/version.d.ts.map +1 -0
  631. package/version.js +4 -0
  632. package/version.js.map +1 -0
  633. package/window.d.ts +570 -0
  634. package/window.d.ts.map +1 -0
  635. package/window.js +1677 -0
  636. package/window.js.map +1 -0
  637. package/wire.d.ts +150 -35
  638. package/wire.d.ts.map +1 -1
  639. package/wire.js +27 -1
  640. package/wire.js.map +1 -1
  641. package/connection/established.d.ts +0 -53
  642. package/connection/established.d.ts.map +0 -1
  643. package/connection/established.js +0 -3
  644. package/connection/established.js.map +0 -1
  645. package/ietf/adapter.d.ts +0 -75
  646. package/ietf/adapter.d.ts.map +0 -1
  647. package/ietf/adapter.js +0 -700
  648. package/ietf/adapter.js.map +0 -1
  649. package/lite/datagram_stream.d.ts +0 -8
  650. package/lite/datagram_stream.d.ts.map +0 -1
  651. package/lite/datagram_stream.js +0 -44
  652. package/lite/datagram_stream.js.map +0 -1
  653. package/lite/fetch.d.ts +0 -28
  654. package/lite/fetch.d.ts.map +0 -1
  655. package/lite/fetch.js +0 -79
  656. package/lite/fetch.js.map +0 -1
  657. package/util/log.d.ts +0 -5
  658. package/util/log.d.ts.map +0 -1
  659. package/util/log.js +0 -17
  660. package/util/log.js.map +0 -1
  661. package/zod.d.ts +0 -13
  662. package/zod.d.ts.map +0 -1
  663. package/zod.js +0 -19
  664. package/zod.js.map +0 -1
package/util/key.js ADDED
@@ -0,0 +1,38 @@
1
+ // Group keys are bigints, which `Math.min` and `Math.max` refuse.
2
+ /** The smaller of two keys. */
3
+ export function min(a, b) {
4
+ return a < b ? a : b;
5
+ }
6
+ /** The larger of two keys. */
7
+ export function max(a, b) {
8
+ return a > b ? a : b;
9
+ }
10
+ /** `a - b`, or 0 when `b` is at or past `a`. */
11
+ export function saturatingSub(a, b) {
12
+ return a > b ? a - b : 0n;
13
+ }
14
+ /** An exclusive end past every group a wire can carry (2^64), which an open run ends at. */
15
+ export const UNBOUNDED = 1n << 64n;
16
+ /** The reserved group key, 2^64-1: no group is created there, so every group fits a half-open range. */
17
+ export const RESERVED = UNBOUNDED - 1n;
18
+ /** Refuse a group key a u64 cannot hold, or that is not a bigint, either of which a plain JS caller can pass. */
19
+ export function checkKey(key) {
20
+ if (typeof key !== "bigint")
21
+ throw new TypeError(`group sequence must be a bigint: ${String(key)}`);
22
+ if (key < 0n)
23
+ throw new RangeError(`group sequence must be non-negative: ${key}`);
24
+ if (key >= UNBOUNDED)
25
+ throw new RangeError(`group sequence exceeds 2^64-1: ${key}`);
26
+ return key;
27
+ }
28
+ /** Refuse an exclusive end of a run of group keys that is not a bigint in `[0, 2^64-1]`, so a run never names the reserved group. */
29
+ export function checkEnd(end) {
30
+ if (typeof end !== "bigint")
31
+ throw new TypeError(`group end must be a bigint: ${String(end)}`);
32
+ if (end < 0n)
33
+ throw new RangeError(`group end must be non-negative: ${end}`);
34
+ if (end > RESERVED)
35
+ throw new RangeError(`group end exceeds 2^64-1: ${end}`);
36
+ return end;
37
+ }
38
+ //# sourceMappingURL=key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/util/key.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,+BAA+B;AAC/B,MAAM,UAAU,GAAG,CAAC,CAAS,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CAAC,CAAC;IAC7E,IAAI,GAAG,GAAG,QAAQ;QAAE,MAAM,IAAI,UAAU,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC;IAC7E,OAAO,GAAG,CAAC;AACZ,CAAC","sourcesContent":["// Group keys are bigints, which `Math.min` and `Math.max` refuse.\n\n/** The smaller of two keys. */\nexport function min(a: bigint, b: bigint): bigint {\n\treturn a < b ? a : b;\n}\n\n/** The larger of two keys. */\nexport function max(a: bigint, b: bigint): bigint {\n\treturn a > b ? a : b;\n}\n\n/** `a - b`, or 0 when `b` is at or past `a`. */\nexport function saturatingSub(a: bigint, b: bigint): bigint {\n\treturn a > b ? a - b : 0n;\n}\n\n/** An exclusive end past every group a wire can carry (2^64), which an open run ends at. */\nexport const UNBOUNDED = 1n << 64n;\n\n/** The reserved group key, 2^64-1: no group is created there, so every group fits a half-open range. */\nexport const RESERVED = UNBOUNDED - 1n;\n\n/** Refuse a group key a u64 cannot hold, or that is not a bigint, either of which a plain JS caller can pass. */\nexport function checkKey(key: bigint): bigint {\n\tif (typeof key !== \"bigint\") throw new TypeError(`group sequence must be a bigint: ${String(key)}`);\n\tif (key < 0n) throw new RangeError(`group sequence must be non-negative: ${key}`);\n\tif (key >= UNBOUNDED) throw new RangeError(`group sequence exceeds 2^64-1: ${key}`);\n\treturn key;\n}\n\n/** Refuse an exclusive end of a run of group keys that is not a bigint in `[0, 2^64-1]`, so a run never names the reserved group. */\nexport function checkEnd(end: bigint): bigint {\n\tif (typeof end !== \"bigint\") throw new TypeError(`group end must be a bigint: ${String(end)}`);\n\tif (end < 0n) throw new RangeError(`group end must be non-negative: ${end}`);\n\tif (end > RESERVED) throw new RangeError(`group end exceeds 2^64-1: ${end}`);\n\treturn end;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/util/limits.ts"],"names":[],"mappings":""}
package/util/limits.js ADDED
@@ -0,0 +1,76 @@
1
+ import { Session, SessionCode } from "../error.js";
2
+ /**
3
+ * The largest frame a peer may send, as Rust's `MAX_CACHE_BYTES`: a received frame declaring more
4
+ * is `FrameTooLarge` at its header. It also caps a compressed frame, which is stored and sent
5
+ * whole since the lite-07 header declares a slice's size before its bytes.
6
+ * @internal
7
+ */
8
+ export const MAX_FRAME_BYTES = 32 * 1024 * 1024;
9
+ /**
10
+ * Bytes in each segment of a frame written in pieces past one segment, as Rust's
11
+ * `frame::SEGMENT`: segment `i` holds the frame's bytes from `i * SEGMENT_BYTES`. A wire
12
+ * frame within one segment is decoded whole; a larger one streams in.
13
+ * @internal
14
+ */
15
+ export const SEGMENT_BYTES = 1024 * 1024;
16
+ /** The default limits, matching moq-net's. @internal */
17
+ export const LIMITS = Object.freeze({ announces: 100_000 });
18
+ /** A session's count of live peer requests, which closes the session past its cap. @internal */
19
+ export class Slots {
20
+ #live = 0;
21
+ #max;
22
+ #quic;
23
+ #reason;
24
+ constructor(max, { quic, reason }) {
25
+ this.#max = max;
26
+ this.#quic = quic;
27
+ this.#reason = reason;
28
+ }
29
+ /** Take one slot, or close the session with TOO_MANY_REQUESTS and throw at the cap. */
30
+ acquire() {
31
+ if (this.tryAcquire())
32
+ return;
33
+ const err = new Session(SessionCode.TooManyRequests, { reason: this.#reason });
34
+ this.#quic?.close({ closeCode: err.code, reason: this.#reason });
35
+ throw err;
36
+ }
37
+ /** Take one slot, or leave the session alone and return false at the cap. */
38
+ tryAcquire() {
39
+ if (this.#live >= this.#max)
40
+ return false;
41
+ this.#live += 1;
42
+ return true;
43
+ }
44
+ /** How many slots are left to take. */
45
+ available() {
46
+ return this.#max - this.#live;
47
+ }
48
+ /** Give back `count` slots. */
49
+ release(count = 1) {
50
+ this.#live -= count;
51
+ }
52
+ }
53
+ /** A map whose every entry holds one slot, as moq-net charges each live advertisement. @internal */
54
+ export class SlotMap extends Map {
55
+ #slots;
56
+ constructor(slots) {
57
+ super();
58
+ this.#slots = slots;
59
+ }
60
+ set(key, value) {
61
+ if (!this.has(key))
62
+ this.#slots.acquire();
63
+ return super.set(key, value);
64
+ }
65
+ delete(key) {
66
+ if (!super.delete(key))
67
+ return false;
68
+ this.#slots.release();
69
+ return true;
70
+ }
71
+ clear() {
72
+ this.#slots.release(this.size);
73
+ super.clear();
74
+ }
75
+ }
76
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/util/limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC;AAazC,wDAAwD;AACxD,MAAM,CAAC,MAAM,MAAM,GAAqB,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;AAE9E,gGAAgG;AAChG,MAAM,OAAO,KAAK;IACjB,KAAK,GAAG,CAAC,CAAC;IACV,IAAI,CAAS;IACb,KAAK,CAAgB;IACrB,OAAO,CAAS;IAEhB,YAAY,GAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAA2C;QACjF,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,uFAAuF;IACvF,OAAO;QACN,IAAI,IAAI,CAAC,UAAU,EAAE;YAAE,OAAO;QAC9B,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC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Content":["import { Session, SessionCode } from \"../error.ts\";\n\n/**\n * The largest frame a peer may send, as Rust's `MAX_CACHE_BYTES`: a received frame declaring more\n * is `FrameTooLarge` at its header. It also caps a compressed frame, which is stored and sent\n * whole since the lite-07 header declares a slice's size before its bytes.\n * @internal\n */\nexport const MAX_FRAME_BYTES = 32 * 1024 * 1024;\n\n/**\n * Bytes in each segment of a frame written in pieces past one segment, as Rust's\n * `frame::SEGMENT`: segment `i` holds the frame's bytes from `i * SEGMENT_BYTES`. A wire\n * frame within one segment is decoded whole; a larger one streams in.\n * @internal\n */\nexport const SEGMENT_BYTES = 1024 * 1024;\n\n/**\n * How many live requests a peer may hold on one session, as moq-net's `session::Limits`.\n * Subscriptions, FETCHes, and listing PUBLISHes have no cap: each holds a bidi stream, so stream\n * credit bounds them.\n * @internal\n */\nexport interface Limits {\n\t/** Broadcasts (moq-lite) or namespaces (moq-transport) the peer may have announced to us. */\n\tannounces: number;\n}\n\n/** The default limits, matching moq-net's. @internal */\nexport const LIMITS: Readonly<Limits> = Object.freeze({ announces: 100_000 });\n\n/** A session's count of live peer requests, which closes the session past its cap. @internal */\nexport class Slots {\n\t#live = 0;\n\t#max: number;\n\t#quic?: WebTransport;\n\t#reason: string;\n\n\tconstructor(max: number, { quic, reason }: { quic?: WebTransport; reason: string }) {\n\t\tthis.#max = max;\n\t\tthis.#quic = quic;\n\t\tthis.#reason = reason;\n\t}\n\n\t/** Take one slot, or close the session with TOO_MANY_REQUESTS and throw at the cap. */\n\tacquire() {\n\t\tif (this.tryAcquire()) return;\n\t\tconst err = new Session(SessionCode.TooManyRequests, { reason: this.#reason });\n\t\tthis.#quic?.close({ closeCode: err.code, reason: this.#reason });\n\t\tthrow err;\n\t}\n\n\t/** Take one slot, or leave the session alone and return false at the cap. */\n\ttryAcquire(): boolean {\n\t\tif (this.#live >= this.#max) return false;\n\t\tthis.#live += 1;\n\t\treturn true;\n\t}\n\n\t/** How many slots are left to take. */\n\tavailable(): number {\n\t\treturn this.#max - this.#live;\n\t}\n\n\t/** Give back `count` slots. */\n\trelease(count = 1) {\n\t\tthis.#live -= count;\n\t}\n}\n\n/** A map whose every entry holds one slot, as moq-net charges each live advertisement. @internal */\nexport class SlotMap<K, V> extends Map<K, V> {\n\t#slots: Slots;\n\n\tconstructor(slots: Slots) {\n\t\tsuper();\n\t\tthis.#slots = slots;\n\t}\n\n\toverride set(key: K, value: V): this {\n\t\tif (!this.has(key)) this.#slots.acquire();\n\t\treturn super.set(key, value);\n\t}\n\n\toverride delete(key: K): boolean {\n\t\tif (!super.delete(key)) return false;\n\t\tthis.#slots.release();\n\t\treturn true;\n\t}\n\n\toverride clear() {\n\t\tthis.#slots.release(this.size);\n\t\tsuper.clear();\n\t}\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import { type Dispose, type Getter, Signal } from "@moq/signals";
2
+ type Listener<T> = (value: T) => void;
3
+ /** A package-private signal whose listeners hold demand for its producer. */
4
+ export declare class Observed<T> extends Signal<T> {
5
+ #private;
6
+ readonly wanted: Signal<boolean>;
7
+ subscribe(fn: Listener<T>): Dispose;
8
+ watch(fn: Listener<T>): Dispose;
9
+ changed(): Promise<T>;
10
+ changed(fn: Listener<T>): Dispose;
11
+ }
12
+ /** Forward a changing getter without observing its value until a reader asks. */
13
+ export declare class Follow<T> implements Getter<T | undefined> {
14
+ #private;
15
+ constructor(source: Getter<Getter<T> | undefined>);
16
+ peek(): T | undefined;
17
+ subscribe(fn: Listener<T | undefined>): Dispose;
18
+ changed(): Promise<T | undefined>;
19
+ changed(fn: Listener<T | undefined>): Dispose;
20
+ watch(fn: Listener<T | undefined>): Dispose;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=observed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observed.d.ts","sourceRoot":"","sources":["../../src/util/observed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGjE,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEtC,6EAA6E;AAC7E,qBAAa,QAAQ,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;;IACzC,QAAQ,CAAC,MAAM,kBAAqB;IAe3B,SAAS,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAQ3C;IAIQ,KAAK,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAOvC;IAEQ,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;CAkB3C;AAED,iFAAiF;AACjF,qBAAa,MAAM,CAAC,CAAC,CAAE,YAAW,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;;IAGtD,YAAY,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAEhD;IAED,IAAI,IAAI,CAAC,GAAG,SAAS,CAEpB;IAED,SAAS,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,OAAO,CAoB9C;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC;IAyB9C,KAAK,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,OAAO,CAE1C;CACD"}
@@ -0,0 +1,122 @@
1
+ import { Signal } from "@moq/signals";
2
+ import { watchVia } from "./watch.js";
3
+ /** A package-private signal whose listeners hold demand for its producer. */
4
+ export class Observed extends Signal {
5
+ wanted = new Signal(false);
6
+ #observers = 0;
7
+ // Set while Signal's own watch registers its listener, which is already one per call.
8
+ #watching = false;
9
+ #observe() {
10
+ if (++this.#observers === 1)
11
+ this.wanted.set(true);
12
+ let active = true;
13
+ return () => {
14
+ if (!active)
15
+ return;
16
+ active = false;
17
+ if (--this.#observers === 0)
18
+ this.wanted.set(false);
19
+ };
20
+ }
21
+ subscribe(fn) {
22
+ const release = this.#observe();
23
+ // A wrapper per call, so subscribing the same `fn` twice holds demand twice.
24
+ const dispose = super.subscribe(this.#watching ? fn : (value) => fn(value));
25
+ return () => {
26
+ dispose();
27
+ release();
28
+ };
29
+ }
30
+ // Signal's own watch delivers its first call in the same flush as any change before it, but
31
+ // only to the exact listener it registered, so `subscribe` must not wrap that one.
32
+ watch(fn) {
33
+ this.#watching = true;
34
+ try {
35
+ return super.watch(fn);
36
+ }
37
+ finally {
38
+ this.#watching = false;
39
+ }
40
+ }
41
+ changed(fn) {
42
+ if (!fn)
43
+ return new Promise((resolve) => this.changed(resolve));
44
+ const release = this.#observe();
45
+ const dispose = super.changed((value) => {
46
+ // Schedule a reactive reader's next run before publishing unwanted, so its
47
+ // replacement listener coalesces away the temporary gap in demand.
48
+ try {
49
+ fn(value);
50
+ }
51
+ finally {
52
+ release();
53
+ }
54
+ });
55
+ return () => {
56
+ dispose();
57
+ release();
58
+ };
59
+ }
60
+ }
61
+ /** Forward a changing getter without observing its value until a reader asks. */
62
+ export class Follow {
63
+ #source;
64
+ constructor(source) {
65
+ this.#source = source;
66
+ }
67
+ peek() {
68
+ return this.#source.peek()?.peek();
69
+ }
70
+ subscribe(fn) {
71
+ let inner;
72
+ let stopInner;
73
+ const follow = () => {
74
+ const next = this.#source.peek();
75
+ if (next === inner)
76
+ return;
77
+ const previous = stopInner;
78
+ inner = next;
79
+ stopInner = inner?.subscribe(() => fn(this.peek()));
80
+ previous?.();
81
+ };
82
+ const stopSource = this.#source.subscribe(() => {
83
+ follow();
84
+ fn(this.peek());
85
+ });
86
+ follow();
87
+ return () => {
88
+ stopSource();
89
+ stopInner?.();
90
+ };
91
+ }
92
+ changed(fn) {
93
+ if (!fn)
94
+ return new Promise((resolve) => this.changed(resolve));
95
+ let active = true;
96
+ let stopInner;
97
+ let stopSource;
98
+ const dispose = () => {
99
+ active = false;
100
+ stopSource?.();
101
+ stopInner?.();
102
+ };
103
+ const changed = () => {
104
+ if (!active)
105
+ return;
106
+ active = false;
107
+ try {
108
+ fn(this.peek());
109
+ }
110
+ finally {
111
+ dispose();
112
+ }
113
+ };
114
+ stopSource = this.#source.changed(changed);
115
+ stopInner = this.#source.peek()?.changed(changed);
116
+ return dispose;
117
+ }
118
+ watch(fn) {
119
+ return watchVia(this, fn);
120
+ }
121
+ }
122
+ //# sourceMappingURL=observed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observed.js","sourceRoot":"","sources":["../../src/util/observed.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,6EAA6E;AAC7E,MAAM,OAAO,QAAY,SAAQ,MAAS;IAChC,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IACpC,UAAU,GAAG,CAAC,CAAC;IACf,sFAAsF;IACtF,SAAS,GAAG,KAAK,CAAC;IAElB,QAAQ;QACP,IAAI,EAAE,IAAI,CAAC,UAAU,KAAK,CAAC;YAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,MAAM,GAAG,IAAI,CAAC;QAClB,OAAO,GAAG,EAAE;YACX,IAAI,CAAC,MAAM;gBAAE,OAAO;YACpB,MAAM,GAAG,KAAK,CAAC;YACf,IAAI,EAAE,IAAI,CAAC,UAAU,KAAK,CAAC;gBAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrD,CAAC,CAAC;IACH,CAAC;IAEQ,SAAS,CAAC,EAAe;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChC,6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M,OAAO,GAAG,GAAG,EAAE;YACpB,IAAI,CAAC,MAAM;gBAAE,OAAO;YACpB,MAAM,GAAG,KAAK,CAAC;YACf,IAAI,CAAC;gBACJ,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YACjB,CAAC;oBAAS,CAAC;gBACV,OAAO,EAAE,CAAC;YACX,CAAC;QACF,CAAC,CAAC;QACF,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3C,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,EAA2B;QAChC,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3B,CAAC;CACD","sourcesContent":["import { type Dispose, type Getter, Signal } from \"@moq/signals\";\nimport { watchVia } from \"./watch.ts\";\n\ntype Listener<T> = (value: T) => void;\n\n/** A package-private signal whose listeners hold demand for its producer. */\nexport class Observed<T> extends Signal<T> {\n\treadonly wanted = new Signal(false);\n\t#observers = 0;\n\t// Set while Signal's own watch registers its listener, which is already one per call.\n\t#watching = false;\n\n\t#observe(): Dispose {\n\t\tif (++this.#observers === 1) this.wanted.set(true);\n\t\tlet active = true;\n\t\treturn () => {\n\t\t\tif (!active) return;\n\t\t\tactive = false;\n\t\t\tif (--this.#observers === 0) this.wanted.set(false);\n\t\t};\n\t}\n\n\toverride subscribe(fn: Listener<T>): Dispose {\n\t\tconst release = this.#observe();\n\t\t// A wrapper per call, so subscribing the same `fn` twice holds demand twice.\n\t\tconst dispose = super.subscribe(this.#watching ? fn : (value) => fn(value));\n\t\treturn () => {\n\t\t\tdispose();\n\t\t\trelease();\n\t\t};\n\t}\n\n\t// Signal's own watch delivers its first call in the same flush as any change before it, but\n\t// only to the exact listener it registered, so `subscribe` must not wrap that one.\n\toverride watch(fn: Listener<T>): Dispose {\n\t\tthis.#watching = true;\n\t\ttry {\n\t\t\treturn super.watch(fn);\n\t\t} finally {\n\t\t\tthis.#watching = false;\n\t\t}\n\t}\n\n\toverride changed(): Promise<T>;\n\toverride changed(fn: Listener<T>): Dispose;\n\toverride changed(fn?: Listener<T>): Promise<T> | Dispose {\n\t\tif (!fn) return new Promise<T>((resolve) => this.changed(resolve));\n\t\tconst release = this.#observe();\n\t\tconst dispose = super.changed((value) => {\n\t\t\t// Schedule a reactive reader's next run before publishing unwanted, so its\n\t\t\t// replacement listener coalesces away the temporary gap in demand.\n\t\t\ttry {\n\t\t\t\tfn(value);\n\t\t\t} finally {\n\t\t\t\trelease();\n\t\t\t}\n\t\t});\n\t\treturn () => {\n\t\t\tdispose();\n\t\t\trelease();\n\t\t};\n\t}\n}\n\n/** Forward a changing getter without observing its value until a reader asks. */\nexport class Follow<T> implements Getter<T | undefined> {\n\t#source: Getter<Getter<T> | undefined>;\n\n\tconstructor(source: Getter<Getter<T> | undefined>) {\n\t\tthis.#source = source;\n\t}\n\n\tpeek(): T | undefined {\n\t\treturn this.#source.peek()?.peek();\n\t}\n\n\tsubscribe(fn: Listener<T | undefined>): Dispose {\n\t\tlet inner: Getter<T> | undefined;\n\t\tlet stopInner: Dispose | undefined;\n\t\tconst follow = () => {\n\t\t\tconst next = this.#source.peek();\n\t\t\tif (next === inner) return;\n\t\t\tconst previous = stopInner;\n\t\t\tinner = next;\n\t\t\tstopInner = inner?.subscribe(() => fn(this.peek()));\n\t\t\tprevious?.();\n\t\t};\n\t\tconst stopSource = this.#source.subscribe(() => {\n\t\t\tfollow();\n\t\t\tfn(this.peek());\n\t\t});\n\t\tfollow();\n\t\treturn () => {\n\t\t\tstopSource();\n\t\t\tstopInner?.();\n\t\t};\n\t}\n\n\tchanged(): Promise<T | undefined>;\n\tchanged(fn: Listener<T | undefined>): Dispose;\n\tchanged(fn?: Listener<T | undefined>): Promise<T | undefined> | Dispose {\n\t\tif (!fn) return new Promise<T | undefined>((resolve) => this.changed(resolve));\n\t\tlet active = true;\n\t\tlet stopInner: Dispose | undefined;\n\t\tlet stopSource: Dispose | undefined;\n\t\tconst dispose = () => {\n\t\t\tactive = false;\n\t\t\tstopSource?.();\n\t\t\tstopInner?.();\n\t\t};\n\t\tconst changed = () => {\n\t\t\tif (!active) return;\n\t\t\tactive = false;\n\t\t\ttry {\n\t\t\t\tfn(this.peek());\n\t\t\t} finally {\n\t\t\t\tdispose();\n\t\t\t}\n\t\t};\n\t\tstopSource = this.#source.changed(changed);\n\t\tstopInner = this.#source.peek()?.changed(changed);\n\t\treturn dispose;\n\t}\n\n\twatch(fn: Listener<T | undefined>): Dispose {\n\t\treturn watchVia(this, fn);\n\t}\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sorted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sorted.d.ts","sourceRoot":"","sources":["../../src/util/sorted.ts"],"names":[],"mappings":""}
package/util/sorted.js ADDED
@@ -0,0 +1,149 @@
1
+ // Chunks stay between LOAD / 2 and 2 * LOAD entries, so an insert or delete shifts one chunk
2
+ // and the chunk index rather than the whole collection.
3
+ const LOAD = 256;
4
+ /**
5
+ * Distinct values ordered by a key, with neighbor lookups by key.
6
+ *
7
+ * Kept in sorted chunks, the layout of Python's `sortedcontainers`: a lookup is two binary
8
+ * searches, and an insert or delete costs O(log n + LOAD + n / LOAD) moves. Callers must not
9
+ * change a stored value's key, and must not mutate the list while iterating {@link from}.
10
+ *
11
+ * @internal
12
+ */
13
+ export class Sorted {
14
+ #chunks = [];
15
+ #size = 0;
16
+ // The position the last #seek found.
17
+ #c = 0;
18
+ #i = 0;
19
+ #key;
20
+ #compare;
21
+ constructor(key, compare) {
22
+ this.#key = key;
23
+ this.#compare = compare;
24
+ }
25
+ /** How many values it holds. */
26
+ get size() {
27
+ return this.#size;
28
+ }
29
+ /** The value with the lowest key. */
30
+ first() {
31
+ return this.#chunks[0]?.[0];
32
+ }
33
+ /** The value with the highest key. */
34
+ last() {
35
+ return this.#chunks.at(-1)?.at(-1);
36
+ }
37
+ /** The value with the lowest key at or above `key`. */
38
+ ceil(key) {
39
+ this.#seek(key, true);
40
+ return this.#at();
41
+ }
42
+ /** The value with the lowest key above `key`. */
43
+ higher(key) {
44
+ this.#seek(key, false);
45
+ return this.#at();
46
+ }
47
+ /** The value with the highest key at or below `key`. */
48
+ floor(key) {
49
+ this.#seek(key, false);
50
+ return this.#before();
51
+ }
52
+ /** The value with the highest key below `key`. */
53
+ lower(key) {
54
+ this.#seek(key, true);
55
+ return this.#before();
56
+ }
57
+ /** Every value with a key at or above `key`, in order. */
58
+ *from(key) {
59
+ this.#seek(key, true);
60
+ let i = this.#i;
61
+ for (let c = this.#c; c < this.#chunks.length; c++, i = 0) {
62
+ const chunk = this.#chunks[c];
63
+ for (; i < chunk.length; i++)
64
+ yield chunk[i];
65
+ }
66
+ }
67
+ /** Add `value`, whose key no stored value has. */
68
+ insert(value) {
69
+ this.#size++;
70
+ const last = this.#chunks.length - 1;
71
+ if (last < 0) {
72
+ this.#chunks.push([value]);
73
+ return;
74
+ }
75
+ this.#seek(this.#key(value), false);
76
+ let c = this.#c;
77
+ let i = this.#i;
78
+ if (c > last) {
79
+ c = last;
80
+ i = this.#chunks[last].length;
81
+ }
82
+ const chunk = this.#chunks[c];
83
+ chunk.splice(i, 0, value);
84
+ if (chunk.length > 2 * LOAD)
85
+ this.#chunks.splice(c + 1, 0, chunk.splice(LOAD));
86
+ }
87
+ /** Remove the value stored under `key`, if any. */
88
+ delete(key) {
89
+ this.#seek(key, true);
90
+ const c = this.#c;
91
+ const i = this.#i;
92
+ const chunk = this.#chunks[c];
93
+ if (!chunk || this.#compare(this.#key(chunk[i]), key) !== 0)
94
+ return;
95
+ this.#size--;
96
+ chunk.splice(i, 1);
97
+ if (this.#chunks.length === 1) {
98
+ if (chunk.length === 0)
99
+ this.#chunks.pop();
100
+ }
101
+ else if (chunk.length < LOAD / 2) {
102
+ // Merge into a neighbor so chunks stay large enough to keep the chunk index short.
103
+ const a = c > 0 ? c - 1 : c;
104
+ const merged = this.#chunks[a].concat(this.#chunks[a + 1]);
105
+ const half = merged.length >>> 1;
106
+ if (merged.length > 2 * LOAD)
107
+ this.#chunks.splice(a, 2, merged.slice(0, half), merged.slice(half));
108
+ else
109
+ this.#chunks.splice(a, 2, merged);
110
+ }
111
+ }
112
+ // Point `#c` and `#i` at the first value whose key is above `key`, or at or above it when
113
+ // `inclusive`. Fields rather than a returned pair, so a lookup allocates nothing.
114
+ #seek(key, inclusive) {
115
+ let lo = 0;
116
+ let hi = this.#chunks.length;
117
+ while (lo < hi) {
118
+ const mid = (lo + hi) >>> 1;
119
+ const chunk = this.#chunks[mid];
120
+ if (this.#above(chunk[chunk.length - 1], key, inclusive))
121
+ hi = mid;
122
+ else
123
+ lo = mid + 1;
124
+ }
125
+ this.#c = lo;
126
+ const chunk = this.#chunks[lo];
127
+ lo = 0;
128
+ hi = chunk?.length ?? 0;
129
+ while (lo < hi) {
130
+ const mid = (lo + hi) >>> 1;
131
+ if (this.#above(chunk[mid], key, inclusive))
132
+ hi = mid;
133
+ else
134
+ lo = mid + 1;
135
+ }
136
+ this.#i = lo;
137
+ }
138
+ #above(value, key, inclusive) {
139
+ const order = this.#compare(this.#key(value), key);
140
+ return inclusive ? order >= 0 : order > 0;
141
+ }
142
+ #at() {
143
+ return this.#chunks[this.#c]?.[this.#i];
144
+ }
145
+ #before() {
146
+ return this.#i > 0 ? this.#chunks[this.#c][this.#i - 1] : this.#chunks[this.#c - 1]?.at(-1);
147
+ }
148
+ }
149
+ //# sourceMappingURL=sorted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sorted.js","sourceRoot":"","sources":["../../src/util/sorted.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,wDAAwD;AACxD,MAAM,IAAI,GAAG,GAAG,CAAC;AAEjB;;;;;;;;GAQG;AACH,MAAM,OAAO,MAAM;IAClB,OAAO,GAAU,EAA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AC;YAC5B,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC;gBAAE,EAAE,GAAG,GAAG,CAAC;;gBACjD,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACd,CAAC;IAED,MAAM,CAAC,KAAQ,EAAE,GAAM,EAAE,SAAkB;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;QACnD,OAAO,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;IAC3C,CAAC;IAED,GAAG;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,OAAO;QACN,OAAO,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7F,CAAC;CACD","sourcesContent":["// Chunks stay between LOAD / 2 and 2 * LOAD entries, so an insert or delete shifts one chunk\n// and the chunk index rather than the whole collection.\nconst LOAD = 256;\n\n/**\n * Distinct values ordered by a key, with neighbor lookups by key.\n *\n * Kept in sorted chunks, the layout of Python's `sortedcontainers`: a lookup is two binary\n * searches, and an insert or delete costs O(log n + LOAD + n / LOAD) moves. Callers must not\n * change a stored value's key, and must not mutate the list while iterating {@link from}.\n *\n * @internal\n */\nexport class Sorted<K, V> {\n\t#chunks: V[][] = [];\n\t#size = 0;\n\t// The position the last #seek found.\n\t#c = 0;\n\t#i = 0;\n\treadonly #key: (value: V) => K;\n\treadonly #compare: (a: K, b: K) => number;\n\n\tconstructor(key: (value: V) => K, compare: (a: K, b: K) => number) {\n\t\tthis.#key = key;\n\t\tthis.#compare = compare;\n\t}\n\n\t/** How many values it holds. */\n\tget size(): number {\n\t\treturn this.#size;\n\t}\n\n\t/** The value with the lowest key. */\n\tfirst(): V | undefined {\n\t\treturn this.#chunks[0]?.[0];\n\t}\n\n\t/** The value with the highest key. */\n\tlast(): V | undefined {\n\t\treturn this.#chunks.at(-1)?.at(-1);\n\t}\n\n\t/** The value with the lowest key at or above `key`. */\n\tceil(key: K): V | undefined {\n\t\tthis.#seek(key, true);\n\t\treturn this.#at();\n\t}\n\n\t/** The value with the lowest key above `key`. */\n\thigher(key: K): V | undefined {\n\t\tthis.#seek(key, false);\n\t\treturn this.#at();\n\t}\n\n\t/** The value with the highest key at or below `key`. */\n\tfloor(key: K): V | undefined {\n\t\tthis.#seek(key, false);\n\t\treturn this.#before();\n\t}\n\n\t/** The value with the highest key below `key`. */\n\tlower(key: K): V | undefined {\n\t\tthis.#seek(key, true);\n\t\treturn this.#before();\n\t}\n\n\t/** Every value with a key at or above `key`, in order. */\n\t*from(key: K): Generator<V> {\n\t\tthis.#seek(key, true);\n\t\tlet i = this.#i;\n\t\tfor (let c = this.#c; c < this.#chunks.length; c++, i = 0) {\n\t\t\tconst chunk = this.#chunks[c];\n\t\t\tfor (; i < chunk.length; i++) yield chunk[i];\n\t\t}\n\t}\n\n\t/** Add `value`, whose key no stored value has. */\n\tinsert(value: V): void {\n\t\tthis.#size++;\n\t\tconst last = this.#chunks.length - 1;\n\t\tif (last < 0) {\n\t\t\tthis.#chunks.push([value]);\n\t\t\treturn;\n\t\t}\n\t\tthis.#seek(this.#key(value), false);\n\t\tlet c = this.#c;\n\t\tlet i = this.#i;\n\t\tif (c > last) {\n\t\t\tc = last;\n\t\t\ti = this.#chunks[last].length;\n\t\t}\n\t\tconst chunk = this.#chunks[c];\n\t\tchunk.splice(i, 0, value);\n\t\tif (chunk.length > 2 * LOAD) this.#chunks.splice(c + 1, 0, chunk.splice(LOAD));\n\t}\n\n\t/** Remove the value stored under `key`, if any. */\n\tdelete(key: K): void {\n\t\tthis.#seek(key, true);\n\t\tconst c = this.#c;\n\t\tconst i = this.#i;\n\t\tconst chunk = this.#chunks[c];\n\t\tif (!chunk || this.#compare(this.#key(chunk[i]), key) !== 0) return;\n\t\tthis.#size--;\n\t\tchunk.splice(i, 1);\n\t\tif (this.#chunks.length === 1) {\n\t\t\tif (chunk.length === 0) this.#chunks.pop();\n\t\t} else if (chunk.length < LOAD / 2) {\n\t\t\t// Merge into a neighbor so chunks stay large enough to keep the chunk index short.\n\t\t\tconst a = c > 0 ? c - 1 : c;\n\t\t\tconst merged = this.#chunks[a].concat(this.#chunks[a + 1]);\n\t\t\tconst half = merged.length >>> 1;\n\t\t\tif (merged.length > 2 * LOAD) this.#chunks.splice(a, 2, merged.slice(0, half), merged.slice(half));\n\t\t\telse this.#chunks.splice(a, 2, merged);\n\t\t}\n\t}\n\n\t// Point `#c` and `#i` at the first value whose key is above `key`, or at or above it when\n\t// `inclusive`. Fields rather than a returned pair, so a lookup allocates nothing.\n\t#seek(key: K, inclusive: boolean): void {\n\t\tlet lo = 0;\n\t\tlet hi = this.#chunks.length;\n\t\twhile (lo < hi) {\n\t\t\tconst mid = (lo + hi) >>> 1;\n\t\t\tconst chunk = this.#chunks[mid];\n\t\t\tif (this.#above(chunk[chunk.length - 1], key, inclusive)) hi = mid;\n\t\t\telse lo = mid + 1;\n\t\t}\n\t\tthis.#c = lo;\n\t\tconst chunk = this.#chunks[lo];\n\t\tlo = 0;\n\t\thi = chunk?.length ?? 0;\n\t\twhile (lo < hi) {\n\t\t\tconst mid = (lo + hi) >>> 1;\n\t\t\tif (this.#above(chunk[mid], key, inclusive)) hi = mid;\n\t\t\telse lo = mid + 1;\n\t\t}\n\t\tthis.#i = lo;\n\t}\n\n\t#above(value: V, key: K, inclusive: boolean): boolean {\n\t\tconst order = this.#compare(this.#key(value), key);\n\t\treturn inclusive ? order >= 0 : order > 0;\n\t}\n\n\t#at(): V | undefined {\n\t\treturn this.#chunks[this.#c]?.[this.#i];\n\t}\n\n\t#before(): V | undefined {\n\t\treturn this.#i > 0 ? this.#chunks[this.#c][this.#i - 1] : this.#chunks[this.#c - 1]?.at(-1);\n\t}\n}\n"]}
package/util/timeout.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { type Duration } from "@moq/clock";
1
2
  export declare class TimeoutError extends Error {
2
3
  constructor(message: string);
3
4
  }
4
- export declare function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T>;
5
+ export declare function withTimeout<T>(promise: Promise<T>, duration: Duration, message: string): Promise<T>;
5
6
  //# sourceMappingURL=timeout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAKD,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAM3F"}
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAoB,MAAM,YAAY,CAAC;AAE7D,qBAAa,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAKD,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAOzG"}
package/util/timeout.js CHANGED
@@ -1,18 +1,21 @@
1
- /* @ts-self-types="./timeout.d.ts" */
1
+ import { Elapsed, timeout } from "@moq/clock";
2
2
  export class TimeoutError extends Error {
3
3
  constructor(message) {
4
4
  super(message);
5
5
  this.name = "TimeoutError";
6
6
  }
7
7
  }
8
- // Race `promise` against a timeout. There's no cancellation; if `promise`
9
- // settles after the timeout fires the caller is responsible for cleaning up
10
- // any side effects (open streams, etc.) it may produce.
11
- export function withTimeout(promise, ms, message) {
12
- let timer;
13
- const timeout = new Promise((_, reject) => {
14
- timer = setTimeout(() => reject(new TimeoutError(message)), ms);
15
- });
16
- return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
8
+ // Race `promise` against a timeout on the installed clock. There's no cancellation; if
9
+ // `promise` settles after the timeout fires the caller is responsible for cleaning up any
10
+ // side effects (open streams, etc.) it may produce.
11
+ export async function withTimeout(promise, duration, message) {
12
+ try {
13
+ return await timeout(duration, promise);
14
+ }
15
+ catch (err) {
16
+ if (err instanceof Elapsed)
17
+ throw new TimeoutError(message);
18
+ throw err;
19
+ }
17
20
  }
18
21
  //# sourceMappingURL=timeout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC5B,CAAC;CACD;AAED,0EAA0E;AAC1E,4EAA4E;AAC5E,wDAAwD;AACxD,MAAM,UAAU,WAAW,CAAI,OAAmB,EAAE,EAAU,EAAE,OAAe;IAC9E,IAAI,KAAoC,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAChD,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["export class TimeoutError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"TimeoutError\";\n\t}\n}\n\n// Race `promise` against a timeout. There's no cancellation; if `promise`\n// settles after the timeout fires the caller is responsible for cleaning up\n// any side effects (open streams, etc.) it may produce.\nexport function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {\n\tlet timer: ReturnType<typeof setTimeout>;\n\tconst timeout = new Promise<never>((_, reject) => {\n\t\ttimer = setTimeout(() => reject(new TimeoutError(message)), ms);\n\t});\n\treturn Promise.race([promise, timeout]).finally(() => clearTimeout(timer));\n}\n"]}
1
+ {"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE7D,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC5B,CAAC;CACD;AAED,uFAAuF;AACvF,0FAA0F;AAC1F,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAI,OAAmB,EAAE,QAAkB,EAAE,OAAe;IAC5F,IAAI,CAAC;QACJ,OAAO,MAAM,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,IAAI,GAAG,YAAY,OAAO;YAAE,MAAM,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC5D,MAAM,GAAG,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["import { type Duration, Elapsed, timeout } from \"@moq/clock\";\n\nexport class TimeoutError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"TimeoutError\";\n\t}\n}\n\n// Race `promise` against a timeout on the installed clock. There's no cancellation; if\n// `promise` settles after the timeout fires the caller is responsible for cleaning up any\n// side effects (open streams, etc.) it may produce.\nexport async function withTimeout<T>(promise: Promise<T>, duration: Duration, message: string): Promise<T> {\n\ttry {\n\t\treturn await timeout(duration, promise);\n\t} catch (err) {\n\t\tif (err instanceof Elapsed) throw new TimeoutError(message);\n\t\tthrow err;\n\t}\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../src/util/timer.ts"],"names":[],"mappings":""}
package/util/timer.js ADDED
@@ -0,0 +1,19 @@
1
+ import { sleep } from "@moq/clock";
2
+ /**
3
+ * Run `fn` after `duration` on the installed clock, and return the call that cancels it.
4
+ *
5
+ * `ref: false` lets a Node or Bun process exit while only this timer is pending.
6
+ *
7
+ * @internal
8
+ */
9
+ export function after(duration, fn, options) {
10
+ const abort = new AbortController();
11
+ void sleep(duration, { signal: abort.signal, ref: options?.ref }).then(() => {
12
+ // The wakeup can already be queued when the timer is cancelled.
13
+ if (!abort.signal.aborted)
14
+ fn();
15
+ }, ignore);
16
+ return () => abort.abort();
17
+ }
18
+ function ignore() { }
19
+ //# sourceMappingURL=timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/util/timer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,QAAkB,EAAE,EAAc,EAAE,OAA2B;IACpF,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;IACpC,KAAK,KAAK,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QAC3E,gEAAgE;QAChE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO;YAAE,EAAE,EAAE,CAAC;IACjC,CAAC,EAAE,MAAM,CAAC,CAAC;IACX,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,SAAS,MAAM,KAAU,CAAC","sourcesContent":["import { type Duration, sleep } from \"@moq/clock\";\n\n/**\n * Run `fn` after `duration` on the installed clock, and return the call that cancels it.\n *\n * `ref: false` lets a Node or Bun process exit while only this timer is pending.\n *\n * @internal\n */\nexport function after(duration: Duration, fn: () => void, options?: { ref?: boolean }): () => void {\n\tconst abort = new AbortController();\n\tvoid sleep(duration, { signal: abort.signal, ref: options?.ref }).then(() => {\n\t\t// The wakeup can already be queued when the timer is cancelled.\n\t\tif (!abort.signal.aborted) fn();\n\t}, ignore);\n\treturn () => abort.abort();\n}\n\nfunction ignore(): void {}\n"]}
package/util/u64.js CHANGED
@@ -1,4 +1,3 @@
1
- /* @ts-self-types="./u64.d.ts" */
2
1
  // An unsigned 64-bit integer as two u32 halves, so nothing on the hot path needs a BigInt.
3
2
  // Package-internal. Varints are only its wire encoding; see ./varint.ts.
4
3
  /** 2^32, the weight of the upper half. */
package/util/utf8.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  /** Decode a protocol string, rejecting bytes that are not valid UTF-8. */
2
2
  export declare function decodeUtf8(buffer: Uint8Array): string;
3
+ /** Throw unless a track name is well-formed: UTF-8 cannot carry a lone surrogate, so the encoder would write U+FFFD, another name's bytes. */
4
+ export declare function checkName(name: string): void;
3
5
  //# sourceMappingURL=utf8.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../../src/util/utf8.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAErD"}
1
+ {"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../../src/util/utf8.ts"],"names":[],"mappings":"AAGA,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAErD;AAED,8IAA8I;AAC9I,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE5C"}
package/util/utf8.js CHANGED
@@ -1,7 +1,12 @@
1
- /* @ts-self-types="./utf8.d.ts" */
2
- const decoder = new TextDecoder("utf-8", { fatal: true });
1
+ // `ignoreBOM` keeps a leading U+FEFF, which is text like any other, as Rust does.
2
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
3
3
  /** Decode a protocol string, rejecting bytes that are not valid UTF-8. */
4
4
  export function decodeUtf8(buffer) {
5
5
  return decoder.decode(buffer);
6
6
  }
7
+ /** Throw unless a track name is well-formed: UTF-8 cannot carry a lone surrogate, so the encoder would write U+FFFD, another name's bytes. */
8
+ export function checkName(name) {
9
+ if (!name.isWellFormed())
10
+ throw new Error("track name contains a lone surrogate");
11
+ }
7
12
  //# sourceMappingURL=utf8.js.map
package/util/utf8.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utf8.js","sourceRoot":"","sources":["../../src/util/utf8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1D,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC5C,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["const decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\n/** Decode a protocol string, rejecting bytes that are not valid UTF-8. */\nexport function decodeUtf8(buffer: Uint8Array): string {\n\treturn decoder.decode(buffer);\n}\n"]}
1
+ {"version":3,"file":"utf8.js","sourceRoot":"","sources":["../../src/util/utf8.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAE3E,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC5C,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED,8IAA8I;AAC9I,MAAM,UAAU,SAAS,CAAC,IAAY;IACrC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;AACnF,CAAC","sourcesContent":["// `ignoreBOM` keeps a leading U+FEFF, which is text like any other, as Rust does.\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true });\n\n/** Decode a protocol string, rejecting bytes that are not valid UTF-8. */\nexport function decodeUtf8(buffer: Uint8Array): string {\n\treturn decoder.decode(buffer);\n}\n\n/** Throw unless a track name is well-formed: UTF-8 cannot carry a lone surrogate, so the encoder would write U+FFFD, another name's bytes. */\nexport function checkName(name: string): void {\n\tif (!name.isWellFormed()) throw new Error(\"track name contains a lone surrogate\");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../../src/util/varint.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,eAAO,MAAM,KAAK;IAAK,EAAE;CAAK,CAAC;AAE/B,sGAAsG;AACtG,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAYhD;AAaD,sDAAsD;AACtD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;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