@powersync/service-module-mongodb-storage 0.5.1 → 0.6.1

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 (37) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/storage/MongoBucketStorage.d.ts +7 -17
  3. package/dist/storage/MongoBucketStorage.js +48 -183
  4. package/dist/storage/MongoBucketStorage.js.map +1 -1
  5. package/dist/storage/implementation/MongoBucketBatch.d.ts +2 -2
  6. package/dist/storage/implementation/MongoBucketBatch.js +5 -5
  7. package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
  8. package/dist/storage/implementation/MongoCompactor.d.ts +0 -6
  9. package/dist/storage/implementation/MongoCompactor.js +1 -2
  10. package/dist/storage/implementation/MongoCompactor.js.map +1 -1
  11. package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +16 -3
  12. package/dist/storage/implementation/MongoSyncBucketStorage.js +212 -16
  13. package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
  14. package/dist/storage/implementation/MongoWriteCheckpointAPI.js +1 -2
  15. package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
  16. package/dist/storage/implementation/PersistedBatch.js +4 -5
  17. package/dist/storage/implementation/PersistedBatch.js.map +1 -1
  18. package/dist/storage/implementation/db.js +1 -1
  19. package/dist/storage/implementation/db.js.map +1 -1
  20. package/dist/storage/implementation/models.d.ts +1 -0
  21. package/dist/storage/implementation/util.d.ts +0 -14
  22. package/dist/storage/implementation/util.js +0 -38
  23. package/dist/storage/implementation/util.js.map +1 -1
  24. package/package.json +7 -7
  25. package/src/storage/MongoBucketStorage.ts +51 -216
  26. package/src/storage/implementation/MongoBucketBatch.ts +5 -8
  27. package/src/storage/implementation/MongoCompactor.ts +2 -10
  28. package/src/storage/implementation/MongoSyncBucketStorage.ts +292 -37
  29. package/src/storage/implementation/MongoWriteCheckpointAPI.ts +1 -3
  30. package/src/storage/implementation/PersistedBatch.ts +4 -5
  31. package/src/storage/implementation/db.ts +1 -1
  32. package/src/storage/implementation/models.ts +5 -0
  33. package/src/storage/implementation/util.ts +0 -45
  34. package/test/src/__snapshots__/storage_sync.test.ts.snap +138 -0
  35. package/test/src/storage_compacting.test.ts +1 -7
  36. package/test/src/storage_sync.test.ts +1 -1
  37. package/tsconfig.tsbuildinfo +1 -1
@@ -9,6 +9,7 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 1`] = `
9
9
  "bucket": "mybucket[]",
10
10
  "checksum": -93886621,
11
11
  "count": 2,
12
+ "priority": 3,
12
13
  },
13
14
  ],
14
15
  "last_op_id": "2",
@@ -44,6 +45,7 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
44
45
  "bucket": "mybucket[]",
45
46
  "checksum": 499012468,
46
47
  "count": 4,
48
+ "priority": 3,
47
49
  },
48
50
  ],
49
51
  "write_checkpoint": undefined,
@@ -102,6 +104,7 @@ exports[`sync - mongodb > expiring token 1`] = `
102
104
  "bucket": "mybucket[]",
103
105
  "checksum": 0,
104
106
  "count": 0,
107
+ "priority": 3,
105
108
  },
106
109
  ],
107
110
  "last_op_id": "0",
@@ -124,6 +127,136 @@ exports[`sync - mongodb > expiring token 2`] = `
124
127
  ]
