@moqtap/codec 0.2.3 → 0.3.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 (299) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +100 -99
  3. package/dist/{chunk-RZHAPEXO.js → chunk-2A57DRXV.js} +36 -10
  4. package/dist/{chunk-73MWUKSJ.js → chunk-2UTVXWFF.js} +190 -102
  5. package/dist/{chunk-JTVCOMBI.cjs → chunk-3XKO6PCR.cjs} +290 -183
  6. package/dist/{chunk-ACQ4CUJP.cjs → chunk-4BDEU3D4.cjs} +237 -158
  7. package/dist/{chunk-4N4INRE7.cjs → chunk-4HBKHNU2.cjs} +144 -110
  8. package/dist/{chunk-2ZT6CVSE.js → chunk-4IVZZOY3.js} +269 -162
  9. package/dist/{chunk-GLBQDG4L.cjs → chunk-5O764MBD.cjs} +508 -117
  10. package/dist/chunk-7KBAWOBA.js +1212 -0
  11. package/dist/{chunk-JSQM2MG3.js → chunk-7QOPNSDF.js} +44 -12
  12. package/dist/{chunk-SYHW3FLI.cjs → chunk-7RE6KSIY.cjs} +28 -8
  13. package/dist/{chunk-YG5KJESI.js → chunk-AY6IAHUM.js} +28 -8
  14. package/dist/{chunk-EFM5T7OM.js → chunk-BLQDWOSG.js} +36 -10
  15. package/dist/{chunk-UYXTY6ZQ.cjs → chunk-E65QKRSN.cjs} +20 -12
  16. package/dist/{chunk-BISI45MN.cjs → chunk-EAHE3IOG.cjs} +44 -12
  17. package/dist/{chunk-PZBPH2D7.js → chunk-GCBFHZW6.js} +216 -137
  18. package/dist/{chunk-GXEW4COZ.cjs → chunk-H5NSL4MO.cjs} +36 -10
  19. package/dist/chunk-HZHSO7EW.cjs +1212 -0
  20. package/dist/{chunk-KZCYQ7ED.cjs → chunk-IILNSDEQ.cjs} +69 -41
  21. package/dist/{chunk-4XYGE53S.cjs → chunk-J3XCPBW3.cjs} +36 -10
  22. package/dist/{chunk-6AEHWULA.cjs → chunk-JKOEJZ5B.cjs} +28 -8
  23. package/dist/{chunk-RUPCJTC3.cjs → chunk-JL3NEW3O.cjs} +23 -1
  24. package/dist/{chunk-G7GI7LJA.js → chunk-LORZMJJB.js} +36 -10
  25. package/dist/{chunk-DUBCL3WF.cjs → chunk-LV5C6MEC.cjs} +36 -10
  26. package/dist/{chunk-ENURAVHI.cjs → chunk-MYXAD5JC.cjs} +44 -12
  27. package/dist/{chunk-FXZ2MYKJ.js → chunk-MZ7HUCGJ.js} +20 -12
  28. package/dist/{chunk-S74DWJE2.cjs → chunk-OKG2HT25.cjs} +277 -88
  29. package/dist/{chunk-BGWGVINJ.cjs → chunk-PKEOQSSZ.cjs} +144 -110
  30. package/dist/{chunk-2GODRVT5.js → chunk-Q46ZURKX.js} +325 -48
  31. package/dist/{chunk-UR6JKS56.js → chunk-Q7IGWV3P.js} +41 -9
  32. package/dist/{chunk-XSNX2IUJ.js → chunk-RW4UG7CN.js} +121 -87
  33. package/dist/{chunk-DWK5ZQZ4.js → chunk-RZTLQAKF.js} +28 -8
  34. package/dist/{chunk-UNS34PTA.cjs → chunk-S6IPIN66.cjs} +44 -12
  35. package/dist/{chunk-YIG2C3LF.cjs → chunk-SDWRXXOO.cjs} +214 -126
  36. package/dist/{chunk-CEH7ESNC.js → chunk-SHMA4PBY.js} +121 -87
  37. package/dist/{chunk-MC7W6PMI.js → chunk-U3ZVLT5L.js} +483 -135
  38. package/dist/{chunk-VJUUZ4W2.cjs → chunk-UJU63EFY.cjs} +374 -97
  39. package/dist/{chunk-7L43FE6P.js → chunk-VOU7PNHI.js} +23 -1
  40. package/dist/{chunk-E6E3NQYU.js → chunk-WRHGCVYN.js} +44 -12
  41. package/dist/{chunk-FPISPJ5N.cjs → chunk-XNWYLVGU.cjs} +529 -181
  42. package/dist/{chunk-U3IPZYPX.js → chunk-XS77RBY7.js} +228 -39
  43. package/dist/{chunk-JGG7CMSZ.cjs → chunk-XZE5R57R.cjs} +144 -110
  44. package/dist/{chunk-77MNXX3M.js → chunk-Y6KCSM3V.js} +121 -87
  45. package/dist/{chunk-TLYNOOQP.cjs → chunk-YTPZZI2M.cjs} +41 -9
  46. package/dist/{chunk-7DUBLRXC.js → chunk-YWRCSQBA.js} +44 -12
  47. package/dist/{chunk-MRJWLGYH.js → chunk-Z3VKP3PJ.js} +69 -41
  48. package/dist/{chunk-E6P74GDT.js → chunk-Z6U26IRI.js} +464 -73
  49. package/dist/{codec-FvGCxIhr.d.ts → codec-25u4_1HS.d.ts} +4 -4
  50. package/dist/{codec-DRcsBCsb.d.ts → codec-3Ppy_5Gd.d.ts} +4 -4
  51. package/dist/{codec-BdVMRMOI.d.ts → codec-BB0U8MF2.d.cts} +4 -4
  52. package/dist/{codec-B2cH-f5V.d.cts → codec-BHHfBTnV.d.ts} +4 -4
  53. package/dist/{codec-B5K73Bdj.d.ts → codec-BN6jk0Td.d.cts} +4 -4
  54. package/dist/{codec-R8GrCPt2.d.ts → codec-BU0gaSZm.d.ts} +4 -4
  55. package/dist/{codec-Bq-tLtfP.d.ts → codec-C-Yk2RNa.d.ts} +4 -4
  56. package/dist/codec-CFWQY9Lj.d.cts +18 -0
  57. package/dist/{codec-CPlK3Pi5.d.ts → codec-COy4uuPO.d.cts} +4 -4
  58. package/dist/codec-CewFCsEy.d.ts +18 -0
  59. package/dist/{codec-KXHvXZVb.d.cts → codec-Ck7ZwFF1.d.cts} +4 -4
  60. package/dist/{codec-DZhZSIii.d.cts → codec-D2QVSH9D.d.ts} +4 -4
  61. package/dist/{codec-BwFgpeQu.d.ts → codec-DDUBJGn0.d.cts} +4 -4
  62. package/dist/{codec-BFeliJFc.d.ts → codec-DNfml-se.d.ts} +4 -4
  63. package/dist/{codec-C4n1PS09.d.cts → codec-DoOGjjDq.d.cts} +4 -4
  64. package/dist/{codec-Bap882Fh.d.cts → codec-J7ekOSMc.d.ts} +4 -4
  65. package/dist/{codec-SKBeHQk7.d.ts → codec-R9TJCq-E.d.cts} +4 -4
  66. package/dist/{codec-DNUIgLqc.d.cts → codec-ZwV-Njt6.d.ts} +4 -4
  67. package/dist/{codec-HgBgHkFI.d.cts → codec-j819z_hL.d.cts} +4 -4
  68. package/dist/{codec-DY4QH364.d.cts → codec-w8z2j_uo.d.cts} +4 -4
  69. package/dist/{codec-CPvPq0sb.d.cts → codec-wtt6WF1K.d.ts} +4 -4
  70. package/dist/{codec-BUMjz0J4.d.cts → codec-z6_2PSzi.d.cts} +4 -4
  71. package/dist/draft10-session.cjs +2 -2
  72. package/dist/draft10-session.d.cts +6 -6
  73. package/dist/draft10-session.d.ts +6 -6
  74. package/dist/draft10-session.js +1 -1
  75. package/dist/draft10.cjs +8 -5
  76. package/dist/draft10.d.cts +14 -12
  77. package/dist/draft10.d.ts +14 -12
  78. package/dist/draft10.js +16 -13
  79. package/dist/draft11-session.cjs +2 -2
  80. package/dist/draft11-session.d.cts +6 -6
  81. package/dist/draft11-session.d.ts +6 -6
  82. package/dist/draft11-session.js +1 -1
  83. package/dist/draft11.cjs +8 -5
  84. package/dist/draft11.d.cts +14 -12
  85. package/dist/draft11.d.ts +14 -12
  86. package/dist/draft11.js +16 -13
  87. package/dist/draft12-session.cjs +2 -2
  88. package/dist/draft12-session.d.cts +6 -6
  89. package/dist/draft12-session.d.ts +6 -6
  90. package/dist/draft12-session.js +1 -1
  91. package/dist/draft12.cjs +8 -5
  92. package/dist/draft12.d.cts +16 -14
  93. package/dist/draft12.d.ts +16 -14
  94. package/dist/draft12.js +16 -13
  95. package/dist/draft13-session.cjs +2 -2
  96. package/dist/draft13-session.d.cts +6 -6
  97. package/dist/draft13-session.d.ts +6 -6
  98. package/dist/draft13-session.js +1 -1
  99. package/dist/draft13.cjs +8 -5
  100. package/dist/draft13.d.cts +16 -14
  101. package/dist/draft13.d.ts +16 -14
  102. package/dist/draft13.js +16 -13
  103. package/dist/draft14-session.cjs +2 -2
  104. package/dist/draft14-session.d.cts +6 -6
  105. package/dist/draft14-session.d.ts +6 -6
  106. package/dist/draft14-session.js +1 -1
  107. package/dist/draft14.cjs +14 -5
  108. package/dist/draft14.d.cts +14 -12
  109. package/dist/draft14.d.ts +14 -12
  110. package/dist/draft14.js +13 -4
  111. package/dist/draft15-session.cjs +2 -2
  112. package/dist/draft15-session.d.cts +6 -6
  113. package/dist/draft15-session.d.ts +6 -6
  114. package/dist/draft15-session.js +1 -1
  115. package/dist/draft15.cjs +8 -5
  116. package/dist/draft15.d.cts +14 -12
  117. package/dist/draft15.d.ts +14 -12
  118. package/dist/draft15.js +16 -13
  119. package/dist/draft16-session.cjs +2 -2
  120. package/dist/draft16-session.d.cts +6 -6
  121. package/dist/draft16-session.d.ts +6 -6
  122. package/dist/draft16-session.js +1 -1
  123. package/dist/draft16.cjs +8 -5
  124. package/dist/draft16.d.cts +14 -12
  125. package/dist/draft16.d.ts +14 -12
  126. package/dist/draft16.js +16 -13
  127. package/dist/draft17-session.cjs +2 -2
  128. package/dist/draft17-session.d.cts +7 -7
  129. package/dist/draft17-session.d.ts +7 -7
  130. package/dist/draft17-session.js +1 -1
  131. package/dist/draft17.cjs +8 -5
  132. package/dist/draft17.d.cts +11 -9
  133. package/dist/draft17.d.ts +11 -9
  134. package/dist/draft17.js +16 -13
  135. package/dist/draft7-session.cjs +2 -2
  136. package/dist/draft7-session.d.cts +6 -5
  137. package/dist/draft7-session.d.ts +6 -5
  138. package/dist/draft7-session.js +1 -1
  139. package/dist/draft7.cjs +71 -14
  140. package/dist/draft7.d.cts +53 -134
  141. package/dist/draft7.d.ts +53 -134
  142. package/dist/draft7.js +76 -19
  143. package/dist/draft8-session.cjs +2 -2
  144. package/dist/draft8-session.d.cts +6 -6
  145. package/dist/draft8-session.d.ts +6 -6
  146. package/dist/draft8-session.js +1 -1
  147. package/dist/draft8.cjs +8 -5
  148. package/dist/draft8.d.cts +14 -12
  149. package/dist/draft8.d.ts +14 -12
  150. package/dist/draft8.js +7 -4
  151. package/dist/draft9-session.cjs +2 -2
  152. package/dist/draft9-session.d.cts +6 -6
  153. package/dist/draft9-session.d.ts +6 -6
  154. package/dist/draft9-session.js +1 -1
  155. package/dist/draft9.cjs +8 -5
  156. package/dist/draft9.d.cts +14 -12
  157. package/dist/draft9.d.ts +14 -12
  158. package/dist/draft9.js +7 -4
  159. package/dist/index.cjs +52 -74
  160. package/dist/index.d.cts +41 -60
  161. package/dist/index.d.ts +41 -60
  162. package/dist/index.js +40 -62
  163. package/dist/{session-types-CJIFbTPd.d.ts → session-types-C7UONex5.d.cts} +28 -27
  164. package/dist/{session-types-Cbq8IGCP.d.cts → session-types-X-IYEGoG.d.ts} +28 -27
  165. package/dist/session.cjs +46 -13
  166. package/dist/session.d.cts +28 -9
  167. package/dist/session.d.ts +28 -9
  168. package/dist/session.js +46 -13
  169. package/dist/{types-DxSFvL2b.d.cts → types--Q7_DcvP.d.cts} +43 -39
  170. package/dist/{types-DxSFvL2b.d.ts → types--Q7_DcvP.d.ts} +43 -39
  171. package/dist/{types-B0FT5Qs2.d.ts → types-0IWbU9Z_.d.cts} +36 -36
  172. package/dist/{types-B0FT5Qs2.d.cts → types-0IWbU9Z_.d.ts} +36 -36
  173. package/dist/{types-gQsr0AAA.d.cts → types-B3g5G9KP.d.cts} +36 -36
  174. package/dist/{types-gQsr0AAA.d.ts → types-B3g5G9KP.d.ts} +36 -36
  175. package/dist/{types-Pme7sua0.d.cts → types-BFpFNM_m.d.cts} +57 -32
  176. package/dist/{types-Pme7sua0.d.ts → types-BFpFNM_m.d.ts} +57 -32
  177. package/dist/{types-8gUGeMgs.d.ts → types-Br7fm2mf.d.cts} +48 -26
  178. package/dist/{types-8gUGeMgs.d.cts → types-Br7fm2mf.d.ts} +48 -26
  179. package/dist/{types-BeAVNU-F.d.cts → types-C2qKTRR_.d.cts} +50 -45
  180. package/dist/{types-BeAVNU-F.d.ts → types-C2qKTRR_.d.ts} +50 -45
  181. package/dist/{types-DKpsfD3i.d.cts → types-DEaypVsD.d.cts} +115 -55
  182. package/dist/{types-DKpsfD3i.d.ts → types-DEaypVsD.d.ts} +115 -55
  183. package/dist/types-Dl4IaAHR.d.cts +282 -0
  184. package/dist/types-Dl4IaAHR.d.ts +282 -0
  185. package/dist/{types-CDa7F5ct.d.cts → types-DrQpTW1G.d.cts} +58 -50
  186. package/dist/{types-CDa7F5ct.d.ts → types-DrQpTW1G.d.ts} +58 -50
  187. package/dist/types-DuIO7cWK.d.cts +25 -0
  188. package/dist/types-DuIO7cWK.d.ts +25 -0
  189. package/dist/{types-B9A2g05r.d.cts → types-DuxfOYiO.d.cts} +47 -31
  190. package/dist/{types-B9A2g05r.d.ts → types-DuxfOYiO.d.ts} +47 -31
  191. package/dist/{types-D1dI_oTX.d.cts → types-jV1yDDBA.d.cts} +36 -36
  192. package/dist/{types-D1dI_oTX.d.ts → types-jV1yDDBA.d.ts} +36 -36
  193. package/package.json +192 -192
  194. package/src/core/buffer-reader.ts +130 -130
  195. package/src/core/buffer-writer.ts +100 -100
  196. package/src/core/errors.ts +1 -1
  197. package/src/core/hex.ts +21 -21
  198. package/src/core/session-types.ts +61 -59
  199. package/src/core/types.ts +18 -361
  200. package/src/drafts/draft07/codec.ts +1058 -938
  201. package/src/drafts/draft07/data-streams.ts +240 -240
  202. package/src/drafts/draft07/index.ts +124 -89
  203. package/src/drafts/draft07/messages.ts +76 -42
  204. package/src/drafts/draft07/rules.ts +107 -101
  205. package/src/drafts/draft07/session-fsm.ts +315 -287
  206. package/src/drafts/draft07/session.ts +8 -6
  207. package/src/drafts/draft07/types.ts +406 -72
  208. package/src/drafts/draft07/varint.ts +51 -51
  209. package/src/drafts/draft08/codec.ts +985 -953
  210. package/src/drafts/draft08/data-streams.ts +363 -359
  211. package/src/drafts/draft08/index.ts +10 -9
  212. package/src/drafts/draft08/messages.ts +59 -59
  213. package/src/drafts/draft08/rules.ts +73 -73
  214. package/src/drafts/draft08/session-fsm.ts +335 -303
  215. package/src/drafts/draft08/session.ts +6 -7
  216. package/src/drafts/draft08/types.ts +380 -384
  217. package/src/drafts/draft09/codec.ts +977 -945
  218. package/src/drafts/draft09/data-streams.ts +336 -332
  219. package/src/drafts/draft09/index.ts +10 -9
  220. package/src/drafts/draft09/messages.ts +59 -59
  221. package/src/drafts/draft09/rules.ts +73 -73
  222. package/src/drafts/draft09/session-fsm.ts +335 -303
  223. package/src/drafts/draft09/session.ts +6 -7
  224. package/src/drafts/draft09/types.ts +380 -384
  225. package/src/drafts/draft10/codec.ts +977 -945
  226. package/src/drafts/draft10/data-streams.ts +336 -332
  227. package/src/drafts/draft10/index.ts +10 -9
  228. package/src/drafts/draft10/messages.ts +59 -59
  229. package/src/drafts/draft10/rules.ts +73 -73
  230. package/src/drafts/draft10/session-fsm.ts +335 -303
  231. package/src/drafts/draft10/session.ts +6 -7
  232. package/src/drafts/draft10/types.ts +380 -384
  233. package/src/drafts/draft11/codec.ts +1054 -988
  234. package/src/drafts/draft11/data-streams.ts +316 -269
  235. package/src/drafts/draft11/index.ts +10 -9
  236. package/src/drafts/draft11/messages.ts +60 -59
  237. package/src/drafts/draft11/rules.ts +73 -73
  238. package/src/drafts/draft11/session-fsm.ts +359 -333
  239. package/src/drafts/draft11/session.ts +6 -7
  240. package/src/drafts/draft11/types.ts +385 -381
  241. package/src/drafts/draft12/codec.ts +1178 -1122
  242. package/src/drafts/draft12/data-streams.ts +324 -275
  243. package/src/drafts/draft12/index.ts +10 -9
  244. package/src/drafts/draft12/messages.ts +67 -66
  245. package/src/drafts/draft12/rules.ts +79 -79
  246. package/src/drafts/draft12/session-fsm.ts +384 -358
  247. package/src/drafts/draft12/session.ts +6 -7
  248. package/src/drafts/draft12/types.ts +424 -419
  249. package/src/drafts/draft13/codec.ts +1296 -1206
  250. package/src/drafts/draft13/data-streams.ts +326 -275
  251. package/src/drafts/draft13/index.ts +10 -9
  252. package/src/drafts/draft13/messages.ts +73 -68
  253. package/src/drafts/draft13/rules.ts +81 -81
  254. package/src/drafts/draft13/session-fsm.ts +392 -366
  255. package/src/drafts/draft13/session.ts +6 -7
  256. package/src/drafts/draft13/types.ts +447 -438
  257. package/src/drafts/draft14/codec.ts +1347 -1043
  258. package/src/drafts/draft14/data-streams.ts +831 -813
  259. package/src/drafts/draft14/index.ts +17 -9
  260. package/src/drafts/draft14/messages.ts +65 -65
  261. package/src/drafts/draft14/rules.ts +81 -81
  262. package/src/drafts/draft14/session-fsm.ts +415 -405
  263. package/src/drafts/draft14/session.ts +6 -7
  264. package/src/drafts/draft14/types.ts +451 -381
  265. package/src/drafts/draft15/codec.ts +1138 -978
  266. package/src/drafts/draft15/data-streams.ts +842 -794
  267. package/src/drafts/draft15/index.ts +10 -9
  268. package/src/drafts/draft15/messages.ts +54 -53
  269. package/src/drafts/draft15/rules.ts +67 -67
  270. package/src/drafts/draft15/session-fsm.ts +319 -299
  271. package/src/drafts/draft15/session.ts +6 -7
  272. package/src/drafts/draft15/types.ts +357 -339
  273. package/src/drafts/draft16/codec.ts +1242 -966
  274. package/src/drafts/draft16/data-streams.ts +835 -789
  275. package/src/drafts/draft16/index.ts +10 -9
  276. package/src/drafts/draft16/messages.ts +56 -55
  277. package/src/drafts/draft16/rules.ts +69 -69
  278. package/src/drafts/draft16/session-fsm.ts +319 -299
  279. package/src/drafts/draft16/session.ts +6 -7
  280. package/src/drafts/draft16/types.ts +386 -357
  281. package/src/drafts/draft17/codec.ts +1209 -971
  282. package/src/drafts/draft17/data-streams.ts +969 -758
  283. package/src/drafts/draft17/index.ts +9 -7
  284. package/src/drafts/draft17/messages.ts +43 -42
  285. package/src/drafts/draft17/rules.ts +58 -58
  286. package/src/drafts/draft17/session-fsm.ts +248 -216
  287. package/src/drafts/draft17/session.ts +5 -5
  288. package/src/drafts/draft17/types.ts +337 -313
  289. package/src/index.ts +85 -274
  290. package/src/session.ts +62 -23
  291. package/dist/chunk-FZDIEHQL.cjs +0 -1042
  292. package/dist/chunk-HDWJ2GDE.js +0 -24
  293. package/dist/chunk-KNDYS3DK.cjs +0 -24
  294. package/dist/chunk-N2KBF5Q2.js +0 -1042
  295. package/dist/types-QNXoxC9Y.d.cts +0 -236
  296. package/dist/types-QNXoxC9Y.d.ts +0 -236
  297. package/src/drafts/draft07/announce-fsm.ts +0 -2
  298. package/src/drafts/draft07/parameters.ts +0 -12
  299. package/src/drafts/draft07/subscription-fsm.ts +0 -3
