@pmate/chat-sdk 0.12.0-next.95 → 0.12.0-next.96
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.
|
@@ -16,7 +16,8 @@ export type InboxClientOptions = InboxScope & {
|
|
|
16
16
|
onError?: (error: unknown) => void;
|
|
17
17
|
onProgress?: (progress: InboxProgress) => void;
|
|
18
18
|
onChange?: (threads: readonly string[]) => void;
|
|
19
|
-
live?: boolean;
|
|
19
|
+
live?: boolean; /** Consume shared committed storage without owning network synchronization. */
|
|
20
|
+
replica?: boolean;
|
|
20
21
|
};
|
|
21
22
|
/** Push full facts normally; range catch-up repairs gaps and silent push loss.
|
|
22
23
|
* One persisted lease owns live/check traffic across tabs and team sessions. */
|
|
@@ -64,6 +65,7 @@ export declare class InboxClient {
|
|
|
64
65
|
readyForDisplay(): boolean;
|
|
65
66
|
offlineMode(): boolean;
|
|
66
67
|
allowOffline(): Promise<void>;
|
|
68
|
+
private restoreReplica;
|
|
67
69
|
private initialize;
|
|
68
70
|
synchronize(): Promise<void>;
|
|
69
71
|
private catchUp;
|
|
@@ -37,8 +37,11 @@ export class InboxClient {
|
|
|
37
37
|
if (typeof BroadcastChannel !== "undefined" && typeof window !== "undefined") {
|
|
38
38
|
this.channel = new BroadcastChannel(`pmate-inbox:${this.store.owner}`);
|
|
39
39
|
this.channel.onmessage = event => {
|
|
40
|
-
if (Array.isArray(event.data?.threads))
|
|
40
|
+
if (Array.isArray(event.data?.threads)) {
|
|
41
|
+
if (this.options.replica)
|
|
42
|
+
void this.restoreReplica().catch(error => this.failed(error));
|
|
41
43
|
this.notify(event.data.threads, false);
|
|
44
|
+
}
|
|
42
45
|
if (Array.isArray(event.data?.events)) {
|
|
43
46
|
const events = event.data.events;
|
|
44
47
|
void this.queueReceipts(() => {
|
|
@@ -129,7 +132,20 @@ export class InboxClient {
|
|
|
129
132
|
this.enterOffline();
|
|
130
133
|
this.publish({ ...this.progress, stage: "offline", percent: 100 });
|
|
131
134
|
}
|
|
135
|
+
async restoreReplica() {
|
|
136
|
+
const cursor = await this.store.cursor();
|
|
137
|
+
if (!cursor?.initialized)
|
|
138
|
+
return;
|
|
139
|
+
if (!this.receiptsHydrated)
|
|
140
|
+
await this.hydrateReceipts();
|
|
141
|
+
this.initializedOnce = true;
|
|
142
|
+
this.publish({ stage: "ready", percent: 100, processed: "0", total: "0" });
|
|
143
|
+
}
|
|
132
144
|
async initialize() {
|
|
145
|
+
if (this.options.replica) {
|
|
146
|
+
await this.restoreReplica();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
133
149
|
if (this.options.live === false) {
|
|
134
150
|
if (!this.offlineAllowed)
|
|
135
151
|
await this.synchronize();
|
|
@@ -161,6 +177,8 @@ export class InboxClient {
|
|
|
161
177
|
synchronize() {
|
|
162
178
|
if (this.closed)
|
|
163
179
|
return Promise.reject(new Error("INBOX_CLIENT_CLOSED"));
|
|
180
|
+
if (this.options.replica)
|
|
181
|
+
return this.restoreReplica();
|
|
164
182
|
return this.running ??= this.catchUp().catch(error => { this.failed(error); throw error; }).finally(() => { this.running = undefined; });
|
|
165
183
|
}
|
|
166
184
|
async catchUp() {
|
package/package.json
CHANGED