@powersync/service-module-mongodb 0.0.0-dev-20250724093011 → 0.0.0-dev-20250724111728

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.
@@ -17,7 +17,7 @@ import { MongoManager } from '@module/replication/MongoManager.js';
17
17
  import { createCheckpoint, STANDALONE_CHECKPOINT_ID } from '@module/replication/MongoRelation.js';
18
18
  import { NormalizedMongoConnectionConfig } from '@module/types/types.js';
19
19
 
20
- import { TEST_CONNECTION_OPTIONS, clearTestDb } from './util.js';
20
+ import { clearTestDb, TEST_CONNECTION_OPTIONS } from './util.js';
21
21
 
22
22
  export class ChangeStreamTestContext {
23
23
  private _walStream?: ChangeStream;
@@ -119,7 +119,20 @@ export class ChangeStreamTestContext {
119
119
 
120
120
  async replicateSnapshot() {
121
121
  await this.walStream.initReplication();
122
- await this.storage!.autoActivate();
122
+ }
123
+
124
+ /**
125
+ * A snapshot is not consistent until streaming replication has caught up.
126
+ * We simulate that for tests.
127
+ * Do not use if there are any writes performed while doing the snapshot, as that
128
+ * would result in inconsistent data.
129
+ */
130
+ async markSnapshotConsistent() {
131
+ const checkpoint = await createCheckpoint(this.client, this.db, STANDALONE_CHECKPOINT_ID);
132
+
133
+ await this.storage!.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
134
+ await batch.keepalive(checkpoint);
135
+ });
123
136
  }
124
137
 
125
138
  startStreaming() {
@@ -195,12 +208,11 @@ export async function getClientCheckpoint(
195
208
  while (Date.now() - start < timeout) {
196
209
  const storage = await storageFactory.getActiveStorage();
197
210
  const cp = await storage?.getCheckpoint();
198
- if (cp == null) {
199
- throw new Error('No sync rules available');
200
- }
201
- lastCp = cp;
202
- if (cp.lsn && cp.lsn >= lsn) {
203
- return cp.checkpoint;
211
+ if (cp != null) {
212
+ lastCp = cp;
213
+ if (cp.lsn && cp.lsn >= lsn) {
214
+ return cp.checkpoint;
215
+ }
204
216
  }
205
217
  await new Promise((resolve) => setTimeout(resolve, 30));
206
218
  }