@powersync/service-module-postgres-storage 0.0.0-dev-20250818104041 → 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 +10 -9
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/storage/PostgresReportStorageFactory.d.ts +6 -6
- package/dist/storage/PostgresReportStorageFactory.js +5 -5
- package/dist/storage/PostgresReportStorageFactory.js.map +1 -1
- package/package.json +10 -10
- package/src/storage/PostgresReportStorageFactory.ts +9 -15
- package/test/src/__snapshots__/storage_sync.test.ts.snap +197 -0
- package/test/src/sdk-report-storage.test.ts +14 -14
|
@@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { POSTGRES_REPORT_STORAGE_FACTORY } from './util.js';
|
|
3
3
|
import { event_types } from '@powersync/service-types';
|
|
4
4
|
|
|
5
|
-
function removeVolatileFields(sdks: event_types.
|
|
5
|
+
function removeVolatileFields(sdks: event_types.ClientConnection[]): Partial<event_types.ClientConnection>[] {
|
|
6
6
|
return sdks.map((sdk) => {
|
|
7
7
|
const { id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
|
|
8
8
|
return {
|
|
@@ -199,7 +199,7 @@ describe('SDK reporting storage', async () => {
|
|
|
199
199
|
await deleteData();
|
|
200
200
|
});
|
|
201
201
|
it('Should show connected users with start range', async () => {
|
|
202
|
-
const current = await factory.
|
|
202
|
+
const current = await factory.getConnectedClients({
|
|
203
203
|
range: {
|
|
204
204
|
start: new Date(
|
|
205
205
|
now.getFullYear(),
|
|
@@ -213,7 +213,7 @@ describe('SDK reporting storage', async () => {
|
|
|
213
213
|
expect(current).toMatchSnapshot();
|
|
214
214
|
});
|
|
215
215
|
it('Should show connected users with start range and end range', async () => {
|
|
216
|
-
const current = await factory.
|
|
216
|
+
const current = await factory.getConnectedClients({
|
|
217
217
|
range: {
|
|
218
218
|
end: nowLess5minutes.toISOString(),
|
|
219
219
|
start: new Date(
|
|
@@ -228,21 +228,21 @@ describe('SDK reporting storage', async () => {
|
|
|
228
228
|
expect(current).toMatchSnapshot();
|
|
229
229
|
});
|
|
230
230
|
it('Should show SDK scrape data for user over the past month', async () => {
|
|
231
|
-
const sdk = await factory.
|
|
231
|
+
const sdk = await factory.getClientConnectionReports({
|
|
232
232
|
start: monthAgo,
|
|
233
233
|
end: now
|
|
234
234
|
});
|
|
235
235
|
expect(sdk).toMatchSnapshot();
|
|
236
236
|
});
|
|
237
237
|
it('Should show SDK scrape data for user over the past week', async () => {
|
|
238
|
-
const sdk = await factory.
|
|
238
|
+
const sdk = await factory.getClientConnectionReports({
|
|
239
239
|
start: weekAgo,
|
|
240
240
|
end: now
|
|
241
241
|
});
|
|
242
242
|
expect(sdk).toMatchSnapshot();
|
|
243
243
|
});
|
|
244
244
|
it('Should show SDK scrape data for user over the past day', async () => {
|
|
245
|
-
const sdk = await factory.
|
|
245
|
+
const sdk = await factory.getClientConnectionReports({
|
|
246
246
|
start: dayAgo,
|
|
247
247
|
end: now
|
|
248
248
|
});
|
|
@@ -258,7 +258,7 @@ describe('SDK reporting storage', async () => {
|
|
|
258
258
|
now.getMinutes() + 20
|
|
259
259
|
);
|
|
260
260
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
261
|
-
await factory.
|
|
261
|
+
await factory.reportClientConnection({
|
|
262
262
|
sdk: user_one.sdk,
|
|
263
263
|
connected_at: newConnectAt,
|
|
264
264
|
jwt_exp: jwtExp,
|
|
@@ -268,7 +268,7 @@ describe('SDK reporting storage', async () => {
|
|
|
268
268
|
});
|
|
269
269
|
|
|
270
270
|
const sdk = await factory.db
|
|
271
|
-
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_one.user_id }}`.rows<event_types.
|
|
271
|
+
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_one.user_id }}`.rows<event_types.ClientConnection>();
|
|
272
272
|
expect(sdk).toHaveLength(1);
|
|
273
273
|
expect(new Date(sdk[0].connected_at).toISOString()).toEqual(newConnectAt.toISOString());
|
|
274
274
|
expect(new Date(sdk[0].jwt_exp!).toISOString()).toEqual(jwtExp.toISOString());
|
|
@@ -287,7 +287,7 @@ describe('SDK reporting storage', async () => {
|
|
|
287
287
|
);
|
|
288
288
|
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
289
289
|
|
|
290
|
-
await factory.
|
|
290
|
+
await factory.reportClientDisconnection({
|
|
291
291
|
disconnected_at: disconnectAt,
|
|
292
292
|
jwt_exp: jwtExp,
|
|
293
293
|
client_id: user_three.client_id,
|
|
@@ -297,7 +297,7 @@ describe('SDK reporting storage', async () => {
|
|
|
297
297
|
});
|
|
298
298
|
|
|
299
299
|
const sdk = await factory.db
|
|
300
|
-
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_three.user_id }}`.rows<event_types.
|
|
300
|
+
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_three.user_id }}`.rows<event_types.ClientConnection>();
|
|
301
301
|
expect(sdk).toHaveLength(1);
|
|
302
302
|
expect(new Date(sdk[0].disconnected_at!).toISOString()).toEqual(disconnectAt.toISOString());
|
|
303
303
|
const cleaned = removeVolatileFields(sdk);
|
|
@@ -308,7 +308,7 @@ describe('SDK reporting storage', async () => {
|
|
|
308
308
|
const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
|
|
309
309
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
310
310
|
|
|
311
|
-
await factory.
|
|
311
|
+
await factory.reportClientConnection({
|
|
312
312
|
sdk: user_week.sdk,
|
|
313
313
|
connected_at: newConnectAt,
|
|
314
314
|
jwt_exp: jwtExp,
|
|
@@ -318,7 +318,7 @@ describe('SDK reporting storage', async () => {
|
|
|
318
318
|
});
|
|
319
319
|
|
|
320
320
|
const sdk = await factory.db
|
|
321
|
-
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_week.user_id }}`.rows<event_types.
|
|
321
|
+
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_week.user_id }}`.rows<event_types.ClientConnection>();
|
|
322
322
|
expect(sdk).toHaveLength(2);
|
|
323
323
|
const cleaned = removeVolatileFields(sdk);
|
|
324
324
|
expect(cleaned).toMatchSnapshot();
|
|
@@ -327,10 +327,10 @@ describe('SDK reporting storage', async () => {
|
|
|
327
327
|
it('Should delete rows older than specified range', async () => {
|
|
328
328
|
await deleteData();
|
|
329
329
|
await loadData();
|
|
330
|
-
await factory.
|
|
330
|
+
await factory.deleteOldConnectionData({
|
|
331
331
|
date: weekAgo
|
|
332
332
|
});
|
|
333
|
-
const sdk = await factory.
|
|
333
|
+
const sdk = await factory.getClientConnectionReports({
|
|
334
334
|
start: monthAgo,
|
|
335
335
|
end: now
|
|
336
336
|
});
|