@calimero-network/mero-js 25.3.2 → 25.3.3
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/dist/events/sse.d.ts +8 -0
- package/dist/events/sse.js +19 -8
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +19 -8
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +19 -8
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3328,7 +3328,8 @@ var SseClient = class {
|
|
|
3328
3328
|
return;
|
|
3329
3329
|
}
|
|
3330
3330
|
this.closed = false;
|
|
3331
|
-
|
|
3331
|
+
const controller = new AbortController();
|
|
3332
|
+
this.abortController = controller;
|
|
3332
3333
|
try {
|
|
3333
3334
|
const url2 = `${this.baseUrl}/sse`;
|
|
3334
3335
|
const headers = {
|
|
@@ -3338,7 +3339,7 @@ var SseClient = class {
|
|
|
3338
3339
|
const proofAttached = carriesProof(headers);
|
|
3339
3340
|
const response = await this.fetchImpl(url2, {
|
|
3340
3341
|
headers,
|
|
3341
|
-
signal:
|
|
3342
|
+
signal: controller.signal,
|
|
3342
3343
|
...proofAttached && { redirect: "manual" }
|
|
3343
3344
|
});
|
|
3344
3345
|
if (proofAttached) refuseProofRedirect(response, url2);
|
|
@@ -3366,21 +3367,31 @@ var SseClient = class {
|
|
|
3366
3367
|
if (!response.body) {
|
|
3367
3368
|
throw new Error("SSE response has no body");
|
|
3368
3369
|
}
|
|
3369
|
-
this.readStream(response.body).catch((err) => {
|
|
3370
|
-
if (this.
|
|
3370
|
+
this.readStream(response.body, controller).catch((err) => {
|
|
3371
|
+
if (this.superseded(controller)) return;
|
|
3371
3372
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
3372
3373
|
this.emit("error", error);
|
|
3373
3374
|
this.scheduleReconnect();
|
|
3374
3375
|
});
|
|
3375
3376
|
} catch (err) {
|
|
3376
|
-
if (this.
|
|
3377
|
+
if (this.superseded(controller)) return;
|
|
3377
3378
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
3378
3379
|
this.emit("error", error);
|
|
3379
3380
|
if (error instanceof AuthRevokedError) return;
|
|
3380
3381
|
this.scheduleReconnect();
|
|
3381
3382
|
}
|
|
3382
3383
|
}
|
|
3383
|
-
|
|
3384
|
+
/**
|
|
3385
|
+
* Whether `controller`'s connection is no longer the one this client holds:
|
|
3386
|
+
* closed, or replaced by a later connect. Its abort lands asynchronously,
|
|
3387
|
+
* after a `close()` + `connect()` has already cleared `closed`, so `closed`
|
|
3388
|
+
* alone cannot tell; reporting it, and reconnecting for it, would abort the
|
|
3389
|
+
* live connection, whose own abort would do the same, without end.
|
|
3390
|
+
*/
|
|
3391
|
+
superseded(controller) {
|
|
3392
|
+
return this.closed || controller.signal.aborted || this.abortController !== controller;
|
|
3393
|
+
}
|
|
3394
|
+
async readStream(body, controller) {
|
|
3384
3395
|
const reader = body.getReader();
|
|
3385
3396
|
const decoder = new TextDecoder();
|
|
3386
3397
|
let buffer = "";
|
|
@@ -3408,11 +3419,11 @@ var SseClient = class {
|
|
|
3408
3419
|
}
|
|
3409
3420
|
}
|
|
3410
3421
|
} catch (err) {
|
|
3411
|
-
if (this.
|
|
3422
|
+
if (this.superseded(controller)) return;
|
|
3412
3423
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
3413
3424
|
this.emit("error", error);
|
|
3414
3425
|
}
|
|
3415
|
-
if (!this.
|
|
3426
|
+
if (!this.superseded(controller)) {
|
|
3416
3427
|
this.scheduleReconnect();
|
|
3417
3428
|
}
|
|
3418
3429
|
}
|