@powersync/service-module-mongodb-storage 0.0.0-dev-20250819134004 → 0.0.0-dev-20250825132649

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +9 -7
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/migrations/db/migrations/1752661449910-connection-reporting.js +36 -0
  6. package/dist/migrations/db/migrations/1752661449910-connection-reporting.js.map +1 -0
  7. package/dist/storage/MongoBucketStorage.js +1 -1
  8. package/dist/storage/MongoBucketStorage.js.map +1 -1
  9. package/dist/storage/MongoReportStorage.d.ts +2 -3
  10. package/dist/storage/MongoReportStorage.js +8 -24
  11. package/dist/storage/MongoReportStorage.js.map +1 -1
  12. package/dist/storage/implementation/MongoBucketBatch.js +1 -1
  13. package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
  14. package/dist/storage/implementation/MongoSyncBucketStorage.js +1 -1
  15. package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
  16. package/dist/storage/implementation/PersistedBatch.js +1 -1
  17. package/dist/storage/implementation/PersistedBatch.js.map +1 -1
  18. package/dist/storage/implementation/db.d.ts +2 -2
  19. package/dist/storage/implementation/db.js +6 -6
  20. package/dist/storage/implementation/db.js.map +1 -1
  21. package/dist/storage/storage-index.d.ts +2 -2
  22. package/dist/storage/storage-index.js +2 -2
  23. package/dist/storage/storage-index.js.map +1 -1
  24. package/dist/utils/test-utils.d.ts +11 -0
  25. package/dist/utils/test-utils.js +40 -0
  26. package/dist/utils/test-utils.js.map +1 -0
  27. package/dist/{storage/implementation → utils}/util.d.ts +1 -6
  28. package/dist/{storage/implementation → utils}/util.js +0 -15
  29. package/dist/utils/util.js.map +1 -0
  30. package/dist/utils/utils-index.d.ts +2 -0
  31. package/dist/utils/utils-index.js +3 -0
  32. package/dist/utils/utils-index.js.map +1 -0
  33. package/package.json +8 -8
  34. package/src/index.ts +1 -0
  35. package/src/migrations/db/migrations/{1752661449910-sdk-reporting.ts → 1752661449910-connection-reporting.ts} +10 -22
  36. package/src/storage/MongoBucketStorage.ts +1 -1
  37. package/src/storage/MongoReportStorage.ts +11 -28
  38. package/src/storage/implementation/MongoBucketBatch.ts +1 -1
  39. package/src/storage/implementation/MongoSyncBucketStorage.ts +1 -1
  40. package/src/storage/implementation/PersistedBatch.ts +1 -1
  41. package/src/storage/implementation/db.ts +6 -6
  42. package/src/storage/storage-index.ts +2 -2
  43. package/src/utils/test-utils.ts +55 -0
  44. package/src/{storage/implementation → utils}/util.ts +1 -17
  45. package/src/utils/utils-index.ts +2 -0
  46. package/test/src/__snapshots__/{sdk-report-storage.test.ts.snap → connection-report-storage.test.ts.snap} +59 -29
  47. package/test/src/__snapshots__/storage_sync.test.ts.snap +12 -11
  48. package/test/src/{sdk-report-storage.test.ts → connection-report-storage.test.ts} +26 -38
  49. package/test/src/util.ts +3 -5
  50. package/tsconfig.tsbuildinfo +1 -1
  51. package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js +0 -48
  52. package/dist/migrations/db/migrations/1752661449910-sdk-reporting.js.map +0 -1
  53. package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.d.ts +0 -7
  54. package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.js +0 -13
  55. package/dist/storage/implementation/MongoTestReportStorageFactoryGenerator.js.map +0 -1
  56. package/dist/storage/implementation/MongoTestStorageFactoryGenerator.d.ts +0 -7
  57. package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js +0 -18
  58. package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js.map +0 -1
  59. package/dist/storage/implementation/util.js.map +0 -1
  60. package/src/storage/implementation/MongoTestReportStorageFactoryGenerator.ts +0 -22
  61. package/src/storage/implementation/MongoTestStorageFactoryGenerator.ts +0 -28
  62. /package/dist/migrations/db/migrations/{1752661449910-sdk-reporting.d.ts → 1752661449910-connection-reporting.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`SDK reporting storage > Should create a sdk event if its after a day 1`] = `
3
+ exports[`SDK reporting storage > Should create a connection report if its after a day 1`] = `
4
4
  [
5
5
  {
6
6
  "client_id": "client_week",
@@ -45,12 +45,53 @@ exports[`SDK reporting storage > Should delete rows older than specified range 1
45
45
  "sdk": "powersync-js/1.24.5",
46
46
  "users": 1,
47
47
  },
48
+ {
49
+ "clients": 1,
50
+ "sdk": "unknown",
51
+ "users": 1,
52
+ },
48
53
  ],
49
54
  "users": 5,
50
55
  }
51
56
  `;
52
57
 
53
- exports[`SDK reporting storage > Should show SDK scrape data for user over the past day 1`] = `
58
+ exports[`SDK reporting storage > Should show connected users with start range 1`] = `
59
+ {
60
+ "sdks": [
61
+ {
62
+ "clients": 1,
63
+ "sdk": "powersync-dart/1.6.4",
64
+ "users": 1,
65
+ },
66
+ {
67
+ "clients": 1,
68
+ "sdk": "powersync-js/1.21.1",
69
+ "users": 1,
70
+ },
71
+ {
72
+ "clients": 1,
73
+ "sdk": "unknown",
74
+ "users": 1,
75
+ },
76
+ ],
77
+ "users": 2,
78
+ }
79
+ `;
80
+
81
+ exports[`SDK reporting storage > Should show connected users with start range and end range 1`] = `
82
+ {
83
+ "sdks": [
84
+ {
85
+ "clients": 1,
86
+ "sdk": "powersync-js/1.21.1",
87
+ "users": 1,
88
+ },
89
+ ],
90
+ "users": 1,
91
+ }
92
+ `;
93
+
94
+ exports[`SDK reporting storage > Should show connection report data for user over the past day 1`] = `
54
95
  {
55
96
  "sdks": [
56
97
  {
@@ -68,12 +109,17 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
68
109
  "sdk": "powersync-js/1.21.4",
69
110
  "users": 1,
70
111
  },
112
+ {
113
+ "clients": 1,
114
+ "sdk": "unknown",
115
+ "users": 1,
116
+ },
71
117
  ],
72
118
  "users": 3,
73
119
  }
74
120
  `;
75
121
 
76
- exports[`SDK reporting storage > Should show SDK scrape data for user over the past month 1`] = `
122
+ exports[`SDK reporting storage > Should show connection report data for user over the past month 1`] = `
77
123
  {
78
124
  "sdks": [
79
125
  {
@@ -111,12 +157,17 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
111
157
  "sdk": "powersync-js/1.24.5",
112
158
  "users": 1,
113
159
  },
160
+ {
161
+ "clients": 1,
162
+ "sdk": "unknown",
163
+ "users": 1,
164
+ },
114
165
  ],
115
166
  "users": 7,
116
167
  }
117
168
  `;
118
169
 
119
- exports[`SDK reporting storage > Should show SDK scrape data for user over the past week 1`] = `
170
+ exports[`SDK reporting storage > Should show connection report data for user over the past week 1`] = `
120
171
  {
121
172
  "sdks": [
122
173
  {
@@ -144,38 +195,17 @@ exports[`SDK reporting storage > Should show SDK scrape data for user over the p
144
195
  "sdk": "powersync-js/1.24.5",
145
196
  "users": 1,
146
197
  },
147
- ],
148
- "users": 5,
149
- }
150
- `;
151
-
152
- exports[`SDK reporting storage > Should show connected users with start range 1`] = `
153
- {
154
- "sdks": [
155
198
  {
156
199
  "clients": 1,
157
- "sdk": "powersync-dart/1.6.4",
200
+ "sdk": "unknown",
158
201
  "users": 1,
159
202
  },
160
203
  ],
161
- "users": 1,
162
- }
163
- `;
164
-
165
- exports[`SDK reporting storage > Should show connected users with start range and end range 1`] = `
166
- {
167
- "sdks": [
168
- {
169
- "clients": 1,
170
- "sdk": "powersync-js/1.21.1",
171
- "users": 1,
172
- },
173
- ],
174
- "users": 1,
204
+ "users": 5,
175
205
  }
176
206
  `;
177
207
 
178
- exports[`SDK reporting storage > Should update a connected sdk event and make it disconnected 1`] = `
208
+ exports[`SDK reporting storage > Should update a connected connection report and make it disconnected 1`] = `
179
209
  [
180
210
  {
181
211
  "client_id": "client_three",
@@ -186,7 +216,7 @@ exports[`SDK reporting storage > Should update a connected sdk event and make it
186
216
  ]
187
217
  `;
188
218
 
189
- exports[`SDK reporting storage > Should update a sdk event if its within a day 1`] = `
219
+ exports[`SDK reporting storage > Should update a connection report if its within a day 1`] = `
190
220
  [
191
221
  {
192
222
  "client_id": "client_one",
@@ -39,7 +39,7 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
39
39
  "bucket": "mybucket[]",
40
40
  "data": [
41
41
  {
42
- "checksum": -93886621n,
42
+ "checksum": -93886621,
43
43
  "op": "CLEAR",
44
44
  "op_id": "2",
45
45
  },
@@ -74,7 +74,7 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
74
74
  "bucket": "mybucket[]",
75
75
  "data": [
76
76
  {
77
- "checksum": 1859363232n,
77
+ "checksum": 1859363232,
78
78
  "data": "{"id":"t1","description":"Test 1b"}",
79
79
  "object_id": "t1",
80
80
  "object_type": "test",
@@ -83,7 +83,7 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
83
83
  "subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
84
84
  },
85
85
  {
86
- "checksum": 3028503153n,
86
+ "checksum": 3028503153,
87
87
  "data": "{"id":"t2","description":"Test 2b"}",
88
88
  "object_id": "t2",
89
89
  "object_type": "test",
@@ -203,6 +203,7 @@ exports[`sync - mongodb > sends checkpoint complete line for empty checkpoint 1`
203
203
  "next_after": "1",
204
204
  },
205
205
  },
206
+ null,
206
207
  {
207
208
  "checkpoint_complete": {
208
209
  "last_op_id": "1",
@@ -274,7 +275,7 @@ exports[`sync - mongodb > sync buckets in order 1`] = `
274
275
  "bucket": "b1[]",
275
276
  "data": [
276
277
  {
277
- "checksum": 2912868539n,
278
+ "checksum": 2912868539,
278
279
  "data": "{"id":"earlier","description":"Test 2"}",
279
280
  "object_id": "earlier",
280
281
  "object_type": "test",
@@ -299,7 +300,7 @@ exports[`sync - mongodb > sync buckets in order 1`] = `
299
300
  "bucket": "b0[]",
300
301
  "data": [
301
302
  {
302
- "checksum": 920318466n,
303
+ "checksum": 920318466,
303
304
  "data": "{"id":"t1","description":"Test 1"}",
304
305
  "object_id": "t1",
305
306
  "object_type": "test",
@@ -354,7 +355,7 @@ exports[`sync - mongodb > sync global data 1`] = `
354
355
  "bucket": "mybucket[]",
355
356
  "data": [
356
357
  {
357
- "checksum": 920318466n,
358
+ "checksum": 920318466,
358
359
  "data": "{"id":"t1","description":"Test 1"}",
359
360
  "object_id": "t1",
360
361
  "object_type": "test",
@@ -363,7 +364,7 @@ exports[`sync - mongodb > sync global data 1`] = `
363
364
  "subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
364
365
  },
365
366
  {
366
- "checksum": 3280762209n,
367
+ "checksum": 3280762209,
367
368
  "data": "{"id":"t2","description":"Test 2"}",
368
369
  "object_id": "t2",
369
370
  "object_type": "test",
@@ -702,7 +703,7 @@ exports[`sync - mongodb > sync updates to data query only 2`] = `
702
703
  "bucket": "by_user["user1"]",
703
704
  "data": [
704
705
  {
705
- "checksum": 1418351250n,
706
+ "checksum": 1418351250,
706
707
  "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
707
708
  "object_id": "list1",
708
709
  "object_type": "lists",
@@ -787,7 +788,7 @@ exports[`sync - mongodb > sync updates to global data 2`] = `
787
788
  "bucket": "mybucket[]",
788
789
  "data": [
789
790
  {
790
- "checksum": 920318466n,
791
+ "checksum": 920318466,
791
792
  "data": "{"id":"t1","description":"Test 1"}",
792
793
  "object_id": "t1",
793
794
  "object_type": "test",
@@ -836,7 +837,7 @@ exports[`sync - mongodb > sync updates to global data 3`] = `
836
837
  "bucket": "mybucket[]",
837
838
  "data": [
838
839
  {
839
- "checksum": 3280762209n,
840
+ "checksum": 3280762209,
840
841
  "data": "{"id":"t2","description":"Test 2"}",
841
842
  "object_id": "t2",
842
843
  "object_type": "test",
@@ -909,7 +910,7 @@ exports[`sync - mongodb > sync updates to parameter query + data 2`] = `
909
910
  "bucket": "by_user["user1"]",
910
911
  "data": [
911
912
  {
912
- "checksum": 1418351250n,
913
+ "checksum": 1418351250,
913
914
  "data": "{"id":"list1","user_id":"user1","name":"User 1"}",
914
915
  "object_id": "list1",
915
916
  "object_type": "lists",
@@ -68,6 +68,15 @@ describe('SDK reporting storage', async () => {
68
68
  jwt_exp: nowLess5minutes
69
69
  };
70
70
 
71
+ const user_old = {
72
+ user_id: 'user_one',
73
+ client_id: '',
74
+ connected_at: now,
75
+ sdk: 'unknown',
76
+ user_agent: 'Dart (flutter-web) Chrome/128 android',
77
+ jwt_exp: nowAdd5minutes
78
+ };
79
+
71
80
  const user_week = {
72
81
  user_id: 'user_week',
73
82
  client_id: 'client_week',
@@ -96,19 +105,20 @@ describe('SDK reporting storage', async () => {
96
105
  };
97
106
 
98
107
  async function loadData() {
99
- await factory.db.sdk_report_events.insertMany([
108
+ await factory.db.connection_report_events.insertMany([
100
109
  user_one,
101
110
  user_two,
102
111
  user_three,
103
112
  user_four,
104
113
  user_week,
105
114
  user_month,
106
- user_expired
115
+ user_expired,
116
+ user_old
107
117
  ]);
108
118
  }
109
119
 
110
120
  function deleteData() {
111
- return factory.db.sdk_report_events.deleteMany();
121
+ return factory.db.connection_report_events.deleteMany();
112
122
  }
113
123
 
114
124
  beforeAll(async () => {
@@ -119,49 +129,25 @@ describe('SDK reporting storage', async () => {
119
129
  await deleteData();
120
130
  });
121
131
  it('Should show connected users with start range', async () => {
122
- const current = await factory.getConnectedClients({
123
- range: {
124
- start: new Date(
125
- now.getFullYear(),
126
- now.getMonth(),
127
- now.getDate(),
128
- now.getHours(),
129
- now.getMinutes() - 1
130
- ).toISOString()
131
- }
132
- });
132
+ const current = await factory.getConnectedClients();
133
133
  expect(current).toMatchSnapshot();
134
134
  });
135
- it('Should show connected users with start range and end range', async () => {
136
- const current = await factory.getConnectedClients({
137
- range: {
138
- end: nowLess5minutes.toISOString(),
139
- start: new Date(
140
- now.getFullYear(),
141
- now.getMonth(),
142
- now.getDate(),
143
- now.getHours(),
144
- now.getMinutes() - 6
145
- ).toISOString()
146
- }
147
- });
148
- expect(current).toMatchSnapshot();
149
- });
150
- it('Should show SDK scrape data for user over the past month', async () => {
135
+
136
+ it('Should show connection report data for user over the past month', async () => {
151
137
  const sdk = await factory.getClientConnectionReports({
152
138
  start: monthAgo,
153
139
  end: now
154
140
  });
155
141
  expect(sdk).toMatchSnapshot();
156
142
  });
157
- it('Should show SDK scrape data for user over the past week', async () => {
143
+ it('Should show connection report data for user over the past week', async () => {
158
144
  const sdk = await factory.getClientConnectionReports({
159
145
  start: weekAgo,
160
146
  end: now
161
147
  });
162
148
  expect(sdk).toMatchSnapshot();
163
149
  });
164
- it('Should show SDK scrape data for user over the past day', async () => {
150
+ it('Should show connection report data for user over the past day', async () => {
165
151
  const sdk = await factory.getClientConnectionReports({
166
152
  start: dayAgo,
167
153
  end: now
@@ -169,7 +155,7 @@ describe('SDK reporting storage', async () => {
169
155
  expect(sdk).toMatchSnapshot();
170
156
  });
171
157
 
172
- it('Should update a sdk event if its within a day', async () => {
158
+ it('Should update a connection report if its within a day', async () => {
173
159
  const newConnectAt = new Date(
174
160
  now.getFullYear(),
175
161
  now.getMonth(),
@@ -187,7 +173,9 @@ describe('SDK reporting storage', async () => {
187
173
  user_agent: user_one.user_agent
188
174
  });
189
175
 
190
- const sdk = await factory.db.sdk_report_events.find({ user_id: user_one.user_id }).toArray();
176
+ const sdk = await factory.db.connection_report_events
177
+ .find({ user_id: user_one.user_id, client_id: user_one.client_id })
178
+ .toArray();
191
179
  expect(sdk).toHaveLength(1);
192
180
  expect(new Date(sdk[0].connected_at)).toEqual(newConnectAt);
193
181
  expect(new Date(sdk[0].jwt_exp!)).toEqual(jwtExp);
@@ -196,7 +184,7 @@ describe('SDK reporting storage', async () => {
196
184
  expect(cleaned).toMatchSnapshot();
197
185
  });
198
186
 
199
- it('Should update a connected sdk event and make it disconnected', async () => {
187
+ it('Should update a connected connection report and make it disconnected', async () => {
200
188
  const disconnectAt = new Date(
201
189
  now.getFullYear(),
202
190
  now.getMonth(),
@@ -215,14 +203,14 @@ describe('SDK reporting storage', async () => {
215
203
  connected_at: user_three.connected_at
216
204
  });
217
205
 
218
- const sdk = await factory.db.sdk_report_events.find({ user_id: user_three.user_id }).toArray();
206
+ const sdk = await factory.db.connection_report_events.find({ user_id: user_three.user_id }).toArray();
219
207
  expect(sdk).toHaveLength(1);
220
208
  expect(new Date(sdk[0].disconnected_at!)).toEqual(disconnectAt);
221
209
  const cleaned = removeVolatileFields(sdk);
222
210
  expect(cleaned).toMatchSnapshot();
223
211
  });
224
212
 
225
- it('Should create a sdk event if its after a day', async () => {
213
+ it('Should create a connection report if its after a day', async () => {
226
214
  const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
227
215
  const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
228
216
 
@@ -235,7 +223,7 @@ describe('SDK reporting storage', async () => {
235
223
  user_agent: user_week.user_agent
236
224
  });
237
225
 
238
- const sdk = await factory.db.sdk_report_events.find({ user_id: user_week.user_id }).toArray();
226
+ const sdk = await factory.db.connection_report_events.find({ user_id: user_week.user_id }).toArray();
239
227
  expect(sdk).toHaveLength(2);
240
228
  const cleaned = removeVolatileFields(sdk);
241
229
  expect(cleaned).toMatchSnapshot();
package/test/src/util.ts CHANGED
@@ -1,14 +1,12 @@
1
1
  import { env } from './env.js';
2
+ import { mongoTestReportStorageFactoryGenerator, mongoTestStorageFactoryGenerator } from '@module/utils/test-utils.js';
2
3
 
3
- import { MongoTestStorageFactoryGenerator } from '@module/storage/implementation/MongoTestStorageFactoryGenerator.js';
4
- import { MongoTestReportStorageFactoryGenerator } from '@module/storage/implementation/MongoTestReportStorageFactoryGenerator.js';
5
-
6
- export const INITIALIZED_MONGO_STORAGE_FACTORY = MongoTestStorageFactoryGenerator({
4
+ export const INITIALIZED_MONGO_STORAGE_FACTORY = mongoTestStorageFactoryGenerator({
7
5
  url: env.MONGO_TEST_URL,
8
6
  isCI: env.CI
9
7
  });
10
8
 
11
- export const INITIALIZED_MONGO_REPORT_STORAGE_FACTORY = MongoTestReportStorageFactoryGenerator({
9
+ export const INITIALIZED_MONGO_REPORT_STORAGE_FACTORY = mongoTestReportStorageFactoryGenerator({
12
10
  url: env.MONGO_TEST_URL,
13
11
  isCI: env.CI
14
12
  });