@@ -8,87 +8,87 @@ import type {
8
8
  SubscriptionState,
9
9
  TransitionResult,
10
10
  ValidationResult,
11
- } from "../../core/session-types.js";
11
+ } from '../../core/session-types.js'
12
12
  import {
13
13
  CLIENT_ONLY_MESSAGES,
14
14
  getLegalIncoming,
15
15
  getLegalOutgoing,
16
16
  SERVER_ONLY_MESSAGES,
17
- } from "./rules.js";
18
- import type { Draft16Message, Draft16MessageType } from "./types.js";
17
+ } from './rules.js'
18
+ import type { Draft16Message, Draft16MessageType } from './types.js'
19
19
 
20
20
  function violation(
21
- code: ProtocolViolation<Draft16MessageType>["code"],
21
+ code: ProtocolViolation<Draft16MessageType>['code'],
22
22
  message: string,
23
23
  currentPhase: SessionPhase,
24
24
  offendingMessage: Draft16MessageType,
25
25
  ): ProtocolViolation<Draft16MessageType> {
26
- return { code, message, currentPhase, offendingMessage };
26
+ return { code, message, currentPhase, offendingMessage }
27
27
  }
28
28
 
29
29
  export class Draft16SessionFSM {
30
- private _phase: SessionPhase = "idle";
31
- private _role: "client" | "server";
32
- private _subscriptions = new Map<bigint, SubscriptionState>();
33
- private _publishes = new Map<bigint, PublishState>();
34
- private _fetches = new Map<bigint, FetchState>();
35
- private _requestIds = new Set<bigint>();
30
+ private _phase: SessionPhase = 'idle'
31
+ private _role: 'client' | 'server'
32
+ private _subscriptions = new Map<bigint, SubscriptionState>()
33
+ private _publishes = new Map<bigint, PublishState>()
34
+ private _fetches = new Map<bigint, FetchState>()
35
+ private _requestIds = new Set<bigint>()
36
36
 
37
- constructor(role: "client" | "server") {
38
- this._role = role;
37
+ constructor(role: 'client' | 'server') {
38
+ this._role = role
39
39
  }
40
40
 
41
41
  get phase(): SessionPhase {
42
- return this._phase;
42
+ return this._phase
43
43
  }
44
- get role(): "client" | "server" {
45
- return this._role;
44
+ get role(): 'client' | 'server' {
45
+ return this._role
46
46
  }
47
47
  get subscriptions(): ReadonlyMap<bigint, SubscriptionState> {
48
- return this._subscriptions;
48
+ return this._subscriptions
49
49
  }
50
50
  get announces(): ReadonlyMap<string, AnnounceState> {
51
- return new Map();
51
+ return new Map()
52
52
  }
53
53
  get publishes(): ReadonlyMap<bigint, PublishState> {
54
- return this._publishes;
54
+ return this._publishes
55
55
  }
56
56
  get fetches(): ReadonlyMap<bigint, FetchState> {
57
- return this._fetches;
57
+ return this._fetches
58
58
  }
59
59
 
60
60
  get legalOutgoing(): ReadonlySet<Draft16MessageType> {
61
- return getLegalOutgoing(this._phase, this._role);
61
+ return getLegalOutgoing(this._phase, this._role)
62
62
  }
63
63
 
64
64
  get legalIncoming(): ReadonlySet<Draft16MessageType> {
65
- return getLegalIncoming(this._phase, this._role);
65
+ return getLegalIncoming(this._phase, this._role)
66
66
  }
67
67
 
68
68
  private checkRole(
69
69
  message: Draft16Message,
70
- direction: "inbound" | "outbound",
70
+ direction: 'inbound' | 'outbound',
71
71
  ): ProtocolViolation<Draft16MessageType> | null {
72
72
  const senderRole =
73
- direction === "outbound" ? this._role : this._role === "client" ? "server" : "client";
73
+ direction === 'outbound' ? this._role : this._role === 'client' ? 'server' : 'client'
74
74
 
75
- if (CLIENT_ONLY_MESSAGES.has(message.type) && senderRole !== "client") {
75
+ if (CLIENT_ONLY_MESSAGES.has(message.type) && senderRole !== 'client') {
76
76
  return violation(
77
- "ROLE_VIOLATION",
77
+ 'ROLE_VIOLATION',
78
78
  `${message.type} can only be sent by client`,
79
79
  this._phase,
80
80
  message.type,
81
- );
81
+ )
82
82
  }
83
- if (SERVER_ONLY_MESSAGES.has(message.type) && senderRole !== "server") {
83
+ if (SERVER_ONLY_MESSAGES.has(message.type) && senderRole !== 'server') {
84
84
  return violation(
85
- "ROLE_VIOLATION",
85
+ 'ROLE_VIOLATION',
86
86
  `${message.type} can only be sent by server`,
87
87
  this._phase,
88
88
  message.type,
89
- );
89
+ )
90
90
  }
91
- return null;
91
+ return null
92
92
  }
93
93
 
94
94
  private checkDuplicateRequestId(
@@ -97,13 +97,13 @@ export class Draft16SessionFSM {
97
97
  ): ProtocolViolation<Draft16MessageType> | null {
98
98
  if (this._requestIds.has(requestId)) {
99
99
  return violation(
100
- "DUPLICATE_REQUEST_ID",
100
+ 'DUPLICATE_REQUEST_ID',
101
101
  `Request ID ${requestId} already in use`,
102
102
  this._phase,
103
103
  msgType,
104
- );
104
+ )
105
105
  }
106
- return null;
106
+ return null
107
107
  }
108
108
 
109
109
  private checkKnownRequestId(
@@ -112,252 +112,262 @@ export class Draft16SessionFSM {
112
112
  ): ProtocolViolation<Draft16MessageType> | null {
113
113
  if (!this._requestIds.has(requestId)) {
114
114
  return violation(
115
- "UNKNOWN_REQUEST_ID",
115
+ 'UNKNOWN_REQUEST_ID',
116
116
  `No request with ID ${requestId}`,
117
117
  this._phase,
118
118
  msgType,
119
- );
119
+ )
120
120
  }
121
- return null;
121
+ return null
122
122
  }
123
123
 
124
124
  validateOutgoing(message: Draft16Message): ValidationResult<Draft16MessageType> {
125
- const roleViolation = this.checkRole(message, "outbound");
126
- if (roleViolation) return { ok: false, violation: roleViolation };
125
+ const roleViolation = this.checkRole(message, 'outbound')
126
+ if (roleViolation) return { ok: false, violation: roleViolation }
127
127
 
128
128
  if (!this.legalOutgoing.has(message.type)) {
129
129
  return {
130
130
  ok: false,
131
131
  violation: violation(
132
- this._phase === "idle" || this._phase === "setup"
133
- ? "MESSAGE_BEFORE_SETUP"
134
- : "UNEXPECTED_MESSAGE",
132
+ this._phase === 'idle' || this._phase === 'setup'
133
+ ? 'MESSAGE_BEFORE_SETUP'
134
+ : 'UNEXPECTED_MESSAGE',
135
135
  `Cannot send ${message.type} in phase ${this._phase}`,
136
136
  this._phase,
137
137
  message.type,
138
138
  ),
139
- };
139
+ }
140
140
  }
141
- return { ok: true };
141
+ return { ok: true }
142
142
  }
143
143
 
144
144
  receive(message: Draft16Message): TransitionResult<Draft16MessageType> {
145
- const roleViolation = this.checkRole(message, "inbound");
146
- if (roleViolation) return { ok: false, violation: roleViolation };
147
- return this.applyTransition(message, "inbound");
145
+ const roleViolation = this.checkRole(message, 'inbound')
146
+ if (roleViolation) return { ok: false, violation: roleViolation }
147
+ return this.applyTransition(message, 'inbound')
148
148
  }
149
149
 
150
150
  send(message: Draft16Message): TransitionResult<Draft16MessageType> {
151
- const roleViolation = this.checkRole(message, "outbound");
152
- if (roleViolation) return { ok: false, violation: roleViolation };
153
- return this.applyTransition(message, "outbound");
151
+ const roleViolation = this.checkRole(message, 'outbound')
152
+ if (roleViolation) return { ok: false, violation: roleViolation }
153
+ return this.applyTransition(message, 'outbound')
154
154
  }
155
155
 
156
156
  private applyTransition(
157
157
  message: Draft16Message,
158
- direction: "inbound" | "outbound",
158
+ direction: 'inbound' | 'outbound',
159
159
  ): TransitionResult<Draft16MessageType> {
160
- const sideEffects: SideEffect[] = [];
160
+ const sideEffects: SideEffect[] = []
161
161
 
162
162
  switch (message.type) {
163
- case "client_setup":
164
- return this.handleClientSetup(direction);
165
- case "server_setup":
166
- return this.handleServerSetup(direction);
167
- case "goaway":
168
- return this.handleGoAway(message, sideEffects);
163
+ case 'client_setup':
164
+ return this.handleClientSetup(direction)
165
+ case 'server_setup':
166
+ return this.handleServerSetup(direction)
167
+ case 'goaway':
168
+ return this.handleGoAway(message, sideEffects)
169
169
 
170
170
  // Subscribe lifecycle
171
- case "subscribe":
172
- return this.handleSubscribe(message, sideEffects);
173
- case "subscribe_ok":
174
- return this.handleSubscribeOk(message, sideEffects);
175
- case "request_update":
176
- return this.handleRequestUpdate(message, sideEffects);
177
- case "unsubscribe":
178
- return this.handleUnsubscribe(message, sideEffects);
171
+ case 'subscribe':
172
+ return this.handleSubscribe(message, sideEffects)
173
+ case 'subscribe_ok':
174
+ return this.handleSubscribeOk(message, sideEffects)
175
+ case 'request_update':
176
+ return this.handleRequestUpdate(message, sideEffects)
177
+ case 'unsubscribe':
178
+ return this.handleUnsubscribe(message, sideEffects)
179
179
 
180
180
  // Publish lifecycle
181
- case "publish":
182
- return this.handlePublish(message, sideEffects);
183
- case "publish_ok":
184
- return this.handlePublishOk(message, sideEffects);
185
- case "publish_done":
186
- return this.handlePublishDone(message, sideEffects);
181
+ case 'publish':
182
+ return this.handlePublish(message, sideEffects)
183
+ case 'publish_ok':
184
+ return this.handlePublishOk(message, sideEffects)
185
+ case 'publish_done':
186
+ return this.handlePublishDone(message, sideEffects)
187
187
 
188
188
  // Fetch lifecycle
189
- case "fetch":
190
- return this.handleFetch(message, sideEffects);
191
- case "fetch_ok":
192
- return this.handleFetchOk(message, sideEffects);
193
- case "fetch_cancel":
194
- return this.handleFetchCancel(message, sideEffects);
189
+ case 'fetch':
190
+ return this.handleFetch(message, sideEffects)
191
+ case 'fetch_ok':
192
+ return this.handleFetchOk(message, sideEffects)
193
+ case 'fetch_cancel':
194
+ return this.handleFetchCancel(message, sideEffects)
195
195
 
196
196
  // Consolidated responses
197
- case "request_ok":
198
- return this.handleRequestOk(message, sideEffects);
199
- case "request_error":
200
- return this.handleRequestError(message, sideEffects);
197
+ case 'request_ok':
198
+ return this.handleRequestOk(message, sideEffects)
199
+ case 'request_error':
200
+ return this.handleRequestError(message, sideEffects)
201
201
 
202
202
  // Namespace and track status — register request IDs
203
- case "publish_namespace":
204
- return this.handlePublishNamespace(message, sideEffects);
205
- case "subscribe_namespace":
206
- return this.handleSubscribeNamespace(message, sideEffects);
207
- case "track_status":
208
- return this.handleTrackStatus(message, sideEffects);
203
+ case 'publish_namespace':
204
+ return this.handlePublishNamespace(message, sideEffects)
205
+ case 'subscribe_namespace':
206
+ return this.handleSubscribeNamespace(message, sideEffects)
207
+ case 'track_status':
208
+ return this.handleTrackStatus(message, sideEffects)
209
209
 
210
210
  // Other ready-phase messages
211
211
  default:
212
- return this.handleReadyPhaseMessage(message);
212
+ return this.handleReadyPhaseMessage(message)
213
213
  }
214
214
  }
215
215
 
216
216
  private handleClientSetup(
217
- direction: "inbound" | "outbound",
217
+ direction: 'inbound' | 'outbound',
218
218
  ): TransitionResult<Draft16MessageType> {
219
- if (this._phase !== "idle") {
219
+ if (this._phase !== 'idle') {
220
220
  return {
221
221
  ok: false,
222
222
  violation: violation(
223
- "SETUP_VIOLATION",
224
- "CLIENT_SETUP already sent/received",
223
+ 'SETUP_VIOLATION',
224
+ 'CLIENT_SETUP already sent/received',
225
225
  this._phase,
226
- "client_setup",
226
+ 'client_setup',
227
227
  ),
228
- };
228
+ }
229
229
  }
230
- if (direction === "outbound" && this._role !== "client") {
230
+ if (direction === 'outbound' && this._role !== 'client') {
231
231
  return {
232
232
  ok: false,
233
233
  violation: violation(
234
- "ROLE_VIOLATION",
235
- "Only client can send CLIENT_SETUP",
234
+ 'ROLE_VIOLATION',
235
+ 'Only client can send CLIENT_SETUP',
236
236
  this._phase,
237
- "client_setup",
237
+ 'client_setup',
238
238
  ),
239
- };
239
+ }
240
240
  }
241
- this._phase = "setup";
242
- return { ok: true, phase: this._phase, sideEffects: [] };
241
+ this._phase = 'setup'
242
+ return { ok: true, phase: this._phase, sideEffects: [] }
243
243
  }
244
244
 
245
245
  private handleServerSetup(
246
- direction: "inbound" | "outbound",
246
+ direction: 'inbound' | 'outbound',
247
247
  ): TransitionResult<Draft16MessageType> {
248
- if (this._phase !== "setup") {
248
+ if (this._phase !== 'setup') {
249
249
  return {
250
250
  ok: false,
251
251
  violation: violation(
252
- "SETUP_VIOLATION",
253
- "SERVER_SETUP before CLIENT_SETUP",
252
+ 'SETUP_VIOLATION',
253
+ 'SERVER_SETUP before CLIENT_SETUP',
254
254
  this._phase,
255
- "server_setup",
255
+ 'server_setup',
256
256
  ),
257
- };
257
+ }
258
258
  }
259
- if (direction === "outbound" && this._role !== "server") {
259
+ if (direction === 'outbound' && this._role !== 'server') {
260
260
  return {
261
261
  ok: false,
262
262
  violation: violation(
263
- "ROLE_VIOLATION",
264
- "Only server can send SERVER_SETUP",
263
+ 'ROLE_VIOLATION',
264
+ 'Only server can send SERVER_SETUP',
265
265
  this._phase,
266
- "server_setup",
266
+ 'server_setup',
267
267
  ),
268
- };
268
+ }
269
+ }
270
+ this._phase = 'ready'
271
+ return {
272
+ ok: true,
273
+ phase: this._phase,
274
+ sideEffects: [{ type: 'session-ready' }],
269
275
  }
270
- this._phase = "ready";
271
- return { ok: true, phase: this._phase, sideEffects: [{ type: "session-ready" }] };
272
276
  }
273
277
 
274
278
  private handleGoAway(
275
279
  message: Draft16Message,
276
280
  sideEffects: SideEffect[],
277
281
  ): TransitionResult<Draft16MessageType> {
278
- if (this._phase !== "ready" && this._phase !== "draining") {
282
+ if (this._phase !== 'ready' && this._phase !== 'draining') {
279
283
  return {
280
284
  ok: false,
281
285
  violation: violation(
282
- "UNEXPECTED_MESSAGE",
286
+ 'UNEXPECTED_MESSAGE',
283
287
  `GOAWAY not valid in phase ${this._phase}`,
284
288
  this._phase,
285
- "goaway",
289
+ 'goaway',
286
290
  ),
287
- };
291
+ }
288
292
  }
289
- this._phase = "draining";
290
- const goaway = message as import("./types.js").Draft16GoAway;
291
- sideEffects.push({ type: "session-draining", goAwayUri: goaway.new_session_uri });
292
- return { ok: true, phase: this._phase, sideEffects };
293
+ this._phase = 'draining'
294
+ const goaway = message as import('./types.js').Draft16GoAway
295
+ sideEffects.push({
296
+ type: 'session-draining',
297
+ goAwayUri: goaway.new_session_uri,
298
+ })
299
+ return { ok: true, phase: this._phase, sideEffects }
293
300
  }
294
301
 
295
302
  private requireReady(msgType: Draft16MessageType): ProtocolViolation<Draft16MessageType> | null {
296
- if (this._phase !== "ready" && this._phase !== "draining") {
303
+ if (this._phase !== 'ready' && this._phase !== 'draining') {
297
304
  return violation(
298
- this._phase === "idle" || this._phase === "setup"
299
- ? "MESSAGE_BEFORE_SETUP"
300
- : "UNEXPECTED_MESSAGE",
305
+ this._phase === 'idle' || this._phase === 'setup'
306
+ ? 'MESSAGE_BEFORE_SETUP'
307
+ : 'UNEXPECTED_MESSAGE',
301
308
  `${msgType} requires ready phase, current: ${this._phase}`,
302
309
  this._phase,
303
310
  msgType,
304
- );
311
+ )
305
312
  }
306
- return null;
313
+ return null
307
314
  }
308
315
 
309
316
  private handleSubscribe(
310
317
  message: Draft16Message,
311
318
  sideEffects: SideEffect[],
312
319
  ): TransitionResult<Draft16MessageType> {
313
- const err = this.requireReady(message.type);
314
- if (err) return { ok: false, violation: err };
315
- const sub = message as import("./types.js").Draft16Subscribe;
316
- const dupErr = this.checkDuplicateRequestId(sub.request_id, message.type);
317
- if (dupErr) return { ok: false, violation: dupErr };
318
- this._requestIds.add(sub.request_id);
320
+ const err = this.requireReady(message.type)
321
+ if (err) return { ok: false, violation: err }
322
+ const sub = message as import('./types.js').Draft16Subscribe
323
+ const dupErr = this.checkDuplicateRequestId(sub.request_id, message.type)
324
+ if (dupErr) return { ok: false, violation: dupErr }
325
+ this._requestIds.add(sub.request_id)
319
326
  this._subscriptions.set(sub.request_id, {
320
327
  subscribeId: sub.request_id,
321
- phase: "pending",
328
+ phase: 'pending',
322
329
  trackNamespace: sub.track_namespace,
323
330
  trackName: sub.track_name,
324
- });
325
- return { ok: true, phase: this._phase, sideEffects };
331
+ })
332
+ return { ok: true, phase: this._phase, sideEffects }
326
333
  }