125
128
  `;
126
129
 
130
+ exports[`sync - mongodb > sends checkpoint complete line for empty checkpoint 1`] = `
131
+ [
132
+ {
133
+ "checkpoint": {
134
+ "buckets": [
135
+ {
136
+ "bucket": "mybucket[]",
137
+ "checksum": -1221282404,
138
+ "count": 1,
139
+ "priority": 3,
140
+ },
141
+ ],
142
+ "last_op_id": "1",
143
+ "write_checkpoint": undefined,
144
+ },
145
+ },
146
+ {
147
+ "data": {
148
+ "after": "0",
149
+ "bucket": "mybucket[]",
150
+ "data": [
151
+ {
152
+ "checksum": 3073684892,
153
+ "data": "{"id":"t1","description":"sync"}",
154
+ "object_id": "t1",
155
+ "object_type": "test",
156
+ "op": "PUT",
157
+ "op_id": "1",
158
+ "subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
159
+ },
160
+ ],
161
+ "has_more": false,
162
+ "next_after": "1",
163
+ },
164
+ },
165
+ {
166
+ "checkpoint_complete": {
167
+ "last_op_id": "1",
168
+ },
169
+ },
170
+ {
171
+ "checkpoint_diff": {
172
+ "last_op_id": "1",
173
+ "removed_buckets": [],
174
+ "updated_buckets": [],
175
+ "write_checkpoint": "1",
176
+ },
177
+ },
178
+ {
179
+ "checkpoint_complete": {
180
+ "last_op_id": "1",
181
+ },
182
+ },
183
+ ]
184
+ `;
185
+
186
+ exports[`sync - mongodb > sync buckets in order 1`] = `
187
+ [
188
+ {
189
+ "checkpoint": {
190
+ "buckets": [
191
+ {
192
+ "bucket": "b0[]",
193
+ "checksum": 920318466,
194
+ "count": 1,
195
+ "priority": 2,
196
+ },
197
+ {
198
+ "bucket": "b1[]",
199
+ "checksum": -1382098757,
200
+ "count": 1,
201
+ "priority": 1,
202
+ },
203
+ ],
204
+ "last_op_id": "2",
205
+ "write_checkpoint": undefined,
206
+ },
207
+ },
208
+ {
209
+ "data": {
210
+ "after": "0",
211
+ "bucket": "b1[]",
212
+ "data": [
213
+ {
214
+ "checksum": 2912868539n,
215
+ "data": "{"id":"earlier","description":"Test 2"}",
216
+ "object_id": "earlier",
217
+ "object_type": "test",
218
+ "op": "PUT",
219
+ "op_id": "2",
220
+ "subkey": "0dfe86bd-d15b-5fd0-9c7b-a31693030ee0",
221
+ },
222
+ ],
223
+ "has_more": false,
224
+ "next_after": "2",
225
+ },
226
+ },
227
+ {
228
+ "partial_checkpoint_complete": {
229
+ "last_op_id": "2",
230
+ "priority": 1,
231
+ },
232
+ },
233
+ {
234
+ "data": {
235
+ "after": "0",
236
+ "bucket": "b0[]",
237
+ "data": [
238
+ {
239
+ "checksum": 920318466n,
240
+ "data": "{"id":"t1","description":"Test 1"}",
241
+ "object_id": "t1",
242
+ "object_type": "test",
243
+ "op": "PUT",
244
+ "op_id": "1",
245
+ "subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
246
+ },
247
+ ],
248
+ "has_more": false,
249
+ "next_after": "1",
250
+ },
251
+ },
252
+ {
253
+ "checkpoint_complete": {
254
+ "last_op_id": "2",
255
+ },
256
+ },
257
+ ]
258
+ `;
259
+
127
260
  exports[`sync - mongodb > sync global data 1`] = `
128
261
  [
129
262
  {
@@ -133,6 +266,7 @@ exports[`sync - mongodb > sync global data 1`] = `
133
266
  "bucket": "mybucket[]",
134
267
  "checksum": -93886621,
135
268
  "count": 2,
269
+ "priority": 3,
136
270
  },
137
271
  ],
138
272
  "last_op_id": "2",
@@ -184,6 +318,7 @@ exports[`sync - mongodb > sync legacy non-raw data 1`] = `
184
318
  "bucket": "mybucket[]",
185
319
  "checksum": -852817836,
186
320
  "count": 1,
321
+ "priority": 3,
187
322
  },
188
323
  ],
189
324
  "last_op_id": "1",
@@ -231,6 +366,7 @@ exports[`sync - mongodb > sync updates to global data 1`] = `
231
366
  "bucket": "mybucket[]",
232
367
  "checksum": 0,
233
368
  "count": 0,
369
+ "priority": 3,
234
370
  },
235
371
  ],
236
372
  "last_op_id": "0",
@@ -256,6 +392,7 @@ exports[`sync - mongodb > sync updates to global data 2`] = `
256
392
  "bucket": "mybucket[]",
257
393
  "checksum": 920318466,
258
394
  "count": 1,
395
+ "priority": 3,
259
396
  },
260
397
  ],
261
398
  "write_checkpoint": undefined,
@@ -299,6 +436,7 @@ exports[`sync - mongodb > sync updates to global data 3`] = `
299
436
  "bucket": "mybucket[]",
300
437
  "checksum": -93886621,
301
438
  "count": 2,
439
+ "priority": 3,
302
440
  },
303
441
  ],
304
442
  "write_checkpoint": undefined,
@@ -1,11 +1,5 @@
1
- import { MongoCompactOptions } from '@module/storage/implementation/MongoCompactor.js';
2
1
  import { register } from '@powersync/service-core-tests';
3
2
  import { describe } from 'vitest';
4
3
  import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
5
4
 
6
- describe('Mongo Sync Bucket Storage Compact', () =>
7
- register.registerCompactTests<MongoCompactOptions>(INITIALIZED_MONGO_STORAGE_FACTORY, {
8
- clearBatchLimit: 2,
9
- moveBatchLimit: 1,
10
- moveBatchQueryLimit: 1
11
- }));
5
+ describe('Mongo Sync Bucket Storage Compact', () => register.registerCompactTests(INITIALIZED_MONGO_STORAGE_FACTORY));
@@ -19,7 +19,7 @@ describe('sync - mongodb', () => {
19
19
  - SELECT id, description FROM "%"
20
20
  `
21
21
  );
22
- using factory = await INITIALIZED_MONGO_STORAGE_FACTORY();
22
+ await using factory = await INITIALIZED_MONGO_STORAGE_FACTORY();
23
23
  const bucketStorage = factory.getInstance(sync_rules);
24
24
 
25
25
  const result = await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {