@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/lite/answer.js ADDED
@@ -0,0 +1,301 @@
1
+ // Lite-07: what this session sends on its Announce Stream as a publisher, answering the prefixes
2
+ // the peer asks for from this origin's own claims.
3
+ //
4
+ // A browser forwards nothing and declares no Node ID, so it sends claims and never routes: one
5
+ // per broadcast the peer is shown, at no cost. The peer edits its prefixes in place: each edit
6
+ // takes effect at the ANNOUNCE_OK answering it, where both ends drop every claim within a prefix
7
+ // it removed, and the answer then tells what the added prefixes cover.
8
+ //
9
+ // A prefix wider than our grant is answered region by region, as if the peer had asked for each
10
+ // granted region inside it: a claim above a region is presented at the region. A claim is shown
11
+ // where the grant covers some path beneath it. A grant change is answered before the ANNOUNCE_OK of
12
+ // the next edit.
13
+ import { race } from "@moq/signals";
14
+ import { ProtocolViolation } from "../error.js";
15
+ import { coveringPrefixes, hiddenBelow, presented, within } from "../internal.js";
16
+ import * as Path from "../path.js";
17
+ import { sameIdentity } from "../wire.js";
18
+ import { claimsEqual, ownClaim, requestFits } from "./announce.js";
19
+ /** Answers the prefixes a lite-07 peer asks for. @internal */
20
+ export class Answer {
21
+ #publish;
22
+ /** The prefixes in effect, by Prefix ID. */
23
+ #prefixes = new Map();
24
+ #nextPrefix = 0n;
25
+ /** The peer's edit not answered yet. */
26
+ #request;
27
+ /** The ANNOUNCE_REQUESTs of an edit that continues: its removes and its adds so far. */
28
+ #parts;
29
+ /** The claims the peer holds, by their path from the session's root. */
30
+ #live = new Map();
31
+ #nextAnnounce = 0n;
32
+ /** The session is leaving: nothing more is sent. */
33
+ #withdrawn = false;
34
+ #closed = false;
35
+ // Anything that may change what the peer is owed marks the answer dirty and wakes the loop,
36
+ // which alone writes. A change landing mid-sync leaves it dirty for the next pass.
37
+ #dirty = true;
38
+ #notify;
39
+ #running;
40
+ constructor(publish) {
41
+ this.#publish = publish;
42
+ }
43
+ #poke() {
44
+ this.#dirty = true;
45
+ this.#notify?.();
46
+ }
47
+ /** Whether the peer's edit continues in its next message, which must be its next ANNOUNCE_REQUEST. */
48
+ continuing() {
49
+ return this.#parts !== undefined;
50
+ }
51
+ /**
52
+ * ANNOUNCE_REQUEST: the peer edits the prefixes it asks for, over as many messages as `more`
53
+ * says. Returns the loop answering it, started by the first request and running until the
54
+ * session leaves.
55
+ */
56
+ request(more, remove, add) {
57
+ this.#running ??= this.#run();
58
+ if (this.#withdrawn || this.#closed)
59
+ return this.#running;
60
+ // One edit at a time, so a peer that never reads its answers leaves one here beside the
61
+ // one being answered.
62
+ if (this.#request)
63
+ throw new ProtocolViolation("ANNOUNCE_REQUEST before the last was answered");
64
+ if (this.#parts) {
65
+ remove = [...this.#parts.remove, ...remove];
66
+ add = [...this.#parts.add, ...add];
67
+ this.#parts = undefined;
68
+ }
69
+ const left = new Map(this.#prefixes);
70
+ // Parts that could never make a valid edit fail before more of them pile up: their Adds
71
+ // alone already pass the set's limit, or they remove more than the set holds.
72
+ if (remove.length > left.size ||
73
+ !requestFits(add.map(({ prefix }) => prefix), this.#publish.version))
74
+ throw new ProtocolViolation("ANNOUNCE_REQUEST parts past the limit");
75
+ if (more) {
76
+ this.#parts = { remove, add };
77
+ return this.#running;
78
+ }
79
+ for (const id of remove) {
80
+ if (!left.delete(id))
81
+ throw new ProtocolViolation(`ANNOUNCE_REQUEST removes unknown Prefix ID ${id}`);
82
+ }
83
+ const set = new Set();
84
+ for (const prefix of left.values())
85
+ set.add(prefix.path);
86
+ for (const { prefix } of add) {
87
+ if (set.has(prefix))
88
+ throw new ProtocolViolation(`ANNOUNCE_REQUEST adds ${prefix} twice`);
89
+ set.add(prefix);
90
+ }
91
+ // No prefix in the set lies below another, and the whole set fits one message.
92
+ for (const prefix of set) {
93
+ for (const above of coveringPrefixes(prefix)) {
94
+ if (above !== prefix && set.has(above))
95
+ throw new ProtocolViolation(`ANNOUNCE_REQUEST nests ${prefix} below ${above}`);
96
+ }
97
+ }
98
+ if (!requestFits(set, this.#publish.version))
99
+ throw new ProtocolViolation("ANNOUNCE_REQUEST set too large");
100
+ // Each added prefix takes the next Prefix ID, in the order the edit names them.
101
+ const added = add.map(({ prefix, hidden }) => [this.#nextPrefix++, { path: prefix, hidden }]);
102
+ this.#request = { remove, add: added };
103
+ this.#notify?.();
104
+ return this.#running;
105
+ }
106
+ /** The session ended: stop answering. */
107
+ close() {
108
+ this.#closed = true;
109
+ this.#notify?.();
110
+ }
111
+ async #run() {
112
+ const { advertised, grant, closing, ready } = this.#publish;
113
+ // Woken by the origin's claims or our grant.
114
+ const stops = [advertised, grant].map((source) => source?.subscribe(() => this.#poke()));
115
+ try {
116
+ const settled = ready.then(() => "ready");
117
+ if ((await race([settled, closing])) !== "ready")
118
+ return;
119
+ for (;;) {
120
+ if (this.#closed)
121
+ return;
122
+ // The session is leaving: finishing the stream ends everything the peer was sent.
123
+ if (closing.peek()) {
124
+ this.#withdrawn = true;
125
+ this.#live.clear();
126
+ return;
127
+ }
128
+ const request = this.#request;
129
+ if (request) {
130
+ await this.#edit(request);
131
+ continue;
132
+ }
133
+ if (this.#dirty) {
134
+ await this.#sync();
135
+ continue;
136
+ }
137
+ const woke = new Promise((resolve) => {
138
+ this.#notify = resolve;
139
+ });
140
+ await race([woke, closing]);
141
+ this.#notify = undefined;
142
+ }
143
+ }
144
+ finally {
145
+ for (const stop of stops)
146
+ stop?.();
147
+ }
148
+ }
149
+ // Put the peer's request in effect: answer it, drop what the removed prefixes covered, tell
150
+ // what the added ones cover, and close each added prefix's initial set.
151
+ async #edit(request) {
152
+ // A grant change the peer may have seen before this edit is answered before it.
153
+ if (this.#dirty)
154
+ await this.#sync();
155
+ const removed = [];
156
+ for (const id of request.remove) {
157
+ const prefix = this.#prefixes.get(id);
158
+ if (prefix)
159
+ removed.push(prefix.path);
160
+ this.#prefixes.delete(id);
161
+ }
162
+ // Both ends drop every claim the removed prefixes covered.
163
+ for (const path of [...this.#live.keys()]) {
164
+ if (removed.some((prefix) => Path.hasPrefix(prefix, path)))
165
+ this.#live.delete(path);
166
+ }
167
+ for (const [id, prefix] of request.add)
168
+ this.#prefixes.set(id, prefix);
169
+ // Held until now, so an edit sent before this answer is refused rather than checked
170
+ // against stale prefixes. Let go before the answer is written: the peer may send its
171
+ // next edit the moment it reads it, which can be before the write returns here.
172
+ this.#request = undefined;
173
+ await this.#publish.stream.send({ status: "ok" });
174
+ await this.#sync();
175
+ const synced = request.add.map(([prefix]) => ({ status: "synced", prefix }));
176
+ if (synced.length > 0)
177
+ await this.#publish.stream.send(...synced);
178
+ }
179
+ // Bring the claims the peer holds in line with the origin's.
180
+ async #sync() {
181
+ this.#dirty = false;
182
+ const msgs = this.#changes();
183
+ if (msgs.length > 0)
184
+ await this.#publish.stream.send(...msgs);
185
+ }
186
+ // How the claims the peer holds differ from what the requested prefixes show it now.
187
+ #changes() {
188
+ const { advertised, origin } = this.#publish;
189
+ const table = origin ? advertised.peek() : undefined;
190
+ const grant = this.#publish.grant?.peek();
191
+ const granted = grant && regions(grant.publish);
192
+ // The claims the peer is shown, by their path from the session's root: the table under each
193
+ // prefix, less the hidden ones it did not ask for and whatever our grant does not let us publish.
194
+ const latest = new Map();
195
+ // A claim is filed where its route serves the whole subtree, so it is shown where some path it
196
+ // covers is in the handle's scope and our grant, if any, lets us publish it, as one at `a` serves
197
+ // `a/b` though `a` itself is not granted.
198
+ const shows = (_, path) => {
199
+ const served = within(path, [origin?.allowed]);
200
+ if (!grant)
201
+ return served === undefined || served.size > 0;
202
+ if (served === undefined)
203
+ return grant.publish.overlaps(path);
204
+ return served.toArray().some((prefix) => grant.publish.overlaps(prefix.text));
205
+ };
206
+ // Whether the advertisement a claim the peer holds came from is still in the table, as when
207
+ // its presentation moved: the claim is lost to the peer rather than ended, since its publisher
208
+ // never withdrew it. Another path's advertisement of the same identity proves nothing.
209
+ // Indexed once per diff, and only when a claim leaves.
210
+ let advertisements;
211
+ const stillAdvertised = (sent) => {
212
+ if (!advertisements) {
213
+ advertisements = new Map();
214
+ for (const candidates of table?.values() ?? []) {
215
+ for (const snap of candidates) {
216
+ const identities = advertisements.get(snap.ref) ?? new Set();
217
+ identities.add(snap.route.identity);
218
+ advertisements.set(snap.ref, identities);
219
+ }
220
+ }
221
+ }
222
+ return advertisements.get(sent.snap.ref)?.has(sent.snap.route.identity) ?? false;
223
+ };
224
+ const ids = [...this.#prefixes.keys()].sort((a, b) => (a < b ? -1 : 1));
225
+ for (const id of table ? ids : []) {
226
+ const prefix = this.#prefixes.get(id);
227
+ if (!prefix || !table)
228
+ continue;
229
+ const carries = (covered) => prefix.hidden || !hiddenBelow(prefix.path, covered);
230
+ for (const read of reads(prefix.path, granted)) {
231
+ // A claim covering what is read from above keeps how many segments broader than it it is.
232
+ for (const [suffix, snap] of presented(read, table, carries, {
233
+ root: origin?.root,
234
+ keepAbove: true,
235
+ shows,
236
+ })) {
237
+ latest.set(Path.join(read, suffix), snap);
238
+ }
239
+ }
240
+ }
241
+ const msgs = [];
242
+ const end = (path, sent, lost) => {
243
+ this.#live.delete(path);
244
+ console.debug(`announce: broadcast=${path} active=false lost=${lost}`);
245
+ msgs.push({ status: "endedId", id: sent.id, lost });
246
+ };
247
+ for (const [path, sent] of [...this.#live]) {
248
+ // No longer granted, it is lost to the peer: its publisher never ended it.
249
+ if (!latest.has(path))
250
+ end(path, sent, !shows(sent.snap, path) || stillAdvertised(sent));
251
+ }
252
+ for (const [path, snap] of latest) {
253
+ const { identity, epoch, cost } = snap.route;
254
+ if (identity === undefined)
255
+ continue;
256
+ // A claim above the session's root covers all of what the peer sees, so it is no more
257
+ // above the path than the path is deep.
258
+ const depth = BigInt(Path.parts(path).length);
259
+ const above = snap.route.above ?? 0n;
260
+ const claim = { ...ownClaim(epoch ?? 0n, above < depth ? above : depth), cost };
261
+ const sent = this.#live.get(path);
262
+ if (!sent || !sameIdentity(sent.snap, snap)) {
263
+ this.#live.set(path, { id: this.#nextAnnounce++, snap, claim });
264
+ console.debug(`announce: broadcast=${path} active=true identity=${identity}`);
265
+ // Every claim's path is relative to the session, whichever prefix it answers.
266
+ msgs.push({ status: "start", suffix: path, identity, claim });
267
+ // Another identity is another claim, started before the one it replaces ends, so
268
+ // the peer sees the broadcast restart rather than go.
269
+ if (sent)
270
+ msgs.push({ status: "endedId", id: sent.id, lost: false });
271
+ }
272
+ else if (!claimsEqual(sent.claim, claim)) {
273
+ this.#live.set(path, { id: sent.id, snap, claim });
274
+ msgs.push({ status: "change", id: sent.id, claim });
275
+ }
276
+ else {
277
+ sent.snap = snap;
278
+ }
279
+ }
280
+ return msgs;
281
+ }
282
+ }
283
+ // The regions `prefixes` confine the peer to, or undefined when they allow every path: the
284
+ // prefixes themselves, already none within another. One too long or deep to be a path holds none.
285
+ // Mirrors rs/moq-net's `Permit::regions`.
286
+ function regions(prefixes) {
287
+ if (prefixes.matches(Path.empty()))
288
+ return undefined;
289
+ return prefixes
290
+ .toArray()
291
+ .map((prefix) => prefix.text)
292
+ .filter((region) => Path.check(region) === undefined);
293
+ }
294
+ // What answers the requested `prefix`: the prefix itself when a region holds it or nothing confines
295
+ // the peer, and otherwise each region inside it.
296
+ function reads(prefix, granted) {
297
+ if (!granted || granted.some((region) => Path.hasPrefix(region, prefix)))
298
+ return [prefix];
299
+ return granted.filter((region) => Path.hasPrefix(prefix, region));
300
+ }
301
+ //# sourceMappingURL=answer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer.js","sourceRoot":"","sources":["../../src/lite/answer.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,mDAAmD;AACnD,EAAE;AACF,+FAA+F;AAC/F,+FAA+F;AAC/F,iGAAiG;AACjG,uEAAuE;AACvE,EAAE;AACF,gGAAgG;AAChG,gGAAgG;AAChG,oGAAoG;AACpG,iBAAiB;AAEjB,OAAO,EAAgC,IAAI,EAAE,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,SAAS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,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAkB,CAAC;SAC1C,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC;AACxD,CAAC;AAED,oGAAoG;AACpG,iDAAiD;AACjD,SAAS,KAAK,CAAC,MAAkB,EAAE,OAAiC;IACnE,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1F,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["// Lite-07: what this session sends on its Announce Stream as a publisher, answering the prefixes\n// the peer asks for from this origin's own claims.\n//\n// A browser forwards nothing and declares no Node ID, so it sends claims and never routes: one\n// per broadcast the peer is shown, at no cost. The peer edits its prefixes in place: each edit\n// takes effect at the ANNOUNCE_OK answering it, where both ends drop every claim within a prefix\n// it removed, and the answer then tells what the added prefixes cover.\n//\n// A prefix wider than our grant is answered region by region, as if the peer had asked for each\n// granted region inside it: a claim above a region is presented at the region. A claim is shown\n// where the grant covers some path beneath it. A grant change is answered before the ANNOUNCE_OK of\n// the next edit.\n\nimport { type GetPromise, type Getter, race } from \"@moq/signals\";\nimport type { Grant } from \"../auth.ts\";\nimport { ProtocolViolation } from \"../error.ts\";\nimport type * as Identity from \"../identity.ts\";\nimport { coveringPrefixes, hiddenBelow, presented, within } from \"../internal.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Advertised, type Advertisements, type OriginConsumer, sameIdentity } from \"../wire.ts\";\nimport { type Add, type AnnounceBroadcast, type Claim, claimsEqual, ownClaim, requestFits } from \"./announce.ts\";\nimport type { AnnounceStream } from \"./announce_stream.ts\";\nimport type { Version } from \"./version.ts\";\n\n/** What the session answers its peer from. */\nexport interface Publish {\n\tversion: Version;\n\t/** The origin's claims, or undefined once it closed. */\n\tadvertised: Getter<Advertisements | undefined>;\n\t/** The origin's scope, when the session publishes one. */\n\torigin?: Pick<OriginConsumer, \"covers\" | \"allowed\" | \"root\">;\n\t/** Our grant: only what it lets us publish is announced. */\n\tgrant?: Getter<Grant | undefined>;\n\t/** Resolves once the tokens this session presented at setup are answered, so nothing is\n\t * announced before the grant it would be checked against. */\n\tready: Promise<void>;\n\t/** Settles when the session starts leaving. */\n\tclosing: GetPromise<true>;\n\tstream: AnnounceStream;\n}\n\n/** A prefix the peer asked for. */\ninterface Prefix {\n\tpath: Path.Valid;\n\thidden: boolean;\n}\n\n/** A claim the peer holds: its Announce ID, the broadcast it serves, and what it was sent. */\ninterface Sent {\n\tid: bigint;\n\tsnap: Advertised;\n\tclaim: Claim;\n}\n\n/** Answers the prefixes a lite-07 peer asks for. @internal */\nexport class Answer {\n\t#publish: Publish;\n\t/** The prefixes in effect, by Prefix ID. */\n\t#prefixes = new Map<bigint, Prefix>();\n\t#nextPrefix = 0n;\n\t/** The peer's edit not answered yet. */\n\t#request?: { remove: bigint[]; add: [bigint, Prefix][] };\n\t/** The ANNOUNCE_REQUESTs of an edit that continues: its removes and its adds so far. */\n\t#parts?: { remove: bigint[]; add: Add[] };\n\t/** The claims the peer holds, by their path from the session's root. */\n\t#live = new Map<Path.Valid, Sent>();\n\t#nextAnnounce = 0n;\n\t/** The session is leaving: nothing more is sent. */\n\t#withdrawn = false;\n\t#closed = false;\n\n\t// Anything that may change what the peer is owed marks the answer dirty and wakes the loop,\n\t// which alone writes. A change landing mid-sync leaves it dirty for the next pass.\n\t#dirty = true;\n\t#notify?: () => void;\n\t#running?: Promise<void>;\n\n\tconstructor(publish: Publish) {\n\t\tthis.#publish = publish;\n\t}\n\n\t#poke() {\n\t\tthis.#dirty = true;\n\t\tthis.#notify?.();\n\t}\n\n\t/** Whether the peer's edit continues in its next message, which must be its next ANNOUNCE_REQUEST. */\n\tcontinuing(): boolean {\n\t\treturn this.#parts !== undefined;\n\t}\n\n\t/**\n\t * ANNOUNCE_REQUEST: the peer edits the prefixes it asks for, over as many messages as `more`\n\t * says. Returns the loop answering it, started by the first request and running until the\n\t * session leaves.\n\t */\n\trequest(more: boolean, remove: bigint[], add: Add[]): Promise<void> {\n\t\tthis.#running ??= this.#run();\n\t\tif (this.#withdrawn || this.#closed) return this.#running;\n\t\t// One edit at a time, so a peer that never reads its answers leaves one here beside the\n\t\t// one being answered.\n\t\tif (this.#request) throw new ProtocolViolation(\"ANNOUNCE_REQUEST before the last was answered\");\n\t\tif (this.#parts) {\n\t\t\tremove = [...this.#parts.remove, ...remove];\n\t\t\tadd = [...this.#parts.add, ...add];\n\t\t\tthis.#parts = undefined;\n\t\t}\n\t\tconst left = new Map(this.#prefixes);\n\t\t// Parts that could never make a valid edit fail before more of them pile up: their Adds\n\t\t// alone already pass the set's limit, or they remove more than the set holds.\n\t\tif (\n\t\t\tremove.length > left.size ||\n\t\t\t!requestFits(\n\t\t\t\tadd.map(({ prefix }) => prefix),\n\t\t\t\tthis.#publish.version,\n\t\t\t)\n\t\t)\n\t\t\tthrow new ProtocolViolation(\"ANNOUNCE_REQUEST parts past the limit\");\n\t\tif (more) {\n\t\t\tthis.#parts = { remove, add };\n\t\t\treturn this.#running;\n\t\t}\n\t\tfor (const id of remove) {\n\t\t\tif (!left.delete(id)) throw new ProtocolViolation(`ANNOUNCE_REQUEST removes unknown Prefix ID ${id}`);\n\t\t}\n\t\tconst set = new Set<Path.Valid>();\n\t\tfor (const prefix of left.values()) set.add(prefix.path);\n\t\tfor (const { prefix } of add) {\n\t\t\tif (set.has(prefix)) throw new ProtocolViolation(`ANNOUNCE_REQUEST adds ${prefix} twice`);\n\t\t\tset.add(prefix);\n\t\t}\n\t\t// No prefix in the set lies below another, and the whole set fits one message.\n\t\tfor (const prefix of set) {\n\t\t\tfor (const above of coveringPrefixes(prefix)) {\n\t\t\t\tif (above !== prefix && set.has(above))\n\t\t\t\t\tthrow new ProtocolViolation(`ANNOUNCE_REQUEST nests ${prefix} below ${above}`);\n\t\t\t}\n\t\t}\n\t\tif (!requestFits(set, this.#publish.version)) throw new ProtocolViolation(\"ANNOUNCE_REQUEST set too large\");\n\t\t// Each added prefix takes the next Prefix ID, in the order the edit names them.\n\t\tconst added = add.map(({ prefix, hidden }): [bigint, Prefix] => [this.#nextPrefix++, { path: prefix, hidden }]);\n\t\tthis.#request = { remove, add: added };\n\t\tthis.#notify?.();\n\t\treturn this.#running;\n\t}\n\n\t/** The session ended: stop answering. */\n\tclose() {\n\t\tthis.#closed = true;\n\t\tthis.#notify?.();\n\t}\n\n\tasync #run(): Promise<void> {\n\t\tconst { advertised, grant, closing, ready } = this.#publish;\n\t\t// Woken by the origin's claims or our grant.\n\t\tconst stops = [advertised, grant].map((source) => source?.subscribe(() => this.#poke()));\n\t\ttry {\n\t\t\tconst settled = ready.then(() => \"ready\" as const);\n\t\t\tif ((await race([settled, closing])) !== \"ready\") return;\n\t\t\tfor (;;) {\n\t\t\t\tif (this.#closed) return;\n\t\t\t\t// The session is leaving: finishing the stream ends everything the peer was sent.\n\t\t\t\tif (closing.peek()) {\n\t\t\t\t\tthis.#withdrawn = true;\n\t\t\t\t\tthis.#live.clear();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst request = this.#request;\n\t\t\t\tif (request) {\n\t\t\t\t\tawait this.#edit(request);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (this.#dirty) {\n\t\t\t\t\tawait this.#sync();\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst woke = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.#notify = resolve;\n\t\t\t\t});\n\t\t\t\tawait race([woke, closing]);\n\t\t\t\tthis.#notify = undefined;\n\t\t\t}\n\t\t} finally {\n\t\t\tfor (const stop of stops) stop?.();\n\t\t}\n\t}\n\n\t// Put the peer's request in effect: answer it, drop what the removed prefixes covered, tell\n\t// what the added ones cover, and close each added prefix's initial set.\n\tasync #edit(request: { remove: bigint[]; add: [bigint, Prefix][] }) {\n\t\t// A grant change the peer may have seen before this edit is answered before it.\n\t\tif (this.#dirty) await this.#sync();\n\t\tconst removed: Path.Valid[] = [];\n\t\tfor (const id of request.remove) {\n\t\t\tconst prefix = this.#prefixes.get(id);\n\t\t\tif (prefix) removed.push(prefix.path);\n\t\t\tthis.#prefixes.delete(id);\n\t\t}\n\t\t// Both ends drop every claim the removed prefixes covered.\n\t\tfor (const path of [...this.#live.keys()]) {\n\t\t\tif (removed.some((prefix) => Path.hasPrefix(prefix, path))) this.#live.delete(path);\n\t\t}\n\t\tfor (const [id, prefix] of request.add) this.#prefixes.set(id, prefix);\n\n\t\t// Held until now, so an edit sent before this answer is refused rather than checked\n\t\t// against stale prefixes. Let go before the answer is written: the peer may send its\n\t\t// next edit the moment it reads it, which can be before the write returns here.\n\t\tthis.#request = undefined;\n\t\tawait this.#publish.stream.send({ status: \"ok\" });\n\t\tawait this.#sync();\n\t\tconst synced = request.add.map(([prefix]) => ({ status: \"synced\", prefix }) as const);\n\t\tif (synced.length > 0) await this.#publish.stream.send(...synced);\n\t}\n\n\t// Bring the claims the peer holds in line with the origin's.\n\tasync #sync() {\n\t\tthis.#dirty = false;\n\t\tconst msgs = this.#changes();\n\t\tif (msgs.length > 0) await this.#publish.stream.send(...msgs);\n\t}\n\n\t// How the claims the peer holds differ from what the requested prefixes show it now.\n\t#changes(): AnnounceBroadcast[] {\n\t\tconst { advertised, origin } = this.#publish;\n\t\tconst table = origin ? advertised.peek() : undefined;\n\t\tconst grant = this.#publish.grant?.peek();\n\t\tconst granted = grant && regions(grant.publish);\n\t\t// The claims the peer is shown, by their path from the session's root: the table under each\n\t\t// prefix, less the hidden ones it did not ask for and whatever our grant does not let us publish.\n\t\tconst latest = new Map<Path.Valid, Advertised>();\n\t\t// A claim is filed where its route serves the whole subtree, so it is shown where some path it\n\t\t// covers is in the handle's scope and our grant, if any, lets us publish it, as one at `a` serves\n\t\t// `a/b` though `a` itself is not granted.\n\t\tconst shows = (_: Advertised, path: Path.Valid) => {\n\t\t\tconst served = within(path, [origin?.allowed]);\n\t\t\tif (!grant) return served === undefined || served.size > 0;\n\t\t\tif (served === undefined) return grant.publish.overlaps(path);\n\t\t\treturn served.toArray().some((prefix) => grant.publish.overlaps(prefix.text));\n\t\t};\n\t\t// Whether the advertisement a claim the peer holds came from is still in the table, as when\n\t\t// its presentation moved: the claim is lost to the peer rather than ended, since its publisher\n\t\t// never withdrew it. Another path's advertisement of the same identity proves nothing.\n\t\t// Indexed once per diff, and only when a claim leaves.\n\t\tlet advertisements: Map<object, Set<Identity.Valid | undefined>> | undefined;\n\t\tconst stillAdvertised = (sent: Sent) => {\n\t\t\tif (!advertisements) {\n\t\t\t\tadvertisements = new Map();\n\t\t\t\tfor (const candidates of table?.values() ?? []) {\n\t\t\t\t\tfor (const snap of candidates) {\n\t\t\t\t\t\tconst identities = advertisements.get(snap.ref) ?? new Set();\n\t\t\t\t\t\tidentities.add(snap.route.identity);\n\t\t\t\t\t\tadvertisements.set(snap.ref, identities);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn advertisements.get(sent.snap.ref)?.has(sent.snap.route.identity) ?? false;\n\t\t};\n\t\tconst ids = [...this.#prefixes.keys()].sort((a, b) => (a < b ? -1 : 1));\n\t\tfor (const id of table ? ids : []) {\n\t\t\tconst prefix = this.#prefixes.get(id);\n\t\t\tif (!prefix || !table) continue;\n\t\t\tconst carries = (covered: Path.Valid) => prefix.hidden || !hiddenBelow(prefix.path, covered);\n\t\t\tfor (const read of reads(prefix.path, granted)) {\n\t\t\t\t// A claim covering what is read from above keeps how many segments broader than it it is.\n\t\t\t\tfor (const [suffix, snap] of presented(read, table, carries, {\n\t\t\t\t\troot: origin?.root,\n\t\t\t\t\tkeepAbove: true,\n\t\t\t\t\tshows,\n\t\t\t\t})) {\n\t\t\t\t\tlatest.set(Path.join(read, suffix), snap);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst msgs: AnnounceBroadcast[] = [];\n\t\tconst end = (path: Path.Valid, sent: Sent, lost: boolean) => {\n\t\t\tthis.#live.delete(path);\n\t\t\tconsole.debug(`announce: broadcast=${path} active=false lost=${lost}`);\n\t\t\tmsgs.push({ status: \"endedId\", id: sent.id, lost });\n\t\t};\n\t\tfor (const [path, sent] of [...this.#live]) {\n\t\t\t// No longer granted, it is lost to the peer: its publisher never ended it.\n\t\t\tif (!latest.has(path)) end(path, sent, !shows(sent.snap, path) || stillAdvertised(sent));\n\t\t}\n\t\tfor (const [path, snap] of latest) {\n\t\t\tconst { identity, epoch, cost } = snap.route;\n\t\t\tif (identity === undefined) continue;\n\t\t\t// A claim above the session's root covers all of what the peer sees, so it is no more\n\t\t\t// above the path than the path is deep.\n\t\t\tconst depth = BigInt(Path.parts(path).length);\n\t\t\tconst above = snap.route.above ?? 0n;\n\t\t\tconst claim = { ...ownClaim(epoch ?? 0n, above < depth ? above : depth), cost };\n\t\t\tconst sent = this.#live.get(path);\n\t\t\tif (!sent || !sameIdentity(sent.snap, snap)) {\n\t\t\t\tthis.#live.set(path, { id: this.#nextAnnounce++, snap, claim });\n\t\t\t\tconsole.debug(`announce: broadcast=${path} active=true identity=${identity}`);\n\t\t\t\t// Every claim's path is relative to the session, whichever prefix it answers.\n\t\t\t\tmsgs.push({ status: \"start\", suffix: path, identity, claim });\n\t\t\t\t// Another identity is another claim, started before the one it replaces ends, so\n\t\t\t\t// the peer sees the broadcast restart rather than go.\n\t\t\t\tif (sent) msgs.push({ status: \"endedId\", id: sent.id, lost: false });\n\t\t\t} else if (!claimsEqual(sent.claim, claim)) {\n\t\t\t\tthis.#live.set(path, { id: sent.id, snap, claim });\n\t\t\t\tmsgs.push({ status: \"change\", id: sent.id, claim });\n\t\t\t} else {\n\t\t\t\tsent.snap = snap;\n\t\t\t}\n\t\t}\n\t\treturn msgs;\n\t}\n}\n\n// The regions `prefixes` confine the peer to, or undefined when they allow every path: the\n// prefixes themselves, already none within another. One too long or deep to be a path holds none.\n// Mirrors rs/moq-net's `Permit::regions`.\nfunction regions(prefixes: Path.Prefixes): Path.Valid[] | undefined {\n\tif (prefixes.matches(Path.empty())) return undefined;\n\treturn prefixes\n\t\t.toArray()\n\t\t.map((prefix) => prefix.text as Path.Valid)\n\t\t.filter((region) => Path.check(region) === undefined);\n}\n\n// What answers the requested `prefix`: the prefix itself when a region holds it or nothing confines\n// the peer, and otherwise each region inside it.\nfunction reads(prefix: Path.Valid, granted: Path.Valid[] | undefined): Path.Valid[] {\n\tif (!granted || granted.some((region) => Path.hasPrefix(region, prefix))) return [prefix];\n\treturn granted.filter((region) => Path.hasPrefix(prefix, region));\n}\n"]}
package/lite/auth.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type * as Path from "../path.ts";
2
+ import { type Reader, type Writer } from "../stream.ts";
3
+ import { type Version } from "./version.ts";
4
+ /** The first message on an Auth Stream: the token the opener presents. Lite07+. */
5
+ export declare class AuthMessage {
6
+ #private;
7
+ token: Uint8Array;
8
+ constructor(token: Uint8Array);
9
+ encode(w: Writer, version: Version): Promise<void>;
10
+ static decode(r: Reader, version: Version): Promise<AuthMessage>;
11
+ }
12
+ /** The grant a token earns, as the acceptor writes it. Encodes its own type. */
13
+ export declare class AuthOk {
14
+ #private;
15
+ static id: number;
16
+ publish: Path.Prefixes;
17
+ subscribe: Path.Prefixes;
18
+ /** Milliseconds until the grant lapses, or undefined for never. */
19
+ expires?: number;
20
+ constructor(publish: Path.Prefixes, subscribe: Path.Prefixes, expires?: number);
21
+ encode(w: Writer, version: Version): Promise<void>;
22
+ static decode(r: Reader, version: Version): Promise<AuthOk>;
23
+ }
24
+ /** The acceptor refusing a token, or revoking it after an AUTH_OK. Encodes its own type. */
25
+ export declare class AuthError {
26
+ #private;
27
+ static id: number;
28
+ /** A code from the session error registry. */
29
+ code: number;
30
+ reason: string;
31
+ constructor(code: number, reason: string);
32
+ /**
33
+ * Whether the code says the acceptor failed to decide (INTERNAL_ERROR, TOO_MANY_REQUESTS, or
34
+ * CONTROL_MESSAGE_TIMEOUT), so the presenter presents the token again after a backoff. Any
35
+ * other code is the acceptor's verdict.
36
+ */
37
+ undecided(): boolean;
38
+ encode(w: Writer, version: Version): Promise<void>;
39
+ static decode(r: Reader, version: Version): Promise<AuthError>;
40
+ }
41
+ /** A message the acceptor writes on the Auth Stream. */
42
+ export type AuthReply = AuthOk | AuthError;
43
+ /** Decode the next AUTH_OK or AUTH_ERROR, or undefined once the stream ends. */
44
+ export declare function decodeAuthReplyMaybe(r: Reader, version: Version): Promise<AuthReply | undefined>;
45
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lite/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,KAAK,MAAM,EAAU,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAKhE,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AASrD,mFAAmF;AACnF,qBAAa,WAAW;;IACvB,KAAK,EAAE,UAAU,CAAC;IAElB,YAAY,KAAK,EAAE,UAAU,EAE5B;IAYK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAGrE;CACD;AAED,gFAAgF;AAChF,qBAAa,MAAM;;IAClB,MAAM,CAAC,EAAE,SAAK;IAEd,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC;IACvB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC;IACzB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,YAAY,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,EAI7E;IAkBK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAShE;CACD;AAED,4FAA4F;AAC5F,qBAAa,SAAS;;IACrB,MAAM,CAAC,EAAE,SAAK;IAEd,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IAEf,YAAY,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAGvC;IAED;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAMnB;IAyBK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAGnE;CACD;AAED,wDAAwD;AACxD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAE3C,gFAAgF;AAChF,wBAAsB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAYtG"}
package/lite/auth.js ADDED
@@ -0,0 +1,204 @@
1
+ import { Unsupported } from "../auth.js";
2
+ import { decodePrefixes, encodePrefixes } from "../auth_session.js";
3
+ import { ProtocolViolation, SessionCode, SessionError } from "../error.js";
4
+ import { Stream } from "../stream.js";
5
+ import { decodeUtf8 } from "../util/utf8.js";
6
+ import { closeViolation } from "./error.js";
7
+ import * as Message from "./message.js";
8
+ import { StreamId } from "./stream.js";
9
+ import { hasAuth } from "./version.js";
10
+ function guardAuth(version) {
11
+ if (!hasAuth(version))
12
+ throw new Error("auth not supported for this version");
13
+ }
14
+ /** Longest AUTH_ERROR reason, in bytes, matching the Rust decoder. */
15
+ const MAX_REASON = 8192;
16
+ /** The first message on an Auth Stream: the token the opener presents. Lite07+. */
17
+ export class AuthMessage {
18
+ token;
19
+ constructor(token) {
20
+ this.token = token;
21
+ }
22
+ async #encode(w) {
23
+ await w.u53(this.token.byteLength);
24
+ if (this.token.byteLength > 0)
25
+ await w.write(this.token);
26
+ }
27
+ static async #decode(r) {
28
+ const size = await r.u53();
29
+ return new AuthMessage(await r.read(size));
30
+ }
31
+ async encode(w, version) {
32
+ guardAuth(version);
33
+ return Message.encode(w, this.#encode.bind(this));
34
+ }
35
+ static async decode(r, version) {
36
+ guardAuth(version);
37
+ return Message.decode(r, AuthMessage.#decode);
38
+ }
39
+ }
40
+ /** The grant a token earns, as the acceptor writes it. Encodes its own type. */
41
+ export class AuthOk {
42
+ static id = 0;
43
+ publish;
44
+ subscribe;
45
+ /** Milliseconds until the grant lapses, or undefined for never. */
46
+ expires;
47
+ constructor(publish, subscribe, expires) {
48
+ this.publish = publish;
49
+ this.subscribe = subscribe;
50
+ this.expires = expires;
51
+ }
52
+ async #encode(w) {
53
+ await encodePrefixes(w, this.publish);
54
+ await encodePrefixes(w, this.subscribe);
55
+ // 0 means never, so a lapsed grant rounds up to the smallest real expiry.
56
+ const expires = this.expires === undefined ? 0 : Math.min(Math.max(Math.ceil(this.expires), 1), Number.MAX_SAFE_INTEGER);
57
+ await w.u53(expires);
58
+ }
59
+ static async #decode(r) {
60
+ const publish = await decodePrefixes(r);
61
+ const subscribe = await decodePrefixes(r);
62
+ const expires = await r.u53();
63
+ return new AuthOk(publish, subscribe, expires === 0 ? undefined : expires);
64
+ }
65
+ async encode(w, version) {
66
+ guardAuth(version);
67
+ return Message.encode(w, this.#encode.bind(this), { id: AuthOk.id });
68
+ }
69
+ static async decode(r, version) {
70
+ guardAuth(version);
71
+ return Message.decode(r, async (body) => {
72
+ try {
73
+ return await AuthOk.#decode(body);
74
+ }
75
+ catch (cause) {
76
+ throw new ProtocolViolation("malformed AUTH_OK", { cause });
77
+ }
78
+ });
79
+ }
80
+ }
81
+ /** The acceptor refusing a token, or revoking it after an AUTH_OK. Encodes its own type. */
82
+ export class AuthError {
83
+ static id = 1;
84
+ /** A code from the session error registry. */
85
+ code;
86
+ reason;
87
+ constructor(code, reason) {
88
+ this.code = code;
89
+ this.reason = reason;
90
+ }
91
+ /**
92
+ * Whether the code says the acceptor failed to decide (INTERNAL_ERROR, TOO_MANY_REQUESTS, or
93
+ * CONTROL_MESSAGE_TIMEOUT), so the presenter presents the token again after a backoff. Any
94
+ * other code is the acceptor's verdict.
95
+ */
96
+ undecided() {
97
+ return (this.code === SessionCode.Internal ||
98
+ this.code === SessionCode.TooManyRequests ||
99
+ this.code === SessionCode.Timeout);
100
+ }
101
+ async #encode(w) {
102
+ if (new TextEncoder().encode(this.reason).byteLength > MAX_REASON) {
103
+ throw new Error("AUTH_ERROR reason exceeds 8,192 bytes");
104
+ }
105
+ await w.u53(this.code);
106
+ await w.string(this.reason);
107
+ }
108
+ static async #decode(r) {
109
+ const code = await r.u53();
110
+ if (code > 0xffffffff)
111
+ throw new ProtocolViolation("AUTH_ERROR code exceeds 32 bits");
112
+ const size = await r.u62();
113
+ if (size > BigInt(MAX_REASON)) {
114
+ throw new ProtocolViolation("AUTH_ERROR reason exceeds 8,192 bytes");
115
+ }
116
+ const bytes = await r.read(Number(size));
117
+ try {
118
+ return new AuthError(code, decodeUtf8(bytes));
119
+ }
120
+ catch (cause) {
121
+ throw new ProtocolViolation("invalid UTF-8 AUTH_ERROR reason", { cause });
122
+ }
123
+ }
124
+ async encode(w, version) {
125
+ guardAuth(version);
126
+ return Message.encode(w, this.#encode.bind(this), { id: AuthError.id });
127
+ }
128
+ static async decode(r, version) {
129
+ guardAuth(version);
130
+ return Message.decode(r, AuthError.#decode);
131
+ }
132
+ }
133
+ /** Decode the next AUTH_OK or AUTH_ERROR, or undefined once the stream ends. */
134
+ export async function decodeAuthReplyMaybe(r, version) {
135
+ guardAuth(version);
136
+ if (await r.done())
137
+ return undefined;
138
+ const typ = await r.u53();
139
+ switch (typ) {
140
+ case AuthOk.id:
141
+ return AuthOk.decode(r, version);
142
+ case AuthError.id:
143
+ return AuthError.decode(r, version);
144
+ default:
145
+ throw new Error(`unknown auth reply type: ${typ}`);
146
+ }
147
+ }
148
+ /** The moq-lite binding of the token lifecycle: one Auth Stream per token. @internal */
149
+ export class LiteAuthWire {
150
+ #quic;
151
+ #version;
152
+ constructor(quic, version) {
153
+ this.#quic = quic;
154
+ this.#version = version;
155
+ }
156
+ async present(token) {
157
+ const stream = await Stream.open(this.#quic, { version: this.#version });
158
+ await stream.writer.u53(StreamId.Auth);
159
+ await new AuthMessage(token).encode(stream.writer, this.#version);
160
+ return stream;
161
+ }
162
+ async read(stream) {
163
+ let reply;
164
+ try {
165
+ reply = await decodeAuthReplyMaybe(stream.reader, this.#version);
166
+ }
167
+ catch (err) {
168
+ closeViolation(this.#quic, err);
169
+ throw err;
170
+ }
171
+ if (!reply)
172
+ return undefined;
173
+ if (reply instanceof AuthOk) {
174
+ return { grant: { publish: reply.publish, subscribe: reply.subscribe, expires: reply.expires } };
175
+ }
176
+ return {
177
+ refused: reply.code === SessionCode.Unsupported
178
+ ? new Unsupported(reply.reason)
179
+ : new SessionError(reply.code, { reason: reply.reason }),
180
+ undecided: reply.undecided(),
181
+ };
182
+ }
183
+ /** The stream type is already consumed by the dispatcher. */
184
+ async accept(stream) {
185
+ const msg = await AuthMessage.decode(stream.reader, this.#version);
186
+ return msg.token;
187
+ }
188
+ async withdrawn(stream) {
189
+ if (!(await stream.reader.done()))
190
+ throw new ProtocolViolation("additional message on an AUTH stream");
191
+ }
192
+ async grant(stream, grant) {
193
+ await new AuthOk(grant.publish, grant.subscribe, grant.expires).encode(stream.writer, this.#version);
194
+ }
195
+ async refuse(stream, code, reason) {
196
+ await new AuthError(code, reason).encode(stream.writer, this.#version);
197
+ }
198
+ /** Tell the presenter explicitly, including after an earlier grant. */
199
+ async unsupported(stream, reason) {
200
+ await new AuthError(SessionCode.Unsupported, reason).encode(stream.writer, this.#version);
201
+ await stream.writer.close();
202
+ }
203
+ }
204
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lite/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAiB,cAAc,EAAE,cAAc,EAAkC,MAAM,oBAAoB,CAAC;AACnH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3E,OAAO,EAAe,MAAM,EAAe,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAgB,MAAM,cAAc,CAAC;AAErD,SAAS,SAAS,CAAC,OAAgB;IAClC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;AAC/E,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,mFAAmF;AACnF,MAAM,OAAO,WAAW;IACvB,KAAK,CAAa;IAElB,YAAY,KAAiB;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,GA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S,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC;IAED,uEAAuE;IACvE,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,MAAc;QAC/C,MAAM,IAAI,SAAS,CAAC,WAAW,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1F,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;CACD","sourcesContent":["import { Unsupported } from \"../auth.ts\";\nimport { type AuthWire, decodePrefixes, encodePrefixes, type WireGrant, type WireReply } from \"../auth_session.ts\";\nimport { ProtocolViolation, SessionCode, SessionError } from \"../error.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Stream, type Writer } from \"../stream.ts\";\nimport { decodeUtf8 } from \"../util/utf8.ts\";\nimport { closeViolation } from \"./error.ts\";\nimport * as Message from \"./message.ts\";\nimport { StreamId } from \"./stream.ts\";\nimport { hasAuth, type Version } from \"./version.ts\";\n\nfunction guardAuth(version: Version) {\n\tif (!hasAuth(version)) throw new Error(\"auth not supported for this version\");\n}\n\n/** Longest AUTH_ERROR reason, in bytes, matching the Rust decoder. */\nconst MAX_REASON = 8192;\n\n/** The first message on an Auth Stream: the token the opener presents. Lite07+. */\nexport class AuthMessage {\n\ttoken: Uint8Array;\n\n\tconstructor(token: Uint8Array) {\n\t\tthis.token = token;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.token.byteLength);\n\t\tif (this.token.byteLength > 0) await w.write(this.token);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AuthMessage> {\n\t\tconst size = await r.u53();\n\t\treturn new AuthMessage(await r.read(size));\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardAuth(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AuthMessage> {\n\t\tguardAuth(version);\n\t\treturn Message.decode(r, AuthMessage.#decode);\n\t}\n}\n\n/** The grant a token earns, as the acceptor writes it. Encodes its own type. */\nexport class AuthOk {\n\tstatic id = 0;\n\n\tpublish: Path.Prefixes;\n\tsubscribe: Path.Prefixes;\n\t/** Milliseconds until the grant lapses, or undefined for never. */\n\texpires?: number;\n\n\tconstructor(publish: Path.Prefixes, subscribe: Path.Prefixes, expires?: number) {\n\t\tthis.publish = publish;\n\t\tthis.subscribe = subscribe;\n\t\tthis.expires = expires;\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait encodePrefixes(w, this.publish);\n\t\tawait encodePrefixes(w, this.subscribe);\n\t\t// 0 means never, so a lapsed grant rounds up to the smallest real expiry.\n\t\tconst expires =\n\t\t\tthis.expires === undefined ? 0 : Math.min(Math.max(Math.ceil(this.expires), 1), Number.MAX_SAFE_INTEGER);\n\t\tawait w.u53(expires);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AuthOk> {\n\t\tconst publish = await decodePrefixes(r);\n\t\tconst subscribe = await decodePrefixes(r);\n\t\tconst expires = await r.u53();\n\t\treturn new AuthOk(publish, subscribe, expires === 0 ? undefined : expires);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardAuth(version);\n\t\treturn Message.encode(w, this.#encode.bind(this), { id: AuthOk.id });\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AuthOk> {\n\t\tguardAuth(version);\n\t\treturn Message.decode(r, async (body) => {\n\t\t\ttry {\n\t\t\t\treturn await AuthOk.#decode(body);\n\t\t\t} catch (cause) {\n\t\t\t\tthrow new ProtocolViolation(\"malformed AUTH_OK\", { cause });\n\t\t\t}\n\t\t});\n\t}\n}\n\n/** The acceptor refusing a token, or revoking it after an AUTH_OK. Encodes its own type. */\nexport class AuthError {\n\tstatic id = 1;\n\n\t/** A code from the session error registry. */\n\tcode: number;\n\treason: string;\n\n\tconstructor(code: number, reason: string) {\n\t\tthis.code = code;\n\t\tthis.reason = reason;\n\t}\n\n\t/**\n\t * Whether the code says the acceptor failed to decide (INTERNAL_ERROR, TOO_MANY_REQUESTS, or\n\t * CONTROL_MESSAGE_TIMEOUT), so the presenter presents the token again after a backoff. Any\n\t * other code is the acceptor's verdict.\n\t */\n\tundecided(): boolean {\n\t\treturn (\n\t\t\tthis.code === SessionCode.Internal ||\n\t\t\tthis.code === SessionCode.TooManyRequests ||\n\t\t\tthis.code === SessionCode.Timeout\n\t\t);\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tif (new TextEncoder().encode(this.reason).byteLength > MAX_REASON) {\n\t\t\tthrow new Error(\"AUTH_ERROR reason exceeds 8,192 bytes\");\n\t\t}\n\t\tawait w.u53(this.code);\n\t\tawait w.string(this.reason);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AuthError> {\n\t\tconst code = await r.u53();\n\t\tif (code > 0xffffffff) throw new ProtocolViolation(\"AUTH_ERROR code exceeds 32 bits\");\n\t\tconst size = await r.u62();\n\t\tif (size > BigInt(MAX_REASON)) {\n\t\t\tthrow new ProtocolViolation(\"AUTH_ERROR reason exceeds 8,192 bytes\");\n\t\t}\n\t\tconst bytes = await r.read(Number(size));\n\t\ttry {\n\t\t\treturn new AuthError(code, decodeUtf8(bytes));\n\t\t} catch (cause) {\n\t\t\tthrow new ProtocolViolation(\"invalid UTF-8 AUTH_ERROR reason\", { cause });\n\t\t}\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tguardAuth(version);\n\t\treturn Message.encode(w, this.#encode.bind(this), { id: AuthError.id });\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AuthError> {\n\t\tguardAuth(version);\n\t\treturn Message.decode(r, AuthError.#decode);\n\t}\n}\n\n/** A message the acceptor writes on the Auth Stream. */\nexport type AuthReply = AuthOk | AuthError;\n\n/** Decode the next AUTH_OK or AUTH_ERROR, or undefined once the stream ends. */\nexport async function decodeAuthReplyMaybe(r: Reader, version: Version): Promise<AuthReply | undefined> {\n\tguardAuth(version);\n\tif (await r.done()) return undefined;\n\tconst typ = await r.u53();\n\tswitch (typ) {\n\t\tcase AuthOk.id:\n\t\t\treturn AuthOk.decode(r, version);\n\t\tcase AuthError.id:\n\t\t\treturn AuthError.decode(r, version);\n\t\tdefault:\n\t\t\tthrow new Error(`unknown auth reply type: ${typ}`);\n\t}\n}\n\n/** The moq-lite binding of the token lifecycle: one Auth Stream per token. @internal */\nexport class LiteAuthWire implements AuthWire {\n\t#quic: WebTransport;\n\t#version: Version;\n\n\tconstructor(quic: WebTransport, version: Version) {\n\t\tthis.#quic = quic;\n\t\tthis.#version = version;\n\t}\n\n\tasync present(token: Uint8Array): Promise<Stream> {\n\t\tconst stream = await Stream.open(this.#quic, { version: this.#version });\n\t\tawait stream.writer.u53(StreamId.Auth);\n\t\tawait new AuthMessage(token).encode(stream.writer, this.#version);\n\t\treturn stream;\n\t}\n\n\tasync read(stream: Stream): Promise<WireReply | undefined> {\n\t\tlet reply: AuthReply | undefined;\n\t\ttry {\n\t\t\treply = await decodeAuthReplyMaybe(stream.reader, this.#version);\n\t\t} catch (err) {\n\t\t\tcloseViolation(this.#quic, err);\n\t\t\tthrow err;\n\t\t}\n\t\tif (!reply) return undefined;\n\t\tif (reply instanceof AuthOk) {\n\t\t\treturn { grant: { publish: reply.publish, subscribe: reply.subscribe, expires: reply.expires } };\n\t\t}\n\t\treturn {\n\t\t\trefused:\n\t\t\t\treply.code === SessionCode.Unsupported\n\t\t\t\t\t? new Unsupported(reply.reason)\n\t\t\t\t\t: new SessionError(reply.code as SessionCode, { reason: reply.reason }),\n\t\t\tundecided: reply.undecided(),\n\t\t};\n\t}\n\n\t/** The stream type is already consumed by the dispatcher. */\n\tasync accept(stream: Stream): Promise<Uint8Array> {\n\t\tconst msg = await AuthMessage.decode(stream.reader, this.#version);\n\t\treturn msg.token;\n\t}\n\n\tasync withdrawn(stream: Stream): Promise<void> {\n\t\tif (!(await stream.reader.done())) throw new ProtocolViolation(\"additional message on an AUTH stream\");\n\t}\n\n\tasync grant(stream: Stream, grant: WireGrant): Promise<void> {\n\t\tawait new AuthOk(grant.publish, grant.subscribe, grant.expires).encode(stream.writer, this.#version);\n\t}\n\n\tasync refuse(stream: Stream, code: SessionCode, reason: string): Promise<void> {\n\t\tawait new AuthError(code, reason).encode(stream.writer, this.#version);\n\t}\n\n\t/** Tell the presenter explicitly, including after an earlier grant. */\n\tasync unsupported(stream: Stream, reason: string): Promise<void> {\n\t\tawait new AuthError(SessionCode.Unsupported, reason).encode(stream.writer, this.#version);\n\t\tawait stream.writer.close();\n\t}\n}\n"]}