@moqtap/codec 0.1.1 → 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 (252) 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-YBZD3DU5.cjs → chunk-7IVGHMKJ.cjs} +44 -42
  8. package/dist/chunk-BISI45MN.cjs +680 -0
  9. package/dist/{chunk-NLYTRGXA.cjs → chunk-BPNL5YFQ.cjs} +5 -5
  10. package/dist/chunk-CXDHOMHG.js +1097 -0
  11. package/dist/chunk-DUBCL3WF.cjs +749 -0
  12. package/dist/chunk-DWK5ZQZ4.js +642 -0
  13. package/dist/chunk-E6E3NQYU.js +680 -0
  14. package/dist/chunk-EFM5T7OM.js +698 -0
  15. package/dist/chunk-ENURAVHI.cjs +680 -0
  16. package/dist/{chunk-Z66WDWHI.js → chunk-FXZ2MYKJ.js} +127 -1
  17. package/dist/chunk-G26SJ6XS.cjs +1341 -0
  18. package/dist/chunk-G7GI7LJA.js +737 -0
  19. package/dist/chunk-GXEW4COZ.cjs +737 -0
  20. package/dist/chunk-HSVYF6XX.cjs +1361 -0
  21. package/dist/chunk-IBVM4DMJ.cjs +1097 -0
  22. package/dist/chunk-IV2H5CFI.cjs +1275 -0
  23. package/dist/chunk-IV2HRJVT.js +1198 -0
  24. package/dist/chunk-JSQM2MG3.js +680 -0
  25. package/dist/chunk-K4OLITS2.cjs +1055 -0
  26. package/dist/{chunk-UOBWHJA5.js → chunk-KFTCU2P6.js} +2 -3
  27. package/dist/chunk-LH4NTURO.js +1361 -0
  28. package/dist/{chunk-YTXLWKOR.js → chunk-MFAP7R6L.js} +1 -1
  29. package/dist/chunk-NGVE2RZT.js +1097 -0
  30. package/dist/chunk-NUX5BHWO.js +1341 -0
  31. package/dist/chunk-PJRA2TQ5.js +1055 -0
  32. package/dist/chunk-RVJAGE4S.cjs +1198 -0
  33. package/dist/{chunk-QYG6KGOV.cjs → chunk-RWQ43Z4F.cjs} +2 -3
  34. package/dist/chunk-RZHAPEXO.js +749 -0
  35. package/dist/chunk-ST24APEO.js +1109 -0
  36. package/dist/chunk-SYHW3FLI.cjs +642 -0
  37. package/dist/chunk-TLYNOOQP.cjs +432 -0
  38. package/dist/{chunk-IXHOBNXA.js → chunk-TMNGRIPL.js} +43 -41
  39. package/dist/chunk-UNS34PTA.cjs +680 -0
  40. package/dist/chunk-UR6JKS56.js +432 -0
  41. package/dist/{chunk-NPWHHWXT.cjs → chunk-UYXTY6ZQ.cjs} +127 -1
  42. package/dist/chunk-XUUCOLWU.cjs +1097 -0
  43. package/dist/chunk-YG5KJESI.js +641 -0
  44. package/dist/chunk-ZBKE2QRQ.js +1401 -0
  45. package/dist/chunk-ZSPO2GF2.cjs +1401 -0
  46. package/dist/codec-95k8CAu5.d.cts +35 -0
  47. package/dist/codec-AFuOxfsO.d.ts +60 -0
  48. package/dist/codec-B-UJ5Iow.d.cts +75 -0
  49. package/dist/codec-BC5jfvMb.d.ts +35 -0
  50. package/dist/codec-BECYPfY8.d.ts +35 -0
  51. package/dist/codec-BsPU1vNC.d.ts +39 -0
  52. package/dist/codec-BvpuF-6u.d.cts +39 -0
  53. package/dist/codec-C8jZI5Cx.d.cts +39 -0
  54. package/dist/codec-CAevkgf5.d.cts +33 -0
  55. package/dist/codec-CSUqCrRs.d.ts +39 -0
  56. package/dist/codec-C_HMXNK_.d.ts +33 -0
  57. package/dist/{codec-Bvr7rFtj.d.cts → codec-CpuvYTSV.d.cts} +1 -1
  58. package/dist/codec-D0x8-SCw.d.cts +35 -0
  59. package/dist/codec-D7ARhpG1.d.ts +75 -0
  60. package/dist/codec-DNAUGshO.d.cts +60 -0
  61. package/dist/codec-DPx_QNn0.d.ts +31 -0
  62. package/dist/{codec-B2mc2g3i.d.ts → codec-DRhCx_hw.d.ts} +1 -1
  63. package/dist/codec-Db7YPe3l.d.ts +31 -0
  64. package/dist/codec-axkJpb7D.d.cts +31 -0
  65. package/dist/codec-ujAbFaep.d.cts +31 -0
  66. package/dist/draft10-session.cjs +6 -0
  67. package/dist/draft10-session.d.cts +8 -0
  68. package/dist/draft10-session.d.ts +8 -0
  69. package/dist/draft10-session.js +6 -0
  70. package/dist/draft10.cjs +115 -0
  71. package/dist/draft10.d.cts +95 -0
  72. package/dist/draft10.d.ts +95 -0
  73. package/dist/draft10.js +115 -0
  74. package/dist/draft11-session.cjs +6 -0
  75. package/dist/draft11-session.d.cts +8 -0
  76. package/dist/draft11-session.d.ts +8 -0
  77. package/dist/draft11-session.js +6 -0
  78. package/dist/draft11.cjs +109 -0
  79. package/dist/draft11.d.cts +99 -0
  80. package/dist/draft11.d.ts +99 -0
  81. package/dist/draft11.js +109 -0
  82. package/dist/draft12-session.cjs +6 -0
  83. package/dist/draft12-session.d.cts +8 -0
  84. package/dist/draft12-session.d.ts +8 -0
  85. package/dist/draft12-session.js +6 -0
  86. package/dist/draft12.cjs +117 -0
  87. package/dist/draft12.d.cts +106 -0
  88. package/dist/draft12.d.ts +106 -0
  89. package/dist/draft12.js +117 -0
  90. package/dist/draft13-session.cjs +6 -0
  91. package/dist/draft13-session.d.cts +8 -0
  92. package/dist/draft13-session.d.ts +8 -0
  93. package/dist/draft13-session.js +6 -0
  94. package/dist/draft13.cjs +119 -0
  95. package/dist/draft13.d.cts +108 -0
  96. package/dist/draft13.d.ts +108 -0
  97. package/dist/draft13.js +119 -0
  98. package/dist/draft14-session.cjs +2 -2
  99. package/dist/draft14-session.d.cts +3 -3
  100. package/dist/draft14-session.d.ts +3 -3
  101. package/dist/draft14-session.js +1 -1
  102. package/dist/draft14.cjs +3 -3
  103. package/dist/draft14.d.cts +16 -4
  104. package/dist/draft14.d.ts +16 -4
  105. package/dist/draft14.js +2 -2
  106. package/dist/draft15-session.cjs +6 -0
  107. package/dist/draft15-session.d.cts +8 -0
  108. package/dist/draft15-session.d.ts +8 -0
  109. package/dist/draft15-session.js +6 -0
  110. package/dist/draft15.cjs +111 -0
  111. package/dist/draft15.d.cts +93 -0
  112. package/dist/draft15.d.ts +93 -0
  113. package/dist/draft15.js +111 -0
  114. package/dist/draft16-session.cjs +6 -0
  115. package/dist/draft16-session.d.cts +8 -0
  116. package/dist/draft16-session.d.ts +8 -0
  117. package/dist/draft16-session.js +6 -0
  118. package/dist/draft16.cjs +113 -0
  119. package/dist/draft16.d.cts +94 -0
  120. package/dist/draft16.d.ts +94 -0
  121. package/dist/draft16.js +113 -0
  122. package/dist/draft17-session.cjs +8 -0
  123. package/dist/draft17-session.d.cts +51 -0
  124. package/dist/draft17-session.d.ts +51 -0
  125. package/dist/draft17-session.js +8 -0
  126. package/dist/draft17.cjs +99 -0
  127. package/dist/draft17.d.cts +40 -0
  128. package/dist/draft17.d.ts +40 -0
  129. package/dist/draft17.js +99 -0
  130. package/dist/draft7-session.cjs +3 -3
  131. package/dist/draft7-session.d.cts +3 -3
  132. package/dist/draft7-session.d.ts +3 -3
  133. package/dist/draft7-session.js +2 -2
  134. package/dist/draft7.cjs +4 -4
  135. package/dist/draft7.d.cts +2 -2
  136. package/dist/draft7.d.ts +2 -2
  137. package/dist/draft7.js +2 -2
  138. package/dist/draft8-session.cjs +6 -0
  139. package/dist/draft8-session.d.cts +8 -0
  140. package/dist/draft8-session.d.ts +8 -0
  141. package/dist/draft8-session.js +6 -0
  142. package/dist/draft8.cjs +115 -0
  143. package/dist/draft8.d.cts +95 -0
  144. package/dist/draft8.d.ts +95 -0
  145. package/dist/draft8.js +115 -0
  146. package/dist/draft9-session.cjs +6 -0
  147. package/dist/draft9-session.d.cts +8 -0
  148. package/dist/draft9-session.d.ts +8 -0
  149. package/dist/draft9-session.js +6 -0
  150. package/dist/draft9.cjs +115 -0
  151. package/dist/draft9.d.cts +95 -0
  152. package/dist/draft9.d.ts +95 -0
  153. package/dist/draft9.js +115 -0
  154. package/dist/index.cjs +76 -4
  155. package/dist/index.d.cts +68 -5
  156. package/dist/index.d.ts +68 -5
  157. package/dist/index.js +76 -4
  158. package/dist/{session-types-DFjMk4HH.d.ts → session-types-CJIFbTPd.d.ts} +1 -1
  159. package/dist/{session-types-DW1RSZX_.d.cts → session-types-Cbq8IGCP.d.cts} +1 -1
  160. package/dist/session.cjs +5 -5
  161. package/dist/session.d.cts +3 -3
  162. package/dist/session.d.ts +3 -3
  163. package/dist/session.js +5 -5
  164. package/dist/types-4VxSL2Ho.d.cts +261 -0
  165. package/dist/types-4VxSL2Ho.d.ts +261 -0
  166. package/dist/types-B2afJZM-.d.cts +236 -0
  167. package/dist/types-B2afJZM-.d.ts +236 -0
  168. package/dist/types-Bg6QYNVt.d.cts +290 -0
  169. package/dist/types-Bg6QYNVt.d.ts +290 -0
  170. package/dist/types-C_1HrqBl.d.cts +306 -0
  171. package/dist/types-C_1HrqBl.d.ts +306 -0
  172. package/dist/types-Cw4WE9dh.d.cts +261 -0
  173. package/dist/types-Cw4WE9dh.d.ts +261 -0
  174. package/dist/types-D5gNQiDj.d.cts +261 -0
  175. package/dist/types-D5gNQiDj.d.ts +261 -0
  176. package/dist/types-DqCDFqgB.d.cts +230 -0
  177. package/dist/types-DqCDFqgB.d.ts +230 -0
  178. package/dist/types-ERexTpT8.d.cts +217 -0
  179. package/dist/types-ERexTpT8.d.ts +217 -0
  180. package/dist/{types-DPYE49t0.d.cts → types-QNXoxC9Y.d.cts} +2 -7
  181. package/dist/{types-DPYE49t0.d.ts → types-QNXoxC9Y.d.ts} +2 -7
  182. package/dist/types-r-CasCf1.d.cts +262 -0
  183. package/dist/types-r-CasCf1.d.ts +262 -0
  184. package/package.json +110 -2
  185. package/src/core/types.ts +24 -7
  186. package/src/drafts/draft07/codec.ts +49 -41
  187. package/src/drafts/draft07/rules.ts +1 -3
  188. package/src/drafts/draft08/codec.ts +1254 -0
  189. package/src/drafts/draft08/index.ts +125 -0
  190. package/src/drafts/draft08/messages.ts +72 -0
  191. package/src/drafts/draft08/rules.ts +91 -0
  192. package/src/drafts/draft08/session-fsm.ts +718 -0
  193. package/src/drafts/draft08/session.ts +26 -0
  194. package/src/drafts/draft08/types.ts +377 -0
  195. package/src/drafts/draft09/codec.ts +1235 -0
  196. package/src/drafts/draft09/index.ts +125 -0
  197. package/src/drafts/draft09/messages.ts +72 -0
  198. package/src/drafts/draft09/rules.ts +91 -0
  199. package/src/drafts/draft09/session-fsm.ts +718 -0
  200. package/src/drafts/draft09/session.ts +26 -0
  201. package/src/drafts/draft09/types.ts +376 -0
  202. package/src/drafts/draft10/codec.ts +1235 -0
  203. package/src/drafts/draft10/index.ts +125 -0
  204. package/src/drafts/draft10/messages.ts +72 -0
  205. package/src/drafts/draft10/rules.ts +91 -0
  206. package/src/drafts/draft10/session-fsm.ts +718 -0
  207. package/src/drafts/draft10/session.ts +26 -0
  208. package/src/drafts/draft10/types.ts +376 -0
  209. package/src/drafts/draft11/codec.ts +1198 -0
  210. package/src/drafts/draft11/index.ts +123 -0
  211. package/src/drafts/draft11/messages.ts +71 -0
  212. package/src/drafts/draft11/rules.ts +100 -0
  213. package/src/drafts/draft11/session-fsm.ts +758 -0
  214. package/src/drafts/draft11/session.ts +26 -0
  215. package/src/drafts/draft11/types.ts +375 -0
  216. package/src/drafts/draft12/codec.ts +1354 -0
  217. package/src/drafts/draft12/index.ts +130 -0
  218. package/src/drafts/draft12/messages.ts +84 -0
  219. package/src/drafts/draft12/rules.ts +106 -0
  220. package/src/drafts/draft12/session-fsm.ts +805 -0
  221. package/src/drafts/draft12/session.ts +26 -0
  222. package/src/drafts/draft12/types.ts +414 -0
  223. package/src/drafts/draft13/codec.ts +1438 -0
  224. package/src/drafts/draft13/index.ts +132 -0
  225. package/src/drafts/draft13/messages.ts +86 -0
  226. package/src/drafts/draft13/rules.ts +108 -0
  227. package/src/drafts/draft13/session-fsm.ts +819 -0
  228. package/src/drafts/draft13/session.ts +26 -0
  229. package/src/drafts/draft13/types.ts +433 -0
  230. package/src/drafts/draft14/session-fsm.ts +182 -1
  231. package/src/drafts/draft15/codec.ts +1661 -0
  232. package/src/drafts/draft15/index.ts +121 -0
  233. package/src/drafts/draft15/messages.ts +64 -0
  234. package/src/drafts/draft15/rules.ts +95 -0
  235. package/src/drafts/draft15/session-fsm.ts +687 -0
  236. package/src/drafts/draft15/session.ts +26 -0
  237. package/src/drafts/draft15/types.ts +336 -0
  238. package/src/drafts/draft16/codec.ts +1623 -0
  239. package/src/drafts/draft16/index.ts +123 -0
  240. package/src/drafts/draft16/messages.ts +67 -0
  241. package/src/drafts/draft16/rules.ts +96 -0
  242. package/src/drafts/draft16/session-fsm.ts +682 -0
  243. package/src/drafts/draft16/session.ts +26 -0
  244. package/src/drafts/draft16/types.ts +354 -0
  245. package/src/drafts/draft17/codec.ts +1621 -0
  246. package/src/drafts/draft17/index.ts +105 -0
  247. package/src/drafts/draft17/messages.ts +53 -0
  248. package/src/drafts/draft17/rules.ts +85 -0
  249. package/src/drafts/draft17/session-fsm.ts +437 -0
  250. package/src/drafts/draft17/session.ts +15 -0
  251. package/src/drafts/draft17/types.ts +310 -0
  252. package/src/index.ts +217 -2
