@powersync/service-module-mongodb 0.1.8 → 0.3.0
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 +30 -0
- package/dist/api/MongoRouteAPIAdapter.d.ts +1 -1
- package/dist/api/MongoRouteAPIAdapter.js +6 -5
- package/dist/api/MongoRouteAPIAdapter.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/module/MongoModule.d.ts +0 -1
- package/dist/module/MongoModule.js +4 -6
- package/dist/module/MongoModule.js.map +1 -1
- package/dist/replication/ChangeStream.d.ts +1 -1
- package/dist/replication/ChangeStream.js +3 -3
- package/dist/replication/ChangeStream.js.map +1 -1
- package/dist/replication/ChangeStreamReplicationJob.js +2 -2
- package/dist/replication/ChangeStreamReplicationJob.js.map +1 -1
- package/dist/replication/MongoManager.d.ts +1 -1
- package/dist/replication/MongoManager.js +1 -1
- package/dist/replication/MongoManager.js.map +1 -1
- package/dist/replication/MongoRelation.d.ts +1 -1
- package/dist/replication/MongoRelation.js +16 -6
- package/dist/replication/MongoRelation.js.map +1 -1
- package/dist/types/types.d.ts +16 -19
- package/dist/types/types.js +4 -21
- package/dist/types/types.js.map +1 -1
- package/package.json +11 -9
- package/src/api/MongoRouteAPIAdapter.ts +7 -6
- package/src/index.ts +3 -0
- package/src/module/MongoModule.ts +4 -7
- package/src/replication/ChangeStream.ts +3 -3
- package/src/replication/ChangeStreamReplicationJob.ts +3 -4
- package/src/replication/MongoManager.ts +2 -1
- package/src/replication/MongoRelation.ts +16 -7
- package/src/types/types.ts +8 -27
- package/test/src/change_stream.test.ts +38 -38
- package/test/src/change_stream_utils.ts +7 -6
- package/test/src/env.ts +1 -0
- package/test/src/mongo_test.test.ts +74 -14
- package/test/src/setup.ts +4 -1
- package/test/src/slow_tests.test.ts +11 -16
- package/test/src/util.ts +7 -27
- package/test/tsconfig.json +3 -0
- package/tsconfig.json +6 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +1 -1
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
import { MONGO_STORAGE_FACTORY } from '@core-tests/util.js';
|
|
2
|
-
import { BucketStorageFactory } from '@powersync/service-core';
|
|
3
|
-
import * as mongo from 'mongodb';
|
|
4
1
|
import { setTimeout } from 'node:timers/promises';
|
|
5
2
|
import { describe, expect, test } from 'vitest';
|
|
6
|
-
import { ChangeStreamTestContext, setSnapshotHistorySeconds } from './change_stream_utils.js';
|
|
7
|
-
import { env } from './env.js';
|
|
8
3
|
|
|
9
|
-
|
|
4
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
5
|
+
import { storage } from '@powersync/service-core';
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
data:
|
|
15
|
-
- SELECT _id as id, description FROM "test_data"
|
|
16
|
-
`;
|
|
7
|
+
import { ChangeStreamTestContext, setSnapshotHistorySeconds } from './change_stream_utils.js';
|
|
8
|
+
import { env } from './env.js';
|
|
9
|
+
import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
|
|
17
10
|
|
|
18
11
|
describe('change stream slow tests - mongodb', { timeout: 60_000 }, function () {
|
|
19
12
|
if (env.CI || env.SLOW_TESTS) {
|
|
20
|
-
defineSlowTests(
|
|
13
|
+
defineSlowTests(INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
21
14
|
} else {
|
|
22
15
|
// Need something in this file.
|
|
23
16
|
test('no-op', () => {});
|
|
24
17
|
}
|
|
25
18
|
});
|
|
26
19
|
|
|
27
|
-
function defineSlowTests(factory:
|
|
20
|
+
function defineSlowTests(factory: storage.TestStorageFactory) {
|
|
28
21
|
test('replicating snapshot with lots of data', async () => {
|
|
29
22
|
await using context = await ChangeStreamTestContext.open(factory);
|
|
30
23
|
// Test with low minSnapshotHistoryWindowInSeconds, to trigger:
|
|
@@ -96,8 +89,10 @@ bucket_definitions:
|
|
|
96
89
|
|
|
97
90
|
const data = await context.getBucketData('global[]', undefined, { limit: 50_000, chunkLimitBytes: 60_000_000 });
|
|
98
91
|
|
|
99
|
-
const preDocuments = data.filter((d) => JSON.parse(d.data! as string).description.startsWith('pre')).length;
|
|
100
|
-
const updatedDocuments = data.filter((d) =>
|
|
92
|
+
const preDocuments = data.filter((d: any) => JSON.parse(d.data! as string).description.startsWith('pre')).length;
|
|
93
|
+
const updatedDocuments = data.filter((d: any) =>
|
|
94
|
+
JSON.parse(d.data! as string).description.startsWith('updated')
|
|
95
|
+
).length;
|
|
101
96
|
|
|
102
97
|
// If the test works properly, preDocuments should be around 2000-3000.
|
|
103
98
|
// The total should be around 9000-9900.
|
package/test/src/util.ts
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
+
import * as mongo_storage from '@powersync/service-module-mongodb-storage';
|
|
3
3
|
|
|
4
|
+
import * as types from '@module/types/types.js';
|
|
4
5
|
import { env } from './env.js';
|
|
5
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
6
|
-
import { connectMongo } from '@core-tests/util.js';
|
|
7
|
-
import * as mongo from 'mongodb';
|
|
8
|
-
|
|
9
|
-
// The metrics need to be initialized before they can be used
|
|
10
|
-
await Metrics.initialise({
|
|
11
|
-
disable_telemetry_sharing: true,
|
|
12
|
-
powersync_instance_id: 'test',
|
|
13
|
-
internal_metrics_endpoint: 'unused.for.tests.com'
|
|
14
|
-
});
|
|
15
|
-
Metrics.getInstance().resetCounters();
|
|
16
6
|
|
|
17
7
|
export const TEST_URI = env.MONGO_TEST_DATA_URL;
|
|
18
8
|
|
|
@@ -21,20 +11,10 @@ export const TEST_CONNECTION_OPTIONS = types.normalizeConnectionConfig({
|
|
|
21
11
|
uri: TEST_URI
|
|
22
12
|
});
|
|
23
13
|
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// None of the PG tests insert data into this collection, so it was never created
|
|
30
|
-
if (!(await db.db.listCollections({ name: db.bucket_parameters.collectionName }).hasNext())) {
|
|
31
|
-
await db.db.createCollection('bucket_parameters');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
await db.clear();
|
|
35
|
-
|
|
36
|
-
return new MongoBucketStorage(db, { slot_name_prefix: 'test_' });
|
|
37
|
-
};
|
|
14
|
+
export const INITIALIZED_MONGO_STORAGE_FACTORY = mongo_storage.MongoTestStorageFactoryGenerator({
|
|
15
|
+
url: env.MONGO_TEST_URL,
|
|
16
|
+
isCI: env.CI
|
|
17
|
+
});
|
|
38
18
|
|
|
39
19
|
export async function clearTestDb(db: mongo.Db) {
|
|
40
20
|
await db.dropDatabase();
|
package/test/tsconfig.json
CHANGED