@powersync/service-module-mongodb-storage 0.18.2 → 0.19.0
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 +48 -0
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.d.ts +3 -0
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.js +41 -0
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.js.map +1 -0
- package/dist/storage/MongoBucketStorage.d.ts +5 -1
- package/dist/storage/MongoBucketStorage.js +5 -1
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +3 -0
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoChecksums.d.ts +2 -0
- package/dist/storage/implementation/MongoChecksums.js +3 -2
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +15 -19
- package/dist/storage/implementation/MongoCompactor.js +68 -260
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js +26 -3
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +12 -5
- package/dist/storage/implementation/MongoSyncBucketStorage.js +25 -14
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +2 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +146 -34
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +2 -0
- package/dist/storage/implementation/common/PersistedBatch.d.ts +6 -0
- package/dist/storage/implementation/common/PersistedBatch.js +15 -8
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +16 -0
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +11 -2
- package/dist/storage/implementation/v1/MongoCompactorV1.js +250 -1
- package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +20 -11
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
- package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +9 -10
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js +2 -8
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -1
- package/dist/storage/implementation/v3/BucketDataContextV3.d.ts +13 -0
- package/dist/storage/implementation/v3/BucketDataContextV3.js +23 -0
- package/dist/storage/implementation/v3/BucketDataContextV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +3 -1
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +1 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.js +59 -103
- package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +23 -2
- package/dist/storage/implementation/v3/MongoCompactorV3.js +354 -219
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +5 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +12 -11
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -1
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +5 -3
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +109 -106
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +5 -2
- package/dist/storage/implementation/v3/PersistedBatchV3.js +53 -15
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +2 -1
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +3 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
- package/dist/storage/implementation/v3/bucket-format.d.ts +10 -1
- package/dist/storage/implementation/v3/bucket-format.js +28 -9
- package/dist/storage/implementation/v3/bucket-format.js.map +1 -1
- package/dist/storage/implementation/v3/chunking.js +3 -1
- package/dist/storage/implementation/v3/chunking.js.map +1 -1
- package/dist/storage/implementation/v3/models.d.ts +38 -1
- package/dist/storage/implementation/v3/models.js.map +1 -1
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.d.ts +21 -0
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js +44 -0
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.d.ts +30 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.js +12 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.d.ts +70 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js +146 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.d.ts +42 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js +285 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js.map +1 -0
- package/dist/types/types.d.ts +35 -0
- package/dist/types/types.js +35 -1
- package/dist/types/types.js.map +1 -1
- package/dist/utils/test-utils.js +3 -1
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.d.ts +8 -1
- package/dist/utils/util.js +125 -2
- package/dist/utils/util.js.map +1 -1
- package/package.json +10 -7
- package/src/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.ts +55 -0
- package/src/storage/MongoBucketStorage.ts +10 -2
- package/src/storage/implementation/MongoBucketBatch.ts +4 -0
- package/src/storage/implementation/MongoChecksums.ts +5 -2
- package/src/storage/implementation/MongoCompactor.ts +90 -314
- package/src/storage/implementation/MongoStorageProvider.ts +32 -3
- package/src/storage/implementation/MongoSyncBucketStorage.ts +34 -24
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +164 -37
- package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +2 -0
- package/src/storage/implementation/common/PersistedBatch.ts +22 -10
- package/src/storage/implementation/models.ts +16 -0
- package/src/storage/implementation/v1/MongoCompactorV1.ts +292 -8
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +54 -40
- package/src/storage/implementation/v1/SingleBucketStoreV1.ts +18 -27
- package/src/storage/implementation/v3/BucketDataContextV3.ts +32 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +3 -1
- package/src/storage/implementation/v3/MongoChecksumsV3.ts +75 -105
- package/src/storage/implementation/v3/MongoCompactorV3.ts +456 -258
- package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +21 -19
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +123 -126
- package/src/storage/implementation/v3/PersistedBatchV3.ts +69 -16
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +5 -0
- package/src/storage/implementation/v3/bucket-format.ts +36 -9
- package/src/storage/implementation/v3/chunking.ts +3 -1
- package/src/storage/implementation/v3/models.ts +40 -1
- package/src/storage/implementation/v3/object-storage/BucketDataObjectStorage.ts +54 -0
- package/src/storage/implementation/v3/object-storage/ObjectStorage.ts +29 -0
- package/src/storage/implementation/v3/object-storage/ObjectStorageLifecycle.ts +171 -0
- package/src/storage/implementation/v3/object-storage/S3ObjectStorage.ts +343 -0
- package/src/types/types.ts +42 -1
- package/src/utils/test-utils.ts +3 -1
- package/src/utils/util.ts +182 -4
- package/test/src/__snapshots__/storage_sync.test.ts.snap +1 -583
- package/test/src/cleanup-stopped-sync-configs.test.ts +24 -1
- package/test/src/helpers/MemoryObjectStorage.ts +53 -0
- package/test/src/helpers/s3TestFactory.ts +69 -0
- package/test/src/object_storage_lifecycle.test.ts +59 -0
- package/test/src/setup.ts +6 -1
- package/test/src/storage.test.ts +216 -2
- package/test/src/storage_compacting.test.ts +176 -187
- package/test/src/storage_object_storage_inline_threshold.test.ts +116 -0
- package/test/src/storage_s3_checksums.test.ts +191 -0
- package/test/src/storage_s3_compaction_lifecycle.test.ts +417 -0
- package/test/src/storage_s3_reading.test.ts +526 -0
- package/test/src/storage_s3_writing.test.ts +135 -0
- package/test/src/storage_sync.test.ts +95 -5
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/implementation/common/SingleBucketStore.d.ts +0 -54
- package/dist/storage/implementation/common/SingleBucketStore.js +0 -3
- package/dist/storage/implementation/common/SingleBucketStore.js.map +0 -1
- package/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +0 -18
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js +0 -84
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +0 -1
- package/src/storage/implementation/common/SingleBucketStore.ts +0 -63
- package/src/storage/implementation/v3/SingleBucketStoreV3.ts +0 -108
|
@@ -191,7 +191,7 @@ function registerSyncStorageTests(storageConfig: storage.TestStorageConfig, stor
|
|
|
191
191
|
const checkpoint = flushResult!.flushed_op;
|
|
192
192
|
|
|
193
193
|
const options: storage.BucketDataBatchOptions = {};
|
|
194
|
-
const batch1 = await test_utils.
|
|
194
|
+
const batch1 = await test_utils.getBatchArray(
|
|
195
195
|
bucketStorage.getBucketDataBatch(
|
|
196
196
|
test_utils.testCheckpoint(checkpoint),
|
|
197
197
|
[bucketRequest(syncRulesContent, 'global[]', 0n)],
|
|
@@ -208,7 +208,7 @@ function registerSyncStorageTests(storageConfig: storage.TestStorageConfig, stor
|
|
|
208
208
|
next_after: '2'
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
-
const batch2 = await test_utils.
|
|
211
|
+
const batch2 = await test_utils.getBatchArray(
|
|
212
212
|
bucketStorage.getBucketDataBatch(
|
|
213
213
|
test_utils.testCheckpoint(checkpoint),
|
|
214
214
|
[bucketRequest(syncRulesContent, 'global[]', batch1[0].chunkData.next_after)],
|
|
@@ -224,7 +224,7 @@ function registerSyncStorageTests(storageConfig: storage.TestStorageConfig, stor
|
|
|
224
224
|
next_after: '3'
|
|
225
225
|
});
|
|
226
226
|
|
|
227
|
-
const batch3 = await test_utils.
|
|
227
|
+
const batch3 = await test_utils.getBatchArray(
|
|
228
228
|
bucketStorage.getBucketDataBatch(
|
|
229
229
|
test_utils.testCheckpoint(checkpoint),
|
|
230
230
|
[bucketRequest(syncRulesContent, 'global[]', batch2[0].chunkData.next_after)],
|
|
@@ -1467,6 +1467,96 @@ streams:
|
|
|
1467
1467
|
expect(await mongoFactory.db.current_data.countDocuments({ '_id.g': syncRules.replicationStreamId })).toBe(0);
|
|
1468
1468
|
});
|
|
1469
1469
|
|
|
1470
|
+
test.runIf(storageVersion < 3)(
|
|
1471
|
+
'clear removes large v1 current_data sets without affecting other streams',
|
|
1472
|
+
async () => {
|
|
1473
|
+
await using factory = await storageConfig.factory();
|
|
1474
|
+
const syncRules = await factory.updateSyncRules(
|
|
1475
|
+
updateSyncRulesFromYaml(MINIMAL_SYNC_RULES, {
|
|
1476
|
+
storageVersion
|
|
1477
|
+
})
|
|
1478
|
+
);
|
|
1479
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
1480
|
+
const mongoFactory = factory as MongoBucketStorage;
|
|
1481
|
+
const sourceTableId = new bson.ObjectId();
|
|
1482
|
+
const documents = Array.from({ length: 10_002 }, (_, index) => ({
|
|
1483
|
+
_id: {
|
|
1484
|
+
g: syncRules.replicationStreamId,
|
|
1485
|
+
t: sourceTableId,
|
|
1486
|
+
k: index
|
|
1487
|
+
},
|
|
1488
|
+
data: new bson.Binary(),
|
|
1489
|
+
buckets: [],
|
|
1490
|
+
lookups: []
|
|
1491
|
+
}));
|
|
1492
|
+
await mongoFactory.db.current_data.insertMany([
|
|
1493
|
+
...documents,
|
|
1494
|
+
{
|
|
1495
|
+
_id: {
|
|
1496
|
+
g: syncRules.replicationStreamId + 1,
|
|
1497
|
+
t: sourceTableId,
|
|
1498
|
+
k: 0
|
|
1499
|
+
},
|
|
1500
|
+
data: new bson.Binary(),
|
|
1501
|
+
buckets: [],
|
|
1502
|
+
lookups: []
|
|
1503
|
+
}
|
|
1504
|
+
]);
|
|
1505
|
+
|
|
1506
|
+
await bucketStorage.clear();
|
|
1507
|
+
|
|
1508
|
+
expect(await mongoFactory.db.current_data.countDocuments({ '_id.g': syncRules.replicationStreamId })).toBe(0);
|
|
1509
|
+
expect(await mongoFactory.db.current_data.countDocuments({ '_id.g': syncRules.replicationStreamId + 1 })).toBe(1);
|
|
1510
|
+
}
|
|
1511
|
+
);
|
|
1512
|
+
|
|
1513
|
+
test.runIf(storageVersion < 3)(
|
|
1514
|
+
'clear removes large v1 parameter index sets without affecting other streams',
|
|
1515
|
+
async () => {
|
|
1516
|
+
await using factory = await storageConfig.factory();
|
|
1517
|
+
const syncRules = await factory.updateSyncRules(
|
|
1518
|
+
updateSyncRulesFromYaml(MINIMAL_SYNC_RULES, {
|
|
1519
|
+
storageVersion
|
|
1520
|
+
})
|
|
1521
|
+
);
|
|
1522
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
1523
|
+
const mongoFactory = factory as MongoBucketStorage;
|
|
1524
|
+
const sourceTableId = new bson.ObjectId();
|
|
1525
|
+
const documents = Array.from({ length: 10_002 }, (_, index) => ({
|
|
1526
|
+
_id: BigInt(index * 2),
|
|
1527
|
+
key: {
|
|
1528
|
+
g: syncRules.replicationStreamId,
|
|
1529
|
+
t: sourceTableId,
|
|
1530
|
+
k: index
|
|
1531
|
+
},
|
|
1532
|
+
lookup: new bson.Binary(),
|
|
1533
|
+
bucket_parameters: []
|
|
1534
|
+
}));
|
|
1535
|
+
await mongoFactory.db.bucket_parameters.insertMany([
|
|
1536
|
+
...documents,
|
|
1537
|
+
{
|
|
1538
|
+
_id: 1n,
|
|
1539
|
+
key: {
|
|
1540
|
+
g: syncRules.replicationStreamId + 1,
|
|
1541
|
+
t: sourceTableId,
|
|
1542
|
+
k: 0
|
|
1543
|
+
},
|
|
1544
|
+
lookup: new bson.Binary(),
|
|
1545
|
+
bucket_parameters: []
|
|
1546
|
+
}
|
|
1547
|
+
]);
|
|
1548
|
+
|
|
1549
|
+
await bucketStorage.clear();
|
|
1550
|
+
|
|
1551
|
+
expect(await mongoFactory.db.bucket_parameters.countDocuments({ 'key.g': syncRules.replicationStreamId })).toBe(
|
|
1552
|
+
0
|
|
1553
|
+
);
|
|
1554
|
+
expect(
|
|
1555
|
+
await mongoFactory.db.bucket_parameters.countDocuments({ 'key.g': syncRules.replicationStreamId + 1 })
|
|
1556
|
+
).toBe(1);
|
|
1557
|
+
}
|
|
1558
|
+
);
|
|
1559
|
+
|
|
1470
1560
|
test.runIf(storageVersion < 3)('storage metrics include v1 current_data', async () => {
|
|
1471
1561
|
await using factory = await storageConfig.factory();
|
|
1472
1562
|
const syncRules = await factory.updateSyncRules(
|
|
@@ -1747,7 +1837,7 @@ describe('sync - mongodb', () => {
|
|
|
1747
1837
|
async function getFilteredOps(start: number, checkpoint: number): Promise<bigint[]> {
|
|
1748
1838
|
const { syncRules, bucketStorage } = await setupFilteringTest();
|
|
1749
1839
|
const request = bucketRequest(syncRules.syncConfigContent[0], 'global[]', BigInt(start));
|
|
1750
|
-
const batch = await test_utils.
|
|
1840
|
+
const batch = await test_utils.getBatchArray(
|
|
1751
1841
|
bucketStorage.getBucketDataBatch(test_utils.testCheckpoint(BigInt(checkpoint)), [request])
|
|
1752
1842
|
);
|
|
1753
1843
|
const ops = batch.flatMap((b) => b.chunkData.data.map((d) => BigInt(d.op_id)));
|
|
@@ -1894,7 +1984,7 @@ describe('sync - mongodb', () => {
|
|
|
1894
1984
|
const roundRequests = requests
|
|
1895
1985
|
.filter((request) => pending.has(request.bucket))
|
|
1896
1986
|
.map((request) => ({ ...request, start: positions.get(request.bucket)! }));
|
|
1897
|
-
const batch = await test_utils.
|
|
1987
|
+
const batch = await test_utils.getBatchArray(
|
|
1898
1988
|
bucketStorage.getBucketDataBatch(test_utils.testCheckpoint(end), roundRequests)
|
|
1899
1989
|
);
|
|
1900
1990
|
let anyHasMore = false;
|