327
334
 
328
335
  private handleSubscribeOk(
329
336
  message: Draft16Message,
330
337
  sideEffects: SideEffect[],
331
338
  ): TransitionResult<Draft16MessageType> {
332
- const err = this.requireReady(message.type);
333
- if (err) return { ok: false, violation: err };
334
- const ok = message as import("./types.js").Draft16SubscribeOk;
335
- const idErr = this.checkKnownRequestId(ok.request_id, message.type);
336
- if (idErr) return { ok: false, violation: idErr };
337
- const existing = this._subscriptions.get(ok.request_id);
339
+ const err = this.requireReady(message.type)
340
+ if (err) return { ok: false, violation: err }
341
+ const ok = message as import('./types.js').Draft16SubscribeOk
342
+ const idErr = this.checkKnownRequestId(ok.request_id, message.type)
343
+ if (idErr) return { ok: false, violation: idErr }
344
+ const existing = this._subscriptions.get(ok.request_id)
338
345
  if (!existing)
339
346
  return {
340
347
  ok: false,
341
348
  violation: violation(
342
- "UNKNOWN_REQUEST_ID",
349
+ 'UNKNOWN_REQUEST_ID',
343
350
  `No subscription with request ID ${ok.request_id}`,
344
351
  this._phase,
345
352
  message.type,
346
353
  ),
347
- };
348
- if (existing.phase !== "pending")
354
+ }
355
+ if (existing.phase !== 'pending')
349
356
  return {
350
357
  ok: false,
351
358
  violation: violation(
352
- "STATE_VIOLATION",
359
+ 'STATE_VIOLATION',
353
360
  `Subscription ${ok.request_id} is ${existing.phase}, not pending`,
354
361
  this._phase,
355
362
  message.type,
356
363
  ),
357
- };
358
- this._subscriptions.set(ok.request_id, { ...existing, phase: "active" });
359
- sideEffects.push({ type: "subscription-activated", subscribeId: ok.request_id });
360
- return { ok: true, phase: this._phase, sideEffects };
364
+ }
365
+ this._subscriptions.set(ok.request_id, { ...existing, phase: 'active' })
366
+ sideEffects.push({
367
+ type: 'subscription-activated',
368
+ subscribeId: ok.request_id,
369
+ })
370
+ return { ok: true, phase: this._phase, sideEffects }
361
371
  }
