@powersync/service-module-mongodb-storage 0.0.0-dev-20250819134004 → 0.0.0-dev-20250825132649

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 (62) hide show
  1. package/CHANGELOG.md +9 -7
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/migrations/db/migrations/1752661449910-connection-reporting.js +36 -0
  6. package/dist/migrations/db/migrations/1752661449910-connection-reporting.js.map +1 -0
  7. package/dist/storage/MongoBucketStorage.js +1 -1
  8. package/dist/storage/MongoBucketStorage.js.map +1 -1
  9. package/dist/storage/MongoReportStorage.d.ts +2 -3
  10. package/dist/storage/MongoReportStorage.js +8 -24
  11. package/dist/storage/MongoReportStorage.js.map +1 -1
  12. package/dist/storage/implementation/MongoBucketBatch.js +1 -1
  13. package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
  14. package/dist/storage/implementation/MongoSyncBucketStorage.js +1 -1
  15. package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
  16. package/dist/storage/implementation/PersistedBatch.js +1 -1
  17. package/dist/storage/implementation/PersistedBatch.js.map +1 -1
  18. package/dist/storage/implementation/db.d.ts +2 -2
  19. package/dist/storage/implementation/db.js +6 -6
  20. package/dist/storage/implementation/db.js.map +1 -1
  21. package/dist/storage/storage-index.d.ts +2 -2
  22. package/dist/storage/storage-index.js +2 -2
  23. package/dist/storage/storage-index.js.map +1 -1
  24. package/dist/utils/test-utils.d.ts +11 -0
  25. package/dist/utils/test-utils.js +40 -0
  26. package/dist/utils/test-utils.js.map +1 -0
  27. package/dist/{storage/implementation → utils}/util.d.ts +1 -6
  28. package/dist/{storage/implementation → utils}/util.js +0 -15
  29. package/dist/utils/util.js.map +1 -0
  30. package/dist/utils/utils-index.d.ts +2 -0
  31. package/dist/utils/utils-index.js +3 -0
  32. package/dist/utils/utils-index.js.map +1 -0
  33. package/package.json +8 -8
  34. package/src/index.ts +1 -0
  35. package/src/migrations/db/migrations/{1752661449910-sdk-reporting.ts → 1752661449910-connection-reporting.ts} +10 -22
  36. package/src/storage/MongoBucketStorage.ts +1 -1
  37. package/src/storage/MongoReportStorage.ts +11 -28
  38. package/src/storage/implementation/MongoBucketBatch.ts +1 -1
  39. package/src/storage/implementation/MongoSyncBucketStorage.ts +1 -1
  40. package/src/storage/implementation/PersistedBatch.ts +1 -1
  41. package/src/storage/implementation/db.ts +6 -6
  42. package/src/storage/storage-index.ts +2 -2
  43. package/src/utils/test-utils.ts +55 -0
  44. package/src/{storage/implementation → utils}/util.ts +1 -17
  45. package/src/utils/utils-index.ts +2 -0
  46. package/test/src/__snapshots__/{sdk-report-storage.test.ts.snap → connection-report-storage.test.ts.snap} +59 -29
  47. package/test/src/__snapshots__/storage_sync.test.ts.snap +12 -11
  48. package/test/src/{sdk-report-storage.test.ts → connection-report-storage.test.ts} +26 -38
  49. package/test/src/util.ts +3 -5
  50. package/tsconfig.tsbuildinfo +1 -1
  51. package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js +0 -48
  52. package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js.map +0 -1
  53. package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.d.ts +0 -7
  54. package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.js +0 -13
  55. package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.js.map +0 -1
  56. package/dist/storage/implementation/MongoTestStorageFactoryGenerator.d.ts +0 -7
  57. package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js +0 -18
  58. package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js.map +0 -1
  59. package/dist/storage/implementation/util.js.map +0 -1
  60. package/src/storage/implementation/MongoTestReportStorageFactoryGenerator.ts +0 -22
  61. package/src/storage/implementation/MongoTestStorageFactoryGenerator.ts +0 -28
  62. /package/dist/migrations/db/migrations/{1752661449910-sdk-reporting.d.ts → 1752661449910-connection-reporting.d.ts} +0 -0
@@ -21,7 +21,7 @@ export declare class PowerSyncMongo {
21
21
  readonly locks: mongo.Collection<lib_mongo.locks.Lock>;
22
22
  readonly bucket_state: mongo.Collection<BucketStateDocument>;
23
23
  readonly checkpoint_events: mongo.Collection<CheckpointEventDocument>;
24
- readonly sdk_report_events: mongo.Collection<ClientConnectionDocument>;
24
+ readonly connection_report_events: mongo.Collection<ClientConnectionDocument>;
25
25
  readonly client: mongo.MongoClient;
26
26
  readonly db: mongo.Db;
27
27
  constructor(client: mongo.MongoClient, options?: PowerSyncMongoOptions);
@@ -48,6 +48,6 @@ export declare class PowerSyncMongo {
48
48
  /**
49
49
  * Only use in migrations and tests.
50
50
  */
51
- createSdkReportingCollection(): Promise<void>;
51
+ createConnectionReportingCollection(): Promise<void>;
52
52
  }
53
53
  export declare function createPowerSyncMongo(config: MongoStorageConfig, options?: lib_mongo.MongoConnectionOptions): PowerSyncMongo;
@@ -13,7 +13,7 @@ export class PowerSyncMongo {
13
13
  locks;
14
14
  bucket_state;
15
15
  checkpoint_events;
16
- sdk_report_events;
16
+ connection_report_events;
17
17
  client;
18
18
  db;
19
19
  constructor(client, options) {
@@ -34,7 +34,7 @@ export class PowerSyncMongo {
34
34
  this.locks = this.db.collection('locks');
35
35
  this.bucket_state = this.db.collection('bucket_state');
36
36
  this.checkpoint_events = this.db.collection('checkpoint_events');
37
- this.sdk_report_events = this.db.collection('sdk_report_events');
37
+ this.connection_report_events = this.db.collection('connection_report_events');
38
38
  }
39
39
  /**
40
40
  * Clear all collections.
@@ -51,7 +51,7 @@ export class PowerSyncMongo {
51
51
  await this.locks.deleteMany({});
52
52
  await this.bucket_state.deleteMany({});
53
53
  await this.custom_write_checkpoints.deleteMany({});
54
- await this.sdk_report_events.deleteMany({});
54
+ await this.connection_report_events.deleteMany({});
55
55
  }
56
56
  /**
57
57
  * Drop the entire database.
@@ -101,15 +101,15 @@ export class PowerSyncMongo {
101
101
  /**
102
102
  * Only use in migrations and tests.
103
103
  */
104
- async createSdkReportingCollection() {
104
+ async createConnectionReportingCollection() {
105
105
  const existingCollections = await this.db
106
- .listCollections({ name: 'sdk_report_events' }, { nameOnly: false })
106
+ .listCollections({ name: 'connection_report_events' }, { nameOnly: false })
107
107
  .toArray();
108
108
  const collection = existingCollections[0];
109
109
  if (collection != null) {
110
110
  return;
111
111
  }
112
- await this.db.createCollection('sdk_report_events');
112
+ await this.db.createCollection('connection_report_events');
113
113
  }
114
114
  }
115
115
  export function createPowerSyncMongo(config, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"db.js","sourceRoot":"","sources":["../../../src/storage/implementation/db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAyBrE,MAAM,OAAO,cAAc;IAChB,YAAY,CAAwC;IACpD,WAAW,CAAuC;IAClD,iBAAiB,CAA4C;IAC7D,cAAc,CAAuC;IACrD,UAAU,CAAqC;IAC/C,aAAa,CAAwC;IACrD,wBAAwB,CAAkD;IAC1E,iBAAiB,CAA4C;IAC7D,QAAQ,CAAqC;IAC7C,KAAK,CAAyC;IAC9C,YAAY,CAAwC;IACpD,iBAAiB,CAA4C;IAC7D,iBAAiB,CAA6C;IAE9D,MAAM,CAAoB;IAC1B,EAAE,CAAW;IAEtB,YAAY,MAAyB,EAAE,OAA+B;QACpE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE;YACtC,GAAG,OAAO,CAAC,iCAAiC;SAC7C,CAAC,CAAC;QACH,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC,UAAU,CAAsB,cAAc,CAAC,CAAC;QACvE,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;QAChD,IA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QACb,MAAM,UAAU,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QACD,MAAM,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,0BAA0B,CAAC,CAAC;IAC7D,CAAC;CACF;AAED,MAAM,UAAU,oBAAoB,CAAC,MAA0B,EAAE,OAA0C;IACzG,OAAO,IAAI,cAAc,CACvB,SAAS,CAAC,iBAAiB,CAAC,MAAM,EAAE;QAClC,gBAAgB,EAAE,iBAAiB;QACnC,GAAG,OAAO;KACX,CAAC,EACF,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAC9B,CAAC;AACJ,CAAC"}
@@ -7,9 +7,9 @@ export * from './implementation/MongoPersistedSyncRulesContent.js';
7
7
  export * from './implementation/MongoStorageProvider.js';
8
8
  export * from './implementation/MongoSyncBucketStorage.js';
9
9
  export * from './implementation/MongoSyncRulesLock.js';
10
- export * from './implementation/MongoTestStorageFactoryGenerator.js';
11
10
  export * from './implementation/OperationBatch.js';
12
11
  export * from './implementation/PersistedBatch.js';
13
- export * from './implementation/util.js';
12
+ export * from '../utils/util.js';
14
13
  export * from './MongoBucketStorage.js';
15
14
  export * from './MongoReportStorage.js';
15
+ export * as test_utils from '../utils/test-utils.js';
@@ -7,10 +7,10 @@ export * from './implementation/MongoPersistedSyncRulesContent.js';
7
7
  export * from './implementation/MongoStorageProvider.js';
8
8
  export * from './implementation/MongoSyncBucketStorage.js';
9
9
  export * from './implementation/MongoSyncRulesLock.js';
10
- export * from './implementation/MongoTestStorageFactoryGenerator.js';
11
10
  export * from './implementation/OperationBatch.js';
12
11
  export * from './implementation/PersistedBatch.js';
13
- export * from './implementation/util.js';
12
+ export * from '../utils/util.js';
14
13
  export * from './MongoBucketStorage.js';
15
14
  export * from './MongoReportStorage.js';
15
+ export * as test_utils from '../utils/test-utils.js';
16
16
  //# sourceMappingURL=storage-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oDAAoD,CAAC;AACnE,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,sDAAsD,CAAC;AACrE,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oDAAoD,CAAC;AACnE,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { PowerSyncMongo } from '../storage/implementation/db.js';
2
+ import { TestStorageOptions } from '@powersync/service-core';
3
+ import { MongoReportStorage } from '../storage/MongoReportStorage.js';
4
+ import { MongoBucketStorage } from '../storage/MongoBucketStorage.js';
5
+ export type MongoTestStorageOptions = {
6
+ url: string;
7
+ isCI: boolean;
8
+ };
9
+ export declare function mongoTestStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions): (options?: TestStorageOptions) => Promise<MongoBucketStorage>;
10
+ export declare function mongoTestReportStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions): (options?: TestStorageOptions) => Promise<MongoReportStorage>;
11
+ export declare const connectMongoForTests: (url: string, isCI: boolean) => PowerSyncMongo;
@@ -0,0 +1,40 @@
1
+ import { mongo } from '@powersync/lib-service-mongodb';
2
+ import { PowerSyncMongo } from '../storage/implementation/db.js';
3
+ import { MongoReportStorage } from '../storage/MongoReportStorage.js';
4
+ import { MongoBucketStorage } from '../storage/MongoBucketStorage.js';
5
+ export function mongoTestStorageFactoryGenerator(factoryOptions) {
6
+ return async (options) => {
7
+ const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI);
8
+ // None of the tests insert data into this collection, so it was never created
9
+ if (!(await db.db.listCollections({ name: db.bucket_parameters.collectionName }).hasNext())) {
10
+ await db.db.createCollection('bucket_parameters');
11
+ }
12
+ // Full migrations are not currently run for tests, so we manually create this
13
+ await db.createCheckpointEventsCollection();
14
+ if (!options?.doNotClear) {
15
+ await db.clear();
16
+ }
17
+ return new MongoBucketStorage(db, { slot_name_prefix: 'test_' });
18
+ };
19
+ }
20
+ export function mongoTestReportStorageFactoryGenerator(factoryOptions) {
21
+ return async (options) => {
22
+ const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI);
23
+ await db.createConnectionReportingCollection();
24
+ if (!options?.doNotClear) {
25
+ await db.clear();
26
+ }
27
+ return new MongoReportStorage(db);
28
+ };
29
+ }
30
+ export const connectMongoForTests = (url, isCI) => {
31
+ // Short timeout for tests, to fail fast when the server is not available.
32
+ // Slightly longer timeouts for CI, to avoid arbitrary test failures
33
+ const client = new mongo.MongoClient(url, {
34
+ connectTimeoutMS: isCI ? 15_000 : 5_000,
35
+ socketTimeoutMS: isCI ? 15_000 : 5_000,
36
+ serverSelectionTimeoutMS: isCI ? 15_000 : 2_500
37
+ });
38
+ return new PowerSyncMongo(client);
39
+ };
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zE,MAAM,EAAE,CAAC,mCAAmC,EAAE,CAAC;QAE/C,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;YACzB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,kBAAkB,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,IAAa,EAAE,EAAE;IACjE,0EAA0E;IAC1E,oEAAoE;IACpE,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACxC,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;QACvC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;QACtC,wBAAwB,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;KAChD,CAAC,CAAC;IACH,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC,CAAC"}
@@ -1,8 +1,7 @@
1
1
  import * as bson from 'bson';
