@powersync/service-module-mongodb-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 +8 -7
- package/dist/storage/MongoReportStorage.d.ts +7 -7
- package/dist/storage/MongoReportStorage.js +11 -11
- package/dist/storage/MongoReportStorage.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +2 -2
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +1 -1
- package/package.json +8 -8
- package/src/storage/MongoReportStorage.ts +16 -14
- package/src/storage/implementation/db.ts +2 -2
- package/src/storage/implementation/models.ts +1 -1
- package/test/src/__snapshots__/storage_sync.test.ts.snap +197 -0
- package/test/src/sdk-report-storage.test.ts +13 -13
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -10,9 +10,21 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 1`] = `
|
|
|
10
10
|
"checksum": -93886621,
|
|
11
11
|
"count": 2,
|
|
12
12
|
"priority": 3,
|
|
13
|
+
"subscriptions": [
|
|
14
|
+
{
|
|
15
|
+
"default": 0,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
13
18
|
},
|
|
14
19
|
],
|
|
15
20
|
"last_op_id": "2",
|
|
21
|
+
"streams": [
|
|
22
|
+
{
|
|
23
|
+
"errors": [],
|
|
24
|
+
"is_default": true,
|
|
25
|
+
"name": "mybucket",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
16
28
|
"write_checkpoint": undefined,
|
|
17
29
|
},
|
|
18
30
|
},
|
|
@@ -46,6 +58,11 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
|
|
|
46
58
|
"checksum": 499012468,
|
|
47
59
|
"count": 4,
|
|
48
60
|
"priority": 3,
|
|
61
|
+
"subscriptions": [
|
|
62
|
+
{
|
|
63
|
+
"default": 0,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
49
66
|
},
|
|
50
67
|
],
|
|
51
68
|
"write_checkpoint": undefined,
|
|
@@ -105,9 +122,21 @@ exports[`sync - mongodb > expiring token 1`] = `
|
|
|
105
122
|
"checksum": 0,
|
|
106
123
|
"count": 0,
|
|
107
124
|
"priority": 3,
|
|
125
|
+
"subscriptions": [
|
|
126
|
+
{
|
|
127
|
+
"default": 0,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
108
130
|
},
|
|
109
131
|
],
|
|
110
132
|
"last_op_id": "0",
|
|
133
|
+
"streams": [
|
|
134
|
+
{
|
|
135
|
+
"errors": [],
|
|
136
|
+
"is_default": true,
|
|
137
|
+
"name": "mybucket",
|
|
138
|
+
},
|
|
139
|
+
],
|
|
111
140
|
"write_checkpoint": undefined,
|
|
112
141
|
},
|
|
113
142
|
},
|
|
@@ -137,9 +166,21 @@ exports[`sync - mongodb > sends checkpoint complete line for empty checkpoint 1`
|
|
|
137
166
|
"checksum": -1221282404,
|
|
138
167
|
"count": 1,
|
|
139
168
|
"priority": 3,
|
|
169
|
+
"subscriptions": [
|
|
170
|
+
{
|
|
171
|
+
"default": 0,
|
|
172
|
+
},
|
|
173
|
+
],
|
|
140
174
|
},
|
|
141
175
|
],
|
|
142
176
|
"last_op_id": "1",
|
|
177
|
+
"streams": [
|
|
178
|
+
{
|
|
179
|
+
"errors": [],
|
|
180
|
+
"is_default": true,
|
|
181
|
+
"name": "mybucket",
|
|
182
|
+
},
|
|
183
|
+
],
|
|
143
184
|
"write_checkpoint": undefined,
|
|
144
185
|
},
|
|
145
186
|
},
|
|
@@ -193,15 +234,37 @@ exports[`sync - mongodb > sync buckets in order 1`] = `
|
|
|
193
234
|
"checksum": 920318466,
|
|
194
235
|
"count": 1,
|
|
195
236
|
"priority": 2,
|
|
237
|
+
"subscriptions": [
|
|
238
|
+
{
|
|
239
|
+
"default": 0,
|
|
240
|
+
},
|
|
241
|
+
],
|
|
196
242
|
},
|
|
197
243
|
{
|
|
198
244
|
"bucket": "b1[]",
|
|
199
245
|
"checksum": -1382098757,
|
|
200
246
|
"count": 1,
|
|
201
247
|
"priority": 1,
|
|
248
|
+
"subscriptions": [
|
|
249
|
+
{
|
|
250
|
+
"default": 1,
|
|
251
|
+
},
|
|
252
|
+
],
|
|
202
253
|
},
|
|
203
254
|
],
|
|
204
255
|
"last_op_id": "2",
|
|
256
|
+
"streams": [
|
|
257
|
+
{
|
|
258
|
+
"errors": [],
|
|
259
|
+
"is_default": true,
|
|
260
|
+
"name": "b0",
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"errors": [],
|
|
264
|
+
"is_default": true,
|
|
265
|
+
"name": "b1",
|
|
266
|
+
},
|
|
267
|
+
],
|
|
205
268
|
"write_checkpoint": undefined,
|
|
206
269
|
},
|
|
207
270
|
},
|
|
@@ -267,9 +330,21 @@ exports[`sync - mongodb > sync global data 1`] = `
|
|
|
267
330
|
"checksum": -93886621,
|
|
268
331
|
"count": 2,
|
|
269
332
|
"priority": 3,
|
|
333
|
+
"subscriptions": [
|
|
334
|
+
{
|
|
335
|
+
"default": 0,
|
|
336
|
+
},
|
|
337
|
+
],
|
|
270
338
|
},
|
|
271
339
|
],
|
|
272
340
|
"last_op_id": "2",
|
|
341
|
+
"streams": [
|
|
342
|
+
{
|
|
343
|
+
"errors": [],
|
|
344
|
+
"is_default": true,
|
|
345
|
+
"name": "mybucket",
|
|
346
|
+
},
|
|
347
|
+
],
|
|
273
348
|
"write_checkpoint": undefined,
|
|
274
349
|
},
|
|
275
350
|
},
|
|
@@ -319,21 +394,53 @@ exports[`sync - mongodb > sync interrupts low-priority buckets on new checkpoint
|
|
|
319
394
|
"checksum": -659831575,
|
|
320
395
|
"count": 2000,
|
|
321
396
|
"priority": 2,
|
|
397
|
+
"subscriptions": [
|
|
398
|
+
{
|
|
399
|
+
"default": 0,
|
|
400
|
+
},
|
|
401
|
+
],
|
|
322
402
|
},
|
|
323
403
|
{
|
|
324
404
|
"bucket": "b0b[]",
|
|
325
405
|
"checksum": -659831575,
|
|
326
406
|
"count": 2000,
|
|
327
407
|
"priority": 2,
|
|
408
|
+
"subscriptions": [
|
|
409
|
+
{
|
|
410
|
+
"default": 1,
|
|
411
|
+
},
|
|
412
|
+
],
|
|
328
413
|
},
|
|
329
414
|
{
|
|
330
415
|
"bucket": "b1[]",
|
|
331
416
|
"checksum": -1096116670,
|
|
332
417
|
"count": 1,
|
|
333
418
|
"priority": 1,
|
|
419
|
+
"subscriptions": [
|
|
420
|
+
{
|
|
421
|
+
"default": 2,
|
|
422
|
+
},
|
|
423
|
+
],
|
|
334
424
|
},
|
|
335
425
|
],
|
|
336
426
|
"last_op_id": "4001",
|
|
427
|
+
"streams": [
|
|
428
|
+
{
|
|
429
|
+
"errors": [],
|
|
430
|
+
"is_default": true,
|
|
431
|
+
"name": "b0a",
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
"errors": [],
|
|
435
|
+
"is_default": true,
|
|
436
|
+
"name": "b0b",
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
"errors": [],
|
|
440
|
+
"is_default": true,
|
|
441
|
+
"name": "b1",
|
|
442
|
+
},
|
|
443
|
+
],
|
|
337
444
|
"write_checkpoint": undefined,
|
|
338
445
|
},
|
|
339
446
|
},
|
|
@@ -380,18 +487,33 @@ exports[`sync - mongodb > sync interrupts low-priority buckets on new checkpoint
|
|
|
380
487
|
"checksum": 883076828,
|
|
381
488
|
"count": 2001,
|
|
382
489
|
"priority": 2,
|
|
490
|
+
"subscriptions": [
|
|
491
|
+
{
|
|
492
|
+
"default": 0,
|
|
493
|
+
},
|
|
494
|
+
],
|
|
383
495
|
},
|
|
384
496
|
{
|
|
385
497
|
"bucket": "b0b[]",
|
|
386
498
|
"checksum": 883076828,
|
|
387
499
|
"count": 2001,
|
|
388
500
|
"priority": 2,
|
|
501
|
+
"subscriptions": [
|
|
502
|
+
{
|
|
503
|
+
"default": 1,
|
|
504
|
+
},
|
|
505
|
+
],
|
|
389
506
|
},
|
|
390
507
|
{
|
|
391
508
|
"bucket": "b1[]",
|
|
392
509
|
"checksum": 1841937527,
|
|
393
510
|
"count": 2,
|
|
394
511
|
"priority": 1,
|
|
512
|
+
"subscriptions": [
|
|
513
|
+
{
|
|
514
|
+
"default": 2,
|
|
515
|
+
},
|
|
516
|
+
],
|
|
395
517
|
},
|
|
396
518
|
],
|
|
397
519
|
"write_checkpoint": undefined,
|
|
@@ -466,9 +588,21 @@ exports[`sync - mongodb > sync legacy non-raw data 1`] = `
|
|
|
466
588
|
"checksum": -852817836,
|
|
467
589
|
"count": 1,
|
|
468
590
|
"priority": 3,
|
|
591
|
+
"subscriptions": [
|
|
592
|
+
{
|
|
593
|
+
"default": 0,
|
|
594
|
+
},
|
|
595
|
+
],
|
|
469
596
|
},
|
|
470
597
|
],
|
|
471
598
|
"last_op_id": "1",
|
|
599
|
+
"streams": [
|
|
600
|
+
{
|
|
601
|
+
"errors": [],
|
|
602
|
+
"is_default": true,
|
|
603
|
+
"name": "mybucket",
|
|
604
|
+
},
|
|
605
|
+
],
|
|
472
606
|
"write_checkpoint": undefined,
|
|
473
607
|
},
|
|
474
608
|
},
|
|
@@ -514,9 +648,21 @@ exports[`sync - mongodb > sync updates to data query only 1`] = `
|
|
|
514
648
|
"checksum": 0,
|
|
515
649
|
"count": 0,
|
|
516
650
|
"priority": 3,
|
|
651
|
+
"subscriptions": [
|
|
652
|
+
{
|
|
653
|
+
"default": 0,
|
|
654
|
+
},
|
|
655
|
+
],
|
|
517
656
|
},
|
|
518
657
|
],
|
|
519
658
|
"last_op_id": "1",
|
|
659
|
+
"streams": [
|
|
660
|
+
{
|
|
661
|
+
"errors": [],
|
|
662
|
+
"is_default": true,
|
|
663
|
+
"name": "by_user",
|
|
664
|
+
},
|
|
665
|
+
],
|
|
520
666
|
"write_checkpoint": undefined,
|
|
521
667
|
},
|
|
522
668
|
},
|
|
@@ -540,6 +686,11 @@ exports[`sync - mongodb > sync updates to data query only 2`] = `
|
|
|
540
686
|
"checksum": 1418351250,
|
|
541
687
|
"count": 1,
|
|
542
688
|
"priority": 3,
|
|
689
|
+
"subscriptions": [
|
|
690
|
+
{
|
|
691
|
+
"default": 0,
|
|
692
|
+
},
|
|
693
|
+
],
|
|
543
694
|
},
|
|
544
695
|
],
|
|
545
696
|
"write_checkpoint": undefined,
|
|
@@ -582,9 +733,21 @@ exports[`sync - mongodb > sync updates to global data 1`] = `
|
|
|
582
733
|
"checksum": 0,
|
|
583
734
|
"count": 0,
|
|
584
735
|
"priority": 3,
|
|
736
|
+
"subscriptions": [
|
|
737
|
+
{
|
|
738
|
+
"default": 0,
|
|
739
|
+
},
|
|
740
|
+
],
|
|
585
741
|
},
|
|
586
742
|
],
|
|
587
743
|
"last_op_id": "0",
|
|
744
|
+
"streams": [
|
|
745
|
+
{
|
|
746
|
+
"errors": [],
|
|
747
|
+
"is_default": true,
|
|
748
|
+
"name": "mybucket",
|
|
749
|
+
},
|
|
750
|
+
],
|
|
588
751
|
"write_checkpoint": undefined,
|
|
589
752
|
},
|
|
590
753
|
},
|
|
@@ -608,6 +771,11 @@ exports[`sync - mongodb > sync updates to global data 2`] = `
|
|
|
608
771
|
"checksum": 920318466,
|
|
609
772
|
"count": 1,
|
|
610
773
|
"priority": 3,
|
|
774
|
+
"subscriptions": [
|
|
775
|
+
{
|
|
776
|
+
"default": 0,
|
|
777
|
+
},
|
|
778
|
+
],
|
|
611
779
|
},
|
|
612
780
|
],
|
|
613
781
|
"write_checkpoint": undefined,
|
|
@@ -652,6 +820,11 @@ exports[`sync - mongodb > sync updates to global data 3`] = `
|
|
|
652
820
|
"checksum": -93886621,
|
|
653
821
|
"count": 2,
|
|
654
822
|
"priority": 3,
|
|
823
|
+
"subscriptions": [
|
|
824
|
+
{
|
|
825
|
+
"default": 0,
|
|
826
|
+
},
|
|
827
|
+
],
|
|
655
828
|
},
|
|
656
829
|
],
|
|
657
830
|
"write_checkpoint": undefined,
|
|
@@ -690,6 +863,13 @@ exports[`sync - mongodb > sync updates to parameter query + data 1`] = `
|
|
|
690
863
|
"checkpoint": {
|
|
691
864
|
"buckets": [],
|
|
692
865
|
"last_op_id": "0",
|
|
866
|
+
"streams": [
|
|
867
|
+
{
|
|
868
|
+
"errors": [],
|
|
869
|
+
"is_default": true,
|
|
870
|
+
"name": "by_user",
|
|
871
|
+
},
|
|
872
|
+
],
|
|
693
873
|
"write_checkpoint": undefined,
|
|
694
874
|
},
|
|
695
875
|
},
|
|
@@ -713,6 +893,11 @@ exports[`sync - mongodb > sync updates to parameter query + data 2`] = `
|
|
|
713
893
|
"checksum": 1418351250,
|
|
714
894
|
"count": 1,
|
|
715
895
|
"priority": 3,
|
|
896
|
+
"subscriptions": [
|
|
897
|
+
{
|
|
898
|
+
"default": 0,
|
|
899
|
+
},
|
|
900
|
+
],
|
|
716
901
|
},
|
|
717
902
|
],
|
|
718
903
|
"write_checkpoint": undefined,
|
|
@@ -751,6 +936,13 @@ exports[`sync - mongodb > sync updates to parameter query only 1`] = `
|
|
|
751
936
|
"checkpoint": {
|
|
752
937
|
"buckets": [],
|
|
753
938
|
"last_op_id": "0",
|
|
939
|
+
"streams": [
|
|
940
|
+
{
|
|
941
|
+
"errors": [],
|
|
942
|
+
"is_default": true,
|
|
943
|
+
"name": "by_user",
|
|
944
|
+
},
|
|
945
|
+
],
|
|
754
946
|
"write_checkpoint": undefined,
|
|
755
947
|
},
|
|
756
948
|
},
|
|
@@ -774,6 +966,11 @@ exports[`sync - mongodb > sync updates to parameter query only 2`] = `
|
|
|
774
966
|
"checksum": 0,
|
|
775
967
|
"count": 0,
|
|
776
968
|
"priority": 3,
|
|
969
|
+
"subscriptions": [
|
|
970
|
+
{
|
|
971
|
+
"default": 0,
|
|
972
|
+
},
|
|
973
|
+
],
|
|
777
974
|
},
|
|
778
975
|
],
|
|
779
976
|
"write_checkpoint": undefined,
|
|
@@ -3,9 +3,9 @@ import { INITIALIZED_MONGO_REPORT_STORAGE_FACTORY } from './util.js';
|
|
|
3
3
|
import { event_types } from '@powersync/service-types';
|
|
4
4
|
|
|
5
5
|
function removeVolatileFields(
|
|
6
|
-
sdks: event_types.
|
|
7
|
-
): Partial<event_types.
|
|
8
|
-
return sdks.map((sdk: Partial<event_types.
|
|
6
|
+
sdks: event_types.ClientConnection[]
|
|
7
|
+
): Partial<event_types.ClientConnection & { _id: string }>[] {
|
|
8
|
+
return sdks.map((sdk: Partial<event_types.ClientConnection & { _id: string }>) => {
|
|
9
9
|
const { _id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
|
|
10
10
|
return {
|
|
11
11
|
...rest
|
|
@@ -119,7 +119,7 @@ describe('SDK reporting storage', async () => {
|
|
|
119
119
|
await deleteData();
|
|
120
120
|
});
|
|
121
121
|
it('Should show connected users with start range', async () => {
|
|
122
|
-
const current = await factory.
|
|
122
|
+
const current = await factory.getConnectedClients({
|
|
123
123
|
range: {
|
|
124
124
|
start: new Date(
|
|
125
125
|
now.getFullYear(),
|
|
@@ -133,7 +133,7 @@ describe('SDK reporting storage', async () => {
|
|
|
133
133
|
expect(current).toMatchSnapshot();
|
|
134
134
|
});
|
|
135
135
|
it('Should show connected users with start range and end range', async () => {
|
|
136
|
-
const current = await factory.
|
|
136
|
+
const current = await factory.getConnectedClients({
|
|
137
137
|
range: {
|
|
138
138
|
end: nowLess5minutes.toISOString(),
|
|
139
139
|
start: new Date(
|
|
@@ -148,21 +148,21 @@ describe('SDK reporting storage', async () => {
|
|
|
148
148
|
expect(current).toMatchSnapshot();
|
|
149
149
|
});
|
|
150
150
|
it('Should show SDK scrape data for user over the past month', async () => {
|
|
151
|
-
const sdk = await factory.
|
|
151
|
+
const sdk = await factory.getClientConnectionReports({
|
|
152
152
|
start: monthAgo,
|
|
153
153
|
end: now
|
|
154
154
|
});
|
|
155
155
|
expect(sdk).toMatchSnapshot();
|
|
156
156
|
});
|
|
157
157
|
it('Should show SDK scrape data for user over the past week', async () => {
|
|
158
|
-
const sdk = await factory.
|
|
158
|
+
const sdk = await factory.getClientConnectionReports({
|
|
159
159
|
start: weekAgo,
|
|
160
160
|
end: now
|
|
161
161
|
});
|
|
162
162
|
expect(sdk).toMatchSnapshot();
|
|
163
163
|
});
|
|
164
164
|
it('Should show SDK scrape data for user over the past day', async () => {
|
|
165
|
-
const sdk = await factory.
|
|
165
|
+
const sdk = await factory.getClientConnectionReports({
|
|
166
166
|
start: dayAgo,
|
|
167
167
|
end: now
|
|
168
168
|
});
|
|
@@ -178,7 +178,7 @@ describe('SDK reporting storage', async () => {
|
|
|
178
178
|
now.getMinutes() + 20
|
|
179
179
|
);
|
|
180
180
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
181
|
-
await factory.
|
|
181
|
+
await factory.reportClientConnection({
|
|
182
182
|
sdk: user_one.sdk,
|
|
183
183
|
connected_at: newConnectAt,
|
|
184
184
|
jwt_exp: jwtExp,
|
|
@@ -206,7 +206,7 @@ describe('SDK reporting storage', async () => {
|
|
|
206
206
|
);
|
|
207
207
|
const jwtExp = new Date(disconnectAt.getFullYear(), disconnectAt.getMonth(), disconnectAt.getDate() + 1);
|
|
208
208
|
|
|
209
|
-
await factory.
|
|
209
|
+
await factory.reportClientDisconnection({
|
|
210
210
|
disconnected_at: disconnectAt,
|
|
211
211
|
jwt_exp: jwtExp,
|
|
212
212
|
client_id: user_three.client_id,
|
|
@@ -226,7 +226,7 @@ describe('SDK reporting storage', async () => {
|
|
|
226
226
|
const newConnectAt = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, now.getHours());
|
|
227
227
|
const jwtExp = new Date(newConnectAt.getFullYear(), newConnectAt.getMonth(), newConnectAt.getDate() + 1);
|
|
228
228
|
|
|
229
|
-
await factory.
|
|
229
|
+
await factory.reportClientConnection({
|
|
230
230
|
sdk: user_week.sdk,
|
|
231
231
|
connected_at: newConnectAt,
|
|
232
232
|
jwt_exp: jwtExp,
|
|
@@ -244,10 +244,10 @@ describe('SDK reporting storage', async () => {
|
|
|
244
244
|
it('Should delete rows older than specified range', async () => {
|
|
245
245
|
await deleteData();
|
|
246
246
|
await loadData();
|
|
247
|
-
await factory.
|
|
247
|
+
await factory.deleteOldConnectionData({
|
|
248
248
|
date: weekAgo
|
|
249
249
|
});
|
|
250
|
-
const sdk = await factory.
|
|
250
|
+
const sdk = await factory.getClientConnectionReports({
|
|
251
251
|
start: monthAgo,
|
|
252
252
|
end: now
|
|
253
253
|
});
|