@ironflow/browser 0.20.2 → 0.21.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 +1 -1
- package/dist/agents/index.d.ts +34 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +24 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/invoke.d.ts +16 -0
- package/dist/agents/invoke.d.ts.map +1 -0
- package/dist/agents/invoke.js +222 -0
- package/dist/agents/invoke.js.map +1 -0
- package/dist/agents/readMemory.d.ts +18 -0
- package/dist/agents/readMemory.d.ts.map +1 -0
- package/dist/agents/readMemory.js +87 -0
- package/dist/agents/readMemory.js.map +1 -0
- package/dist/agents/subscribe.d.ts +23 -0
- package/dist/agents/subscribe.d.ts.map +1 -0
- package/dist/agents/subscribe.js +117 -0
- package/dist/agents/subscribe.js.map +1 -0
- package/dist/agents/types.d.ts +156 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +7 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/client.d.ts +844 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +2243 -0
- package/dist/client.js.map +1 -0
- package/dist/config-client.d.ts +43 -0
- package/dist/config-client.d.ts.map +1 -0
- package/dist/config-client.js +134 -0
- package/dist/config-client.js.map +1 -0
- package/dist/config.d.ts +91 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +55 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/kv.d.ts +79 -0
- package/dist/kv.d.ts.map +1 -0
- package/dist/kv.js +289 -0
- package/dist/kv.js.map +1 -0
- package/dist/projection-stream.d.ts +42 -0
- package/dist/projection-stream.d.ts.map +1 -0
- package/dist/projection-stream.js +48 -0
- package/dist/projection-stream.js.map +1 -0
- package/dist/subscription.d.ts +107 -0
- package/dist/subscription.d.ts.map +1 -0
- package/dist/subscription.js +450 -0
- package/dist/subscription.js.map +1 -0
- package/dist/transport/connectrpc.d.ts +74 -0
- package/dist/transport/connectrpc.d.ts.map +1 -0
- package/dist/transport/connectrpc.js +393 -0
- package/dist/transport/connectrpc.js.map +1 -0
- package/dist/transport/index.d.ts +7 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +6 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/types.d.ts +69 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +5 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/transport/websocket.d.ts +38 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +276 -0
- package/dist/transport/websocket.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription management for browser client
|
|
3
|
+
*/
|
|
4
|
+
import { generateId, createNoopLogger } from "@ironflow/core";
|
|
5
|
+
/**
|
|
6
|
+
* Default auto-connect timeout (ms) used by subscribe() when the transport is
|
|
7
|
+
* not yet connected. 10s matches the transport's default connection timeout.
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_AUTO_CONNECT_TIMEOUT_MS = 10_000;
|
|
10
|
+
/**
|
|
11
|
+
* Subscription manager handles all active subscriptions
|
|
12
|
+
*/
|
|
13
|
+
export class SubscriptionManager {
|
|
14
|
+
transport;
|
|
15
|
+
// Logger is stored for future use (debugging, diagnostics)
|
|
16
|
+
_logger;
|
|
17
|
+
subscriptions = new Map();
|
|
18
|
+
patternToId = new Map();
|
|
19
|
+
pendingPatterns = new Map();
|
|
20
|
+
/** Maps pattern to array of pending lookupKeys for O(1) lookup */
|
|
21
|
+
patternToPendingKeys = new Map();
|
|
22
|
+
connectionChangeCallbacks = new Set();
|
|
23
|
+
errorCallbacks = new Set();
|
|
24
|
+
/** Shared in-flight connect promise so concurrent subscribe() calls don't double-connect. */
|
|
25
|
+
connectPromise = null;
|
|
26
|
+
/** Wired in constructor; removed in disconnect(). SSR-guarded. */
|
|
27
|
+
visibilityListener = null;
|
|
28
|
+
autoConnectTimeoutMs;
|
|
29
|
+
/**
|
|
30
|
+
* Count of currently active (non-pending) subscriptions. Surfaced via
|
|
31
|
+
* `ironflow.getActiveSubscriptionCount()` for leak audits and
|
|
32
|
+
* diagnostics.
|
|
33
|
+
*/
|
|
34
|
+
get activeSubscriptionCount() {
|
|
35
|
+
return this.subscriptions.size;
|
|
36
|
+
}
|
|
37
|
+
constructor(transport, logger) {
|
|
38
|
+
this.transport = transport;
|
|
39
|
+
this._logger = logger === false ? createNoopLogger() : (logger ?? createNoopLogger());
|
|
40
|
+
this._logger.debug("SubscriptionManager initialized");
|
|
41
|
+
this.autoConnectTimeoutMs = DEFAULT_AUTO_CONNECT_TIMEOUT_MS;
|
|
42
|
+
// Set up transport callbacks
|
|
43
|
+
const callbacks = {
|
|
44
|
+
onEvent: this.handleEvent.bind(this),
|
|
45
|
+
onError: this.handleError.bind(this),
|
|
46
|
+
onConnectionChange: this.handleConnectionChange.bind(this),
|
|
47
|
+
onSubscribed: this.handleSubscribed.bind(this),
|
|
48
|
+
onSubscribeFailed: this.handleSubscribeFailed.bind(this),
|
|
49
|
+
};
|
|
50
|
+
this.transport.setCallbacks(callbacks);
|
|
51
|
+
// Wire Page Visibility API: on return to foreground, if the transport has
|
|
52
|
+
// silently died (mobile Safari / long-backgrounded tab), trigger a
|
|
53
|
+
// reconnect health-check instead of waiting for the next user interaction.
|
|
54
|
+
if (typeof document !== "undefined" && typeof document.addEventListener === "function") {
|
|
55
|
+
const listener = () => {
|
|
56
|
+
if (document.hidden) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const state = this.transport.connectionState;
|
|
60
|
+
if (state !== "connected" && state !== "connecting") {
|
|
61
|
+
this.ensureConnected().catch(() => {
|
|
62
|
+
// Best-effort; transport's own reconnect loop continues.
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
document.addEventListener("visibilitychange", listener);
|
|
67
|
+
this.visibilityListener = listener;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Subscribe to events matching a pattern
|
|
72
|
+
*/
|
|
73
|
+
async subscribe(pattern, callbacksAndOptions) {
|
|
74
|
+
// Handle array of patterns
|
|
75
|
+
if (Array.isArray(pattern)) {
|
|
76
|
+
const subscriptions = [];
|
|
77
|
+
try {
|
|
78
|
+
for (const p of pattern) {
|
|
79
|
+
const sub = await this.subscribeSingle(p, callbacksAndOptions);
|
|
80
|
+
subscriptions.push(sub);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// Rollback successful subscriptions on failure
|
|
85
|
+
for (const sub of subscriptions) {
|
|
86
|
+
sub.unsubscribe();
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
// Return a combined subscription
|
|
91
|
+
const combinedPattern = pattern.join(",");
|
|
92
|
+
const combinedId = generateId();
|
|
93
|
+
const combinedSub = {
|
|
94
|
+
id: combinedId,
|
|
95
|
+
pattern: combinedPattern,
|
|
96
|
+
connectionState: this.transport.connectionState,
|
|
97
|
+
unsubscribe: () => {
|
|
98
|
+
for (const sub of subscriptions) {
|
|
99
|
+
sub.unsubscribe();
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
return combinedSub;
|
|
104
|
+
}
|
|
105
|
+
return this.subscribeSingle(pattern, callbacksAndOptions);
|
|
106
|
+
}
|
|
107
|
+
async subscribeSingle(pattern, callbacksAndOptions) {
|
|
108
|
+
// Extract options and callbacks
|
|
109
|
+
const { replay, includeMetadata, filter, namespace, consumerGroup, ackMode, backpressure, trackState, ...callbacks } = callbacksAndOptions;
|
|
110
|
+
const options = {
|
|
111
|
+
replay,
|
|
112
|
+
includeMetadata,
|
|
113
|
+
filter,
|
|
114
|
+
namespace,
|
|
115
|
+
consumerGroup,
|
|
116
|
+
ackMode,
|
|
117
|
+
backpressure,
|
|
118
|
+
trackState,
|
|
119
|
+
};
|
|
120
|
+
// Generate lookup key: for consumer groups, allow multiple subscriptions to same pattern
|
|
121
|
+
// by appending a unique ID; for broadcast, use pattern directly to prevent duplicates
|
|
122
|
+
const lookupKey = consumerGroup
|
|
123
|
+
? `${pattern}:cg:${generateId()}`
|
|
124
|
+
: pattern;
|
|
125
|
+
// Check if already subscribed (only for broadcast subscriptions)
|
|
126
|
+
if (!consumerGroup && this.patternToId.has(lookupKey)) {
|
|
127
|
+
throw new Error(`Already subscribed to pattern: ${pattern}`);
|
|
128
|
+
}
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
const tempId = generateId();
|
|
131
|
+
const pending = {
|
|
132
|
+
id: tempId,
|
|
133
|
+
pattern,
|
|
134
|
+
lookupKey,
|
|
135
|
+
options,
|
|
136
|
+
callbacks: callbacks,
|
|
137
|
+
connectionState: this.transport.connectionState,
|
|
138
|
+
resolve: resolve,
|
|
139
|
+
reject,
|
|
140
|
+
};
|
|
141
|
+
this.pendingPatterns.set(lookupKey, pending);
|
|
142
|
+
// Track lookupKey by pattern for efficient lookup when server responds
|
|
143
|
+
const pendingKeys = this.patternToPendingKeys.get(pattern) ?? [];
|
|
144
|
+
pendingKeys.push(lookupKey);
|
|
145
|
+
this.patternToPendingKeys.set(pattern, pendingKeys);
|
|
146
|
+
// Auto-connect: callers shouldn't need to call connect() before
|
|
147
|
+
// subscribe(). When already connected, we call transport.subscribe
|
|
148
|
+
// synchronously (fast path — matches pre-#536 behavior). Otherwise we
|
|
149
|
+
// await connect and then subscribe, rejecting the promise if connect
|
|
150
|
+
// fails or times out. Fixes #536 Defect A, where watch()/subscribe()
|
|
151
|
+
// would hang forever waiting on a connect nobody kicked off.
|
|
152
|
+
if (this.transport.connectionState === "connected") {
|
|
153
|
+
this.transport.subscribe(pattern, options);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this.ensureConnected().then(() => {
|
|
157
|
+
// Guard against disconnect() racing with connect: disconnect()
|
|
158
|
+
// clears pendingPatterns, so if ours is gone, settle the outer
|
|
159
|
+
// promise with a clear rejection instead of hanging — hanging
|
|
160
|
+
// forever is the exact class of bug this PR fixes.
|
|
161
|
+
if (!this.pendingPatterns.has(lookupKey)) {
|
|
162
|
+
reject(new Error("ironflow: subscription canceled before connect completed"));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
this.transport.subscribe(pattern, options);
|
|
166
|
+
}, (err) => {
|
|
167
|
+
this.removePending(pattern, lookupKey);
|
|
168
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/** Remove a pending subscription entry from both tracking maps. */
|
|
173
|
+
removePending(pattern, lookupKey) {
|
|
174
|
+
this.pendingPatterns.delete(lookupKey);
|
|
175
|
+
const keys = this.patternToPendingKeys.get(pattern);
|
|
176
|
+
if (!keys)
|
|
177
|
+
return;
|
|
178
|
+
const idx = keys.indexOf(lookupKey);
|
|
179
|
+
if (idx >= 0)
|
|
180
|
+
keys.splice(idx, 1);
|
|
181
|
+
if (keys.length === 0)
|
|
182
|
+
this.patternToPendingKeys.delete(pattern);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Unsubscribe by pattern
|
|
186
|
+
*/
|
|
187
|
+
unsubscribeByPattern(pattern) {
|
|
188
|
+
const subscriptionId = this.patternToId.get(pattern);
|
|
189
|
+
if (!subscriptionId) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.transport.unsubscribe(subscriptionId);
|
|
193
|
+
this.subscriptions.delete(subscriptionId);
|
|
194
|
+
this.patternToId.delete(pattern);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Unsubscribe by subscription ID
|
|
198
|
+
*/
|
|
199
|
+
unsubscribeById(subscriptionId) {
|
|
200
|
+
const state = this.subscriptions.get(subscriptionId);
|
|
201
|
+
if (!state) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
this.transport.unsubscribe(subscriptionId);
|
|
205
|
+
this.subscriptions.delete(subscriptionId);
|
|
206
|
+
this.patternToId.delete(state.lookupKey);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create a subscription group for batch management
|
|
210
|
+
*/
|
|
211
|
+
createGroup() {
|
|
212
|
+
const subscriptions = [];
|
|
213
|
+
return {
|
|
214
|
+
add: async (pattern, callbacks) => {
|
|
215
|
+
const sub = await this.subscribe(pattern, callbacks);
|
|
216
|
+
subscriptions.push(sub);
|
|
217
|
+
return sub;
|
|
218
|
+
},
|
|
219
|
+
unsubscribeAll: () => {
|
|
220
|
+
for (const sub of subscriptions) {
|
|
221
|
+
sub.unsubscribe();
|
|
222
|
+
}
|
|
223
|
+
subscriptions.length = 0;
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Add a global connection change callback
|
|
229
|
+
*/
|
|
230
|
+
onConnectionChange(callback) {
|
|
231
|
+
this.connectionChangeCallbacks.add(callback);
|
|
232
|
+
return () => this.connectionChangeCallbacks.delete(callback);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Add a global error callback
|
|
236
|
+
*/
|
|
237
|
+
onError(callback) {
|
|
238
|
+
this.errorCallbacks.add(callback);
|
|
239
|
+
return () => this.errorCallbacks.delete(callback);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Get current connection state
|
|
243
|
+
*/
|
|
244
|
+
get connectionState() {
|
|
245
|
+
return this.transport.connectionState;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Connect to the server
|
|
249
|
+
*/
|
|
250
|
+
async connect() {
|
|
251
|
+
await this.ensureConnected();
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Ensure the transport is connected, sharing a single in-flight connect
|
|
255
|
+
* across concurrent callers. Resolves when `onConnectionChange` reports
|
|
256
|
+
* "connected"; rejects if the transport's connect() throws or the
|
|
257
|
+
* auto-connect timeout elapses.
|
|
258
|
+
*/
|
|
259
|
+
ensureConnected() {
|
|
260
|
+
if (this.transport.connectionState === "connected") {
|
|
261
|
+
return Promise.resolve();
|
|
262
|
+
}
|
|
263
|
+
if (this.connectPromise) {
|
|
264
|
+
return this.connectPromise;
|
|
265
|
+
}
|
|
266
|
+
const promise = new Promise((resolve, reject) => {
|
|
267
|
+
let settled = false;
|
|
268
|
+
let timeoutHandle = setTimeout(() => {
|
|
269
|
+
if (settled)
|
|
270
|
+
return;
|
|
271
|
+
settled = true;
|
|
272
|
+
cleanup();
|
|
273
|
+
reject(new Error(`ironflow: connect timeout after ${this.autoConnectTimeoutMs}ms`));
|
|
274
|
+
}, this.autoConnectTimeoutMs);
|
|
275
|
+
const cleanup = () => {
|
|
276
|
+
if (timeoutHandle) {
|
|
277
|
+
clearTimeout(timeoutHandle);
|
|
278
|
+
timeoutHandle = null;
|
|
279
|
+
}
|
|
280
|
+
unsubscribe();
|
|
281
|
+
};
|
|
282
|
+
const unsubscribe = this.onConnectionChange((state) => {
|
|
283
|
+
if (state === "connected" && !settled) {
|
|
284
|
+
settled = true;
|
|
285
|
+
cleanup();
|
|
286
|
+
resolve();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
// Only start a fresh connect if the transport is idle. If it's already
|
|
290
|
+
// "connecting" or "reconnecting", the onConnectionChange listener above
|
|
291
|
+
// will resolve us when the in-flight connect finishes.
|
|
292
|
+
if (this.transport.connectionState === "disconnected") {
|
|
293
|
+
this.transport.connect().then(() => {
|
|
294
|
+
// Real transports flip state to "connected" before the connect()
|
|
295
|
+
// promise resolves, so the listener has already fired. The resolve
|
|
296
|
+
// here covers transports / test doubles that don't synthesize a
|
|
297
|
+
// connection-state callback but do signal success by resolving.
|
|
298
|
+
if (settled)
|
|
299
|
+
return;
|
|
300
|
+
settled = true;
|
|
301
|
+
cleanup();
|
|
302
|
+
resolve();
|
|
303
|
+
}, (err) => {
|
|
304
|
+
if (settled)
|
|
305
|
+
return;
|
|
306
|
+
settled = true;
|
|
307
|
+
cleanup();
|
|
308
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
// .finally returns a NEW promise; store that one so the === check in
|
|
313
|
+
// the cleanup closure can actually match what's held on the instance.
|
|
314
|
+
// Without this, a rejected connect would stay cached forever and the
|
|
315
|
+
// next ensureConnected() caller would get an instant rejection instead
|
|
316
|
+
// of retrying.
|
|
317
|
+
const wrapped = promise.finally(() => {
|
|
318
|
+
if (this.connectPromise === wrapped) {
|
|
319
|
+
this.connectPromise = null;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
this.connectPromise = wrapped;
|
|
323
|
+
return wrapped;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Disconnect from the server
|
|
327
|
+
*/
|
|
328
|
+
disconnect() {
|
|
329
|
+
this.transport.disconnect();
|
|
330
|
+
this.subscriptions.clear();
|
|
331
|
+
this.patternToId.clear();
|
|
332
|
+
this.pendingPatterns.clear();
|
|
333
|
+
this.patternToPendingKeys.clear();
|
|
334
|
+
this.connectPromise = null;
|
|
335
|
+
if (this.visibilityListener && typeof document !== "undefined") {
|
|
336
|
+
document.removeEventListener("visibilitychange", this.visibilityListener);
|
|
337
|
+
this.visibilityListener = null;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Pause subscriptions (for tab visibility)
|
|
342
|
+
*/
|
|
343
|
+
pause() {
|
|
344
|
+
this.transport.pause();
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Resume subscriptions
|
|
348
|
+
*/
|
|
349
|
+
resume() {
|
|
350
|
+
this.transport.resume();
|
|
351
|
+
}
|
|
352
|
+
handleEvent(subscriptionId, event) {
|
|
353
|
+
const state = this.subscriptions.get(subscriptionId);
|
|
354
|
+
if (!state) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
// Track last event if enabled
|
|
358
|
+
if (state.options?.trackState) {
|
|
359
|
+
state.lastEvent = event;
|
|
360
|
+
}
|
|
361
|
+
state.callbacks.onEvent?.(event);
|
|
362
|
+
}
|
|
363
|
+
handleError(subscriptionId, error) {
|
|
364
|
+
// Call global error handlers
|
|
365
|
+
for (const callback of this.errorCallbacks) {
|
|
366
|
+
callback(error);
|
|
367
|
+
}
|
|
368
|
+
// Call subscription-specific error handler
|
|
369
|
+
if (subscriptionId) {
|
|
370
|
+
const state = this.subscriptions.get(subscriptionId);
|
|
371
|
+
state?.callbacks.onError?.(error);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
handleConnectionChange(state) {
|
|
375
|
+
// Update all subscription states
|
|
376
|
+
for (const sub of this.subscriptions.values()) {
|
|
377
|
+
sub.connectionState = state;
|
|
378
|
+
sub.callbacks.onStateChange?.(state);
|
|
379
|
+
}
|
|
380
|
+
// Call global callbacks
|
|
381
|
+
for (const callback of this.connectionChangeCallbacks) {
|
|
382
|
+
callback(state);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
handleSubscribed(pattern, subscriptionId) {
|
|
386
|
+
// Find pending subscription using pattern-to-keys map for O(1) lookup
|
|
387
|
+
const pendingKeys = this.patternToPendingKeys.get(pattern);
|
|
388
|
+
if (!pendingKeys || pendingKeys.length === 0) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
// Get the first pending key (FIFO order)
|
|
392
|
+
const pendingKey = pendingKeys.shift();
|
|
393
|
+
if (pendingKeys.length === 0) {
|
|
394
|
+
this.patternToPendingKeys.delete(pattern);
|
|
395
|
+
}
|
|
396
|
+
const pending = this.pendingPatterns.get(pendingKey);
|
|
397
|
+
if (!pending) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
this.pendingPatterns.delete(pendingKey);
|
|
401
|
+
// Update state with real subscription ID
|
|
402
|
+
pending.id = subscriptionId;
|
|
403
|
+
this.subscriptions.set(subscriptionId, pending);
|
|
404
|
+
this.patternToId.set(pending.lookupKey, subscriptionId);
|
|
405
|
+
// Create subscription object
|
|
406
|
+
const isManualAck = pending.options?.ackMode === "manual";
|
|
407
|
+
if (isManualAck) {
|
|
408
|
+
const ackableSub = {
|
|
409
|
+
id: subscriptionId,
|
|
410
|
+
pattern,
|
|
411
|
+
connectionState: pending.connectionState,
|
|
412
|
+
lastEvent: pending.lastEvent,
|
|
413
|
+
unsubscribe: () => this.unsubscribeById(subscriptionId),
|
|
414
|
+
ack: (eventId) => this.transport.ack(eventId, "ack"),
|
|
415
|
+
nak: (eventId, delay) => this.transport.ack(eventId, "nak", delay),
|
|
416
|
+
term: (eventId) => this.transport.ack(eventId, "term"),
|
|
417
|
+
};
|
|
418
|
+
pending.resolve?.(ackableSub);
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
const sub = {
|
|
422
|
+
id: subscriptionId,
|
|
423
|
+
pattern,
|
|
424
|
+
connectionState: pending.connectionState,
|
|
425
|
+
lastEvent: pending.lastEvent,
|
|
426
|
+
unsubscribe: () => this.unsubscribeById(subscriptionId),
|
|
427
|
+
};
|
|
428
|
+
pending.resolve?.(sub);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
handleSubscribeFailed(pattern, error) {
|
|
432
|
+
// Find pending subscription using pattern-to-keys map for O(1) lookup
|
|
433
|
+
const pendingKeys = this.patternToPendingKeys.get(pattern);
|
|
434
|
+
if (!pendingKeys || pendingKeys.length === 0) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
// Get the first pending key (FIFO order)
|
|
438
|
+
const pendingKey = pendingKeys.shift();
|
|
439
|
+
if (pendingKeys.length === 0) {
|
|
440
|
+
this.patternToPendingKeys.delete(pattern);
|
|
441
|
+
}
|
|
442
|
+
const pending = this.pendingPatterns.get(pendingKey);
|
|
443
|
+
if (!pending) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
this.pendingPatterns.delete(pendingKey);
|
|
447
|
+
pending.reject?.(error);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../src/subscription.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAwC9D;;;GAGG;AACH,MAAM,+BAA+B,GAAG,MAAM,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,mBAAmB;IACtB,SAAS,CAAY;IAC7B,2DAA2D;IACnD,OAAO,CAAS;IAChB,aAAa,GAAmC,IAAI,GAAG,EAAE,CAAC;IAC1D,WAAW,GAAwB,IAAI,GAAG,EAAE,CAAC;IAC7C,eAAe,GAAmC,IAAI,GAAG,EAAE,CAAC;IACpE,kEAAkE;IAC1D,oBAAoB,GAA0B,IAAI,GAAG,EAAE,CAAC;IACxD,yBAAyB,GAA0C,IAAI,GAAG,EAAE,CAAC;IAC7E,cAAc,GAAgD,IAAI,GAAG,EAAE,CAAC;IAChF,6FAA6F;IACrF,cAAc,GAAyB,IAAI,CAAC;IACpD,kEAAkE;IAC1D,kBAAkB,GAAwB,IAAI,CAAC;IACtC,oBAAoB,CAAS;IAE9C;;;;OAIG;IACH,IAAW,uBAAuB;QAChC,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,YAAY,SAAoB,EAAE,MAAuB;QACvD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,gBAAgB,EAAE,CAAC,CAAC;QACtF,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAC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,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,GAAiB;gBACxB,EAAE,EAAE,cAAc;gBAClB,OAAO;gBACP,eAAe,EAAE,OAAO,CAAC,eAAe;gBACxC,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC;aACxD,CAAC;YACF,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAEO,qBAAqB,CAAC,OAAe,EAAE,KAAY;QACzD,sEAAsE;QACtE,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7C,OAAO;QACT,CAAC;QAED,yCAAyC;QACzC,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,EAAG,CAAC;QACxC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConnectRPC transport implementation for browser
|
|
3
|
+
*
|
|
4
|
+
* Uses @connectrpc/connect-web for browser-compatible gRPC communication.
|
|
5
|
+
*/
|
|
6
|
+
import type { ConnectionState, SubscribeOptions as CoreSubscribeOptions, AckType } from "@ironflow/core";
|
|
7
|
+
import type { Transport, TransportCallbacks, TransportOptions } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Check if a stream error is an explicit user/framework cancellation that
|
|
10
|
+
* should always be suppressed (page unload, React unmount, HMR).
|
|
11
|
+
*/
|
|
12
|
+
export declare function isExplicitCancellation(error: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a stream error is a recoverable network/availability issue that
|
|
15
|
+
* should be suppressed when auto-reconnect is enabled. These errors indicate
|
|
16
|
+
* transient problems the transport can recover from automatically.
|
|
17
|
+
*
|
|
18
|
+
* When auto-reconnect is disabled, these errors are surfaced to onError so
|
|
19
|
+
* users can implement their own recovery strategy.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isTransientNetworkError(error: unknown): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* ConnectRPC-based transport for browser subscriptions
|
|
24
|
+
*
|
|
25
|
+
* Uses server streaming for auto-ack mode subscriptions.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ConnectRPCTransport implements Transport {
|
|
28
|
+
private readonly serverUrl;
|
|
29
|
+
private readonly options;
|
|
30
|
+
private callbacks?;
|
|
31
|
+
private webTransport;
|
|
32
|
+
private client;
|
|
33
|
+
private _connectionState;
|
|
34
|
+
private reconnectAttempt;
|
|
35
|
+
private reconnectTimer;
|
|
36
|
+
private paused;
|
|
37
|
+
private activeSubscriptions;
|
|
38
|
+
private subscriptionIdCounter;
|
|
39
|
+
constructor(serverUrl: string, options: TransportOptions);
|
|
40
|
+
get connectionState(): ConnectionState;
|
|
41
|
+
setCallbacks(callbacks: TransportCallbacks): void;
|
|
42
|
+
connect(): Promise<void>;
|
|
43
|
+
disconnect(): void;
|
|
44
|
+
subscribe(pattern: string, options?: CoreSubscribeOptions): void;
|
|
45
|
+
unsubscribe(subscriptionId: string): void;
|
|
46
|
+
ack(eventId: string, type: AckType, _delay?: number): Promise<void>;
|
|
47
|
+
pause(): void;
|
|
48
|
+
resume(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Start the subscription stream for a given subscription
|
|
51
|
+
*/
|
|
52
|
+
private startSubscriptionStream;
|
|
53
|
+
/**
|
|
54
|
+
* Convert protobuf event to SDK event
|
|
55
|
+
*/
|
|
56
|
+
private convertProtoEvent;
|
|
57
|
+
/**
|
|
58
|
+
* Handle disconnection
|
|
59
|
+
*/
|
|
60
|
+
private handleDisconnect;
|
|
61
|
+
/**
|
|
62
|
+
* Schedule a reconnection attempt
|
|
63
|
+
*/
|
|
64
|
+
private scheduleReconnect;
|
|
65
|
+
/**
|
|
66
|
+
* Clear the reconnect timer
|
|
67
|
+
*/
|
|
68
|
+
private clearReconnectTimer;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a ConnectRPC transport for browser
|
|
72
|
+
*/
|
|
73
|
+
export declare function createConnectRPCTransport(serverUrl: string, options: TransportOptions): Transport;
|
|
74
|
+
//# sourceMappingURL=connectrpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectrpc.d.ts","sourceRoot":"","sources":["../../src/transport/connectrpc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,IAAI,oBAAoB,EACxC,OAAO,EAER,MAAM,gBAAgB,CAAC;AAmBxB,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAwClF;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAc9D;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAmB/D;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,SAAS;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,SAAS,CA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