@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.
- package/README.md +99 -95
- package/dist/chunk-4RIXXEII.js +1275 -0
- package/dist/chunk-4XYGE53S.cjs +698 -0
- package/dist/chunk-4YJANAXU.cjs +1109 -0
- package/dist/chunk-6AEHWULA.cjs +641 -0
- package/dist/chunk-7DUBLRXC.js +680 -0
- package/dist/{chunk-YBZD3DU5.cjs → chunk-7IVGHMKJ.cjs} +44 -42
- package/dist/chunk-BISI45MN.cjs +680 -0
- package/dist/{chunk-NLYTRGXA.cjs → chunk-BPNL5YFQ.cjs} +5 -5
- package/dist/chunk-CXDHOMHG.js +1097 -0
- package/dist/chunk-DUBCL3WF.cjs +749 -0
- package/dist/chunk-DWK5ZQZ4.js +642 -0
- package/dist/chunk-E6E3NQYU.js +680 -0
- package/dist/chunk-EFM5T7OM.js +698 -0
- package/dist/chunk-ENURAVHI.cjs +680 -0
- package/dist/{chunk-Z66WDWHI.js → chunk-FXZ2MYKJ.js} +127 -1
- package/dist/chunk-G26SJ6XS.cjs +1341 -0
- package/dist/chunk-G7GI7LJA.js +737 -0
- package/dist/chunk-GXEW4COZ.cjs +737 -0
- package/dist/chunk-HSVYF6XX.cjs +1361 -0
- package/dist/chunk-IBVM4DMJ.cjs +1097 -0
- package/dist/chunk-IV2H5CFI.cjs +1275 -0
- package/dist/chunk-IV2HRJVT.js +1198 -0
- package/dist/chunk-JSQM2MG3.js +680 -0
- package/dist/chunk-K4OLITS2.cjs +1055 -0
- package/dist/{chunk-UOBWHJA5.js → chunk-KFTCU2P6.js} +2 -3
- package/dist/chunk-LH4NTURO.js +1361 -0
- package/dist/{chunk-YTXLWKOR.js → chunk-MFAP7R6L.js} +1 -1
- package/dist/chunk-NGVE2RZT.js +1097 -0
- package/dist/chunk-NUX5BHWO.js +1341 -0
- package/dist/chunk-PJRA2TQ5.js +1055 -0
- package/dist/chunk-RVJAGE4S.cjs +1198 -0
- package/dist/{chunk-QYG6KGOV.cjs → chunk-RWQ43Z4F.cjs} +2 -3
- package/dist/chunk-RZHAPEXO.js +749 -0
- package/dist/chunk-ST24APEO.js +1109 -0
- package/dist/chunk-SYHW3FLI.cjs +642 -0
- package/dist/chunk-TLYNOOQP.cjs +432 -0
- package/dist/{chunk-IXHOBNXA.js → chunk-TMNGRIPL.js} +43 -41
- package/dist/chunk-UNS34PTA.cjs +680 -0
- package/dist/chunk-UR6JKS56.js +432 -0
- package/dist/{chunk-NPWHHWXT.cjs → chunk-UYXTY6ZQ.cjs} +127 -1
- package/dist/chunk-XUUCOLWU.cjs +1097 -0
- package/dist/chunk-YG5KJESI.js +641 -0
- package/dist/chunk-ZBKE2QRQ.js +1401 -0
- package/dist/chunk-ZSPO2GF2.cjs +1401 -0
- package/dist/codec-95k8CAu5.d.cts +35 -0
- package/dist/codec-AFuOxfsO.d.ts +60 -0
- package/dist/codec-B-UJ5Iow.d.cts +75 -0
- package/dist/codec-BC5jfvMb.d.ts +35 -0
- package/dist/codec-BECYPfY8.d.ts +35 -0
- package/dist/codec-BsPU1vNC.d.ts +39 -0
- package/dist/codec-BvpuF-6u.d.cts +39 -0
- package/dist/codec-C8jZI5Cx.d.cts +39 -0
- package/dist/codec-CAevkgf5.d.cts +33 -0
- package/dist/codec-CSUqCrRs.d.ts +39 -0
- package/dist/codec-C_HMXNK_.d.ts +33 -0
- package/dist/{codec-Bvr7rFtj.d.cts → codec-CpuvYTSV.d.cts} +1 -1
- package/dist/codec-D0x8-SCw.d.cts +35 -0
- package/dist/codec-D7ARhpG1.d.ts +75 -0
- package/dist/codec-DNAUGshO.d.cts +60 -0
- package/dist/codec-DPx_QNn0.d.ts +31 -0
- package/dist/{codec-B2mc2g3i.d.ts → codec-DRhCx_hw.d.ts} +1 -1
- package/dist/codec-Db7YPe3l.d.ts +31 -0
- package/dist/codec-axkJpb7D.d.cts +31 -0
- package/dist/codec-ujAbFaep.d.cts +31 -0
- package/dist/draft10-session.cjs +6 -0
- package/dist/draft10-session.d.cts +8 -0
- package/dist/draft10-session.d.ts +8 -0
- package/dist/draft10-session.js +6 -0
- package/dist/draft10.cjs +115 -0
- package/dist/draft10.d.cts +95 -0
- package/dist/draft10.d.ts +95 -0
- package/dist/draft10.js +115 -0
- package/dist/draft11-session.cjs +6 -0
- package/dist/draft11-session.d.cts +8 -0
- package/dist/draft11-session.d.ts +8 -0
- package/dist/draft11-session.js +6 -0
- package/dist/draft11.cjs +109 -0
- package/dist/draft11.d.cts +99 -0
- package/dist/draft11.d.ts +99 -0
- package/dist/draft11.js +109 -0
- package/dist/draft12-session.cjs +6 -0
- package/dist/draft12-session.d.cts +8 -0
- package/dist/draft12-session.d.ts +8 -0
- package/dist/draft12-session.js +6 -0
- package/dist/draft12.cjs +117 -0
- package/dist/draft12.d.cts +106 -0
- package/dist/draft12.d.ts +106 -0
- package/dist/draft12.js +117 -0
- package/dist/draft13-session.cjs +6 -0
- package/dist/draft13-session.d.cts +8 -0
- package/dist/draft13-session.d.ts +8 -0
- package/dist/draft13-session.js +6 -0
- package/dist/draft13.cjs +119 -0
- package/dist/draft13.d.cts +108 -0
- package/dist/draft13.d.ts +108 -0
- package/dist/draft13.js +119 -0
- package/dist/draft14-session.cjs +2 -2
- package/dist/draft14-session.d.cts +3 -3
- package/dist/draft14-session.d.ts +3 -3
- package/dist/draft14-session.js +1 -1
- package/dist/draft14.cjs +3 -3
- package/dist/draft14.d.cts +16 -4
- package/dist/draft14.d.ts +16 -4
- package/dist/draft14.js +2 -2
- package/dist/draft15-session.cjs +6 -0
- package/dist/draft15-session.d.cts +8 -0
- package/dist/draft15-session.d.ts +8 -0
- package/dist/draft15-session.js +6 -0
- package/dist/draft15.cjs +111 -0
- package/dist/draft15.d.cts +93 -0
- package/dist/draft15.d.ts +93 -0
- package/dist/draft15.js +111 -0
- package/dist/draft16-session.cjs +6 -0
- package/dist/draft16-session.d.cts +8 -0
- package/dist/draft16-session.d.ts +8 -0
- package/dist/draft16-session.js +6 -0
- package/dist/draft16.cjs +113 -0
- package/dist/draft16.d.cts +94 -0
- package/dist/draft16.d.ts +94 -0
- package/dist/draft16.js +113 -0
- package/dist/draft17-session.cjs +8 -0
- package/dist/draft17-session.d.cts +51 -0
- package/dist/draft17-session.d.ts +51 -0
- package/dist/draft17-session.js +8 -0
- package/dist/draft17.cjs +99 -0
- package/dist/draft17.d.cts +40 -0
- package/dist/draft17.d.ts +40 -0
- package/dist/draft17.js +99 -0
- package/dist/draft7-session.cjs +3 -3
- package/dist/draft7-session.d.cts +3 -3
- package/dist/draft7-session.d.ts +3 -3
- package/dist/draft7-session.js +2 -2
- package/dist/draft7.cjs +4 -4
- package/dist/draft7.d.cts +2 -2
- package/dist/draft7.d.ts +2 -2
- package/dist/draft7.js +2 -2
- package/dist/draft8-session.cjs +6 -0
- package/dist/draft8-session.d.cts +8 -0
- package/dist/draft8-session.d.ts +8 -0
- package/dist/draft8-session.js +6 -0
- package/dist/draft8.cjs +115 -0
- package/dist/draft8.d.cts +95 -0
- package/dist/draft8.d.ts +95 -0
- package/dist/draft8.js +115 -0
- package/dist/draft9-session.cjs +6 -0
- package/dist/draft9-session.d.cts +8 -0
- package/dist/draft9-session.d.ts +8 -0
- package/dist/draft9-session.js +6 -0
- package/dist/draft9.cjs +115 -0
- package/dist/draft9.d.cts +95 -0
- package/dist/draft9.d.ts +95 -0
- package/dist/draft9.js +115 -0
- package/dist/index.cjs +76 -4
- package/dist/index.d.cts +68 -5
- package/dist/index.d.ts +68 -5
- package/dist/index.js +76 -4
- package/dist/{session-types-DFjMk4HH.d.ts → session-types-CJIFbTPd.d.ts} +1 -1
- package/dist/{session-types-DW1RSZX_.d.cts → session-types-Cbq8IGCP.d.cts} +1 -1
- package/dist/session.cjs +5 -5
- package/dist/session.d.cts +3 -3
- package/dist/session.d.ts +3 -3
- package/dist/session.js +5 -5
- package/dist/types-4VxSL2Ho.d.cts +261 -0
- package/dist/types-4VxSL2Ho.d.ts +261 -0
- package/dist/types-B2afJZM-.d.cts +236 -0
- package/dist/types-B2afJZM-.d.ts +236 -0
- package/dist/types-Bg6QYNVt.d.cts +290 -0
- package/dist/types-Bg6QYNVt.d.ts +290 -0
- package/dist/types-C_1HrqBl.d.cts +306 -0
- package/dist/types-C_1HrqBl.d.ts +306 -0
- package/dist/types-Cw4WE9dh.d.cts +261 -0
- package/dist/types-Cw4WE9dh.d.ts +261 -0
- package/dist/types-D5gNQiDj.d.cts +261 -0
- package/dist/types-D5gNQiDj.d.ts +261 -0
- package/dist/types-DqCDFqgB.d.cts +230 -0
- package/dist/types-DqCDFqgB.d.ts +230 -0
- package/dist/types-ERexTpT8.d.cts +217 -0
- package/dist/types-ERexTpT8.d.ts +217 -0
- package/dist/{types-DPYE49t0.d.cts → types-QNXoxC9Y.d.cts} +2 -7
- package/dist/{types-DPYE49t0.d.ts → types-QNXoxC9Y.d.ts} +2 -7
- package/dist/types-r-CasCf1.d.cts +262 -0
- package/dist/types-r-CasCf1.d.ts +262 -0
- package/package.json +110 -2
- package/src/core/types.ts +24 -7
- package/src/drafts/draft07/codec.ts +49 -41
- package/src/drafts/draft07/rules.ts +1 -3
- package/src/drafts/draft08/codec.ts +1254 -0
- package/src/drafts/draft08/index.ts +125 -0
- package/src/drafts/draft08/messages.ts +72 -0
- package/src/drafts/draft08/rules.ts +91 -0
- package/src/drafts/draft08/session-fsm.ts +718 -0
- package/src/drafts/draft08/session.ts +26 -0
- package/src/drafts/draft08/types.ts +377 -0
- package/src/drafts/draft09/codec.ts +1235 -0
- package/src/drafts/draft09/index.ts +125 -0
- package/src/drafts/draft09/messages.ts +72 -0
- package/src/drafts/draft09/rules.ts +91 -0
- package/src/drafts/draft09/session-fsm.ts +718 -0
- package/src/drafts/draft09/session.ts +26 -0
- package/src/drafts/draft09/types.ts +376 -0
- package/src/drafts/draft10/codec.ts +1235 -0
- package/src/drafts/draft10/index.ts +125 -0
- package/src/drafts/draft10/messages.ts +72 -0
- package/src/drafts/draft10/rules.ts +91 -0
- package/src/drafts/draft10/session-fsm.ts +718 -0
- package/src/drafts/draft10/session.ts +26 -0
- package/src/drafts/draft10/types.ts +376 -0
- package/src/drafts/draft11/codec.ts +1198 -0
- package/src/drafts/draft11/index.ts +123 -0
- package/src/drafts/draft11/messages.ts +71 -0
- package/src/drafts/draft11/rules.ts +100 -0
- package/src/drafts/draft11/session-fsm.ts +758 -0
- package/src/drafts/draft11/session.ts +26 -0
- package/src/drafts/draft11/types.ts +375 -0
- package/src/drafts/draft12/codec.ts +1354 -0
- package/src/drafts/draft12/index.ts +130 -0
- package/src/drafts/draft12/messages.ts +84 -0
- package/src/drafts/draft12/rules.ts +106 -0
- package/src/drafts/draft12/session-fsm.ts +805 -0
- package/src/drafts/draft12/session.ts +26 -0
- package/src/drafts/draft12/types.ts +414 -0
- package/src/drafts/draft13/codec.ts +1438 -0
- package/src/drafts/draft13/index.ts +132 -0
- package/src/drafts/draft13/messages.ts +86 -0
- package/src/drafts/draft13/rules.ts +108 -0
- package/src/drafts/draft13/session-fsm.ts +819 -0
- package/src/drafts/draft13/session.ts +26 -0
- package/src/drafts/draft13/types.ts +433 -0
- package/src/drafts/draft14/session-fsm.ts +182 -1
- package/src/drafts/draft15/codec.ts +1661 -0
- package/src/drafts/draft15/index.ts +121 -0
- package/src/drafts/draft15/messages.ts +64 -0
- package/src/drafts/draft15/rules.ts +95 -0
- package/src/drafts/draft15/session-fsm.ts +687 -0
- package/src/drafts/draft15/session.ts +26 -0
- package/src/drafts/draft15/types.ts +336 -0
- package/src/drafts/draft16/codec.ts +1623 -0
- package/src/drafts/draft16/index.ts +123 -0
- package/src/drafts/draft16/messages.ts +67 -0
- package/src/drafts/draft16/rules.ts +96 -0
- package/src/drafts/draft16/session-fsm.ts +682 -0
- package/src/drafts/draft16/session.ts +26 -0
- package/src/drafts/draft16/types.ts +354 -0
- package/src/drafts/draft17/codec.ts +1621 -0
- package/src/drafts/draft17/index.ts +105 -0
- package/src/drafts/draft17/messages.ts +53 -0
- package/src/drafts/draft17/rules.ts +85 -0
- package/src/drafts/draft17/session-fsm.ts +437 -0
- package/src/drafts/draft17/session.ts +15 -0
- package/src/drafts/draft17/types.ts +310 -0
- package/src/index.ts +217 -2
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// 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 {
|
|
74
|
+
_phase = "idle";
|
|
75
|
+
_role;
|
|
76
|
+
_setupDirection = null;
|
|
77
|
+
_subscriptions = /* @__PURE__ */ new Map();
|
|
78
|
+
_publishes = /* @__PURE__ */ new Map();
|
|
79
|
+
_fetches = /* @__PURE__ */ new Map();
|
|
80
|
+
_requestIds = /* @__PURE__ */ new Set();
|
|
81
|
+
_pendingSubscribes = [];
|
|
82
|
+
_pendingPublishes = [];
|
|
83
|
+
_pendingFetches = [];
|
|
84
|
+
constructor(role) {
|
|
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
|
+
};
|
|
417
|
+
|
|
418
|
+
// src/drafts/draft17/session.ts
|
|
419
|
+
function createDraft17SessionState(role) {
|
|
420
|
+
return new Draft17SessionFSM(role);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export {
|
|
424
|
+
CONTROL_MESSAGES,
|
|
425
|
+
CLIENT_ONLY_MESSAGES,
|
|
426
|
+
SERVER_ONLY_MESSAGES,
|
|
427
|
+
BIDIRECTIONAL_MESSAGES,
|
|
428
|
+
getLegalOutgoing,
|
|
429
|
+
getLegalIncoming,
|
|
430
|
+
Draft17SessionFSM,
|
|
431
|
+
createDraft17SessionState
|
|
432
|
+
};
|
|
@@ -234,7 +234,34 @@ var Draft14SessionFSM = (_class = class {
|
|
|
234
234
|
return this.handleFetchError(message, direction, sideEffects);
|
|
235
235
|
case "fetch_cancel":
|
|
236
236
|
return this.handleFetchCancel(message, direction, sideEffects);
|
|
237
|
-
// Publish namespace
|
|
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
|
|
238
265
|
default:
|
|
239
266
|
return this.handleReadyPhaseMessage(message);
|
|
240
267
|
}
|
|
@@ -678,6 +705,105 @@ var Draft14SessionFSM = (_class = class {
|
|
|
678
705
|
sideEffects.push({ type: "fetch-ended", requestId: cancel.request_id, reason: "cancelled" });
|
|
679
706
|
return { ok: true, phase: this._phase, sideEffects };
|
|
680
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
|
+
}
|
|
681
807
|
// ─── Generic ready-phase handler ──────────────────────────────────────────────
|
|
682
808
|
handleReadyPhaseMessage(message) {
|
|
683
809
|
const err = this.requireReady(message.type);
|