@powersync/service-module-mongodb-storage 0.0.0-dev-20250813080357 → 0.0.0-dev-20250819134004
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 +11 -7
- package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js +11 -8
- package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js.map +1 -1
- package/dist/storage/MongoReportStorage.d.ts +9 -9
- package/dist/storage/MongoReportStorage.js +78 -75
- package/dist/storage/MongoReportStorage.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/MongoStorageProvider.d.ts +1 -1
- package/dist/storage/implementation/db.d.ts +2 -2
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +1 -1
- package/package.json +8 -8
- package/src/migrations/db/migrations/1752661449910-sdk-reporting.ts +11 -8
- package/src/storage/MongoReportStorage.ts +94 -92
- package/src/storage/implementation/MongoBucketBatch.ts +1 -1
- package/src/storage/implementation/MongoStorageProvider.ts +1 -1
- package/src/storage/implementation/db.ts +2 -2
- package/src/storage/implementation/models.ts +1 -1
- package/test/src/__snapshots__/storage_sync.test.ts.snap +197 -0
- package/test/src/sdk-report-storage.test.ts +31 -31
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -3,10 +3,10 @@ import { INITIALIZED_MONGO_REPORT_STORAGE_FACTORY } from './util.js';
|
|
|
3
3
|
import { event_types } from '@powersync/service-types';
|
|
4
4
|
|
|
5
5
|
function removeVolatileFields(
|
|
6
|
-
sdks: event_types.
|
|
7
|
-
): Partial<event_types.
|
|
8
|
-
return sdks.map((sdk: Partial<event_types.
|
|
9
|
-
const { _id,
|
|
6
|
+
sdks: event_types.ClientConnection[]
|
|
7
|
+
): Partial<event_types.ClientConnection & { _id: string }>[] {
|
|
8
|
+
return sdks.map((sdk: Partial<event_types.ClientConnection & { _id: string }>) => {
|
|
9
|
+
const { _id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
|
|
10
10
|
return {
|
|
11
11
|
...rest
|
|
12
12
|
};
|
|
@@ -37,7 +37,7 @@ describe('SDK reporting storage', async () => {
|
|
|
37
37
|
const user_one = {
|
|
38
38
|
user_id: 'user_one',
|
|
39
39
|
client_id: 'client_one',
|
|
40
|
-
|
|
40
|
+
connected_at: now,
|
|
41
41
|
sdk: 'powersync-dart/1.6.4',
|
|
42
42
|
user_agent: 'powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android',
|
|
43
43
|
jwt_exp: nowAdd5minutes
|
|
@@ -45,7 +45,7 @@ describe('SDK reporting storage', async () => {
|
|
|
45
45
|
const user_two = {
|
|
46
46
|
user_id: 'user_two',
|
|
47
47
|
client_id: 'client_two',
|
|
48
|
-
|
|
48
|
+
connected_at: nowLess5minutes,
|
|
49
49
|
sdk: 'powersync-js/1.21.1',
|
|
50
50
|
user_agent: 'powersync-js/1.21.0 powersync-web Chromium/138 linux',
|
|
51
51
|
jwt_exp: nowAdd5minutes
|
|
@@ -53,16 +53,16 @@ describe('SDK reporting storage', async () => {
|
|
|
53
53
|
const user_three = {
|
|
54
54
|
user_id: 'user_three',
|
|
55
55
|
client_id: 'client_three',
|
|
56
|
-
|
|
56
|
+
connected_at: yesterday,
|
|
57
57
|
sdk: 'powersync-js/1.21.2',
|
|
58
58
|
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
59
|
-
|
|
59
|
+
disconnected_at: yesterday
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
const user_four = {
|
|
63
63
|
user_id: 'user_four',
|
|
64
64
|
client_id: 'client_four',
|
|
65
|
-
|
|
65
|
+
connected_at: now,
|
|
66
66
|
sdk: 'powersync-js/1.21.4',
|
|
67
67
|
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
68
68
|
jwt_exp: nowLess5minutes
|
|
@@ -71,25 +71,25 @@ describe('SDK reporting storage', async () => {
|
|
|
71
71
|
const user_week = {
|
|
72
72
|
user_id: 'user_week',
|
|
73
73
|
client_id: 'client_week',
|
|
74
|
-
|
|
74
|
+
connected_at: weekAgo,
|
|
75
75
|
sdk: 'powersync-js/1.24.5',
|
|
76
76
|
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
77
|
-
|
|
77
|
+
disconnected_at: weekAgo
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
const user_month = {
|
|
81
81
|
user_id: 'user_month',
|
|
82
82
|
client_id: 'client_month',
|
|
83
|
-
|
|
83
|
+
connected_at: monthAgo,
|
|
84
84
|
sdk: 'powersync-js/1.23.6',
|
|
85
85
|
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
86
|
-
|
|
86
|
+
disconnected_at: monthAgo
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
const user_expired = {
|
|
90
90
|
user_id: 'user_expired',
|
|
91
91
|
client_id: 'client_expired',
|
|
92
|
-
|
|
92
|
+
connected_at: monthAgo,
|
|
93
93
|
sdk: 'powersync-js/1.23.7',
|
|
94
94
|
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
95
95
|
jwt_exp: monthAgo
|
|
@@ -119,7 +119,7 @@ describe('SDK reporting storage', async () => {
|
|
|
119
119
|
await deleteData();
|
|
120
120
|
});
|
|
121
121
|
it('Should show connected users with start range', async () => {
|
|
122
|
-
const current = await factory.
|
|
122
|
+
const current = await factory.getConnectedClients({
|
|
123
123
|
range: {
|
|
124
124
|
start: new Date(
|
|
125
125
|
now.getFullYear(),
|
|
@@ -133,7 +133,7 @@ describe('SDK reporting storage', async () => {
|
|
|
133
133
|
expect(current).toMatchSnapshot();
|
|
134
134
|
});
|
|
135
135
|
it('Should show connected users with start range and end range', async () => {
|
|
136
|
-
const current = await factory.
|
|
136
|
+
const current = await factory.getConnectedClients({
|
|
137
137
|
range: {
|
|
138
138
|
end: nowLess5minutes.toISOString(),
|
|
139
139
|
start: new Date(
|
|
@@ -148,21 +148,21 @@ describe('SDK reporting storage', async () => {
|
|
|
148
148
|
expect(current).toMatchSnapshot();
|
|
149
149
|
});
|
|
150
150
|
it('Should show SDK scrape data for user over the past month', async () => {
|
|
151
|
-
const sdk = await factory.
|
|
151
|
+
const sdk = await factory.getClientConnectionReports({
|
|
152
152
|
start: monthAgo,
|
|
153
153
|
end: now
|
|
154
154
|
});
|
|
155
155
|
expect(sdk).toMatchSnapshot();
|
|
156
156
|
});
|
|
157
157
|
it('Should show SDK scrape data for user over the past week', async () => {
|
|
158
|
-
const sdk = await factory.
|
|
158
|
+
const sdk = await factory.getClientConnectionReports({
|
|
159
159
|
start: weekAgo,
|
|
160
160
|
end: now
|
|
161
161
|
});
|
|
162
162
|
expect(sdk).toMatchSnapshot();
|
|
163
163
|
});
|
|
164
164
|
it('Should show SDK scrape data for user over the past day', async () => {
|
|
165
|
-
const sdk = await factory.
|
|
165
|
+
const sdk = await factory.getClientConnectionReports({
|
|
166
166
|
start: dayAgo,
|
|
167
167
|
end: now
|
|
168
168
|
});
|
|
@@ -178,9 +178,9 @@ describe('SDK reporting storage', async () => {
|
|
|
178
178
|
now.getMinutes() + 20
|
|
179
179
|
);
|
|
180
180
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
181
|
-
await factory.
|
|
181
|
+
await factory.reportClientConnection({
|
|
182
182
|
sdk: user_one.sdk,
|
|
183
|
-
|
|
183
|
+
connected_at: newConnectAt,
|
|
184
184
|
jwt_exp: jwtExp,
|
|
185
185
|
client_id: user_one.client_id,
|
|
186
186
|
user_id: user_one.user_id,
|
|
@@ -189,9 +189,9 @@ describe('SDK reporting storage', async () => {
|
|
|
189
189
|
|
|
190
190
|
const sdk = await factory.db.sdk_report_events.find({ user_id: user_one.user_id }).toArray();
|
|
191
191
|
expect(sdk).toHaveLength(1);
|
|
192
|
-
expect(new Date(sdk[0].
|
|
192
|
+
expect(new Date(sdk[0].connected_at)).toEqual(newConnectAt);
|
|
193
193
|
expect(new Date(sdk[0].jwt_exp!)).toEqual(jwtExp);
|
|
194
|
-
expect(sdk[0].
|
|
194
|
+
expect(sdk[0].disconnected_at).toBeUndefined();
|
|
195
195
|
const cleaned = removeVolatileFields(sdk);
|
|
196
196
|
expect(cleaned).toMatchSnapshot();
|
|
197
197
|
});
|
|
@@ -206,18 +206,18 @@ describe('SDK reporting storage', async () => {
|
|
|
206
206
|
);
|
|
207
207
|
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
208
208
|
|
|
209
|
-
await factory.
|
|
210
|
-
|
|
209
|
+
await factory.reportClientDisconnection({
|
|
210
|
+
disconnected_at: disconnectAt,
|
|
211
211
|
jwt_exp: jwtExp,
|
|
212
212
|
client_id: user_three.client_id,
|
|
213
213
|
user_id: user_three.user_id,
|
|
214
214
|
user_agent: user_three.user_agent,
|
|
215
|
-
|
|
215
|
+
connected_at: user_three.connected_at
|
|
216
216
|
});
|
|
217
217
|
|
|
218
218
|
const sdk = await factory.db.sdk_report_events.find({ user_id: user_three.user_id }).toArray();
|
|
219
219
|
expect(sdk).toHaveLength(1);
|
|
220
|
-
expect(new Date(sdk[0].
|
|
220
|
+
expect(new Date(sdk[0].disconnected_at!)).toEqual(disconnectAt);
|
|
221
221
|
const cleaned = removeVolatileFields(sdk);
|
|
222
222
|
expect(cleaned).toMatchSnapshot();
|
|
223
223
|
});
|
|
@@ -226,9 +226,9 @@ describe('SDK reporting storage', async () => {
|
|
|
226
226
|
const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
|
|
227
227
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
228
228
|
|
|
229
|
-
await factory.
|
|
229
|
+
await factory.reportClientConnection({
|
|
230
230
|
sdk: user_week.sdk,
|
|
231
|
-
|
|
231
|
+
connected_at: newConnectAt,
|
|
232
232
|
jwt_exp: jwtExp,
|
|
233
233
|
client_id: user_week.client_id,
|
|
234
234
|
user_id: user_week.user_id,
|
|
@@ -244,10 +244,10 @@ describe('SDK reporting storage', async () => {
|
|
|
244
244
|
it('Should delete rows older than specified range', async () => {
|
|
245
245
|
await deleteData();
|
|
246
246
|
await loadData();
|
|
247
|
-
await factory.
|
|
247
|
+
await factory.deleteOldConnectionData({
|
|
248
248
|
date: weekAgo
|
|
249
249
|
});
|
|
250
|
-
const sdk = await factory.
|
|
250
|
+
const sdk = await factory.getClientConnectionReports({
|
|
251
251
|
start: monthAgo,
|
|
252
252
|
end: now
|
|
253
253
|
});
|