@powersync/service-module-mongodb-storage 0.15.4 → 0.17.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 +69 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +1 -1
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +1 -1
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +2 -2
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -1
- package/dist/storage/MongoBucketStorage.d.ts +8 -6
- package/dist/storage/MongoBucketStorage.js +153 -66
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +15 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +58 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/CheckpointState.d.ts +20 -0
- package/dist/storage/implementation/CheckpointState.js +31 -0
- package/dist/storage/implementation/CheckpointState.js.map +1 -0
- package/dist/storage/implementation/MongoBucketBatch.d.ts +48 -35
- package/dist/storage/implementation/MongoBucketBatch.js +118 -379
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatchShared.d.ts +5 -0
- package/dist/storage/implementation/MongoBucketBatchShared.js +8 -0
- package/dist/storage/implementation/MongoBucketBatchShared.js.map +1 -0
- package/dist/storage/implementation/MongoChecksums.d.ts +29 -17
- package/dist/storage/implementation/MongoChecksums.js +13 -72
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +98 -58
- package/dist/storage/implementation/MongoCompactor.js +229 -296
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +11 -6
- package/dist/storage/implementation/MongoParameterCompactor.js +11 -8
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +14 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js +67 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +22 -5
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +56 -13
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +61 -32
- package/dist/storage/implementation/MongoSyncBucketStorage.js +85 -523
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +10 -4
- package/dist/storage/implementation/MongoSyncRulesLock.js +19 -13
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +1 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/OperationBatch.js +1 -1
- package/dist/storage/implementation/SyncRuleStateUpdate.d.ts +14 -0
- package/dist/storage/implementation/SyncRuleStateUpdate.js +36 -0
- package/dist/storage/implementation/SyncRuleStateUpdate.js.map +1 -0
- package/dist/storage/implementation/common/BucketDataDoc.d.ts +35 -0
- package/dist/storage/implementation/common/BucketDataDoc.js +2 -0
- package/dist/storage/implementation/common/BucketDataDoc.js.map +1 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +13 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +2 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +1 -0
- package/dist/storage/implementation/common/PersistedBatch.d.ts +108 -0
- package/dist/storage/implementation/common/PersistedBatch.js +237 -0
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -0
- package/dist/storage/implementation/common/SingleBucketStore.d.ts +54 -0
- package/dist/storage/implementation/common/SingleBucketStore.js +3 -0
- package/dist/storage/implementation/common/SingleBucketStore.js.map +1 -0
- package/dist/storage/implementation/common/SourceRecordStore.d.ts +35 -0
- package/dist/storage/implementation/common/SourceRecordStore.js +2 -0
- package/dist/storage/implementation/common/SourceRecordStore.js.map +1 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.d.ts +27 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +57 -0
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +7 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.js +9 -0
- package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -0
- package/dist/storage/implementation/db.d.ts +41 -36
- package/dist/storage/implementation/db.js +77 -99
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +79 -66
- package/dist/storage/implementation/models.js +20 -1
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +27 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +407 -0
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.d.ts +12 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.js +56 -0
- package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +23 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.js +52 -0
- package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.d.ts +9 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js +20 -0
- package/dist/storage/implementation/v1/MongoParameterCompactorV1.js.map +1 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +50 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +354 -0
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.d.ts +25 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.js +183 -0
- package/dist/storage/implementation/v1/PersistedBatchV1.js.map +1 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +18 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js +57 -0
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.d.ts +19 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.js +105 -0
- package/dist/storage/implementation/v1/SourceRecordStoreV1.js.map +1 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +12 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +20 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -0
- package/dist/storage/implementation/v1/models.d.ts +45 -0
- package/dist/storage/implementation/v1/models.js +37 -0
- package/dist/storage/implementation/v1/models.js.map +1 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +30 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +463 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +15 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.js +84 -0
- package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +23 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.js +68 -0
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +9 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +18 -0
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +4 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js +9 -0
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +63 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +508 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +28 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.js +259 -0
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +18 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js +48 -0
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +1 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +22 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js +164 -0
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +22 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +74 -0
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +101 -0
- package/dist/storage/implementation/v3/models.js +34 -0
- package/dist/storage/implementation/v3/models.js.map +1 -0
- package/dist/storage/storage-index.d.ts +6 -3
- package/dist/storage/storage-index.js +6 -3
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/utils/util.d.ts +10 -3
- package/dist/utils/util.js +24 -3
- package/dist/utils/util.js.map +1 -1
- package/package.json +9 -9
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +1 -1
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +7 -7
- package/src/storage/MongoBucketStorage.ts +254 -99
- package/src/storage/implementation/BucketDefinitionMapping.ts +75 -0
- package/src/storage/implementation/CheckpointState.ts +59 -0
- package/src/storage/implementation/MongoBucketBatch.ts +182 -490
- package/src/storage/implementation/MongoBucketBatchShared.ts +11 -0
- package/src/storage/implementation/MongoChecksums.ts +53 -75
- package/src/storage/implementation/MongoCompactor.ts +374 -404
- package/src/storage/implementation/MongoParameterCompactor.ts +37 -24
- package/src/storage/implementation/MongoPersistedSyncRules.ts +82 -0
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +78 -16
- package/src/storage/implementation/MongoSyncBucketStorage.ts +179 -628
- package/src/storage/implementation/MongoSyncRulesLock.ts +20 -16
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +3 -1
- package/src/storage/implementation/OperationBatch.ts +1 -1
- package/src/storage/implementation/SyncRuleStateUpdate.ts +38 -0
- package/src/storage/implementation/common/BucketDataDoc.ts +37 -0
- package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +15 -0
- package/src/storage/implementation/common/PersistedBatch.ts +364 -0
- package/src/storage/implementation/common/SingleBucketStore.ts +63 -0
- package/src/storage/implementation/common/SourceRecordStore.ts +48 -0
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +80 -0
- package/src/storage/implementation/createMongoSyncBucketStorage.ts +25 -0
- package/src/storage/implementation/db.ts +110 -131
- package/src/storage/implementation/models.ts +102 -79
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +509 -0
- package/src/storage/implementation/v1/MongoChecksumsV1.ts +75 -0
- package/src/storage/implementation/v1/MongoCompactorV1.ts +93 -0
- package/src/storage/implementation/v1/MongoParameterCompactorV1.ts +26 -0
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +543 -0
- package/src/storage/implementation/v1/PersistedBatchV1.ts +229 -0
- package/src/storage/implementation/v1/SingleBucketStoreV1.ts +74 -0
- package/src/storage/implementation/v1/SourceRecordStoreV1.ts +156 -0
- package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +28 -0
- package/src/storage/implementation/v1/models.ts +99 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +607 -0
- package/src/storage/implementation/v3/MongoChecksumsV3.ts +120 -0
- package/src/storage/implementation/v3/MongoCompactorV3.ts +107 -0
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +24 -0
- package/src/storage/implementation/v3/MongoParameterLookupV3.ts +11 -0
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +678 -0
- package/src/storage/implementation/v3/PersistedBatchV3.ts +317 -0
- package/src/storage/implementation/v3/SingleBucketStoreV3.ts +68 -0
- package/src/storage/implementation/v3/SourceRecordStoreV3.ts +226 -0
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +117 -0
- package/src/storage/implementation/v3/models.ts +164 -0
- package/src/storage/storage-index.ts +6 -3
- package/src/utils/util.ts +34 -5
- package/test/src/storage_compacting.test.ts +57 -29
- package/test/src/storage_sync.test.ts +767 -5
- package/test/src/storeCurrentData.test.ts +211 -0
- package/test/tsconfig.json +0 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/implementation/PersistedBatch.d.ts +0 -71
- package/dist/storage/implementation/PersistedBatch.js +0 -354
- package/dist/storage/implementation/PersistedBatch.js.map +0 -1
- package/src/storage/implementation/PersistedBatch.ts +0 -432
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { storage, updateSyncRulesFromYaml } from '@powersync/service-core';
|
|
2
|
+
import { bucketRequest, test_utils } from '@powersync/service-core-tests';
|
|
3
|
+
import * as bson from 'bson';
|
|
4
|
+
import { describe, expect, test } from 'vitest';
|
|
5
|
+
import { MongoBucketStorage } from '../../src/storage/MongoBucketStorage.js';
|
|
6
|
+
import { INITIALIZED_MONGO_STORAGE_FACTORY, TEST_STORAGE_VERSIONS } from './util.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Tests for the per-table `storeCurrentData` flag in MongoDB storage (both v1 and v3).
|
|
10
|
+
*
|
|
11
|
+
* Two things are exercised:
|
|
12
|
+
* 1. `resolveTables` derives `storeCurrentData = !sendsCompleteRows` in memory on every call
|
|
13
|
+
* (it is not persisted; an unreported source defaults to keeping a copy).
|
|
14
|
+
* 2. A batch honours the flag: when `storeCurrentData` is false, the row payload is NOT kept in
|
|
15
|
+
* the current_data collection, while the bucket data is still produced as usual.
|
|
16
|
+
*
|
|
17
|
+
* The mapping from a source's replica identity to `sendsCompleteRows` is a Postgres concern and is
|
|
18
|
+
* covered in module-postgres; here we only exercise the storage layer's boolean handling.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const SYNC_RULES = `
|
|
22
|
+
bucket_definitions:
|
|
23
|
+
global:
|
|
24
|
+
data:
|
|
25
|
+
- SELECT id, description FROM "%"
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
function descriptor(name: string, sendsCompleteRows?: boolean): storage.SourceEntityDescriptor {
|
|
29
|
+
return {
|
|
30
|
+
connectionTag: storage.SourceTable.DEFAULT_TAG,
|
|
31
|
+
objectId: name,
|
|
32
|
+
schema: 'public',
|
|
33
|
+
name,
|
|
34
|
+
replicaIdColumns: [{ name: 'id', type: 'VARCHAR', typeId: 25 }],
|
|
35
|
+
sendsCompleteRows
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function singleUseIdGenerator(hex: string) {
|
|
40
|
+
let used = false;
|
|
41
|
+
return () => {
|
|
42
|
+
if (used) {
|
|
43
|
+
throw new Error(`Can only generate a single id using ${hex}`);
|
|
44
|
+
}
|
|
45
|
+
used = true;
|
|
46
|
+
return new bson.ObjectId(hex);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns the row payload stored in current_data for the (single) record of `table`, or null if no
|
|
52
|
+
* payload is stored. v1 stores an empty BSON object ({}) when storeCurrentData is false; v3 stores
|
|
53
|
+
* null. Both are normalised to null here so the assertions are version-agnostic.
|
|
54
|
+
*/
|
|
55
|
+
async function storedRowPayload(
|
|
56
|
+
storageVersion: number,
|
|
57
|
+
factory: storage.BucketStorageFactory,
|
|
58
|
+
bucketStorage: storage.SyncRulesBucketStorage,
|
|
59
|
+
syncRulesId: number,
|
|
60
|
+
table: storage.SourceTable
|
|
61
|
+
): Promise<Record<string, any> | null> {
|
|
62
|
+
let data: bson.Binary | null | undefined;
|
|
63
|
+
if (storageVersion < 3) {
|
|
64
|
+
const db = (factory as MongoBucketStorage).db;
|
|
65
|
+
const doc = await db.current_data.findOne({ '_id.g': syncRulesId });
|
|
66
|
+
data = doc?.data;
|
|
67
|
+
} else {
|
|
68
|
+
const db = (bucketStorage as any).db;
|
|
69
|
+
const doc = await db.sourceRecordsV3(syncRulesId, table.id).findOne({});
|
|
70
|
+
data = doc?.data;
|
|
71
|
+
}
|
|
72
|
+
if (data == null) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const decoded = bson.deserialize(data.buffer);
|
|
76
|
+
return Object.keys(decoded).length === 0 ? null : decoded;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function registerStoreCurrentDataTests(storageVersion: number) {
|
|
80
|
+
test('resolveTables derives storeCurrentData fresh each call, with no persisted memory', async () => {
|
|
81
|
+
await using factory = await INITIALIZED_MONGO_STORAGE_FACTORY.factory();
|
|
82
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES, { storageVersion }));
|
|
83
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
84
|
+
|
|
85
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
86
|
+
|
|
87
|
+
// Sources that always send complete rows (e.g. Postgres REPLICA IDENTITY FULL) don't need current_data.
|
|
88
|
+
const complete = await writer.resolveTables({
|
|
89
|
+
connection_id: 1,
|
|
90
|
+
source: descriptor('test_complete', true),
|
|
91
|
+
idGenerator: singleUseIdGenerator('6544e3899293153fa7b38301')
|
|
92
|
+
});
|
|
93
|
+
expect(complete.tables[0].storeCurrentData).toBe(false);
|
|
94
|
+
|
|
95
|
+
// Sources that may send partial/key data still need current_data.
|
|
96
|
+
const partial = await writer.resolveTables({
|
|
97
|
+
connection_id: 1,
|
|
98
|
+
source: descriptor('test_partial', false),
|
|
99
|
+
idGenerator: singleUseIdGenerator('6544e3899293153fa7b38302')
|
|
100
|
+
});
|
|
101
|
+
expect(partial.tables[0].storeCurrentData).toBe(true);
|
|
102
|
+
|
|
103
|
+
// Re-resolving an already-resolved table with no completeness info (sendsCompleteRows undefined)
|
|
104
|
+
// does not remember the earlier value: nothing is persisted, so it falls back to the default
|
|
105
|
+
// (keep a copy).
|
|
106
|
+
const reResolved = await writer.resolveTables({
|
|
107
|
+
connection_id: 1,
|
|
108
|
+
source: descriptor('test_complete')
|
|
109
|
+
});
|
|
110
|
+
expect(reResolved.tables[0].storeCurrentData).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('storeCurrentData=false omits the row payload from current_data, data still syncs', async () => {
|
|
114
|
+
await using factory = await INITIALIZED_MONGO_STORAGE_FACTORY.factory();
|
|
115
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES, { storageVersion }));
|
|
116
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
117
|
+
|
|
118
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
119
|
+
const table = await test_utils.resolveTestTable(writer, 'test_data', ['id'], INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
120
|
+
table.storeCurrentData = false;
|
|
121
|
+
|
|
122
|
+
await writer.save({
|
|
123
|
+
sourceTable: table,
|
|
124
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
125
|
+
after: { id: 'test1', description: 'test data' },
|
|
126
|
+
afterReplicaId: test_utils.rid('test1')
|
|
127
|
+
});
|
|
128
|
+
const flushResult = await writer.flush();
|
|
129
|
+
const checkpoint = flushResult!.flushed_op;
|
|
130
|
+
|
|
131
|
+
const batch = await test_utils.fromAsync(
|
|
132
|
+
bucketStorage.getBucketDataBatch(checkpoint, [bucketRequest(syncRules, 'global[]', 0n)])
|
|
133
|
+
);
|
|
134
|
+
expect(test_utils.getBatchData(batch)).toMatchObject([{ op: 'PUT', object_id: 'test1' }]);
|
|
135
|
+
|
|
136
|
+
// No row payload retained in current_data.
|
|
137
|
+
expect(await storedRowPayload(storageVersion, factory, bucketStorage, syncRules.id, table)).toBeNull();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('storeCurrentData=true retains the row payload in current_data', async () => {
|
|
141
|
+
await using factory = await INITIALIZED_MONGO_STORAGE_FACTORY.factory();
|
|
142
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES, { storageVersion }));
|
|
143
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
144
|
+
|
|
145
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
146
|
+
const table = await test_utils.resolveTestTable(writer, 'test_data', ['id'], INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
147
|
+
table.storeCurrentData = true;
|
|
148
|
+
|
|
149
|
+
await writer.save({
|
|
150
|
+
sourceTable: table,
|
|
151
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
152
|
+
after: { id: 'test1', description: 'test data' },
|
|
153
|
+
afterReplicaId: test_utils.rid('test1')
|
|
154
|
+
});
|
|
155
|
+
const flushResult = await writer.flush();
|
|
156
|
+
const checkpoint = flushResult!.flushed_op;
|
|
157
|
+
|
|
158
|
+
const batch = await test_utils.fromAsync(
|
|
159
|
+
bucketStorage.getBucketDataBatch(checkpoint, [bucketRequest(syncRules, 'global[]', 0n)])
|
|
160
|
+
);
|
|
161
|
+
expect(test_utils.getBatchData(batch)).toMatchObject([{ op: 'PUT', object_id: 'test1' }]);
|
|
162
|
+
|
|
163
|
+
expect(await storedRowPayload(storageVersion, factory, bucketStorage, syncRules.id, table)).toMatchObject({
|
|
164
|
+
id: 'test1'
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('storeCurrentData=false processes UPDATE without a stored copy', async () => {
|
|
169
|
+
await using factory = await INITIALIZED_MONGO_STORAGE_FACTORY.factory();
|
|
170
|
+
const syncRules = await factory.updateSyncRules(updateSyncRulesFromYaml(SYNC_RULES, { storageVersion }));
|
|
171
|
+
const bucketStorage = factory.getInstance(syncRules);
|
|
172
|
+
|
|
173
|
+
await using writer = await bucketStorage.createWriter(test_utils.BATCH_OPTIONS);
|
|
174
|
+
const table = await test_utils.resolveTestTable(writer, 'test_data', ['id'], INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
175
|
+
table.storeCurrentData = false;
|
|
176
|
+
|
|
177
|
+
// With REPLICA IDENTITY FULL the UPDATE carries the full row, so it is applied from `after`
|
|
178
|
+
// rather than a stored copy of the previous row.
|
|
179
|
+
await writer.save({
|
|
180
|
+
sourceTable: table,
|
|
181
|
+
tag: storage.SaveOperationTag.INSERT,
|
|
182
|
+
after: { id: 'test1', description: 'original' },
|
|
183
|
+
afterReplicaId: test_utils.rid('test1')
|
|
184
|
+
});
|
|
185
|
+
await writer.save({
|
|
186
|
+
sourceTable: table,
|
|
187
|
+
tag: storage.SaveOperationTag.UPDATE,
|
|
188
|
+
after: { id: 'test1', description: 'updated' },
|
|
189
|
+
afterReplicaId: test_utils.rid('test1')
|
|
190
|
+
});
|
|
191
|
+
const flushResult = await writer.flush();
|
|
192
|
+
const checkpoint = flushResult!.flushed_op;
|
|
193
|
+
|
|
194
|
+
const batch = await test_utils.fromAsync(
|
|
195
|
+
bucketStorage.getBucketDataBatch(checkpoint, [bucketRequest(syncRules, 'global[]', 0n)])
|
|
196
|
+
);
|
|
197
|
+
const data = test_utils.getBatchData(batch);
|
|
198
|
+
expect(data.length).toBeGreaterThan(0);
|
|
199
|
+
expect(data.at(-1)).toMatchObject({ op: 'PUT', object_id: 'test1' });
|
|
200
|
+
|
|
201
|
+
expect(await storedRowPayload(storageVersion, factory, bucketStorage, syncRules.id, table)).toBeNull();
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
describe('MongoDB storage - storeCurrentData', () => {
|
|
206
|
+
for (const storageVersion of TEST_STORAGE_VERSIONS) {
|
|
207
|
+
describe(`storage v${storageVersion}`, () => {
|
|
208
|
+
registerStoreCurrentDataTests(storageVersion);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
});
|