@moqtap/codec 0.1.0 → 0.2.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 (277) hide show
  1. package/README.md +99 -95
  2. package/dist/chunk-4RIXXEII.js +1275 -0
  3. package/dist/chunk-4XYGE53S.cjs +698 -0
  4. package/dist/chunk-4YJANAXU.cjs +1109 -0
  5. package/dist/chunk-6AEHWULA.cjs +641 -0
  6. package/dist/chunk-7DUBLRXC.js +680 -0
  7. package/dist/{chunk-WNTXF3DE.cjs → chunk-7IVGHMKJ.cjs} +164 -62
  8. package/dist/{chunk-YBSEOSSP.js → chunk-A27S7HW7.js} +5 -1
  9. package/dist/chunk-BISI45MN.cjs +680 -0
  10. package/dist/{chunk-3BSZ55L3.cjs → chunk-BPNL5YFQ.cjs} +158 -24
  11. package/dist/chunk-CXDHOMHG.js +1097 -0
  12. package/dist/chunk-DUBCL3WF.cjs +749 -0
  13. package/dist/chunk-DWK5ZQZ4.js +642 -0
  14. package/dist/chunk-E6E3NQYU.js +680 -0
  15. package/dist/chunk-EFM5T7OM.js +698 -0
  16. package/dist/chunk-ENURAVHI.cjs +680 -0
  17. package/dist/{chunk-5WFXFLL4.cjs → chunk-FUFTMAQD.cjs} +96 -63
  18. package/dist/{chunk-2NARXGVA.cjs → chunk-FWISIR26.cjs} +5 -1
  19. package/dist/{chunk-YPXLV5YK.js → chunk-FXZ2MYKJ.js} +376 -38
  20. package/dist/chunk-G26SJ6XS.cjs +1341 -0
  21. package/dist/chunk-G7GI7LJA.js +737 -0
  22. package/dist/chunk-GXEW4COZ.cjs +737 -0
  23. package/dist/chunk-HSVYF6XX.cjs +1361 -0
  24. package/dist/chunk-IBVM4DMJ.cjs +1097 -0
  25. package/dist/chunk-IV2H5CFI.cjs +1275 -0
  26. package/dist/chunk-IV2HRJVT.js +1198 -0
  27. package/dist/chunk-JSQM2MG3.js +680 -0
  28. package/dist/chunk-K4OLITS2.cjs +1055 -0
  29. package/dist/{chunk-UOBWHJA5.js → chunk-KFTCU2P6.js} +2 -3
  30. package/dist/chunk-LH4NTURO.js +1361 -0
  31. package/dist/{chunk-DC4L6ZIT.js → chunk-MFAP7R6L.js} +154 -20
  32. package/dist/chunk-NGVE2RZT.js +1097 -0
  33. package/dist/chunk-NUX5BHWO.js +1341 -0
  34. package/dist/chunk-PJRA2TQ5.js +1055 -0
  35. package/dist/chunk-RVJAGE4S.cjs +1198 -0
  36. package/dist/{chunk-QYG6KGOV.cjs → chunk-RWQ43Z4F.cjs} +2 -3
  37. package/dist/chunk-RZHAPEXO.js +749 -0
  38. package/dist/chunk-ST24APEO.js +1109 -0
  39. package/dist/chunk-SYHW3FLI.cjs +642 -0
  40. package/dist/chunk-TLYNOOQP.cjs +432 -0
  41. package/dist/{chunk-23YG7F46.js → chunk-TMNGRIPL.js} +153 -51
  42. package/dist/{chunk-IQPDRQVC.js → chunk-U2B3B42P.js} +62 -29
  43. package/dist/chunk-UNS34PTA.cjs +680 -0
  44. package/dist/chunk-UR6JKS56.js +432 -0
  45. package/dist/{chunk-GDRGWFEK.cjs → chunk-UYXTY6ZQ.cjs} +376 -38
  46. package/dist/chunk-XUUCOLWU.cjs +1097 -0
  47. package/dist/chunk-YG5KJESI.js +641 -0
  48. package/dist/chunk-ZBKE2QRQ.js +1401 -0
  49. package/dist/chunk-ZSPO2GF2.cjs +1401 -0
  50. package/dist/codec-95k8CAu5.d.cts +35 -0
  51. package/dist/codec-AFuOxfsO.d.ts +60 -0
  52. package/dist/codec-B-UJ5Iow.d.cts +75 -0
  53. package/dist/codec-BC5jfvMb.d.ts +35 -0
  54. package/dist/codec-BECYPfY8.d.ts +35 -0
  55. package/dist/codec-BsPU1vNC.d.ts +39 -0
  56. package/dist/codec-BvpuF-6u.d.cts +39 -0
  57. package/dist/codec-C8jZI5Cx.d.cts +39 -0
  58. package/dist/codec-CAevkgf5.d.cts +33 -0
  59. package/dist/codec-CSUqCrRs.d.ts +39 -0
  60. package/dist/codec-C_HMXNK_.d.ts +33 -0
  61. package/dist/{codec-CTvFtQQI.d.cts → codec-CpuvYTSV.d.cts} +5 -5
  62. package/dist/codec-D0x8-SCw.d.cts +35 -0
  63. package/dist/codec-D7ARhpG1.d.ts +75 -0
  64. package/dist/codec-DNAUGshO.d.cts +60 -0
  65. package/dist/codec-DPx_QNn0.d.ts +31 -0
  66. package/dist/{codec-qPzfmLNu.d.ts → codec-DRhCx_hw.d.ts} +5 -5
  67. package/dist/codec-Db7YPe3l.d.ts +31 -0
  68. package/dist/codec-axkJpb7D.d.cts +31 -0
  69. package/dist/codec-ujAbFaep.d.cts +31 -0
  70. package/dist/draft10-session.cjs +6 -0
  71. package/dist/draft10-session.d.cts +8 -0
  72. package/dist/draft10-session.d.ts +8 -0
  73. package/dist/draft10-session.js +6 -0
  74. package/dist/draft10.cjs +115 -0
  75. package/dist/draft10.d.cts +95 -0
  76. package/dist/draft10.d.ts +95 -0
  77. package/dist/draft10.js +115 -0
  78. package/dist/draft11-session.cjs +6 -0
  79. package/dist/draft11-session.d.cts +8 -0
  80. package/dist/draft11-session.d.ts +8 -0
  81. package/dist/draft11-session.js +6 -0
  82. package/dist/draft11.cjs +109 -0
  83. package/dist/draft11.d.cts +99 -0
  84. package/dist/draft11.d.ts +99 -0
  85. package/dist/draft11.js +109 -0
  86. package/dist/draft12-session.cjs +6 -0
  87. package/dist/draft12-session.d.cts +8 -0
  88. package/dist/draft12-session.d.ts +8 -0
  89. package/dist/draft12-session.js +6 -0
  90. package/dist/draft12.cjs +117 -0
  91. package/dist/draft12.d.cts +106 -0
  92. package/dist/draft12.d.ts +106 -0
  93. package/dist/draft12.js +117 -0
  94. package/dist/draft13-session.cjs +6 -0
  95. package/dist/draft13-session.d.cts +8 -0
  96. package/dist/draft13-session.d.ts +8 -0
  97. package/dist/draft13-session.js +6 -0
  98. package/dist/draft13.cjs +119 -0
  99. package/dist/draft13.d.cts +108 -0
  100. package/dist/draft13.d.ts +108 -0
  101. package/dist/draft13.js +119 -0
  102. package/dist/draft14-session.cjs +2 -2
  103. package/dist/draft14-session.d.cts +4 -4
  104. package/dist/draft14-session.d.ts +4 -4
  105. package/dist/draft14-session.js +1 -1
  106. package/dist/draft14.cjs +4 -4
  107. package/dist/draft14.d.cts +27 -15
  108. package/dist/draft14.d.ts +27 -15
  109. package/dist/draft14.js +3 -3
  110. package/dist/draft15-session.cjs +6 -0
  111. package/dist/draft15-session.d.cts +8 -0
  112. package/dist/draft15-session.d.ts +8 -0
  113. package/dist/draft15-session.js +6 -0
  114. package/dist/draft15.cjs +111 -0
  115. package/dist/draft15.d.cts +93 -0
  116. package/dist/draft15.d.ts +93 -0
  117. package/dist/draft15.js +111 -0
  118. package/dist/draft16-session.cjs +6 -0
  119. package/dist/draft16-session.d.cts +8 -0
  120. package/dist/draft16-session.d.ts +8 -0
  121. package/dist/draft16-session.js +6 -0
  122. package/dist/draft16.cjs +113 -0
  123. package/dist/draft16.d.cts +94 -0
  124. package/dist/draft16.d.ts +94 -0
  125. package/dist/draft16.js +113 -0
  126. package/dist/draft17-session.cjs +8 -0
  127. package/dist/draft17-session.d.cts +51 -0
  128. package/dist/draft17-session.d.ts +51 -0
  129. package/dist/draft17-session.js +8 -0
  130. package/dist/draft17.cjs +99 -0
  131. package/dist/draft17.d.cts +40 -0
  132. package/dist/draft17.d.ts +40 -0
  133. package/dist/draft17.js +99 -0
  134. package/dist/draft7-session.cjs +3 -3
  135. package/dist/draft7-session.d.cts +3 -3
  136. package/dist/draft7-session.d.ts +3 -3
  137. package/dist/draft7-session.js +2 -2
  138. package/dist/draft7.cjs +6 -6
  139. package/dist/draft7.d.cts +10 -10
  140. package/dist/draft7.d.ts +10 -10
  141. package/dist/draft7.js +3 -3
  142. package/dist/draft8-session.cjs +6 -0
  143. package/dist/draft8-session.d.cts +8 -0
  144. package/dist/draft8-session.d.ts +8 -0
  145. package/dist/draft8-session.js +6 -0
  146. package/dist/draft8.cjs +115 -0
  147. package/dist/draft8.d.cts +95 -0
  148. package/dist/draft8.d.ts +95 -0
  149. package/dist/draft8.js +115 -0
  150. package/dist/draft9-session.cjs +6 -0
  151. package/dist/draft9-session.d.cts +8 -0
  152. package/dist/draft9-session.d.ts +8 -0
  153. package/dist/draft9-session.js +6 -0
  154. package/dist/draft9.cjs +115 -0
  155. package/dist/draft9.d.cts +95 -0
  156. package/dist/draft9.d.ts +95 -0
  157. package/dist/draft9.js +115 -0
  158. package/dist/index.cjs +79 -7
  159. package/dist/index.d.cts +71 -8
  160. package/dist/index.d.ts +71 -8
  161. package/dist/index.js +77 -5
  162. package/dist/{session-types-B9NIf7_F.d.ts → session-types-CJIFbTPd.d.ts} +20 -20
  163. package/dist/{session-types-CCo-oA-d.d.cts → session-types-Cbq8IGCP.d.cts} +20 -20
  164. package/dist/session.cjs +5 -5
  165. package/dist/session.d.cts +3 -3
  166. package/dist/session.d.ts +3 -3
  167. package/dist/session.js +5 -5
  168. package/dist/types-4VxSL2Ho.d.cts +261 -0
  169. package/dist/types-4VxSL2Ho.d.ts +261 -0
  170. package/dist/types-B2afJZM-.d.cts +236 -0
  171. package/dist/types-B2afJZM-.d.ts +236 -0
  172. package/dist/{types-CIk5W10V.d.ts → types-BTFeKYCb.d.cts} +37 -37
  173. package/dist/{types-CIk5W10V.d.cts → types-BTFeKYCb.d.ts} +37 -37
  174. package/dist/types-Bg6QYNVt.d.cts +290 -0
  175. package/dist/types-Bg6QYNVt.d.ts +290 -0
  176. package/dist/types-C_1HrqBl.d.cts +306 -0
  177. package/dist/types-C_1HrqBl.d.ts +306 -0
  178. package/dist/types-Cw4WE9dh.d.cts +261 -0
  179. package/dist/types-Cw4WE9dh.d.ts +261 -0
  180. package/dist/types-D5gNQiDj.d.cts +261 -0
  181. package/dist/types-D5gNQiDj.d.ts +261 -0
  182. package/dist/types-DqCDFqgB.d.cts +230 -0
  183. package/dist/types-DqCDFqgB.d.ts +230 -0
  184. package/dist/types-ERexTpT8.d.cts +217 -0
  185. package/dist/types-ERexTpT8.d.ts +217 -0
  186. package/dist/{types-ClXELFGN.d.cts → types-QNXoxC9Y.d.cts} +36 -41
  187. package/dist/{types-ClXELFGN.d.ts → types-QNXoxC9Y.d.ts} +36 -41
  188. package/dist/types-r-CasCf1.d.cts +262 -0
  189. package/dist/types-r-CasCf1.d.ts +262 -0
  190. package/package.json +116 -8
  191. package/src/core/buffer-reader.ts +16 -9
  192. package/src/core/buffer-writer.ts +2 -2
  193. package/src/core/errors.ts +1 -1
  194. package/src/core/session-types.ts +28 -41
  195. package/src/core/types.ts +92 -75
  196. package/src/drafts/draft07/announce-fsm.ts +1 -1
  197. package/src/drafts/draft07/codec.ts +235 -118
  198. package/src/drafts/draft07/index.ts +43 -44
  199. package/src/drafts/draft07/messages.ts +1 -1
  200. package/src/drafts/draft07/parameters.ts +2 -2
  201. package/src/drafts/draft07/rules.ts +67 -38
  202. package/src/drafts/draft07/session-fsm.ts +330 -117
  203. package/src/drafts/draft07/session.ts +10 -10
  204. package/src/drafts/draft07/subscription-fsm.ts +1 -1
  205. package/src/drafts/draft07/varint.ts +4 -4
  206. package/src/drafts/draft08/codec.ts +1254 -0
  207. package/src/drafts/draft08/index.ts +125 -0
  208. package/src/drafts/draft08/messages.ts +72 -0
  209. package/src/drafts/draft08/rules.ts +91 -0
  210. package/src/drafts/draft08/session-fsm.ts +718 -0
  211. package/src/drafts/draft08/session.ts +26 -0
  212. package/src/drafts/draft08/types.ts +377 -0
  213. package/src/drafts/draft09/codec.ts +1235 -0
  214. package/src/drafts/draft09/index.ts +125 -0
  215. package/src/drafts/draft09/messages.ts +72 -0
  216. package/src/drafts/draft09/rules.ts +91 -0
  217. package/src/drafts/draft09/session-fsm.ts +718 -0
  218. package/src/drafts/draft09/session.ts +26 -0
  219. package/src/drafts/draft09/types.ts +376 -0
  220. package/src/drafts/draft10/codec.ts +1235 -0
  221. package/src/drafts/draft10/index.ts +125 -0
  222. package/src/drafts/draft10/messages.ts +72 -0
  223. package/src/drafts/draft10/rules.ts +91 -0
  224. package/src/drafts/draft10/session-fsm.ts +718 -0
  225. package/src/drafts/draft10/session.ts +26 -0
  226. package/src/drafts/draft10/types.ts +376 -0
  227. package/src/drafts/draft11/codec.ts +1198 -0
  228. package/src/drafts/draft11/index.ts +123 -0
  229. package/src/drafts/draft11/messages.ts +71 -0
  230. package/src/drafts/draft11/rules.ts +100 -0
  231. package/src/drafts/draft11/session-fsm.ts +758 -0
  232. package/src/drafts/draft11/session.ts +26 -0
  233. package/src/drafts/draft11/types.ts +375 -0
  234. package/src/drafts/draft12/codec.ts +1354 -0
  235. package/src/drafts/draft12/index.ts +130 -0
  236. package/src/drafts/draft12/messages.ts +84 -0
  237. package/src/drafts/draft12/rules.ts +106 -0
  238. package/src/drafts/draft12/session-fsm.ts +805 -0
  239. package/src/drafts/draft12/session.ts +26 -0
  240. package/src/drafts/draft12/types.ts +414 -0
  241. package/src/drafts/draft13/codec.ts +1438 -0
  242. package/src/drafts/draft13/index.ts +132 -0
  243. package/src/drafts/draft13/messages.ts +86 -0
  244. package/src/drafts/draft13/rules.ts +108 -0
  245. package/src/drafts/draft13/session-fsm.ts +819 -0
  246. package/src/drafts/draft13/session.ts +26 -0
  247. package/src/drafts/draft13/types.ts +433 -0
  248. package/src/drafts/draft14/codec.ts +339 -189
  249. package/src/drafts/draft14/index.ts +103 -108
  250. package/src/drafts/draft14/messages.ts +61 -61
  251. package/src/drafts/draft14/rules.ts +77 -34
  252. package/src/drafts/draft14/session-fsm.ts +640 -147
  253. package/src/drafts/draft14/session.ts +13 -13
  254. package/src/drafts/draft14/types.ts +68 -68
  255. package/src/drafts/draft15/codec.ts +1661 -0
  256. package/src/drafts/draft15/index.ts +121 -0
  257. package/src/drafts/draft15/messages.ts +64 -0
  258. package/src/drafts/draft15/rules.ts +95 -0
  259. package/src/drafts/draft15/session-fsm.ts +687 -0
  260. package/src/drafts/draft15/session.ts +26 -0
  261. package/src/drafts/draft15/types.ts +336 -0
  262. package/src/drafts/draft16/codec.ts +1623 -0
  263. package/src/drafts/draft16/index.ts +123 -0
  264. package/src/drafts/draft16/messages.ts +67 -0
  265. package/src/drafts/draft16/rules.ts +96 -0
  266. package/src/drafts/draft16/session-fsm.ts +682 -0
  267. package/src/drafts/draft16/session.ts +26 -0
  268. package/src/drafts/draft16/types.ts +354 -0
  269. package/src/drafts/draft17/codec.ts +1621 -0
  270. package/src/drafts/draft17/index.ts +105 -0
  271. package/src/drafts/draft17/messages.ts +53 -0
  272. package/src/drafts/draft17/rules.ts +85 -0
  273. package/src/drafts/draft17/session-fsm.ts +437 -0
  274. package/src/drafts/draft17/session.ts +15 -0
  275. package/src/drafts/draft17/types.ts +310 -0
  276. package/src/index.ts +283 -33
  277. package/src/session.ts +20 -20
@@ -31,12 +31,8 @@ var CONTROL_MESSAGES = /* @__PURE__ */ new Set([
31
31
  "max_request_id",
32
32
  "requests_blocked"
33
33
  ]);
34
- var CLIENT_ONLY_MESSAGES = /* @__PURE__ */ new Set([
35
- "client_setup"
36
- ]);
37
- var SERVER_ONLY_MESSAGES = /* @__PURE__ */ new Set([
38
- "server_setup"
39
- ]);
34
+ var CLIENT_ONLY_MESSAGES = /* @__PURE__ */ new Set(["client_setup"]);
35
+ var SERVER_ONLY_MESSAGES = /* @__PURE__ */ new Set(["server_setup"]);
40
36
  var BIDIRECTIONAL_MESSAGES = /* @__PURE__ */ new Set([
41
37
  "subscribe",
42
38
  "subscribe_ok",
@@ -135,22 +131,42 @@ var Draft14SessionFSM = (_class = class {
135
131
  checkRole(message, direction) {
136
132
  const senderRole = direction === "outbound" ? this._role : this._role === "client" ? "server" : "client";
137
133
  if (CLIENT_ONLY_MESSAGES.has(message.type) && senderRole !== "client") {
138
- return violation("ROLE_VIOLATION", `${message.type} can only be sent by client`, this._phase, message.type);
134
+ return violation(
135
+ "ROLE_VIOLATION",
136
+ `${message.type} can only be sent by client`,
137
+ this._phase,
138
+ message.type
139
+ );
139
140
  }
140
141
  if (SERVER_ONLY_MESSAGES.has(message.type) && senderRole !== "server") {
141
- return violation("ROLE_VIOLATION", `${message.type} can only be sent by server`, this._phase, message.type);
142
+ return violation(
143
+ "ROLE_VIOLATION",
144
+ `${message.type} can only be sent by server`,
145
+ this._phase,
146
+ message.type
147
+ );
142
148
  }
143
149
  return null;
144
150
  }
145
151
  checkDuplicateRequestId(requestId, msgType) {
146
152
  if (this._requestIds.has(requestId)) {
147
- return violation("DUPLICATE_REQUEST_ID", `Request ID ${requestId} already in use`, this._phase, msgType);
153
+ return violation(
154
+ "DUPLICATE_REQUEST_ID",
155
+ `Request ID ${requestId} already in use`,
156
+ this._phase,
157
+ msgType
158
+ );
148
159
  }
149
160
  return null;
150
161
  }
151
162
  checkKnownRequestId(requestId, msgType) {
152
163
  if (!this._requestIds.has(requestId)) {
153
- return violation("UNKNOWN_REQUEST_ID", `No request with ID ${requestId}`, this._phase, msgType);
164
+ return violation(
165
+ "UNKNOWN_REQUEST_ID",
166
+ `No request with ID ${requestId}`,
167
+ this._phase,
168
+ msgType
169
+ );
154
170
  }
155
171
  return null;
156
172
  }
@@ -218,34 +234,101 @@ var Draft14SessionFSM = (_class = class {
218
234
  return this.handleFetchError(message, direction, sideEffects);
219
235
  case "fetch_cancel":
220
236
  return this.handleFetchCancel(message, direction, sideEffects);
221
- // Publish namespace, subscribe namespace, track status, and other ready-phase messages
237
+ // Publish namespace lifecycle
238
+ case "publish_namespace":
239
+ return this.handlePublishNamespace(message, sideEffects);
240
+ case "publish_namespace_ok":
241
+ return this.handlePublishNamespaceOk(message, sideEffects);
242
+ case "publish_namespace_error":
243
+ return this.handlePublishNamespaceError(message, sideEffects);
244
+ case "publish_namespace_done":
245
+ return this.handlePublishNamespaceDone(message, sideEffects);
246
+ case "publish_namespace_cancel":
247
+ return this.handlePublishNamespaceCancel(message, sideEffects);
248
+ // Subscribe namespace lifecycle
249
+ case "subscribe_namespace":
250
+ return this.handleSubscribeNamespace(message, sideEffects);
251
+ case "subscribe_namespace_ok":
252
+ return this.handleSubscribeNamespaceOk(message, sideEffects);
253
+ case "subscribe_namespace_error":
254
+ return this.handleSubscribeNamespaceError(message, sideEffects);
255
+ case "unsubscribe_namespace":
256
+ return this.handleUnsubscribeNamespace(message, sideEffects);
257
+ // Track status lifecycle
258
+ case "track_status":
259
+ return this.handleTrackStatus(message, sideEffects);
260
+ case "track_status_ok":
261
+ return this.handleTrackStatusOk(message, sideEffects);
262
+ case "track_status_error":
263
+ return this.handleTrackStatusError(message, sideEffects);
264
+ // Other ready-phase messages
222
265
  default:
223
266
  return this.handleReadyPhaseMessage(message);
224
267
  }
225
268
  }
226
269
  handleClientSetup(_message, direction) {
227
270
  if (this._phase !== "idle") {
228
- return { ok: false, violation: violation("SETUP_VIOLATION", "CLIENT_SETUP already sent/received", this._phase, "client_setup") };
271
+ return {
272
+ ok: false,
273
+ violation: violation(
274
+ "SETUP_VIOLATION",
275
+ "CLIENT_SETUP already sent/received",
276
+ this._phase,
277
+ "client_setup"
278
+ )
279
+ };
229
280
  }
230
281
  if (direction === "outbound" && this._role !== "client") {
231
- return { ok: false, violation: violation("ROLE_VIOLATION", "Only client can send CLIENT_SETUP", this._phase, "client_setup") };
282
+ return {
283
+ ok: false,
284
+ violation: violation(
285
+ "ROLE_VIOLATION",
286
+ "Only client can send CLIENT_SETUP",
287
+ this._phase,
288
+ "client_setup"
289
+ )
290
+ };
232
291
  }
233
292
  this._phase = "setup";
234
293
  return { ok: true, phase: this._phase, sideEffects: [] };
235
294
  }
236
295
  handleServerSetup(_message, direction) {
237
296
  if (this._phase !== "setup") {
238
- return { ok: false, violation: violation("SETUP_VIOLATION", "SERVER_SETUP before CLIENT_SETUP", this._phase, "server_setup") };
297
+ return {
298
+ ok: false,
299
+ violation: violation(
300
+ "SETUP_VIOLATION",
301
+ "SERVER_SETUP before CLIENT_SETUP",
302
+ this._phase,
303
+ "server_setup"
304
+ )
305
+ };
239
306
  }
240
307
  if (direction === "outbound" && this._role !== "server") {
241
- return { ok: false, violation: violation("ROLE_VIOLATION", "Only server can send SERVER_SETUP", this._phase, "server_setup") };
308
+ return {
309
+ ok: false,
310
+ violation: violation(
311
+ "ROLE_VIOLATION",
312
+ "Only server can send SERVER_SETUP",
313
+ this._phase,
314
+ "server_setup"
315
+ )
316
+ };
242
317
  }
243
318
  this._phase = "ready";
244
319
  return { ok: true, phase: this._phase, sideEffects: [{ type: "session-ready" }] };
245
320
  }
246
321
  handleGoAway(message, _direction, sideEffects) {
247
322
  if (this._phase !== "ready" && this._phase !== "draining") {
248
- return { ok: false, violation: violation("UNEXPECTED_MESSAGE", `GOAWAY not valid in phase ${this._phase}`, this._phase, "goaway") };
323
+ return {
324
+ ok: false,
325
+ violation: violation(
326
+ "UNEXPECTED_MESSAGE",
327
+ `GOAWAY not valid in phase ${this._phase}`,
328
+ this._phase,
329
+ "goaway"
330
+ )
331
+ };
249
332
  }
250
333
  this._phase = "draining";
251
334
  const goaway = message;
@@ -287,10 +370,26 @@ var Draft14SessionFSM = (_class = class {
287
370
  if (idErr) return { ok: false, violation: idErr };
288
371
  const existing = this._subscriptions.get(ok.request_id);
289
372
  if (!existing) {
290
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No subscription with request ID ${ok.request_id}`, this._phase, message.type) };
373
+ return {
374
+ ok: false,
375
+ violation: violation(
376
+ "UNKNOWN_REQUEST_ID",
377
+ `No subscription with request ID ${ok.request_id}`,
378
+ this._phase,
379
+ message.type
380
+ )
381
+ };
291
382
  }
292
383
  if (existing.phase !== "pending") {
293
- return { ok: false, violation: violation("STATE_VIOLATION", `Subscription ${ok.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
384
+ return {
385
+ ok: false,
386
+ violation: violation(
387
+ "STATE_VIOLATION",
388
+ `Subscription ${ok.request_id} is ${existing.phase}, not pending`,
389
+ this._phase,
390
+ message.type
391
+ )
392
+ };
294
393
  }
295
394
  this._subscriptions.set(ok.request_id, { ...existing, phase: "active" });
296
395
  sideEffects.push({ type: "subscription-activated", subscribeId: ok.request_id });
@@ -304,13 +403,33 @@ var Draft14SessionFSM = (_class = class {
304
403
  if (idErr) return { ok: false, violation: idErr };
305
404
  const existing = this._subscriptions.get(subErr.request_id);
306
405
  if (!existing) {
307
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No subscription with request ID ${subErr.request_id}`, this._phase, message.type) };
406
+ return {
407
+ ok: false,
408
+ violation: violation(
409
+ "UNKNOWN_REQUEST_ID",
410
+ `No subscription with request ID ${subErr.request_id}`,
411
+ this._phase,
412
+ message.type
413
+ )
414
+ };
308
415
  }
309
416
  if (existing.phase !== "pending") {
310
- return { ok: false, violation: violation("STATE_VIOLATION", `Subscription ${subErr.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
417
+ return {
418
+ ok: false,
419
+ violation: violation(
420
+ "STATE_VIOLATION",
421
+ `Subscription ${subErr.request_id} is ${existing.phase}, not pending`,
422
+ this._phase,
423
+ message.type
424
+ )
425
+ };
311
426
  }
312
427
  this._subscriptions.set(subErr.request_id, { ...existing, phase: "error" });
313
- sideEffects.push({ type: "subscription-ended", subscribeId: subErr.request_id, reason: subErr.reason_phrase });
428
+ sideEffects.push({
429
+ type: "subscription-ended",
430
+ subscribeId: subErr.request_id,
431
+ reason: subErr.reason_phrase
432
+ });
314
433
  return { ok: true, phase: this._phase, sideEffects };
315
434
  }
316
435
  handleSubscribeUpdate(message, _direction, sideEffects) {
@@ -321,10 +440,26 @@ var Draft14SessionFSM = (_class = class {
321
440
  if (idErr) return { ok: false, violation: idErr };
322
441
  const existing = this._subscriptions.get(update.request_id);
323
442
  if (!existing) {
324
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No subscription with request ID ${update.request_id}`, this._phase, message.type) };
443
+ return {
444
+ ok: false,
445
+ violation: violation(
446
+ "UNKNOWN_REQUEST_ID",
447
+ `No subscription with request ID ${update.request_id}`,
448
+ this._phase,
449
+ message.type
450
+ )
451
+ };
325
452
  }
326
453
  if (existing.phase !== "active") {
327
- return { ok: false, violation: violation("STATE_VIOLATION", `Subscription ${update.request_id} is ${existing.phase}, not active`, this._phase, message.type) };
454
+ return {
455
+ ok: false,
456
+ violation: violation(
457
+ "STATE_VIOLATION",
458
+ `Subscription ${update.request_id} is ${existing.phase}, not active`,
459
+ this._phase,
460
+ message.type
461
+ )
462
+ };
328
463
  }
329
464
  return { ok: true, phase: this._phase, sideEffects };
330
465
  }
@@ -336,10 +471,22 @@ var Draft14SessionFSM = (_class = class {
336
471
  if (idErr) return { ok: false, violation: idErr };
337
472
  const existing = this._subscriptions.get(unsub.request_id);
338
473
  if (!existing) {
339
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No subscription with request ID ${unsub.request_id}`, this._phase, message.type) };
474
+ return {
475
+ ok: false,
476
+ violation: violation(
477
+ "UNKNOWN_REQUEST_ID",
478
+ `No subscription with request ID ${unsub.request_id}`,
479
+ this._phase,
480
+ message.type
481
+ )
482
+ };
340
483
  }
341
484
  this._subscriptions.set(unsub.request_id, { ...existing, phase: "done" });
342
- sideEffects.push({ type: "subscription-ended", subscribeId: unsub.request_id, reason: "unsubscribed" });
485
+ sideEffects.push({
486
+ type: "subscription-ended",
487
+ subscribeId: unsub.request_id,
488
+ reason: "unsubscribed"
489
+ });
343
490
  return { ok: true, phase: this._phase, sideEffects };
344
491
  }
345
492
  // ─── Publish lifecycle ────────────────────────────────────────────────────────
@@ -364,10 +511,26 @@ var Draft14SessionFSM = (_class = class {
364
511
  if (idErr) return { ok: false, violation: idErr };
365
512
  const existing = this._publishes.get(ok.request_id);
366
513
  if (!existing) {
367
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No publish with request ID ${ok.request_id}`, this._phase, message.type) };
514
+ return {
515
+ ok: false,
516
+ violation: violation(
517
+ "UNKNOWN_REQUEST_ID",
518
+ `No publish with request ID ${ok.request_id}`,
519
+ this._phase,
520
+ message.type
521
+ )
522
+ };
368
523
  }
369
524
  if (existing.phase !== "pending") {
370
- return { ok: false, violation: violation("STATE_VIOLATION", `Publish ${ok.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
525
+ return {
526
+ ok: false,
527
+ violation: violation(
528
+ "STATE_VIOLATION",
529
+ `Publish ${ok.request_id} is ${existing.phase}, not pending`,
530
+ this._phase,
531
+ message.type
532
+ )
533
+ };
371
534
  }
372
535
  this._publishes.set(ok.request_id, { ...existing, phase: "active" });
373
536
  sideEffects.push({ type: "publish-activated", requestId: ok.request_id });
@@ -381,13 +544,33 @@ var Draft14SessionFSM = (_class = class {
381
544
  if (idErr) return { ok: false, violation: idErr };
382
545
  const existing = this._publishes.get(pubErr.request_id);
383
546
  if (!existing) {
384
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No publish with request ID ${pubErr.request_id}`, this._phase, message.type) };
547
+ return {
548
+ ok: false,
549
+ violation: violation(
550
+ "UNKNOWN_REQUEST_ID",
551
+ `No publish with request ID ${pubErr.request_id}`,
552
+ this._phase,
553
+ message.type
554
+ )
555
+ };
385
556
  }
386
557
  if (existing.phase !== "pending") {
387
- return { ok: false, violation: violation("STATE_VIOLATION", `Publish ${pubErr.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
558
+ return {
559
+ ok: false,
560
+ violation: violation(
561
+ "STATE_VIOLATION",
562
+ `Publish ${pubErr.request_id} is ${existing.phase}, not pending`,
563
+ this._phase,
564
+ message.type
565
+ )
566
+ };
388
567
  }
389
568
  this._publishes.set(pubErr.request_id, { ...existing, phase: "error" });
390
- sideEffects.push({ type: "publish-ended", requestId: pubErr.request_id, reason: pubErr.reason_phrase });
569
+ sideEffects.push({
570
+ type: "publish-ended",
571
+ requestId: pubErr.request_id,
572
+ reason: pubErr.reason_phrase
573
+ });
391
574
  return { ok: true, phase: this._phase, sideEffects };
392
575
  }
393
576
  handlePublishDone(message, _direction, sideEffects) {
@@ -398,10 +581,22 @@ var Draft14SessionFSM = (_class = class {
398
581
  if (idErr) return { ok: false, violation: idErr };
399
582
  const existing = this._publishes.get(done.request_id);
400
583
  if (!existing) {
401
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No publish with request ID ${done.request_id}`, this._phase, message.type) };
584
+ return {
585
+ ok: false,
586
+ violation: violation(
587
+ "UNKNOWN_REQUEST_ID",
588
+ `No publish with request ID ${done.request_id}`,
589
+ this._phase,
590
+ message.type
591
+ )
592
+ };
402
593
  }
403
594
  this._publishes.set(done.request_id, { ...existing, phase: "done" });
404
- sideEffects.push({ type: "publish-ended", requestId: done.request_id, reason: done.reason_phrase });
595
+ sideEffects.push({
596
+ type: "publish-ended",
597
+ requestId: done.request_id,
598
+ reason: done.reason_phrase
599
+ });
405
600
  return { ok: true, phase: this._phase, sideEffects };
406
601
  }
407
602
  // ─── Fetch lifecycle ──────────────────────────────────────────────────────────
@@ -426,10 +621,26 @@ var Draft14SessionFSM = (_class = class {
426
621
  if (idErr) return { ok: false, violation: idErr };
427
622
  const existing = this._fetches.get(ok.request_id);
428
623
  if (!existing) {
429
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No fetch with request ID ${ok.request_id}`, this._phase, message.type) };
624
+ return {
625
+ ok: false,
626
+ violation: violation(
627
+ "UNKNOWN_REQUEST_ID",
628
+ `No fetch with request ID ${ok.request_id}`,
629
+ this._phase,
630
+ message.type
631
+ )
632
+ };
430
633
  }
431
634
  if (existing.phase !== "pending") {
432
- return { ok: false, violation: violation("STATE_VIOLATION", `Fetch ${ok.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
635
+ return {
636
+ ok: false,
637
+ violation: violation(
638
+ "STATE_VIOLATION",
639
+ `Fetch ${ok.request_id} is ${existing.phase}, not pending`,
640
+ this._phase,
641
+ message.type
642
+ )
643
+ };
433
644
  }
434
645
  this._fetches.set(ok.request_id, { ...existing, phase: "active" });
435
646
  sideEffects.push({ type: "fetch-activated", requestId: ok.request_id });
@@ -443,13 +654,33 @@ var Draft14SessionFSM = (_class = class {
443
654
  if (idErr) return { ok: false, violation: idErr };
444
655
  const existing = this._fetches.get(fetchErr.request_id);
445
656
  if (!existing) {
446
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No fetch with request ID ${fetchErr.request_id}`, this._phase, message.type) };
657
+ return {
658
+ ok: false,
659
+ violation: violation(
660
+ "UNKNOWN_REQUEST_ID",
661
+ `No fetch with request ID ${fetchErr.request_id}`,
662
+ this._phase,
663
+ message.type
664
+ )
665
+ };
447
666
  }
448
667
  if (existing.phase !== "pending") {
449
- return { ok: false, violation: violation("STATE_VIOLATION", `Fetch ${fetchErr.request_id} is ${existing.phase}, not pending`, this._phase, message.type) };
668
+ return {
669
+ ok: false,
670
+ violation: violation(
671
+ "STATE_VIOLATION",
672
+ `Fetch ${fetchErr.request_id} is ${existing.phase}, not pending`,
673
+ this._phase,
674
+ message.type
675
+ )
676
+ };
450
677
  }
451
678
  this._fetches.set(fetchErr.request_id, { ...existing, phase: "error" });
452
- sideEffects.push({ type: "fetch-ended", requestId: fetchErr.request_id, reason: fetchErr.reason_phrase });
679
+ sideEffects.push({
680
+ type: "fetch-ended",
681
+ requestId: fetchErr.request_id,
682
+ reason: fetchErr.reason_phrase
683
+ });
453
684
  return { ok: true, phase: this._phase, sideEffects };
454
685
  }
455
686
  handleFetchCancel(message, _direction, sideEffects) {
@@ -460,12 +691,119 @@ var Draft14SessionFSM = (_class = class {
460
691
  if (idErr) return { ok: false, violation: idErr };
461
692
  const existing = this._fetches.get(cancel.request_id);
462
693
  if (!existing) {
463
- return { ok: false, violation: violation("UNKNOWN_REQUEST_ID", `No fetch with request ID ${cancel.request_id}`, this._phase, message.type) };
694
+ return {
695
+ ok: false,
696
+ violation: violation(
697
+ "UNKNOWN_REQUEST_ID",
698
+ `No fetch with request ID ${cancel.request_id}`,
699
+ this._phase,
700
+ message.type
701
+ )
702
+ };
464
703
  }
465
704
  this._fetches.set(cancel.request_id, { ...existing, phase: "cancelled" });
466
705
  sideEffects.push({ type: "fetch-ended", requestId: cancel.request_id, reason: "cancelled" });
467
706
  return { ok: true, phase: this._phase, sideEffects };
468
707
  }
708
+ // ─── Publish namespace lifecycle ──────────────────────────────────────────────
709
+ handlePublishNamespace(message, sideEffects) {
710
+ const err = this.requireReady(message.type);
711
+ if (err) return { ok: false, violation: err };
712
+ const pn = message;
713
+ const dupErr = this.checkDuplicateRequestId(pn.request_id, message.type);
714
+ if (dupErr) return { ok: false, violation: dupErr };
715
+ this._requestIds.add(pn.request_id);
716
+ return { ok: true, phase: this._phase, sideEffects };
717
+ }
718
+ handlePublishNamespaceOk(message, sideEffects) {
719
+ const err = this.requireReady(message.type);
720
+ if (err) return { ok: false, violation: err };
721
+ const ok = message;
722
+ const idErr = this.checkKnownRequestId(ok.request_id, message.type);
723
+ if (idErr) return { ok: false, violation: idErr };
724
+ return { ok: true, phase: this._phase, sideEffects };
725
+ }
726
+ handlePublishNamespaceError(message, sideEffects) {
727
+ const err = this.requireReady(message.type);
728
+ if (err) return { ok: false, violation: err };
729
+ const pnErr = message;
730
+ const idErr = this.checkKnownRequestId(pnErr.request_id, message.type);
731
+ if (idErr) return { ok: false, violation: idErr };
732
+ return { ok: true, phase: this._phase, sideEffects };
733
+ }
734
+ handlePublishNamespaceDone(message, sideEffects) {
735
+ const err = this.requireReady(message.type);
736
+ if (err) return { ok: false, violation: err };
737
+ const done = message;
738
+ const idErr = this.checkKnownRequestId(done.request_id, message.type);
739
+ if (idErr) return { ok: false, violation: idErr };
740
+ return { ok: true, phase: this._phase, sideEffects };
741
+ }
742
+ handlePublishNamespaceCancel(message, sideEffects) {
743
+ const err = this.requireReady(message.type);
744
+ if (err) return { ok: false, violation: err };
745
+ const cancel = message;
746
+ const idErr = this.checkKnownRequestId(cancel.request_id, message.type);
747
+ if (idErr) return { ok: false, violation: idErr };
748
+ return { ok: true, phase: this._phase, sideEffects };
749
+ }
750
+ // ─── Subscribe namespace lifecycle ──────────────────────────────────────────────
751
+ handleSubscribeNamespace(message, sideEffects) {
752
+ const err = this.requireReady(message.type);
753
+ if (err) return { ok: false, violation: err };
754
+ const sn = message;
755
+ const dupErr = this.checkDuplicateRequestId(sn.request_id, message.type);
756
+ if (dupErr) return { ok: false, violation: dupErr };
757
+ this._requestIds.add(sn.request_id);
758
+ return { ok: true, phase: this._phase, sideEffects };
759
+ }
760
+ handleSubscribeNamespaceOk(message, sideEffects) {
761
+ const err = this.requireReady(message.type);
762
+ if (err) return { ok: false, violation: err };
763
+ const ok = message;
764
+ const idErr = this.checkKnownRequestId(ok.request_id, message.type);
765
+ if (idErr) return { ok: false, violation: idErr };
766
+ return { ok: true, phase: this._phase, sideEffects };
767
+ }
768
+ handleSubscribeNamespaceError(message, sideEffects) {
769
+ const err = this.requireReady(message.type);
770
+ if (err) return { ok: false, violation: err };
771
+ const snErr = message;
772
+ const idErr = this.checkKnownRequestId(snErr.request_id, message.type);
773
+ if (idErr) return { ok: false, violation: idErr };
774
+ return { ok: true, phase: this._phase, sideEffects };
775
+ }
776
+ handleUnsubscribeNamespace(message, sideEffects) {
777
+ const err = this.requireReady(message.type);
778
+ if (err) return { ok: false, violation: err };
779
+ return { ok: true, phase: this._phase, sideEffects };
780
+ }
781
+ // ─── Track status lifecycle ──────────────────────────────────────────────────
782
+ handleTrackStatus(message, sideEffects) {
783
+ const err = this.requireReady(message.type);
784
+ if (err) return { ok: false, violation: err };
785
+ const ts = message;
786
+ const dupErr = this.checkDuplicateRequestId(ts.request_id, message.type);
787
+ if (dupErr) return { ok: false, violation: dupErr };
788
+ this._requestIds.add(ts.request_id);
789
+ return { ok: true, phase: this._phase, sideEffects };
790
+ }
791
+ handleTrackStatusOk(message, sideEffects) {
792
+ const err = this.requireReady(message.type);
793
+ if (err) return { ok: false, violation: err };
794
+ const ok = message;
795
+ const idErr = this.checkKnownRequestId(ok.request_id, message.type);
796
+ if (idErr) return { ok: false, violation: idErr };
797
+ return { ok: true, phase: this._phase, sideEffects };
798
+ }
799
+ handleTrackStatusError(message, sideEffects) {
800
+ const err = this.requireReady(message.type);
801
+ if (err) return { ok: false, violation: err };
802
+ const tsErr = message;
803
+ const idErr = this.checkKnownRequestId(tsErr.request_id, message.type);
804
+ if (idErr) return { ok: false, violation: idErr };
805
+ return { ok: true, phase: this._phase, sideEffects };
806
+ }
469
807
  // ─── Generic ready-phase handler ──────────────────────────────────────────────
470
808
  handleReadyPhaseMessage(message) {
471
809
  const err = this.requireReady(message.type);