@@ -0,0 +1,432 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;// src/drafts/draft17/rules.ts
2
+ var CONTROL_MESSAGES = /* @__PURE__ */ new Set([
3
+ "setup",
4
+ "subscribe",
5
+ "subscribe_ok",
6
+ "request_update",
7
+ "publish",
8
+ "publish_ok",
9
+ "publish_done",
10
+ "publish_namespace",
11
+ "namespace",
12
+ "namespace_done",
13
+ "subscribe_namespace",
14
+ "publish_blocked",
15
+ "fetch",
16
+ "fetch_ok",
17
+ "track_status",
18
+ "request_ok",
19
+ "request_error",
20
+ "goaway"
21
+ ]);
22
+ var CLIENT_ONLY_MESSAGES = /* @__PURE__ */ new Set();
23
+ var SERVER_ONLY_MESSAGES = /* @__PURE__ */ new Set();
24
+ var BIDIRECTIONAL_MESSAGES = /* @__PURE__ */ new Set([
25
+ "setup",
26
+ "subscribe",
27
+ "subscribe_ok",
28
+ "request_update",
29
+ "publish",
30
+ "publish_ok",
31
+ "publish_done",
32
+ "publish_namespace",
33
+ "namespace",
34
+ "namespace_done",
35
+ "subscribe_namespace",
36
+ "publish_blocked",
37
+ "fetch",
38
+ "fetch_ok",
39
+ "track_status",
40
+ "request_ok",
41
+ "request_error",
42
+ "goaway"
43
+ ]);
44
+ function getLegalOutgoing(phase, _role) {
45
+ const legal = /* @__PURE__ */ new Set();
46
+ switch (phase) {
47
+ case "idle":
48
+ legal.add("setup");
49
+ break;
50
+ case "setup":
51
+ legal.add("setup");
52
+ break;
53
+ case "ready": {
54
+ for (const msg of BIDIRECTIONAL_MESSAGES) {
55
+ legal.add(msg);
56
+ }
57
+ break;
58
+ }
59
+ case "draining":
60
+ break;
61
+ }
62
+ return legal;
63
+ }
64
+ function getLegalIncoming(phase, role) {
65
+ const remoteRole = role === "client" ? "server" : "client";
66
+ return getLegalOutgoing(phase, remoteRole);
67
+ }
68
+
69
+ // src/drafts/draft17/session-fsm.ts
70
+ function violation(code, message, currentPhase, offendingMessage) {
71
+ return { code, message, currentPhase, offendingMessage };
72
+ }
73
+ var Draft17SessionFSM = (_class = class {
74
+ __init() {this._phase = "idle"}
75
+
76
+ __init2() {this._setupDirection = null}
77
+ __init3() {this._subscriptions = /* @__PURE__ */ new Map()}
78
+ __init4() {this._publishes = /* @__PURE__ */ new Map()}
79
+ __init5() {this._fetches = /* @__PURE__ */ new Map()}
80
+ __init6() {this._requestIds = /* @__PURE__ */ new Set()}
81
+ __init7() {this._pendingSubscribes = []}
82
+ __init8() {this._pendingPublishes = []}
83
+ __init9() {this._pendingFetches = []}
84
+ constructor(role) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);
85
+ this._role = role;
86
+ }
87
+ get phase() {
88
+ return this._phase;
89
+ }
90
+ get role() {
91
+ return this._role;
92
+ }
93
+ get subscriptions() {
94
+ return this._subscriptions;
95
+ }
96
+ get announces() {
97
+ return /* @__PURE__ */ new Map();
98
+ }
99
+ get publishes() {
100
+ return this._publishes;
101
+ }
102
+ get fetches() {
103
+ return this._fetches;
104
+ }
105
+ get legalOutgoing() {
106
+ return getLegalOutgoing(this._phase, this._role);
107
+ }
108
+ get legalIncoming() {
109
+ return getLegalIncoming(this._phase, this._role);
110
+ }
111
+ checkDuplicateRequestId(requestId, msgType) {
112
+ if (this._requestIds.has(requestId)) {
113
+ return violation(
114
+ "DUPLICATE_REQUEST_ID",
115
+ `Request ID ${requestId} already in use`,
116
+ this._phase,
117
+ msgType
118
+ );
119
+ }
120
+ return null;
121
+ }
122
+ validateOutgoing(message) {
123
+ if (!this.legalOutgoing.has(message.type)) {
124
+ return {
125
+ ok: false,
126
+ violation: violation(
127
+ this._phase === "idle" || this._phase === "setup" ? "MESSAGE_BEFORE_SETUP" : "UNEXPECTED_MESSAGE",
128
+ `Cannot send ${message.type} in phase ${this._phase}`,
129
+ this._phase,
130
+ message.type
131
+ )
132
+ };
133
+ }
134
+ return { ok: true };
135
+ }
136
+ receive(message) {
137
+ return this.applyTransition(message, "inbound");
138
+ }
139
+ send(message) {
140
+ return this.applyTransition(message, "outbound");
141
+ }
142
+ applyTransition(message, direction) {
143
+ const sideEffects = [];
144
+ switch (message.type) {
145
+ case "setup":
146
+ return this.handleSetup(direction);
147
+ case "goaway":
148
+ return this.handleGoAway(message, sideEffects);
149
+ case "subscribe":
150
+ return this.handleSubscribe(message, sideEffects);
151
+ case "subscribe_ok":
152
+ return this.handleSubscribeOk(message, sideEffects);
153
+ case "request_update":
154
+ return this.handleRequestUpdate(message, sideEffects);
155
+ case "publish":
156
+ return this.handlePublish(message, sideEffects);
157
+ case "publish_ok":
158
+ return this.handlePublishOk(sideEffects);
159
+ case "publish_done":
160
+ return this.handlePublishDone(message, sideEffects);
161
+ case "fetch":
162
+ return this.handleFetch(message, sideEffects);
163
+ case "fetch_ok":
164
+ return this.handleFetchOk(sideEffects);
165
+ case "request_ok":
166
+ return this.handleRequestOk(sideEffects);
167
+ case "request_error":
168
+ return this.handleRequestError(sideEffects);
169
+ default:
170
+ return this.handleReadyPhaseMessage(message);
171
+ }
172
+ }
173
+ handleSetup(direction) {
174
+ if (this._phase === "idle") {
175
+ this._setupDirection = direction;
176
+ this._phase = "setup";
177
+ return { ok: true, phase: this._phase, sideEffects: [] };
178
+ }
179
+ if (this._phase === "setup") {
180
+ if (direction === this._setupDirection) {
181
+ return {
182
+ ok: false,
183
+ violation: violation(
184
+ "SETUP_VIOLATION",
185
+ `Second SETUP must be ${this._setupDirection === "inbound" ? "outbound" : "inbound"}, got ${direction}`,
186
+ this._phase,
187
+ "setup"
188
+ )
189
+ };
190
+ }
191
+ this._phase = "ready";
192
+ return { ok: true, phase: this._phase, sideEffects: [{ type: "session-ready" }] };
193
+ }
194
+ return {
195
+ ok: false,
196
+ violation: violation(
197
+ "SETUP_VIOLATION",
198
+ "SETUP not valid in current phase",
199
+ this._phase,
200
+ "setup"
201
+ )
202
+ };
203
+ }
204
+ handleGoAway(message, sideEffects) {
205
+ if (this._phase !== "ready" && this._phase !== "draining") {
206
+ return {
207
+ ok: false,
208
+ violation: violation(
209
+ "UNEXPECTED_MESSAGE",
210
+ `GOAWAY not valid in phase ${this._phase}`,
211
+ this._phase,
212
+ "goaway"
213
+ )
214
+ };
215
+ }
216
+ this._phase = "draining";
217
+ const goaway = message;
218
+ sideEffects.push({ type: "session-draining", goAwayUri: goaway.new_session_uri });
219
+ return { ok: true, phase: this._phase, sideEffects };
220
+ }
221
+ requireReady(msgType) {
222
+ if (this._phase !== "ready" && this._phase !== "draining") {
223
+ return violation(
224
+ this._phase === "idle" || this._phase === "setup" ? "MESSAGE_BEFORE_SETUP" : "UNEXPECTED_MESSAGE",
225
+ `${msgType} requires ready phase, current: ${this._phase}`,
226
+ this._phase,
227
+ msgType
228
+ );
229
+ }
230
+ return null;
231
+ }
232
+ handleSubscribe(message, sideEffects) {
233
+ const err = this.requireReady(message.type);
234
+ if (err) return { ok: false, violation: err };
235
+ const sub = message;
236
+ const dupErr = this.checkDuplicateRequestId(sub.request_id, message.type);
237
+ if (dupErr) return { ok: false, violation: dupErr };
238
+ this._requestIds.add(sub.request_id);
239
+ this._subscriptions.set(sub.request_id, {
240
+ subscribeId: sub.request_id,
241
+ phase: "pending",
242
+ trackNamespace: sub.track_namespace,
243
+ trackName: sub.track_name
244
+ });
245
+ this._pendingSubscribes.push(sub.request_id);
246
+ return { ok: true, phase: this._phase, sideEffects };
247
+ }
248
+ handleSubscribeOk(_message, sideEffects) {
249
+ const err = this.requireReady("subscribe_ok");
250
+ if (err) return { ok: false, violation: err };
251
+ const requestId = this._pendingSubscribes.shift();
252
+ if (requestId === void 0) {
253
+ return {
254
+ ok: false,
255
+ violation: violation(
256
+ "UNEXPECTED_MESSAGE",
257
+ "SUBSCRIBE_OK with no pending subscribe",
258
+ this._phase,
259
+ "subscribe_ok"
260
+ )
261
+ };
262
+ }
263
+ const existing = this._subscriptions.get(requestId);
264
+ if (existing && existing.phase === "pending") {
265
+ this._subscriptions.set(requestId, { ...existing, phase: "active" });
266
+ sideEffects.push({ type: "subscription-activated", subscribeId: requestId });
267
+ }
268
+ return { ok: true, phase: this._phase, sideEffects };
269
+ }
270
+ handleRequestUpdate(message, sideEffects) {
271
+ const err = this.requireReady(message.type);
272
+ if (err) return { ok: false, violation: err };
273
+ const update = message;
274
+ const dupErr = this.checkDuplicateRequestId(update.request_id, message.type);
275
+ if (dupErr) return { ok: false, violation: dupErr };
276
+ this._requestIds.add(update.request_id);
277
+ return { ok: true, phase: this._phase, sideEffects };
278
+ }
279
+ handlePublish(message, sideEffects) {
280
+ const err = this.requireReady(message.type);
281
+ if (err) return { ok: false, violation: err };
282
+ const pub = message;
283
+ const dupErr = this.checkDuplicateRequestId(pub.request_id, message.type);
284
+ if (dupErr) return { ok: false, violation: dupErr };
285
+ this._requestIds.add(pub.request_id);
286
+ this._publishes.set(pub.request_id, { requestId: pub.request_id, phase: "pending" });
287
+ this._pendingPublishes.push(pub.request_id);
288
+ return { ok: true, phase: this._phase, sideEffects };
289
+ }
290
+ handlePublishOk(sideEffects) {
291
+ const err = this.requireReady("publish_ok");
292
+ if (err) return { ok: false, violation: err };
293
+ const requestId = this._pendingPublishes.shift();
294
+ if (requestId === void 0) {
295
+ return {
296
+ ok: false,
297
+ violation: violation(
298
+ "UNEXPECTED_MESSAGE",
299
+ "PUBLISH_OK with no pending publish",
300
+ this._phase,
301
+ "publish_ok"
302
+ )
303
+ };
304
+ }
305
+ const existing = this._publishes.get(requestId);
306
+ if (existing && existing.phase === "pending") {
307
+ this._publishes.set(requestId, { ...existing, phase: "active" });
308
+ sideEffects.push({ type: "publish-activated", requestId });
309
+ }
310
+ return { ok: true, phase: this._phase, sideEffects };
311
+ }
312
+ handlePublishDone(_message, sideEffects) {
313
+ const err = this.requireReady("publish_done");
314
+ if (err) return { ok: false, violation: err };
315
+ for (const [reqId, pub] of this._publishes) {
316
+ if (pub.phase === "active") {
317
+ this._publishes.set(reqId, { ...pub, phase: "done" });
318
+ sideEffects.push({ type: "publish-ended", requestId: reqId, reason: "done" });
319
+ break;
320
+ }
321
+ }
322
+ return { ok: true, phase: this._phase, sideEffects };
323
+ }
324
+ handleFetch(message, sideEffects) {
325
+ const err = this.requireReady(message.type);
326
+ if (err) return { ok: false, violation: err };
327
+ const fetch = message;
328
+ const dupErr = this.checkDuplicateRequestId(fetch.request_id, message.type);
329
+ if (dupErr) return { ok: false, violation: dupErr };
330
+ this._requestIds.add(fetch.request_id);
331
+ this._fetches.set(fetch.request_id, { requestId: fetch.request_id, phase: "pending" });
332
+ this._pendingFetches.push(fetch.request_id);
333
+ return { ok: true, phase: this._phase, sideEffects };
334
+ }
335
+ handleFetchOk(sideEffects) {
336
+ const err = this.requireReady("fetch_ok");
337
+ if (err) return { ok: false, violation: err };
338
+ const requestId = this._pendingFetches.shift();
339
+ if (requestId === void 0) {
340
+ return {
341
+ ok: false,
342
+ violation: violation(
343
+ "UNEXPECTED_MESSAGE",
344
+ "FETCH_OK with no pending fetch",
345
+ this._phase,
346
+ "fetch_ok"
347
+ )
348
+ };
349
+ }
350
+ const existing = this._fetches.get(requestId);
351
+ if (existing && existing.phase === "pending") {
352
+ this._fetches.set(requestId, { ...existing, phase: "active" });
353
+ sideEffects.push({ type: "fetch-activated", requestId });
354
+ }
355
+ return { ok: true, phase: this._phase, sideEffects };
356
+ }
357
+ handleRequestError(sideEffects) {
358
+ const err = this.requireReady("request_error");
359
+ if (err) return { ok: false, violation: err };
360
+ const subId = this.dequeuePending(this._pendingSubscribes, this._subscriptions);
361
+ if (subId !== void 0) {
362
+ const sub = this._subscriptions.get(subId);
363
+ this._subscriptions.set(subId, { ...sub, phase: "error" });
364
+ sideEffects.push({ type: "subscription-ended", subscribeId: subId, reason: "request_error" });
365
+ return { ok: true, phase: this._phase, sideEffects };
366
+ }
367
+ const pubId = this.dequeuePending(this._pendingPublishes, this._publishes);
368
+ if (pubId !== void 0) {
369
+ const pub = this._publishes.get(pubId);
370
+ this._publishes.set(pubId, { ...pub, phase: "error" });
371
+ sideEffects.push({ type: "publish-ended", requestId: pubId, reason: "request_error" });
372
+ return { ok: true, phase: this._phase, sideEffects };
373
+ }
374
+ const fetchId = this.dequeuePending(this._pendingFetches, this._fetches);
375
+ if (fetchId !== void 0) {
376
+ const f = this._fetches.get(fetchId);
377
+ this._fetches.set(fetchId, { ...f, phase: "error" });
378
+ sideEffects.push({ type: "fetch-ended", requestId: fetchId, reason: "request_error" });
379
+ return { ok: true, phase: this._phase, sideEffects };
380
+ }
381
+ return { ok: true, phase: this._phase, sideEffects };
382
+ }
383
+ handleRequestOk(sideEffects) {
384
+ const err = this.requireReady("request_ok");
385
+ if (err) return { ok: false, violation: err };
386
+ return { ok: true, phase: this._phase, sideEffects };
387
+ }
388
+ dequeuePending(queue, stateMap) {
389
+ while (queue.length > 0) {
390
+ const id = queue[0];
391
+ const state = stateMap.get(id);
392
+ if (state && state.phase === "pending") {
393
+ queue.shift();
394
+ return id;
395
+ }
396
+ queue.shift();
397
+ }
398
+ return void 0;
399
+ }
400
+ handleReadyPhaseMessage(message) {
401
+ const err = this.requireReady(message.type);
402
+ if (err) return { ok: false, violation: err };
403
+ return { ok: true, phase: this._phase, sideEffects: [] };
404
+ }
405
+ reset() {
406
+ this._phase = "idle";
407
+ this._setupDirection = null;
408
+ this._subscriptions.clear();
409
+ this._publishes.clear();
410
+ this._fetches.clear();
411
+ this._requestIds.clear();
412
+ this._pendingSubscribes.length = 0;
413
+ this._pendingPublishes.length = 0;
414
+ this._pendingFetches.length = 0;
415
+ }
416
+ }, _class);
417
+
418
+ // src/drafts/draft17/session.ts
419
+ function createDraft17SessionState(role) {
420
+ return new Draft17SessionFSM(role);
421
+ }
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+ exports.CONTROL_MESSAGES = CONTROL_MESSAGES; exports.CLIENT_ONLY_MESSAGES = CLIENT_ONLY_MESSAGES; exports.SERVER_ONLY_MESSAGES = SERVER_ONLY_MESSAGES; exports.BIDIRECTIONAL_MESSAGES = BIDIRECTIONAL_MESSAGES; exports.getLegalOutgoing = getLegalOutgoing; exports.getLegalIncoming = getLegalIncoming; exports.Draft17SessionFSM = Draft17SessionFSM; exports.createDraft17SessionState = createDraft17SessionState;
@@ -259,50 +259,44 @@ function encodeFetchError(msg, writer) {
259
259
  function encodeFetchCancel(msg, writer) {
260
260
  writer.writeVarInt(msg.subscribeId);
261
261
  }
262
+ function encodeObjectPayload(msg, writer) {
263
+ if (msg.payload.byteLength === 0) {
264
+ writer.writeVarInt(0);
265
+ writer.writeVarInt(msg.objectStatus ?? 0);
266
+ } else {
267
+ writer.writeVarInt(msg.payload.byteLength);
268
+ writer.writeBytes(msg.payload);
269
+ }
270
+ }
262
271
  function encodeObjectStream(msg, writer) {
263
272
  writer.writeVarInt(MESSAGE_TYPE_IDS.object_stream);
264
- writer.writeVarInt(msg.subscribeId);
265
273
  writer.writeVarInt(msg.trackAlias);
266
274
  writer.writeVarInt(msg.groupId);
267
275
  writer.writeVarInt(msg.objectId);
268
276
  writer.writeUint8(msg.publisherPriority);
269
- if (msg.objectStatus !== void 0) {
270
- writer.writeVarInt(msg.objectStatus);
271
- } else {
272
- writer.writeVarInt(0);
273
- }
274
- writer.writeBytes(msg.payload);
277
+ encodeObjectPayload(msg, writer);
275
278
  }
276
279
  function encodeObjectDatagram(msg, writer) {
277
280
  writer.writeVarInt(MESSAGE_TYPE_IDS.object_datagram);
278
- writer.writeVarInt(msg.subscribeId);
279
281
  writer.writeVarInt(msg.trackAlias);
280
282
  writer.writeVarInt(msg.groupId);
281
283
  writer.writeVarInt(msg.objectId);
282
284
  writer.writeUint8(msg.publisherPriority);
283
- if (msg.objectStatus !== void 0) {
284
- writer.writeVarInt(msg.objectStatus);
285
- } else {
286
- writer.writeVarInt(0);
287
- }
288
- writer.writeBytes(msg.payload);
285
+ encodeObjectPayload(msg, writer);
289
286
  }
290
287
  function encodeStreamHeaderTrack(msg, writer) {
291
288
  writer.writeVarInt(MESSAGE_TYPE_IDS.stream_header_track);
292
- writer.writeVarInt(msg.subscribeId);
293
289
  writer.writeVarInt(msg.trackAlias);
294
290
  writer.writeUint8(msg.publisherPriority);
295
291
  }
296
292
  function encodeStreamHeaderGroup(msg, writer) {
297
293
  writer.writeVarInt(MESSAGE_TYPE_IDS.stream_header_group);
298
- writer.writeVarInt(msg.subscribeId);
299
294
  writer.writeVarInt(msg.trackAlias);
300
295
  writer.writeVarInt(msg.groupId);
301
296
  writer.writeUint8(msg.publisherPriority);
302
297
  }
303
298
  function encodeStreamHeaderSubgroup(msg, writer) {
304
299
  writer.writeVarInt(MESSAGE_TYPE_IDS.stream_header_subgroup);
305
- writer.writeVarInt(msg.subscribeId);
306
300
  writer.writeVarInt(msg.trackAlias);
307
301
  writer.writeVarInt(msg.groupId);
308
302
  writer.writeVarInt(msg.subgroupId);
@@ -608,71 +602,79 @@ function decodeFetchCancel(reader) {
608
602
  return { type: "fetch_cancel", subscribeId };
609
603
  }
610
604
  function decodeObjectStream(reader) {
611
- const subscribeId = reader.readVarInt();
612
605
  const trackAlias = reader.readVarInt();
613
606
  const groupId = reader.readVarInt();
614
607
  const objectId = reader.readVarInt();
615
608
  const publisherPriority = reader.readUint8();
616
- const objectStatusRaw = Number(reader.readVarInt());
617
- const payload = reader.readBytes(reader.remaining);
618
- const base = {
609
+ const payloadLength = Number(reader.readVarInt());
610
+ if (payloadLength === 0) {
611
+ const objectStatus = reader.remaining > 0 ? Number(reader.readVarInt()) : 0;
612
+ return {
613
+ type: "object_stream",
614
+ trackAlias,
615
+ groupId,
616
+ objectId,
617
+ publisherPriority,
618
+ objectStatus,
619
+ payload: new Uint8Array(0)
620
+ };
621
+ }
622
+ const payload = reader.readBytes(payloadLength);
623
+ return {
619
624
  type: "object_stream",
620
- subscribeId,
621
625
  trackAlias,
622
626
  groupId,
623
627
  objectId,
624
628
  publisherPriority,
625
629
  payload
626
630
  };
627
- if (objectStatusRaw !== 0) {
628
- return { ...base, objectStatus: objectStatusRaw };
629
- }
630
- return base;
631
631
  }
632
632
  function decodeObjectDatagram(reader) {
633
- const subscribeId = reader.readVarInt();
634
633
  const trackAlias = reader.readVarInt();
635
634
  const groupId = reader.readVarInt();
636
635
  const objectId = reader.readVarInt();
637
636
  const publisherPriority = reader.readUint8();
638
- const objectStatusRaw = Number(reader.readVarInt());
639
- const payload = reader.readBytes(reader.remaining);
640
- const base = {
637
+ const payloadLength = Number(reader.readVarInt());
638
+ if (payloadLength === 0) {
639
+ const objectStatus = reader.remaining > 0 ? Number(reader.readVarInt()) : 0;
640
+ return {
641
+ type: "object_datagram",
642
+ trackAlias,
643
+ groupId,
644
+ objectId,
645
+ publisherPriority,
646
+ objectStatus,
647
+ payload: new Uint8Array(0)
648
+ };
649
+ }
650
+ const payload = reader.readBytes(payloadLength);
651
+ return {
641
652
  type: "object_datagram",
642
- subscribeId,
643
653
  trackAlias,
644
654
  groupId,
645
655
  objectId,
646
656
  publisherPriority,
647
657
  payload
648
658
  };
649
- if (objectStatusRaw !== 0) {
650
- return { ...base, objectStatus: objectStatusRaw };
651
- }
652
- return base;
653
659
  }
654
660
  function decodeStreamHeaderTrack(reader) {
655
- const subscribeId = reader.readVarInt();
656
661
  const trackAlias = reader.readVarInt();
657
662
  const publisherPriority = reader.readUint8();
658
- return { type: "stream_header_track", subscribeId, trackAlias, publisherPriority };
663
+ return { type: "stream_header_track", trackAlias, publisherPriority };
659
664
  }
660
665
  function decodeStreamHeaderGroup(reader) {
661
- const subscribeId = reader.readVarInt();
662
666
  const trackAlias = reader.readVarInt();
663
667
  const groupId = reader.readVarInt();
664
668
  const publisherPriority = reader.readUint8();
665
- return { type: "stream_header_group", subscribeId, trackAlias, groupId, publisherPriority };
669
+ return { type: "stream_header_group", trackAlias, groupId, publisherPriority };
666
670
  }
667
671
  function decodeStreamHeaderSubgroup(reader) {
668
- const subscribeId = reader.readVarInt();
669
672
  const trackAlias = reader.readVarInt();
670
673
  const groupId = reader.readVarInt();
671
674
  const subgroupId = reader.readVarInt();
672
675
  const publisherPriority = reader.readUint8();
673
676
  return {
674
677
  type: "stream_header_subgroup",
675
- subscribeId,
676
678
  trackAlias,
677
679
  groupId,
678
680
  subgroupId,