@tallyui/database 3.0.0-next.1 → 3.0.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/dist/index.d.ts +7 -0
- package/dist/index.js +18 -5
- package/package.json +2 -2
- package/src/catalogue-reconcile.ts +20 -3
- package/src/fingerprint-reconcile.ts +9 -3
package/dist/index.d.ts
CHANGED
|
@@ -289,6 +289,13 @@ type CatalogueReconcileEvent = {
|
|
|
289
289
|
type: 'tombstoned';
|
|
290
290
|
count: number;
|
|
291
291
|
keys: string[];
|
|
292
|
+
}
|
|
293
|
+
/** Local copies sharing a listed match key with another: deletion candidates, sent to confirmGone (#369). */
|
|
294
|
+
| {
|
|
295
|
+
type: 'duplicate';
|
|
296
|
+
count: number;
|
|
297
|
+
keys: string[];
|
|
298
|
+
code: 'duplicate_match_key';
|
|
292
299
|
} | {
|
|
293
300
|
type: 'kept';
|
|
294
301
|
count: number;
|
package/dist/index.js
CHANGED
|
@@ -709,7 +709,9 @@ function startCatalogueRunner({
|
|
|
709
709
|
else await collection.upsertLocal(stateId, JSON.parse(JSON.stringify(value)));
|
|
710
710
|
};
|
|
711
711
|
load().then(({ lastCompleteAt }) => {
|
|
712
|
-
if (lastCompleteAt !== void 0
|
|
712
|
+
if (lastCompleteAt !== void 0 && (state.value.lastCompleteAt === void 0 || state.value.lastCompleteAt < lastCompleteAt)) {
|
|
713
|
+
update({ lastCompleteAt });
|
|
714
|
+
}
|
|
713
715
|
}).catch(() => {
|
|
714
716
|
});
|
|
715
717
|
const sleep2 = (ms) => new Promise((resolve) => {
|
|
@@ -816,6 +818,7 @@ function startCatalogueRunner({
|
|
|
816
818
|
if (!current.uninterrupted) log({ type: "kept", count: 0, keys: [], reason: "resumed-pass" });
|
|
817
819
|
else {
|
|
818
820
|
const candidates = [];
|
|
821
|
+
const duplicates = [];
|
|
819
822
|
let localCount = 0;
|
|
820
823
|
for await (const chunk of readFreshInChunks(collection)) {
|
|
821
824
|
checkAborted();
|
|
@@ -823,9 +826,15 @@ function startCatalogueRunner({
|
|
|
823
826
|
for (const doc of chunk) {
|
|
824
827
|
const key = adapter.matchKey ? adapter.matchKey(doc) : keyOf(doc);
|
|
825
828
|
if (key === void 0 || !seen.has(key)) candidates.push(doc);
|
|
829
|
+
else if (adapter.matchKey && index?.has(key) && index.get(key) !== keyOf(doc)) duplicates.push(doc);
|
|
826
830
|
}
|
|
827
831
|
}
|
|
828
832
|
unlisted = candidates.length;
|
|
833
|
+
candidates.push(...duplicates);
|
|
834
|
+
if (duplicates.length) {
|
|
835
|
+
log({ type: "duplicate", ...listed(duplicates.map(keyOf)), code: "duplicate_match_key" });
|
|
836
|
+
console.warn("Catalogue reconcile: duplicate_match_key", duplicates.length);
|
|
837
|
+
}
|
|
829
838
|
let gone = [];
|
|
830
839
|
if (!candidates.length || keepCandidates) {
|
|
831
840
|
} else if (braked(candidates.length, localCount)) {
|
|
@@ -854,8 +863,9 @@ function startCatalogueRunner({
|
|
|
854
863
|
}
|
|
855
864
|
checkAborted();
|
|
856
865
|
const lastCompletedAt = now();
|
|
857
|
-
|
|
858
|
-
|
|
866
|
+
const counted = pages > 0;
|
|
867
|
+
await save(counted ? { lastCompletedAt, lastCompleteAt: current.uninterrupted ? lastCompletedAt : saved.lastCompleteAt } : { lastCompletedAt: saved.lastCompletedAt, lastCompleteAt: saved.lastCompleteAt });
|
|
868
|
+
const summary = { pages, compared, refetched, tombstoned, kept, unlisted, complete: counted && current.uninterrupted, durationMs: lastCompletedAt - startedAt };
|
|
859
869
|
log({ type: "pass-completed", ...summary });
|
|
860
870
|
return summary;
|
|
861
871
|
};
|
|
@@ -996,13 +1006,16 @@ function startFingerprintReconcile({
|
|
|
996
1006
|
const state = new BehaviorSubject6({ running: false });
|
|
997
1007
|
let summary;
|
|
998
1008
|
let result;
|
|
1009
|
+
let lastCompleteAt;
|
|
999
1010
|
catalogue$.subscribe({
|
|
1000
|
-
next: ({ lastResult, ...rest }) => {
|
|
1011
|
+
next: ({ lastResult, lastCompleteAt: completedAt, ...rest }) => {
|
|
1012
|
+
if (!summary && !lastResult) lastCompleteAt = completedAt;
|
|
1001
1013
|
if (lastResult !== summary) {
|
|
1002
1014
|
summary = lastResult;
|
|
1003
1015
|
result = lastResult && toResult(lastResult);
|
|
1016
|
+
if (result?.complete) lastCompleteAt = completedAt;
|
|
1004
1017
|
}
|
|
1005
|
-
state.next(
|
|
1018
|
+
state.next({ ...rest, ...lastCompleteAt !== void 0 && { lastCompleteAt }, ...result && { lastResult: result } });
|
|
1006
1019
|
},
|
|
1007
1020
|
complete: () => state.complete()
|
|
1008
1021
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/database",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "RxDB database factory for Tally UI — accepts pluggable connector schemas",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"rxjs": "7.8.2"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tallyui/core": "^3.0.0
|
|
32
|
+
"@tallyui/core": "^3.0.0"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsup",
|
|
@@ -31,6 +31,8 @@ export type CatalogueReconcileEvent =
|
|
|
31
31
|
| { type: 'pass-started'; resumed: boolean }
|
|
32
32
|
| { type: 'refetched'; count: number; keys: string[] }
|
|
33
33
|
| { type: 'tombstoned'; count: number; keys: string[] }
|
|
34
|
+
/** Local copies sharing a listed match key with another: deletion candidates, sent to confirmGone (#369). */
|
|
35
|
+
| { type: 'duplicate'; count: number; keys: string[]; code: 'duplicate_match_key' }
|
|
34
36
|
| { type: 'kept'; count: number; keys: string[]; reason: 'unconfirmed' | 'resumed-pass' }
|
|
35
37
|
/** `message` tells the store owner, in plain words and without naming a backend, what was kept and why. */
|
|
36
38
|
| { type: 'kept'; count: number; keys: string[]; reason: 'brake'; message: string }
|
|
@@ -175,7 +177,11 @@ export function startCatalogueRunner<Doc, Cursor = unknown>({
|
|
|
175
177
|
if (memory) memory = value;
|
|
176
178
|
else await collection.upsertLocal(stateId, JSON.parse(JSON.stringify(value)));
|
|
177
179
|
};
|
|
178
|
-
load().then(({ lastCompleteAt }) => {
|
|
180
|
+
load().then(({ lastCompleteAt }) => {
|
|
181
|
+
if (lastCompleteAt !== undefined && (state.value.lastCompleteAt === undefined || state.value.lastCompleteAt < lastCompleteAt)) {
|
|
182
|
+
update({ lastCompleteAt });
|
|
183
|
+
}
|
|
184
|
+
}).catch(() => {});
|
|
179
185
|
|
|
180
186
|
const sleep = (ms: number) => new Promise<void>((resolve) => {
|
|
181
187
|
const onAbort = () => { cancel(); resolve(); };
|
|
@@ -288,6 +294,7 @@ export function startCatalogueRunner<Doc, Cursor = unknown>({
|
|
|
288
294
|
else {
|
|
289
295
|
// Local documents the listing never named are candidates; only confirmed ones may go.
|
|
290
296
|
const candidates: Doc[] = [];
|
|
297
|
+
const duplicates: Doc[] = [];
|
|
291
298
|
let localCount = 0;
|
|
292
299
|
for await (const chunk of readFreshInChunks(collection)) {
|
|
293
300
|
checkAborted();
|
|
@@ -295,9 +302,15 @@ export function startCatalogueRunner<Doc, Cursor = unknown>({
|
|
|
295
302
|
for (const doc of chunk) {
|
|
296
303
|
const key = adapter.matchKey ? adapter.matchKey(doc) : keyOf(doc);
|
|
297
304
|
if (key === undefined || !seen.has(key)) candidates.push(doc);
|
|
305
|
+
else if (adapter.matchKey && index?.has(key) && index.get(key) !== keyOf(doc)) duplicates.push(doc);
|
|
298
306
|
}
|
|
299
307
|
}
|
|
300
308
|
unlisted = candidates.length;
|
|
309
|
+
candidates.push(...duplicates);
|
|
310
|
+
if (duplicates.length) {
|
|
311
|
+
log({ type: 'duplicate', ...listed(duplicates.map(keyOf)), code: 'duplicate_match_key' });
|
|
312
|
+
console.warn('Catalogue reconcile: duplicate_match_key', duplicates.length);
|
|
313
|
+
}
|
|
301
314
|
// The brake applies to the candidates, before confirmGone: a broken listing never sends
|
|
302
315
|
// thousands of confirmation requests, and whatever confirmGone confirms stays under it.
|
|
303
316
|
let gone: Doc[] = [];
|
|
@@ -335,8 +348,12 @@ export function startCatalogueRunner<Doc, Cursor = unknown>({
|
|
|
335
348
|
|
|
336
349
|
checkAborted();
|
|
337
350
|
const lastCompletedAt = now();
|
|
338
|
-
|
|
339
|
-
const
|
|
351
|
+
// A pass that yielded no page listed nothing: it is neither complete nor a completed pass, so the gate runs it again at the next check (#368).
|
|
352
|
+
const counted = pages > 0;
|
|
353
|
+
await save(counted
|
|
354
|
+
? { lastCompletedAt, lastCompleteAt: current.uninterrupted ? lastCompletedAt : saved.lastCompleteAt }
|
|
355
|
+
: { lastCompletedAt: saved.lastCompletedAt, lastCompleteAt: saved.lastCompleteAt });
|
|
356
|
+
const summary = { pages, compared, refetched, tombstoned, kept, unlisted, complete: counted && current.uninterrupted, durationMs: lastCompletedAt - startedAt };
|
|
340
357
|
log({ type: 'pass-completed', ...summary });
|
|
341
358
|
return summary;
|
|
342
359
|
};
|
|
@@ -139,10 +139,16 @@ export function startFingerprintReconcile<Doc>({
|
|
|
139
139
|
const state = new BehaviorSubject<FingerprintReconcileState>({ running: false });
|
|
140
140
|
let summary: CatalogueReconcileSummary | undefined;
|
|
141
141
|
let result: FingerprintReconcileResult | undefined;
|
|
142
|
+
let lastCompleteAt: number | undefined;
|
|
142
143
|
catalogue$.subscribe({
|
|
143
|
-
next: ({ lastResult, ...rest }) => {
|
|
144
|
-
if (
|
|
145
|
-
|
|
144
|
+
next: ({ lastResult, lastCompleteAt: completedAt, ...rest }) => {
|
|
145
|
+
if (!summary && !lastResult) lastCompleteAt = completedAt;
|
|
146
|
+
if (lastResult !== summary) {
|
|
147
|
+
summary = lastResult;
|
|
148
|
+
result = lastResult && toResult(lastResult);
|
|
149
|
+
if (result?.complete) lastCompleteAt = completedAt;
|
|
150
|
+
}
|
|
151
|
+
state.next({ ...rest, ...(lastCompleteAt !== undefined && { lastCompleteAt }), ...(result && { lastResult: result }) });
|
|
146
152
|
},
|
|
147
153
|
complete: () => state.complete(),
|
|
148
154
|
});
|