@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,215 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`Connection reporting storage > Should create a connection report if its after a day 1`] = `
|
|
4
|
-
[
|
|
5
|
-
{
|
|
6
|
-
"client_id": "client_week",
|
|
7
|
-
"sdk": "powersync-js/1.24.5",
|
|
8
|
-
"user_agent": "powersync-js/1.21.0 powersync-web Firefox/141 linux",
|
|
9
|
-
"user_id": "user_week",
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"client_id": "client_week",
|
|
13
|
-
"sdk": "powersync-js/1.24.5",
|
|
14
|
-
"user_agent": "powersync-js/1.21.0 powersync-web Firefox/141 linux",
|
|
15
|
-
"user_id": "user_week",
|
|
16
|
-
},
|
|
17
|
-
]
|
|
18
|
-
`;
|
|
19
|
-
|
|
20
|
-
exports[`Connection reporting storage > Should delete rows older than specified range 1`] = `
|
|
21
|
-
{
|
|
22
|
-
"sdks": [
|
|
23
|
-
{
|
|
24
|
-
"clients": 1,
|
|
25
|
-
"sdk": "powersync-dart/1.6.4",
|
|
26
|
-
"users": 1,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"clients": 1,
|
|
30
|
-
"sdk": "powersync-js/1.21.1",
|
|
31
|
-
"users": 1,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"clients": 1,
|
|
35
|
-
"sdk": "powersync-js/1.21.2",
|
|
36
|
-
"users": 1,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"clients": 1,
|
|
40
|
-
"sdk": "powersync-js/1.21.4",
|
|
41
|
-
"users": 1,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"clients": 1,
|
|
45
|
-
"sdk": "powersync-js/1.24.5",
|
|
46
|
-
"users": 1,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
"clients": 1,
|
|
50
|
-
"sdk": "unknown",
|
|
51
|
-
"users": 1,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
"users": 5,
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
exports[`Connection reporting storage > Should update a connected connection report and make it disconnected 1`] = `
|
|
59
|
-
[
|
|
60
|
-
{
|
|
61
|
-
"client_id": "client_three",
|
|
62
|
-
"sdk": "powersync-js/1.21.2",
|
|
63
|
-
"user_agent": "powersync-js/1.21.0 powersync-web Firefox/141 linux",
|
|
64
|
-
"user_id": "user_three",
|
|
65
|
-
},
|
|
66
|
-
]
|
|
67
|
-
`;
|
|
68
|
-
|
|
69
|
-
exports[`Connection reporting storage > Should update a connection report if its within a day 1`] = `
|
|
70
|
-
[
|
|
71
|
-
{
|
|
72
|
-
"client_id": "client_one",
|
|
73
|
-
"sdk": "powersync-dart/1.6.4",
|
|
74
|
-
"user_agent": "powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android",
|
|
75
|
-
"user_id": "user_one",
|
|
76
|
-
},
|
|
77
|
-
]
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
|
-
exports[`Report storage tests > Should show connection report data for user over the past day 1`] = `
|
|
81
|
-
{
|
|
82
|
-
"sdks": [
|
|
83
|
-
{
|
|
84
|
-
"clients": 1,
|
|
85
|
-
"sdk": "powersync-dart/1.6.4",
|
|
86
|
-
"users": 1,
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
"clients": 1,
|
|
90
|
-
"sdk": "powersync-js/1.21.1",
|
|
91
|
-
"users": 1,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
"clients": 1,
|
|
95
|
-
"sdk": "powersync-js/1.21.4",
|
|
96
|
-
"users": 1,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"clients": 1,
|
|
100
|
-
"sdk": "unknown",
|
|
101
|
-
"users": 1,
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
"users": 3,
|
|
105
|
-
}
|
|
106
|
-
`;
|
|
107
|
-
|
|
108
|
-
exports[`Report storage tests > Should show connection report data for user over the past month 1`] = `
|
|
109
|
-
{
|
|
110
|
-
"sdks": [
|
|
111
|
-
{
|
|
112
|
-
"clients": 1,
|
|
113
|
-
"sdk": "powersync-dart/1.6.4",
|
|
114
|
-
"users": 1,
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"clients": 1,
|
|
118
|
-
"sdk": "powersync-js/1.21.1",
|
|
119
|
-
"users": 1,
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"clients": 1,
|
|
123
|
-
"sdk": "powersync-js/1.21.2",
|
|
124
|
-
"users": 1,
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
"clients": 1,
|
|
128
|
-
"sdk": "powersync-js/1.21.4",
|
|
129
|
-
"users": 1,
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
"clients": 1,
|
|
133
|
-
"sdk": "powersync-js/1.23.6",
|
|
134
|
-
"users": 1,
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
"clients": 1,
|
|
138
|
-
"sdk": "powersync-js/1.23.7",
|
|
139
|
-
"users": 1,
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
"clients": 1,
|
|
143
|
-
"sdk": "powersync-js/1.24.5",
|
|
144
|
-
"users": 1,
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"clients": 1,
|
|
148
|
-
"sdk": "unknown",
|
|
149
|
-
"users": 1,
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
"users": 7,
|
|
153
|
-
}
|
|
154
|
-
`;
|
|
155
|
-
|
|
156
|
-
exports[`Report storage tests > Should show connection report data for user over the past week 1`] = `
|
|
157
|
-
{
|
|
158
|
-
"sdks": [
|
|
159
|
-
{
|
|
160
|
-
"clients": 1,
|
|
161
|
-
"sdk": "powersync-dart/1.6.4",
|
|
162
|
-
"users": 1,
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
"clients": 1,
|
|
166
|
-
"sdk": "powersync-js/1.21.1",
|
|
167
|
-
"users": 1,
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
"clients": 1,
|
|
171
|
-
"sdk": "powersync-js/1.21.2",
|
|
172
|
-
"users": 1,
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
"clients": 1,
|
|
176
|
-
"sdk": "powersync-js/1.21.4",
|
|
177
|
-
"users": 1,
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
"clients": 1,
|
|
181
|
-
"sdk": "powersync-js/1.24.5",
|
|
182
|
-
"users": 1,
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
"clients": 1,
|
|
186
|
-
"sdk": "unknown",
|
|
187
|
-
"users": 1,
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
"users": 5,
|
|
191
|
-
}
|
|
192
|
-
`;
|
|
193
|
-
|
|
194
|
-
exports[`Report storage tests > Should show currently connected users 1`] = `
|
|
195
|
-
{
|
|
196
|
-
"sdks": [
|
|
197
|
-
{
|
|
198
|
-
"clients": 1,
|
|
199
|
-
"sdk": "powersync-dart/1.6.4",
|
|
200
|
-
"users": 1,
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
"clients": 1,
|
|
204
|
-
"sdk": "powersync-js/1.21.1",
|
|
205
|
-
"users": 1,
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
"clients": 1,
|
|
209
|
-
"sdk": "unknown",
|
|
210
|
-
"users": 1,
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
"users": 2,
|
|
214
|
-
}
|
|
215
|
-
`;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
2
|
-
import { INITIALIZED_MONGO_REPORT_STORAGE_FACTORY } from './util.js';
|
|
3
|
-
import { register, ReportUserData } from '@powersync/service-core-tests';
|
|
4
|
-
import { event_types } from '@powersync/service-types';
|
|
5
|
-
import { MongoReportStorage } from '@module/storage/MongoReportStorage.js';
|
|
6
|
-
|
|
7
|
-
const userData = register.REPORT_TEST_USERS;
|
|
8
|
-
const dates = register.REPORT_TEST_DATES;
|
|
9
|
-
const factory = await INITIALIZED_MONGO_REPORT_STORAGE_FACTORY();
|
|
10
|
-
|
|
11
|
-
function removeVolatileFields(
|
|
12
|
-
sdks: event_types.ClientConnection[]
|
|
13
|
-
): Partial<event_types.ClientConnection & { _id: string }>[] {
|
|
14
|
-
return sdks.map((sdk: Partial<event_types.ClientConnection & { _id: string }>) => {
|
|
15
|
-
const { _id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
|
|
16
|
-
return {
|
|
17
|
-
...rest
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function loadData(data: ReportUserData, factory: MongoReportStorage) {
|
|
23
|
-
await factory.db.connection_report_events.insertMany(Object.values(data));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function deleteData(factory: MongoReportStorage) {
|
|
27
|
-
await factory.db.connection_report_events.deleteMany();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
beforeAll(async () => {
|
|
31
|
-
await loadData(userData, factory);
|
|
32
|
-
});
|
|
33
|
-
afterAll(async () => {
|
|
34
|
-
await deleteData(factory);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('Report storage tests', async () => {
|
|
38
|
-
await register.registerReportTests(factory);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('Connection reporting storage', async () => {
|
|
42
|
-
it('Should create a connection report if its after a day', async () => {
|
|
43
|
-
const newConnectAt = new Date(
|
|
44
|
-
dates.now.getFullYear(),
|
|
45
|
-
dates.now.getMonth(),
|
|
46
|
-
dates.now.getDate() + 1,
|
|
47
|
-
dates.now.getHours()
|
|
48
|
-
);
|
|
49
|
-
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
50
|
-
|
|
51
|
-
await factory.reportClientConnection({
|
|
52
|
-
sdk: userData.user_week.sdk,
|
|
53
|
-
connected_at: newConnectAt,
|
|
54
|
-
jwt_exp: jwtExp,
|
|
55
|
-
client_id: userData.user_week.client_id,
|
|
56
|
-
user_id: userData.user_week.user_id,
|
|
57
|
-
user_agent: userData.user_week.user_agent
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const sdk = await factory.db.connection_report_events.find({ user_id: userData.user_week.user_id }).toArray();
|
|
61
|
-
expect(sdk).toHaveLength(2);
|
|
62
|
-
const cleaned = removeVolatileFields(sdk);
|
|
63
|
-
expect(cleaned).toMatchSnapshot();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('Should update a connection report if its within a day', async () => {
|
|
67
|
-
const newConnectAt = new Date(
|
|
68
|
-
dates.now.getFullYear(),
|
|
69
|
-
dates.now.getMonth(),
|
|
70
|
-
dates.now.getDate(),
|
|
71
|
-
dates.now.getHours(),
|
|
72
|
-
dates.now.getMinutes() + 20
|
|
73
|
-
);
|
|
74
|
-
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
75
|
-
await factory.reportClientConnection({
|
|
76
|
-
sdk: userData.user_one.sdk,
|
|
77
|
-
connected_at: newConnectAt,
|
|
78
|
-
jwt_exp: jwtExp,
|
|
79
|
-
client_id: userData.user_one.client_id,
|
|
80
|
-
user_id: userData.user_one.user_id,
|
|
81
|
-
user_agent: userData.user_one.user_agent
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const sdk = await factory.db.connection_report_events
|
|
85
|
-
.find({ user_id: userData.user_one.user_id, client_id: userData.user_one.client_id })
|
|
86
|
-
.toArray();
|
|
87
|
-
expect(sdk).toHaveLength(1);
|
|
88
|
-
expect(new Date(sdk[0].connected_at)).toEqual(newConnectAt);
|
|
89
|
-
expect(new Date(sdk[0].jwt_exp!)).toEqual(jwtExp);
|
|
90
|
-
expect(sdk[0].disconnected_at).toBeUndefined();
|
|
91
|
-
const cleaned = removeVolatileFields(sdk);
|
|
92
|
-
expect(cleaned).toMatchSnapshot();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('Should update a connected connection report and make it disconnected', async () => {
|
|
96
|
-
const disconnectAt = new Date(
|
|
97
|
-
dates.now.getFullYear(),
|
|
98
|
-
dates.now.getMonth(),
|
|
99
|
-
dates.now.getDate(),
|
|
100
|
-
dates.now.getHours(),
|
|
101
|
-
dates.now.getMinutes() + 20
|
|
102
|
-
);
|
|
103
|
-
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
104
|
-
|
|
105
|
-
await factory.reportClientDisconnection({
|
|
106
|
-
disconnected_at: disconnectAt,
|
|
107
|
-
jwt_exp: jwtExp,
|
|
108
|
-
client_id: userData.user_three.client_id,
|
|
109
|
-
user_id: userData.user_three.user_id,
|
|
110
|
-
user_agent: userData.user_three.user_agent,
|
|
111
|
-
connected_at: userData.user_three.connected_at
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const sdk = await factory.db.connection_report_events.find({ user_id: userData.user_three.user_id }).toArray();
|
|
115
|
-
expect(sdk).toHaveLength(1);
|
|
116
|
-
expect(new Date(sdk[0].disconnected_at!)).toEqual(disconnectAt);
|
|
117
|
-
const cleaned = removeVolatileFields(sdk);
|
|
118
|
-
expect(cleaned).toMatchSnapshot();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('Should delete rows older than specified range', async () => {
|
|
122
|
-
await deleteData(factory);
|
|
123
|
-
await loadData(userData, factory);
|
|
124
|
-
await factory.deleteOldConnectionData({
|
|
125
|
-
date: dates.weekAgo
|
|
126
|
-
});
|
|
127
|
-
const sdk = await factory.getClientConnectionReports({
|
|
128
|
-
start: dates.monthAgo,
|
|
129
|
-
end: dates.now
|
|
130
|
-
});
|
|
131
|
-
expect(sdk).toMatchSnapshot();
|
|
132
|
-
});
|
|
133
|
-
});
|