@powersync/service-module-postgres-storage 0.0.0-dev-20250813080357 → 0.0.0-dev-20250818104041
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 +12 -9
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/storage/PostgresReportStorageFactory.d.ts +4 -4
- package/dist/@types/storage/PostgresStorageProvider.d.ts +1 -1
- package/dist/migrations/scripts/1684951997326-init.js +3 -3
- package/dist/migrations/scripts/1684951997326-init.js.map +1 -1
- package/dist/storage/PostgresReportStorageFactory.js +21 -21
- package/dist/storage/PostgresReportStorageFactory.js.map +1 -1
- package/dist/storage/batch/PostgresBucketBatch.js +1 -1
- package/dist/storage/batch/PostgresBucketBatch.js.map +1 -1
- package/package.json +9 -9
- package/src/migrations/scripts/1684951997326-init.ts +3 -3
- package/src/storage/PostgresReportStorageFactory.ts +26 -26
- package/src/storage/PostgresStorageProvider.ts +1 -1
- package/src/storage/batch/PostgresBucketBatch.ts +1 -1
- package/test/src/sdk-report-storage.test.ts +34 -34
|
@@ -2,9 +2,9 @@ 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.SdkConnection[]): Partial<event_types.SdkConnection>[] {
|
|
6
6
|
return sdks.map((sdk) => {
|
|
7
|
-
const { id,
|
|
7
|
+
const { id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
|
|
8
8
|
return {
|
|
9
9
|
...rest
|
|
10
10
|
};
|
|
@@ -35,7 +35,7 @@ describe('SDK reporting storage', async () => {
|
|
|
35
35
|
const user_one = {
|
|
36
36
|
user_id: 'user_one',
|
|
37
37
|
client_id: 'client_one',
|
|
38
|
-
|
|
38
|
+
connected_at: now.toISOString(),
|
|
39
39
|
sdk: 'powersync-dart/1.6.4',
|
|
40
40
|
user_agent: 'powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android',
|
|
41
41
|
jwt_exp: nowAdd5minutes.toISOString(),
|
|
@@ -44,7 +44,7 @@ describe('SDK reporting storage', async () => {
|
|
|
44
44
|
const user_two = {
|
|
45
45
|
user_id: 'user_two',
|
|
46
46
|
client_id: 'client_two',
|
|
47
|
-
|
|
47
|
+
connected_at: nowLess5minutes.toISOString(),
|
|
48
48
|
sdk: 'powersync-js/1.21.1',
|
|
49
49
|
user_agent: 'powersync-js/1.21.0 powersync-web Chromium/138 linux',
|
|
50
50
|
jwt_exp: nowAdd5minutes.toISOString(),
|
|
@@ -53,17 +53,17 @@ 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.toISOString(),
|
|
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.toISOString(),
|
|
60
60
|
id: '3'
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const user_four = {
|
|
64
64
|
user_id: 'user_four',
|
|
65
65
|
client_id: 'client_four',
|
|
66
|
-
|
|
66
|
+
connected_at: now.toISOString(),
|
|
67
67
|
sdk: 'powersync-js/1.21.4',
|
|
68
68
|
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
69
69
|
jwt_exp: nowLess5minutes.toISOString(),
|
|
@@ -73,27 +73,27 @@ describe('SDK reporting storage', async () => {
|
|
|
73
73
|
const user_week = {
|
|
74
74
|
user_id: 'user_week',
|
|
75
75
|
client_id: 'client_week',
|
|
76
|
-
|
|
76
|
+
connected_at: weekAgo.toISOString(),
|
|
77
77
|
sdk: 'powersync-js/1.24.5',
|
|
78
78
|
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
79
|
-
|
|
79
|
+
disconnected_at: weekAgo.toISOString(),
|
|
80
80
|
id: 'week'
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
const user_month = {
|
|
84
84
|
user_id: 'user_month',
|
|
85
85
|
client_id: 'client_month',
|
|
86
|
-
|
|
86
|
+
connected_at: monthAgo.toISOString(),
|
|
87
87
|
sdk: 'powersync-js/1.23.6',
|
|
88
88
|
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
89
|
-
|
|
89
|
+
disconnected_at: monthAgo.toISOString(),
|
|
90
90
|
id: 'month'
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
const user_expired = {
|
|
94
94
|
user_id: 'user_expired',
|
|
95
95
|
client_id: 'client_expired',
|
|
96
|
-
|
|
96
|
+
connected_at: monthAgo.toISOString(),
|
|
97
97
|
sdk: 'powersync-js/1.23.7',
|
|
98
98
|
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
99
99
|
jwt_exp: monthAgo.toISOString(),
|
|
@@ -106,18 +106,18 @@ describe('SDK reporting storage', async () => {
|
|
|
106
106
|
sdk_report_events (
|
|
107
107
|
user_id,
|
|
108
108
|
client_id,
|
|
109
|
-
|
|
109
|
+
connected_at,
|
|
110
110
|
sdk,
|
|
111
111
|
user_agent,
|
|
112
112
|
jwt_exp,
|
|
113
113
|
id,
|
|
114
|
-
|
|
114
|
+
disconnected_at
|
|
115
115
|
)
|
|
116
116
|
VALUES
|
|
117
117
|
(
|
|
118
118
|
${{ type: 'varchar', value: user_one.user_id }},
|
|
119
119
|
${{ type: 'varchar', value: user_one.client_id }},
|
|
120
|
-
${{ type: 1184, value: user_one.
|
|
120
|
+
${{ type: 1184, value: user_one.connected_at }},
|
|
121
121
|
${{ type: 'varchar', value: user_one.sdk }},
|
|
122
122
|
${{ type: 'varchar', value: user_one.user_agent }},
|
|
123
123
|
${{ type: 1184, value: user_one.jwt_exp }},
|
|
@@ -127,7 +127,7 @@ describe('SDK reporting storage', async () => {
|
|
|
127
127
|
(
|
|
128
128
|
${{ type: 'varchar', value: user_two.user_id }},
|
|
129
129
|
${{ type: 'varchar', value: user_two.client_id }},
|
|
130
|
-
${{ type: 1184, value: user_two.
|
|
130
|
+
${{ type: 1184, value: user_two.connected_at }},
|
|
131
131
|
${{ type: 'varchar', value: user_two.sdk }},
|
|
132
132
|
${{ type: 'varchar', value: user_two.user_agent }},
|
|
133
133
|
${{ type: 1184, value: user_two.jwt_exp }},
|
|
@@ -137,7 +137,7 @@ describe('SDK reporting storage', async () => {
|
|
|
137
137
|
(
|
|
138
138
|
${{ type: 'varchar', value: user_four.user_id }},
|
|
139
139
|
${{ type: 'varchar', value: user_four.client_id }},
|
|
140
|
-
${{ type: 1184, value: user_four.
|
|
140
|
+
${{ type: 1184, value: user_four.connected_at }},
|
|
141
141
|
${{ type: 'varchar', value: user_four.sdk }},
|
|
142
142
|
${{ type: 'varchar', value: user_four.user_agent }},
|
|
143
143
|
${{ type: 1184, value: user_four.jwt_exp }},
|
|
@@ -147,37 +147,37 @@ describe('SDK reporting storage', async () => {
|
|
|
147
147
|
(
|
|
148
148
|
${{ type: 'varchar', value: user_three.user_id }},
|
|
149
149
|
${{ type: 'varchar', value: user_three.client_id }},
|
|
150
|
-
${{ type: 1184, value: user_three.
|
|
150
|
+
${{ type: 1184, value: user_three.connected_at }},
|
|
151
151
|
${{ type: 'varchar', value: user_three.sdk }},
|
|
152
152
|
${{ type: 'varchar', value: user_three.user_agent }},
|
|
153
153
|
NULL,
|
|
154
154
|
${{ type: 'varchar', value: user_three.id }},
|
|
155
|
-
${{ type: 1184, value: user_three.
|
|
155
|
+
${{ type: 1184, value: user_three.disconnected_at }}
|
|
156
156
|
),
|
|
157
157
|
(
|
|
158
158
|
${{ type: 'varchar', value: user_week.user_id }},
|
|
159
159
|
${{ type: 'varchar', value: user_week.client_id }},
|
|
160
|
-
${{ type: 1184, value: user_week.
|
|
160
|
+
${{ type: 1184, value: user_week.connected_at }},
|
|
161
161
|
${{ type: 'varchar', value: user_week.sdk }},
|
|
162
162
|
${{ type: 'varchar', value: user_week.user_agent }},
|
|
163
163
|
NULL,
|
|
164
164
|
${{ type: 'varchar', value: user_week.id }},
|
|
165
|
-
${{ type: 1184, value: user_week.
|
|
165
|
+
${{ type: 1184, value: user_week.disconnected_at }}
|
|
166
166
|
),
|
|
167
167
|
(
|
|
168
168
|
${{ type: 'varchar', value: user_month.user_id }},
|
|
169
169
|
${{ type: 'varchar', value: user_month.client_id }},
|
|
170
|
-
${{ type: 1184, value: user_month.
|
|
170
|
+
${{ type: 1184, value: user_month.connected_at }},
|
|
171
171
|
${{ type: 'varchar', value: user_month.sdk }},
|
|
172
172
|
${{ type: 'varchar', value: user_month.user_agent }},
|
|
173
173
|
NULL,
|
|
174
174
|
${{ type: 'varchar', value: user_month.id }},
|
|
175
|
-
${{ type: 1184, value: user_month.
|
|
175
|
+
${{ type: 1184, value: user_month.disconnected_at }}
|
|
176
176
|
),
|
|
177
177
|
(
|
|
178
178
|
${{ type: 'varchar', value: user_expired.user_id }},
|
|
179
179
|
${{ type: 'varchar', value: user_expired.client_id }},
|
|
180
|
-
${{ type: 1184, value: user_expired.
|
|
180
|
+
${{ type: 1184, value: user_expired.connected_at }},
|
|
181
181
|
${{ type: 'varchar', value: user_expired.sdk }},
|
|
182
182
|
${{ type: 'varchar', value: user_expired.user_agent }},
|
|
183
183
|
${{ type: 1184, value: user_expired.jwt_exp }},
|
|
@@ -260,7 +260,7 @@ describe('SDK reporting storage', async () => {
|
|
|
260
260
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
261
261
|
await factory.reportSdkConnect({
|
|
262
262
|
sdk: user_one.sdk,
|
|
263
|
-
|
|
263
|
+
connected_at: newConnectAt,
|
|
264
264
|
jwt_exp: jwtExp,
|
|
265
265
|
client_id: user_one.client_id,
|
|
266
266
|
user_id: user_one.user_id,
|
|
@@ -268,11 +268,11 @@ 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.SdkConnection>();
|
|
272
272
|
expect(sdk).toHaveLength(1);
|
|
273
|
-
expect(new Date(sdk[0].
|
|
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());
|
|
275
|
-
expect(sdk[0].
|
|
275
|
+
expect(sdk[0].disconnected_at).toBeNull();
|
|
276
276
|
const cleaned = removeVolatileFields(sdk);
|
|
277
277
|
expect(cleaned).toMatchSnapshot();
|
|
278
278
|
});
|
|
@@ -288,18 +288,18 @@ describe('SDK reporting storage', async () => {
|
|
|
288
288
|
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
289
289
|
|
|
290
290
|
await factory.reportSdkDisconnect({
|
|
291
|
-
|
|
291
|
+
disconnected_at: disconnectAt,
|
|
292
292
|
jwt_exp: jwtExp,
|
|
293
293
|
client_id: user_three.client_id,
|
|
294
294
|
user_id: user_three.user_id,
|
|
295
295
|
user_agent: user_three.user_agent,
|
|
296
|
-
|
|
296
|
+
connected_at: yesterday
|
|
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.SdkConnection>();
|
|
301
301
|
expect(sdk).toHaveLength(1);
|
|
302
|
-
expect(new Date(sdk[0].
|
|
302
|
+
expect(new Date(sdk[0].disconnected_at!).toISOString()).toEqual(disconnectAt.toISOString());
|
|
303
303
|
const cleaned = removeVolatileFields(sdk);
|
|
304
304
|
expect(cleaned).toMatchSnapshot();
|
|
305
305
|
});
|
|
@@ -310,7 +310,7 @@ describe('SDK reporting storage', async () => {
|
|
|
310
310
|
|
|
311
311
|
await factory.reportSdkConnect({
|
|
312
312
|
sdk: user_week.sdk,
|
|
313
|
-
|
|
313
|
+
connected_at: newConnectAt,
|
|
314
314
|
jwt_exp: jwtExp,
|
|
315
315
|
client_id: user_week.client_id,
|
|
316
316
|
user_id: user_week.user_id,
|
|
@@ -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.SdkConnection>();
|
|
322
322
|
expect(sdk).toHaveLength(2);
|
|
323
323
|
const cleaned = removeVolatileFields(sdk);
|
|
324
324
|
expect(cleaned).toMatchSnapshot();
|