@pmate/chat-sdk 0.12.0-next.46 → 0.12.0-next.47
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.
|
@@ -90,6 +90,7 @@ export declare class MessageClient<T extends StoredMessage> {
|
|
|
90
90
|
private release;
|
|
91
91
|
private flushWrites;
|
|
92
92
|
private runWrites;
|
|
93
|
+
private assertNetworkAvailable;
|
|
93
94
|
synchronize(thread: string): Promise<void>;
|
|
94
95
|
/** Keep an explicitly requested history range in the shared subscribed view. */
|
|
95
96
|
expandWindow(thread: string, page: MessageSnapshot<T>): Promise<void>;
|
|
@@ -168,7 +168,8 @@ export class MessageClient {
|
|
|
168
168
|
const fallback = await this.fallback(thread, limit);
|
|
169
169
|
if (!fallback.messages.length)
|
|
170
170
|
throw error;
|
|
171
|
-
|
|
171
|
+
if (!isOfflineNetworkFailure(error))
|
|
172
|
+
this.options.onError?.(error, thread);
|
|
172
173
|
return fallback;
|
|
173
174
|
}
|
|
174
175
|
}
|
|
@@ -188,7 +189,8 @@ export class MessageClient {
|
|
|
188
189
|
const cached = await this.fallback(thread, limit);
|
|
189
190
|
if (!cached.messages.length)
|
|
190
191
|
throw error;
|
|
191
|
-
|
|
192
|
+
if (!isOfflineNetworkFailure(error))
|
|
193
|
+
this.options.onError?.(error, thread);
|
|
192
194
|
return cached;
|
|
193
195
|
}
|
|
194
196
|
const snapshot = await this.reload(thread);
|
|
@@ -433,6 +435,12 @@ export class MessageClient {
|
|
|
433
435
|
this.release(queue);
|
|
434
436
|
}
|
|
435
437
|
}
|
|
438
|
+
assertNetworkAvailable(thread) {
|
|
439
|
+
if (this.closed || this.closing || this.scopeDenied || this.revoked.has(thread))
|
|
440
|
+
throw new Error("MESSAGE_CLIENT_UNAVAILABLE");
|
|
441
|
+
if (isOffline())
|
|
442
|
+
throw new TypeError("MESSAGE_OFFLINE_UNAVAILABLE");
|
|
443
|
+
}
|
|
436
444
|
synchronize(thread) {
|
|
437
445
|
if (this.closed || this.closing || this.scopeDenied || this.revoked.has(thread))
|
|
438
446
|
return Promise.reject(new Error("MESSAGE_CLIENT_UNAVAILABLE"));
|
|
@@ -449,6 +457,7 @@ export class MessageClient {
|
|
|
449
457
|
}
|
|
450
458
|
let version = coverage?.resetVersion ?? 0;
|
|
451
459
|
let after = coverage?.complete ? coverage.checkpoint : undefined;
|
|
460
|
+
this.assertNetworkAvailable(thread);
|
|
452
461
|
let page = after && this.options.transport.changes
|
|
453
462
|
? await this.options.transport.changes(thread, after, this.abort.signal)
|
|
454
463
|
: await this.options.transport.load(thread, this.abort.signal);
|
|
@@ -457,6 +466,7 @@ export class MessageClient {
|
|
|
457
466
|
throw new Error("MESSAGE_CLIENT_UNAVAILABLE");
|
|
458
467
|
version = await this.storage.resetThread(thread, false, scopeVersion);
|
|
459
468
|
after = undefined;
|
|
469
|
+
this.assertNetworkAvailable(thread);
|
|
460
470
|
page = await this.options.transport.load(thread, this.abort.signal);
|
|
461
471
|
}
|
|
462
472
|
for (;;) {
|
|
@@ -470,6 +480,7 @@ export class MessageClient {
|
|
|
470
480
|
if (!page.checkpoint || page.checkpoint === after || !this.options.transport.changes)
|
|
471
481
|
throw new Error("MESSAGE_SYNC_NO_PROGRESS");
|
|
472
482
|
after = page.checkpoint;
|
|
483
|
+
this.assertNetworkAvailable(thread);
|
|
473
484
|
page = await this.options.transport.changes(thread, after, this.abort.signal);
|
|
474
485
|
}
|
|
475
486
|
})().catch(async (error) => {
|
|
@@ -530,7 +541,8 @@ export class MessageClient {
|
|
|
530
541
|
const fallback = await this.fallback(thread, limit, before);
|
|
531
542
|
if (!fallback.messages.length)
|
|
532
543
|
throw error;
|
|
533
|
-
|
|
544
|
+
if (!isOfflineNetworkFailure(error))
|
|
545
|
+
this.options.onError?.(error, thread);
|
|
534
546
|
return fallback;
|
|
535
547
|
}
|
|
536
548
|
}
|
|
@@ -546,6 +558,7 @@ export class MessageClient {
|
|
|
546
558
|
}
|
|
547
559
|
const token = page.coverage.nextBefore, version = page.coverage.resetVersion ?? 0, scopeVersion = page.coverage.scopeVersion ?? 0;
|
|
548
560
|
const task = (async () => {
|
|
561
|
+
this.assertNetworkAvailable(thread);
|
|
549
562
|
const remote = await this.options.transport.older(thread, token, this.abort.signal);
|
|
550
563
|
if (this.closed || this.scopeDenied || this.revoked.has(thread))
|
|
551
564
|
throw new Error("MESSAGE_CLIENT_UNAVAILABLE");
|
package/package.json
CHANGED