@powersync/service-module-mongodb-storage 0.0.0-dev-20250723130556 → 0.0.0-dev-20250723143431
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 +5 -5
- package/dist/storage/MongoReportStorage.d.ts +3 -0
- package/dist/storage/MongoReportStorage.js +70 -65
- package/dist/storage/MongoReportStorage.js.map +1 -1
- package/dist/storage/implementation/util.d.ts +7 -0
- package/dist/storage/implementation/util.js +13 -0
- package/dist/storage/implementation/util.js.map +1 -1
- package/dist/storage/storage-index.d.ts +1 -0
- package/dist/storage/storage-index.js +1 -0
- package/dist/storage/storage-index.js.map +1 -1
- package/package.json +6 -6
- package/src/storage/MongoReportStorage.ts +73 -67
- package/src/storage/implementation/util.ts +14 -1
- package/src/storage/storage-index.ts +1 -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-20250723143431
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
- Updated dependencies [4ebc3bf]
|
|
11
11
|
- Updated dependencies [1aafdaf]
|
|
12
12
|
- Updated dependencies [a700ec9]
|
|
13
|
-
- @powersync/service-core@0.0.0-dev-
|
|
14
|
-
- @powersync/service-types@0.0.0-dev-
|
|
15
|
-
- @powersync/lib-services-framework@0.0.0-dev-
|
|
16
|
-
- @powersync/lib-service-mongodb@0.0.0-dev-
|
|
13
|
+
- @powersync/service-core@0.0.0-dev-20250723143431
|
|
14
|
+
- @powersync/service-types@0.0.0-dev-20250723143431
|
|
15
|
+
- @powersync/lib-services-framework@0.0.0-dev-20250723143431
|
|
16
|
+
- @powersync/lib-service-mongodb@0.0.0-dev-20250723143431
|
|
17
17
|
|
|
18
18
|
## 0.10.4
|
|
19
19
|
|
|
@@ -7,6 +7,9 @@ export declare class MongoReportStorage implements storage.ReportStorageFactory
|
|
|
7
7
|
constructor(db: PowerSyncMongo);
|
|
8
8
|
private sdkFacetPipeline;
|
|
9
9
|
private sdkProjectPipeline;
|
|
10
|
+
private updateDocFilter;
|
|
11
|
+
private dayDateRange;
|
|
12
|
+
private timeStampQuery;
|
|
10
13
|
deleteOldSdkData(data: event_types.DeleteOldSdkData): Promise<void>;
|
|
11
14
|
scrapeSdkData(data: event_types.ScrapeSdkDataRequest): Promise<event_types.ListCurrentConnections>;
|
|
12
15
|
reportSdkConnect(data: event_types.SdkConnectBucketData): Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { logger } from '@powersync/lib-services-framework';
|
|
2
|
+
import { parseJsDate } from './implementation/util.js';
|
|
2
3
|
function parseDate(date) {
|
|
3
4
|
const year = date.getFullYear();
|
|
4
5
|
const month = date.getMonth();
|
|
@@ -12,66 +13,6 @@ function parseDate(date) {
|
|
|
12
13
|
parsedDate: date
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
|
-
function updateDocFilter(userId, clientId) {
|
|
16
|
-
const { year, month, today, parsedDate } = parseDate(new Date());
|
|
17
|
-
const nextDay = today + 1;
|
|
18
|
-
return {
|
|
19
|
-
user_id: userId,
|
|
20
|
-
client_id: clientId,
|
|
21
|
-
connect_at: {
|
|
22
|
-
$gte: parsedDate,
|
|
23
|
-
$lt: new Date(year, month, nextDay)
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function timeSpan(period, timeframe = 1) {
|
|
28
|
-
const { year, month, today, parsedDate } = parseDate(new Date());
|
|
29
|
-
switch (period) {
|
|
30
|
-
case 'month': {
|
|
31
|
-
return { $lte: parsedDate, $gt: new Date(year, parsedDate.getMonth() - timeframe) };
|
|
32
|
-
}
|
|
33
|
-
case 'week': {
|
|
34
|
-
const weekStartDate = new Date(parsedDate);
|
|
35
|
-
weekStartDate.setDate(weekStartDate.getDate() - 6 * timeframe);
|
|
36
|
-
const weekStart = parseDate(weekStartDate);
|
|
37
|
-
return {
|
|
38
|
-
$lte: parsedDate,
|
|
39
|
-
$gt: new Date(weekStart.year, weekStart.month, weekStart.today)
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
case 'hour': {
|
|
43
|
-
// Get the last hour from the current time
|
|
44
|
-
const previousHour = parsedDate.getHours() - timeframe;
|
|
45
|
-
return {
|
|
46
|
-
$gte: new Date(year, month, today, previousHour),
|
|
47
|
-
$lt: new Date(year, month, today, parsedDate.getHours())
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
default: {
|
|
51
|
-
return {
|
|
52
|
-
$lte: parsedDate,
|
|
53
|
-
$gt: new Date(year, month, today - timeframe)
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function dayDateRange(data) {
|
|
59
|
-
const { range } = data;
|
|
60
|
-
if (!range) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
const date = new Date();
|
|
64
|
-
const { day, parsedDate } = parseDate(new Date(range.start_date));
|
|
65
|
-
if (day - date.getDay() > 2 || day - date.getDay() < -2) {
|
|
66
|
-
throw new Error('Invalid start date for `day` period. Max period is withing 2 days');
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
connect_at: {
|
|
70
|
-
$lte: date,
|
|
71
|
-
$gt: parsedDate
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
16
|
export class MongoReportStorage {
|
|
76
17
|
client;
|
|
77
18
|
db;
|
|
@@ -121,10 +62,70 @@ export class MongoReportStorage {
|
|
|
121
62
|
}
|
|
122
63
|
};
|
|
123
64
|
}
|
|
65
|
+
updateDocFilter(userId, clientId) {
|
|
66
|
+
const { year, month, today, parsedDate } = parseDate(new Date());
|
|
67
|
+
const nextDay = today + 1;
|
|
68
|
+
return {
|
|
69
|
+
user_id: userId,
|
|
70
|
+
client_id: clientId,
|
|
71
|
+
connect_at: {
|
|
72
|
+
$gte: parsedDate,
|
|
73
|
+
$lt: new Date(year, month, nextDay)
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
dayDateRange(data) {
|
|
78
|
+
const { range } = data;
|
|
79
|
+
if (!range) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const date = new Date();
|
|
83
|
+
const { day, parsedDate } = parseJsDate(new Date(range.start_date));
|
|
84
|
+
if (day - date.getDay() > 2 || day - date.getDay() < -2) {
|
|
85
|
+
throw new Error('Invalid start date for `day` period. Max period is withing 2 days');
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
connect_at: {
|
|
89
|
+
$lte: date,
|
|
90
|
+
$gt: parsedDate
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
timeStampQuery(period, timeframe = 1) {
|
|
95
|
+
const { year, month, today, parsedDate } = parseJsDate(new Date());
|
|
96
|
+
switch (period) {
|
|
97
|
+
case 'month': {
|
|
98
|
+
return { $lte: parsedDate, $gt: new Date(year, parsedDate.getMonth() - timeframe) };
|
|
99
|
+
}
|
|
100
|
+
case 'week': {
|
|
101
|
+
const weekStartDate = new Date(parsedDate);
|
|
102
|
+
weekStartDate.setDate(weekStartDate.getDate() - 6 * timeframe);
|
|
103
|
+
const weekStart = parseJsDate(weekStartDate);
|
|
104
|
+
return {
|
|
105
|
+
$lte: parsedDate,
|
|
106
|
+
$gt: new Date(weekStart.year, weekStart.month, weekStart.today)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
case 'hour': {
|
|
110
|
+
// Get the last hour from the current time
|
|
111
|
+
const previousHour = parsedDate.getHours() - timeframe;
|
|
112
|
+
return {
|
|
113
|
+
$gte: new Date(year, month, today, previousHour),
|
|
114
|
+
$lt: new Date(year, month, today, parsedDate.getHours())
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
default: {
|
|
118
|
+
return {
|
|
119
|
+
$lte: parsedDate,
|
|
120
|
+
$gt: new Date(year, month, today - timeframe)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
124
125
|
async deleteOldSdkData(data) {
|
|
125
126
|
const { period, timeframe } = data;
|
|
126
127
|
const result = await this.db.sdk_report_events.deleteMany({
|
|
127
|
-
connect_at:
|
|
128
|
+
connect_at: this.timeStampQuery(period, timeframe),
|
|
128
129
|
$or: [{ disconnect_at: { $exists: true } }, { jwt_exp: { $lt: new Date() }, disconnect_at: { $exists: false } }]
|
|
129
130
|
});
|
|
130
131
|
if (result.deletedCount > 0) {
|
|
@@ -132,7 +133,7 @@ export class MongoReportStorage {
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
async scrapeSdkData(data) {
|
|
135
|
-
const timespanFilter =
|
|
136
|
+
const timespanFilter = this.timeStampQuery(data.period, data.interval);
|
|
136
137
|
const result = await this.db.sdk_report_events
|
|
137
138
|
.aggregate([
|
|
138
139
|
{
|
|
@@ -147,7 +148,9 @@ export class MongoReportStorage {
|
|
|
147
148
|
return result[0];
|
|
148
149
|
}
|
|
149
150
|
async reportSdkConnect(data) {
|
|
150
|
-
|
|
151
|
+
const updateFilter = this.updateDocFilter(data.user_id, data.client_id);
|
|
152
|
+
console.log(updateFilter);
|
|
153
|
+
await this.db.sdk_report_events.findOneAndUpdate(updateFilter, {
|
|
151
154
|
$set: data,
|
|
152
155
|
$unset: {
|
|
153
156
|
disconnect_at: ''
|
|
@@ -157,7 +160,9 @@ export class MongoReportStorage {
|
|
|
157
160
|
});
|
|
158
161
|
}
|
|
159
162
|
async reportSdkDisconnect(data) {
|
|
160
|
-
|
|
163
|
+
const updateFilter = this.updateDocFilter(data.user_id, data.client_id);
|
|
164
|
+
console.log(updateFilter);
|
|
165
|
+
await this.db.sdk_report_events.findOneAndUpdate(updateFilter, {
|
|
161
166
|
$set: {
|
|
162
167
|
disconnect_at: data.disconnect_at
|
|
163
168
|
},
|
|
@@ -173,7 +178,7 @@ export class MongoReportStorage {
|
|
|
173
178
|
$match: {
|
|
174
179
|
disconnect_at: { $exists: false },
|
|
175
180
|
jwt_exp: { $gt: new Date() },
|
|
176
|
-
...dayDateRange(data)
|
|
181
|
+
...this.dayDateRange(data)
|
|
177
182
|
}
|
|
178
183
|
},
|
|
179
184
|
this.sdkFacetPipeline(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"MongoReportStorage.js","sourceRoot":"","sources":["../../src/storage/MongoReportStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,SAAS,SAAS,CAAC,IAAU;IAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC1B,OAAO;QACL,IAAI;QACJ,KAAK;QACL,KAAK;QACL,GAAG;QACH,UAAU,EAAE,IAAI;KACjB,CAAC;AACJ,CAAC;AAED,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;IAEO,gBAAgB;QACtB,OAAO;YACL,MAAM,EAAE;gBACN,YAAY,EAAE;oBACZ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AE;gBACN,OAAO,EAAE,EAAE;aACZ;SACF,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,sBAAsB,CAC1B,IAA+C;QAE/C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,iBAAiB;aAC3C,SAAS,CAAC;YACT;gBACE,MAAM,EAAE;oBACN,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;oBACjC,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE;oBAC5B,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;iBAC3B;aACF;YACD,IAAI,CAAC,gBAAgB,EAAE;YACvB,IAAI,CAAC,kBAAkB,EAAE;SAC1B,CAAC;aACD,OAAO,EAAE,CAAC;QACb,OAAO,MAAM,CAAC,CAAC,CAAuC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,QAAQ;IACV,CAAC;CACF"}
|
|
@@ -26,3 +26,10 @@ export declare function replicaIdToSubkey(table: bson.ObjectId, id: storage.Repl
|
|
|
26
26
|
* Helper for unit tests
|
|
27
27
|
*/
|
|
28
28
|
export declare const connectMongoForTests: (url: string, isCI: boolean) => PowerSyncMongo;
|
|
29
|
+
export declare function parseJsDate(date: Date): {
|
|
30
|
+
year: number;
|
|
31
|
+
month: number;
|
|
32
|
+
today: number;
|
|
33
|
+
day: number;
|
|
34
|
+
parsedDate: Date;
|
|
35
|
+
};
|
|
@@ -108,4 +108,17 @@ export const connectMongoForTests = (url, isCI) => {
|
|
|
108
108
|
});
|
|
109
109
|
return new PowerSyncMongo(client);
|
|
110
110
|
};
|
|
111
|
+
export function parseJsDate(date) {
|
|
112
|
+
const year = date.getFullYear();
|
|
113
|
+
const month = date.getMonth();
|
|
114
|
+
const today = date.getDate();
|
|
115
|
+
const day = date.getDay();
|
|
116
|
+
return {
|
|
117
|
+
year,
|
|
118
|
+
month,
|
|
119
|
+
today,
|
|
120
|
+
day,
|
|
121
|
+
parsedDate: date
|
|
122
|
+
};
|
|
123
|
+
}
|
|
111
124
|
//# sourceMappingURL=util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/storage/implementation/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/storage/implementation/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,MAAM,UAAU,cAAc,CAAI,MAAkB,EAAE,IAAiB;IACrE,IAAI,MAAM,GAAG;QACX,IAAI,EAAE;YACJ,GAAG,MAAM;SACH;QACR,GAAG,EAAE;YACH,GAAG,MAAM;SACH;KACT,CAAC;IAEF,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;IACtC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,aAAqB;IACpE,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,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C,KAAK;KAChD,CAAC,CAAC;IACH,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,IAAU;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC1B,OAAO;QACL,IAAI;QACJ,KAAK;QACL,KAAK;QACL,GAAG;QACH,UAAU,EAAE,IAAI;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -12,4 +12,5 @@ export * from './implementation/OperationBatch.js';
|
|
|
12
12
|
export * from './implementation/PersistedBatch.js';
|
|
13
13
|
export * from './implementation/util.js';
|
|
14
14
|
export * from './MongoBucketStorage.js';
|
|
15
|
+
export * from './MongoReportStorage.js';
|
|
15
16
|
//# sourceMappingURL=storage-index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oDAAoD,CAAC;AACnE,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,sDAAsD,CAAC;AACrE,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oDAAoD,CAAC;AACnE,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,sDAAsD,CAAC;AACrE,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,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-20250723143431",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"license": "FSL-1.1-Apache-2.0",
|
|
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-
|
|
30
|
+
"@powersync/lib-service-mongodb": "0.0.0-dev-20250723143431",
|
|
31
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20250723143431",
|
|
32
|
+
"@powersync/service-core": "0.0.0-dev-20250723143431",
|
|
33
|
+
"@powersync/service-types": "0.0.0-dev-20250723143431",
|
|
34
34
|
"@powersync/service-jsonbig": "0.17.10",
|
|
35
35
|
"@powersync/service-sync-rules": "0.27.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@powersync/service-core-tests": "0.0.0-dev-
|
|
38
|
+
"@powersync/service-core-tests": "0.0.0-dev-20250723143431"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -b",
|
|
@@ -3,6 +3,7 @@ import { storage } from '@powersync/service-core';
|
|
|
3
3
|
import { event_types } from '@powersync/service-types';
|
|
4
4
|
import { PowerSyncMongo } from './implementation/db.js';
|
|
5
5
|
import { logger } from '@powersync/lib-services-framework';
|
|
6
|
+
import { parseJsDate } from './implementation/util.js';
|
|
6
7
|
|
|
7
8
|
function parseDate(date: Date) {
|
|
8
9
|
const year = date.getFullYear();
|
|
@@ -17,68 +18,6 @@ function parseDate(date: Date) {
|
|
|
17
18
|
parsedDate: date
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
|
-
function updateDocFilter(userId: string, clientId: string) {
|
|
21
|
-
const { year, month, today, parsedDate } = parseDate(new Date());
|
|
22
|
-
const nextDay = today + 1;
|
|
23
|
-
return {
|
|
24
|
-
user_id: userId,
|
|
25
|
-
client_id: clientId,
|
|
26
|
-
connect_at: {
|
|
27
|
-
$gte: parsedDate,
|
|
28
|
-
$lt: new Date(year, month, nextDay)
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function timeSpan(period: event_types.TimeFrames, timeframe: number = 1): mongo.Filter<mongo.Document> {
|
|
34
|
-
const { year, month, today, parsedDate } = parseDate(new Date());
|
|
35
|
-
switch (period) {
|
|
36
|
-
case 'month': {
|
|
37
|
-
return { $lte: parsedDate, $gt: new Date(year, parsedDate.getMonth() - timeframe) };
|
|
38
|
-
}
|
|
39
|
-
case 'week': {
|
|
40
|
-
const weekStartDate = new Date(parsedDate);
|
|
41
|
-
weekStartDate.setDate(weekStartDate.getDate() - 6 * timeframe);
|
|
42
|
-
const weekStart = parseDate(weekStartDate);
|
|
43
|
-
return {
|
|
44
|
-
$lte: parsedDate,
|
|
45
|
-
$gt: new Date(weekStart.year, weekStart.month, weekStart.today)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
case 'hour': {
|
|
49
|
-
// Get the last hour from the current time
|
|
50
|
-
const previousHour = parsedDate.getHours() - timeframe;
|
|
51
|
-
return {
|
|
52
|
-
$gte: new Date(year, month, today, previousHour),
|
|
53
|
-
$lt: new Date(year, month, today, parsedDate.getHours())
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
default: {
|
|
57
|
-
return {
|
|
58
|
-
$lte: parsedDate,
|
|
59
|
-
$gt: new Date(year, month, today - timeframe)
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function dayDateRange(data: event_types.ListCurrentConnectionsRequest) {
|
|
66
|
-
const { range } = data;
|
|
67
|
-
if (!range) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
const date = new Date();
|
|
71
|
-
const { day, parsedDate } = parseDate(new Date(range.start_date));
|
|
72
|
-
if (day - date.getDay() > 2 || day - date.getDay() < -2) {
|
|
73
|
-
throw new Error('Invalid start date for `day` period. Max period is withing 2 days');
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
connect_at: {
|
|
77
|
-
$lte: date,
|
|
78
|
-
$gt: parsedDate
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
21
|
|
|
83
22
|
export class MongoReportStorage implements storage.ReportStorageFactory {
|
|
84
23
|
private readonly client: mongo.MongoClient;
|
|
@@ -133,10 +72,73 @@ export class MongoReportStorage implements storage.ReportStorageFactory {
|
|
|
133
72
|
};
|
|
134
73
|
}
|
|
135
74
|
|
|
75
|
+
private updateDocFilter(userId: string, clientId: string) {
|
|
76
|
+
const { year, month, today, parsedDate } = parseDate(new Date());
|
|
77
|
+
const nextDay = today + 1;
|
|
78
|
+
return {
|
|
79
|
+
user_id: userId,
|
|
80
|
+
client_id: clientId,
|
|
81
|
+
connect_at: {
|
|
82
|
+
$gte: parsedDate,
|
|
83
|
+
$lt: new Date(year, month, nextDay)
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private dayDateRange(data: event_types.ListCurrentConnectionsRequest) {
|
|
89
|
+
const { range } = data;
|
|
90
|
+
if (!range) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
const date = new Date();
|
|
94
|
+
const { day, parsedDate } = parseJsDate(new Date(range.start_date));
|
|
95
|
+
if (day - date.getDay() > 2 || day - date.getDay() < -2) {
|
|
96
|
+
throw new Error('Invalid start date for `day` period. Max period is withing 2 days');
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
connect_at: {
|
|
100
|
+
$lte: date,
|
|
101
|
+
$gt: parsedDate
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private timeStampQuery(period: event_types.TimeFrames, timeframe: number = 1): mongo.Filter<mongo.Document> {
|
|
107
|
+
const { year, month, today, parsedDate } = parseJsDate(new Date());
|
|
108
|
+
switch (period) {
|
|
109
|
+
case 'month': {
|
|
110
|
+
return { $lte: parsedDate, $gt: new Date(year, parsedDate.getMonth() - timeframe) };
|
|
111
|
+
}
|
|
112
|
+
case 'week': {
|
|
113
|
+
const weekStartDate = new Date(parsedDate);
|
|
114
|
+
weekStartDate.setDate(weekStartDate.getDate() - 6 * timeframe);
|
|
115
|
+
const weekStart = parseJsDate(weekStartDate);
|
|
116
|
+
return {
|
|
117
|
+
$lte: parsedDate,
|
|
118
|
+
$gt: new Date(weekStart.year, weekStart.month, weekStart.today)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
case 'hour': {
|
|
122
|
+
// Get the last hour from the current time
|
|
123
|
+
const previousHour = parsedDate.getHours() - timeframe;
|
|
124
|
+
return {
|
|
125
|
+
$gte: new Date(year, month, today, previousHour),
|
|
126
|
+
$lt: new Date(year, month, today, parsedDate.getHours())
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
default: {
|
|
130
|
+
return {
|
|
131
|
+
$lte: parsedDate,
|
|
132
|
+
$gt: new Date(year, month, today - timeframe)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
136
138
|
async deleteOldSdkData(data: event_types.DeleteOldSdkData): Promise<void> {
|
|
137
139
|
const { period, timeframe } = data;
|
|
138
140
|
const result = await this.db.sdk_report_events.deleteMany({
|
|
139
|
-
connect_at:
|
|
141
|
+
connect_at: this.timeStampQuery(period, timeframe),
|
|
140
142
|
$or: [{ disconnect_at: { $exists: true } }, { jwt_exp: { $lt: new Date() }, disconnect_at: { $exists: false } }]
|
|
141
143
|
});
|
|
142
144
|
if (result.deletedCount > 0) {
|
|
@@ -145,7 +147,7 @@ export class MongoReportStorage implements storage.ReportStorageFactory {
|
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
async scrapeSdkData(data: event_types.ScrapeSdkDataRequest): Promise<event_types.ListCurrentConnections> {
|
|
148
|
-
const timespanFilter =
|
|
150
|
+
const timespanFilter = this.timeStampQuery(data.period, data.interval);
|
|
149
151
|
const result = await this.db.sdk_report_events
|
|
150
152
|
.aggregate([
|
|
151
153
|
{
|
|
@@ -161,8 +163,10 @@ export class MongoReportStorage implements storage.ReportStorageFactory {
|
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
async reportSdkConnect(data: event_types.SdkConnectBucketData): Promise<void> {
|
|
166
|
+
const updateFilter = this.updateDocFilter(data.user_id, data.client_id!);
|
|
167
|
+
console.log(updateFilter);
|
|
164
168
|
await this.db.sdk_report_events.findOneAndUpdate(
|
|
165
|
-
|
|
169
|
+
updateFilter,
|
|
166
170
|
{
|
|
167
171
|
$set: data,
|
|
168
172
|
$unset: {
|
|
@@ -175,7 +179,9 @@ export class MongoReportStorage implements storage.ReportStorageFactory {
|
|
|
175
179
|
);
|
|
176
180
|
}
|
|
177
181
|
async reportSdkDisconnect(data: event_types.SdkDisconnectEventData): Promise<void> {
|
|
178
|
-
|
|
182
|
+
const updateFilter = this.updateDocFilter(data.user_id, data.client_id!);
|
|
183
|
+
console.log(updateFilter);
|
|
184
|
+
await this.db.sdk_report_events.findOneAndUpdate(updateFilter, {
|
|
179
185
|
$set: {
|
|
180
186
|
disconnect_at: data.disconnect_at
|
|
181
187
|
},
|
|
@@ -193,7 +199,7 @@ export class MongoReportStorage implements storage.ReportStorageFactory {
|
|
|
193
199
|
$match: {
|
|
194
200
|
disconnect_at: { $exists: false },
|
|
195
201
|
jwt_exp: { $gt: new Date() },
|
|
196
|
-
...dayDateRange(data)
|
|
202
|
+
...this.dayDateRange(data)
|
|
197
203
|
}
|
|
198
204
|
},
|
|
199
205
|
this.sdkFacetPipeline(),
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as bson from 'bson';
|
|
2
2
|
import * as crypto from 'crypto';
|
|
3
3
|
import * as uuid from 'uuid';
|
|
4
|
-
|
|
5
4
|
import { mongo } from '@powersync/lib-service-mongodb';
|
|
6
5
|
import { storage, utils } from '@powersync/service-core';
|
|
7
6
|
|
|
@@ -117,3 +116,17 @@ export const connectMongoForTests = (url: string, isCI: boolean) => {
|
|
|
117
116
|
});
|
|
118
117
|
return new PowerSyncMongo(client);
|
|
119
118
|
};
|
|
119
|
+
|
|
120
|
+
export function parseJsDate(date: Date) {
|
|
121
|
+
const year = date.getFullYear();
|
|
122
|
+
const month = date.getMonth();
|
|
123
|
+
const today = date.getDate();
|
|
124
|
+
const day = date.getDay();
|
|
125
|
+
return {
|
|
126
|
+
year,
|
|
127
|
+
month,
|
|
128
|
+
today,
|
|
129
|
+
day,
|
|
130
|
+
parsedDate: date
|
|
131
|
+
};
|
|
132
|
+
}
|