@powersync/service-module-mongodb-storage 0.0.0-dev-20250827091123 → 0.0.0-dev-20250828134335
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 +28 -13
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/storage/MongoBucketStorage.js +1 -1
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +1 -1
- package/dist/storage/implementation/MongoBucketBatch.js +7 -4
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +16 -2
- package/dist/storage/implementation/MongoCompactor.js +204 -48
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoStorageProvider.d.ts +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js +3 -7
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +12 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.js +196 -37
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.d.ts +7 -0
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js +18 -0
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js.map +1 -0
- package/dist/storage/implementation/PersistedBatch.d.ts +1 -0
- package/dist/storage/implementation/PersistedBatch.js +13 -6
- package/dist/storage/implementation/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +1 -6
- package/dist/storage/implementation/db.js +0 -16
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +14 -3
- package/dist/{utils → storage/implementation}/util.d.ts +35 -3
- package/dist/{utils → storage/implementation}/util.js +54 -0
- package/dist/storage/implementation/util.js.map +1 -0
- package/dist/storage/storage-index.d.ts +2 -3
- package/dist/storage/storage-index.js +2 -3
- package/dist/storage/storage-index.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +0 -1
- package/src/storage/MongoBucketStorage.ts +1 -1
- package/src/storage/implementation/MongoBucketBatch.ts +8 -6
- package/src/storage/implementation/MongoCompactor.ts +239 -49
- package/src/storage/implementation/MongoStorageProvider.ts +4 -9
- package/src/storage/implementation/MongoSyncBucketStorage.ts +242 -38
- package/src/storage/implementation/MongoTestStorageFactoryGenerator.ts +28 -0
- package/src/storage/implementation/PersistedBatch.ts +14 -6
- package/src/storage/implementation/db.ts +0 -18
- package/src/storage/implementation/models.ts +15 -3
- package/src/{utils → storage/implementation}/util.ts +61 -3
- package/src/storage/storage-index.ts +2 -3
- package/test/src/__snapshots__/storage_sync.test.ts.snap +110 -0
- package/test/src/util.ts +2 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/migrations/db/migrations/1752661449910-connection-reporting.d.ts +0 -3
- package/dist/migrations/db/migrations/1752661449910-connection-reporting.js +0 -36
- package/dist/migrations/db/migrations/1752661449910-connection-reporting.js.map +0 -1
- package/dist/storage/MongoReportStorage.d.ts +0 -18
- package/dist/storage/MongoReportStorage.js +0 -154
- package/dist/storage/MongoReportStorage.js.map +0 -1
- package/dist/utils/test-utils.d.ts +0 -11
- package/dist/utils/test-utils.js +0 -40
- package/dist/utils/test-utils.js.map +0 -1
- package/dist/utils/util.js.map +0 -1
- package/dist/utils/utils-index.d.ts +0 -2
- package/dist/utils/utils-index.js +0 -3
- package/dist/utils/utils-index.js.map +0 -1
- package/src/migrations/db/migrations/1752661449910-connection-reporting.ts +0 -58
- package/src/storage/MongoReportStorage.ts +0 -177
- package/src/utils/test-utils.ts +0 -55
- package/src/utils/utils-index.ts +0 -2
- package/test/src/__snapshots__/connection-report-storage.test.ts.snap +0 -215
- package/test/src/connection-report-storage.test.ts +0 -133
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
await db.db.dropCollection('connection_report_events');
|
|
31
|
-
}
|
|
32
|
-
finally {
|
|
33
|
-
await db.client.close();
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=1752661449910-connection-reporting.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,CA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|
-
import { storage } from '@powersync/service-core';
|
|
2
|
-
import { event_types } from '@powersync/service-types';
|
|
3
|
-
import { PowerSyncMongo } from './implementation/db.js';
|
|
4
|
-
export declare class MongoReportStorage implements storage.ReportStorage {
|
|
5
|
-
private readonly client;
|
|
6
|
-
readonly db: PowerSyncMongo;
|
|
7
|
-
constructor(db: PowerSyncMongo);
|
|
8
|
-
deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void>;
|
|
9
|
-
getClientConnectionReports(data: event_types.ClientConnectionReportRequest): Promise<event_types.ClientConnectionReportResponse>;
|
|
10
|
-
reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void>;
|
|
11
|
-
reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void>;
|
|
12
|
-
getConnectedClients(): Promise<event_types.ClientConnectionReportResponse>;
|
|
13
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
14
|
-
private parseJsDate;
|
|
15
|
-
private connectionsFacetPipeline;
|
|
16
|
-
private connectionsProjectPipeline;
|
|
17
|
-
private updateDocFilter;
|
|
18
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
2
|
-
export class MongoReportStorage {
|
|
3
|
-
client;
|
|
4
|
-
db;
|
|
5
|
-
constructor(db) {
|
|
6
|
-
this.client = db.client;
|
|
7
|
-
this.db = db;
|
|
8
|
-
}
|
|
9
|
-
async deleteOldConnectionData(data) {
|
|
10
|
-
const { date } = data;
|
|
11
|
-
const result = await this.db.connection_report_events.deleteMany({
|
|
12
|
-
connected_at: { $lt: date },
|
|
13
|
-
$or: [
|
|
14
|
-
{ disconnected_at: { $exists: true } },
|
|
15
|
-
{ jwt_exp: { $lt: new Date() }, disconnected_at: { $exists: false } }
|
|
16
|
-
]
|
|
17
|
-
});
|
|
18
|
-
if (result.deletedCount > 0) {
|
|
19
|
-
logger.info(`TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from connection_report_events.`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async getClientConnectionReports(data) {
|
|
23
|
-
const { start, end } = data;
|
|
24
|
-
const result = await this.db.connection_report_events
|
|
25
|
-
.aggregate([
|
|
26
|
-
{
|
|
27
|
-
$match: {
|
|
28
|
-
connected_at: { $lte: end, $gte: start }
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
this.connectionsFacetPipeline(),
|
|
32
|
-
this.connectionsProjectPipeline()
|
|
33
|
-
])
|
|
34
|
-
.toArray();
|
|
35
|
-
return result[0];
|
|
36
|
-
}
|
|
37
|
-
async reportClientConnection(data) {
|
|
38
|
-
const updateFilter = this.updateDocFilter(data.user_id, data.client_id);
|
|
39
|
-
await this.db.connection_report_events.findOneAndUpdate(updateFilter, {
|
|
40
|
-
$set: data,
|
|
41
|
-
$unset: {
|
|
42
|
-
disconnected_at: ''
|
|
43
|
-
}
|
|
44
|
-
}, {
|
|
45
|
-
upsert: true
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
async reportClientDisconnection(data) {
|
|
49
|
-
const { connected_at, user_id, client_id } = data;
|
|
50
|
-
await this.db.connection_report_events.findOneAndUpdate({
|
|
51
|
-
client_id,
|
|
52
|
-
user_id,
|
|
53
|
-
connected_at
|
|
54
|
-
}, {
|
|
55
|
-
$set: {
|
|
56
|
-
disconnected_at: data.disconnected_at
|
|
57
|
-
},
|
|
58
|
-
$unset: {
|
|
59
|
-
jwt_exp: ''
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
async getConnectedClients() {
|
|
64
|
-
const result = await this.db.connection_report_events
|
|
65
|
-
.aggregate([
|
|
66
|
-
{
|
|
67
|
-
$match: {
|
|
68
|
-
disconnected_at: { $exists: false },
|
|
69
|
-
jwt_exp: { $gt: new Date() }
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
this.connectionsFacetPipeline(),
|
|
73
|
-
this.connectionsProjectPipeline()
|
|
74
|
-
])
|
|
75
|
-
.toArray();
|
|
76
|
-
return result[0];
|
|
77
|
-
}
|
|
78
|
-
async [Symbol.asyncDispose]() {
|
|
79
|
-
// No-op
|
|
80
|
-
}
|
|
81
|
-
parseJsDate(date) {
|
|
82
|
-
const year = date.getUTCFullYear();
|
|
83
|
-
const month = date.getUTCMonth();
|
|
84
|
-
const today = date.getUTCDate();
|
|
85
|
-
const day = date.getUTCDay();
|
|
86
|
-
return {
|
|
87
|
-
year,
|
|
88
|
-
month,
|
|
89
|
-
today,
|
|
90
|
-
day,
|
|
91
|
-
parsedDate: date
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
connectionsFacetPipeline() {
|
|
95
|
-
return {
|
|
96
|
-
$facet: {
|
|
97
|
-
unique_users: [
|
|
98
|
-
{
|
|
99
|
-
$group: {
|
|
100
|
-
_id: '$user_id'
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
$count: 'count'
|
|
105
|
-
}
|
|
106
|
-
],
|
|
107
|
-
sdk_versions_array: [
|
|
108
|
-
{
|
|
109
|
-
$group: {
|
|
110
|
-
_id: '$sdk',
|
|
111
|
-
total: { $sum: 1 },
|
|
112
|
-
client_ids: { $addToSet: '$client_id' },
|
|
113
|
-
user_ids: { $addToSet: '$user_id' }
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
$project: {
|
|
118
|
-
_id: 0,
|
|
119
|
-
sdk: '$_id',
|
|
120
|
-
users: { $size: '$user_ids' },
|
|
121
|
-
clients: { $size: '$client_ids' }
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
$sort: {
|
|
126
|
-
sdk: 1
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
connectionsProjectPipeline() {
|
|
134
|
-
return {
|
|
135
|
-
$project: {
|
|
136
|
-
users: { $ifNull: [{ $arrayElemAt: ['$unique_users.count', 0] }, 0] },
|
|
137
|
-
sdks: '$sdk_versions_array'
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
updateDocFilter(userId, clientId) {
|
|
142
|
-
const { year, month, today } = this.parseJsDate(new Date());
|
|
143
|
-
const nextDay = today + 1;
|
|
144
|
-
return {
|
|
145
|
-
user_id: userId,
|
|
146
|
-
client_id: clientId,
|
|
147
|
-
connected_at: {
|
|
148
|
-
$gte: new Date(Date.UTC(year, month, today)),
|
|
149
|
-
$lt: new Date(Date.UTC(year, month, nextDay))
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
//# sourceMappingURL=MongoReportStorage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;gBACtC,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,KAAK,EA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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;
|
package/dist/utils/test-utils.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
};
|
|
40
|
-
//# sourceMappingURL=test-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/utils/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAOtE,MAAM,UAAU,gCAAgC,CAAC,cAAuC;IACtF,OAAO,KAAK,EAAE,OAA4B,EAAE,EAAE;QAC5C,MAAM,EAAE,GAAG,oBAAoB,CAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;QAEzE,8EAA8E;QAC9E,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,cAAc,EAA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AC9C,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;SAC/B,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAoB,EAAE,EAAqB;IAC3E,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;QACvB,mDAAmD;QACnD,OAAO,GAAG,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;IACtD,CAAC;SAAM,CAAC;QACN,oCAAoC;QACpC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3C,OAAO,IAAI,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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
await db.db.dropCollection('connection_report_events');
|
|
55
|
-
} finally {
|
|
56
|
-
await db.client.close();
|
|
57
|
-
}
|
|
58
|
-
};
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
-
import { storage } from '@powersync/service-core';
|
|
3
|
-
import { event_types } from '@powersync/service-types';
|
|
4
|
-
import { PowerSyncMongo } from './implementation/db.js';
|
|
5
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
6
|
-
|
|
7
|
-
export class MongoReportStorage implements storage.ReportStorage {
|
|
8
|
-
private readonly client: mongo.MongoClient;
|
|
9
|
-
public readonly db: PowerSyncMongo;
|
|
10
|
-
|
|
11
|
-
constructor(db: PowerSyncMongo) {
|
|
12
|
-
this.client = db.client;
|
|
13
|
-
this.db = db;
|
|
14
|
-
}
|
|
15
|
-
async deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void> {
|
|
16
|
-
const { date } = data;
|
|
17
|
-
const result = await this.db.connection_report_events.deleteMany({
|
|
18
|
-
connected_at: { $lt: date },
|
|
19
|
-
$or: [
|
|
20
|
-
{ disconnected_at: { $exists: true } },
|
|
21
|
-
{ jwt_exp: { $lt: new Date() }, disconnected_at: { $exists: false } }
|
|
22
|
-
]
|
|
23
|
-
});
|
|
24
|
-
if (result.deletedCount > 0) {
|
|
25
|
-
logger.info(
|
|
26
|
-
`TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from connection_report_events.`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async getClientConnectionReports(
|
|
32
|
-
data: event_types.ClientConnectionReportRequest
|
|
33
|
-
): Promise<event_types.ClientConnectionReportResponse> {
|
|
34
|
-
const { start, end } = data;
|
|
35
|
-
const result = await this.db.connection_report_events
|
|
36
|
-
.aggregate<event_types.ClientConnectionReportResponse>([
|
|
37
|
-
{
|
|
38
|
-
$match: {
|
|
39
|
-
connected_at: { $lte: end, $gte: start }
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
this.connectionsFacetPipeline(),
|
|
43
|
-
this.connectionsProjectPipeline()
|
|
44
|
-
])
|
|
45
|
-
.toArray();
|
|
46
|
-
return result[0];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void> {
|
|
50
|
-
const updateFilter = this.updateDocFilter(data.user_id, data.client_id!);
|
|
51
|
-
await this.db.connection_report_events.findOneAndUpdate(
|
|
52
|
-
updateFilter,
|
|
53
|
-
{
|
|
54
|
-
$set: data,
|
|
55
|
-
$unset: {
|
|
56
|
-
disconnected_at: ''
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
upsert: true
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
async reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void> {
|
|
65
|
-
const { connected_at, user_id, client_id } = data;
|
|
66
|
-
await this.db.connection_report_events.findOneAndUpdate(
|
|
67
|
-
{
|
|
68
|
-
client_id,
|
|
69
|
-
user_id,
|
|
70
|
-
connected_at
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
$set: {
|
|
74
|
-
disconnected_at: data.disconnected_at
|
|
75
|
-
},
|
|
76
|
-
$unset: {
|
|
77
|
-
jwt_exp: ''
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
async getConnectedClients(): Promise<event_types.ClientConnectionReportResponse> {
|
|
83
|
-
const result = await this.db.connection_report_events
|
|
84
|
-
.aggregate<event_types.ClientConnectionReportResponse>([
|
|
85
|
-
{
|
|
86
|
-
$match: {
|
|
87
|
-
disconnected_at: { $exists: false },
|
|
88
|
-
jwt_exp: { $gt: new Date() }
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
this.connectionsFacetPipeline(),
|
|
92
|
-
this.connectionsProjectPipeline()
|
|
93
|
-
])
|
|
94
|
-
.toArray();
|
|
95
|
-
return result[0];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async [Symbol.asyncDispose]() {
|
|
99
|
-
// No-op
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private parseJsDate(date: Date) {
|
|
103
|
-
const year = date.getUTCFullYear();
|
|
104
|
-
const month = date.getUTCMonth();
|
|
105
|
-
const today = date.getUTCDate();
|
|
106
|
-
const day = date.getUTCDay();
|
|
107
|
-
return {
|
|
108
|
-
year,
|
|
109
|
-
month,
|
|
110
|
-
today,
|
|
111
|
-
day,
|
|
112
|
-
parsedDate: date
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private connectionsFacetPipeline() {
|
|
117
|
-
return {
|
|
118
|
-
$facet: {
|
|
119
|
-
unique_users: [
|
|
120
|
-
{
|
|
121
|
-
$group: {
|
|
122
|
-
_id: '$user_id'
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
$count: 'count'
|
|
127
|
-
}
|
|
128
|
-
],
|
|
129
|
-
sdk_versions_array: [
|
|
130
|
-
{
|
|
131
|
-
$group: {
|
|
132
|
-
_id: '$sdk',
|
|
133
|
-
total: { $sum: 1 },
|
|
134
|
-
client_ids: { $addToSet: '$client_id' },
|
|
135
|
-
user_ids: { $addToSet: '$user_id' }
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
$project: {
|
|
140
|
-
_id: 0,
|
|
141
|
-
sdk: '$_id',
|
|
142
|
-
users: { $size: '$user_ids' },
|
|
143
|
-
clients: { $size: '$client_ids' }
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
$sort: {
|
|
148
|
-
sdk: 1
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
]
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private connectionsProjectPipeline() {
|
|
157
|
-
return {
|
|
158
|
-
$project: {
|
|
159
|
-
users: { $ifNull: [{ $arrayElemAt: ['$unique_users.count', 0] }, 0] },
|
|
160
|
-
sdks: '$sdk_versions_array'
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private updateDocFilter(userId: string, clientId: string) {
|
|
166
|
-
const { year, month, today } = this.parseJsDate(new Date());
|
|
167
|
-
const nextDay = today + 1;
|
|
168
|
-
return {
|
|
169
|
-
user_id: userId,
|
|
170
|
-
client_id: clientId,
|
|
171
|
-
connected_at: {
|
|
172
|
-
$gte: new Date(Date.UTC(year, month, today)),
|
|
173
|
-
$lt: new Date(Date.UTC(year, month, nextDay))
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
package/src/utils/test-utils.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
};
|
package/src/utils/utils-index.ts
DELETED