@powersync/service-module-mongodb-storage 0.0.0-dev-20250818104041 → 0.0.0-dev-20250820110726
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 +8 -7
- package/dist/migrations/db/migrations/1752661449910-connection-reporting.js +48 -0
- package/dist/migrations/db/migrations/1752661449910-connection-reporting.js.map +1 -0
- package/dist/storage/MongoReportStorage.d.ts +7 -7
- package/dist/storage/MongoReportStorage.js +17 -17
- package/dist/storage/MongoReportStorage.js.map +1 -1
- package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.js +1 -1
- package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +3 -3
- package/dist/storage/implementation/db.js +6 -6
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +1 -1
- package/package.json +8 -8
- package/src/migrations/db/migrations/1752661449910-connection-reporting.ts +70 -0
- package/src/storage/MongoReportStorage.ts +22 -20
- package/src/storage/implementation/MongoTestReportStorageFactoryGenerator.ts +1 -1
- package/src/storage/implementation/db.ts +7 -7
- package/src/storage/implementation/models.ts +1 -1
- package/test/src/__snapshots__/{sdk-report-storage.test.ts.snap → connection-report-storage.test.ts.snap} +32 -32
- package/test/src/__snapshots__/storage_sync.test.ts.snap +197 -0
- package/test/src/{sdk-report-storage.test.ts → connection-report-storage.test.ts} +24 -24
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js +0 -48
- package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js.map +0 -1
- package/src/migrations/db/migrations/1752661449910-sdk-reporting.ts +0 -70
- /package/dist/migrations/db/migrations/{1752661449910-sdk-reporting.d.ts → 1752661449910-connection-reporting.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @powersync/service-module-mongodb-storage
|
|
2
2
|
|
|
3
|
-
## 0.0.0-dev-
|
|
3
|
+
## 0.0.0-dev-20250820110726
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
@@ -10,17 +10,18 @@
|
|
|
10
10
|
- 060b829: Update license abbreviation to FSL-1.1-ALv2.
|
|
11
11
|
- d49bebe: - Hooked up the MySQL binlog heartbeat events with the bucket batch keepalive mechanism.
|
|
12
12
|
Heartbeat events will now update the latest keepalive timestamp in the sync rules.
|
|
13
|
+
- Updated dependencies [d2be184]
|
|
13
14
|
- Updated dependencies [f1d187b]
|
|
14
15
|
- Updated dependencies [0fad466]
|
|
15
16
|
- Updated dependencies [a700ec9]
|
|
16
17
|
- Updated dependencies [060b829]
|
|
17
18
|
- Updated dependencies [d49bebe]
|
|
18
|
-
- @powersync/service-
|
|
19
|
-
- @powersync/service-
|
|
20
|
-
- @powersync/
|
|
21
|
-
- @powersync/
|
|
22
|
-
- @powersync/lib-service-mongodb@0.0.0-dev-
|
|
23
|
-
- @powersync/service-jsonbig@0.0.0-dev-
|
|
19
|
+
- @powersync/service-sync-rules@0.0.0-dev-20250820110726
|
|
20
|
+
- @powersync/service-core@0.0.0-dev-20250820110726
|
|
21
|
+
- @powersync/service-types@0.0.0-dev-20250820110726
|
|
22
|
+
- @powersync/lib-services-framework@0.0.0-dev-20250820110726
|
|
23
|
+
- @powersync/lib-service-mongodb@0.0.0-dev-20250820110726
|
|
24
|
+
- @powersync/service-jsonbig@0.0.0-dev-20250820110726
|
|
24
25
|
|
|
25
26
|
## 0.11.0
|
|
26
27
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as storage from '../../../storage/storage-index.js';
|
|
2
|
+
export const up = async (context) => {
|
|
3
|
+
const { service_context: { configuration } } = context;
|
|
4
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
5
|
+
try {
|
|
6
|
+
await db.createConnectionReportingCollection();
|
|
7
|
+
await db.connection_report_events.createIndex({
|
|
8
|
+
connected_at: 1,
|
|
9
|
+
jwt_exp: 1,
|
|
10
|
+
disconnected_at: 1
|
|
11
|
+
}, { name: 'connection_list_index' });
|
|
12
|
+
await db.connection_report_events.createIndex({
|
|
13
|
+
user_id: 1
|
|
14
|
+
}, { name: 'connection_user_id_index' });
|
|
15
|
+
await db.connection_report_events.createIndex({
|
|
16
|
+
client_id: 1
|
|
17
|
+
}, { name: 'connection_client_id_index' });
|
|
18
|
+
await db.connection_report_events.createIndex({
|
|
19
|
+
sdk: 1
|
|
20
|
+
}, { name: 'connection_index' });
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
await db.client.close();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const down = async (context) => {
|
|
27
|
+
const { service_context: { configuration } } = context;
|
|
28
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
29
|
+
try {
|
|
30
|
+
if (await db.connection_report_events.indexExists('connection_list_index')) {
|
|
31
|
+
await db.connection_report_events.dropIndex('connection_list_index');
|
|
32
|
+
}
|
|
33
|
+
if (await db.connection_report_events.indexExists('connection_user_id_index')) {
|
|
34
|
+
await db.connection_report_events.dropIndex('connection_user_id_index');
|
|
35
|
+
}
|
|
36
|
+
if (await db.connection_report_events.indexExists('connection_client_id_index')) {
|
|
37
|
+
await db.connection_report_events.dropIndex('connection_client_id_index');
|
|
38
|
+
}
|
|
39
|
+
if (await db.connection_report_events.indexExists('connection_index')) {
|
|
40
|
+
await db.connection_report_events.dropIndex('connection_index');
|
|
41
|
+
}
|
|
42
|
+
await db.db.dropCollection('connection_report_events');
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
await db.client.close();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=1752661449910-connection-reporting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1752661449910-connection-reporting.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1752661449910-connection-reporting.ts"],"names":[],"mappings":"AACA,OA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ACH,IAAI,MAAM,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,CAAC;YAC3E,MAAM,EAAE,CAAC,wBAAwB,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;QACvE,CAAC;QACD,IAAI,MAAM,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAC,0BAA0B,CAAC,EAAE,CAAC;YAC9E,MAAM,EAAE,CAAC,wBAAwB,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,MAAM,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAC,4BAA4B,CAAC,EAAE,CAAC;YAChF,MAAM,EAAE,CAAC,wBAAwB,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,MAAM,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACtE,MAAM,EAAE,CAAC,wBAAwB,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,0BAA0B,CAAC,CAAC;IACzD,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -5,15 +5,15 @@ export declare class MongoReportStorage implements storage.ReportStorage {
|
|
|
5
5
|
private readonly client;
|
|
6
6
|
readonly db: PowerSyncMongo;
|
|
7
7
|
constructor(db: PowerSyncMongo);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void>;
|
|
9
|
+
getClientConnectionReports(data: event_types.ClientConnectionReportRequest): Promise<event_types.ClientConnectionReport>;
|
|
10
|
+
reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void>;
|
|
11
|
+
reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void>;
|
|
12
|
+
getConnectedClients(data: event_types.ClientConnectionsRequest): Promise<event_types.ClientConnectionReport>;
|
|
13
13
|
[Symbol.asyncDispose](): Promise<void>;
|
|
14
14
|
private parseJsDate;
|
|
15
|
-
private
|
|
16
|
-
private
|
|
15
|
+
private connectionsFacetPipeline;
|
|
16
|
+
private connectionsProjectPipeline;
|
|
17
17
|
private updateDocFilter;
|
|
18
18
|
private listConnectionsDateRange;
|
|
19
19
|
}
|
|
@@ -6,9 +6,9 @@ export class MongoReportStorage {
|
|
|
6
6
|
this.client = db.client;
|
|
7
7
|
this.db = db;
|
|
8
8
|
}
|
|
9
|
-
async
|
|
9
|
+
async deleteOldConnectionData(data) {
|
|
10
10
|
const { date } = data;
|
|
11
|
-
const result = await this.db.
|
|
11
|
+
const result = await this.db.connection_report_events.deleteMany({
|
|
12
12
|
connected_at: { $lt: date },
|
|
13
13
|
$or: [
|
|
14
14
|
{ disconnected_at: { $exists: true } },
|
|
@@ -16,27 +16,27 @@ export class MongoReportStorage {
|
|
|
16
16
|
]
|
|
17
17
|
});
|
|
18
18
|
if (result.deletedCount > 0) {
|
|
19
|
-
logger.info(`TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from
|
|
19
|
+
logger.info(`TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from connection_report_events.`);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
async
|
|
22
|
+
async getClientConnectionReports(data) {
|
|
23
23
|
const { start, end } = data;
|
|
24
|
-
const result = await this.db.
|
|
24
|
+
const result = await this.db.connection_report_events
|
|
25
25
|
.aggregate([
|
|
26
26
|
{
|
|
27
27
|
$match: {
|
|
28
28
|
connected_at: { $lte: end, $gte: start }
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
31
|
+
this.connectionsFacetPipeline(),
|
|
32
|
+
this.connectionsProjectPipeline()
|
|
33
33
|
])
|
|
34
34
|
.toArray();
|
|
35
35
|
return result[0];
|
|
36
36
|
}
|
|
37
|
-
async
|
|
37
|
+
async reportClientConnection(data) {
|
|
38
38
|
const updateFilter = this.updateDocFilter(data.user_id, data.client_id);
|
|
39
|
-
await this.db.
|
|
39
|
+
await this.db.connection_report_events.findOneAndUpdate(updateFilter, {
|
|
40
40
|
$set: data,
|
|
41
41
|
$unset: {
|
|
42
42
|
disconnected_at: ''
|
|
@@ -45,9 +45,9 @@ export class MongoReportStorage {
|
|
|
45
45
|
upsert: true
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
async
|
|
48
|
+
async reportClientDisconnection(data) {
|
|
49
49
|
const { connected_at, user_id, client_id } = data;
|
|
50
|
-
await this.db.
|
|
50
|
+
await this.db.connection_report_events.findOneAndUpdate({
|
|
51
51
|
client_id,
|
|
52
52
|
user_id,
|
|
53
53
|
connected_at
|
|
@@ -60,9 +60,9 @@ export class MongoReportStorage {
|
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
async
|
|
63
|
+
async getConnectedClients(data) {
|
|
64
64
|
const timeframeFilter = this.listConnectionsDateRange(data);
|
|
65
|
-
const result = await this.db.
|
|
65
|
+
const result = await this.db.connection_report_events
|
|
66
66
|
.aggregate([
|
|
67
67
|
{
|
|
68
68
|
$match: {
|
|
@@ -71,8 +71,8 @@ export class MongoReportStorage {
|
|
|
71
71
|
...timeframeFilter
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
74
|
+
this.connectionsFacetPipeline(),
|
|
75
|
+
this.connectionsProjectPipeline()
|
|
76
76
|
])
|
|
77
77
|
.toArray();
|
|
78
78
|
return result[0];
|
|
@@ -93,7 +93,7 @@ export class MongoReportStorage {
|
|
|
93
93
|
parsedDate: date
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
connectionsFacetPipeline() {
|
|
97
97
|
return {
|
|
98
98
|
$facet: {
|
|
99
99
|
unique_users: [
|
|
@@ -132,7 +132,7 @@ export class MongoReportStorage {
|
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
connectionsProjectPipeline() {
|
|
136
136
|
return {
|
|
137
137
|
$project: {
|
|
138
138
|
users: { $ifNull: [{ $arrayElemAt: ['$unique_users.count', 0] }, 0] },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,MAAM,OAAO,kBAAkB;IACZ,MAAM,CAAoB;IAC3B,EAAE,CAAiB;IAEnC,YAAY,EAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;QACxB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IACD,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,MAAM,OAAO,kBAAkB;IACZ,MAAM,CAAoB;IAC3B,EAAE,CAAiB;IAEnC,YAAY,EAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;QACxB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IACD,KAAK,CAAC,uBAAuB,CAAC,IAAyC;QACrE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QACtB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,wBAAwB,CAAC,UAAU,CAAC;YAC/D,YAAY,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;YAC3B,GAAG,EAAE;gBACH,EAAE,eAAe,EAAE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,EAAE,KAAK,CAAC;gBAClC,GAAG,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC;aACpC;SACF,CAAC;IACJ,CAAC;IAEO,wBAAwB,CAAC,IAA0C;QACzE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;QACxE,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO;YACL,YAAY,EAAE;gBACZ,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;aAChB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -3,7 +3,7 @@ import { MongoReportStorage } from '../MongoReportStorage.js';
|
|
|
3
3
|
export const MongoTestReportStorageFactoryGenerator = (factoryOptions) => {
|
|
4
4
|
return async (options) => {
|
|
5
5
|
const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI);
|
|
6
|
-
await db.
|
|
6
|
+
await db.createConnectionReportingCollection();
|
|
7
7
|
if (!options?.doNotClear) {
|
|
8
8
|
await db.clear();
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoTestReportStorageFactoryGenerator.js","sourceRoot":"","sources":["../../../src/storage/implementation/MongoTestReportStorageFactoryGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAO9D,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,cAAuC,EAAE,EAAE;IAChG,OAAO,KAAK,EAAE,OAA4B,EAAE,EAAE;QAC5C,MAAM,EAAE,GAAG,oBAAoB,CAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;QAEzE,MAAM,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"MongoTestReportStorageFactoryGenerator.js","sourceRoot":"","sources":["../../../src/storage/implementation/MongoTestReportStorageFactoryGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAO9D,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,cAAuC,EAAE,EAAE;IAChG,OAAO,KAAK,EAAE,OAA4B,EAAE,EAAE;QAC5C,MAAM,EAAE,GAAG,oBAAoB,CAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;QAEzE,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,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
2
|
import { mongo } from '@powersync/lib-service-mongodb';
|
|
3
3
|
import { MongoStorageConfig } from '../../types/types.js';
|
|
4
|
-
import { BucketDataDocument, BucketParameterDocument, BucketStateDocument, CheckpointEventDocument, CurrentDataDocument, CustomWriteCheckpointDocument, IdSequenceDocument, InstanceDocument,
|
|
4
|
+
import { BucketDataDocument, BucketParameterDocument, BucketStateDocument, CheckpointEventDocument, ClientConnectionDocument, CurrentDataDocument, CustomWriteCheckpointDocument, IdSequenceDocument, InstanceDocument, SourceTableDocument, SyncRuleDocument, WriteCheckpointDocument } from './models.js';
|
|
5
5
|
export interface PowerSyncMongoOptions {
|
|
6
6
|
/**
|
|
7
7
|
* Optional - uses the database from the MongoClient connection URI if not specified.
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
|
104
|
+
async createConnectionReportingCollection() {
|
|
105
105
|
const existingCollections = await this.db
|
|
106
|
-
.listCollections({ name: '
|
|
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('
|
|
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,
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../../src/storage/implementation/db.ts"],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vC,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,EAAE;aACtC,eAAe,CAAC,EAAE,IAAI,EAAE,0BAA0B,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;aAC1E,OAAO,EAAE,CAAC;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"}
|
|
@@ -190,5 +190,5 @@ export interface WriteCheckpointDocument {
|
|
|
190
190
|
export interface InstanceDocument {
|
|
191
191
|
_id: string;
|
|
192
192
|
}
|
|
193
|
-
export interface
|
|
193
|
+
export interface ClientConnectionDocument extends event_types.ClientConnection {
|
|
194
194
|
}
|
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-
|
|
5
|
+
"version": "0.0.0-dev-20250820110726",
|
|
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-
|
|
31
|
-
"@powersync/lib-services-framework": "0.0.0-dev-
|
|
32
|
-
"@powersync/service-core": "0.0.0-dev-
|
|
33
|
-
"@powersync/service-types": "0.0.0-dev-
|
|
34
|
-
"@powersync/service-jsonbig": "0.0.0-dev-
|
|
35
|
-
"@powersync/service-sync-rules": "0.0.0-dev-
|
|
30
|
+
"@powersync/lib-service-mongodb": "0.0.0-dev-20250820110726",
|
|
31
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20250820110726",
|
|
32
|
+
"@powersync/service-core": "0.0.0-dev-20250820110726",
|
|
33
|
+
"@powersync/service-types": "0.0.0-dev-20250820110726",
|
|
34
|
+
"@powersync/service-jsonbig": "0.0.0-dev-20250820110726",
|
|
35
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20250820110726"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@powersync/service-core-tests": "0.0.0-dev-
|
|
38
|
+
"@powersync/service-core-tests": "0.0.0-dev-20250820110726"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -b",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { migrations } from '@powersync/service-core';
|
|
2
|
+
import * as storage from '../../../storage/storage-index.js';
|
|
3
|
+
import { MongoStorageConfig } from '../../../types/types.js';
|
|
4
|
+
|
|
5
|
+
export const up: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
6
|
+
const {
|
|
7
|
+
service_context: { configuration }
|
|
8
|
+
} = context;
|
|
9
|
+
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
await db.createConnectionReportingCollection();
|
|
13
|
+
|
|
14
|
+
await db.connection_report_events.createIndex(
|
|
15
|
+
{
|
|
16
|
+
connected_at: 1,
|
|
17
|
+
jwt_exp: 1,
|
|
18
|
+
disconnected_at: 1
|
|
19
|
+
},
|
|
20
|
+
{ name: 'connection_list_index' }
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
await db.connection_report_events.createIndex(
|
|
24
|
+
{
|
|
25
|
+
user_id: 1
|
|
26
|
+
},
|
|
27
|
+
{ name: 'connection_user_id_index' }
|
|
28
|
+
);
|
|
29
|
+
await db.connection_report_events.createIndex(
|
|
30
|
+
{
|
|
31
|
+
client_id: 1
|
|
32
|
+
},
|
|
33
|
+
{ name: 'connection_client_id_index' }
|
|
34
|
+
);
|
|
35
|
+
await db.connection_report_events.createIndex(
|
|
36
|
+
{
|
|
37
|
+
sdk: 1
|
|
38
|
+
},
|
|
39
|
+
{ name: 'connection_index' }
|
|
40
|
+
);
|
|
41
|
+
} finally {
|
|
42
|
+
await db.client.close();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
47
|
+
const {
|
|
48
|
+
service_context: { configuration }
|
|
49
|
+
} = context;
|
|
50
|
+
|
|
51
|
+
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
if (await db.connection_report_events.indexExists('connection_list_index')) {
|
|
55
|
+
await db.connection_report_events.dropIndex('connection_list_index');
|
|
56
|
+
}
|
|
57
|
+
if (await db.connection_report_events.indexExists('connection_user_id_index')) {
|
|
58
|
+
await db.connection_report_events.dropIndex('connection_user_id_index');
|
|
59
|
+
}
|
|
60
|
+
if (await db.connection_report_events.indexExists('connection_client_id_index')) {
|
|
61
|
+
await db.connection_report_events.dropIndex('connection_client_id_index');
|
|
62
|
+
}
|
|
63
|
+
if (await db.connection_report_events.indexExists('connection_index')) {
|
|
64
|
+
await db.connection_report_events.dropIndex('connection_index');
|
|
65
|
+
}
|
|
66
|
+
await db.db.dropCollection('connection_report_events');
|
|
67
|
+
} finally {
|
|
68
|
+
await db.client.close();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -12,9 +12,9 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
12
12
|
this.client = db.client;
|
|
13
13
|
this.db = db;
|
|
14
14
|
}
|
|
15
|
-
async
|
|
15
|
+
async deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void> {
|
|
16
16
|
const { date } = data;
|
|
17
|
-
const result = await this.db.
|
|
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,30 +23,32 @@ 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
|
|
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
|
-
async
|
|
31
|
+
async getClientConnectionReports(
|
|
32
|
+
data: event_types.ClientConnectionReportRequest
|
|
33
|
+
): Promise<event_types.ClientConnectionReport> {
|
|
32
34
|
const { start, end } = data;
|
|
33
|
-
const result = await this.db.
|
|
34
|
-
.aggregate<event_types.
|
|
35
|
+
const result = await this.db.connection_report_events
|
|
36
|
+
.aggregate<event_types.ClientConnectionReport>([
|
|
35
37
|
{
|
|
36
38
|
$match: {
|
|
37
39
|
connected_at: { $lte: end, $gte: start }
|
|
38
40
|
}
|
|
39
41
|
},
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
42
|
+
this.connectionsFacetPipeline(),
|
|
43
|
+
this.connectionsProjectPipeline()
|
|
42
44
|
])
|
|
43
45
|
.toArray();
|
|
44
46
|
return result[0];
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
async
|
|
49
|
+
async reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void> {
|
|
48
50
|
const updateFilter = this.updateDocFilter(data.user_id, data.client_id!);
|
|
49
|
-
await this.db.
|
|
51
|
+
await this.db.connection_report_events.findOneAndUpdate(
|
|
50
52
|
updateFilter,
|
|
51
53
|
{
|
|
52
54
|
$set: data,
|
|
@@ -59,9 +61,9 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
59
61
|
}
|
|
60
62
|
);
|
|
61
63
|
}
|
|
62
|
-
async
|
|
64
|
+
async reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void> {
|
|
63
65
|
const { connected_at, user_id, client_id } = data;
|
|
64
|
-
await this.db.
|
|
66
|
+
await this.db.connection_report_events.findOneAndUpdate(
|
|
65
67
|
{
|
|
66
68
|
client_id,
|
|
67
69
|
user_id,
|
|
@@ -77,10 +79,10 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
77
79
|
}
|
|
78
80
|
);
|
|
79
81
|
}
|
|
80
|
-
async
|
|
82
|
+
async getConnectedClients(data: event_types.ClientConnectionsRequest): Promise<event_types.ClientConnectionReport> {
|
|
81
83
|
const timeframeFilter = this.listConnectionsDateRange(data);
|
|
82
|
-
const result = await this.db.
|
|
83
|
-
.aggregate<event_types.
|
|
84
|
+
const result = await this.db.connection_report_events
|
|
85
|
+
.aggregate<event_types.ClientConnectionReport>([
|
|
84
86
|
{
|
|
85
87
|
$match: {
|
|
86
88
|
disconnected_at: { $exists: false },
|
|
@@ -88,8 +90,8 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
88
90
|
...timeframeFilter
|
|
89
91
|
}
|
|
90
92
|
},
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
93
|
+
this.connectionsFacetPipeline(),
|
|
94
|
+
this.connectionsProjectPipeline()
|
|
93
95
|
])
|
|
94
96
|
.toArray();
|
|
95
97
|
return result[0];
|
|
@@ -113,7 +115,7 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
113
115
|
};
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
private
|
|
118
|
+
private connectionsFacetPipeline() {
|
|
117
119
|
return {
|
|
118
120
|
$facet: {
|
|
119
121
|
unique_users: [
|
|
@@ -153,7 +155,7 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
153
155
|
};
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
private
|
|
158
|
+
private connectionsProjectPipeline() {
|
|
157
159
|
return {
|
|
158
160
|
$project: {
|
|
159
161
|
users: { $ifNull: [{ $arrayElemAt: ['$unique_users.count', 0] }, 0] },
|
|
@@ -176,7 +178,7 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
176
178
|
};
|
|
177
179
|
}
|
|
178
180
|
|
|
179
|
-
private listConnectionsDateRange(data: event_types.
|
|
181
|
+
private listConnectionsDateRange(data: event_types.ClientConnectionsRequest) {
|
|
180
182
|
const { range } = data;
|
|
181
183
|
if (!range) {
|
|
182
184
|
return undefined;
|
|
@@ -11,7 +11,7 @@ export const MongoTestReportStorageFactoryGenerator = (factoryOptions: MongoTest
|
|
|
11
11
|
return async (options?: TestStorageOptions) => {
|
|
12
12
|
const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI);
|
|
13
13
|
|
|
14
|
-
await db.
|
|
14
|
+
await db.createConnectionReportingCollection();
|
|
15
15
|
|
|
16
16
|
if (!options?.doNotClear) {
|
|
17
17
|
await db.clear();
|
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
BucketParameterDocument,
|
|
9
9
|
BucketStateDocument,
|
|
10
10
|
CheckpointEventDocument,
|
|
11
|
+
ClientConnectionDocument,
|
|
11
12
|
CurrentDataDocument,
|
|
12
13
|
CustomWriteCheckpointDocument,
|
|
13
14
|
IdSequenceDocument,
|
|
14
15
|
InstanceDocument,
|
|
15
|
-
SdkConnectEventDocument,
|
|
16
16
|
SourceTableDocument,
|
|
17
17
|
SyncRuleDocument,
|
|
18
18
|
WriteCheckpointDocument
|
|
@@ -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
|
|
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.
|
|
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.
|
|
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
|
|
138
|
+
async createConnectionReportingCollection() {
|
|
139
139
|
const existingCollections = await this.db
|
|
140
|
-
.listCollections({ name: '
|
|
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('
|
|
146
|
+
await this.db.createCollection('connection_report_events');
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|