2
2
  import { mongo } from '@powersync/lib-service-mongodb';
3
3
  import { storage, utils } from '@powersync/service-core';
4
- import { PowerSyncMongo } from './db.js';
5
- import { BucketDataDocument } from './models.js';
4
+ import { BucketDataDocument } from '../storage/implementation/models.js';
6
5
  export declare function idPrefixFilter<T>(prefix: Partial<T>, rest: (keyof T)[]): mongo.Condition<T>;
7
6
  export declare function generateSlotName(prefix: string, sync_rules_id: number): string;
8
7
  /**
@@ -22,8 +21,4 @@ export declare function readSingleBatch<T>(cursor: mongo.FindCursor<T>): Promise
22
21
  }>;
23
22
  export declare function mapOpEntry(row: BucketDataDocument): utils.OplogEntry;
24
23
  export declare function replicaIdToSubkey(table: bson.ObjectId, id: storage.ReplicaId): string;
25
- /**
26
- * Helper for unit tests
27
- */
28
- export declare const connectMongoForTests: (url: string, isCI: boolean) => PowerSyncMongo;
29
24
  export declare function setSessionSnapshotTime(session: mongo.ClientSession, time: bson.Timestamp): void;
@@ -1,9 +1,7 @@
1
1
  import * as bson from 'bson';