362
372
 
363
373
  // Renamed from handleSubscribeUpdate in draft-15
@@ -365,264 +375,274 @@ export class Draft16SessionFSM {
365
375
  message: Draft16Message,
366
376
  sideEffects: SideEffect[],
367
377
  ): TransitionResult<Draft16MessageType> {
368
- const err = this.requireReady(message.type);
369
- if (err) return { ok: false, violation: err };
370
- const update = message as import("./types.js").Draft16RequestUpdate;
371
- const dupErr = this.checkDuplicateRequestId(update.request_id, message.type);
372
- if (dupErr) return { ok: false, violation: dupErr };
373
- this._requestIds.add(update.request_id);
374
- const existing = this._subscriptions.get(update.existing_request_id);
378
+ const err = this.requireReady(message.type)
379
+ if (err) return { ok: false, violation: err }
380
+ const update = message as import('./types.js').Draft16RequestUpdate
381
+ const dupErr = this.checkDuplicateRequestId(update.request_id, message.type)
382
+ if (dupErr) return { ok: false, violation: dupErr }
383
+ this._requestIds.add(update.request_id)
384
+ const existing = this._subscriptions.get(update.existing_request_id)
375
385
  if (!existing)
376
386
  return {
377
387
  ok: false,
378
388
  violation: violation(
379
- "UNKNOWN_REQUEST_ID",
389
+ 'UNKNOWN_REQUEST_ID',
380
390
  `No subscription with request ID ${update.existing_request_id}`,
381
391
  this._phase,
382
392
  message.type,
383
393
  ),
384
- };
385
- if (existing.phase !== "active")
394
+ }
395
+ if (existing.phase !== 'active')
386
396
  return {
387
397
  ok: false,
388
398
  violation: violation(
389
- "STATE_VIOLATION",
399
+ 'STATE_VIOLATION',
390
400
  `Subscription ${update.existing_request_id} is ${existing.phase}, not active`,
391
401
  this._phase,
392
402
  message.type,
393
403
  ),
394
- };
395
- return { ok: true, phase: this._phase, sideEffects };
404
+ }
405
+ return { ok: true, phase: this._phase, sideEffects }
396
406
  }
