@kumiai/rpc 0.9.0 → 0.9.1
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/lib/hub-mux.d.ts +13 -0
- package/lib/hub-mux.js +43 -2
- package/lib/peer.d.ts +10 -0
- package/lib/peer.js +7 -0
- package/package.json +1 -1
package/lib/hub-mux.d.ts
CHANGED
|
@@ -111,6 +111,19 @@ export type HubMux = {
|
|
|
111
111
|
* is not held, so a later retain asks again, carrying its own `options`.
|
|
112
112
|
*/
|
|
113
113
|
retainTopic: (topicID: string, options?: HubSubscribeOptions) => void;
|
|
114
|
+
/**
|
|
115
|
+
* Clear a latched subscribe refusal and ask once more, for a topic whose refusal may now be
|
|
116
|
+
* answered differently — an `AuthorizationDeniedError` cleared by the peer since becoming a group
|
|
117
|
+
* member, above all. Single-shot: it re-asks exactly once and re-latches if the hub still refuses,
|
|
118
|
+
* so the host calls it on each authorization change rather than to poll. A no-op unless the topic
|
|
119
|
+
* is currently refused and still retained; re-asks with the options the hub refused.
|
|
120
|
+
*/
|
|
121
|
+
rearmTopic: (topicID: string) => void;
|
|
122
|
+
/**
|
|
123
|
+
* Rearm every currently-refused topic at once — the group-wide {@link rearmTopic}, for a caller
|
|
124
|
+
* that has become authorized and does not track which topics were individually refused.
|
|
125
|
+
*/
|
|
126
|
+
rearmRefusedTopics: () => void;
|
|
114
127
|
/** Pull a topic's log as the local DID. */
|
|
115
128
|
fetchTopic: (params: MuxFetchTopicParams) => Promise<HubFetchTopicResult>;
|
|
116
129
|
onInbound: (topicID: string, listener: InboundListener, options?: HubSubscribeOptions) => () => void;
|
package/lib/hub-mux.js
CHANGED
|
@@ -151,7 +151,7 @@ const warnReceiveEnded = (ended)=>{
|
|
|
151
151
|
kind: 'refused',
|
|
152
152
|
error,
|
|
153
153
|
permanent,
|
|
154
|
-
|
|
154
|
+
options
|
|
155
155
|
});
|
|
156
156
|
reportFailure({
|
|
157
157
|
topicID,
|
|
@@ -183,12 +183,51 @@ const warnReceiveEnded = (ended)=>{
|
|
|
183
183
|
// downgrade the hub refused to perform, which is worse than the refusal it replaces.
|
|
184
184
|
//
|
|
185
185
|
// A retry-exhausted failure carries no answer, so any retain re-asks.
|
|
186
|
-
if (state.permanent && (options?.retention == null || options.retention === state.retention)) {
|
|
186
|
+
if (state.permanent && (options?.retention == null || options.retention === state.options?.retention)) {
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
189
|
void attemptSubscribe(topicID, options, 0);
|
|
190
190
|
};
|
|
191
191
|
/**
|
|
192
|
+
* Clear a latched refusal so the topic is asked for once more, on the caller's word that the
|
|
193
|
+
* answer may now be different. A permanent refusal — an `AuthorizationDeniedError` above all — is
|
|
194
|
+
* an answer to a request made under conditions that CAN change: a peer refused because it was not
|
|
195
|
+
* yet a group member is admitted moments later, and nothing about that transition re-shapes the
|
|
196
|
+
* request, so the retain gate (which only re-asks under a different retention) never re-drives it.
|
|
197
|
+
* This is the external-event clear the note on `createHubMux` describes, the same shape a freed
|
|
198
|
+
* quota would need: the host, which owns the membership/authorization change the hub cannot see,
|
|
199
|
+
* says "ask again."
|
|
200
|
+
*
|
|
201
|
+
* Single-shot by construction: it re-asks EXACTLY once (via `attemptSubscribe(..., 0)`), and if
|
|
202
|
+
* the hub still refuses, the topic re-latches. A rearm is one fresh chance to ask, never a retry
|
|
203
|
+
* loop — call it again on the next authorization change. A no-op unless the topic is currently
|
|
204
|
+
* `refused` (a held or in-flight subscription is left untouched) and still has holders (a topic
|
|
205
|
+
* nothing retains is not resurrected). Re-asks with the SAME `options` the hub refused.
|
|
206
|
+
*/ const rearmTopic = (topicID)=>{
|
|
207
|
+
if (disposed) return;
|
|
208
|
+
const state = subscriptions.get(topicID);
|
|
209
|
+
if (state?.kind !== 'refused') return;
|
|
210
|
+
const { options } = state;
|
|
211
|
+
subscriptions.delete(topicID);
|
|
212
|
+
if ((refcount.get(topicID) ?? 0) > 0) {
|
|
213
|
+
void attemptSubscribe(topicID, options, 0);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Rearm EVERY currently-refused topic — the group-wide form of {@link rearmTopic}, for a caller
|
|
218
|
+
* that learns it has become authorized without tracking which individual topics were refused
|
|
219
|
+
* (a freshly-admitted group member, whose whole set of group topics was refused during the window
|
|
220
|
+
* before its membership landed). Snapshots the refused set first, so rearming one — which deletes
|
|
221
|
+
* its subscription entry — does not disturb the iteration.
|
|
222
|
+
*/ const rearmRefusedTopics = ()=>{
|
|
223
|
+
if (disposed) return;
|
|
224
|
+
const refused = [];
|
|
225
|
+
for (const [topicID, state] of subscriptions){
|
|
226
|
+
if (state.kind === 'refused') refused.push(topicID);
|
|
227
|
+
}
|
|
228
|
+
for (const topicID of refused)rearmTopic(topicID);
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
192
231
|
* The enforcement half. A topic the hub refused is one this peer cannot read, so it does not go
|
|
193
232
|
* on transmitting there as a full participant either: every publish and every fetch on it
|
|
194
233
|
* rejects with the hub's own error.
|
|
@@ -518,6 +557,8 @@ const warnReceiveEnded = (ended)=>{
|
|
|
518
557
|
retainTopic: (topicID, options)=>{
|
|
519
558
|
retain(topicID, options);
|
|
520
559
|
},
|
|
560
|
+
rearmTopic,
|
|
561
|
+
rearmRefusedTopics,
|
|
521
562
|
fetchTopic,
|
|
522
563
|
onInbound,
|
|
523
564
|
suspendPublishing: ()=>{
|
package/lib/peer.d.ts
CHANGED
|
@@ -244,6 +244,16 @@ export type GroupPeer<Protocols extends Record<string, GroupProtocolDefinition>>
|
|
|
244
244
|
* caller can observe a roster change being detected without reaching into the port.
|
|
245
245
|
*/
|
|
246
246
|
anchorEpoch: () => number;
|
|
247
|
+
/**
|
|
248
|
+
* Re-drive any hub subscription this peer latched as refused, on the host's word that the refusal
|
|
249
|
+
* may now be answered differently. The one case that needs it: a peer whose group topics were
|
|
250
|
+
* subscribed the instant it joined — before the app-level authorization that gates them had landed
|
|
251
|
+
* — is refused `AuthorizationDeniedError`, and that refusal is latched permanent (a busy retry
|
|
252
|
+
* against an answer would be worse). Once the host knows the peer is authorized (its membership
|
|
253
|
+
* row has replicated), it calls this to ask again. Single-shot per call: a topic the hub still
|
|
254
|
+
* refuses simply re-latches, so call it on each authorization change rather than to poll.
|
|
255
|
+
*/
|
|
256
|
+
reauthorize: () => void;
|
|
247
257
|
dispose: () => Promise<void>;
|
|
248
258
|
};
|
|
249
259
|
export declare function createGroupPeer<Protocols extends Record<string, ProtocolDefinition>>(params: GroupPeerParams<Protocols>): GroupPeer<Protocols>;
|
package/lib/peer.js
CHANGED
|
@@ -1740,6 +1740,13 @@ export function createGroupPeer(params) {
|
|
|
1740
1740
|
await runSerial(()=>rebuildEpoch());
|
|
1741
1741
|
},
|
|
1742
1742
|
anchorEpoch: ()=>anchor.epoch,
|
|
1743
|
+
reauthorize: ()=>{
|
|
1744
|
+
// No `assertLive`/`ready` wait: rearming a refused subscription is a synchronous, idempotent
|
|
1745
|
+
// hint the mux applies against its own state, safe on a peer that is still initializing and a
|
|
1746
|
+
// no-op on a disposed one (the mux guards `disposed`). It touches only topics the hub already
|
|
1747
|
+
// refused, so it cannot subscribe anything a normal retain would not have.
|
|
1748
|
+
mux.rearmRefusedTopics();
|
|
1749
|
+
},
|
|
1743
1750
|
dispose: ()=>{
|
|
1744
1751
|
if (disposePromise != null) return disposePromise;
|
|
1745
1752
|
disposed = true;
|