@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/internal.js CHANGED
@@ -1,5 +1,41 @@
1
- /* @ts-self-types="./internal.d.ts" */
1
+ /**
2
+ * Package-internal constructor hooks. Classes keep their constructors private so consumers
3
+ * can't mint detached handles; sibling modules create identities through these hooks instead.
4
+ * Not exported from the package entrypoint.
5
+ *
6
+ * @module
7
+ */
8
+ import { Duration } from "@moq/clock";
9
+ import { NotFound, StreamCode, StreamError, toStreamCode } from "./error.js";
10
+ import { isAnonymous } from "./hop.js";
11
+ import * as Identity from "./identity.js";
2
12
  import * as Path from "./path.js";
13
+ import { max, min, UNBOUNDED } from "./util/key.js";
14
+ import * as Varint from "./varint.js";
15
+ /** A null {@link Live.max} in milliseconds, which the model holds as the largest value every peer can read. */
16
+ export const NO_MAX_DELAY = Varint.MAX_U53;
17
+ /** A datagram track's properties as the stream track info a wire answers with: no groups, so no age, refresh, or compression. */
18
+ export function datagramTrackInfo(info) {
19
+ return {
20
+ compression: "none",
21
+ timescale: info.timescale,
22
+ maxAge: null,
23
+ priority: info.priority,
24
+ refresh: { ratio: null, interval: null },
25
+ };
26
+ }
27
+ /**
28
+ * `value` rounded up to a whole millisecond, as the wire carries it: callers derive one from
29
+ * measurements (a jitter estimate scaled off RTT), and a budget shortened by rounding skips a group
30
+ * the subscriber still wants. Refused past the safe integer range, naming `field`.
31
+ */
32
+ export function wireMillis(field, value) {
33
+ const millis = Math.ceil(value.asMillis());
34
+ if (!Number.isSafeInteger(millis)) {
35
+ throw new RangeError(`${field} exceeds the safe integer millisecond range: ${value}`);
36
+ }
37
+ return Duration.millis(millis);
38
+ }
3
39
  /** Normalize public group bounds into an inclusive start and exclusive end. */
