cry-synced-db-client 0.1.199 → 0.1.200
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/CHANGELOG.md +24 -0
- package/dist/index.js +169 -57
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
+
## 0.1.200 (2026-06-14)
|
|
4
|
+
|
|
5
|
+
### `preprocessDirtyItem` skip/throw zdaj incrementa `numUploadAttempts`
|
|
6
|
+
|
|
7
|
+
`SyncEngine.uploadDirtyItems`: ko `preprocessDirtyItem` vrne `undefined` ali vrže
|
|
8
|
+
exception, se item ne samo preskoči — zdaj dobi tudi `incrementDirtyUploadAttempts`,
|
|
9
|
+
tako da po 2+ skipih postane stuck in viden prek `getStuckItems()` / `onDirtyItemStuck`.
|
|
10
|
+
|
|
11
|
+
Prej so skipani itemi tiho ostali v `_dirty_changes` brez metapodatkov in nikoli ne
|
|
12
|
+
bi postali stuck — zdaj se po 3 skipih (vsak sync da 2 incrementa = main + followUp)
|
|
13
|
+
dobijo `stuckSince`.
|
|
14
|
+
|
|
15
|
+
**Internal:**
|
|
16
|
+
- V `uploadDirtyItems` zbira `preprocessSkippedIds` v obeh poteh, batch-write v
|
|
17
|
+
`incrementDirtyUploadAttempts` takoj za `for` zanko (en DB write za vse skipane
|
|
18
|
+
iteme namesto N write-ov)
|
|
19
|
+
|
|
20
|
+
**Tests:** 5 novih testov v `test/preprocessDirtyItem.test.ts`:
|
|
21
|
+
- `undefined/throw: numUploadAttempts increments across sync cycles, eventually stuck`
|
|
22
|
+
- `undefined/throw: onDirtyItemStuck fires when item becomes stuck`
|
|
23
|
+
- `mixed: stuck item via getStuckItems while non-stuck dirty still active`
|
|
24
|
+
|
|
25
|
+
876 pass, 0 fail.
|
|
26
|
+
|
|
3
27
|
## 0.1.198 (2026-06-13)
|
|
4
28
|
|
|
5
29
|
### Stuck-item tracking (`getStuckItems` / `discardStuckItems` / `onDirtyItemStuck`)
|
package/dist/index.js
CHANGED
|
@@ -3245,7 +3245,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3245
3245
|
configMap.set(collectionName, config);
|
|
3246
3246
|
}
|
|
3247
3247
|
this.callOnFindNewerManyCall(syncSpecs, calledFrom);
|
|
3248
|
-
this.callbackSafe(this.callbacks.onServerSyncStart, {
|
|
3248
|
+
this.callbackSafe(this.callbacks.onServerSyncStart, {
|
|
3249
|
+
calledFrom,
|
|
3250
|
+
collectionCount: syncSpecs.length
|
|
3251
|
+
});
|
|
3249
3252
|
const findNewerManyStartTime = Date.now();
|
|
3250
3253
|
const collectionState = /* @__PURE__ */ new Map();
|
|
3251
3254
|
for (const [name] of configMap) {
|
|
@@ -3276,7 +3279,12 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3276
3279
|
if (!config) return;
|
|
3277
3280
|
const state = collectionState.get(collection);
|
|
3278
3281
|
state.receivedCount += items.length;
|
|
3279
|
-
const stats = await this.processIncomingServerData(
|
|
3282
|
+
const stats = await this.processIncomingServerData(
|
|
3283
|
+
collection,
|
|
3284
|
+
config,
|
|
3285
|
+
items,
|
|
3286
|
+
state.source
|
|
3287
|
+
);
|
|
3280
3288
|
state.conflicts += stats.conflictsResolved;
|
|
3281
3289
|
if (stats.maxTs) {
|
|
3282
3290
|
if (!state.maxTs || this.compareTimestamps(stats.maxTs, state.maxTs) > 0) {
|
|
@@ -3358,12 +3366,16 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3358
3366
|
try {
|
|
3359
3367
|
uploadStats = await this.uploadDirtyItems(calledFrom);
|
|
3360
3368
|
await this.deps.flushAllPendingChanges();
|
|
3361
|
-
const followUp = await this.uploadDirtyItems(
|
|
3369
|
+
const followUp = await this.uploadDirtyItems(
|
|
3370
|
+
`${calledFrom != null ? calledFrom : "sync"}:followUp`
|
|
3371
|
+
);
|
|
3362
3372
|
if (followUp.sentCount > 0) {
|
|
3363
3373
|
uploadStats.sentCount += followUp.sentCount;
|
|
3364
3374
|
if (followUp.collectionSentCounts) {
|
|
3365
3375
|
uploadStats.collectionSentCounts = uploadStats.collectionSentCounts || {};
|
|
3366
|
-
for (const [c, n] of Object.entries(
|
|
3376
|
+
for (const [c, n] of Object.entries(
|
|
3377
|
+
followUp.collectionSentCounts
|
|
3378
|
+
)) {
|
|
3367
3379
|
uploadStats.collectionSentCounts[c] = (uploadStats.collectionSentCounts[c] || 0) + n;
|
|
3368
3380
|
}
|
|
3369
3381
|
}
|
|
@@ -3375,7 +3387,9 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3375
3387
|
);
|
|
3376
3388
|
}
|
|
3377
3389
|
sentCount = uploadStats.sentCount;
|
|
3378
|
-
for (const [collectionName, stats] of Object.entries(
|
|
3390
|
+
for (const [collectionName, stats] of Object.entries(
|
|
3391
|
+
uploadStats.collectionSentCounts || {}
|
|
3392
|
+
)) {
|
|
3379
3393
|
if (collectionStats[collectionName]) {
|
|
3380
3394
|
collectionStats[collectionName].sentCount = stats;
|
|
3381
3395
|
} else {
|
|
@@ -3473,15 +3487,20 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3473
3487
|
});
|
|
3474
3488
|
}
|
|
3475
3489
|
}
|
|
3476
|
-
if (dexieSave.length > 0)
|
|
3490
|
+
if (dexieSave.length > 0)
|
|
3491
|
+
await this.dexieDb.saveMany(collection, dexieSave);
|
|
3477
3492
|
if (dexieDeleteIds.length > 0) {
|
|
3478
3493
|
await this.dexieDb.deleteMany(collection, dexieDeleteIds);
|
|
3479
3494
|
}
|
|
3480
3495
|
if (memUpsert.length > 0) {
|
|
3481
|
-
this.deps.writeToInMemBatch(collection, memUpsert, "upsert", {
|
|
3496
|
+
this.deps.writeToInMemBatch(collection, memUpsert, "upsert", {
|
|
3497
|
+
source: "incremental"
|
|
3498
|
+
});
|
|
3482
3499
|
}
|
|
3483
3500
|
if (memDelete.length > 0) {
|
|
3484
|
-
this.deps.writeToInMemBatch(collection, memDelete, "delete", {
|
|
3501
|
+
this.deps.writeToInMemBatch(collection, memDelete, "delete", {
|
|
3502
|
+
source: "incremental"
|
|
3503
|
+
});
|
|
3485
3504
|
}
|
|
3486
3505
|
if (reAddDirty.length > 0) {
|
|
3487
3506
|
await this.dexieDb.addDirtyChangesBatch(collection, reAddDirty);
|
|
@@ -3520,7 +3539,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3520
3539
|
const updates = [];
|
|
3521
3540
|
const skipped = [];
|
|
3522
3541
|
const ids = dirtyChanges.map((dc) => dc._id);
|
|
3523
|
-
const fullItems = await this.dexieDb.getByIds(
|
|
3542
|
+
const fullItems = await this.dexieDb.getByIds(
|
|
3543
|
+
collectionName,
|
|
3544
|
+
ids
|
|
3545
|
+
);
|
|
3524
3546
|
const orphanReconstructed = [];
|
|
3525
3547
|
for (let i = 0; i < fullItems.length; i++) {
|
|
3526
3548
|
const fullItem = fullItems[i];
|
|
@@ -3531,7 +3553,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3531
3553
|
const currentServerRev = typeof fullItem._rev === "number" ? fullItem._rev : void 0;
|
|
3532
3554
|
updates.push({ _id: fullItem._id, delta, currentServerRev });
|
|
3533
3555
|
} else {
|
|
3534
|
-
skipped.push({
|
|
3556
|
+
skipped.push({
|
|
3557
|
+
_id: String(fullItem._id),
|
|
3558
|
+
reason: "no-delta-for-fullitem"
|
|
3559
|
+
});
|
|
3535
3560
|
}
|
|
3536
3561
|
} else if (id != null) {
|
|
3537
3562
|
const delta = dirtyChangesMap.get(String(id));
|
|
@@ -3568,7 +3593,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3568
3593
|
timestamp: /* @__PURE__ */ new Date()
|
|
3569
3594
|
});
|
|
3570
3595
|
} catch (err) {
|
|
3571
|
-
console.error(
|
|
3596
|
+
console.error(
|
|
3597
|
+
`[SyncEngine] onUploadSkip callback failed: ${err}`,
|
|
3598
|
+
err
|
|
3599
|
+
);
|
|
3572
3600
|
}
|
|
3573
3601
|
}
|
|
3574
3602
|
continue;
|
|
@@ -3585,10 +3613,14 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3585
3613
|
timestamp: /* @__PURE__ */ new Date()
|
|
3586
3614
|
});
|
|
3587
3615
|
} catch (err) {
|
|
3588
|
-
console.error(
|
|
3616
|
+
console.error(
|
|
3617
|
+
`[SyncEngine] onUploadSkip callback failed: ${err}`,
|
|
3618
|
+
err
|
|
3619
|
+
);
|
|
3589
3620
|
}
|
|
3590
3621
|
}
|
|
3591
3622
|
const mappedUpdates = [];
|
|
3623
|
+
const preprocessSkippedIds = [];
|
|
3592
3624
|
for (const item of updates) {
|
|
3593
3625
|
const dirtyBaseRev = typeof item.delta._rev === "number" ? item.delta._rev : void 0;
|
|
3594
3626
|
const stripped = stripServerManagedFromChanges(
|
|
@@ -3605,8 +3637,12 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3605
3637
|
};
|
|
3606
3638
|
if (this.preprocessDirtyItem) {
|
|
3607
3639
|
try {
|
|
3608
|
-
const processed = this.preprocessDirtyItem(
|
|
3640
|
+
const processed = this.preprocessDirtyItem(
|
|
3641
|
+
candidate,
|
|
3642
|
+
collectionName
|
|
3643
|
+
);
|
|
3609
3644
|
if (processed === void 0) {
|
|
3645
|
+
preprocessSkippedIds.push(item._id);
|
|
3610
3646
|
continue;
|
|
3611
3647
|
}
|
|
3612
3648
|
candidate = processed;
|
|
@@ -3615,6 +3651,7 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3615
3651
|
`[SyncEngine] preprocessDirtyItem(${collectionName}) failed for _id=${String(item._id)}; keeping dirty for retry:`,
|
|
3616
3652
|
err
|
|
3617
3653
|
);
|
|
3654
|
+
preprocessSkippedIds.push(item._id);
|
|
3618
3655
|
continue;
|
|
3619
3656
|
}
|
|
3620
3657
|
}
|
|
@@ -3624,14 +3661,23 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3624
3661
|
update: candidate.update
|
|
3625
3662
|
});
|
|
3626
3663
|
}
|
|
3664
|
+
if (preprocessSkippedIds.length > 0) {
|
|
3665
|
+
const newlyStuck = await this.dexieDb.incrementDirtyUploadAttempts(
|
|
3666
|
+
collectionName,
|
|
3667
|
+
preprocessSkippedIds
|
|
3668
|
+
);
|
|
3669
|
+
this.callOnDirtyItemStuck(collectionName, newlyStuck, calledFrom);
|
|
3670
|
+
}
|
|
3627
3671
|
if (mappedUpdates.length === 0) continue;
|
|
3628
|
-
collectionBatches.push([
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3672
|
+
collectionBatches.push([
|
|
3673
|
+
{
|
|
3674
|
+
collection: collectionName,
|
|
3675
|
+
batch: {
|
|
3676
|
+
updates: mappedUpdates,
|
|
3677
|
+
deletes: []
|
|
3678
|
+
}
|
|
3633
3679
|
}
|
|
3634
|
-
|
|
3680
|
+
]);
|
|
3635
3681
|
}
|
|
3636
3682
|
if (collectionBatches.length === 0) {
|
|
3637
3683
|
return { sentCount: 0 };
|
|
@@ -3669,7 +3715,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3669
3715
|
const allIds = [];
|
|
3670
3716
|
for (const u of b.batch.updates) allIds.push(u._id);
|
|
3671
3717
|
for (const d of b.batch.deletes) allIds.push((_a = d._id) != null ? _a : d);
|
|
3672
|
-
const newlyStuck = await this.dexieDb.incrementDirtyUploadAttempts(
|
|
3718
|
+
const newlyStuck = await this.dexieDb.incrementDirtyUploadAttempts(
|
|
3719
|
+
b.collection,
|
|
3720
|
+
allIds
|
|
3721
|
+
);
|
|
3673
3722
|
this.callOnDirtyItemStuck(b.collection, newlyStuck, calledFrom);
|
|
3674
3723
|
}
|
|
3675
3724
|
}
|
|
@@ -3721,7 +3770,9 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3721
3770
|
`[SyncEngine] Sync upload [${collection}]: ${ambiguous.length} id(s) appeared in BOTH inserted/updated/deleted AND errors[] \u2014 keeping dirty for safety. _ids: ${ambiguous.join(", ")}`
|
|
3722
3771
|
);
|
|
3723
3772
|
}
|
|
3724
|
-
const dirtyBeforeRefresh = mustRefreshIds.size > 0 ? await this.dexieDb.getDirtyChangesBatch(collection, [
|
|
3773
|
+
const dirtyBeforeRefresh = mustRefreshIds.size > 0 ? await this.dexieDb.getDirtyChangesBatch(collection, [
|
|
3774
|
+
...mustRefreshIds
|
|
3775
|
+
]) : /* @__PURE__ */ new Map();
|
|
3725
3776
|
const uploadedByIdRefresh = mustRefreshIds.size > 0 ? this.uploadedSnapshotFor(collectionBatches, collection) : /* @__PURE__ */ new Map();
|
|
3726
3777
|
if (allSuccessIds.length > 0) {
|
|
3727
3778
|
await this.dexieDb.clearDirtyChangesBatch(collection, allSuccessIds);
|
|
@@ -3730,8 +3781,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3730
3781
|
for (const batch of collectionBatches) {
|
|
3731
3782
|
for (const b of batch) {
|
|
3732
3783
|
if (b.collection !== collection) continue;
|
|
3733
|
-
for (const u of b.batch.updates)
|
|
3734
|
-
|
|
3784
|
+
for (const u of b.batch.updates)
|
|
3785
|
+
sentIdsForCollection.add(String(u._id));
|
|
3786
|
+
for (const d of b.batch.deletes)
|
|
3787
|
+
sentIdsForCollection.add(String(d._id));
|
|
3735
3788
|
}
|
|
3736
3789
|
}
|
|
3737
3790
|
const retainedIds = [];
|
|
@@ -3741,7 +3794,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3741
3794
|
}
|
|
3742
3795
|
}
|
|
3743
3796
|
if (retainedIds.length > 0) {
|
|
3744
|
-
const newlyStuck = await this.dexieDb.incrementDirtyUploadAttempts(
|
|
3797
|
+
const newlyStuck = await this.dexieDb.incrementDirtyUploadAttempts(
|
|
3798
|
+
collection,
|
|
3799
|
+
retainedIds
|
|
3800
|
+
);
|
|
3745
3801
|
this.callOnDirtyItemStuck(collection, newlyStuck, calledFrom);
|
|
3746
3802
|
}
|
|
3747
3803
|
let collectionSentCount = 0;
|
|
@@ -3753,7 +3809,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3753
3809
|
if (isWriteOnly) {
|
|
3754
3810
|
await this.dexieDb.deleteMany(collection, idsToCheck);
|
|
3755
3811
|
} else {
|
|
3756
|
-
const dexieItems = await this.dexieDb.getByIds(
|
|
3812
|
+
const dexieItems = await this.dexieDb.getByIds(
|
|
3813
|
+
collection,
|
|
3814
|
+
idsToCheck
|
|
3815
|
+
);
|
|
3757
3816
|
const dexieSaveBatch = [];
|
|
3758
3817
|
const inMemUpdateBatch = [];
|
|
3759
3818
|
const inMemDeleteIds = [];
|
|
@@ -3781,7 +3840,12 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3781
3840
|
await this.dexieDb.deleteMany(collection, dexieDeleteIds);
|
|
3782
3841
|
}
|
|
3783
3842
|
if (inMemUpdateBatch.length > 0) {
|
|
3784
|
-
this.deps.writeToInMemBatch(
|
|
3843
|
+
this.deps.writeToInMemBatch(
|
|
3844
|
+
collection,
|
|
3845
|
+
inMemUpdateBatch,
|
|
3846
|
+
"upsert",
|
|
3847
|
+
{ source: "incremental" }
|
|
3848
|
+
);
|
|
3785
3849
|
}
|
|
3786
3850
|
if (inMemDeleteIds.length > 0) {
|
|
3787
3851
|
this.deps.writeToInMemBatch(
|
|
@@ -3804,7 +3868,9 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3804
3868
|
}
|
|
3805
3869
|
await this.dexieDb.deleteMany(collection, deleteIds);
|
|
3806
3870
|
if (!isWriteOnly) {
|
|
3807
|
-
this.deps.writeToInMemBatch(collection, deleteDbEntities, "delete", {
|
|
3871
|
+
this.deps.writeToInMemBatch(collection, deleteDbEntities, "delete", {
|
|
3872
|
+
source: "incremental"
|
|
3873
|
+
});
|
|
3808
3874
|
}
|
|
3809
3875
|
sentCount += deleted.length;
|
|
3810
3876
|
collectionSentCount += deleted.length;
|
|
@@ -3820,7 +3886,7 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3820
3886
|
if (collectionSentCount > 0) {
|
|
3821
3887
|
collectionSentCounts[collection] = collectionSentCount;
|
|
3822
3888
|
}
|
|
3823
|
-
let maxTs
|
|
3889
|
+
let maxTs;
|
|
3824
3890
|
for (const arr of [inserted, updated, deleted]) {
|
|
3825
3891
|
for (const item of arr) {
|
|
3826
3892
|
if (item._ts) {
|
|
@@ -3890,7 +3956,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3890
3956
|
return { sentCount: 0 };
|
|
3891
3957
|
}
|
|
3892
3958
|
const ids = dirtyItems.map((item) => item._id);
|
|
3893
|
-
const fullItems = await this.dexieDb.getByIds(
|
|
3959
|
+
const fullItems = await this.dexieDb.getByIds(
|
|
3960
|
+
collection,
|
|
3961
|
+
ids
|
|
3962
|
+
);
|
|
3894
3963
|
const dirtyChangesMap = /* @__PURE__ */ new Map();
|
|
3895
3964
|
for (const dirtyItem of dirtyItems) {
|
|
3896
3965
|
dirtyChangesMap.set(String(dirtyItem._id), dirtyItem);
|
|
@@ -3906,20 +3975,24 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3906
3975
|
if (updates.length === 0) {
|
|
3907
3976
|
return { sentCount: 0 };
|
|
3908
3977
|
}
|
|
3909
|
-
const collectionBatches = [
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3978
|
+
const collectionBatches = [
|
|
3979
|
+
[
|
|
3980
|
+
{
|
|
3981
|
+
collection,
|
|
3982
|
+
batch: {
|
|
3983
|
+
updates: updates.map((item) => {
|
|
3984
|
+
const _a = item.delta, { _ts, _rev } = _a, changes = __objRest(_a, ["_ts", "_rev"]);
|
|
3985
|
+
return {
|
|
3986
|
+
_id: item._id,
|
|
3987
|
+
_rev: typeof _rev === "number" ? _rev : 0,
|
|
3988
|
+
update: changes
|
|
3989
|
+
};
|
|
3990
|
+
}),
|
|
3991
|
+
deletes: []
|
|
3992
|
+
}
|
|
3993
|
+
}
|
|
3994
|
+
]
|
|
3995
|
+
];
|
|
3923
3996
|
const results = await this.deps.withSyncTimeout(
|
|
3924
3997
|
this.restInterface.updateCollections(collectionBatches),
|
|
3925
3998
|
"updateCollections"
|
|
@@ -3986,8 +4059,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3986
4059
|
for (const batch of collectionBatches) {
|
|
3987
4060
|
for (const b of batch) {
|
|
3988
4061
|
if (b.collection !== collection) continue;
|
|
3989
|
-
for (const u of b.batch.updates)
|
|
3990
|
-
|
|
4062
|
+
for (const u of b.batch.updates)
|
|
4063
|
+
sentIdsForCollection.add(String(u._id));
|
|
4064
|
+
for (const d of b.batch.deletes)
|
|
4065
|
+
sentIdsForCollection.add(String(d._id));
|
|
3991
4066
|
}
|
|
3992
4067
|
}
|
|
3993
4068
|
const retainedIds = [];
|
|
@@ -3997,7 +4072,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
3997
4072
|
}
|
|
3998
4073
|
}
|
|
3999
4074
|
if (retainedIds.length > 0) {
|
|
4000
|
-
const newlyStuck = await this.dexieDb.incrementDirtyUploadAttempts(
|
|
4075
|
+
const newlyStuck = await this.dexieDb.incrementDirtyUploadAttempts(
|
|
4076
|
+
collection,
|
|
4077
|
+
retainedIds
|
|
4078
|
+
);
|
|
4001
4079
|
this.callOnDirtyItemStuck(collection, newlyStuck, calledFrom);
|
|
4002
4080
|
}
|
|
4003
4081
|
if (mustRefresh && mustRefresh.length > 0) {
|
|
@@ -4025,7 +4103,12 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4025
4103
|
const config = this.collections.get(collectionName);
|
|
4026
4104
|
if (!config) return { updatedIds: [] };
|
|
4027
4105
|
const source = (_a = opts == null ? void 0 : opts.source) != null ? _a : "incremental";
|
|
4028
|
-
const result = await this.processIncomingServerData(
|
|
4106
|
+
const result = await this.processIncomingServerData(
|
|
4107
|
+
collectionName,
|
|
4108
|
+
config,
|
|
4109
|
+
serverData,
|
|
4110
|
+
source
|
|
4111
|
+
);
|
|
4029
4112
|
if (result.updatedIds.length > 0) {
|
|
4030
4113
|
this.deps.broadcastUpdates({ [collectionName]: result.updatedIds });
|
|
4031
4114
|
}
|
|
@@ -4043,8 +4126,14 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4043
4126
|
const chunk = serverData.slice(offset, offset + BATCH);
|
|
4044
4127
|
const chunkIds = [];
|
|
4045
4128
|
for (const item of chunk) chunkIds.push(item._id);
|
|
4046
|
-
const localItems = await this.dexieDb.getByIds(
|
|
4047
|
-
|
|
4129
|
+
const localItems = await this.dexieDb.getByIds(
|
|
4130
|
+
collectionName,
|
|
4131
|
+
chunkIds
|
|
4132
|
+
);
|
|
4133
|
+
const dirtyChangesMap = await this.dexieDb.getDirtyChangesBatch(
|
|
4134
|
+
collectionName,
|
|
4135
|
+
chunkIds
|
|
4136
|
+
);
|
|
4048
4137
|
const dexieBatch = [];
|
|
4049
4138
|
const inMemSaveBatch = [];
|
|
4050
4139
|
const inMemDeleteIds = [];
|
|
@@ -4093,7 +4182,9 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4093
4182
|
await this.dexieDb.saveMany(collectionName, dexieBatch);
|
|
4094
4183
|
}
|
|
4095
4184
|
if (inMemSaveBatch.length > 0) {
|
|
4096
|
-
this.deps.writeToInMemBatch(collectionName, inMemSaveBatch, "upsert", {
|
|
4185
|
+
this.deps.writeToInMemBatch(collectionName, inMemSaveBatch, "upsert", {
|
|
4186
|
+
source
|
|
4187
|
+
});
|
|
4097
4188
|
}
|
|
4098
4189
|
if (inMemDeleteIds.length > 0) {
|
|
4099
4190
|
this.deps.writeToInMemBatch(
|
|
@@ -4141,7 +4232,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4141
4232
|
timestamp: /* @__PURE__ */ new Date()
|
|
4142
4233
|
});
|
|
4143
4234
|
} catch (err) {
|
|
4144
|
-
console.error(
|
|
4235
|
+
console.error(
|
|
4236
|
+
`[SyncEngine] onConflictResolved callback failed: ${err}`,
|
|
4237
|
+
err
|
|
4238
|
+
);
|
|
4145
4239
|
}
|
|
4146
4240
|
}
|
|
4147
4241
|
return resolved;
|
|
@@ -4186,7 +4280,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4186
4280
|
calledFrom
|
|
4187
4281
|
});
|
|
4188
4282
|
} catch (err) {
|
|
4189
|
-
console.error(
|
|
4283
|
+
console.error(
|
|
4284
|
+
`[SyncEngine] onFindNewerManyCall callback failed: ${err}`,
|
|
4285
|
+
err
|
|
4286
|
+
);
|
|
4190
4287
|
}
|
|
4191
4288
|
}
|
|
4192
4289
|
}
|
|
@@ -4205,7 +4302,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4205
4302
|
ttfbMs: metrics == null ? void 0 : metrics.ttfbMs
|
|
4206
4303
|
});
|
|
4207
4304
|
} catch (err) {
|
|
4208
|
-
console.error(
|
|
4305
|
+
console.error(
|
|
4306
|
+
`[SyncEngine] onFindNewerManyResult callback failed: ${err}`,
|
|
4307
|
+
err
|
|
4308
|
+
);
|
|
4209
4309
|
}
|
|
4210
4310
|
}
|
|
4211
4311
|
}
|
|
@@ -4218,7 +4318,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4218
4318
|
calledFrom
|
|
4219
4319
|
});
|
|
4220
4320
|
} catch (err) {
|
|
4221
|
-
console.error(
|
|
4321
|
+
console.error(
|
|
4322
|
+
`[SyncEngine] onServerWriteRequest callback failed: ${err}`,
|
|
4323
|
+
err
|
|
4324
|
+
);
|
|
4222
4325
|
}
|
|
4223
4326
|
}
|
|
4224
4327
|
}
|
|
@@ -4233,7 +4336,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4233
4336
|
calledFrom
|
|
4234
4337
|
});
|
|
4235
4338
|
} catch (err) {
|
|
4236
|
-
console.error(
|
|
4339
|
+
console.error(
|
|
4340
|
+
`[SyncEngine] onServerWriteResult callback failed: ${err}`,
|
|
4341
|
+
err
|
|
4342
|
+
);
|
|
4237
4343
|
}
|
|
4238
4344
|
}
|
|
4239
4345
|
}
|
|
@@ -4247,7 +4353,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4247
4353
|
timestamp: /* @__PURE__ */ new Date()
|
|
4248
4354
|
});
|
|
4249
4355
|
} catch (err) {
|
|
4250
|
-
console.error(
|
|
4356
|
+
console.error(
|
|
4357
|
+
`[SyncEngine] onDirtyItemStuck callback failed: ${err}`,
|
|
4358
|
+
err
|
|
4359
|
+
);
|
|
4251
4360
|
}
|
|
4252
4361
|
}
|
|
4253
4362
|
callOnServerSyncWrite(request, response, error, startTime, timestamp, calledFrom) {
|
|
@@ -4267,7 +4376,10 @@ var _SyncEngine = class _SyncEngine {
|
|
|
4267
4376
|
timestamp
|
|
4268
4377
|
});
|
|
4269
4378
|
} catch (err) {
|
|
4270
|
-
console.error(
|
|
4379
|
+
console.error(
|
|
4380
|
+
`[SyncEngine] onServerSyncWrite callback failed: ${err}`,
|
|
4381
|
+
err
|
|
4382
|
+
);
|
|
4271
4383
|
}
|
|
4272
4384
|
}
|
|
4273
4385
|
};
|