@powersync/service-module-mongodb 0.0.0-dev-20260203155513 → 0.0.0-dev-20260223080959

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.
@@ -1,19 +1,22 @@
1
1
  import { ChangeStreamInvalidatedError } from '@module/replication/ChangeStream.js';
2
2
  import { MongoManager } from '@module/replication/MongoManager.js';
3
3
  import { normalizeConnectionConfig } from '@module/types/types.js';
4
- import { BucketStorageFactory, TestStorageOptions } from '@powersync/service-core';
5
4
  import { describe, expect, test } from 'vitest';
6
5
  import { ChangeStreamTestContext } from './change_stream_utils.js';
7
6
  import { env } from './env.js';
8
- import { describeWithStorage } from './util.js';
7
+ import { describeWithStorage, StorageVersionTestContext } from './util.js';
9
8
 
10
9
  describe('mongodb resuming replication', () => {
11
10
  describeWithStorage({}, defineResumeTest);
12
11
  });
13
12
 
14
- function defineResumeTest(factoryGenerator: (options?: TestStorageOptions) => Promise<BucketStorageFactory>) {
13
+ function defineResumeTest({ factory: factoryGenerator, storageVersion }: StorageVersionTestContext) {
14
+ const openContext = (options?: Parameters<typeof ChangeStreamTestContext.open>[1]) => {
15
+ return ChangeStreamTestContext.open(factoryGenerator, { ...options, storageVersion });
16
+ };
17
+
15
18
  test('resuming with a different source database', async () => {
16
- await using context = await ChangeStreamTestContext.open(factoryGenerator);
19
+ await using context = await openContext();
17
20
  const { db } = context;
18
21
 
19
22
  await context.updateSyncRules(/* yaml */
@@ -53,7 +56,7 @@ function defineResumeTest(factoryGenerator: (options?: TestStorageOptions) => Pr
53
56
  const factory = await factoryGenerator({ doNotClear: true });
54
57
 
55
58
  // Create a new context without updating the sync rules
56
- await using context2 = new ChangeStreamTestContext(factory, connectionManager);
59
+ await using context2 = new ChangeStreamTestContext(factory, connectionManager, {}, storageVersion);
57
60
  const activeContent = await factory.getActiveSyncRulesContent();
58
61
  context2.storage = factory.getInstance(activeContent!);
59
62
 
@@ -8,19 +8,19 @@ import { env } from './env.js';
8
8
  import { describeWithStorage } from './util.js';
9
9
 
10
10
  describe.skipIf(!(env.CI || env.SLOW_TESTS))('batch replication', function () {
11
- describeWithStorage({ timeout: 240_000 }, function (factory) {
11
+ describeWithStorage({ timeout: 240_000 }, function ({ factory, storageVersion }) {
12
12
  test('resuming initial replication (1)', async () => {
13
13
  // Stop early - likely to not include deleted row in first replication attempt.
14
- await testResumingReplication(factory, 2000);
14
+ await testResumingReplication(factory, storageVersion, 2000);
15
15
  });
16
16
  test('resuming initial replication (2)', async () => {
17
17
  // Stop late - likely to include deleted row in first replication attempt.
18
- await testResumingReplication(factory, 8000);
18
+ await testResumingReplication(factory, storageVersion, 8000);
19
19
  });
20
20
  });
21
21
  });
22
22
 
23
- async function testResumingReplication(factory: TestStorageFactory, stopAfter: number) {
23
+ async function testResumingReplication(factory: TestStorageFactory, storageVersion: number, stopAfter: number) {
24
24
  // This tests interrupting and then resuming initial replication.
25
25
  // We interrupt replication after test_data1 has fully replicated, and
26
26
  // test_data2 has partially replicated.
@@ -35,7 +35,10 @@ async function testResumingReplication(factory: TestStorageFactory, stopAfter: n
35
35
  let startRowCount: number;
36
36
 
37
37
  {
38
- await using context = await ChangeStreamTestContext.open(factory, { streamOptions: { snapshotChunkLength: 1000 } });
38
+ await using context = await ChangeStreamTestContext.open(factory, {
39
+ storageVersion,
40
+ streamOptions: { snapshotChunkLength: 1000 }
41
+ });
39
42
 
40
43
  await context.updateSyncRules(`bucket_definitions:
41
44
  global:
@@ -87,6 +90,7 @@ async function testResumingReplication(factory: TestStorageFactory, stopAfter: n
87
90
  // Bypass the usual "clear db on factory open" step.
88
91
  await using context2 = await ChangeStreamTestContext.open(factory, {
89
92
  doNotClear: true,
93
+ storageVersion,
90
94
  streamOptions: { snapshotChunkLength: 1000 }
91
95
  });
92
96
 
@@ -2,19 +2,21 @@ import { setTimeout } from 'node:timers/promises';
2
2
  import { describe, expect, test } from 'vitest';
3
3
 
4
4
  import { mongo } from '@powersync/lib-service-mongodb';
5
- import { storage } from '@powersync/service-core';
6
-
7
5
  import { ChangeStreamTestContext, setSnapshotHistorySeconds } from './change_stream_utils.js';
8
6
  import { env } from './env.js';
9
- import { describeWithStorage } from './util.js';
7
+ import { describeWithStorage, StorageVersionTestContext } from './util.js';
10
8
 
11
9
  describe.runIf(env.CI || env.SLOW_TESTS)('change stream slow tests', { timeout: 60_000 }, function () {
12
10
  describeWithStorage({}, defineSlowTests);
13
11
  });
14
12
 
15
- function defineSlowTests(factory: storage.TestStorageFactory) {
13
+ function defineSlowTests({ factory, storageVersion }: StorageVersionTestContext) {
14
+ const openContext = (options?: Parameters<typeof ChangeStreamTestContext.open>[1]) => {
15
+ return ChangeStreamTestContext.open(factory, { ...options, storageVersion });
16
+ };
17
+
16
18
  test('replicating snapshot with lots of data', async () => {
17
- await using context = await ChangeStreamTestContext.open(factory);
19
+ await using context = await openContext();
18
20
  // Test with low minSnapshotHistoryWindowInSeconds, to trigger:
19
21
  // > Read timestamp .. is older than the oldest available timestamp.
20
22
  // This happened when we had {snapshot: true} in the initial
@@ -52,7 +54,7 @@ bucket_definitions:
52
54
  // changestream), we may miss updates, which this test would
53
55
  // hopefully catch.
54
56
 
55
- await using context = await ChangeStreamTestContext.open(factory);
57
+ await using context = await openContext();
56
58
  const { db } = context;
57
59
  await context.updateSyncRules(`
58
60
  bucket_definitions:
package/test/src/util.ts CHANGED
@@ -3,9 +3,14 @@ import * as mongo_storage from '@powersync/service-module-mongodb-storage';
3
3
  import * as postgres_storage from '@powersync/service-module-postgres-storage';
4
4
 
5
5
  import * as types from '@module/types/types.js';
6
- import { env } from './env.js';
7
- import { BSON_DESERIALIZE_DATA_OPTIONS, TestStorageFactory } from '@powersync/service-core';
6
+ import {
7
+ BSON_DESERIALIZE_DATA_OPTIONS,
8
+ CURRENT_STORAGE_VERSION,
9
+ LEGACY_STORAGE_VERSION,
10
+ TestStorageFactory
11
+ } from '@powersync/service-core';
8
12
  import { describe, TestOptions } from 'vitest';
13
+ import { env } from './env.js';
9
14
 
10
15
  export const TEST_URI = env.MONGO_TEST_DATA_URL;
11
16
 
@@ -23,14 +28,34 @@ export const INITIALIZED_POSTGRES_STORAGE_FACTORY = postgres_storage.test_utils.
23
28
  url: env.PG_STORAGE_TEST_URL
24
29
  });
25
30
 
26
- export function describeWithStorage(options: TestOptions, fn: (factory: TestStorageFactory) => void) {
27
- describe.skipIf(!env.TEST_MONGO_STORAGE)(`mongodb storage`, options, function () {
28
- fn(INITIALIZED_MONGO_STORAGE_FACTORY);
29
- });
31
+ const TEST_STORAGE_VERSIONS = [LEGACY_STORAGE_VERSION, CURRENT_STORAGE_VERSION];
30
32
 
31
- describe.skipIf(!env.TEST_POSTGRES_STORAGE)(`postgres storage`, options, function () {
32
- fn(INITIALIZED_POSTGRES_STORAGE_FACTORY);
33
- });
33
+ export interface StorageVersionTestContext {
34
+ factory: TestStorageFactory;
35
+ storageVersion: number;
36
+ }
37
+
38
+ export function describeWithStorage(options: TestOptions, fn: (context: StorageVersionTestContext) => void) {
39
+ const describeFactory = (storageName: string, factory: TestStorageFactory) => {
40
+ describe(`${storageName} storage`, options, function () {
41
+ for (const storageVersion of TEST_STORAGE_VERSIONS) {
42
+ describe(`storage v${storageVersion}`, function () {
43
+ fn({
44
+ factory,
45
+ storageVersion
46
+ });
47
+ });
48
+ }
49
+ });
50
+ };
51
+
52
+ if (env.TEST_MONGO_STORAGE) {
53
+ describeFactory('mongodb', INITIALIZED_MONGO_STORAGE_FACTORY);
54
+ }
55
+
56
+ if (env.TEST_POSTGRES_STORAGE) {
57
+ describeFactory('postgres', INITIALIZED_POSTGRES_STORAGE_FACTORY);
58
+ }
34
59
  }
35
60
 
36
61
  export async function clearTestDb(db: mongo.Db) {
@@ -1,17 +1,13 @@
1
1
  {
2
- "extends": "../../../tsconfig.base.json",
2
+ "extends": "../../../tsconfig.tests.json",
3
3
  "compilerOptions": {
4
- "rootDir": "src",
5
4
  "baseUrl": "./",
6
- "noEmit": true,
7
- "esModuleInterop": true,
8
- "skipLibCheck": true,
9
- "sourceMap": true,
10
5
  "paths": {
11
6
  "@/*": ["../../../packages/service-core/src/*"],
12
7
  "@module/*": ["../src/*"],
13
8
  "@core-tests/*": ["../../../packages/service-core/test/src/*"]
14
- }
9
+ },
10
+ "rootDir": "src"
15
11
  },
16
12
  "include": ["src"],
17
13
  "references": [