4
40
  export function groupBounds(groups = {}) {
5
41
  const bound = (value, start) => {
@@ -8,20 +44,13 @@ export function groupBounds(groups = {}) {
8
44
  if ((value.included === undefined) === (value.excluded === undefined)) {
9
45
  throw new Error("a group bound must be either included or excluded");
10
46
  }
11
- const sequence = value.included ?? value.excluded;
12
- if (sequence === undefined || !Number.isSafeInteger(sequence) || sequence < 0) {
13
- throw new Error("a group bound must be a non-negative safe integer");
47
+ const key = value.included ?? value.excluded;
48
+ if (typeof key !== "bigint" || key < 0n) {
49
+ throw new Error("a group bound must be a non-negative bigint");
14
50
  }
15
- return sequence + (start ? Number(value.excluded !== undefined) : Number(value.included !== undefined));
51
+ return key + ((start ? value.excluded !== undefined : value.included !== undefined) ? 1n : 0n);
16
52
  };
17
- return { start: bound(groups.start, true) ?? 0, end: bound(groups.end, false) };
18
- }
19
- /**
20
- * The announce-interest prefix a scope needs on a prefix-shaped wire: its literal head.
21
- * The peer echoes every suffix beneath it, and the caller filters what arrives.
22
- */
23
- export function scopeHead(scope) {
24
- return Path.from(scope.head);
53
+ return { start: bound(groups.start, true) ?? 0n, end: bound(groups.end, false) };
25
54
  }
26
55
  /**
27
56
  * Whether a segment of `path` below `prefix` starts with `.`, which hides it from announce
@@ -34,83 +63,531 @@ export function hiddenBelow(prefix, path) {
34
63
  /**
35
64
  * Where each carried route lands under the requested prefix: its suffix beneath the
36
65
  * prefix, or the empty suffix for a route above it, where the most specific such route
37
- * wins the way a request through the prefix would resolve.
66
+ * wins the way a request through the prefix would resolve. Only a candidate `shows` admits
67
+ * at the path it lands on competes.
38
68
  */
39
- export function presented(prefix, table, carries) {
69
+ export function presented(prefix, table, carries, options = {}) {
70
+ const { root = Path.empty(), keepAbove = false, shows = () => true } = options;
40
71
  const out = new Map();
41
- let rootLen = -1;
42
- const requested = Path.Pattern.subtree(prefix);
72
+ // Hashed on the absolute path requested, as a request for it resolves. A prefix that is
73
+ // valid alone but too deep under the root can name no broadcast, so nothing lands on it.
74
+ // The wire also counts escaped `/`s while the previous release lives, which a request checks.
75
+ const at = Path.tryJoin(root, prefix);
76
+ if (at === undefined || Path.check(at) !== undefined)
77
+ return out;
78
+ // Every claim covering the prefix, as a request through the prefix resolves: the most specific
79
+ // tier, ranked across the prefixes its claims are filed at, each by its absolute filing.
80
+ const covering = [];
43
81
  for (const [covered, candidates] of table) {
44
82
  if (!carries(covered))
45
83
  continue;
46
84
  if (Path.hasPrefix(covered, prefix)) {
47
- if (covered.length < rootLen)
48
- continue;
49
- // A scoped route covers only what it claims, so the best one that can serve the prefix wins.
50
- const snap = candidates.find((candidate) => !candidate.claim || candidate.claim.overlaps(requested));
51
- if (!snap)
52
- continue;
53
- rootLen = covered.length;
54
- out.set(Path.empty(), snap);
85
+ const depth = Path.parts(covered).length;
86
+ candidates.forEach((candidate, order) => {
87
+ if (!shows(candidate, prefix))
88
+ return;
89
+ // Hold the empty suffix's place in the order the table lists its first claim.
90
+ if (covering.length === 0)
91
+ out.set(Path.empty(), candidate);
92
+ covering.push({
93
+ prefix: candidate.filed ?? Path.join(root, covered),
94
+ depth,
95
+ order: candidate.order ?? order,
96
+ arrival: arrival(candidate.ref),
97
+ candidate,
98
+ route: candidate.route,
99
+ });
100
+ });
55
101
  continue;
56
102
  }
57
103
  const suffix = Path.stripPrefix(prefix, covered);
58
- if (suffix !== null && candidates.length > 0)
59
- out.set(suffix, candidates[0]);
104
+ const best = suffix !== null ? firstEligible(candidates, (candidate) => shows(candidate, covered)) : undefined;
105
+ if (suffix !== null && best)
106
+ out.set(suffix, best);
107
+ }
108
+ // A broadcast published above the requested path serves only its own, so a tier-mate that
109
+ // serves the path ranks ahead of it.
110
+ const best = bestOfTier(at, covering, { serves: (entry) => !entry.candidate.exact || entry.prefix === at });
111
+ if (best) {
112
+ const snap = best.candidate;
113
+ const above = BigInt(Path.parts(prefix).length - best.depth);
114
+ out.set(Path.empty(), keepAbove && above > 0n
115
+ ? { ...snap, route: { ...snap.route, above: (snap.route.above ?? 0n) + above } }
116
+ : snap);
117
+ }
118
+ return out;
119
+ }
120
+ // When each advertisement's ref was first received, across every filing.
121
+ const receipts = new WeakMap();
122
+ let nextReceipt = 0;
123
+ /** Records `ref` as received now, as each announce of a claim is: it ranks as the newest. */
124
+ export function receive(ref) {
125
+ receipts.set(ref, nextReceipt++);
126
+ }
127
+ /**
128
+ * The order `ref` was last {@link receive}d in, stamped now if it never was: a later one is
129
+ * larger, so a full tie across filings goes to the most recently received claim, as Rust's newest
130
+ * route entry. An update keeps its ref's place.
131
+ */
132
+ export function arrival(ref) {
133
+ let order = receipts.get(ref);
134
+ if (order === undefined) {
135
+ order = nextReceipt++;
136
+ receipts.set(ref, order);
137
+ }
138
+ return order;
139
+ }
140
+ /**
141
+ * The best of the most specific claims among `filed`, which all cover `path`: a claim shown above
142
+ * its own prefix counts for the shallower prefix it is really at, and claims of one prefix rank
143
+ * against each other wherever each is filed. Only an identity's highest epoch among them (and
144
+ * `others`, of the same claim when `exact`) is eligible; one that `serves` `path` ranks ahead, then
145
+ * {@link compareTier}, then {@link compareTie}. Mirrors `RouteTable::best_route` in rs/moq-net,
146
+ * and with `serves`, `TableCursor::best`.
147
+ */
148
+ export function bestOfTier(path, filed, options = {}) {
149
+ const { others = () => [], serves = () => true } = options;
150
+ const specificity = (entry) => entry.depth - Number(entry.route.above ?? 0n);
151
+ // A loop, not a spread: a table may hold more candidates than a call takes arguments.
152
+ let most = Number.NEGATIVE_INFINITY;
153
+ for (const entry of filed)
154
+ most = Math.max(most, specificity(entry));
155
+ const tier = filed.filter((entry) => specificity(entry) === most);
156
+ // One claim prefix: an identity's epochs compare across the whole tier.
157
+ const epochs = new Epochs([...tier.map((entry) => entry.route), ...others(most)], () => 0n);
158
+ let best;
159
+ for (const entry of tier) {
160
+ if (epochs.supersedes(entry.route))
161
+ continue;
162
+ if (best === undefined) {
163
+ best = entry;
164
+ continue;
165
+ }
166
+ const serving = Number(serves(best)) - Number(serves(entry));
167
+ if ((serving || compareTier(path, entry, best) || compareTie(path, entry, best)) < 0)
168
+ best = entry;
169
+ }
170
+ return best;
171
+ }
172
+ /**
173
+ * How a full tie between two claims of one tier resolving `path` breaks: to the newest, by each
174
+ * prefix's own order and across prefixes the most recently {@link arrival}, as Rust's final
175
+ * `Reverse(entry.id)`, so a publisher that restarts under a new identity takes over at once. Filed
176
+ * beneath `path` where neither is a lite-07 claim, it goes to the oldest instead, as Rust's
177
+ * `RouteEntry::since`: switching there would restart the route at every relay downstream that
178
+ * ranks it alike. Rust also renews `since` when a re-price changes the rank; this origin forwards
179
+ * no route it received, so a route that dips and recovers here restarts only its own readers.
180
+ * Then the deeper filing.
181
+ */
182
+ export function compareTie(path, a, b) {
183
+ const newest = a.prefix === b.prefix ? a.order - b.order : b.arrival - a.arrival;
184
+ const holds = a.prefix !== path && b.prefix !== path && !a.route.claimed && !b.route.claimed;
185
+ return (holds ? -newest : newest) || b.depth - a.depth;
186
+ }
187
+ /**
188
+ * The first of `candidates`, most preferred first, that `admits` and that no other admitted
189
+ * candidate supersedes. Supersession is decided among what the reader may see, so a higher epoch
190
+ * it cannot see never hides a route it can.
191
+ */
192
+ export function firstEligible(candidates, admits = () => true) {
193
+ const admitted = candidates.filter(admits);
194
+ const epochs = new Epochs(admitted.map((candidate) => candidate.route));
195
+ return admitted.find((candidate) => !epochs.supersedes(candidate.route));
196
+ }
197
+ /**
198
+ * What of `path`'s subtree every one of `scopes` serves: undefined when all of it, and otherwise
199
+ * the prefixes beneath `path` that all of them share, possibly none. Asked about a path rather
200
+ * than a {@link Path.Prefix}, so a path no prefix can spell still gets an answer.
201
+ */
202
+ export function within(path, scopes) {
203
+ let out;
204
+ for (const scope of scopes) {
205
+ if (!scope || scope.matches(path))
206
+ continue;
207
+ const beneath = new Path.Prefixes(scope.toArray().filter((member) => Path.hasPrefix(path, member.text)));
208
+ out = out ? out.intersect(beneath) : beneath;
60
209
  }
61
210
  return out;
62
211
  }
63
- /** Whether the announced prefix's subtree overlaps `scope`. */
64
- export function scopeOverlaps(scope, prefix) {
65
- return scope.overlaps(Path.Pattern.subtree(prefix));
66
- }
67
- /** What `scope` captures from an exact announced prefix, if it pins every wildcard. */
68
- export function scopeCaptures(scope, prefix) {
69
- return scope.captures(Path.Pattern.literal(prefix));
70
- }
71
- /** Hooks assigned in static blocks by the owning class. */
72
- export const hooks = {
73
- makeRequest: () => {
74
- throw new Error("track.ts not loaded");
75
- },
76
- pendingTrackProducer: () => {
77
- throw new Error("track.ts not loaded");
78
- },
79
- tryRecvGroup: () => {
80
- throw new Error("track.ts not loaded");
81
- },
82
- groupChanged: () => {
83
- throw new Error("track.ts not loaded");
84
- },
85
- exemptFetch: () => {
86
- throw new Error("track.ts not loaded");
87
- },
88
- replaceGroups: () => {
89
- throw new Error("track.ts not loaded");
90
- },
91
- groupTimestamp: () => {
92
- throw new Error("group.ts not loaded");
93
- },
94
- groupLatest: () => {
95
- throw new Error("group.ts not loaded");
96
- },
97
- expireGroup: () => {
98
- throw new Error("group.ts not loaded");
99
- },
100
- guardGroup: () => {
101
- throw new Error("group.ts not loaded");
102
- },
103
- readGroupFrame: () => {
104
- throw new Error("group.ts not loaded");
105
- },
106
- evictGroup: () => {
107
- throw new Error("group.ts not loaded");
108
- },
109
- attachAnnouncer: () => {
110
- throw new Error("broadcast.ts not loaded");
111
- },
112
- stampPath: () => {
113
- throw new Error("broadcast.ts not loaded");
114
- },
115
- };
212
+ /** Add `[start, end)` to sorted, disjoint, non-adjacent `runs`, merging every run it touches. */
213
+ export function insertRun(runs, start, end) {
214
+ if (start >= end)
215
+ return;
216
+ // Merging a run it touches, so the first that ends at or past `start`.
217
+ const first = runsFrom(runs, start - 1n);
218
+ let last = first;
219
+ while (last < runs.length && runs[last].start <= end)
220
+ last++;
221
+ const merged = first === last ? { start, end } : { start: min(start, runs[first].start), end: max(end, runs[last - 1].end) };
222
+ runs.splice(first, last - first, merged);
223
+ }
224
+ /** The sorted, disjoint `runs` with `[start, end)` taken out, each part keeping its run's fields. */
225
+ export function removeRun(runs, start, end) {
226
+ return runs.flatMap((run) => [
227
+ { ...run, start: run.start, end: min(run.end, start) },
228
+ { ...run, start: max(run.start, end), end: run.end },
229
+ ].filter((part) => part.start < part.end));
230
+ }
231
+ /** Take `[start, end)` out of sorted, disjoint `runs` in place, each part keeping its run's fields. */
232
+ export function cutRun(runs, start, end) {
233
+ if (start >= end)
234
+ return;
235
+ const from = runsFrom(runs, start);
236
+ let to = from;
237
+ while (to < runs.length && runs[to].start < end)
238
+ to++;
239
+ if (from === to)
240
+ return;
241
+ const parts = [];
242
+ if (runs[from].start < start)
243
+ parts.push({ ...runs[from], end: start });
244
+ if (runs[to - 1].end > end)
245
+ parts.push({ ...runs[to - 1], start: end });
246
+ runs.splice(from, to - from, ...parts);
247
+ }
248
+ /** A key never produced; see {@link Hole}. */
249
+ export function skipHole() {
250
+ return { reason: "skip" };
251
+ }
252
+ /** A key not found, which a later fill or failover may still find; see {@link Hole}. */
253
+ export function dropHole() {
254
+ return { reason: "drop" };
255
+ }
256
+ /** A group judged stale under `budget` milliseconds, within the exclusive group end `cap` when it has one. */
257
+ export function staleHole(budget, cap) {
258
+ return { reason: "old", maxAge: budget, cap };
259
+ }
260
+ /**
261
+ * The verdict a reader's own refusal or failure with `error` reaches: `old` for a superseded
262
+ * group, `skip` for one never produced, else not found. Mirrors the Rust `Hole::missed`.
263
+ */
264
+ export function holeOf(error) {
265
+ switch (toStreamCode(error)) {
266
+ case StreamCode.Old:
267
+ return { reason: "old" };
268
+ case StreamCode.Skip:
269
+ return skipHole();
270
+ default:
271
+ return dropHole();
272
+ }
273
+ }
274
+ /** The error a reader waiting on a key given up as `hole` ends with: a key never produced is simply not found. */
275
+ export function holeError(hole) {
276
+ switch (hole.reason) {
277
+ case "skip":
278
+ return new StreamError(StreamCode.NotFound, { message: "group never produced" });
279
+ case "drop":
280
+ return new NotFound("group");
281
+ case "old":
282
+ return new StreamError(StreamCode.Old, { message: "group is past the budget" });
283
+ }
284
+ }
285
+ /**
286
+ * Whether `run` settles a reader judging under `budget` with `coverage`. Any run but a received
287
+ * stale one does. A stale verdict holds for a reader no wider than the budget it was judged under
288
+ * that reads every group above the run's start: its own successor and edge are then no older than
289
+ * those the verdict was judged against, since a group's verdict looks only above it. An uncapped
290
+ * reader reads them past the live edge; a capped one only when the upstream judged within the very
291
+ * cap it has (`run.cap`), else the verdict may rest on groups above the cap it never sees. A reader
292
+ * whose budget varies by group is held to its widest. Mirrors the Rust `settles`.
293
+ */
294
+ export function settles(run, budget, coverage) {
295
+ if (run.maxAge === undefined)
296
+ return true;
297
+ if ((budget.isUniform() ? budget.at(run.start) : budget.widest()) > run.maxAge)
298
+ return false;
299
+ if (coverage === undefined)
300
+ return false;
301
+ const { cap } = coverage;
302
+ if (cap !== undefined && run.cap !== cap)
303
+ return false;
304
+ const above = run.start + 1n;
305
+ const end = cap ?? UNBOUNDED;
306
+ if (above >= end)
307
+ return true;
308
+ const held = coverage.runs.find((run) => run.start <= above && above < run.end);
309
+ return held !== undefined && held.end >= end;
310
+ }
311
+ /** Whether two runs say the same thing, so they may merge. */
312
+ export function sameHole(a, b) {
313
+ return (a.reason === b.reason &&
314
+ a.maxAge === b.maxAge &&
315
+ a.cap === b.cap &&
316
+ a.refusal === b.refusal &&
317
+ !a.received === !b.received &&
318
+ !a.own === !b.own);
319
+ }
320
+ /**
321
+ * Sorted, disjoint `drops` with `[start, end)` given up as `hole` says, which replaces whatever
322
+ * it overlaps. Neighbours given up alike merge, so a wide DROP stays one run and a peer naming
323
+ * one key per DROP cannot grow the runs.
324
+ */
325
+ export function insertDrop(drops, start, end, hole) {
326
+ if (start >= end)
327
+ return [...drops];
328
+ const next = removeRun(drops, start, end);
329
+ let at = 0;
330
+ while (at < next.length && next[at].start < start)
331
+ at++;
332
+ next.splice(at, 0, {
333
+ start,
334
+ end,
335
+ reason: hole.reason,
336
+ maxAge: hole.maxAge,
337
+ cap: hole.cap,
338
+ received: hole.received,
339
+ own: hole.own,
340
+ refusal: hole.refusal,
341
+ });
342
+ const merged = [];
343
+ for (const run of next) {
344
+ const last = merged[merged.length - 1];
345
+ if (last && last.end === run.start && sameHole(last, run))
346
+ last.end = run.end;
347
+ else
348
+ merged.push({ ...run });
349
+ }
350
+ return merged;
351
+ }
352
+ /**
353
+ * The parts of sorted, disjoint `runs` that sorted, disjoint `cut` leaves, each keeping its run's
354
+ * fields, as {@link removeRun} of each cut would, in one pass.
355
+ */
356
+ export function subtractRuns(runs, cut) {
357
+ const kept = [];
358
+ let first = 0;
359
+ for (const run of runs) {
360
+ while (first < cut.length && cut[first].end <= run.start)
361
+ first++;
362
+ let from = run.start;
363
+ for (let i = first; i < cut.length && cut[i].start < run.end; i++) {
364
+ if (cut[i].start > from)
365
+ kept.push({ ...run, start: from, end: cut[i].start });
366
+ from = max(from, cut[i].end);
367
+ }
368
+ if (from < run.end)
369
+ kept.push({ ...run, start: from, end: run.end });
370
+ }
371
+ return kept;
372
+ }
373
+ /**
374
+ * `drops` with each of the sorted, disjoint `runs` inserted as {@link insertDrop} inserts it, in
375
+ * one pass: folding in a span of many runs costs the runs, not their square.
376
+ */
377
+ export function insertDrops(drops, runs) {
378
+ if (runs.length === 0)
379
+ return [...drops];
380
+ const next = subtractRuns(drops, runs);
381
+ // Appended one by one: a peer controls how many runs there are, past any argument limit.
382
+ for (const run of runs)
383
+ next.push(run);
384
+ next.sort((a, b) => (a.start < b.start ? -1 : a.start > b.start ? 1 : 0));
385
+ const merged = [];
386
+ for (const run of next) {
387
+ const last = merged[merged.length - 1];
388
+ if (last && last.end === run.start && sameHole(last, run))
389
+ last.end = run.end;
390
+ else
391
+ merged.push({ ...run });
392
+ }
393
+ return merged;
394
+ }
395
+ /** The run of `drops` giving `key` up, if any. */
396
+ export function dropAt(drops, key) {
397
+ return drops.find((run) => run.start <= key && key < run.end);
398
+ }
399
+ /** The index of the first of sorted, disjoint `runs` ending past `key`. */
400
+ export function runsFrom(runs, key) {
401
+ let lo = 0;
402
+ let hi = runs.length;
403
+ while (lo < hi) {
404
+ const mid = (lo + hi) >>> 1;
405
+ if (runs[mid].end <= key)
406
+ lo = mid + 1;
407
+ else
408
+ hi = mid;
409
+ }
410
+ return lo;
411
+ }
412
+ /** The parts of `[start, end)` that sorted, disjoint `runs` do not cover, in order. */
413
+ export function runGaps(runs, start, end) {
414
+ const gaps = [];
415
+ let next = start;
416
+ for (let i = runsFrom(runs, start); i < runs.length; i++) {
417
+ const run = runs[i];
418
+ if (next >= end)
419
+ break;
420
+ if (run.start > next)
421
+ gaps.push({ start: next, end: min(run.start, end) });
422
+ next = max(next, run.end);
423
+ }
424
+ if (next < end)
425
+ gaps.push({ start: next, end });
426
+ return gaps;
427
+ }
428
+ /** The first group an exclusive track end excludes whole: one past the last group that may exist. */
429
+ export function finalKey(end) {
430
+ return end.group + (end.frame === 0 ? 0n : 1n);
431
+ }
432
+ /** Filled in by each owning module as it loads. */
433
+ export const hooks = {};
434
+ /** The Spread Hash's offset basis, which lite-06 and earlier rank by. */
435
+ const SPREAD_BASIS = 0x420c0decb00bn;
436
+ /** FNV-1a 64 from `basis` of `path`, then `bytes`. */
437
+ function fnv(path, bytes, basis = SPREAD_BASIS) {
438
+ const prime = 0x100000001b3n;
439
+ let hash = basis;
440
+ for (const byte of new TextEncoder().encode(path)) {
441
+ hash = BigInt.asUintN(64, (hash ^ BigInt(byte)) * prime);
442
+ }
443
+ for (const byte of bytes) {
444
+ hash = BigInt.asUintN(64, (hash ^ BigInt(byte)) * prime);
445
+ }
446
+ return hash;
447
+ }
448
+ /**
449
+ * Spreads a pool's identities across paths: FNV-1a 64 of `path` then the identity's UTF-8.
450
+ * Keyed on the requested path so a pool advertising one prefix shares its paths, and every
451
+ * node agrees, since the identity reads the same everywhere. Mirrors `identity_key` in
452
+ * `rs/moq-net`.
453
+ */
454
+ export function spreadHash(path, identity) {
455
+ return fnv(path, new TextEncoder().encode(identity));
456
+ }
457
+ /**
458
+ * The draft's Rendezvous Hash: standard FNV-1a 64 of `path` then the identity's UTF-8, which
459
+ * spreads a pool's lite-07 claims across paths the same on every node. Mirrors `rendezvous` in
460
+ * `rs/moq-net`.
461
+ */
462
+ function rendezvousHash(path, identity) {
463
+ return fnv(path, new TextEncoder().encode(identity), 0xcbf29ce484222325n);
464
+ }
465
+ /**
466
+ * The best claim covering `path`, as `RouteTable::best_route` in rs/moq-net picks it: only the
467
+ * most specific claims compete, a claim shown above its own prefix counting for the shallower
468
+ * prefix it is really at, and they rank against each other wherever each is filed. Of those, only
469
+ * an identity's highest epoch is eligible, an exact claim's `others` (which never win) included,
470
+ * and the rest order by {@link compareTier}, then {@link compareTie}: a claim is new when it
471
+ * starts or restarts (another identity or epoch), and keeps its place through a re-price.
472
+ * `candidates` lists each
473
+ * covering prefix's, newest first, and `advertised` names each one's ref and route. Every
474
+ * selector ranks through this, so the announcements and the consumes of one session never pick
475
+ * apart.
476
+ */
477
+ export function mostSpecific(path, candidates, advertised, others = []) {
478
+ const filed = [];
479
+ let depth = Path.parts(path).length;
480
+ const exact = depth;
481
+ for (const prefix of coveringPrefixes(path)) {
482
+ let order = 0;
483
+ for (const candidate of candidates(prefix)) {
484
+ const { ref, route } = advertised(candidate);
485
+ filed.push({ prefix, depth, order: order++, arrival: arrival(ref), candidate, route });
486
+ }
487
+ depth--;
488
+ }
489
+ return bestOfTier(path, filed, { others: (specificity) => (specificity === exact ? others : []) })?.candidate;
490
+ }
491
+ /** Covering prefixes, most specific first, including the empty root. */
492
+ export function* coveringPrefixes(path) {
493
+ const segments = Path.parts(path);
494
+ let end = path.length;
495
+ for (let i = segments.length;; i--) {
496
+ yield path.slice(0, end);
497
+ if (i === 0)
498
+ return;
499
+ // Drop the last segment and the `/` before it, if any.
500
+ end = Math.max(end - segments[i - 1].length - 1, 0);
501
+ }
502
+ }
503
+ /**
504
+ * Whether `route` at `prefix` is superseded among `others`: one of them carries its identity at
505
+ * a higher epoch at the same prefix. An older incarnation of an identity is never eligible,
506
+ * however cheap, since its publisher was replaced.
507
+ */
508
+ export function superseded(route, others) {
509
+ return new Epochs(others).supersedes(route);
510
+ }
511
+ /**
512
+ * The highest epoch each identity reaches among a set of routes, per claim: a claim is its prefix
513
+ * and how far above it was shown, so a broader claim shown at a prefix is another claim than the
514
+ * one made there, and its epoch supersedes nothing of it. Built in one pass so ranking N routes
515
+ * stays linear. Only epochs above 0 are kept, since nothing is below 0: the common case, where
516
+ * every identity announces epoch 0, stores nothing. Mirrors `Epochs` in rs/moq-net, whose routes
517
+ * are all of one prefix here.
518
+ */
519
+ class Epochs {
520
+ #highest = new Map();
521
+ #claim;
522
+ /** `claim` names each route's claim among `routes`: its Above, for routes all of one prefix. */
523
+ constructor(routes, claim = (route) => route.above ?? 0n) {
524
+ this.#claim = claim;
525
+ for (const route of routes) {
526
+ const epoch = route.epoch ?? 0n;
527
+ if (epoch === 0n)
528
+ continue;
529
+ let claims = this.#highest.get(route.identity);
530
+ if (!claims) {
531
+ claims = new Map();
532
+ this.#highest.set(route.identity, claims);
533
+ }
534
+ const highest = claims.get(claim(route));
535
+ if (highest === undefined || epoch > highest)
536
+ claims.set(claim(route), epoch);
537
+ }
538
+ }
539
+ /** Whether a route carries `route`'s identity at a higher epoch on the same claim. */
540
+ supersedes(route) {
541
+ const highest = this.#highest.get(route.identity)?.get(this.#claim(route));
542
+ return highest !== undefined && highest > (route.epoch ?? 0n);
543
+ }
544
+ }
545
+ /**
546
+ * Prefer a route that is available (not held), then one that is not draining (a peer that sent
547
+ * GOAWAY), which still reaches its origin, then the highest priority on its path, then identified
548
+ * publishers, then lower static cost.
549
+ */
550
+ export function compareRoutes(a, b) {
551
+ const held = (route) => Number(route.available === false);
552
+ const draining = (route) => Number(route.draining ?? false);
553
+ return (held(a) - held(b) ||
554
+ draining(a) - draining(b) ||
555
+ (b.priority ?? 0) - (a.priority ?? 0) ||
556
+ Number(isAnonymous(a)) - Number(isAnonymous(b)) ||
557
+ (a.cost < b.cost ? -1 : a.cost > b.cost ? 1 : 0));
558
+ }
559
+ /**
560
+ * Order two claims of one tier resolving `path`, each filed at its `prefix`: by preference, hop
561
+ * count, then one filed at `path` itself, then, keyed on `path` whatever each claim's filing, the
562
+ * rendezvous hash of a lite-07 claim's identity or the spread hash of a named one. The hashes only
563
+ * spread a pool over a prefix's paths, as `route_order` in rs/moq-net does. Any other tie breaks by
564
+ * {@link compareTie}.
565
+ */
566
+ export function compareTier(path, a, b) {
567
+ const order = compareRoutes(a.route, b.route) || routeHops(a.route) - routeHops(b.route);
568
+ if (order !== 0)
569
+ return order;
570
+ // A claim filed at the path itself skips the hash and ranks first, as a route entered here at
571
+ // the path does in Rust; two of them tie, for the newest to win.
572
+ const exact = Number(b.prefix === path) - Number(a.prefix === path);
573
+ if (exact !== 0 || a.prefix === path)
574
+ return exact;
575
+ const [ka, kb] = [routeKey(path, a.route), routeKey(path, b.route)];
576
+ return ka < kb ? -1 : ka > kb ? 1 : 0;
577
+ }
578
+ /** The hops a route ranks by: a lite-07 claim counts as the one hop to the peer that sent it. */
579
+ export function routeHops(route) {
580
+ return route.claimed ? 1 : route.hops.length;
581
+ }
582
+ /** The hash a route ranks by beneath its prefix, each route keyed on its own: a lite-07 claim by
583
+ * the rendezvous hash of its identity, a named identity by its spread hash, and one a session
584
+ * minted by none, since no other node shares it. As `route_order` in rs/moq-net. */
585
+ function routeKey(path, route) {
586
+ const identity = route.identity;
587
+ if (route.claimed)
588
+ return rendezvousHash(path, identity ? Identity.text(identity) : "");
589
+ if (identity !== undefined && Identity.isMinted(identity))
590
+ return 0n;
591
+ return spreadHash(path, identity ? Identity.text(identity) : "");
592
+ }
116
593
  //# sourceMappingURL=internal.js.map