397
407
 
398
408
  private handleUnsubscribe(
399
409
  message: Draft16Message,
400
410
  sideEffects: SideEffect[],
401
411
  ): TransitionResult<Draft16MessageType> {
402
- const err = this.requireReady(message.type);
403
- if (err) return { ok: false, violation: err };
404
- const unsub = message as import("./types.js").Draft16Unsubscribe;
405
- const idErr = this.checkKnownRequestId(unsub.request_id, message.type);
406
- if (idErr) return { ok: false, violation: idErr };
407
- const existing = this._subscriptions.get(unsub.request_id);
412
+ const err = this.requireReady(message.type)
413
+ if (err) return { ok: false, violation: err }
414
+ const unsub = message as import('./types.js').Draft16Unsubscribe
415
+ const idErr = this.checkKnownRequestId(unsub.request_id, message.type)
416
+ if (idErr) return { ok: false, violation: idErr }
417
+ const existing = this._subscriptions.get(unsub.request_id)
408
418
  if (!existing)
409
419
  return {
410
420
  ok: false,
411
421
  violation: violation(
412
- "UNKNOWN_REQUEST_ID",
422
+ 'UNKNOWN_REQUEST_ID',
413
423
  `No subscription with request ID ${unsub.request_id}`,
414
424
  this._phase,
415
425
  message.type,
416
426
  ),
417
- };
418
- this._subscriptions.set(unsub.request_id, { ...existing, phase: "done" });
427
+ }
428
+ this._subscriptions.set(unsub.request_id, { ...existing, phase: 'done' })
419
429
  sideEffects.push({
420
- type: "subscription-ended",
430
+ type: 'subscription-ended',
421
431
  subscribeId: unsub.request_id,
422
- reason: "unsubscribed",
423
- });
424
- return { ok: true, phase: this._phase, sideEffects };
432
+ reason: 'unsubscribed',
433
+ })
434
+ return { ok: true, phase: this._phase, sideEffects }
425
435
  }
