@powersync/service-module-mongodb-storage 0.0.0-dev-20260202111439 → 0.0.0-dev-20260202142528
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 +6 -6
- package/dist/migrations/db/migrations/1770037239303-sync-reporting.d.ts +3 -0
- package/dist/migrations/db/migrations/1770037239303-sync-reporting.js +41 -0
- package/dist/migrations/db/migrations/1770037239303-sync-reporting.js.map +1 -0
- package/dist/storage/MongoReportStorage.d.ts +5 -0
- package/dist/storage/MongoReportStorage.js +78 -0
- package/dist/storage/MongoReportStorage.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +10 -0
- package/dist/storage/implementation/db.js +30 -0
- package/dist/storage/implementation/db.js.map +1 -1
- package/package.json +7 -7
- package/src/migrations/db/migrations/1770037239303-sync-reporting.ts +68 -0
- package/src/storage/MongoReportStorage.ts +99 -0
- package/src/storage/implementation/db.ts +32 -0
- package/tsconfig.tsbuildinfo +1 -1
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-20260202142528
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
- Updated dependencies [0255483]
|
|
19
19
|
- Updated dependencies [3207fd2]
|
|
20
20
|
- Updated dependencies [a02cc58]
|
|
21
|
-
- @powersync/service-core@0.0.0-dev-
|
|
22
|
-
- @powersync/service-sync-rules@0.0.0-dev-
|
|
23
|
-
- @powersync/service-types@0.0.0-dev-
|
|
24
|
-
- @powersync/lib-services-framework@0.0.0-dev-
|
|
25
|
-
- @powersync/lib-service-mongodb@0.0.0-dev-
|
|
21
|
+
- @powersync/service-core@0.0.0-dev-20260202142528
|
|
22
|
+
- @powersync/service-sync-rules@0.0.0-dev-20260202142528
|
|
23
|
+
- @powersync/service-types@0.0.0-dev-20260202142528
|
|
24
|
+
- @powersync/lib-services-framework@0.0.0-dev-20260202142528
|
|
25
|
+
- @powersync/lib-service-mongodb@0.0.0-dev-20260202142528
|
|
26
26
|
|
|
27
27
|
## 0.12.16
|
|
28
28
|
|
|
@@ -0,0 +1,41 @@
|
|
|
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.createSyncReportingCollection();
|
|
7
|
+
await db.createBucketReportingCollection();
|
|
8
|
+
// Sync data
|
|
9
|
+
await db.sync_report_events.createIndex({
|
|
10
|
+
type: 1
|
|
11
|
+
}, { name: 'sync_type_index' });
|
|
12
|
+
await db.sync_report_events.createIndex({
|
|
13
|
+
date: 1
|
|
14
|
+
}, { name: 'sync_date_index' });
|
|
15
|
+
// Bucket data
|
|
16
|
+
await db.bucket_report_events.createIndex({
|
|
17
|
+
checkpoint_id: 1
|
|
18
|
+
}, { name: 'checkpoint_id_index' });
|
|
19
|
+
await db.bucket_report_events.createIndex({
|
|
20
|
+
date: 1
|
|
21
|
+
}, { name: 'bucket_date_index' });
|
|
22
|
+
await db.bucket_report_events.createIndex({
|
|
23
|
+
name: 1
|
|
24
|
+
}, { name: 'bucket_name_index' });
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
await db.client.close();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export const down = async (context) => {
|
|
31
|
+
const { service_context: { configuration } } = context;
|
|
32
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
33
|
+
try {
|
|
34
|
+
await db.db.dropCollection('sync_report_events');
|
|
35
|
+
await db.db.dropCollection('bucket_report_events');
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await db.client.close();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=1770037239303-sync-reporting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1770037239303-sync-reporting.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1770037239303-sync-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,6BAA6B,EAAE,CAAC;QACzC,MAAM,EAAE,CAAC,+BAA+B,EAAE,CAAC;QAE3C,YAAY;QACZ,MAAM,EAAE,CAAC,kBAAkB,CAAC,WAAW,CACrC;YACE,IAAI,EAAE,CAAC;SACR,EACD,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAC5B,CAAC;QAEF,MAAM,EAAE,CAAC,kBAAkB,CAAC,WAAW,CACrC;YACE,IAAI,EAAE,CAAC;SACR,EAED,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAC5B,CAAC;QAEF,cAAc;QACd,MAAM,EAAE,CAAC,oBAAoB,CAAC,WAAW,CACvC;YACE,aAAa,EAAE,CAAC;SACjB,EACD,EAAE,IAAI,EAAE,qBAAqB,EAAE,CAChC,CAAC;QACF,MAAM,EAAE,CAAC,oBAAoB,CAAC,WAAW,CACvC;YACE,IAAI,EAAE,CAAC;SACR,EACD,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAC9B,CAAC;QACF,MAAM,EAAE,CAAC,oBAAoB,CAAC,WAAW,CACvC;YACE,IAAI,EAAE,CAAC;SACR,EACD,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAC9B,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IAEZ,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAA6B,CAAC,CAAC;IAErF,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;QACjD,MAAM,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC;IACrD,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -3,7 +3,12 @@ import { event_types } from '@powersync/service-types';
|
|
|
3
3
|
import { PowerSyncMongo } from './implementation/db.js';
|
|
4
4
|
export declare class MongoReportStorage implements storage.ReportStorage {
|
|
5
5
|
readonly db: PowerSyncMongo;
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly session;
|
|
6
8
|
constructor(db: PowerSyncMongo);
|
|
9
|
+
private reportSyncCheckpoint;
|
|
10
|
+
private reportSyncDiffCheckpoint;
|
|
11
|
+
reportSyncAnalyticsEvent(data: event_types.SyncAnalyticsEventData): Promise<void>;
|
|
7
12
|
deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void>;
|
|
8
13
|
getClientConnectionReports(data: event_types.ClientConnectionReportRequest): Promise<event_types.ClientConnectionReportResponse>;
|
|
9
14
|
getGeneralClientConnectionAnalytics(data: event_types.ClientConnectionAnalyticsRequest): Promise<event_types.PaginatedResponse<event_types.ClientConnection>>;
|
|
@@ -1,9 +1,87 @@
|
|
|
1
|
+
import { event_types } from '@powersync/service-types';
|
|
1
2
|
import { logger } from '@powersync/lib-services-framework';
|
|
2
3
|
import { createPaginatedConnectionQuery } from '../utils/util.js';
|
|
3
4
|
export class MongoReportStorage {
|
|
4
5
|
db;
|
|
6
|
+
client;
|
|
7
|
+
session;
|
|
5
8
|
constructor(db) {
|
|
6
9
|
this.db = db;
|
|
10
|
+
this.client = db.client;
|
|
11
|
+
this.session = this.client.startSession();
|
|
12
|
+
}
|
|
13
|
+
async reportSyncCheckpoint(data) {
|
|
14
|
+
const { user_id, client_id, data: checkData } = data;
|
|
15
|
+
const { id, type, last_op_id, buckets, date, streams } = checkData;
|
|
16
|
+
await this.session.withTransaction(async () => {
|
|
17
|
+
await this.db.sync_report_events.insertOne({
|
|
18
|
+
_id: id,
|
|
19
|
+
user_id,
|
|
20
|
+
client_id,
|
|
21
|
+
type,
|
|
22
|
+
last_op_id,
|
|
23
|
+
date,
|
|
24
|
+
streams
|
|
25
|
+
}, { session: this.session });
|
|
26
|
+
await this.db.bucket_report_events.insertMany(buckets.map((bucket) => {
|
|
27
|
+
return {
|
|
28
|
+
status: `synced`,
|
|
29
|
+
checkpoint_id: id,
|
|
30
|
+
client_id,
|
|
31
|
+
user_id,
|
|
32
|
+
name: bucket.name,
|
|
33
|
+
date: date,
|
|
34
|
+
priority: bucket.priority
|
|
35
|
+
};
|
|
36
|
+
}));
|
|
37
|
+
}, { session: this.session });
|
|
38
|
+
}
|
|
39
|
+
async reportSyncDiffCheckpoint(data) {
|
|
40
|
+
const { user_id, client_id, data: checkData } = data;
|
|
41
|
+
const { id, type, last_op_id, updated_buckets, removed_buckets, date, streams } = checkData;
|
|
42
|
+
await this.session.withTransaction(async () => {
|
|
43
|
+
await this.db.sync_report_events.insertOne({
|
|
44
|
+
_id: id,
|
|
45
|
+
user_id,
|
|
46
|
+
client_id,
|
|
47
|
+
type,
|
|
48
|
+
last_op_id,
|
|
49
|
+
date,
|
|
50
|
+
streams
|
|
51
|
+
}, { session: this.session });
|
|
52
|
+
if (updated_buckets.length > 0) {
|
|
53
|
+
await this.db.bucket_report_events.insertMany(updated_buckets.map((bucket) => {
|
|
54
|
+
return {
|
|
55
|
+
type: `updated`,
|
|
56
|
+
checkpoint_id: id,
|
|
57
|
+
client_id,
|
|
58
|
+
user_id,
|
|
59
|
+
name: bucket.name,
|
|
60
|
+
date: date,
|
|
61
|
+
priority: bucket.priority
|
|
62
|
+
};
|
|
63
|
+
}), { session: this.session });
|
|
64
|
+
}
|
|
65
|
+
if (removed_buckets.length > 0) {
|
|
66
|
+
await this.db.bucket_report_events.insertMany(removed_buckets.map((bucket) => {
|
|
67
|
+
return {
|
|
68
|
+
type: `removed`,
|
|
69
|
+
checkpoint_id: id,
|
|
70
|
+
client_id,
|
|
71
|
+
user_id,
|
|
72
|
+
name: bucket,
|
|
73
|
+
date: date,
|
|
74
|
+
priority: 0
|
|
75
|
+
};
|
|
76
|
+
}), { session: this.session });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async reportSyncAnalyticsEvent(data) {
|
|
81
|
+
if (data.data.type === event_types.SyncEventCheckpointType.FULL) {
|
|
82
|
+
return this.reportSyncCheckpoint(data);
|
|
83
|
+
}
|
|
84
|
+
return this.reportSyncDiffCheckpoint(data);
|
|
7
85
|
}
|
|
8
86
|
async deleteOldConnectionData(data) {
|
|
9
87
|
const { date } = data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAGlE,MAAM,OAAO,kBAAkB;IACb,EAAE,CAAiB;IAClB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C5D,MAAM,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC;QAC1B,OAAO;YACL,OAAO,EAAE,MAAM;YACf,SAAS,EAAE,QAAQ;YACnB,YAAY,EAAE;gBACZ,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC5C,GAAG,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;aAC9C;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -22,6 +22,8 @@ export declare class PowerSyncMongo {
|
|
|
22
22
|
readonly bucket_state: mongo.Collection<BucketStateDocument>;
|
|
23
23
|
readonly checkpoint_events: mongo.Collection<CheckpointEventDocument>;
|
|
24
24
|
readonly connection_report_events: mongo.Collection<ClientConnectionDocument>;
|
|
25
|
+
readonly sync_report_events: mongo.Collection<any>;
|
|
26
|
+
readonly bucket_report_events: mongo.Collection<any>;
|
|
25
27
|
readonly client: mongo.MongoClient;
|
|
26
28
|
readonly db: mongo.Db;
|
|
27
29
|
constructor(client: mongo.MongoClient, options?: PowerSyncMongoOptions);
|
|
@@ -49,6 +51,14 @@ export declare class PowerSyncMongo {
|
|
|
49
51
|
* Only use in migrations and tests.
|
|
50
52
|
*/
|
|
51
53
|
createConnectionReportingCollection(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Only use in migrations and tests.
|
|
56
|
+
*/
|
|
57
|
+
createSyncReportingCollection(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Only use in migrations and tests.
|
|
60
|
+
*/
|
|
61
|
+
createBucketReportingCollection(): Promise<void>;
|
|
52
62
|
/**
|
|
53
63
|
* Only use in migrations and tests.
|
|
54
64
|
*/
|
|
@@ -14,6 +14,8 @@ export class PowerSyncMongo {
|
|
|
14
14
|
bucket_state;
|
|
15
15
|
checkpoint_events;
|
|
16
16
|
connection_report_events;
|
|
17
|
+
sync_report_events;
|
|
18
|
+
bucket_report_events;
|
|
17
19
|
client;
|
|
18
20
|
db;
|
|
19
21
|
constructor(client, options) {
|
|
@@ -35,6 +37,8 @@ export class PowerSyncMongo {
|
|
|
35
37
|
this.bucket_state = this.db.collection('bucket_state');
|
|
36
38
|
this.checkpoint_events = this.db.collection('checkpoint_events');
|
|
37
39
|
this.connection_report_events = this.db.collection('connection_report_events');
|
|
40
|
+
this.sync_report_events = this.db.collection('sync_report_events');
|
|
41
|
+
this.bucket_report_events = this.db.collection('bucket_report_events');
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
44
|
* Clear all collections.
|
|
@@ -110,6 +114,32 @@ export class PowerSyncMongo {
|
|
|
110
114
|
}
|
|
111
115
|
await this.db.createCollection('connection_report_events');
|
|
112
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Only use in migrations and tests.
|
|
119
|
+
*/
|
|
120
|
+
async createSyncReportingCollection() {
|
|
121
|
+
const existingCollections = await this.db
|
|
122
|
+
.listCollections({ name: 'sync_report_events' }, { nameOnly: false })
|
|
123
|
+
.toArray();
|
|
124
|
+
const collection = existingCollections[0];
|
|
125
|
+
if (collection != null) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
await this.db.createCollection('sync_report_events');
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Only use in migrations and tests.
|
|
132
|
+
*/
|
|
133
|
+
async createBucketReportingCollection() {
|
|
134
|
+
const existingCollections = await this.db
|
|
135
|
+
.listCollections({ name: 'bucket_report_events' }, { nameOnly: false })
|
|
136
|
+
.toArray();
|
|
137
|
+
const collection = existingCollections[0];
|
|
138
|
+
if (collection != null) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
await this.db.createCollection('bucket_report_events');
|
|
142
|
+
}
|
|
113
143
|
/**
|
|
114
144
|
* Only use in migrations and tests.
|
|
115
145
|
*/
|
|
@@ -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,wBAAwB,CAA6C;
|
|
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,wBAAwB,CAA6C;IACrE,kBAAkB,CAAwB;IAC1C,oBAAoB,CAAwB;IAE5C,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,CAA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ClC,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-20260202142528",
|
|
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-
|
|
30
|
+
"@powersync/lib-service-mongodb": "0.0.0-dev-20260202142528",
|
|
31
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20260202142528",
|
|
32
|
+
"@powersync/service-core": "0.0.0-dev-20260202142528",
|
|
33
33
|
"@powersync/service-jsonbig": "0.17.12",
|
|
34
|
-
"@powersync/service-sync-rules": "0.0.0-dev-
|
|
35
|
-
"@powersync/service-types": "0.0.0-dev-
|
|
34
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20260202142528",
|
|
35
|
+
"@powersync/service-types": "0.0.0-dev-20260202142528"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@powersync/service-core-tests": "0.0.0-dev-
|
|
38
|
+
"@powersync/service-core-tests": "0.0.0-dev-20260202142528"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -b",
|
|
@@ -0,0 +1,68 @@
|
|
|
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.createSyncReportingCollection();
|
|
13
|
+
await db.createBucketReportingCollection();
|
|
14
|
+
|
|
15
|
+
// Sync data
|
|
16
|
+
await db.sync_report_events.createIndex(
|
|
17
|
+
{
|
|
18
|
+
type: 1
|
|
19
|
+
},
|
|
20
|
+
{ name: 'sync_type_index' }
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
await db.sync_report_events.createIndex(
|
|
24
|
+
{
|
|
25
|
+
date: 1
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
{ name: 'sync_date_index' }
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Bucket data
|
|
32
|
+
await db.bucket_report_events.createIndex(
|
|
33
|
+
{
|
|
34
|
+
checkpoint_id: 1
|
|
35
|
+
},
|
|
36
|
+
{ name: 'checkpoint_id_index' }
|
|
37
|
+
);
|
|
38
|
+
await db.bucket_report_events.createIndex(
|
|
39
|
+
{
|
|
40
|
+
date: 1
|
|
41
|
+
},
|
|
42
|
+
{ name: 'bucket_date_index' }
|
|
43
|
+
);
|
|
44
|
+
await db.bucket_report_events.createIndex(
|
|
45
|
+
{
|
|
46
|
+
name: 1
|
|
47
|
+
},
|
|
48
|
+
{ name: 'bucket_name_index' }
|
|
49
|
+
);
|
|
50
|
+
} finally {
|
|
51
|
+
await db.client.close();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
56
|
+
const {
|
|
57
|
+
service_context: { configuration }
|
|
58
|
+
} = context;
|
|
59
|
+
|
|
60
|
+
const db = storage.createPowerSyncMongo(configuration.storage as MongoStorageConfig);
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await db.db.dropCollection('sync_report_events');
|
|
64
|
+
await db.db.dropCollection('bucket_report_events');
|
|
65
|
+
} finally {
|
|
66
|
+
await db.client.close();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -3,13 +3,112 @@ import { event_types } from '@powersync/service-types';
|
|
|
3
3
|
import { PowerSyncMongo } from './implementation/db.js';
|
|
4
4
|
import { logger } from '@powersync/lib-services-framework';
|
|
5
5
|
import { createPaginatedConnectionQuery } from '../utils/util.js';
|
|
6
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
6
7
|
|
|
7
8
|
export class MongoReportStorage implements storage.ReportStorage {
|
|
8
9
|
public readonly db: PowerSyncMongo;
|
|
10
|
+
private readonly client: mongo.MongoClient;
|
|
11
|
+
private readonly session: mongo.ClientSession;
|
|
9
12
|
|
|
10
13
|
constructor(db: PowerSyncMongo) {
|
|
11
14
|
this.db = db;
|
|
15
|
+
this.client = db.client;
|
|
16
|
+
this.session = this.client.startSession();
|
|
12
17
|
}
|
|
18
|
+
|
|
19
|
+
private async reportSyncCheckpoint(data: event_types.SyncAnalyticsEventData) {
|
|
20
|
+
const { user_id, client_id, data: checkData } = data;
|
|
21
|
+
const { id, type, last_op_id, buckets, date, streams } = checkData;
|
|
22
|
+
await this.session.withTransaction(
|
|
23
|
+
async () => {
|
|
24
|
+
await this.db.sync_report_events.insertOne(
|
|
25
|
+
{
|
|
26
|
+
_id: id,
|
|
27
|
+
user_id,
|
|
28
|
+
client_id,
|
|
29
|
+
type,
|
|
30
|
+
last_op_id,
|
|
31
|
+
date,
|
|
32
|
+
streams
|
|
33
|
+
},
|
|
34
|
+
{ session: this.session }
|
|
35
|
+
);
|
|
36
|
+
await this.db.bucket_report_events.insertMany(
|
|
37
|
+
buckets.map((bucket: any) => {
|
|
38
|
+
return {
|
|
39
|
+
status: `synced`,
|
|
40
|
+
checkpoint_id: id,
|
|
41
|
+
client_id,
|
|
42
|
+
user_id,
|
|
43
|
+
name: bucket.name,
|
|
44
|
+
date: date,
|
|
45
|
+
priority: bucket.priority
|
|
46
|
+
};
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
},
|
|
50
|
+
{ session: this.session }
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private async reportSyncDiffCheckpoint(data: event_types.SyncAnalyticsEventData) {
|
|
55
|
+
const { user_id, client_id, data: checkData } = data;
|
|
56
|
+
const { id, type, last_op_id, updated_buckets, removed_buckets, date, streams } = checkData;
|
|
57
|
+
await this.session.withTransaction(async () => {
|
|
58
|
+
await this.db.sync_report_events.insertOne(
|
|
59
|
+
{
|
|
60
|
+
_id: id,
|
|
61
|
+
user_id,
|
|
62
|
+
client_id,
|
|
63
|
+
type,
|
|
64
|
+
last_op_id,
|
|
65
|
+
date,
|
|
66
|
+
streams
|
|
67
|
+
},
|
|
68
|
+
{ session: this.session }
|
|
69
|
+
);
|
|
70
|
+
if (updated_buckets.length > 0) {
|
|
71
|
+
await this.db.bucket_report_events.insertMany(
|
|
72
|
+
updated_buckets.map((bucket: any) => {
|
|
73
|
+
return {
|
|
74
|
+
type: `updated`,
|
|
75
|
+
checkpoint_id: id,
|
|
76
|
+
client_id,
|
|
77
|
+
user_id,
|
|
78
|
+
name: bucket.name,
|
|
79
|
+
date: date,
|
|
80
|
+
priority: bucket.priority
|
|
81
|
+
};
|
|
82
|
+
}),
|
|
83
|
+
{ session: this.session }
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (removed_buckets.length > 0) {
|
|
87
|
+
await this.db.bucket_report_events.insertMany(
|
|
88
|
+
removed_buckets.map((bucket: string) => {
|
|
89
|
+
return {
|
|
90
|
+
type: `removed`,
|
|
91
|
+
checkpoint_id: id,
|
|
92
|
+
client_id,
|
|
93
|
+
user_id,
|
|
94
|
+
name: bucket,
|
|
95
|
+
date: date,
|
|
96
|
+
priority: 0
|
|
97
|
+
};
|
|
98
|
+
}),
|
|
99
|
+
{ session: this.session }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async reportSyncAnalyticsEvent(data: event_types.SyncAnalyticsEventData): Promise<void> {
|
|
106
|
+
if (data.data.type === event_types.SyncEventCheckpointType.FULL) {
|
|
107
|
+
return this.reportSyncCheckpoint(data);
|
|
108
|
+
}
|
|
109
|
+
return this.reportSyncDiffCheckpoint(data);
|
|
110
|
+
}
|
|
111
|
+
|
|
13
112
|
async deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void> {
|
|
14
113
|
const { date } = data;
|
|
15
114
|
const result = await this.db.connection_report_events.deleteMany({
|
|
@@ -39,6 +39,8 @@ export class PowerSyncMongo {
|
|
|
39
39
|
readonly bucket_state: mongo.Collection<BucketStateDocument>;
|
|
40
40
|
readonly checkpoint_events: mongo.Collection<CheckpointEventDocument>;
|
|
41
41
|
readonly connection_report_events: mongo.Collection<ClientConnectionDocument>;
|
|
42
|
+
readonly sync_report_events: mongo.Collection<any>;
|
|
43
|
+
readonly bucket_report_events: mongo.Collection<any>;
|
|
42
44
|
|
|
43
45
|
readonly client: mongo.MongoClient;
|
|
44
46
|
readonly db: mongo.Db;
|
|
@@ -64,6 +66,8 @@ export class PowerSyncMongo {
|
|
|
64
66
|
this.bucket_state = this.db.collection('bucket_state');
|
|
65
67
|
this.checkpoint_events = this.db.collection('checkpoint_events');
|
|
66
68
|
this.connection_report_events = this.db.collection('connection_report_events');
|
|
69
|
+
this.sync_report_events = this.db.collection('sync_report_events');
|
|
70
|
+
this.bucket_report_events = this.db.collection('bucket_report_events');
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
/**
|
|
@@ -145,6 +149,34 @@ export class PowerSyncMongo {
|
|
|
145
149
|
await this.db.createCollection('connection_report_events');
|
|
146
150
|
}
|
|
147
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Only use in migrations and tests.
|
|
154
|
+
*/
|
|
155
|
+
async createSyncReportingCollection() {
|
|
156
|
+
const existingCollections = await this.db
|
|
157
|
+
.listCollections({ name: 'sync_report_events' }, { nameOnly: false })
|
|
158
|
+
.toArray();
|
|
159
|
+
const collection = existingCollections[0];
|
|
160
|
+
if (collection != null) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
await this.db.createCollection('sync_report_events');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Only use in migrations and tests.
|
|
168
|
+
*/
|
|
169
|
+
async createBucketReportingCollection() {
|
|
170
|
+
const existingCollections = await this.db
|
|
171
|
+
.listCollections({ name: 'bucket_report_events' }, { nameOnly: false })
|
|
172
|
+
.toArray();
|
|
173
|
+
const collection = existingCollections[0];
|
|
174
|
+
if (collection != null) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
await this.db.createCollection('bucket_report_events');
|
|
178
|
+
}
|
|
179
|
+
|
|
148
180
|
/**
|
|
149
181
|
* Only use in migrations and tests.
|
|
150
182
|
*/
|