@powersync/service-module-mongodb-storage 0.0.0-dev-20250819134004 → 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 +7 -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.js +6 -6
- 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 +2 -2
- package/dist/storage/implementation/db.js +6 -6
- package/dist/storage/implementation/db.js.map +1 -1
- package/package.json +8 -8
- package/src/migrations/db/migrations/1752661449910-connection-reporting.ts +70 -0
- package/src/storage/MongoReportStorage.ts +6 -6
- package/src/storage/implementation/MongoTestReportStorageFactoryGenerator.ts +1 -1
- package/src/storage/implementation/db.ts +6 -6
- package/test/src/__snapshots__/{sdk-report-storage.test.ts.snap → connection-report-storage.test.ts.snap} +32 -32
- package/test/src/{sdk-report-storage.test.ts → connection-report-storage.test.ts} +11 -11
- 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
|
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
- Updated dependencies [a700ec9]
|
|
17
17
|
- Updated dependencies [060b829]
|
|
18
18
|
- Updated dependencies [d49bebe]
|
|
19
|
-
- @powersync/service-sync-rules@0.0.0-dev-
|
|
20
|
-
- @powersync/service-core@0.0.0-dev-
|
|
21
|
-
- @powersync/service-types@0.0.0-dev-
|
|
22
|
-
- @powersync/lib-services-framework@0.0.0-dev-
|
|
23
|
-
- @powersync/lib-service-mongodb@0.0.0-dev-
|
|
24
|
-
- @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
|
|
25
25
|
|
|
26
26
|
## 0.11.0
|
|
27
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,OAAO,KAAK,OAAO,MAAM,mCAAmC,CAAC;AAG7D,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAA6B,CAAC,CAAC;IAErF,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,mCAAmC,EAAE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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"}
|
|
@@ -8,7 +8,7 @@ export class MongoReportStorage {
|
|
|
8
8
|
}
|
|
9
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,12 +16,12 @@ 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
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: {
|
|
@@ -36,7 +36,7 @@ export class MongoReportStorage {
|
|
|
36
36
|
}
|
|
37
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: ''
|
|
@@ -47,7 +47,7 @@ export class MongoReportStorage {
|
|
|
47
47
|
}
|
|
48
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
|
|
@@ -62,7 +62,7 @@ export class MongoReportStorage {
|
|
|
62
62
|
}
|
|
63
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: {
|
|
@@ -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,uBAAuB,CAAC,IAAyC;QACrE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QACtB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"MongoReportStor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Storage.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"}
|
|
@@ -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","source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OAEG;IACH,KAAK,CAAC,mCAAmC;QACvC,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"}
|
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
|
+
};
|
|
@@ -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.
|
|
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,7 +23,7 @@ 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
|
}
|
|
@@ -32,7 +32,7 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
32
32
|
data: event_types.ClientConnectionReportRequest
|
|
33
33
|
): Promise<event_types.ClientConnectionReport> {
|
|
34
34
|
const { start, end } = data;
|
|
35
|
-
const result = await this.db.
|
|
35
|
+
const result = await this.db.connection_report_events
|
|
36
36
|
.aggregate<event_types.ClientConnectionReport>([
|
|
37
37
|
{
|
|
38
38
|
$match: {
|
|
@@ -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.
|
|
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.
|
|
66
|
+
await this.db.connection_report_events.findOneAndUpdate(
|
|
67
67
|
{
|
|
68
68
|
client_id,
|
|
69
69
|
user_id,
|
|
@@ -81,7 +81,7 @@ export class MongoReportStorage implements storage.ReportStorage {
|
|
|
81
81
|
}
|
|
82
82
|
async getConnectedClients(data: event_types.ClientConnectionsRequest): Promise<event_types.ClientConnectionReport> {
|
|
83
83
|
const timeframeFilter = this.listConnectionsDateRange(data);
|
|
84
|
-
const result = await this.db.
|
|
84
|
+
const result = await this.db.connection_report_events
|
|
85
85
|
.aggregate<event_types.ClientConnectionReport>([
|
|
86
86
|
{
|
|
87
87
|
$match: {
|
|
@@ -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();
|
|
@@ -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
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`SDK reporting storage > Should create a
|
|
3
|
+
exports[`SDK reporting storage > Should create a connection report if its after a day 1`] = `
|
|
4
4
|
[
|
|
5
5
|
{
|
|
6
6
|
"client_id": "client_week",
|
|
@@ -50,7 +50,33 @@ exports[`SDK reporting storage > Should delete rows older than specified range 1
|
|
|
50
50
|
}
|
|
51
51
|
`;
|
|
52
52
|
|
|
53
|
-
exports[`SDK reporting storage > Should show
|
|
53
|
+
exports[`SDK reporting storage > Should show connected users with start range 1`] = `
|
|
54
|
+
{
|
|
55
|
+
"sdks": [
|
|
56
|
+
{
|
|
57
|
+
"clients": 1,
|
|
58
|
+
"sdk": "powersync-dart/1.6.4",
|
|
59
|
+
"users": 1,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
"users": 1,
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
exports[`SDK reporting storage > Should show connected users with start range and end range 1`] = `
|
|
67
|
+
{
|
|
68
|
+
"sdks": [
|
|
69
|
+
{
|
|
70
|
+
"clients": 1,
|
|
71
|
+
"sdk": "powersync-js/1.21.1",
|
|
72
|
+
"users": 1,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
"users": 1,
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
exports[`SDK reporting storage > Should show connection report data for user over the past day 1`] = `
|
|
54
80
|
{
|
|
55
81
|
"sdks": [
|
|
56
82
|
{
|
|
@@ -73,7 +99,7 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
|
|
|
73
99
|
}
|
|
74
100
|
`;
|
|
75
101
|
|
|
76
|
-
exports[`SDK reporting storage > Should show
|
|
102
|
+
exports[`SDK reporting storage > Should show connection report data for user over the past month 1`] = `
|
|
77
103
|
{
|
|
78
104
|
"sdks": [
|
|
79
105
|
{
|
|
@@ -116,7 +142,7 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
|
|
|
116
142
|
}
|
|
117
143
|
`;
|
|
118
144
|
|
|
119
|
-
exports[`SDK reporting storage > Should show
|
|
145
|
+
exports[`SDK reporting storage > Should show connection report data for user over the past week 1`] = `
|
|
120
146
|
{
|
|
121
147
|
"sdks": [
|
|
122
148
|
{
|
|
@@ -149,33 +175,7 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
|
|
|
149
175
|
}
|
|
150
176
|
`;
|
|
151
177
|
|
|
152
|
-
exports[`SDK reporting storage > Should
|
|
153
|
-
{
|
|
154
|
-
"sdks": [
|
|
155
|
-
{
|
|
156
|
-
"clients": 1,
|
|
157
|
-
"sdk": "powersync-dart/1.6.4",
|
|
158
|
-
"users": 1,
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
"users": 1,
|
|
162
|
-
}
|
|
163
|
-
`;
|
|
164
|
-
|
|
165
|
-
exports[`SDK reporting storage > Should show connected users with start range and end range 1`] = `
|
|
166
|
-
{
|
|
167
|
-
"sdks": [
|
|
168
|
-
{
|
|
169
|
-
"clients": 1,
|
|
170
|
-
"sdk": "powersync-js/1.21.1",
|
|
171
|
-
"users": 1,
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
"users": 1,
|
|
175
|
-
}
|
|
176
|
-
`;
|
|
177
|
-
|
|
178
|
-
exports[`SDK reporting storage > Should update a connected sdk event and make it disconnected 1`] = `
|
|
178
|
+
exports[`SDK reporting storage > Should update a connected connection report and make it disconnected 1`] = `
|
|
179
179
|
[
|
|
180
180
|
{
|
|
181
181
|
"client_id": "client_three",
|
|
@@ -186,7 +186,7 @@ exports[`SDK reporting storage > Should update a connected sdk event and make it
|
|
|
186
186
|
]
|
|
187
187
|
`;
|
|
188
188
|
|
|
189
|
-
exports[`SDK reporting storage > Should update a
|
|
189
|
+
exports[`SDK reporting storage > Should update a connection report if its within a day 1`] = `
|
|
190
190
|
[
|
|
191
191
|
{
|
|
192
192
|
"client_id": "client_one",
|