426
436
 
427
437
  private handlePublish(
428
438
  message: Draft16Message,
429
439
  sideEffects: SideEffect[],
430
440
  ): TransitionResult<Draft16MessageType> {
431
- const err = this.requireReady(message.type);
432
- if (err) return { ok: false, violation: err };
433
- const pub = message as import("./types.js").Draft16Publish;
434
- const dupErr = this.checkDuplicateRequestId(pub.request_id, message.type);
435
- if (dupErr) return { ok: false, violation: dupErr };
436
- this._requestIds.add(pub.request_id);
437
- this._publishes.set(pub.request_id, { requestId: pub.request_id, phase: "pending" });
438
- return { ok: true, phase: this._phase, sideEffects };
441
+ const err = this.requireReady(message.type)
442
+ if (err) return { ok: false, violation: err }
443
+ const pub = message as import('./types.js').Draft16Publish
444
+ const dupErr = this.checkDuplicateRequestId(pub.request_id, message.type)
445
+ if (dupErr) return { ok: false, violation: dupErr }
446
+ this._requestIds.add(pub.request_id)
447
+ this._publishes.set(pub.request_id, {
448
+ requestId: pub.request_id,
449
+ phase: 'pending',
450
+ })
451
+ return { ok: true, phase: this._phase, sideEffects }
439
452
  }
440
453
 