2
2
  import * as crypto from 'crypto';
3
3
  import * as uuid from 'uuid';
4
- import { mongo } from '@powersync/lib-service-mongodb';
5
4
  import { storage, utils } from '@powersync/service-core';
6
- import { PowerSyncMongo } from './db.js';
7
5
  import { ServiceAssertionError } from '@powersync/lib-services-framework';
8
6
  export function idPrefixFilter(prefix, rest) {
9
7
  let filter = {
@@ -96,19 +94,6 @@ export function replicaIdToSubkey(table, id) {
96
94
  return uuid.v5(repr, utils.ID_NAMESPACE);
97
95
  }
98
96
  }
99
- /**
100
- * Helper for unit tests
101
- */
102
- export const connectMongoForTests = (url, isCI) => {
103
- // Short timeout for tests, to fail fast when the server is not available.
104
- // Slightly longer timeouts for CI, to avoid arbitrary test failures
105
- const client = new mongo.MongoClient(url, {
106
- connectTimeoutMS: isCI ? 15_000 : 5_000,
107
- socketTimeoutMS: isCI ? 15_000 : 5_000,
108
- serverSelectionTimeoutMS: isCI ? 15_000 : 2_500
109
- });
110
- return new PowerSyncMongo(client);
111
- };
112
97
  export function setSessionSnapshotTime(session, time) {
113
98
  // This is a workaround for the lack of direct support for snapshot reads in the MongoDB driver.
114
99
  if (!session.snapshotEnabled) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/utils/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,MAAM,UAAU,cAAc,CAAI,MAAkB,EAAE,IAAiB;IACrE,I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,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAA4B,EAAE,IAAoB;IACvF,gGAAgG;IAChG,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;QAC7B,MAAM,IAAI,qBAAqB,CAAC,oCAAoC,CAAC,CAAC;IACxE,CAAC;IACD,IAAK,OAAe,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC;QACzC,OAAe,CAAC,YAAY,GAAG,IAAI,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,qBAAqB,CAAC,qCAAqC,CAAC,CAAC;IACzE,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * as test_utils from './test-utils.js';
2
+ export * from './util.js';
@@ -0,0 +1,3 @@
1
+ export * as test_utils from './test-utils.js';
2
+ export * from './util.js';
3
+ //# sourceMappingURL=utils-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-index.js","sourceRoot":"","sources":["../../src/utils/utils-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,cAAc,WAAW,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@powersync/service-module-mongodb-storage",
3
3
  "repository": "https://github.com/powersync-ja/powersync-service",
4
4
  "types": "dist/index.d.ts",
5
- "version": "0.0.0-dev-20250819134004",
5
+ "version": "0.0.0-dev-20250825132649",
6
6
  "main": "dist/index.js",
7
7
  "license": "FSL-1.1-ALv2",
8
8
  "type": "module",
@@ -27,15 +27,15 @@
27
27
  "lru-cache": "^10.2.2",
28
28
  "ts-codec": "^1.3.0",
29
29
  "uuid": "^11.1.0",
30
- "@powersync/lib-service-mongodb": "0.0.0-dev-20250819134004",
31
- "@powersync/lib-services-framework": "0.0.0-dev-20250819134004",
32
- "@powersync/service-core": "0.0.0-dev-20250819134004",
33
- "@powersync/service-types": "0.0.0-dev-20250819134004",
34
- "@powersync/service-jsonbig": "0.0.0-dev-20250819134004",
35
- "@powersync/service-sync-rules": "0.0.0-dev-20250819134004"
30
+ "@powersync/lib-service-mongodb": "0.0.0-dev-20250825132649",
31
+ "@powersync/lib-services-framework": "0.0.0-dev-20250825132649",
32
+ "@powersync/service-core": "0.0.0-dev-20250825132649",
33
+ "@powersync/service-types": "0.0.0-dev-20250825132649",
34
+ "@powersync/service-jsonbig": "0.0.0-dev-20250825132649",
35
+ "@powersync/service-sync-rules": "0.0.0-dev-20250825132649"
36
36
  },
37
37
  "devDependencies": {
38
- "@powersync/service-core-tests": "0.0.0-dev-20250819134004"
38
+ "@powersync/service-core-tests": "0.0.0-dev-20250825132649"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsc -b",
package/src/index.ts CHANGED
@@ -5,3 +5,4 @@ export * as storage from './storage/storage-index.js';
5
5
 
6
6
  export * from './types/types.js';
7
7
  export * as types from './types/types.js';
8
+ export * as utils from './utils/utils-index.js';
@@ -9,34 +9,34 @@ export const up: migrations.PowerSyncMigrationFunction = async (context) => {
9
9
  const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
10
10
 
11
11
  try {
12
- await db.createSdkReportingCollection();
12
+ await db.createConnectionReportingCollection();
13
13
 
14
- await db.sdk_report_events.createIndex(
14
+ await db.connection_report_events.createIndex(
15
15
  {
16
16
  connected_at: 1,
17
17
  jwt_exp: 1,
18
18
  disconnected_at: 1
19
19
  },
20
- { name: 'sdk_list_index' }
20
+ { name: 'connection_list_index' }
21
21
  );
22
22
 
23
- await db.sdk_report_events.createIndex(
23
+ await db.connection_report_events.createIndex(
24
24
  {
25
25
  user_id: 1
26
26
  },
27
- { name: 'sdk_user_id_index' }
27
+ { name: 'connection_user_id_index' }
28
28
  );
29
- await db.sdk_report_events.createIndex(
29
+ await db.connection_report_events.createIndex(
30
30
  {
31
31
  client_id: 1
32
32
  },
33
- { name: 'sdk_client_id_index' }
33
+ { name: 'connection_client_id_index' }
34
34
  );
35
- await db.sdk_report_events.createIndex(
35
+ await db.connection_report_events.createIndex(
36
36
  {
37
37
  sdk: 1
38
38
  },
39
- { name: 'sdk_index' }
39
+ { name: 'connection_index' }
40
40
  );
41
41
  } finally {
42
42
  await db.client.close();
@@ -51,19 +51,7 @@ export const down: migrations.PowerSyncMigrationFunction = async (context) => {
51
51
  const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
52
52
 
53
53
  try {
54
- if (await db.sdk_report_events.indexExists('sdk_list_index')) {
55
- await db.sdk_report_events.dropIndex('sdk_list_index');
56
- }
57
- if (await db.sdk_report_events.indexExists('sdk_user_id_index')) {
58
- await db.sdk_report_events.dropIndex('sdk_user_id_index');
59
- }
60
- if (await db.sdk_report_events.indexExists('sdk_client_id_index')) {
61
- await db.sdk_report_events.dropIndex('sdk_client_id_index');
62
- }
63
- if (await db.sdk_report_events.indexExists('sdk_index')) {
64
- await db.sdk_report_events.dropIndex('sdk_index');
65
- }
66
- await db.db.dropCollection('sdk_report_events');
54
+ await db.db.dropCollection('connection_report_events');
67
55
  } finally {
68
56
  await db.client.close();
69
57
  }
@@ -12,7 +12,7 @@ import { PowerSyncMongo } from './implementation/db.js';
12
12
  import { SyncRuleDocument } from './implementation/models.js';
13
13
  import { MongoPersistedSyncRulesContent } from './implementation/MongoPersistedSyncRulesContent.js';
14
14
  import { MongoSyncBucketStorage } from './implementation/MongoSyncBucketStorage.js';
15
- import { generateSlotName } from './implementation/util.js';
15
+ import { generateSlotName } from '../utils/util.js';
16
16
 
17
17
  export class MongoBucketStorage
18
18
  extends BaseObserver<storage.BucketStorageFactoryListener>
@@ -14,7 +14,7 @@ export class MongoReportStorage implements storage.ReportStorage {
14
14
  }
15
15
  async deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void> {
16
16
  const { date } = data;
17
- const result = await this.db.sdk_report_events.deleteMany({
17
+ const result = await this.db.connection_report_events.deleteMany({
18
18
  connected_at: { $lt: date },
19
19
  $or: [
20
20
  { disconnected_at: { $exists: true } },
@@ -23,17 +23,17 @@ export class MongoReportStorage implements storage.ReportStorage {
23
23
  });
24
24
  if (result.deletedCount > 0) {
25
25
  logger.info(
26
- `TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from sdk_report_events.`
26
+ `TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from connection_report_events.`
27
27
  );
28
28
  }
29
29
  }
30
30
 
31
31
  async getClientConnectionReports(
32
32
  data: event_types.ClientConnectionReportRequest
33
- ): Promise<event_types.ClientConnectionReport> {
33
+ ): Promise<event_types.ClientConnectionReportResponse> {
34
34
  const { start, end } = data;
35
- const result = await this.db.sdk_report_events
36
- .aggregate<event_types.ClientConnectionReport>([
35
+ const result = await this.db.connection_report_events
36
+ .aggregate<event_types.ClientConnectionReportResponse>([
37
37
  {
38
38
  $match: {
39
39
  connected_at: { $lte: end, $gte: start }
@@ -48,7 +48,7 @@ export class MongoReportStorage implements storage.ReportStorage {
48
48
 
49
49
  async reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void> {
50
50
  const updateFilter = this.updateDocFilter(data.user_id, data.client_id!);
51
- await this.db.sdk_report_events.findOneAndUpdate(
51
+ await this.db.connection_report_events.findOneAndUpdate(
52
52
  updateFilter,
53
53
  {
54
54
  $set: data,
@@ -63,7 +63,7 @@ export class MongoReportStorage implements storage.ReportStorage {
63
63
  }
64
64
  async reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void> {
65
65
  const { connected_at, user_id, client_id } = data;
66
- await this.db.sdk_report_events.findOneAndUpdate(
66
+ await this.db.connection_report_events.findOneAndUpdate(
67
67
  {
68
68
  client_id,
69
69
  user_id,
@@ -79,15 +79,13 @@ export class MongoReportStorage implements storage.ReportStorage {
79
79
  }
80
80
  );
81
81
  }
82
- async getConnectedClients(data: event_types.ClientConnectionsRequest): Promise<event_types.ClientConnectionReport> {
83
- const timeframeFilter = this.listConnectionsDateRange(data);
84
- const result = await this.db.sdk_report_events
85
- .aggregate<event_types.ClientConnectionReport>([
82
+ async getConnectedClients(): Promise<event_types.ClientConnectionReportResponse> {
83
+ const result = await this.db.connection_report_events
84
+ .aggregate<event_types.ClientConnectionReportResponse>([
86
85
  {
87
86
  $match: {
88
87
  disconnected_at: { $exists: false },
89
- jwt_exp: { $gt: new Date() },
90
- ...timeframeFilter
88
+ jwt_exp: { $gt: new Date() }
91
89
  }
92
90
  },
93
91
  this.connectionsFacetPipeline(),
@@ -177,19 +175,4 @@ export class MongoReportStorage implements storage.ReportStorage {
177
175
  }
178
176
  };
179
177
  }
180
-
181
- private listConnectionsDateRange(data: event_types.ClientConnectionsRequest) {
182
- const { range } = data;
183
- if (!range) {
184
- return undefined;
185
- }
186
- const endDate = data.range?.end ? new Date(data.range.end) : new Date();
187
- const startDate = new Date(range.start);
188
- return {
189
- connected_at: {
190
- $lte: endDate,
191
- $gte: startDate
192
- }
193
- };
194
- }
195
178
  }
@@ -28,7 +28,7 @@ import { MongoIdSequence } from './MongoIdSequence.js';
28
28
  import { batchCreateCustomWriteCheckpoints } from './MongoWriteCheckpointAPI.js';
29
29
  import { cacheKey, OperationBatch, RecordOperation } from './OperationBatch.js';
30
30
  import { PersistedBatch } from './PersistedBatch.js';
31
- import { idPrefixFilter } from './util.js';
31
+ import { idPrefixFilter } from '../../utils/util.js';
32
32
 
33
33
  /**
34
34
  * 15MB
@@ -32,7 +32,7 @@ import { BucketDataDocument, BucketDataKey, BucketStateDocument, SourceKey, Sour
32
32
  import { MongoBucketBatch } from './MongoBucketBatch.js';
33
33
  import { MongoCompactor } from './MongoCompactor.js';
34
34
  import { MongoWriteCheckpointAPI } from './MongoWriteCheckpointAPI.js';
35
- import { idPrefixFilter, mapOpEntry, readSingleBatch, setSessionSnapshotTime } from './util.js';
35
+ import { idPrefixFilter, mapOpEntry, readSingleBatch, setSessionSnapshotTime } from '../../utils/util.js';
36
36
  import { MongoParameterCompactor } from './MongoParameterCompactor.js';
37
37
 
38
38
  export class MongoSyncBucketStorage
@@ -16,7 +16,7 @@ import {
16
16
  CurrentDataDocument,
17
17
  SourceKey
18
18
  } from './models.js';
19
- import { replicaIdToSubkey } from './util.js';
19
+ import { replicaIdToSubkey } from '../../utils/util.js';
20
20
 
21
21
  /**
22
22
  * Maximum size of operations we write in a single transaction.
@@ -38,7 +38,7 @@ export class PowerSyncMongo {
38
38
  readonly locks: mongo.Collection<lib_mongo.locks.Lock>;
39
39
  readonly bucket_state: mongo.Collection<BucketStateDocument>;
40
40
  readonly checkpoint_events: mongo.Collection<CheckpointEventDocument>;
41
- readonly sdk_report_events: mongo.Collection<ClientConnectionDocument>;
41
+ readonly connection_report_events: mongo.Collection<ClientConnectionDocument>;
42
42
 
43
43
  readonly client: mongo.MongoClient;
44
44
  readonly db: mongo.Db;
@@ -63,7 +63,7 @@ export class PowerSyncMongo {
63
63
  this.locks = this.db.collection('locks');
64
64
  this.bucket_state = this.db.collection('bucket_state');
65
65
  this.checkpoint_events = this.db.collection('checkpoint_events');
66
- this.sdk_report_events = this.db.collection('sdk_report_events');
66
+ this.connection_report_events = this.db.collection('connection_report_events');
67
67
  }
68
68
 
69
69
  /**
@@ -81,7 +81,7 @@ export class PowerSyncMongo {
81
81
  await this.locks.deleteMany({});
82
82
  await this.bucket_state.deleteMany({});
83
83
  await this.custom_write_checkpoints.deleteMany({});
84
- await this.sdk_report_events.deleteMany({});
84
+ await this.connection_report_events.deleteMany({});
85
85
  }
86
86
 
87
87
  /**
@@ -135,15 +135,15 @@ export class PowerSyncMongo {
135
135
  /**
136
136
  * Only use in migrations and tests.
137
137
  */
138
- async createSdkReportingCollection() {
138
+ async createConnectionReportingCollection() {
139
139
  const existingCollections = await this.db
140
- .listCollections({ name: 'sdk_report_events' }, { nameOnly: false })
140
+ .listCollections({ name: 'connection_report_events' }, { nameOnly: false })
141
141
  .toArray();
142
142
  const collection = existingCollections[0];
143
143
  if (collection != null) {
144
144
  return;
145
145
  }
146
- await this.db.createCollection('sdk_report_events');
146
+ await this.db.createCollection('connection_report_events');
147
147
  }
148
148
  }
149
149
 
@@ -7,9 +7,9 @@ export * from './implementation/MongoPersistedSyncRulesContent.js';
7
7
  export * from './implementation/MongoStorageProvider.js';
8
8
  export * from './implementation/MongoSyncBucketStorage.js';
9
9
  export * from './implementation/MongoSyncRulesLock.js';
10
- export * from './implementation/MongoTestStorageFactoryGenerator.js';
11
10
  export * from './implementation/OperationBatch.js';
12
11
  export * from './implementation/PersistedBatch.js';
13
- export * from './implementation/util.js';
12
+ export * from '../utils/util.js';
14
13
  export * from './MongoBucketStorage.js';
15
14
  export * from './MongoReportStorage.js';
15
+ export * as test_utils from '../utils/test-utils.js';
@@ -0,0 +1,55 @@
1
+ import { mongo } from '@powersync/lib-service-mongodb';
2
+ import { PowerSyncMongo } from '../storage/implementation/db.js';
3
+ import { TestStorageOptions } from '@powersync/service-core';
4
+ import { MongoReportStorage } from '../storage/MongoReportStorage.js';
5
+ import { MongoBucketStorage } from '../storage/MongoBucketStorage.js';
6
+
7
+ export type MongoTestStorageOptions = {
8
+ url: string;
9
+ isCI: boolean;
10
+ };
11
+
12
+ export function mongoTestStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions) {
13
+ return async (options?: TestStorageOptions) => {
14
+ const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI);
15
+
16
+ // None of the tests insert data into this collection, so it was never created
17
+ if (!(await db.db.listCollections({ name: db.bucket_parameters.collectionName }).hasNext())) {
18
+ await db.db.createCollection('bucket_parameters');
19
+ }
20
+
21
+ // Full migrations are not currently run for tests, so we manually create this
22
+ await db.createCheckpointEventsCollection();
23
+
24
+ if (!options?.doNotClear) {
25
+ await db.clear();
26
+ }
27
+
28
+ return new MongoBucketStorage(db, { slot_name_prefix: 'test_' });
29
+ };
30
+ }
31
+
32
+ export function mongoTestReportStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions) {
33
+ return async (options?: TestStorageOptions) => {
34
+ const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI);
35
+
36
+ await db.createConnectionReportingCollection();
37
+
38
+ if (!options?.doNotClear) {
39
+ await db.clear();
40
+ }
41
+
42
+ return new MongoReportStorage(db);
43
+ };
44
+ }
45
+
46
+ export const connectMongoForTests = (url: string, isCI: boolean) => {
47
+ // Short timeout for tests, to fail fast when the server is not available.
48
+ // Slightly longer timeouts for CI, to avoid arbitrary test failures
49
+ const client = new mongo.MongoClient(url, {
50
+ connectTimeoutMS: isCI ? 15_000 : 5_000,
51
+ socketTimeoutMS: isCI ? 15_000 : 5_000,
52
+ serverSelectionTimeoutMS: isCI ? 15_000 : 2_500
53
+ });
54
+ return new PowerSyncMongo(client);
55
+ };
@@ -3,9 +3,7 @@ import * as crypto from 'crypto';
3
3
  import * as uuid from 'uuid';
4
4
  import { mongo } from '@powersync/lib-service-mongodb';
5
5
  import { storage, utils } from '@powersync/service-core';
6
-
7
- import { PowerSyncMongo } from './db.js';
8
- import { BucketDataDocument } from './models.js';
6
+ import { BucketDataDocument } from '../storage/implementation/models.js';
9
7
  import { ServiceAssertionError } from '@powersync/lib-services-framework';
10
8
 
11
9
  export function idPrefixFilter<T>(prefix: Partial<T>, rest: (keyof T)[]): mongo.Condition<T> {
@@ -104,20 +102,6 @@ export function replicaIdToSubkey(table: bson.ObjectId, id: storage.ReplicaId):
104
102
  }
105
103
  }
106
104
 
107
- /**
108
- * Helper for unit tests
109
- */
110
- export const connectMongoForTests = (url: string, isCI: boolean) => {
111
- // Short timeout for tests, to fail fast when the server is not available.
112
- // Slightly longer timeouts for CI, to avoid arbitrary test failures
113
- const client = new mongo.MongoClient(url, {
114
- connectTimeoutMS: isCI ? 15_000 : 5_000,
115
- socketTimeoutMS: isCI ? 15_000 : 5_000,
116
- serverSelectionTimeoutMS: isCI ? 15_000 : 2_500
117
- });
118
- return new PowerSyncMongo(client);
119
- };
120
-
121
105
  export function setSessionSnapshotTime(session: mongo.ClientSession, time: bson.Timestamp) {
122
106
  // This is a workaround for the lack of direct support for snapshot reads in the MongoDB driver.
123
107
  if (!session.snapshotEnabled) {
@@ -0,0 +1,2 @@
1
+ export * as test_utils from './test-utils.js';
2
+ export * from './util.js';