@powersync/service-module-mongodb-storage 0.0.0-dev-20250910154512 → 0.0.0-dev-20251030082344
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 +35 -11
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/migrations/db/migrations/1760433882550-bucket-state-index2.js +25 -0
- package/dist/migrations/db/migrations/1760433882550-bucket-state-index2.js.map +1 -0
- package/dist/storage/MongoBucketStorage.js +1 -1
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.js +1 -1
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +13 -3
- package/dist/storage/implementation/MongoCompactor.js +86 -90
- 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 +2 -2
- package/dist/storage/implementation/MongoSyncBucketStorage.js +62 -19
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.d.ts +9 -0
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js +20 -0
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js.map +1 -0
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +6 -2
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/PersistedBatch.js +1 -1
- package/dist/storage/implementation/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +3 -4
- package/dist/storage/implementation/db.js +9 -14
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +0 -3
- package/dist/{utils → storage/implementation}/util.d.ts +7 -2
- package/dist/{utils → storage/implementation}/util.js +16 -1
- 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 +9 -9
- package/src/index.ts +0 -1
- package/src/migrations/db/migrations/{1752661449910-connection-reporting.ts → 1760433882550-bucket-state-index2.ts} +6 -30
- package/src/storage/MongoBucketStorage.ts +1 -1
- package/src/storage/implementation/MongoBucketBatch.ts +1 -1
- package/src/storage/implementation/MongoCompactor.ts +100 -96
- package/src/storage/implementation/MongoStorageProvider.ts +4 -9
- package/src/storage/implementation/MongoSyncBucketStorage.ts +64 -21
- package/src/storage/implementation/MongoTestStorageFactoryGenerator.ts +32 -0
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +6 -2
- package/src/storage/implementation/PersistedBatch.ts +1 -1
- package/src/storage/implementation/db.ts +12 -16
- package/src/storage/implementation/models.ts +0 -3
- package/src/{utils → storage/implementation}/util.ts +19 -3
- package/src/storage/storage-index.ts +2 -3
- package/test/src/storage.test.ts +51 -3
- package/test/src/storage_compacting.test.ts +17 -2
- package/test/src/util.ts +2 -6
- package/tsconfig.tsbuildinfo +1 -1
- 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 -17
- package/dist/storage/MongoReportStorage.js +0 -152
- package/dist/storage/MongoReportStorage.js.map +0 -1
- package/dist/utils/test-utils.d.ts +0 -13
- 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/storage/MongoReportStorage.ts +0 -174
- package/src/utils/test-utils.ts +0 -57
- 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
- /package/dist/migrations/db/migrations/{1752661449910-connection-reporting.d.ts → 1760433882550-bucket-state-index2.d.ts} +0 -0
|
@@ -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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C;QACH,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"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
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
|
-
readonly db: PowerSyncMongo;
|
|
6
|
-
constructor(db: PowerSyncMongo);
|
|
7
|
-
deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void>;
|
|
8
|
-
getClientConnectionReports(data: event_types.ClientConnectionReportRequest): Promise<event_types.ClientConnectionReportResponse>;
|
|
9
|
-
reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void>;
|
|
10
|
-
reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void>;
|
|
11
|
-
getConnectedClients(): Promise<event_types.ClientConnectionReportResponse>;
|
|
12
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
13
|
-
private parseJsDate;
|
|
14
|
-
private connectionsFacetPipeline;
|
|
15
|
-
private connectionsProjectPipeline;
|
|
16
|
-
private updateDocFilter;
|
|
17
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
2
|
-
export class MongoReportStorage {
|
|
3
|
-
db;
|
|
4
|
-
constructor(db) {
|
|
5
|
-
this.db = db;
|
|
6
|
-
}
|
|
7
|
-
async deleteOldConnectionData(data) {
|
|
8
|
-
const { date } = data;
|
|
9
|
-
const result = await this.db.connection_report_events.deleteMany({
|
|
10
|
-
connected_at: { $lt: date },
|
|
11
|
-
$or: [
|
|
12
|
-
{ disconnected_at: { $exists: true } },
|
|
13
|
-
{ jwt_exp: { $lt: new Date() }, disconnected_at: { $exists: false } }
|
|
14
|
-
]
|
|
15
|
-
});
|
|
16
|
-
if (result.deletedCount > 0) {
|
|
17
|
-
logger.info(`TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from connection_report_events.`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async getClientConnectionReports(data) {
|
|
21
|
-
const { start, end } = data;
|
|
22
|
-
const result = await this.db.connection_report_events
|
|
23
|
-
.aggregate([
|
|
24
|
-
{
|
|
25
|
-
$match: {
|
|
26
|
-
connected_at: { $lte: end, $gte: start }
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
this.connectionsFacetPipeline(),
|
|
30
|
-
this.connectionsProjectPipeline()
|
|
31
|
-
])
|
|
32
|
-
.toArray();
|
|
33
|
-
return result[0];
|
|
34
|
-
}
|
|
35
|
-
async reportClientConnection(data) {
|
|
36
|
-
const updateFilter = this.updateDocFilter(data.user_id, data.client_id);
|
|
37
|
-
await this.db.connection_report_events.findOneAndUpdate(updateFilter, {
|
|
38
|
-
$set: data,
|
|
39
|
-
$unset: {
|
|
40
|
-
disconnected_at: ''
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
upsert: true
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
async reportClientDisconnection(data) {
|
|
47
|
-
const { connected_at, user_id, client_id } = data;
|
|
48
|
-
await this.db.connection_report_events.findOneAndUpdate({
|
|
49
|
-
client_id,
|
|
50
|
-
user_id,
|
|
51
|
-
connected_at
|
|
52
|
-
}, {
|
|
53
|
-
$set: {
|
|
54
|
-
disconnected_at: data.disconnected_at
|
|
55
|
-
},
|
|
56
|
-
$unset: {
|
|
57
|
-
jwt_exp: ''
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async getConnectedClients() {
|
|
62
|
-
const result = await this.db.connection_report_events
|
|
63
|
-
.aggregate([
|
|
64
|
-
{
|
|
65
|
-
$match: {
|
|
66
|
-
disconnected_at: { $exists: false },
|
|
67
|
-
jwt_exp: { $gt: new Date() }
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
this.connectionsFacetPipeline(),
|
|
71
|
-
this.connectionsProjectPipeline()
|
|
72
|
-
])
|
|
73
|
-
.toArray();
|
|
74
|
-
return result[0];
|
|
75
|
-
}
|
|
76
|
-
async [Symbol.asyncDispose]() {
|
|
77
|
-
// No-op
|
|
78
|
-
}
|
|
79
|
-
parseJsDate(date) {
|
|
80
|
-
const year = date.getUTCFullYear();
|
|
81
|
-
const month = date.getUTCMonth();
|
|
82
|
-
const today = date.getUTCDate();
|
|
83
|
-
const day = date.getUTCDay();
|
|
84
|
-
return {
|
|
85
|
-
year,
|
|
86
|
-
month,
|
|
87
|
-
today,
|
|
88
|
-
day,
|
|
89
|
-
parsedDate: date
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
connectionsFacetPipeline() {
|
|
93
|
-
return {
|
|
94
|
-
$facet: {
|
|
95
|
-
unique_users: [
|
|
96
|
-
{
|
|
97
|
-
$group: {
|
|
98
|
-
_id: '$user_id'
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
$count: 'count'
|
|
103
|
-
}
|
|
104
|
-
],
|
|
105
|
-
sdk_versions_array: [
|
|
106
|
-
{
|
|
107
|
-
$group: {
|
|
108
|
-
_id: '$sdk',
|
|
109
|
-
total: { $sum: 1 },
|
|
110
|
-
client_ids: { $addToSet: '$client_id' },
|
|
111
|
-
user_ids: { $addToSet: '$user_id' }
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
$project: {
|
|
116
|
-
_id: 0,
|
|
117
|
-
sdk: '$_id',
|
|
118
|
-
users: { $size: '$user_ids' },
|
|
119
|
-
clients: { $size: '$client_ids' }
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
$sort: {
|
|
124
|
-
sdk: 1
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
]
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
connectionsProjectPipeline() {
|
|
132
|
-
return {
|
|
133
|
-
$project: {
|
|
134
|
-
users: { $ifNull: [{ $arrayElemAt: ['$unique_users.count', 0] }, 0] },
|
|
135
|
-
sdks: '$sdk_versions_array'
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
updateDocFilter(userId, clientId) {
|
|
140
|
-
const { year, month, today } = this.parseJsDate(new Date());
|
|
141
|
-
const nextDay = today + 1;
|
|
142
|
-
return {
|
|
143
|
-
user_id: userId,
|
|
144
|
-
client_id: clientId,
|
|
145
|
-
connected_at: {
|
|
146
|
-
$gte: new Date(Date.UTC(year, month, today)),
|
|
147
|
-
$lt: new Date(Date.UTC(year, month, nextDay))
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=MongoReportStorage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,MAAM,OAAO,kBAAkB;IACb,EAAE,CAAiB;IAEnC,YAAY,EAAkB;QAC5B,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,GA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@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { PowerSyncMongo } from '../storage/implementation/db.js';
|
|
2
|
-
import { TestStorageOptions } from '@powersync/service-core';
|
|
3
|
-
import { MongoReportStorage } from '../storage/MongoReportStorage.js';
|
|
4
|
-
import { MongoBucketStorage } from '../storage/MongoBucketStorage.js';
|
|
5
|
-
import { MongoSyncBucketStorageOptions } from '../storage/implementation/MongoSyncBucketStorage.js';
|
|
6
|
-
export type MongoTestStorageOptions = {
|
|
7
|
-
url: string;
|
|
8
|
-
isCI: boolean;
|
|
9
|
-
internalOptions?: MongoSyncBucketStorageOptions;
|
|
10
|
-
};
|
|
11
|
-
export declare function mongoTestStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions): (options?: TestStorageOptions) => Promise<MongoBucketStorage>;
|
|
12
|
-
export declare function mongoTestReportStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions): (options?: TestStorageOptions) => Promise<MongoReportStorage>;
|
|
13
|
-
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_' }, factoryOptions.internalOptions);
|
|
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;AAStE,MAAM,UAAU,gCAAgC,CAAC,cAAuC;IACtF,OAAO,KAAK,EAAE,OAA4B,EAAE,EAAE;QAC5C,MAAM,EAAE,GAAG,oBAAo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ot":"","sources":["../../src/utils/utils-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,cAAc,WAAW,CAAC"}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { storage } from '@powersync/service-core';
|
|
2
|
-
import { event_types } from '@powersync/service-types';
|
|
3
|
-
import { PowerSyncMongo } from './implementation/db.js';
|
|
4
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
5
|
-
|
|
6
|
-
export class MongoReportStorage implements storage.ReportStorage {
|
|
7
|
-
public readonly db: PowerSyncMongo;
|
|
8
|
-
|
|
9
|
-
constructor(db: PowerSyncMongo) {
|
|
10
|
-
this.db = db;
|
|
11
|
-
}
|
|
12
|
-
async deleteOldConnectionData(data: event_types.DeleteOldConnectionData): Promise<void> {
|
|
13
|
-
const { date } = data;
|
|
14
|
-
const result = await this.db.connection_report_events.deleteMany({
|
|
15
|
-
connected_at: { $lt: date },
|
|
16
|
-
$or: [
|
|
17
|
-
{ disconnected_at: { $exists: true } },
|
|
18
|
-
{ jwt_exp: { $lt: new Date() }, disconnected_at: { $exists: false } }
|
|
19
|
-
]
|
|
20
|
-
});
|
|
21
|
-
if (result.deletedCount > 0) {
|
|
22
|
-
logger.info(
|
|
23
|
-
`TTL from ${date.toISOString()}: ${result.deletedCount} MongoDB documents have been removed from connection_report_events.`
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async getClientConnectionReports(
|
|
29
|
-
data: event_types.ClientConnectionReportRequest
|
|
30
|
-
): Promise<event_types.ClientConnectionReportResponse> {
|
|
31
|
-
const { start, end } = data;
|
|
32
|
-
const result = await this.db.connection_report_events
|
|
33
|
-
.aggregate<event_types.ClientConnectionReportResponse>([
|
|
34
|
-
{
|
|
35
|
-
$match: {
|
|
36
|
-
connected_at: { $lte: end, $gte: start }
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
this.connectionsFacetPipeline(),
|
|
40
|
-
this.connectionsProjectPipeline()
|
|
41
|
-
])
|
|
42
|
-
.toArray();
|
|
43
|
-
return result[0];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async reportClientConnection(data: event_types.ClientConnectionBucketData): Promise<void> {
|
|
47
|
-
const updateFilter = this.updateDocFilter(data.user_id, data.client_id!);
|
|
48
|
-
await this.db.connection_report_events.findOneAndUpdate(
|
|
49
|
-
updateFilter,
|
|
50
|
-
{
|
|
51
|
-
$set: data,
|
|
52
|
-
$unset: {
|
|
53
|
-
disconnected_at: ''
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
upsert: true
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
async reportClientDisconnection(data: event_types.ClientDisconnectionEventData): Promise<void> {
|
|
62
|
-
const { connected_at, user_id, client_id } = data;
|
|
63
|
-
await this.db.connection_report_events.findOneAndUpdate(
|
|
64
|
-
{
|
|
65
|
-
client_id,
|
|
66
|
-
user_id,
|
|
67
|
-
connected_at
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
$set: {
|
|
71
|
-
disconnected_at: data.disconnected_at
|
|
72
|
-
},
|
|
73
|
-
$unset: {
|
|
74
|
-
jwt_exp: ''
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
async getConnectedClients(): Promise<event_types.ClientConnectionReportResponse> {
|
|
80
|
-
const result = await this.db.connection_report_events
|
|
81
|
-
.aggregate<event_types.ClientConnectionReportResponse>([
|
|
82
|
-
{
|
|
83
|
-
$match: {
|
|
84
|
-
disconnected_at: { $exists: false },
|
|
85
|
-
jwt_exp: { $gt: new Date() }
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
this.connectionsFacetPipeline(),
|
|
89
|
-
this.connectionsProjectPipeline()
|
|
90
|
-
])
|
|
91
|
-
.toArray();
|
|
92
|
-
return result[0];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async [Symbol.asyncDispose]() {
|
|
96
|
-
// No-op
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private parseJsDate(date: Date) {
|
|
100
|
-
const year = date.getUTCFullYear();
|
|
101
|
-
const month = date.getUTCMonth();
|
|
102
|
-
const today = date.getUTCDate();
|
|
103
|
-
const day = date.getUTCDay();
|
|
104
|
-
return {
|
|
105
|
-
year,
|
|
106
|
-
month,
|
|
107
|
-
today,
|
|
108
|
-
day,
|
|
109
|
-
parsedDate: date
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private connectionsFacetPipeline() {
|
|
114
|
-
return {
|
|
115
|
-
$facet: {
|
|
116
|
-
unique_users: [
|
|
117
|
-
{
|
|
118
|
-
$group: {
|
|
119
|
-
_id: '$user_id'
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
$count: 'count'
|
|
124
|
-
}
|
|
125
|
-
],
|
|
126
|
-
sdk_versions_array: [
|
|
127
|
-
{
|
|
128
|
-
$group: {
|
|
129
|
-
_id: '$sdk',
|
|
130
|
-
total: { $sum: 1 },
|
|
131
|
-
client_ids: { $addToSet: '$client_id' },
|
|
132
|
-
user_ids: { $addToSet: '$user_id' }
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
$project: {
|
|
137
|
-
_id: 0,
|
|
138
|
-
sdk: '$_id',
|
|
139
|
-
users: { $size: '$user_ids' },
|
|
140
|
-
clients: { $size: '$client_ids' }
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
$sort: {
|
|
145
|
-
sdk: 1
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
]
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private connectionsProjectPipeline() {
|
|
154
|
-
return {
|
|
155
|
-
$project: {
|
|
156
|
-
users: { $ifNull: [{ $arrayElemAt: ['$unique_users.count', 0] }, 0] },
|
|
157
|
-
sdks: '$sdk_versions_array'
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private updateDocFilter(userId: string, clientId: string) {
|
|
163
|
-
const { year, month, today } = this.parseJsDate(new Date());
|
|
164
|
-
const nextDay = today + 1;
|
|
165
|
-
return {
|
|
166
|
-
user_id: userId,
|
|
167
|
-
client_id: clientId,
|
|
168
|
-
connected_at: {
|
|
169
|
-
$gte: new Date(Date.UTC(year, month, today)),
|
|
170
|
-
$lt: new Date(Date.UTC(year, month, nextDay))
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
}
|
package/src/utils/test-utils.ts
DELETED
|
@@ -1,57 +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
|
-
import { MongoSyncBucketStorageOptions } from '../storage/implementation/MongoSyncBucketStorage.js';
|
|
7
|
-
|
|
8
|
-
export type MongoTestStorageOptions = {
|
|
9
|
-
url: string;
|
|
10
|
-
isCI: boolean;
|
|
11
|
-
internalOptions?: MongoSyncBucketStorageOptions;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function mongoTestStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions) {
|
|
15
|
-
return async (options?: TestStorageOptions) => {
|
|
16
|
-
const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI);
|
|
17
|
-
|
|
18
|
-
// None of the tests insert data into this collection, so it was never created
|
|
19
|
-
if (!(await db.db.listCollections({ name: db.bucket_parameters.collectionName }).hasNext())) {
|
|
20
|
-
await db.db.createCollection('bucket_parameters');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Full migrations are not currently run for tests, so we manually create this
|
|
24
|
-
await db.createCheckpointEventsCollection();
|
|
25
|
-
|
|
26
|
-
if (!options?.doNotClear) {
|
|
27
|
-
await db.clear();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return new MongoBucketStorage(db, { slot_name_prefix: 'test_' }, factoryOptions.internalOptions);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function mongoTestReportStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions) {
|
|
35
|
-
return async (options?: TestStorageOptions) => {
|
|
36
|
-
const db = connectMongoForTests(factoryOptions.url, factoryOptions.isCI);
|
|
37
|
-
|
|
38
|
-
await db.createConnectionReportingCollection();
|
|
39
|
-
|
|
40
|
-
if (!options?.doNotClear) {
|
|
41
|
-
await db.clear();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return new MongoReportStorage(db);
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const connectMongoForTests = (url: string, isCI: boolean) => {
|
|
49
|
-
// Short timeout for tests, to fail fast when the server is not available.
|
|
50
|
-
// Slightly longer timeouts for CI, to avoid arbitrary test failures
|
|
51
|
-
const client = new mongo.MongoClient(url, {
|
|
52
|
-
connectTimeoutMS: isCI ? 15_000 : 5_000,
|
|
53
|
-
socketTimeoutMS: isCI ? 15_000 : 5_000,
|
|
54
|
-
serverSelectionTimeoutMS: isCI ? 15_000 : 2_500
|
|
55
|
-
});
|
|
56
|
-
return new PowerSyncMongo(client);
|
|
57
|
-
};
|
package/src/utils/utils-index.ts
DELETED