441
454
  private handlePublishOk(
442
455
  message: Draft16Message,
443
456
  sideEffects: SideEffect[],
444
457
  ): TransitionResult<Draft16MessageType> {
445
- const err = this.requireReady(message.type);
446
- if (err) return { ok: false, violation: err };
447
- const ok = message as import("./types.js").Draft16PublishOk;
448
- const idErr = this.checkKnownRequestId(ok.request_id, message.type);
449
- if (idErr) return { ok: false, violation: idErr };
450
- const existing = this._publishes.get(ok.request_id);
458
+ const err = this.requireReady(message.type)
459
+ if (err) return { ok: false, violation: err }
460
+ const ok = message as import('./types.js').Draft16PublishOk
461
+ const idErr = this.checkKnownRequestId(ok.request_id, message.type)
462
+ if (idErr) return { ok: false, violation: idErr }
463
+ const existing = this._publishes.get(ok.request_id)
451
464
  if (!existing)
452
465
  return {
453
466
  ok: false,
454
467
  violation: violation(
455
- "UNKNOWN_REQUEST_ID",
468
+ 'UNKNOWN_REQUEST_ID',
456
469
  `No publish with request ID ${ok.request_id}`,
457
470
  this._phase,
458
471
  message.type,
459
472
  ),
460
- };
461
- if (existing.phase !== "pending")
473
+ }
474
+ if (existing.phase !== 'pending')
462
475
  return {
463
476
  ok: false,
464
477
  violation: violation(
465
- "STATE_VIOLATION",
478
+ 'STATE_VIOLATION',
466
479
  `Publish ${ok.request_id} is ${existing.phase}, not pending`,
467
480
  this._phase,
468
481
  message.type,
469
482
  ),
470
- };
471
- this._publishes.set(ok.request_id, { ...existing, phase: "active" });
472
- sideEffects.push({ type: "publish-activated", requestId: ok.request_id });
473
- return { ok: true, phase: this._phase, sideEffects };
483
+ }
484
+ this._publishes.set(ok.request_id, { ...existing, phase: 'active' })
485
+ sideEffects.push({ type: 'publish-activated', requestId: ok.request_id })
486
+ return { ok: true, phase: this._phase, sideEffects }
474
487
  }
475
488
 
476
489
  private handlePublishDone(
477
490
  message: Draft16Message,
478
491
  sideEffects: SideEffect[],
479
492
  ): TransitionResult<Draft16MessageType> {
480
- const err = this.requireReady(message.type);
481
- if (err) return { ok: false, violation: err };
482
- const done = message as import("./types.js").Draft16PublishDone;
483
- const idErr = this.checkKnownRequestId(done.request_id, message.type);
484
- if (idErr) return { ok: false, violation: idErr };
485
- const existing = this._publishes.get(done.request_id);
493
+ const err = this.requireReady(message.type)
494
+ if (err) return { ok: false, violation: err }
495
+ const done = message as import('./types.js').Draft16PublishDone
496
+ const idErr = this.checkKnownRequestId(done.request_id, message.type)
497
+ if (idErr) return { ok: false, violation: idErr }
498
+ const existing = this._publishes.get(done.request_id)
486
499
  if (!existing)
487
500
  return {
488
501
  ok: false,
489
502
  violation: violation(
490
- "UNKNOWN_REQUEST_ID",
503
+ 'UNKNOWN_REQUEST_ID',
491
504
  `No publish with request ID ${done.request_id}`,
492
505
  this._phase,
493
506
  message.type,
494
507
  ),
495
- };
496
- this._publishes.set(done.request_id, { ...existing, phase: "done" });
508
+ }
509
+ this._publishes.set(done.request_id, { ...existing, phase: 'done' })
497
510
  sideEffects.push({
498
- type: "publish-ended",
511
+ type: 'publish-ended',
499
512
  requestId: done.request_id,
500
513
  reason: done.reason_phrase,
501
- });
502
- return { ok: true, phase: this._phase, sideEffects };
514
+ })
515
+ return { ok: true, phase: this._phase, sideEffects }
503
516
  }
504
517
 
505
518
  private handleFetch(
506
519
  message: Draft16Message,
507
520
  sideEffects: SideEffect[],
508
521
  ): TransitionResult<Draft16MessageType> {
509
- const err = this.requireReady(message.type);
510
- if (err) return { ok: false, violation: err };
511
- const fetch = message as import("./types.js").Draft16Fetch;
512
- const dupErr = this.checkDuplicateRequestId(fetch.request_id, message.type);
513
- if (dupErr) return { ok: false, violation: dupErr };
514
- this._requestIds.add(fetch.request_id);
515
- this._fetches.set(fetch.request_id, { requestId: fetch.request_id, phase: "pending" });
516
- return { ok: true, phase: this._phase, sideEffects };
522
+ const err = this.requireReady(message.type)
523
+ if (err) return { ok: false, violation: err }
524
+ const fetch = message as import('./types.js').Draft16Fetch
525
+ const dupErr = this.checkDuplicateRequestId(fetch.request_id, message.type)
526
+ if (dupErr) return { ok: false, violation: dupErr }
527
+ this._requestIds.add(fetch.request_id)
528
+ this._fetches.set(fetch.request_id, {
529
+ requestId: fetch.request_id,
530
+ phase: 'pending',
531
+ })
532
+ return { ok: true, phase: this._phase, sideEffects }
517
533
  }
518
534
 
519
535
  private handleFetchOk(
520
536
  message: Draft16Message,
521
537
  sideEffects: SideEffect[],
522
538
  ): TransitionResult<Draft16MessageType> {
523
- const err = this.requireReady(message.type);
524
- if (err) return { ok: false, violation: err };
525
- const ok = message as import("./types.js").Draft16FetchOk;
526
- const idErr = this.checkKnownRequestId(ok.request_id, message.type);
527
- if (idErr) return { ok: false, violation: idErr };
528
- const existing = this._fetches.get(ok.request_id);
539
+ const err = this.requireReady(message.type)
540
+ if (err) return { ok: false, violation: err }
541
+ const ok = message as import('./types.js').Draft16FetchOk
542
+ const idErr = this.checkKnownRequestId(ok.request_id, message.type)
543
+ if (idErr) return { ok: false, violation: idErr }
544
+ const existing = this._fetches.get(ok.request_id)
529
545
  if (!existing)
530
546
  return {
531
547
  ok: false,
532
548
  violation: violation(
533
- "UNKNOWN_REQUEST_ID",
549
+ 'UNKNOWN_REQUEST_ID',
534
550
  `No fetch with request ID ${ok.request_id}`,
535
551
  this._phase,
536
552
  message.type,
537
553
  ),
538
- };
539
- if (existing.phase !== "pending")
554
+ }
555
+ if (existing.phase !== 'pending')
540
556
  return {
541
557
  ok: false,
542
558
  violation: violation(
543
- "STATE_VIOLATION",
559
+ 'STATE_VIOLATION',
544
560
  `Fetch ${ok.request_id} is ${existing.phase}, not pending`,
545
561
  this._phase,
546
562
  message.type,
547
563
  ),
548
- };
549
- this._fetches.set(ok.request_id, { ...existing, phase: "active" });
550
- sideEffects.push({ type: "fetch-activated", requestId: ok.request_id });
551
- return { ok: true, phase: this._phase, sideEffects };
564
+ }
565
+ this._fetches.set(ok.request_id, { ...existing, phase: 'active' })
566
+ sideEffects.push({ type: 'fetch-activated', requestId: ok.request_id })
567
+ return { ok: true, phase: this._phase, sideEffects }
552
568
  }
553
569
 
554
570
  private handleFetchCancel(
555
571
  message: Draft16Message,
556
572
  sideEffects: SideEffect[],
557
573
  ): TransitionResult<Draft16MessageType> {
558
- const err = this.requireReady(message.type);
559
- if (err) return { ok: false, violation: err };
560
- const cancel = message as import("./types.js").Draft16FetchCancel;
561
- const idErr = this.checkKnownRequestId(cancel.request_id, message.type);
562
- if (idErr) return { ok: false, violation: idErr };
563
- const existing = this._fetches.get(cancel.request_id);
574
+ const err = this.requireReady(message.type)
575
+ if (err) return { ok: false, violation: err }
576
+ const cancel = message as import('./types.js').Draft16FetchCancel
577
+ const idErr = this.checkKnownRequestId(cancel.request_id, message.type)
578
+ if (idErr) return { ok: false, violation: idErr }
579
+ const existing = this._fetches.get(cancel.request_id)
564
580
  if (!existing)
565
581
  return {
566
582
  ok: false,
567
583
  violation: violation(
568
- "UNKNOWN_REQUEST_ID",
584
+ 'UNKNOWN_REQUEST_ID',
569
585
  `No fetch with request ID ${cancel.request_id}`,
570
586
  this._phase,
571
587
  message.type,
572
588
  ),
573
- };
574
- this._fetches.set(cancel.request_id, { ...existing, phase: "cancelled" });
575
- sideEffects.push({ type: "fetch-ended", requestId: cancel.request_id, reason: "cancelled" });
576
- return { ok: true, phase: this._phase, sideEffects };
589
+ }
590
+ this._fetches.set(cancel.request_id, { ...existing, phase: 'cancelled' })
591
+ sideEffects.push({
592
+ type: 'fetch-ended',
593
+ requestId: cancel.request_id,
594
+ reason: 'cancelled',
595
+ })
596
+ return { ok: true, phase: this._phase, sideEffects }
577
597
  }
