@pmate/chat-sdk 0.12.0-next.90 → 0.12.0-next.91
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.
|
@@ -115,10 +115,10 @@ export class InboxClient {
|
|
|
115
115
|
initial = await this.request("check", { afterSeq: cursor.seq, epoch: cursor.epoch });
|
|
116
116
|
if (!cursor || initial?.resetRequired) {
|
|
117
117
|
const bootstrap = await this.request("bootstrap");
|
|
118
|
-
cursor = await this.store.bootstrap(bootstrap);
|
|
118
|
+
cursor = await this.store.bootstrap(bootstrap, cursor ?? null);
|
|
119
119
|
this.notify([]);
|
|
120
120
|
initial = undefined;
|
|
121
|
-
const target = inboxSequence(bootstrap.headSeq)
|
|
121
|
+
const start = inboxSequence(cursor.seq), target = inboxSequence(bootstrap.headSeq) > start ? inboxSequence(bootstrap.headSeq) : start;
|
|
122
122
|
this.publish({ stage: "syncing", percent: 0, processed: "0", total: (target - start).toString() });
|
|
123
123
|
do {
|
|
124
124
|
const page = await this.request("events", { afterSeq: cursor.seq, throughSeq: target.toString(), epoch: cursor.epoch });
|
|
@@ -117,7 +117,7 @@ export declare class IndexedDbInbox {
|
|
|
117
117
|
claimLease(token: string, now?: number): import("dexie").PromiseExtended<boolean>;
|
|
118
118
|
releaseLease(token: string): import("dexie").PromiseExtended<void>;
|
|
119
119
|
private identity;
|
|
120
|
-
bootstrap(input: InboxBootstrap): Promise<InboxCursor>;
|
|
120
|
+
bootstrap(input: InboxBootstrap, expected?: InboxCursor | null): Promise<InboxCursor>;
|
|
121
121
|
apply(page: InboxPage): Promise<{
|
|
122
122
|
cursor: {
|
|
123
123
|
seq: string;
|
|
@@ -54,12 +54,20 @@ export class IndexedDbInbox {
|
|
|
54
54
|
await this.leases.delete(this.owner); }); }
|
|
55
55
|
identity(data) { if (data.appId !== this.scope.appId || data.profileId !== this.scope.profileId)
|
|
56
56
|
throw new Error("INBOX_IDENTITY_MISMATCH"); }
|
|
57
|
-
async bootstrap(input) {
|
|
57
|
+
async bootstrap(input, expected) {
|
|
58
58
|
this.identity(input);
|
|
59
59
|
const start = inboxSequence(input.startSeq), head = inboxSequence(input.headSeq);
|
|
60
60
|
if (!input.epoch || start < 1n || start > head + 1n || !Number.isSafeInteger(input.windowStart) || !Array.isArray(input.basis))
|
|
61
61
|
throw new Error("INVALID_INBOX_BOOTSTRAP");
|
|
62
62
|
return this.db.transaction("rw", this.tables(), async () => {
|
|
63
|
+
const current = await this.cursor();
|
|
64
|
+
// A slower tab must never erase facts another tab committed while this
|
|
65
|
+
// bootstrap request was in flight. The caller catches up from that cursor.
|
|
66
|
+
if (expected !== undefined && JSON.stringify(current ?? null) !== JSON.stringify(expected)) {
|
|
67
|
+
if (current)
|
|
68
|
+
return current;
|
|
69
|
+
throw new Error("INBOX_BOOTSTRAP_CHANGED");
|
|
70
|
+
}
|
|
63
71
|
// A reset rebuilds current state, while older message cache stays available.
|
|
64
72
|
const old = await this.messages.where("owner").equals(this.owner).toArray();
|
|
65
73
|
await this.messages.bulkDelete(old.filter(row => row.acceptedAt >= input.windowStart).map(row => [row.owner, row.thread, row.id]));
|
package/package.json
CHANGED