@moqtap/codec 0.8.1 → 0.9.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 (127) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +16 -4
  3. package/dist/chunk-BMJMY6FX.cjs +868 -0
  4. package/dist/chunk-MAXEHYVB.cjs +2362 -0
  5. package/dist/{chunk-3YAR3I3S.js → chunk-Q7NSUXXB.js} +3 -1
  6. package/dist/{chunk-VWXUT5R2.cjs → chunk-TVSFDQYE.cjs} +3 -1
  7. package/dist/chunk-WX5PU7HF.js +868 -0
  8. package/dist/chunk-YJGOD3Y4.js +2362 -0
  9. package/dist/{codec-BLYAy2OP.d.ts → codec--CVeqGQv.d.ts} +1 -1
  10. package/dist/{codec-DujHf55Z.d.ts → codec-BJ7BHuiZ.d.ts} +1 -1
  11. package/dist/{codec-D47r_-Rl.d.ts → codec-BKsVu3Fr.d.ts} +1 -1
  12. package/dist/{codec-BNS3gS77.d.ts → codec-BMwgZIgG.d.ts} +1 -1
  13. package/dist/{codec-CI0BjmHc.d.ts → codec-BNy5syCU.d.ts} +1 -1
  14. package/dist/{codec-v6Vloc7H.d.ts → codec-BQa6Qsav.d.ts} +1 -1
  15. package/dist/codec-Bym-K2q2.d.cts +49 -0
  16. package/dist/{codec-D2JbI2tp.d.ts → codec-C006F75E.d.ts} +1 -1
  17. package/dist/codec-C5evFHL-.d.ts +49 -0
  18. package/dist/{codec-DQWQSam3.d.cts → codec-C6Mx4bwz.d.cts} +1 -1
  19. package/dist/{codec-DL0njGkL.d.ts → codec-CA6nbbEk.d.ts} +1 -1
  20. package/dist/{codec-D89DWXbv.d.cts → codec-CSBFdPgP.d.cts} +1 -1
  21. package/dist/{codec-DvcJgYKq.d.cts → codec-CXCjya_G.d.cts} +1 -1
  22. package/dist/{codec-hvkJfCF5.d.cts → codec-C_xxsbKy.d.cts} +1 -1
  23. package/dist/{codec-BOyrk_C9.d.cts → codec-Cfo_z5ET.d.cts} +1 -1
  24. package/dist/{codec-xeuGZY77.d.cts → codec-CgZdadPt.d.cts} +2 -2
  25. package/dist/{codec-WwwUipaU.d.ts → codec-Cl73EfRW.d.ts} +1 -1
  26. package/dist/{codec-BOtv3R5j.d.cts → codec-CtvFK4aV.d.cts} +1 -1
  27. package/dist/{codec-DAePx2NL.d.ts → codec-CviAa4lp.d.ts} +2 -2
  28. package/dist/{codec-DJmV04i0.d.ts → codec-D4RvFQmu.d.ts} +1 -1
  29. package/dist/{codec-cou9XBMF.d.cts → codec-DAyiF5sq.d.cts} +1 -1
  30. package/dist/{codec-CyApDKwf.d.cts → codec-DJmqoIsp.d.cts} +1 -1
  31. package/dist/{codec-NMsTK0GX.d.cts → codec-DchsPfr3.d.cts} +1 -1
  32. package/dist/{codec-DplRgIKq.d.ts → codec-Dl_QIXMz.d.ts} +1 -1
  33. package/dist/{codec-N3g1lxQQ.d.cts → codec-DzLvG8Wb.d.cts} +1 -1
  34. package/dist/{codec-D95gT98n.d.cts → codec-DzkdW4kO.d.cts} +1 -1
  35. package/dist/{codec-CWj5iTxA.d.ts → codec-O-1Js7h4.d.ts} +1 -1
  36. package/dist/{codec-BqqoYdh_.d.cts → codec-vddqy0KY.d.cts} +1 -1
  37. package/dist/draft07-session.d.cts +3 -3
  38. package/dist/draft07-session.d.ts +3 -3
  39. package/dist/draft07.d.cts +3 -3
  40. package/dist/draft07.d.ts +3 -3
  41. package/dist/draft08-session.d.cts +3 -3
  42. package/dist/draft08-session.d.ts +3 -3
  43. package/dist/draft08.d.cts +4 -4
  44. package/dist/draft08.d.ts +4 -4
  45. package/dist/draft09-session.d.cts +3 -3
  46. package/dist/draft09-session.d.ts +3 -3
  47. package/dist/draft09.d.cts +4 -4
  48. package/dist/draft09.d.ts +4 -4
  49. package/dist/draft10-session.d.cts +3 -3
  50. package/dist/draft10-session.d.ts +3 -3
  51. package/dist/draft10.d.cts +4 -4
  52. package/dist/draft10.d.ts +4 -4
  53. package/dist/draft11-session.d.cts +3 -3
  54. package/dist/draft11-session.d.ts +3 -3
  55. package/dist/draft11.d.cts +4 -4
  56. package/dist/draft11.d.ts +4 -4
  57. package/dist/draft12-session.d.cts +3 -3
  58. package/dist/draft12-session.d.ts +3 -3
  59. package/dist/draft12.d.cts +4 -4
  60. package/dist/draft12.d.ts +4 -4
  61. package/dist/draft13-session.d.cts +3 -3
  62. package/dist/draft13-session.d.ts +3 -3
  63. package/dist/draft13.d.cts +4 -4
  64. package/dist/draft13.d.ts +4 -4
  65. package/dist/draft14-session.d.cts +3 -3
  66. package/dist/draft14-session.d.ts +3 -3
  67. package/dist/draft14.d.cts +4 -4
  68. package/dist/draft14.d.ts +4 -4
  69. package/dist/draft15-session.d.cts +3 -3
  70. package/dist/draft15-session.d.ts +3 -3
  71. package/dist/draft15.d.cts +4 -4
  72. package/dist/draft15.d.ts +4 -4
  73. package/dist/draft16-session.d.cts +3 -3
  74. package/dist/draft16-session.d.ts +3 -3
  75. package/dist/draft16.d.cts +4 -4
  76. package/dist/draft16.d.ts +4 -4
  77. package/dist/draft17-session.d.cts +3 -3
  78. package/dist/draft17-session.d.ts +3 -3
  79. package/dist/draft17.d.cts +3 -3
  80. package/dist/draft17.d.ts +3 -3
  81. package/dist/draft18-session.d.cts +3 -3
  82. package/dist/draft18-session.d.ts +3 -3
  83. package/dist/draft18.d.cts +3 -3
  84. package/dist/draft18.d.ts +3 -3
  85. package/dist/draft19-session.d.cts +3 -3
  86. package/dist/draft19-session.d.ts +3 -3
  87. package/dist/draft19.cjs +2 -2
  88. package/dist/draft19.d.cts +3 -3
  89. package/dist/draft19.d.ts +3 -3
  90. package/dist/draft19.js +1 -1
  91. package/dist/draft20-session.cjs +8 -0
  92. package/dist/draft20-session.d.cts +195 -0
  93. package/dist/draft20-session.d.ts +195 -0
  94. package/dist/draft20-session.js +8 -0
  95. package/dist/draft20.cjs +217 -0
  96. package/dist/draft20.d.cts +175 -0
  97. package/dist/draft20.d.ts +175 -0
  98. package/dist/draft20.js +217 -0
  99. package/dist/index.cjs +9 -3
  100. package/dist/index.d.cts +32 -17
  101. package/dist/index.d.ts +32 -17
  102. package/dist/index.js +8 -2
  103. package/dist/{session-types-KsqyVp6y.d.cts → session-types-B9idsih-.d.cts} +13 -1
  104. package/dist/{session-types-C0l_-Ups.d.ts → session-types-Dn7b3RZM.d.ts} +13 -1
  105. package/dist/session.cjs +5 -1
  106. package/dist/session.d.cts +5 -3
  107. package/dist/session.d.ts +5 -3
  108. package/dist/session.js +5 -1
  109. package/dist/types-CWCQwuvy.d.cts +359 -0
  110. package/dist/types-CWCQwuvy.d.ts +359 -0
  111. package/dist/{types-CdCSIfvI.d.cts → types-DG5_iKuv.d.cts} +1 -1
  112. package/dist/{types-CdCSIfvI.d.ts → types-DG5_iKuv.d.ts} +1 -1
  113. package/package.json +16 -3
  114. package/src/core/session-types.ts +7 -0
  115. package/src/core/types.ts +1 -0
  116. package/src/drafts/draft19/codec.ts +4 -2
  117. package/src/drafts/draft20/codec.ts +1737 -0
  118. package/src/drafts/draft20/data-streams.ts +1291 -0
  119. package/src/drafts/draft20/error-codes.ts +135 -0
  120. package/src/drafts/draft20/index.ts +165 -0
  121. package/src/drafts/draft20/messages.ts +68 -0
  122. package/src/drafts/draft20/rules.ts +107 -0
  123. package/src/drafts/draft20/session-fsm.ts +1063 -0
  124. package/src/drafts/draft20/session.ts +21 -0
  125. package/src/drafts/draft20/types.ts +455 -0
  126. package/src/index.ts +20 -2
  127. package/src/session.ts +4 -0
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkBMJMY6FXcjs = require('./chunk-BMJMY6FX.cjs');
5
+
6
+
7
+
8
+ exports.Draft20SessionFSM = _chunkBMJMY6FXcjs.Draft20SessionFSM; exports.createDraft20SessionState = _chunkBMJMY6FXcjs.createDraft20SessionState;
@@ -0,0 +1,195 @@
1
+ import { g as SessionPhase, j as SubscriptionState, b as AnnounceState, f as PublishState, c as FetchState, V as ValidationResult, T as TransitionResult, h as SideEffect } from './session-types-B9idsih-.cjs';
2
+ export { P as ProtocolViolation } from './session-types-B9idsih-.cjs';
3
+ import { a as Draft20MessageType, D as Draft20Message } from './types-CWCQwuvy.cjs';
4
+ import './types-DG5_iKuv.cjs';
5
+
6
+ /**
7
+ * What kind of request a bidirectional request stream carries.
8
+ *
9
+ * draft-20 keeps the draft-17 shape where a response is tied to its request by
10
+ * the stream it arrives on rather than by a Request ID field. Several draft-20
11
+ * rules are stated per request *kind* — most sharply
12
+ * "PUBLISH_STATE_NOTIFY applies only to subscriptions ... An endpoint that
13
+ * receives a PUBLISH_STATE_NOTIFY for any other request type ... MUST close
14
+ * the session with a PROTOCOL_VIOLATION" (Section 10.10) — so the FSM has to
15
+ * know which stream a message arrived on to enforce them. That is what
16
+ * {@link Draft20SessionFSM.receiveOn} and {@link Draft20SessionFSM.sendOn} are
17
+ * for.
18
+ */
19
+ type RequestKind = 'subscription' | 'fetch' | 'track_status' | 'publish_namespace' | 'subscribe_namespace' | 'subscribe_tracks';
20
+ /** Whether the local endpoint or the peer is the publisher on a request stream. */
21
+ type PublisherSide = 'local' | 'remote';
22
+ type FillFetchStreamPhase = 'open' | 'complete' | 'reset' | 'cancelled';
23
+ /**
24
+ * One fill fetch stream — draft-20 Section 5.1.3, new in draft-20.
25
+ *
26
+ * A unidirectional stream that begins with FETCH_HEADER and is delivered
27
+ * exactly as a FETCH response, opened because a SUBSCRIBE or REQUEST_UPDATE
28
+ * carried FILL_PARAMETERS. It is NOT a FETCH: there is no FETCH request, no
29
+ * FETCH_OK and no REQUEST_ERROR for it, so it never appears in
30
+ * {@link Draft20SessionFSM.fetches}.
31
+ */
32
+ interface FillFetchStreamState {
33
+ /**
34
+ * The Request ID of the message that opened it — the SUBSCRIBE's for the
35
+ * initial fill, the REQUEST_UPDATE's for a later one (Section 5.1.3). This
36
+ * is what the stream's FETCH_HEADER carries, and it is how a subscription's
37
+ * concurrent fills are told apart.
38
+ */
39
+ readonly requestId: bigint;
40
+ /** The Request ID of the subscription the fill belongs to. */
41
+ readonly subscribeId: bigint;
42
+ readonly phase: FillFetchStreamPhase;
43
+ }
44
+ declare class Draft20SessionFSM {
45
+ private _phase;
46
+ private _role;
47
+ private _setupDirection;
48
+ private _subscriptions;
49
+ private _subscriptionMeta;
50
+ private _publishes;
51
+ private _fetches;
52
+ private _requests;
53
+ private _requestIds;
54
+ private _pendingSubscribes;
55
+ private _pendingPublishes;
56
+ private _pendingFetches;
57
+ /**
58
+ * The peer's MAX_REQUEST_UPDATES (Setup Option 0x08), learned from its SETUP.
59
+ * 0 means the peer does not limit REQUEST_UPDATE concurrency, and 0 is also
60
+ * the default when the option is absent.
61
+ */
62
+ private _peerMaxRequestUpdates;
63
+ /** The local endpoint's own advertised MAX_REQUEST_UPDATES. */
64
+ private _localMaxRequestUpdates;
65
+ constructor(role: 'client' | 'server');
66
+ get phase(): SessionPhase;
67
+ get role(): 'client' | 'server';
68
+ get subscriptions(): ReadonlyMap<bigint, SubscriptionState>;
69
+ get announces(): ReadonlyMap<string, AnnounceState>;
70
+ get publishes(): ReadonlyMap<bigint, PublishState>;
71
+ get fetches(): ReadonlyMap<bigint, FetchState>;
72
+ get legalOutgoing(): ReadonlySet<Draft20MessageType>;
73
+ get legalIncoming(): ReadonlySet<Draft20MessageType>;
74
+ /**
75
+ * Every fill fetch stream currently tracked, across all subscriptions, keyed
76
+ * by the Request ID that opened it.
77
+ *
78
+ * Fill fetch streams are unidirectional and carry no control messages, so
79
+ * nothing here is inferred from a message alone; the transport events that
80
+ * end one are reported with {@link closeFillFetchStream}.
81
+ */
82
+ get fillFetchStreams(): ReadonlyMap<bigint, FillFetchStreamState>;
83
+ /** The fill fetch streams belonging to one subscription. */
84
+ fillFetchStreamsFor(subscribeId: bigint): ReadonlyMap<bigint, FillFetchStreamState>;
85
+ /** A subscription's current Forward State, or undefined if it is unknown here. */
86
+ forwardStateOf(subscribeId: bigint): 0 | 1 | undefined;
87
+ /** What kind of request a Request ID names, or undefined if it names none. */
88
+ requestKindOf(requestId: bigint): RequestKind | undefined;
89
+ private checkDuplicateRequestId;
90
+ validateOutgoing(message: Draft20Message): ValidationResult<Draft20MessageType>;
91
+ receive(message: Draft20Message): TransitionResult<Draft20MessageType>;
92
+ send(message: Draft20Message): TransitionResult<Draft20MessageType>;
93
+ /**
94
+ * Receive a message that arrived on a known request stream.
95
+ *
96
+ * Prefer this over {@link receive} for anything that carries no Request ID of
97
+ * its own — SUBSCRIBE_OK, REQUEST_OK, REQUEST_ERROR, PUBLISH_DONE, FETCH_OK
98
+ * and PUBLISH_STATE_NOTIFY. Without the stream, the request-kind and
99
+ * direction rules of Section 10.10 cannot be checked at all, and the
100
+ * response-matching below falls back to FIFO guessing.
101
+ */
102
+ receiveOn(requestId: bigint, message: Draft20Message): TransitionResult<Draft20MessageType>;
103
+ /** Send a message on a known request stream. See {@link receiveOn}. */
104
+ sendOn(requestId: bigint, message: Draft20Message): TransitionResult<Draft20MessageType>;
105
+ private applyTransition;
106
+ private handleSetup;
107
+ private handleGoAway;
108
+ private requireReady;
109
+ private handleSubscribe;
110
+ /**
111
+ * Open a fill fetch stream if this message asked for one — draft-20 Sections
112
+ * 5.1.3 and 5.1.3.1, both new in draft-20.
113
+ *
114
+ * Three rules, all of which the draft states as bullets and all of which are
115
+ * easy to get wrong by analogy with draft-19's Joining FETCH:
116
+ *
117
+ * 1. Presence of FILL_PARAMETERS is the request. There is no separate
118
+ * message and no Fetch Type; an empty FILL_PARAMETERS still opens a
119
+ * stream, with every setting inherited from the subscription.
120
+ * 2. It only opens one "while Forward State is 1". FILL_PARAMETERS carried
121
+ * while Forward State is 0 opens nothing, and later transitioning to
122
+ * Forward State 1 without re-sending FILL_PARAMETERS opens nothing
123
+ * either — so this is checked at the moment the message is processed and
124
+ * never retried.
125
+ * 3. Streams accumulate. The new one is keyed by the opening message's
126
+ * Request ID and does not disturb any stream already open on the same
127
+ * subscription.
128
+ *
129
+ * The opened stream has no FETCH_OK: per DECISIONS.md D7 (SPEC-DELTA Section
130
+ * 11 Q9) there is no End Location and no End Of Track for a fill, and stream
131
+ * FIN is the only completion signal. Nothing here synthesizes one, and the
132
+ * stream is deliberately absent from {@link fetches}.
133
+ */
134
+ private applyFillParameters;
135
+ /**
136
+ * Report the transport event that ended a fill fetch stream.
137
+ *
138
+ * A fill fetch stream carries no control message of its own, so its end is
139
+ * never inferable from the message sequence:
140
+ *
141
+ * - `'complete'` — the publisher FINed the stream. Section 5.1.3.1 makes
142
+ * that the ONLY completion signal; there is no FETCH_OK to read an End
143
+ * Location or an End Of Track flag from (DECISIONS.md D7 / Q9).
144
+ * - `'reset'` — the publisher reset it, which is how a fill failure is
145
+ * signalled, "because there is no REQUEST_ERROR associated with a fill
146
+ * fetch stream".
147
+ * - `'cancelled'` — the subscriber sent STOP_SENDING.
148
+ *
149
+ * Either way "Resetting or cancelling a fill fetch stream, by either
150
+ * endpoint, does not affect the subscription, which continues to deliver
151
+ * objects using subscribe subgroups and datagrams", so the subscription's
152
+ * own state is untouched here.
153
+ */
154
+ closeFillFetchStream(requestId: bigint, phase: Exclude<FillFetchStreamPhase, 'open'>): SideEffect[];
155
+ private handleSubscribeOk;
156
+ private handleRequestUpdate;
157
+ /**
158
+ * PUBLISH_STATE_NOTIFY — draft-20 Section 10.10, new in draft-20.
159
+ *
160
+ * Three properties set it apart from every other control message, and all
161
+ * three are enforced here:
162
+ *
163
+ * - **Unilateral.** "The receiver does not respond with REQUEST_OK or
164
+ * REQUEST_ERROR", so nothing is queued as pending and nothing is
165
+ * dequeued. A REQUEST_OK arriving later belongs to some other request.
166
+ * - **Not rate-limited.** "The message is not subject to the
167
+ * MAX_REQUEST_UPDATES limit", so `outstandingUpdates` is deliberately not
168
+ * touched — that counter exists only for REQUEST_UPDATE.
169
+ * - **Publisher to subscriber, subscriptions only.** "An endpoint that
170
+ * receives a PUBLISH_STATE_NOTIFY for any other request type, or from the
171
+ * subscriber, MUST close the session with a PROTOCOL_VIOLATION."
172
+ *
173
+ * The last one needs the request stream, because the message has no Request
174
+ * ID field. Called through {@link receive}/{@link send} without one, the
175
+ * kind and direction rules cannot be evaluated and the message is allowed
176
+ * through unchecked rather than guessed at.
177
+ */
178
+ private handlePublishStateNotify;
179
+ private handlePublish;
180
+ private handlePublishDone;
181
+ private handleFetch;
182
+ private handleFetchOk;
183
+ private handleRequestError;
184
+ private handleRequestOk;
185
+ private handleGenericRequest;
186
+ private restoreUpdateCredit;
187
+ private dropPending;
188
+ private dequeuePending;
189
+ private handleReadyPhaseMessage;
190
+ reset(): void;
191
+ }
192
+
193
+ declare function createDraft20SessionState(role: 'client' | 'server'): Draft20SessionFSM;
194
+
195
+ export { Draft20SessionFSM, type FillFetchStreamPhase, type FillFetchStreamState, type PublisherSide, type RequestKind, SessionPhase, SideEffect, TransitionResult, ValidationResult, createDraft20SessionState };
@@ -0,0 +1,195 @@
1
+ import { g as SessionPhase, j as SubscriptionState, b as AnnounceState, f as PublishState, c as FetchState, V as ValidationResult, T as TransitionResult, h as SideEffect } from './session-types-Dn7b3RZM.js';
2
+ export { P as ProtocolViolation } from './session-types-Dn7b3RZM.js';
3
+ import { a as Draft20MessageType, D as Draft20Message } from './types-CWCQwuvy.js';
4
+ import './types-DG5_iKuv.js';
5
+
6
+ /**
7
+ * What kind of request a bidirectional request stream carries.
8
+ *
9
+ * draft-20 keeps the draft-17 shape where a response is tied to its request by
10
+ * the stream it arrives on rather than by a Request ID field. Several draft-20
11
+ * rules are stated per request *kind* — most sharply
12
+ * "PUBLISH_STATE_NOTIFY applies only to subscriptions ... An endpoint that
13
+ * receives a PUBLISH_STATE_NOTIFY for any other request type ... MUST close
14
+ * the session with a PROTOCOL_VIOLATION" (Section 10.10) — so the FSM has to
15
+ * know which stream a message arrived on to enforce them. That is what
16
+ * {@link Draft20SessionFSM.receiveOn} and {@link Draft20SessionFSM.sendOn} are
17
+ * for.
18
+ */
19
+ type RequestKind = 'subscription' | 'fetch' | 'track_status' | 'publish_namespace' | 'subscribe_namespace' | 'subscribe_tracks';
20
+ /** Whether the local endpoint or the peer is the publisher on a request stream. */
21
+ type PublisherSide = 'local' | 'remote';
22
+ type FillFetchStreamPhase = 'open' | 'complete' | 'reset' | 'cancelled';
23
+ /**
24
+ * One fill fetch stream — draft-20 Section 5.1.3, new in draft-20.
25
+ *
26
+ * A unidirectional stream that begins with FETCH_HEADER and is delivered
27
+ * exactly as a FETCH response, opened because a SUBSCRIBE or REQUEST_UPDATE
28
+ * carried FILL_PARAMETERS. It is NOT a FETCH: there is no FETCH request, no
29
+ * FETCH_OK and no REQUEST_ERROR for it, so it never appears in
30
+ * {@link Draft20SessionFSM.fetches}.
31
+ */
32
+ interface FillFetchStreamState {
33
+ /**
34
+ * The Request ID of the message that opened it — the SUBSCRIBE's for the
35
+ * initial fill, the REQUEST_UPDATE's for a later one (Section 5.1.3). This
36
+ * is what the stream's FETCH_HEADER carries, and it is how a subscription's
37
+ * concurrent fills are told apart.
38
+ */
39
+ readonly requestId: bigint;
40
+ /** The Request ID of the subscription the fill belongs to. */
41
+ readonly subscribeId: bigint;
42
+ readonly phase: FillFetchStreamPhase;
43
+ }
44
+ declare class Draft20SessionFSM {
45
+ private _phase;
46
+ private _role;
47
+ private _setupDirection;
48
+ private _subscriptions;
49
+ private _subscriptionMeta;
50
+ private _publishes;
51
+ private _fetches;
52
+ private _requests;
53
+ private _requestIds;
54
+ private _pendingSubscribes;
55
+ private _pendingPublishes;
56
+ private _pendingFetches;
57
+ /**
58
+ * The peer's MAX_REQUEST_UPDATES (Setup Option 0x08), learned from its SETUP.
59
+ * 0 means the peer does not limit REQUEST_UPDATE concurrency, and 0 is also
60
+ * the default when the option is absent.
61
+ */
62
+ private _peerMaxRequestUpdates;
63
+ /** The local endpoint's own advertised MAX_REQUEST_UPDATES. */
64
+ private _localMaxRequestUpdates;
65
+ constructor(role: 'client' | 'server');
66
+ get phase(): SessionPhase;
67
+ get role(): 'client' | 'server';
68
+ get subscriptions(): ReadonlyMap<bigint, SubscriptionState>;
69
+ get announces(): ReadonlyMap<string, AnnounceState>;
70
+ get publishes(): ReadonlyMap<bigint, PublishState>;
71
+ get fetches(): ReadonlyMap<bigint, FetchState>;
72
+ get legalOutgoing(): ReadonlySet<Draft20MessageType>;
73
+ get legalIncoming(): ReadonlySet<Draft20MessageType>;
74
+ /**
75
+ * Every fill fetch stream currently tracked, across all subscriptions, keyed
76
+ * by the Request ID that opened it.
77
+ *
78
+ * Fill fetch streams are unidirectional and carry no control messages, so
79
+ * nothing here is inferred from a message alone; the transport events that
80
+ * end one are reported with {@link closeFillFetchStream}.
81
+ */
82
+ get fillFetchStreams(): ReadonlyMap<bigint, FillFetchStreamState>;
83
+ /** The fill fetch streams belonging to one subscription. */
84
+ fillFetchStreamsFor(subscribeId: bigint): ReadonlyMap<bigint, FillFetchStreamState>;
85
+ /** A subscription's current Forward State, or undefined if it is unknown here. */
86
+ forwardStateOf(subscribeId: bigint): 0 | 1 | undefined;
87
+ /** What kind of request a Request ID names, or undefined if it names none. */
88
+ requestKindOf(requestId: bigint): RequestKind | undefined;
89
+ private checkDuplicateRequestId;
90
+ validateOutgoing(message: Draft20Message): ValidationResult<Draft20MessageType>;
91
+ receive(message: Draft20Message): TransitionResult<Draft20MessageType>;
92
+ send(message: Draft20Message): TransitionResult<Draft20MessageType>;
93
+ /**
94
+ * Receive a message that arrived on a known request stream.
95
+ *
96
+ * Prefer this over {@link receive} for anything that carries no Request ID of
97
+ * its own — SUBSCRIBE_OK, REQUEST_OK, REQUEST_ERROR, PUBLISH_DONE, FETCH_OK
98
+ * and PUBLISH_STATE_NOTIFY. Without the stream, the request-kind and
99
+ * direction rules of Section 10.10 cannot be checked at all, and the
100
+ * response-matching below falls back to FIFO guessing.
101
+ */
102
+ receiveOn(requestId: bigint, message: Draft20Message): TransitionResult<Draft20MessageType>;
103
+ /** Send a message on a known request stream. See {@link receiveOn}. */
104
+ sendOn(requestId: bigint, message: Draft20Message): TransitionResult<Draft20MessageType>;
105
+ private applyTransition;
106
+ private handleSetup;
107
+ private handleGoAway;
108
+ private requireReady;
109
+ private handleSubscribe;
110
+ /**
111
+ * Open a fill fetch stream if this message asked for one — draft-20 Sections
112
+ * 5.1.3 and 5.1.3.1, both new in draft-20.
113
+ *
114
+ * Three rules, all of which the draft states as bullets and all of which are
115
+ * easy to get wrong by analogy with draft-19's Joining FETCH:
116
+ *
117
+ * 1. Presence of FILL_PARAMETERS is the request. There is no separate
118
+ * message and no Fetch Type; an empty FILL_PARAMETERS still opens a
119
+ * stream, with every setting inherited from the subscription.
120
+ * 2. It only opens one "while Forward State is 1". FILL_PARAMETERS carried
121
+ * while Forward State is 0 opens nothing, and later transitioning to
122
+ * Forward State 1 without re-sending FILL_PARAMETERS opens nothing
123
+ * either — so this is checked at the moment the message is processed and
124
+ * never retried.
125
+ * 3. Streams accumulate. The new one is keyed by the opening message's
126
+ * Request ID and does not disturb any stream already open on the same
127
+ * subscription.
128
+ *
129
+ * The opened stream has no FETCH_OK: per DECISIONS.md D7 (SPEC-DELTA Section
130
+ * 11 Q9) there is no End Location and no End Of Track for a fill, and stream
131
+ * FIN is the only completion signal. Nothing here synthesizes one, and the
132
+ * stream is deliberately absent from {@link fetches}.
133
+ */
134
+ private applyFillParameters;
135
+ /**
136
+ * Report the transport event that ended a fill fetch stream.
137
+ *
138
+ * A fill fetch stream carries no control message of its own, so its end is
139
+ * never inferable from the message sequence:
140
+ *
141
+ * - `'complete'` — the publisher FINed the stream. Section 5.1.3.1 makes
142
+ * that the ONLY completion signal; there is no FETCH_OK to read an End
143
+ * Location or an End Of Track flag from (DECISIONS.md D7 / Q9).
144
+ * - `'reset'` — the publisher reset it, which is how a fill failure is
145
+ * signalled, "because there is no REQUEST_ERROR associated with a fill
146
+ * fetch stream".
147
+ * - `'cancelled'` — the subscriber sent STOP_SENDING.
148
+ *
149
+ * Either way "Resetting or cancelling a fill fetch stream, by either
150
+ * endpoint, does not affect the subscription, which continues to deliver
151
+ * objects using subscribe subgroups and datagrams", so the subscription's
152
+ * own state is untouched here.
153
+ */
154
+ closeFillFetchStream(requestId: bigint, phase: Exclude<FillFetchStreamPhase, 'open'>): SideEffect[];
155
+ private handleSubscribeOk;
156
+ private handleRequestUpdate;
157
+ /**
158
+ * PUBLISH_STATE_NOTIFY — draft-20 Section 10.10, new in draft-20.
159
+ *
160
+ * Three properties set it apart from every other control message, and all
161
+ * three are enforced here:
162
+ *
163
+ * - **Unilateral.** "The receiver does not respond with REQUEST_OK or
164
+ * REQUEST_ERROR", so nothing is queued as pending and nothing is
165
+ * dequeued. A REQUEST_OK arriving later belongs to some other request.
166
+ * - **Not rate-limited.** "The message is not subject to the
167
+ * MAX_REQUEST_UPDATES limit", so `outstandingUpdates` is deliberately not
168
+ * touched — that counter exists only for REQUEST_UPDATE.
169
+ * - **Publisher to subscriber, subscriptions only.** "An endpoint that
170
+ * receives a PUBLISH_STATE_NOTIFY for any other request type, or from the
171
+ * subscriber, MUST close the session with a PROTOCOL_VIOLATION."
172
+ *
173
+ * The last one needs the request stream, because the message has no Request
174
+ * ID field. Called through {@link receive}/{@link send} without one, the
175
+ * kind and direction rules cannot be evaluated and the message is allowed
176
+ * through unchecked rather than guessed at.
177
+ */
178
+ private handlePublishStateNotify;
179
+ private handlePublish;
180
+ private handlePublishDone;
181
+ private handleFetch;
182
+ private handleFetchOk;
183
+ private handleRequestError;
184
+ private handleRequestOk;
185
+ private handleGenericRequest;
186
+ private restoreUpdateCredit;
187
+ private dropPending;
188
+ private dequeuePending;
189
+ private handleReadyPhaseMessage;
190
+ reset(): void;
191
+ }
192
+
193
+ declare function createDraft20SessionState(role: 'client' | 'server'): Draft20SessionFSM;
194
+
195
+ export { Draft20SessionFSM, type FillFetchStreamPhase, type FillFetchStreamState, type PublisherSide, type RequestKind, SessionPhase, SideEffect, TransitionResult, ValidationResult, createDraft20SessionState };
@@ -0,0 +1,8 @@
1
+ import {
2
+ Draft20SessionFSM,
3
+ createDraft20SessionState
4
+ } from "./chunk-WX5PU7HF.js";
5
+ export {
6
+ Draft20SessionFSM,
7
+ createDraft20SessionState
8
+ };
@@ -0,0 +1,217 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ var _chunkMAXEHYVBcjs = require('./chunk-MAXEHYVB.cjs');
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+ var _chunkBMJMY6FXcjs = require('./chunk-BMJMY6FX.cjs');
58
+ require('./chunk-4XLYCT5Q.cjs');
59
+
60
+ // src/drafts/draft20/error-codes.ts
61
+ var SessionTerminationCode = {
62
+ NoError: 0x0n,
63
+ InternalError: 0x1n,
64
+ Unauthorized: 0x2n,
65
+ ProtocolViolation: 0x3n,
66
+ InvalidRequestId: 0x4n,
67
+ DuplicateTrackAlias: 0x5n,
68
+ KeyValueFormattingError: 0x6n,
69
+ InvalidPath: 0x8n,
70
+ MalformedPath: 0x9n,
71
+ GoawayTimeout: 0x10n,
72
+ ControlMessageTimeout: 0x11n,
73
+ DataStreamTimeout: 0x12n,
74
+ AuthTokenCacheOverflow: 0x13n,
75
+ DuplicateAuthTokenAlias: 0x14n,
76
+ // 0x15 VERSION_NEGOTIATION_FAILED — REMOVED in draft-20. Version negotiation
77
+ // moved to ALPN / WT-Available-Protocols in draft-15, so there is no longer a
78
+ // SETUP-time negotiation that can fail. See RETIRED_SESSION_TERMINATION_CODES.
79
+ MalformedAuthToken: 0x16n,
80
+ UnknownAuthTokenAlias: 0x17n,
81
+ ExpiredAuthToken: 0x18n,
82
+ InvalidAuthority: 0x19n,
83
+ MalformedAuthority: 0x1an,
84
+ TooManyRequestUpdates: 0x1bn
85
+ };
86
+ var RequestErrorCode = {
87
+ InternalError: 0x0n,
88
+ Unauthorized: 0x1n,
89
+ Timeout: 0x2n,
90
+ NotSupported: 0x3n,
91
+ MalformedAuthToken: 0x4n,
92
+ ExpiredAuthToken: 0x5n,
93
+ GoingAway: 0x6n,
94
+ ExcessiveLoad: 0x9n,
95
+ DoesNotExist: 0x10n,
96
+ InvalidRange: 0x11n,
97
+ MalformedTrack: 0x12n,
98
+ Uninterested: 0x20n,
99
+ PrefixOverlap: 0x30n,
100
+ NamespaceTooLarge: 0x31n,
101
+ // 0x32 INVALID_JOINING_REQUEST_ID — REMOVED in draft-20 along with the whole
102
+ // joining-fetch mechanism (draft-19 Section 10.12.2). A draft-20 FETCH names
103
+ // its own track inline and never references another request, so there is no
104
+ // joining Request ID left to be invalid. See RETIRED_REQUEST_ERROR_CODES.
105
+ UnsupportedExtension: 0x33n,
106
+ Redirect: 0x34n,
107
+ ConflictingFilters: 0x35n,
108
+ InvalidFilter: 0x36n
109
+ };
110
+ var PublishDoneCode = {
111
+ InternalError: 0x0n,
112
+ Unauthorized: 0x1n,
113
+ TrackEnded: 0x2n,
114
+ // 0x3 SUBSCRIPTION_ENDED — REMOVED in draft-20. The behaviour went with it:
115
+ // Section 5.1.2 now says "A publisher does not end a subscription solely
116
+ // because the Largest Object advances past the end of the current Location
117
+ // Filter", which is the only thing this code used to report.
118
+ // See RETIRED_PUBLISH_DONE_CODES.
119
+ GoingAway: 0x4n,
120
+ TooFarBehind: 0x5n,
121
+ Expired: 0x6n,
122
+ UpdateFailed: 0x8n,
123
+ ExcessiveLoad: 0x9n,
124
+ MalformedTrack: 0x12n
125
+ };
126
+ var DataStreamResetCode = {
127
+ InternalError: 0x0n,
128
+ Cancelled: 0x1n,
129
+ DeliveryTimeout: 0x2n,
130
+ SessionClosed: 0x3n,
131
+ GoingAway: 0x4n,
132
+ TooFarBehind: 0x5n,
133
+ UnknownObjectStatus: 0x6n,
134
+ ExpiredAuthToken: 0x7n,
135
+ ExcessiveLoad: 0x9n,
136
+ MalformedTrack: 0x12n
137
+ };
138
+ var RETIRED_SESSION_TERMINATION_CODES = /* @__PURE__ */ new Set([
139
+ 0x15n
140
+ // VERSION_NEGOTIATION_FAILED (draft-19 Section 3.5)
141
+ ]);
142
+ var RETIRED_REQUEST_ERROR_CODES = /* @__PURE__ */ new Set([
143
+ 0x32n
144
+ // INVALID_JOINING_REQUEST_ID (draft-19 Section 10.6.2)
145
+ ]);
146
+ var RETIRED_PUBLISH_DONE_CODES = /* @__PURE__ */ new Set([
147
+ 0x3n
148
+ // SUBSCRIPTION_ENDED (draft-19 Section 10.11)
149
+ ]);
150
+
151
+ // src/drafts/draft20/index.ts
152
+ var PROTOCOL_STRING = "moqt-20";
153
+ var DRAFT_VERSION = 0xff000014n;
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+ exports.BIDIRECTIONAL_MESSAGES = _chunkBMJMY6FXcjs.BIDIRECTIONAL_MESSAGES; exports.CLIENT_ONLY_MESSAGES = _chunkBMJMY6FXcjs.CLIENT_ONLY_MESSAGES; exports.CONTROL_MESSAGES = _chunkBMJMY6FXcjs.CONTROL_MESSAGES; exports.DRAFT_VERSION = DRAFT_VERSION; exports.DataStreamResetCode = DataStreamResetCode; exports.Draft20SessionFSM = _chunkBMJMY6FXcjs.Draft20SessionFSM; exports.MESSAGE_ID_MAP = _chunkMAXEHYVBcjs.MESSAGE_ID_MAP; exports.MESSAGE_TYPE_MAP = _chunkMAXEHYVBcjs.MESSAGE_TYPE_MAP; exports.MSG_FETCH = _chunkMAXEHYVBcjs.MSG_FETCH; exports.MSG_FETCH_OK = _chunkMAXEHYVBcjs.MSG_FETCH_OK; exports.MSG_GOAWAY = _chunkMAXEHYVBcjs.MSG_GOAWAY; exports.MSG_NAMESPACE = _chunkMAXEHYVBcjs.MSG_NAMESPACE; exports.MSG_NAMESPACE_DONE = _chunkMAXEHYVBcjs.MSG_NAMESPACE_DONE; exports.MSG_PUBLISH = _chunkMAXEHYVBcjs.MSG_PUBLISH; exports.MSG_PUBLISH_DONE = _chunkMAXEHYVBcjs.MSG_PUBLISH_DONE; exports.MSG_PUBLISH_NAMESPACE = _chunkMAXEHYVBcjs.MSG_PUBLISH_NAMESPACE; exports.MSG_PUBLISH_OK = _chunkMAXEHYVBcjs.MSG_PUBLISH_OK; exports.MSG_PUBLISH_SKIPPED = _chunkMAXEHYVBcjs.MSG_PUBLISH_SKIPPED; exports.MSG_PUBLISH_STATE_NOTIFY = _chunkMAXEHYVBcjs.MSG_PUBLISH_STATE_NOTIFY; exports.MSG_REQUEST_ERROR = _chunkMAXEHYVBcjs.MSG_REQUEST_ERROR; exports.MSG_REQUEST_OK = _chunkMAXEHYVBcjs.MSG_REQUEST_OK; exports.MSG_REQUEST_UPDATE = _chunkMAXEHYVBcjs.MSG_REQUEST_UPDATE; exports.MSG_SETUP = _chunkMAXEHYVBcjs.MSG_SETUP; exports.MSG_SUBSCRIBE = _chunkMAXEHYVBcjs.MSG_SUBSCRIBE; exports.MSG_SUBSCRIBE_NAMESPACE = _chunkMAXEHYVBcjs.MSG_SUBSCRIBE_NAMESPACE; exports.MSG_SUBSCRIBE_OK = _chunkMAXEHYVBcjs.MSG_SUBSCRIBE_OK; exports.MSG_SUBSCRIBE_TRACKS = _chunkMAXEHYVBcjs.MSG_SUBSCRIBE_TRACKS; exports.MSG_TRACK_STATUS = _chunkMAXEHYVBcjs.MSG_TRACK_STATUS; exports.PROTOCOL_STRING = PROTOCOL_STRING; exports.PublishDoneCode = PublishDoneCode; exports.REQUEST_STREAM_OPENERS = _chunkBMJMY6FXcjs.REQUEST_STREAM_OPENERS; exports.RETIRED_PUBLISH_DONE_CODES = RETIRED_PUBLISH_DONE_CODES; exports.RETIRED_REQUEST_ERROR_CODES = RETIRED_REQUEST_ERROR_CODES; exports.RETIRED_SESSION_TERMINATION_CODES = RETIRED_SESSION_TERMINATION_CODES; exports.RequestErrorCode = RequestErrorCode; exports.SERVER_ONLY_MESSAGES = _chunkBMJMY6FXcjs.SERVER_ONLY_MESSAGES; exports.SETUP_OPT_AUTHORITY = _chunkMAXEHYVBcjs.SETUP_OPT_AUTHORITY; exports.SETUP_OPT_AUTHORIZATION_TOKEN = _chunkMAXEHYVBcjs.SETUP_OPT_AUTHORIZATION_TOKEN; exports.SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE = _chunkMAXEHYVBcjs.SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE; exports.SETUP_OPT_MAX_FILTER_RANGES = _chunkMAXEHYVBcjs.SETUP_OPT_MAX_FILTER_RANGES; exports.SETUP_OPT_MAX_REQUEST_UPDATES = _chunkMAXEHYVBcjs.SETUP_OPT_MAX_REQUEST_UPDATES; exports.SETUP_OPT_MOQT_IMPLEMENTATION = _chunkMAXEHYVBcjs.SETUP_OPT_MOQT_IMPLEMENTATION; exports.SETUP_OPT_PATH = _chunkMAXEHYVBcjs.SETUP_OPT_PATH; exports.SessionTerminationCode = SessionTerminationCode; exports.UNKNOWN_STREAM_COUNT = _chunkMAXEHYVBcjs.UNKNOWN_STREAM_COUNT; exports.createDataStreamDecoder = _chunkMAXEHYVBcjs.createDataStreamDecoder; exports.createDraft20Codec = _chunkMAXEHYVBcjs.createDraft20Codec; exports.createDraft20SessionState = _chunkBMJMY6FXcjs.createDraft20SessionState; exports.createFetchStreamDecoder = _chunkMAXEHYVBcjs.createFetchStreamDecoder; exports.createStreamDecoder = _chunkMAXEHYVBcjs.createStreamDecoder; exports.createSubgroupStreamDecoder = _chunkMAXEHYVBcjs.createSubgroupStreamDecoder; exports.decodeDataStream = _chunkMAXEHYVBcjs.decodeDataStream; exports.decodeDatagram = _chunkMAXEHYVBcjs.decodeDatagram; exports.decodeFetchStream = _chunkMAXEHYVBcjs.decodeFetchStream; exports.decodeMessage = _chunkMAXEHYVBcjs.decodeMessage; exports.decodeSubgroupStream = _chunkMAXEHYVBcjs.decodeSubgroupStream; exports.encodeDatagram = _chunkMAXEHYVBcjs.encodeDatagram; exports.encodeFetchStream = _chunkMAXEHYVBcjs.encodeFetchStream; exports.encodeMessage = _chunkMAXEHYVBcjs.encodeMessage; exports.encodeSubgroupStream = _chunkMAXEHYVBcjs.encodeSubgroupStream; exports.getLegalIncoming = _chunkBMJMY6FXcjs.getLegalIncoming; exports.getLegalOutgoing = _chunkBMJMY6FXcjs.getLegalOutgoing;