578
598
 
579
599
  private handleRequestError(
580
600
  message: Draft16Message,
581
601
  sideEffects: SideEffect[],
582
602
  ): TransitionResult<Draft16MessageType> {
583
- const err = this.requireReady(message.type);
584
- if (err) return { ok: false, violation: err };
585
- const reqErr = message as import("./types.js").Draft16RequestError;
586
- const sub = this._subscriptions.get(reqErr.request_id);
587
- if (sub && sub.phase === "pending") {
588
- this._subscriptions.set(reqErr.request_id, { ...sub, phase: "error" });
603
+ const err = this.requireReady(message.type)
604
+ if (err) return { ok: false, violation: err }
605
+ const reqErr = message as import('./types.js').Draft16RequestError
606
+ const sub = this._subscriptions.get(reqErr.request_id)
607
+ if (sub && sub.phase === 'pending') {
608
+ this._subscriptions.set(reqErr.request_id, { ...sub, phase: 'error' })
589
609
  sideEffects.push({
590
- type: "subscription-ended",
610
+ type: 'subscription-ended',
591
611
  subscribeId: reqErr.request_id,
592
612
  reason: reqErr.reason_phrase,
593
- });
594
- return { ok: true, phase: this._phase, sideEffects };
613
+ })
614
+ return { ok: true, phase: this._phase, sideEffects }
595
615
  }
596
- const pub = this._publishes.get(reqErr.request_id);
597
- if (pub && pub.phase === "pending") {
598
- this._publishes.set(reqErr.request_id, { ...pub, phase: "error" });
616
+ const pub = this._publishes.get(reqErr.request_id)
617
+ if (pub && pub.phase === 'pending') {
618
+ this._publishes.set(reqErr.request_id, { ...pub, phase: 'error' })
599
619
  sideEffects.push({
600
- type: "publish-ended",
620
+ type: 'publish-ended',
601
621
  requestId: reqErr.request_id,
602
622
  reason: reqErr.reason_phrase,
603
- });
604
- return { ok: true, phase: this._phase, sideEffects };
623
+ })
624
+ return { ok: true, phase: this._phase, sideEffects }
605
625
  }
606
- const fetch = this._fetches.get(reqErr.request_id);
607
- if (fetch && fetch.phase === "pending") {
608
- this._fetches.set(reqErr.request_id, { ...fetch, phase: "error" });
626
+ const fetch = this._fetches.get(reqErr.request_id)
627
+ if (fetch && fetch.phase === 'pending') {
628
+ this._fetches.set(reqErr.request_id, { ...fetch, phase: 'error' })
609
629
  sideEffects.push({
610
- type: "fetch-ended",
630
+ type: 'fetch-ended',
611
631
  requestId: reqErr.request_id,
612
632
  reason: reqErr.reason_phrase,
613
- });
614
- return { ok: true, phase: this._phase, sideEffects };
633
+ })
634
+ return { ok: true, phase: this._phase, sideEffects }
615
635
  }
616
- return { ok: true, phase: this._phase, sideEffects };
636
+ return { ok: true, phase: this._phase, sideEffects }
617
637
  }
618
638
 
619
639
  private handleRequestOk(
620
640
  message: Draft16Message,
621
641
  sideEffects: SideEffect[],
622
642
  ): TransitionResult<Draft16MessageType> {
623
- const err = this.requireReady(message.type);
624
- if (err) return { ok: false, violation: err };
625
- return { ok: true, phase: this._phase, sideEffects };
643
+ const err = this.requireReady(message.type)
644
+ if (err) return { ok: false, violation: err }
645
+ return { ok: true, phase: this._phase, sideEffects }
626
646
  }
627
647
 
628
648
  // ─── Namespace and track status request ID tracking ───
@@ -631,52 +651,52 @@ export class Draft16SessionFSM {
631
651
  message: Draft16Message,
632
652
  sideEffects: SideEffect[],
633
653
  ): TransitionResult<Draft16MessageType> {
634
- const err = this.requireReady(message.type);
635
- if (err) return { ok: false, violation: err };
636
- const pn = message as import("./types.js").Draft16PublishNamespace;
637
- const dupErr = this.checkDuplicateRequestId(pn.request_id, message.type);
638
- if (dupErr) return { ok: false, violation: dupErr };
639
- this._requestIds.add(pn.request_id);
640
- return { ok: true, phase: this._phase, sideEffects };
654
+ const err = this.requireReady(message.type)
655
+ if (err) return { ok: false, violation: err }
656
+ const pn = message as import('./types.js').Draft16PublishNamespace
657
+ const dupErr = this.checkDuplicateRequestId(pn.request_id, message.type)
658
+ if (dupErr) return { ok: false, violation: dupErr }
659
+ this._requestIds.add(pn.request_id)
660
+ return { ok: true, phase: this._phase, sideEffects }
641
661
  }
642
662
 
643
663
  private handleSubscribeNamespace(
644
664
  message: Draft16Message,
645
665
  sideEffects: SideEffect[],
646
666
  ): TransitionResult<Draft16MessageType> {
647
- const err = this.requireReady(message.type);
648
- if (err) return { ok: false, violation: err };
649
- const sn = message as import("./types.js").Draft16SubscribeNamespace;
650
- const dupErr = this.checkDuplicateRequestId(sn.request_id, message.type);
651
- if (dupErr) return { ok: false, violation: dupErr };
652
- this._requestIds.add(sn.request_id);
653
- return { ok: true, phase: this._phase, sideEffects };
667
+ const err = this.requireReady(message.type)
668
+ if (err) return { ok: false, violation: err }
669
+ const sn = message as import('./types.js').Draft16SubscribeNamespace
670
+ const dupErr = this.checkDuplicateRequestId(sn.request_id, message.type)
671
+ if (dupErr) return { ok: false, violation: dupErr }
672
+ this._requestIds.add(sn.request_id)
673
+ return { ok: true, phase: this._phase, sideEffects }
654
674
  }
655
675
 
656
676
  private handleTrackStatus(
657
677
  message: Draft16Message,
658
678
  sideEffects: SideEffect[],
659
679
  ): TransitionResult<Draft16MessageType> {
660
- const err = this.requireReady(message.type);
661
- if (err) return { ok: false, violation: err };
662
- const ts = message as import("./types.js").Draft16TrackStatus;
663
- const dupErr = this.checkDuplicateRequestId(ts.request_id, message.type);
664
- if (dupErr) return { ok: false, violation: dupErr };
665
- this._requestIds.add(ts.request_id);
666
- return { ok: true, phase: this._phase, sideEffects };
680
+ const err = this.requireReady(message.type)
681
+ if (err) return { ok: false, violation: err }
682
+ const ts = message as import('./types.js').Draft16TrackStatus
683
+ const dupErr = this.checkDuplicateRequestId(ts.request_id, message.type)
684
+ if (dupErr) return { ok: false, violation: dupErr }
685
+ this._requestIds.add(ts.request_id)
686
+ return { ok: true, phase: this._phase, sideEffects }
667
687
  }
668
688
 
669
689
  private handleReadyPhaseMessage(message: Draft16Message): TransitionResult<Draft16MessageType> {
670
- const err = this.requireReady(message.type);
671
- if (err) return { ok: false, violation: err };
672
- return { ok: true, phase: this._phase, sideEffects: [] };
690
+ const err = this.requireReady(message.type)
691
+ if (err) return { ok: false, violation: err }
692
+ return { ok: true, phase: this._phase, sideEffects: [] }
673
693
  }
674
694
 
675
695
  reset(): void {
676
- this._phase = "idle";
677
- this._subscriptions.clear();
678
- this._publishes.clear();
679
- this._fetches.clear();
680
- this._requestIds.clear();
696
+ this._phase = 'idle'
697
+ this._subscriptions.clear()
698
+ this._publishes.clear()
699
+ this._fetches.clear()
700
+ this._requestIds.clear()
681
701
  }
682
702
  }