@tanstack/electric-db-collection 0.5.4 → 0.5.5
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/electric.cjs +16 -7
- package/dist/cjs/electric.cjs.map +1 -1
- package/dist/esm/electric.js +18 -9
- package/dist/esm/electric.js.map +1 -1
- package/package.json +3 -3
- package/src/electric.ts +24 -9
package/dist/esm/electric.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isVisibleInSnapshot, isChangeMessage,
|
|
1
|
+
import { isVisibleInSnapshot, isChangeMessage, isControlMessage, ShapeStream } from "@electric-sql/client";
|
|
2
2
|
import { isChangeMessage as isChangeMessage2, isControlMessage as isControlMessage2 } from "@electric-sql/client";
|
|
3
3
|
import DebugModule from "debug";
|
|
4
|
-
import { withCollectionSyncConfigFactory, withCollectionConfigFactory,
|
|
4
|
+
import { withCollectionSyncConfigFactory, withCollectionConfigFactory, warnOnce, withCollectionSyncConfigCleanup, validateSyncPersistenceCapability, DeduplicatedLoadSubset, whenSyncAccepted, and, LoadSubsetOperationAbortedError } from "@tanstack/db";
|
|
5
5
|
import { StreamAbortedError, ExpectedNumberInAwaitTxIdError, TimeoutWaitingForTxIdError, TimeoutWaitingForMatchError } from "./errors.js";
|
|
6
6
|
import { compileSQL } from "./sql-compiler.js";
|
|
7
7
|
import { isMoveOutMessage, isMoveInMessage, deriveDisjunctPositions, getTagLength, addTagToIndex, parseTag, removeTagFromIndex, findRowsMatchingPattern, rowVisible, tagMatchesPattern } from "./tag-index.js";
|
|
@@ -187,10 +187,11 @@ function createLoadSubsetDedupe({
|
|
|
187
187
|
const snapshotParams = compileSQL(opts, compileOptions);
|
|
188
188
|
try {
|
|
189
189
|
const { data: rows } = await stream.fetchSnapshot(snapshotParams);
|
|
190
|
-
if (
|
|
190
|
+
if (!isBufferingInitialSync()) {
|
|
191
191
|
debug(`${logPrefix}Ignoring snapshot - sync completed while fetching`);
|
|
192
192
|
return;
|
|
193
193
|
}
|
|
194
|
+
throwIfAborted();
|
|
194
195
|
if (rows.length > 0) {
|
|
195
196
|
begin();
|
|
196
197
|
for (const row of rows) {
|
|
@@ -206,12 +207,13 @@ function createLoadSubsetDedupe({
|
|
|
206
207
|
debug(`${logPrefix}Applied snapshot with ${rows.length} rows`);
|
|
207
208
|
}
|
|
208
209
|
} catch (error) {
|
|
209
|
-
if (opts.signal?.aborted) return;
|
|
210
210
|
if (handleSnapshotError(error, `fetchSnapshot`)) {
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
|
+
if (opts.signal?.aborted) throw abortReason(opts.signal);
|
|
213
214
|
throw error;
|
|
214
215
|
}
|
|
216
|
+
if (opts.signal?.aborted) throw abortReason(opts.signal);
|
|
215
217
|
return;
|
|
216
218
|
}
|
|
217
219
|
if (syncMode === `progressive`) {
|
|
@@ -933,8 +935,8 @@ function createElectricSync(shapeOptions, options) {
|
|
|
933
935
|
return applied;
|
|
934
936
|
};
|
|
935
937
|
const beginSourceTransaction = () => {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
+
begin();
|
|
939
|
+
metadata?.persistence?.reserveCommitTurn();
|
|
938
940
|
};
|
|
939
941
|
const syncedKeys = /* @__PURE__ */ new Set();
|
|
940
942
|
let resumeInvalid = false;
|
|
@@ -965,7 +967,7 @@ function createElectricSync(shapeOptions, options) {
|
|
|
965
967
|
};
|
|
966
968
|
lifecycle.resumeState = resetState;
|
|
967
969
|
if (metadata) {
|
|
968
|
-
begin(
|
|
970
|
+
begin();
|
|
969
971
|
metadata.collection.set(`electric:resume`, resetState);
|
|
970
972
|
if (expectInResumeSnapshot) {
|
|
971
973
|
expectCurrentCommit?.();
|
|
@@ -1272,11 +1274,18 @@ function createElectricSync(shapeOptions, options) {
|
|
|
1272
1274
|
}
|
|
1273
1275
|
}
|
|
1274
1276
|
const readyErrorVersion = streamErrorVersion;
|
|
1275
|
-
|
|
1277
|
+
const accepted = whenSyncAccepted(applied);
|
|
1278
|
+
if (accepted === true) {
|
|
1276
1279
|
wrappedMarkReady(wasBufferingInitialSync, readyErrorVersion);
|
|
1277
1280
|
} else {
|
|
1278
|
-
void
|
|
1281
|
+
void accepted.then(
|
|
1279
1282
|
() => wrappedMarkReady(wasBufferingInitialSync, readyErrorVersion),
|
|
1283
|
+
() => void 0
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
if (applied !== true) {
|
|
1287
|
+
void applied.then(
|
|
1288
|
+
() => void 0,
|
|
1280
1289
|
(error) => {
|
|
1281
1290
|
if (!isActiveLifecycle() || abortController.signal.aborted) {
|
|
1282
1291
|
return;
|