@powersync/service-module-postgres-storage 0.0.0-dev-20250730153301 → 0.0.0-dev-20250804094552
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 +9 -8
- package/dist/.tsbuildinfo +1 -1
- package/dist/migrations/scripts/1684951997326-init.js +16 -0
- package/dist/migrations/scripts/1684951997326-init.js.map +1 -1
- package/dist/storage/PostgresReportStorageFactory.js +8 -9
- package/dist/storage/PostgresReportStorageFactory.js.map +1 -1
- package/dist/utils/db.js +1 -0
- package/dist/utils/db.js.map +1 -1
- package/package.json +8 -8
- package/src/migrations/scripts/1684951997326-init.ts +20 -0
- package/src/storage/PostgresReportStorageFactory.ts +8 -10
- package/src/utils/db.ts +1 -0
- package/test/src/__snapshots__/sdk-report-storage.test.ts.snap +188 -0
- package/test/src/sdk-report-storage.test.ts +333 -5
- package/test/src/util.ts +1 -3
- package/dist/@types/migrations/scripts/1753871047719-sdk_report.d.ts +0 -3
- package/dist/migrations/scripts/1753871047719-sdk_report.js +0 -109
- package/dist/migrations/scripts/1753871047719-sdk_report.js.map +0 -1
- package/src/migrations/scripts/1753871047719-sdk_report.ts +0 -45
|
@@ -1,11 +1,339 @@
|
|
|
1
|
-
import { beforeAll, describe, it } from 'vitest';
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
2
2
|
import { POSTGRES_REPORT_STORAGE_FACTORY } from './util.js';
|
|
3
|
+
import { event_types } from '@powersync/service-types';
|
|
4
|
+
|
|
5
|
+
function removeVolatileFields(sdks: event_types.SdkConnectDocument[]): Partial<event_types.SdkConnectDocument>[] {
|
|
6
|
+
return sdks.map((sdk) => {
|
|
7
|
+
const { id, disconnect_at, connect_at, jwt_exp, ...rest } = sdk;
|
|
8
|
+
return {
|
|
9
|
+
...rest
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('SDK reporting storage', async () => {
|
|
15
|
+
const factory = await POSTGRES_REPORT_STORAGE_FACTORY();
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const nowAdd5minutes = new Date(
|
|
18
|
+
now.getFullYear(),
|
|
19
|
+
now.getMonth(),
|
|
20
|
+
now.getDate(),
|
|
21
|
+
now.getHours(),
|
|
22
|
+
now.getMinutes() + 5
|
|
23
|
+
);
|
|
24
|
+
const nowLess5minutes = new Date(
|
|
25
|
+
now.getFullYear(),
|
|
26
|
+
now.getMonth(),
|
|
27
|
+
now.getDate(),
|
|
28
|
+
now.getHours(),
|
|
29
|
+
now.getMinutes() - 5
|
|
30
|
+
);
|
|
31
|
+
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
|
|
32
|
+
const weekAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7);
|
|
33
|
+
const monthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
|
|
34
|
+
const user_one = {
|
|
35
|
+
user_id: 'user_one',
|
|
36
|
+
client_id: 'client_one',
|
|
37
|
+
connect_at: now.toISOString(),
|
|
38
|
+
sdk: 'powersync-dart/1.6.4',
|
|
39
|
+
user_agent: 'powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android',
|
|
40
|
+
jwt_exp: nowAdd5minutes.toISOString(),
|
|
41
|
+
id: '1'
|
|
42
|
+
};
|
|
43
|
+
const user_two = {
|
|
44
|
+
user_id: 'user_two',
|
|
45
|
+
client_id: 'client_two',
|
|
46
|
+
connect_at: nowLess5minutes.toISOString(),
|
|
47
|
+
sdk: 'powersync-js/1.21.1',
|
|
48
|
+
user_agent: 'powersync-js/1.21.0 powersync-web Chromium/138 linux',
|
|
49
|
+
jwt_exp: nowAdd5minutes.toISOString(),
|
|
50
|
+
id: '2'
|
|
51
|
+
};
|
|
52
|
+
const user_three = {
|
|
53
|
+
user_id: 'user_three',
|
|
54
|
+
client_id: 'client_three',
|
|
55
|
+
connect_at: yesterday.toISOString(),
|
|
56
|
+
sdk: 'powersync-js/1.21.2',
|
|
57
|
+
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
58
|
+
disconnect_at: yesterday.toISOString(),
|
|
59
|
+
id: '3'
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const user_four = {
|
|
63
|
+
user_id: 'user_four',
|
|
64
|
+
client_id: 'client_four',
|
|
65
|
+
connect_at: now.toISOString(),
|
|
66
|
+
sdk: 'powersync-js/1.21.4',
|
|
67
|
+
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
68
|
+
jwt_exp: nowLess5minutes.toISOString(),
|
|
69
|
+
id: '4'
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const user_week = {
|
|
73
|
+
user_id: 'user_week',
|
|
74
|
+
client_id: 'client_week',
|
|
75
|
+
connect_at: weekAgo.toISOString(),
|
|
76
|
+
sdk: 'powersync-js/1.24.5',
|
|
77
|
+
user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
|
|
78
|
+
disconnect_at: weekAgo.toISOString(),
|
|
79
|
+
id: 'week'
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const user_month = {
|
|
83
|
+
user_id: 'user_month',
|
|
84
|
+
client_id: 'client_month',
|
|
85
|
+
connect_at: monthAgo.toISOString(),
|
|
86
|
+
sdk: 'powersync-js/1.23.6',
|
|
87
|
+
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
88
|
+
disconnect_at: monthAgo.toISOString(),
|
|
89
|
+
id: 'month'
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const user_expired = {
|
|
93
|
+
user_id: 'user_expired',
|
|
94
|
+
client_id: 'client_expired',
|
|
95
|
+
connect_at: monthAgo.toISOString(),
|
|
96
|
+
sdk: 'powersync-js/1.23.7',
|
|
97
|
+
user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
|
|
98
|
+
jwt_exp: monthAgo.toISOString(),
|
|
99
|
+
id: 'expired'
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
async function loadData() {
|
|
103
|
+
await factory.db.sql`
|
|
104
|
+
INSERT INTO
|
|
105
|
+
sdk_report_events (
|
|
106
|
+
user_id,
|
|
107
|
+
client_id,
|
|
108
|
+
connect_at,
|
|
109
|
+
sdk,
|
|
110
|
+
user_agent,
|
|
111
|
+
jwt_exp,
|
|
112
|
+
id,
|
|
113
|
+
disconnect_at
|
|
114
|
+
)
|
|
115
|
+
VALUES
|
|
116
|
+
(
|
|
117
|
+
${{ type: 'varchar', value: user_one.user_id }},
|
|
118
|
+
${{ type: 'varchar', value: user_one.client_id }},
|
|
119
|
+
${{ type: 1184, value: user_one.connect_at }},
|
|
120
|
+
${{ type: 'varchar', value: user_one.sdk }},
|
|
121
|
+
${{ type: 'varchar', value: user_one.user_agent }},
|
|
122
|
+
${{ type: 1184, value: user_one.jwt_exp }},
|
|
123
|
+
${{ type: 'varchar', value: user_one.id }},
|
|
124
|
+
NULL
|
|
125
|
+
),
|
|
126
|
+
(
|
|
127
|
+
${{ type: 'varchar', value: user_two.user_id }},
|
|
128
|
+
${{ type: 'varchar', value: user_two.client_id }},
|
|
129
|
+
${{ type: 1184, value: user_two.connect_at }},
|
|
130
|
+
${{ type: 'varchar', value: user_two.sdk }},
|
|
131
|
+
${{ type: 'varchar', value: user_two.user_agent }},
|
|
132
|
+
${{ type: 1184, value: user_two.jwt_exp }},
|
|
133
|
+
${{ type: 'varchar', value: user_two.id }},
|
|
134
|
+
NULL
|
|
135
|
+
),
|
|
136
|
+
(
|
|
137
|
+
${{ type: 'varchar', value: user_four.user_id }},
|
|
138
|
+
${{ type: 'varchar', value: user_four.client_id }},
|
|
139
|
+
${{ type: 1184, value: user_four.connect_at }},
|
|
140
|
+
${{ type: 'varchar', value: user_four.sdk }},
|
|
141
|
+
${{ type: 'varchar', value: user_four.user_agent }},
|
|
142
|
+
${{ type: 1184, value: user_four.jwt_exp }},
|
|
143
|
+
${{ type: 'varchar', value: user_four.id }},
|
|
144
|
+
NULL
|
|
145
|
+
),
|
|
146
|
+
(
|
|
147
|
+
${{ type: 'varchar', value: user_three.user_id }},
|
|
148
|
+
${{ type: 'varchar', value: user_three.client_id }},
|
|
149
|
+
${{ type: 1184, value: user_three.connect_at }},
|
|
150
|
+
${{ type: 'varchar', value: user_three.sdk }},
|
|
151
|
+
${{ type: 'varchar', value: user_three.user_agent }},
|
|
152
|
+
NULL,
|
|
153
|
+
${{ type: 'varchar', value: user_three.id }},
|
|
154
|
+
${{ type: 1184, value: user_three.disconnect_at }}
|
|
155
|
+
),
|
|
156
|
+
(
|
|
157
|
+
${{ type: 'varchar', value: user_week.user_id }},
|
|
158
|
+
${{ type: 'varchar', value: user_week.client_id }},
|
|
159
|
+
${{ type: 1184, value: user_week.connect_at }},
|
|
160
|
+
${{ type: 'varchar', value: user_week.sdk }},
|
|
161
|
+
${{ type: 'varchar', value: user_week.user_agent }},
|
|
162
|
+
NULL,
|
|
163
|
+
${{ type: 'varchar', value: user_week.id }},
|
|
164
|
+
${{ type: 1184, value: user_week.disconnect_at }}
|
|
165
|
+
),
|
|
166
|
+
(
|
|
167
|
+
${{ type: 'varchar', value: user_month.user_id }},
|
|
168
|
+
${{ type: 'varchar', value: user_month.client_id }},
|
|
169
|
+
${{ type: 1184, value: user_month.connect_at }},
|
|
170
|
+
${{ type: 'varchar', value: user_month.sdk }},
|
|
171
|
+
${{ type: 'varchar', value: user_month.user_agent }},
|
|
172
|
+
NULL,
|
|
173
|
+
${{ type: 'varchar', value: user_month.id }},
|
|
174
|
+
${{ type: 1184, value: user_month.disconnect_at }}
|
|
175
|
+
),
|
|
176
|
+
(
|
|
177
|
+
${{ type: 'varchar', value: user_expired.user_id }},
|
|
178
|
+
${{ type: 'varchar', value: user_expired.client_id }},
|
|
179
|
+
${{ type: 1184, value: user_expired.connect_at }},
|
|
180
|
+
${{ type: 'varchar', value: user_expired.sdk }},
|
|
181
|
+
${{ type: 'varchar', value: user_expired.user_agent }},
|
|
182
|
+
${{ type: 1184, value: user_expired.jwt_exp }},
|
|
183
|
+
${{ type: 'varchar', value: user_expired.id }},
|
|
184
|
+
NULL
|
|
185
|
+
)
|
|
186
|
+
`.execute();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function deleteData() {
|
|
190
|
+
return factory.db.sql`TRUNCATE TABLE sdk_report_events`.execute();
|
|
191
|
+
}
|
|
3
192
|
|
|
4
|
-
describe('SDK reporting storage', () => {
|
|
5
193
|
beforeAll(async () => {
|
|
6
|
-
|
|
194
|
+
await loadData();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
afterAll(async () => {
|
|
198
|
+
await deleteData();
|
|
199
|
+
});
|
|
200
|
+
it('Should show connected users with start range', async () => {
|
|
201
|
+
const current = await factory.listCurrentConnections({
|
|
202
|
+
range: {
|
|
203
|
+
start_date: new Date(
|
|
204
|
+
now.getFullYear(),
|
|
205
|
+
now.getMonth(),
|
|
206
|
+
now.getDate(),
|
|
207
|
+
now.getHours(),
|
|
208
|
+
now.getMinutes() - 1
|
|
209
|
+
).toISOString()
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
expect(current).toMatchSnapshot();
|
|
213
|
+
});
|
|
214
|
+
it('Should show connected users with start range and end range', async () => {
|
|
215
|
+
const current = await factory.listCurrentConnections({
|
|
216
|
+
range: {
|
|
217
|
+
end_date: nowLess5minutes.toISOString(),
|
|
218
|
+
start_date: new Date(
|
|
219
|
+
now.getFullYear(),
|
|
220
|
+
now.getMonth(),
|
|
221
|
+
now.getDate(),
|
|
222
|
+
now.getHours(),
|
|
223
|
+
now.getMinutes() - 6
|
|
224
|
+
).toISOString()
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
expect(current).toMatchSnapshot();
|
|
228
|
+
});
|
|
229
|
+
it('Should show SDK scrape data for user over the past month', async () => {
|
|
230
|
+
const sdk = await factory.scrapeSdkData({
|
|
231
|
+
interval: 1,
|
|
232
|
+
timeframe: 'month'
|
|
233
|
+
});
|
|
234
|
+
expect(sdk).toMatchSnapshot();
|
|
7
235
|
});
|
|
8
|
-
it('Should
|
|
9
|
-
const
|
|
236
|
+
it('Should show SDK scrape data for user over the past week', async () => {
|
|
237
|
+
const sdk = await factory.scrapeSdkData({
|
|
238
|
+
interval: 1,
|
|
239
|
+
timeframe: 'week'
|
|
240
|
+
});
|
|
241
|
+
expect(sdk).toMatchSnapshot();
|
|
242
|
+
});
|
|
243
|
+
it('Should show SDK scrape data for user over the past day', async () => {
|
|
244
|
+
const sdk = await factory.scrapeSdkData({
|
|
245
|
+
interval: 1,
|
|
246
|
+
timeframe: 'day'
|
|
247
|
+
});
|
|
248
|
+
expect(sdk).toMatchSnapshot();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('Should update a sdk event if its within a day', async () => {
|
|
252
|
+
const newConnectAt = new Date(
|
|
253
|
+
now.getFullYear(),
|
|
254
|
+
now.getMonth(),
|
|
255
|
+
now.getDate(),
|
|
256
|
+
now.getHours(),
|
|
257
|
+
now.getMinutes() + 20
|
|
258
|
+
);
|
|
259
|
+
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
260
|
+
await factory.reportSdkConnect({
|
|
261
|
+
sdk: user_one.sdk,
|
|
262
|
+
connect_at: newConnectAt,
|
|
263
|
+
jwt_exp: jwtExp,
|
|
264
|
+
client_id: user_one.client_id,
|
|
265
|
+
user_id: user_one.user_id,
|
|
266
|
+
user_agent: user_one.user_agent
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const sdk = await factory.db
|
|
270
|
+
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_one.user_id }}`.rows<event_types.SdkConnectDocument>();
|
|
271
|
+
expect(sdk).toHaveLength(1);
|
|
272
|
+
expect(new Date(sdk[0].connect_at).toISOString()).toEqual(newConnectAt.toISOString());
|
|
273
|
+
expect(new Date(sdk[0].jwt_exp!).toISOString()).toEqual(jwtExp.toISOString());
|
|
274
|
+
expect(sdk[0].disconnect_at).toBeNull();
|
|
275
|
+
const cleaned = removeVolatileFields(sdk);
|
|
276
|
+
expect(cleaned).toMatchSnapshot();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('Should update a connected sdk event and make it disconnected', async () => {
|
|
280
|
+
const disconnectAt = new Date(
|
|
281
|
+
now.getFullYear(),
|
|
282
|
+
now.getMonth(),
|
|
283
|
+
now.getDate(),
|
|
284
|
+
now.getHours(),
|
|
285
|
+
now.getMinutes() + 20
|
|
286
|
+
);
|
|
287
|
+
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
288
|
+
|
|
289
|
+
await factory.reportSdkDisconnect({
|
|
290
|
+
disconnect_at: disconnectAt,
|
|
291
|
+
jwt_exp: jwtExp,
|
|
292
|
+
client_id: user_three.client_id,
|
|
293
|
+
user_id: user_three.user_id,
|
|
294
|
+
user_agent: user_three.user_agent,
|
|
295
|
+
connect_at: yesterday
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const sdk = await factory.db
|
|
299
|
+
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_three.user_id }}`.rows<event_types.SdkConnectDocument>();
|
|
300
|
+
expect(sdk).toHaveLength(1);
|
|
301
|
+
expect(new Date(sdk[0].disconnect_at!).toISOString()).toEqual(disconnectAt.toISOString());
|
|
302
|
+
const cleaned = removeVolatileFields(sdk);
|
|
303
|
+
expect(cleaned).toMatchSnapshot();
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('Should create a sdk event if its after a day', async () => {
|
|
307
|
+
const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
|
|
308
|
+
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
309
|
+
|
|
310
|
+
await factory.reportSdkConnect({
|
|
311
|
+
sdk: user_week.sdk,
|
|
312
|
+
connect_at: newConnectAt,
|
|
313
|
+
jwt_exp: jwtExp,
|
|
314
|
+
client_id: user_week.client_id,
|
|
315
|
+
user_id: user_week.user_id,
|
|
316
|
+
user_agent: user_week.user_agent
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
const sdk = await factory.db
|
|
320
|
+
.sql`SELECT * FROM sdk_report_events WHERE user_id = ${{ type: 'varchar', value: user_week.user_id }}`.rows<event_types.SdkConnectDocument>();
|
|
321
|
+
expect(sdk).toHaveLength(2);
|
|
322
|
+
const cleaned = removeVolatileFields(sdk);
|
|
323
|
+
expect(cleaned).toMatchSnapshot();
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('Should delete rows older than specified range', async () => {
|
|
327
|
+
await deleteData();
|
|
328
|
+
await loadData();
|
|
329
|
+
await factory.deleteOldSdkData({
|
|
330
|
+
interval: 1,
|
|
331
|
+
timeframe: 'week'
|
|
332
|
+
});
|
|
333
|
+
const sdk = await factory.scrapeSdkData({
|
|
334
|
+
interval: 1,
|
|
335
|
+
timeframe: 'month'
|
|
336
|
+
});
|
|
337
|
+
expect(sdk).toMatchSnapshot();
|
|
10
338
|
});
|
|
11
339
|
});
|
package/test/src/util.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import { normalizePostgresStorageConfig } from '../../src
|
|
4
|
-
import { PostgresMigrationAgent } from '../../src/migrations/PostgresMigrationAgent.js';
|
|
5
|
-
import { postgresTestSetup } from '../../src/storage/PostgresTestStorageFactoryGenerator.js';
|
|
3
|
+
import { normalizePostgresStorageConfig, PostgresMigrationAgent, postgresTestSetup } from '../../src/index.js';
|
|
6
4
|
import { env } from './env.js';
|
|
7
5
|
|
|
8
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
|
-
import { openMigrationDB } from '../migration-utils.js';
|
|
54
|
-
export const up = async (context) => {
|
|
55
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
56
|
-
try {
|
|
57
|
-
const { service_context: { configuration } } = context;
|
|
58
|
-
const client = __addDisposableResource(env_1, openMigrationDB(configuration.storage), true);
|
|
59
|
-
await client.transaction(async (db) => {
|
|
60
|
-
await db.sql `
|
|
61
|
-
CREATE TABLE IF NOT EXISTS sdk_report_events (
|
|
62
|
-
id TEXT PRIMARY KEY,
|
|
63
|
-
user_agent TEXT NOT NULL,
|
|
64
|
-
client_id TEXT NOT NULL,
|
|
65
|
-
user_id TEXT NOT NULL,
|
|
66
|
-
sdk TEXT NOT NULL,
|
|
67
|
-
jwt_exp TIMESTAMP WITH TIME ZONE,
|
|
68
|
-
connect_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
69
|
-
disconnect_at TIMESTAMP WITH TIME ZONE
|
|
70
|
-
)
|
|
71
|
-
`.execute();
|
|
72
|
-
await db.sql `
|
|
73
|
-
CREATE INDEX IF NOT EXISTS sdk_list_index ON sdk_report_events (connect_at, jwt_exp, disconnect_at)
|
|
74
|
-
`.execute();
|
|
75
|
-
await db.sql `CREATE INDEX IF NOT EXISTS sdk_user_id_index ON sdk_report_events (user_id)`.execute();
|
|
76
|
-
await db.sql `CREATE INDEX IF NOT EXISTS sdk_client_id_index ON sdk_report_events (client_id)`.execute();
|
|
77
|
-
await db.sql `CREATE INDEX IF NOT EXISTS sdk_index ON sdk_report_events (sdk)`.execute();
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (e_1) {
|
|
81
|
-
env_1.error = e_1;
|
|
82
|
-
env_1.hasError = true;
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
const result_1 = __disposeResources(env_1);
|
|
86
|
-
if (result_1)
|
|
87
|
-
await result_1;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
export const down = async (context) => {
|
|
91
|
-
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
92
|
-
try {
|
|
93
|
-
const { service_context: { configuration } } = context;
|
|
94
|
-
const client = __addDisposableResource(env_2, openMigrationDB(configuration.storage), true);
|
|
95
|
-
client.lockConnection(async (db) => {
|
|
96
|
-
await db.sql `DROP TABLE IF EXISTS sdk_report_events`.execute();
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
catch (e_2) {
|
|
100
|
-
env_2.error = e_2;
|
|
101
|
-
env_2.hasError = true;
|
|
102
|
-
}
|
|
103
|
-
finally {
|
|
104
|
-
const result_2 = __disposeResources(env_2);
|
|
105
|
-
if (result_2)
|
|
106
|
-
await result_2;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
//# sourceMappingURL=1753871047719-sdk_report.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"1753871047719-sdk_report.js","sourceRoot":"","sources":["../../../src/migrations/scripts/1753871047719-sdk_report.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;;;QACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;QACZ,MAAY,MAAM,kCAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,OAAA,CAAC;QAE5D,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YACpC,MAAM,EAAE,CAAC,GAAG,CAAA;;;;;;;;;;;KAWX,CAAC,OAAO,EAAE,CAAC;YAEZ,MAAM,EAAE,CAAC,GAAG,CAAA;;KAEX,CAAC,OAAO,EAAE,CAAC;YAEZ,MAAM,EAAE,CAAC,GAAG,CAAA,6EAA6E,CAAC,OAAO,EAAE,CAAC;YAEpG,MAAM,EAAE,CAAC,GAAG,CAAA,iFAAiF,CAAC,OAAO,EAAE,CAAC;YAExG,MAAM,EAAE,CAAC,GAAG,CAAA,iEAAiE,CAAC,OAAO,EAAE,CAAC;QAC1F,CAAC,CAAC,CAAC;;;;;;;;;;;CACJ,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;;;QAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;QACZ,MAAY,MAAM,kCAAG,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,OAAA,CAAC;QAC5D,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YACjC,MAAM,EAAE,CAAC,GAAG,CAAA,wCAAwC,CAAC,OAAO,EAAE,CAAC;QACjE,CAAC,CAAC,CAAC;;;;;;;;;;;CACJ,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { migrations } from '@powersync/service-core';
|
|
2
|
-
|
|
3
|
-
import { openMigrationDB } from '../migration-utils.js';
|
|
4
|
-
|
|
5
|
-
export const up: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
6
|
-
const {
|
|
7
|
-
service_context: { configuration }
|
|
8
|
-
} = context;
|
|
9
|
-
await using client = openMigrationDB(configuration.storage);
|
|
10
|
-
|
|
11
|
-
await client.transaction(async (db) => {
|
|
12
|
-
await db.sql`
|
|
13
|
-
CREATE TABLE IF NOT EXISTS sdk_report_events (
|
|
14
|
-
id TEXT PRIMARY KEY,
|
|
15
|
-
user_agent TEXT NOT NULL,
|
|
16
|
-
client_id TEXT NOT NULL,
|
|
17
|
-
user_id TEXT NOT NULL,
|
|
18
|
-
sdk TEXT NOT NULL,
|
|
19
|
-
jwt_exp TIMESTAMP WITH TIME ZONE,
|
|
20
|
-
connect_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
21
|
-
disconnect_at TIMESTAMP WITH TIME ZONE
|
|
22
|
-
)
|
|
23
|
-
`.execute();
|
|
24
|
-
|
|
25
|
-
await db.sql`
|
|
26
|
-
CREATE INDEX IF NOT EXISTS sdk_list_index ON sdk_report_events (connect_at, jwt_exp, disconnect_at)
|
|
27
|
-
`.execute();
|
|
28
|
-
|
|
29
|
-
await db.sql`CREATE INDEX IF NOT EXISTS sdk_user_id_index ON sdk_report_events (user_id)`.execute();
|
|
30
|
-
|
|
31
|
-
await db.sql`CREATE INDEX IF NOT EXISTS sdk_client_id_index ON sdk_report_events (client_id)`.execute();
|
|
32
|
-
|
|
33
|
-
await db.sql`CREATE INDEX IF NOT EXISTS sdk_index ON sdk_report_events (sdk)`.execute();
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const down: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
38
|
-
const {
|
|
39
|
-
service_context: { configuration }
|
|
40
|
-
} = context;
|
|
41
|
-
await using client = openMigrationDB(configuration.storage);
|
|
42
|
-
client.lockConnection(async (db) => {
|
|
43
|
-
await db.sql`DROP TABLE IF EXISTS sdk_report_events`.execute();
|
|
44
|
-
});
|
|
45
|
-
};
|