@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/api/MongoRouteAPIAdapter.d.ts +1 -1
  3. package/dist/api/MongoRouteAPIAdapter.js +6 -5
  4. package/dist/api/MongoRouteAPIAdapter.js.map +1 -1
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +3 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/module/MongoModule.d.ts +0 -1
  9. package/dist/module/MongoModule.js +4 -6
  10. package/dist/module/MongoModule.js.map +1 -1
  11. package/dist/replication/ChangeStream.d.ts +1 -1
  12. package/dist/replication/ChangeStream.js +3 -3
  13. package/dist/replication/ChangeStream.js.map +1 -1
  14. package/dist/replication/ChangeStreamReplicationJob.js +2 -2
  15. package/dist/replication/ChangeStreamReplicationJob.js.map +1 -1
  16. package/dist/replication/MongoManager.d.ts +1 -1
  17. package/dist/replication/MongoManager.js +1 -1
  18. package/dist/replication/MongoManager.js.map +1 -1
  19. package/dist/replication/MongoRelation.d.ts +1 -1
  20. package/dist/replication/MongoRelation.js +16 -6
  21. package/dist/replication/MongoRelation.js.map +1 -1
  22. package/dist/types/types.d.ts +16 -19
  23. package/dist/types/types.js +4 -21
  24. package/dist/types/types.js.map +1 -1
  25. package/package.json +11 -9
  26. package/src/api/MongoRouteAPIAdapter.ts +7 -6
  27. package/src/index.ts +3 -0
  28. package/src/module/MongoModule.ts +4 -7
  29. package/src/replication/ChangeStream.ts +3 -3
  30. package/src/replication/ChangeStreamReplicationJob.ts +3 -4
  31. package/src/replication/MongoManager.ts +2 -1
  32. package/src/replication/MongoRelation.ts +16 -7
  33. package/src/types/types.ts +8 -27
  34. package/test/src/change_stream.test.ts +38 -38
  35. package/test/src/change_stream_utils.ts +7 -6
  36. package/test/src/env.ts +1 -0
  37. package/test/src/mongo_test.test.ts +74 -14
  38. package/test/src/setup.ts +4 -1
  39. package/test/src/slow_tests.test.ts +11 -16
  40. package/test/src/util.ts +7 -27
  41. package/test/tsconfig.json +3 -0
  42. package/tsconfig.json +6 -0
  43. package/tsconfig.tsbuildinfo +1 -1
  44. 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
- type StorageFactory = () => Promise<BucketStorageFactory>;
4
+ import { mongo } from '@powersync/lib-service-mongodb';
5
+ import { storage } from '@powersync/service-core';
10
6
 
11
- const BASIC_SYNC_RULES = `
12
- bucket_definitions:
13
- global:
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(MONGO_STORAGE_FACTORY);
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: StorageFactory) {
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) => JSON.parse(d.data! as string).description.startsWith('updated')).length;
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 * as types from '@module/types/types.js';
2
- import { BucketStorageFactory, Metrics, MongoBucketStorage, OpId } from '@powersync/service-core';
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 type StorageFactory = () => Promise<BucketStorageFactory>;
25
-
26
- export const INITIALIZED_MONGO_STORAGE_FACTORY: StorageFactory = async () => {
27
- const db = await connectMongo();
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();
@@ -23,6 +23,9 @@
23
23
  },
24
24
  {
25
25
  "path": "../../../packages/service-core/"
26
+ },
27
+ {
28
+ "path": "../../../packages/service-core-tests/"
26
29
  }
27
30
  ]
28
31
  }
package/tsconfig.json CHANGED
@@ -23,6 +23,12 @@
23
23
  },
24
24
  {
25
25
  "path": "../../libs/lib-services"
26
+ },
27
+ {
28
+ "path": "../../libs/lib-mongodb"
29
+ },
30
+ {
31
+ "path": "../module-mongodb-storage"
26
32
  }
27
33
  ]
28
34
  }