@tanstack/db-sqlite-persistence-core 0.2.19 → 0.2.21
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/cjs/persisted.cjs +31 -34
- package/dist/cjs/persisted.cjs.map +1 -1
- package/dist/esm/persisted.js +31 -34
- package/dist/esm/persisted.js.map +1 -1
- package/package.json +2 -2
- package/src/persisted.ts +48 -36
package/dist/cjs/persisted.cjs
CHANGED
|
@@ -388,17 +388,12 @@ class PersistedCollectionRuntime {
|
|
|
388
388
|
await this.waitForAppliedReceiptsAfter(appliedCursor);
|
|
389
389
|
if (upstreamLoadSubset) {
|
|
390
390
|
try {
|
|
391
|
-
|
|
392
|
-
if (maybePromise instanceof Promise) {
|
|
393
|
-
await maybePromise.catch((error) => {
|
|
394
|
-
console.warn(
|
|
395
|
-
`Failed to load remote subset in persisted wrapper:`,
|
|
396
|
-
error
|
|
397
|
-
);
|
|
398
|
-
this.queueRemoteSubsetEnsure(options);
|
|
399
|
-
});
|
|
400
|
-
}
|
|
391
|
+
await upstreamLoadSubset(options);
|
|
401
392
|
} catch (error) {
|
|
393
|
+
if (options.signal?.aborted || typeof error === `object` && error !== null && `name` in error && error.name === `AbortError`) {
|
|
394
|
+
this.pendingRemoteSubsetEnsures.delete(this.getSubsetKey(options));
|
|
395
|
+
throw error;
|
|
396
|
+
}
|
|
402
397
|
console.warn(`Failed to trigger remote subset load:`, error);
|
|
403
398
|
this.queueRemoteSubsetEnsure(options);
|
|
404
399
|
}
|
|
@@ -406,6 +401,7 @@ class PersistedCollectionRuntime {
|
|
|
406
401
|
}
|
|
407
402
|
unloadSubset(options, upstreamUnloadSubset) {
|
|
408
403
|
this.activeSubsets.delete(this.getSubsetKey(options));
|
|
404
|
+
this.pendingRemoteSubsetEnsures.delete(this.getSubsetKey(options));
|
|
409
405
|
upstreamUnloadSubset?.(options);
|
|
410
406
|
}
|
|
411
407
|
async forceReloadSubset(options) {
|
|
@@ -965,7 +961,7 @@ class PersistedCollectionRuntime {
|
|
|
965
961
|
return `opts:${stableSerialize(normalizeSubsetOptionsForKey(options))}`;
|
|
966
962
|
}
|
|
967
963
|
queueRemoteSubsetEnsure(options) {
|
|
968
|
-
if (this.mode !== `sync-present` || !this.persistence.coordinator.requestEnsureRemoteSubset) {
|
|
964
|
+
if (this.mode !== `sync-present` || !this.persistence.coordinator.requestEnsureRemoteSubset || this.activeSubsets.get(this.getSubsetKey(options)) !== options) {
|
|
969
965
|
return;
|
|
970
966
|
}
|
|
971
967
|
this.pendingRemoteSubsetEnsures.set(this.getSubsetKey(options), options);
|
|
@@ -1299,23 +1295,7 @@ function createWrappedSyncConfig(sourceSyncConfig, runtime) {
|
|
|
1299
1295
|
const transactionStack = [];
|
|
1300
1296
|
const getOpenTransaction = () => transactionStack[transactionStack.length - 1];
|
|
1301
1297
|
let fullStartPromise = null;
|
|
1302
|
-
const
|
|
1303
|
-
const loadSubscriptionIds = /* @__PURE__ */ new WeakMap();
|
|
1304
|
-
let nextLoadSubscriptionId = 0;
|
|
1305
|
-
const getLoadKey = (options) => {
|
|
1306
|
-
const subscription = options.subscription;
|
|
1307
|
-
if (subscription && typeof subscription === `object`) {
|
|
1308
|
-
const existingId = loadSubscriptionIds.get(subscription);
|
|
1309
|
-
if (existingId) {
|
|
1310
|
-
return `sub:${existingId}`;
|
|
1311
|
-
}
|
|
1312
|
-
nextLoadSubscriptionId++;
|
|
1313
|
-
const nextId = String(nextLoadSubscriptionId);
|
|
1314
|
-
loadSubscriptionIds.set(subscription, nextId);
|
|
1315
|
-
return `sub:${nextId}`;
|
|
1316
|
-
}
|
|
1317
|
-
return `opts:${stableSerialize(normalizeSubsetOptionsForKey(options))}`;
|
|
1318
|
-
};
|
|
1298
|
+
const acquisitions = /* @__PURE__ */ new Map();
|
|
1319
1299
|
runtime.setSyncControls({
|
|
1320
1300
|
begin: params.begin,
|
|
1321
1301
|
write: params.write,
|
|
@@ -1570,23 +1550,40 @@ function createWrappedSyncConfig(sourceSyncConfig, runtime) {
|
|
|
1570
1550
|
return {
|
|
1571
1551
|
cleanup: () => {
|
|
1572
1552
|
startupState.cleanedUp = true;
|
|
1553
|
+
acquisitions.clear();
|
|
1573
1554
|
sourceResult.cleanup?.();
|
|
1574
1555
|
runtime.cleanup();
|
|
1575
1556
|
runtime.clearSyncControls();
|
|
1576
1557
|
},
|
|
1577
1558
|
loadSubset: async (options) => {
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1559
|
+
const acquisition = { forwarded: false };
|
|
1560
|
+
acquisitions.set(options, acquisition);
|
|
1580
1561
|
await fullStartPromise;
|
|
1581
1562
|
const resolvedSourceResult = await sourceResultPromise;
|
|
1582
|
-
if (startupState.cleanedUp ||
|
|
1563
|
+
if (startupState.cleanedUp || acquisitions.get(options) !== acquisition) {
|
|
1583
1564
|
return;
|
|
1584
1565
|
}
|
|
1585
|
-
|
|
1566
|
+
return runtime.loadSubset(options, (loadOptions) => {
|
|
1567
|
+
if (startupState.cleanedUp || acquisitions.get(options) !== acquisition) {
|
|
1568
|
+
return true;
|
|
1569
|
+
}
|
|
1570
|
+
if (!resolvedSourceResult.loadSubset) return true;
|
|
1571
|
+
acquisition.forwarded = true;
|
|
1572
|
+
try {
|
|
1573
|
+
return resolvedSourceResult.loadSubset(loadOptions);
|
|
1574
|
+
} catch (error) {
|
|
1575
|
+
acquisition.forwarded = false;
|
|
1576
|
+
throw error;
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1586
1579
|
},
|
|
1587
1580
|
unloadSubset: (options) => {
|
|
1588
|
-
|
|
1589
|
-
|
|
1581
|
+
const acquisition = acquisitions.get(options);
|
|
1582
|
+
acquisitions.delete(options);
|
|
1583
|
+
runtime.unloadSubset(
|
|
1584
|
+
options,
|
|
1585
|
+
acquisition?.forwarded ? sourceResult.unloadSubset : void 0
|
|
1586
|
+
);
|
|
1590
1587
|
}
|
|
1591
1588
|
};
|
|
1592
1589
|
}
|