@powersync/service-module-mongodb-storage 0.17.0 → 0.18.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.
- package/CHANGELOG.md +27 -0
- package/dist/storage/MongoBucketStorage.d.ts +34 -16
- package/dist/storage/MongoBucketStorage.js +219 -70
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +42 -23
- package/dist/storage/implementation/MongoBucketBatch.js +61 -44
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoChecksums.d.ts +10 -9
- package/dist/storage/implementation/MongoChecksums.js +3 -111
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +2 -0
- package/dist/storage/implementation/MongoCompactor.js +18 -9
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoHydrationState.d.ts +11 -0
- package/dist/storage/implementation/MongoHydrationState.js +49 -0
- package/dist/storage/implementation/MongoHydrationState.js.map +1 -0
- package/dist/storage/implementation/MongoParameterCompactor.d.ts +6 -5
- package/dist/storage/implementation/MongoParameterCompactor.js +24 -1
- package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +13 -0
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js +64 -0
- package/dist/storage/implementation/MongoParsedSyncConfigSet.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.d.ts +36 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.js +90 -0
- package/dist/storage/implementation/MongoPersistedReplicationStream.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.d.ts +25 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js +123 -0
- package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -0
- package/dist/storage/implementation/MongoStorageProvider.js +5 -2
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +41 -23
- package/dist/storage/implementation/MongoSyncBucketStorage.js +51 -43
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +1 -1
- package/dist/storage/implementation/MongoSyncRulesLock.js +3 -3
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +6 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js +2 -0
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js.map +1 -0
- package/dist/storage/implementation/common/PersistedBatch.d.ts +1 -2
- package/dist/storage/implementation/common/PersistedBatch.js +5 -0
- package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +1 -1
- package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
- package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +2 -2
- package/dist/storage/implementation/createMongoSyncBucketStorage.js +4 -4
- package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/db.js +9 -14
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +4 -13
- package/dist/storage/implementation/models.js.map +1 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +9 -1
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js +42 -26
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoChecksumsV1.js +114 -3
- package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +15 -17
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +47 -45
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +2 -1
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +3 -0
- package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -1
- package/dist/storage/implementation/v1/models.d.ts +10 -1
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +8 -4
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +286 -259
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +27 -7
- package/dist/storage/implementation/v3/MongoChecksumsV3.js +202 -18
- package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +19 -2
- package/dist/storage/implementation/v3/MongoCompactorV3.js +511 -22
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +62 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +350 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +40 -28
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +232 -116
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +1 -1
- package/dist/storage/implementation/v3/PersistedBatchV3.js +43 -20
- package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js +52 -16
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +1 -1
- package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +3 -3
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js +13 -11
- package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -1
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +13 -12
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +29 -27
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
- package/dist/storage/implementation/v3/bucket-format.d.ts +4 -0
- package/dist/storage/implementation/v3/bucket-format.js +58 -0
- package/dist/storage/implementation/v3/bucket-format.js.map +1 -0
- package/dist/storage/implementation/v3/chunking.d.ts +10 -0
- package/dist/storage/implementation/v3/chunking.js +28 -0
- package/dist/storage/implementation/v3/chunking.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +64 -21
- package/dist/storage/implementation/v3/models.js +11 -28
- package/dist/storage/implementation/v3/models.js.map +1 -1
- package/dist/storage/implementation/v3/source-table-utils.d.ts +55 -0
- package/dist/storage/implementation/v3/source-table-utils.js +214 -0
- package/dist/storage/implementation/v3/source-table-utils.js.map +1 -0
- package/dist/storage/storage-index.d.ts +4 -4
- package/dist/storage/storage-index.js +4 -4
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/utils/test-utils.d.ts +1 -2
- package/dist/utils/test-utils.js +5 -1
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.d.ts +1 -1
- package/dist/utils/util.js +3 -2
- package/dist/utils/util.js.map +1 -1
- package/package.json +9 -19
- package/src/storage/MongoBucketStorage.ts +334 -87
- package/src/storage/implementation/MongoBucketBatch.ts +86 -58
- package/src/storage/implementation/MongoChecksums.ts +6 -138
- package/src/storage/implementation/MongoCompactor.ts +19 -9
- package/src/storage/implementation/MongoHydrationState.ts +61 -0
- package/src/storage/implementation/MongoParameterCompactor.ts +24 -5
- package/src/storage/implementation/MongoParsedSyncConfigSet.ts +88 -0
- package/src/storage/implementation/MongoPersistedReplicationStream.ts +118 -0
- package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +154 -0
- package/src/storage/implementation/MongoStorageProvider.ts +5 -2
- package/src/storage/implementation/MongoSyncBucketStorage.ts +70 -56
- package/src/storage/implementation/MongoSyncRulesLock.ts +7 -4
- package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +7 -0
- package/src/storage/implementation/common/PersistedBatch.ts +7 -3
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +1 -1
- package/src/storage/implementation/createMongoSyncBucketStorage.ts +21 -7
- package/src/storage/implementation/db.ts +11 -19
- package/src/storage/implementation/models.ts +4 -14
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +55 -34
- package/src/storage/implementation/v1/MongoChecksumsV1.ts +137 -4
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +70 -64
- package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +11 -1
- package/src/storage/implementation/v1/models.ts +11 -1
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +358 -314
- package/src/storage/implementation/v3/MongoChecksumsV3.ts +262 -26
- package/src/storage/implementation/v3/MongoCompactorV3.ts +646 -29
- package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +480 -0
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +315 -157
- package/src/storage/implementation/v3/PersistedBatchV3.ts +62 -36
- package/src/storage/implementation/v3/SingleBucketStoreV3.ts +59 -19
- package/src/storage/implementation/v3/SourceRecordStoreV3.ts +12 -12
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +41 -36
- package/src/storage/implementation/v3/bucket-format.ts +70 -0
- package/src/storage/implementation/v3/chunking.ts +38 -0
- package/src/storage/implementation/v3/models.ts +93 -55
- package/src/storage/implementation/v3/source-table-utils.ts +392 -0
- package/src/storage/storage-index.ts +12 -4
- package/src/utils/test-utils.ts +6 -3
- package/src/utils/util.ts +3 -2
- package/test/src/__snapshots__/storage.test.ts.snap +0 -75
- package/test/src/__snapshots__/storage_sync.test.ts.snap +48 -48
- package/test/src/cleanup-stopped-sync-configs.test.ts +648 -0
- package/test/src/storage.test.ts +11 -11
- package/test/src/storage_compacting.test.ts +1956 -6
- package/test/src/storage_sync.test.ts +1077 -68
- package/test/src/storeCurrentData.test.ts +17 -7
- package/test/src/util.ts +2 -1
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +0 -15
- package/dist/storage/implementation/BucketDefinitionMapping.js +0 -58
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -14
- package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -67
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -29
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -76
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +0 -13
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +0 -2
- package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +0 -1
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +0 -9
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +0 -18
- package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +0 -1
- package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +0 -4
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js +0 -9
- package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +0 -1
- package/src/storage/implementation/BucketDefinitionMapping.ts +0 -75
- package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -82
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -101
- package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +0 -15
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +0 -24
- package/src/storage/implementation/v3/MongoParameterLookupV3.ts +0 -11
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function serializeBucketData(bucket, operations) {
|
|
2
|
+
const minOp = operations[0].o;
|
|
3
|
+
const maxOp = operations[operations.length - 1].o;
|
|
4
|
+
let totalChecksum = 0n;
|
|
5
|
+
let totalSize = 0;
|
|
6
|
+
let maxTargetOp = null;
|
|
7
|
+
const ops = operations.map((op) => {
|
|
8
|
+
totalChecksum += op.checksum;
|
|
9
|
+
totalSize += op.data?.length ?? 0;
|
|
10
|
+
if (op.target_op != null && (maxTargetOp == null || op.target_op > maxTargetOp)) {
|
|
11
|
+
maxTargetOp = op.target_op;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
o: op.o,
|
|
15
|
+
op: op.op,
|
|
16
|
+
source_table: op.source_table,
|
|
17
|
+
source_key: op.source_key,
|
|
18
|
+
table: op.table,
|
|
19
|
+
row_id: op.row_id,
|
|
20
|
+
checksum: op.checksum,
|
|
21
|
+
data: op.data
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
_id: {
|
|
26
|
+
b: bucket,
|
|
27
|
+
o: maxOp
|
|
28
|
+
},
|
|
29
|
+
min_op: minOp,
|
|
30
|
+
checksum: totalChecksum,
|
|
31
|
+
count: operations.length,
|
|
32
|
+
size: totalSize,
|
|
33
|
+
target_op: maxTargetOp,
|
|
34
|
+
ops
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function* loadBucketDataDocument(context, doc) {
|
|
38
|
+
const { _id, ops } = doc;
|
|
39
|
+
const bucketKey = {
|
|
40
|
+
...context,
|
|
41
|
+
bucket: _id.b
|
|
42
|
+
};
|
|
43
|
+
for (const op of ops) {
|
|
44
|
+
yield {
|
|
45
|
+
bucketKey,
|
|
46
|
+
o: op.o,
|
|
47
|
+
op: op.op,
|
|
48
|
+
source_table: op.source_table,
|
|
49
|
+
source_key: op.source_key,
|
|
50
|
+
table: op.table,
|
|
51
|
+
row_id: op.row_id,
|
|
52
|
+
checksum: op.checksum,
|
|
53
|
+
data: op.data,
|
|
54
|
+
target_op: doc.target_op ?? null
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=bucket-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bucket-format.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/bucket-format.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,UAA2B;IAC7E,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,KAAK,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAElD,IAAI,aAAa,GAAG,EAAE,CAAC;IACvB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,WAAW,GAAkB,IAAI,CAAC;IAEtC,MAAM,GAAG,GAAsB,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;QACnD,aAAa,IAAI,EAAE,CAAC,QAAQ,CAAC;QAC7B,SAAS,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC;QAElC,IAAI,EAAE,CAAC,SAAS,IAAI,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,IAAI,EAAE,CAAC,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;YAChF,WAAW,GAAG,EAAE,CAAC,SAAS,CAAC;QAC7B,CAAC;QAED,OAAO;YACL,CAAC,EAAE,EAAE,CAAC,CAAC;YACP,EAAE,EAAE,EAAE,CAAC,EAAE;YACT,YAAY,EAAE,EAAE,CAAC,YAAY;YAC7B,UAAU,EAAE,EAAE,CAAC,UAAU;YACzB,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,MAAM,EAAE,EAAE,CAAC,MAAM;YACjB,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,IAAI,EAAE,EAAE,CAAC,IAAI;SACd,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,EAAE;YACH,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,KAAK;SACT;QACD,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,aAAa;QACvB,KAAK,EAAE,UAAU,CAAC,MAAM;QACxB,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,WAAW;QACtB,GAAG;KACJ,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,CAAC,CAAC,sBAAsB,CACrC,OAAgE,EAChE,GAAyB;IAEzB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;IACzB,MAAM,SAAS,GAAG;QAChB,GAAG,OAAO;QACV,MAAM,EAAE,GAAG,CAAC,CAAC;KACd,CAAC;IAEF,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM;YACJ,SAAS;YACT,CAAC,EAAE,EAAE,CAAC,CAAC;YACP,EAAE,EAAE,EAAE,CAAC,EAAE;YACT,YAAY,EAAE,EAAE,CAAC,YAAY;YAC7B,UAAU,EAAE,EAAE,CAAC,UAAU;YACzB,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,MAAM,EAAE,EAAE,CAAC,MAAM;YACjB,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,IAAI,EAAE,EAAE,CAAC,IAAI;YACb,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,IAAI;SACjC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BucketDataDoc } from '../common/BucketDataDoc.js';
|
|
2
|
+
export declare const DEFAULT_MAX_DOC_SIZE_BYTES: number;
|
|
3
|
+
/**
|
|
4
|
+
* Split an array of bucket data operations into chunks where each chunk's
|
|
5
|
+
* total data size stays close to `maxDocSizeBytes`.
|
|
6
|
+
*
|
|
7
|
+
* The threshold is a target, not a hard ceiling — a single operation whose
|
|
8
|
+
* `data` field exceeds the limit is placed in its own chunk and is NOT split.
|
|
9
|
+
*/
|
|
10
|
+
export declare function chunkBucketData(operations: BucketDataDoc[], maxDocSizeBytes?: number): BucketDataDoc[][];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const DEFAULT_MAX_DOC_SIZE_BYTES = 1024 * 1024; // 1MB
|
|
2
|
+
/**
|
|
3
|
+
* Split an array of bucket data operations into chunks where each chunk's
|
|
4
|
+
* total data size stays close to `maxDocSizeBytes`.
|
|
5
|
+
*
|
|
6
|
+
* The threshold is a target, not a hard ceiling — a single operation whose
|
|
7
|
+
* `data` field exceeds the limit is placed in its own chunk and is NOT split.
|
|
8
|
+
*/
|
|
9
|
+
export function chunkBucketData(operations, maxDocSizeBytes = DEFAULT_MAX_DOC_SIZE_BYTES) {
|
|
10
|
+
const chunks = [];
|
|
11
|
+
let currentChunk = [];
|
|
12
|
+
let currentSize = 0;
|
|
13
|
+
for (const op of operations) {
|
|
14
|
+
const opSize = op.data?.length ?? 0;
|
|
15
|
+
if (currentSize + opSize > maxDocSizeBytes && currentChunk.length > 0) {
|
|
16
|
+
chunks.push(currentChunk);
|
|
17
|
+
currentChunk = [];
|
|
18
|
+
currentSize = 0;
|
|
19
|
+
}
|
|
20
|
+
currentChunk.push(op);
|
|
21
|
+
currentSize += opSize;
|
|
22
|
+
}
|
|
23
|
+
if (currentChunk.length > 0) {
|
|
24
|
+
chunks.push(currentChunk);
|
|
25
|
+
}
|
|
26
|
+
return chunks;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=chunking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunking.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/chunking.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,MAAM;AAE7D;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,UAA2B,EAC3B,eAAe,GAAG,0BAA0B;IAE5C,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,IAAI,YAAY,GAAoB,EAAE,CAAC;IACvC,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC;QAEpC,IAAI,WAAW,GAAG,MAAM,GAAG,eAAe,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC1B,YAAY,GAAG,EAAE,CAAC;YAClB,WAAW,GAAG,CAAC,CAAC;QAClB,CAAC;QAED,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACtB,WAAW,IAAI,MAAM,CAAC;IACxB,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { InternalOpId, SerializedSyncPlan, SyncRuleState } from '@powersync/service-core';
|
|
2
|
-
import { BucketDefinitionId, ParameterIndexId } from '@powersync/service-sync-rules';
|
|
1
|
+
import { InternalOpId, PersistedDefinitionMapping, SerializedSyncPlan, SyncRuleState } from '@powersync/service-core';
|
|
2
|
+
import { BucketDefinitionId, ParameterIndexId, ScopedParameterLookup, SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
3
3
|
import * as bson from 'bson';
|
|
4
|
-
import {
|
|
5
|
-
import { BucketDataDocumentBase, BucketDataKey, BucketParameterDocumentBase, BucketStateDocumentBase, CurrentBucket, ReplicaId, SourceTableDocument, SourceTableKey, SyncRuleCheckpointFields, SyncRuleDocumentBase, TaggedBucketParameterDocument } from '../models.js';
|
|
4
|
+
import { BucketDataKey, BucketParameterDocumentBase, BucketStateDocumentBase, CurrentBucket, OpType, ReplicaId, SourceTableDocumentSnapshotStatus, SourceTableKey, SyncRuleCheckpointFields, SyncRuleDocumentBase, TaggedBucketParameterDocument } from '../models.js';
|
|
6
5
|
/**
|
|
7
6
|
* Embedded in sync_rules.sync_configs.
|
|
8
7
|
*/
|
|
9
|
-
export interface SyncRuleConfigStateV3 extends SyncRuleCheckpointFields
|
|
8
|
+
export interface SyncRuleConfigStateV3 extends SyncRuleCheckpointFields {
|
|
10
9
|
_id: bson.ObjectId;
|
|
11
10
|
/**
|
|
12
11
|
* If false, we cannot create any checkpoints.
|
|
@@ -30,6 +29,29 @@ export interface ReplicationStreamDocumentV3 extends SyncRuleDocumentBase {
|
|
|
30
29
|
* but the model allows multiple configs in any state.
|
|
31
30
|
*/
|
|
32
31
|
sync_configs: SyncRuleConfigStateV3[];
|
|
32
|
+
/**
|
|
33
|
+
* The monotonic head of the stream's op sequence: the highest op id persisted to bucket data,
|
|
34
|
+
* whether or not yet covered by a checkpoint.
|
|
35
|
+
*
|
|
36
|
+
* This is shared across all sync configs of the stream (they share the global op sequence).
|
|
37
|
+
* It is never cleared, only `$max`-advanced. A newly-appended config that replicates nothing
|
|
38
|
+
* adopts this value as its checkpoint rather than starting at 0.
|
|
39
|
+
*
|
|
40
|
+
* Stored as a mongo Long, nullable.
|
|
41
|
+
*/
|
|
42
|
+
last_persisted_op?: bigint | null;
|
|
43
|
+
/**
|
|
44
|
+
* The stream's replication position: all source changes up to this LSN have been processed,
|
|
45
|
+
* and the resulting ops persisted. Replication resumes from here.
|
|
46
|
+
*
|
|
47
|
+
* Like {@link last_persisted_op}, this is shared across all sync configs of the stream -
|
|
48
|
+
* per-config last_checkpoint_lsn values are consistency markers, not replication positions.
|
|
49
|
+
*
|
|
50
|
+
* Set via setResumeLsn() (snapshot start, and per-batch progress during streaming), and
|
|
51
|
+
* advanced on every commit/keepalive - including checkpoint-blocked ones, since commit
|
|
52
|
+
* flushes first and blocking only delays consistency markers, not data persistence.
|
|
53
|
+
*/
|
|
54
|
+
resume_lsn?: string | null;
|
|
33
55
|
}
|
|
34
56
|
/**
|
|
35
57
|
* Static sync config definition.
|
|
@@ -50,16 +72,7 @@ export interface SyncConfigDefinition {
|
|
|
50
72
|
replication_stream_id: number;
|
|
51
73
|
content: string;
|
|
52
74
|
serialized_plan?: SerializedSyncPlan | null;
|
|
53
|
-
rule_mapping:
|
|
54
|
-
/**
|
|
55
|
-
* Map of uniqueName -> id, unique per replication stream.
|
|
56
|
-
*/
|
|
57
|
-
definitions: Record<string, string>;
|
|
58
|
-
/**
|
|
59
|
-
* Map of (lookupName, queryId) -> id, unique per replication stream.
|
|
60
|
-
*/
|
|
61
|
-
parameter_indexes: Record<string, string>;
|
|
62
|
-
};
|
|
75
|
+
rule_mapping: PersistedDefinitionMapping;
|
|
63
76
|
}
|
|
64
77
|
export interface CurrentBucketV3 extends CurrentBucket {
|
|
65
78
|
def: BucketDefinitionId;
|
|
@@ -83,13 +96,21 @@ export interface CurrentDataDocumentV3 {
|
|
|
83
96
|
export interface BucketParameterDocumentV3 extends BucketParameterDocumentBase<SourceTableKey> {
|
|
84
97
|
}
|
|
85
98
|
export type BucketDataKeyV3 = BucketDataKey;
|
|
86
|
-
export interface BucketDataDocumentV3 extends BucketDataDocumentBase {
|
|
87
|
-
_id: BucketDataKeyV3;
|
|
88
|
-
}
|
|
89
|
-
export declare function serializeBucketDataV3(document: BucketDataDoc): BucketDataDocumentV3;
|
|
90
|
-
export declare function loadBucketDataDocumentV3(context: Pick<BucketKey, 'replicationStreamId' | 'definitionId'>, doc: BucketDataDocumentV3): BucketDataDoc;
|
|
91
99
|
export declare function taggedBucketParameterDocumentToV3(document: TaggedBucketParameterDocument): BucketParameterDocumentV3;
|
|
92
|
-
export interface
|
|
100
|
+
export interface ReplicaIdColumn {
|
|
101
|
+
name: string;
|
|
102
|
+
type_oid?: number;
|
|
103
|
+
type?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface SourceTableDocumentV3 {
|
|
106
|
+
_id: bson.ObjectId;
|
|
107
|
+
connection_id: number;
|
|
108
|
+
relation_id: number | string | undefined;
|
|
109
|
+
schema_name: string;
|
|
110
|
+
table_name: string;
|
|
111
|
+
replica_id_columns: ReplicaIdColumn[];
|
|
112
|
+
snapshot_done: boolean;
|
|
113
|
+
snapshot_status: SourceTableDocumentSnapshotStatus | undefined;
|
|
93
114
|
bucket_data_source_ids: BucketDefinitionId[];
|
|
94
115
|
parameter_lookup_source_ids: ParameterIndexId[];
|
|
95
116
|
latest_pending_delete?: InternalOpId | undefined;
|
|
@@ -99,3 +120,25 @@ export interface BucketStateDocumentV3 extends BucketStateDocumentBase {
|
|
|
99
120
|
d: BucketDefinitionId;
|
|
100
121
|
};
|
|
101
122
|
}
|
|
123
|
+
export interface BucketOperation {
|
|
124
|
+
o: bigint;
|
|
125
|
+
op: OpType;
|
|
126
|
+
source_table?: bson.ObjectId;
|
|
127
|
+
source_key?: ReplicaId;
|
|
128
|
+
table?: string;
|
|
129
|
+
row_id?: string;
|
|
130
|
+
checksum: bigint;
|
|
131
|
+
data: string | null;
|
|
132
|
+
}
|
|
133
|
+
export interface BucketDataDocumentV3 {
|
|
134
|
+
_id: BucketDataKey;
|
|
135
|
+
min_op: bigint;
|
|
136
|
+
checksum: bigint;
|
|
137
|
+
count: number;
|
|
138
|
+
size: number;
|
|
139
|
+
target_op?: bigint | null;
|
|
140
|
+
ops: BucketOperation[];
|
|
141
|
+
}
|
|
142
|
+
export declare function serializeParameterLookup(lookup: ScopedParameterLookup): bson.Binary;
|
|
143
|
+
export declare function deserializeParameterLookup(lookup: bson.Binary, indexId: ParameterIndexId): SqliteJsonValue[];
|
|
144
|
+
export declare function taggedBucketParameterDocumentToTagged(document: TaggedBucketParameterDocument): BucketParameterDocumentV3;
|
|
@@ -1,33 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
o: o
|
|
7
|
-
},
|
|
8
|
-
// List fields directly, so that we don't accidentally persist any unknown fields
|
|
9
|
-
op: document.op,
|
|
10
|
-
source_table: document.source_table,
|
|
11
|
-
source_key: document.source_key,
|
|
12
|
-
table: document.table,
|
|
13
|
-
row_id: document.row_id,
|
|
14
|
-
checksum: document.checksum,
|
|
15
|
-
data: document.data,
|
|
16
|
-
target_op: document.target_op
|
|
17
|
-
};
|
|
1
|
+
import { deserializeParameterLookup as deserializeParameterLookupCore } from '@powersync/service-core';
|
|
2
|
+
import * as bson from 'bson';
|
|
3
|
+
export function taggedBucketParameterDocumentToV3(document) {
|
|
4
|
+
const { index: _index, ...rest } = document;
|
|
5
|
+
return rest;
|
|
18
6
|
}
|
|
19
|
-
export function
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
bucketKey: {
|
|
23
|
-
...context,
|
|
24
|
-
bucket: _id.b
|
|
25
|
-
},
|
|
26
|
-
o: _id.o,
|
|
27
|
-
...rest
|
|
28
|
-
};
|
|
7
|
+
export function serializeParameterLookup(lookup) {
|
|
8
|
+
return new bson.Binary(bson.serialize({ l: lookup.values.slice(2) }));
|
|
29
9
|
}
|
|
30
|
-
export function
|
|
10
|
+
export function deserializeParameterLookup(lookup, indexId) {
|
|
11
|
+
return [indexId, '', ...deserializeParameterLookupCore(lookup)];
|
|
12
|
+
}
|
|
13
|
+
export function taggedBucketParameterDocumentToTagged(document) {
|
|
31
14
|
const { index: _index, ...rest } = document;
|
|
32
15
|
return rest;
|
|
33
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/models.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,0BAA0B,IAAI,8BAA8B,EAC7D,MAAM,yBAAyB,CAAC;AAOjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AA2H7B,MAAM,UAAU,iCAAiC,CAAC,QAAuC;IACvF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC5C,OAAO,IAAiC,CAAC;AAC3C,CAAC;AAiDD,MAAM,UAAU,wBAAwB,CAAC,MAA6B;IACpE,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,MAAmB,EAAE,OAAyB;IACvF,OAAO,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,8BAA8B,CAAC,MAAM,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,qCAAqC,CACnD,QAAuC;IAEvC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC5C,OAAO,IAAiC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BucketDefinitionMapping, storage } from '@powersync/service-core';
|
|
2
|
+
import { BucketDataSource, BucketDefinitionId, HydratedSyncConfig, MatchingSources, ParameterIndexId, ParameterIndexLookupCreator, SourceTableRef } from '@powersync/service-sync-rules';
|
|
3
|
+
import * as bson from 'bson';
|
|
4
|
+
import { ReplicaIdColumn, SourceTableDocumentV3 } from './models.js';
|
|
5
|
+
export interface SourceTableIdentity {
|
|
6
|
+
schema: string;
|
|
7
|
+
name: string;
|
|
8
|
+
objectId: number | string | undefined;
|
|
9
|
+
replicaIdColumns: ReplicaIdColumn[];
|
|
10
|
+
}
|
|
11
|
+
export interface SourceTableMembershipIds {
|
|
12
|
+
bucketDataSourceIds: BucketDefinitionId[];
|
|
13
|
+
parameterLookupSourceIds: ParameterIndexId[];
|
|
14
|
+
}
|
|
15
|
+
export interface SourceTableDesiredResolution {
|
|
16
|
+
bucketSourceById: Map<BucketDefinitionId, BucketDataSource>;
|
|
17
|
+
parameterLookupSourceById: Map<ParameterIndexId, ParameterIndexLookupCreator>;
|
|
18
|
+
triggersEvent: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface SourceTableReconciliationContext {
|
|
21
|
+
connectionId: number;
|
|
22
|
+
connectionTag: string;
|
|
23
|
+
identity: SourceTableIdentity;
|
|
24
|
+
storeCurrentData: boolean;
|
|
25
|
+
syncConfig: HydratedSyncConfig;
|
|
26
|
+
mapping: BucketDefinitionMapping;
|
|
27
|
+
desired: SourceTableDesiredResolution;
|
|
28
|
+
}
|
|
29
|
+
export interface SourceTableReconciliationPlan {
|
|
30
|
+
/** Retained source tables, with memberships narrowed to the desired set. */
|
|
31
|
+
tables: storage.SourceTable[];
|
|
32
|
+
/** Membership narrowing to persist for retained snapshot-incomplete docs. */
|
|
33
|
+
narrowingUpdates: SourceTableMembershipUpdate[];
|
|
34
|
+
/**
|
|
35
|
+
* Memberships for a new source-table doc covering desired ids no existing doc covers,
|
|
36
|
+
* or null if no new doc is needed. Empty memberships indicate an event-only table.
|
|
37
|
+
*/
|
|
38
|
+
newTableMemberships: SourceTableMembershipIds | null;
|
|
39
|
+
/** Identity-overlapping docs that conflict with the current identity and must be dropped. */
|
|
40
|
+
dropDocs: SourceTableDocumentV3[];
|
|
41
|
+
}
|
|
42
|
+
export interface SourceTableMembershipUpdate {
|
|
43
|
+
id: bson.ObjectId;
|
|
44
|
+
memberships: SourceTableMembershipIds;
|
|
45
|
+
}
|
|
46
|
+
export interface NewSourceTable {
|
|
47
|
+
doc: SourceTableDocumentV3;
|
|
48
|
+
table: storage.SourceTable;
|
|
49
|
+
}
|
|
50
|
+
export declare function sourceTableDesiredResolution(syncConfig: HydratedSyncConfig, ref: SourceTableRef, mapping: BucketDefinitionMapping): SourceTableDesiredResolution;
|
|
51
|
+
export declare function planSourceTableReconciliation(candidateDocs: SourceTableDocumentV3[], context: SourceTableReconciliationContext): SourceTableReconciliationPlan;
|
|
52
|
+
export declare function overlappingSourceTableFilter(connectionId: number, identity: Pick<SourceTableIdentity, 'schema' | 'name' | 'objectId'>): Record<string, unknown>;
|
|
53
|
+
export declare function createNewSourceTable(id: bson.ObjectId, memberships: SourceTableMembershipIds, context: SourceTableReconciliationContext): NewSourceTable;
|
|
54
|
+
export declare function designateEventCarrier(tables: storage.SourceTable[], triggersEvent: boolean): void;
|
|
55
|
+
export declare function sourceTableFromDocument(doc: SourceTableDocumentV3, connectionTag: string, syncConfig: HydratedSyncConfig, mapping: BucketDefinitionMapping, memberships?: MatchingSources, membershipIds?: SourceTableMembershipIds): storage.SourceTable;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { ReplicationAssertionError } from '@powersync/lib-services-framework';
|
|
2
|
+
import { storage } from '@powersync/service-core';
|
|
3
|
+
export function sourceTableDesiredResolution(syncConfig, ref, mapping) {
|
|
4
|
+
const matchingSources = syncConfig.getMatchingSources(ref);
|
|
5
|
+
return {
|
|
6
|
+
bucketSourceById: new Map(matchingSources.bucketDataSources.map((source) => [mapping.bucketSourceId(source), source])),
|
|
7
|
+
parameterLookupSourceById: new Map(matchingSources.parameterLookupSources.map((source) => [mapping.parameterLookupId(source), source])),
|
|
8
|
+
triggersEvent: syncConfig.tableTriggersEvent(ref)
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function planSourceTableReconciliation(candidateDocs, context) {
|
|
12
|
+
return new SourceTableReconciliationPlanner(context).plan(candidateDocs);
|
|
13
|
+
}
|
|
14
|
+
function sameStringArray(left, right) {
|
|
15
|
+
return left.length == right.length && left.every((value, index) => value == right[index]);
|
|
16
|
+
}
|
|
17
|
+
function matchingSourcesFor(desired, memberships) {
|
|
18
|
+
return {
|
|
19
|
+
bucketDataSources: memberships.bucketDataSourceIds.map((id) => desired.bucketSourceById.get(id)),
|
|
20
|
+
parameterLookupSources: memberships.parameterLookupSourceIds.map((id) => desired.parameterLookupSourceById.get(id))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function intersectMembershipIds(doc, desired) {
|
|
24
|
+
return {
|
|
25
|
+
bucketDataSourceIds: doc.bucket_data_source_ids.filter((id) => desired.bucketSourceById.has(id)),
|
|
26
|
+
parameterLookupSourceIds: doc.parameter_lookup_source_ids.filter((id) => desired.parameterLookupSourceById.has(id))
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function hasMembershipIds(memberships) {
|
|
30
|
+
return memberships.bucketDataSourceIds.length > 0 || memberships.parameterLookupSourceIds.length > 0;
|
|
31
|
+
}
|
|
32
|
+
function sameMembershipIds(doc, memberships) {
|
|
33
|
+
return (sameStringArray(doc.bucket_data_source_ids, memberships.bucketDataSourceIds) &&
|
|
34
|
+
sameStringArray(doc.parameter_lookup_source_ids, memberships.parameterLookupSourceIds));
|
|
35
|
+
}
|
|
36
|
+
class SourceTableReconciliationPlanner {
|
|
37
|
+
context;
|
|
38
|
+
coveredBucketDataSourceIds = new Set();
|
|
39
|
+
coveredParameterLookupSourceIds = new Set();
|
|
40
|
+
retainedDocIds = new Set();
|
|
41
|
+
tables = [];
|
|
42
|
+
narrowingUpdates = [];
|
|
43
|
+
retainedEventOnlyTable = false;
|
|
44
|
+
constructor(context) {
|
|
45
|
+
this.context = context;
|
|
46
|
+
}
|
|
47
|
+
plan(candidateDocs) {
|
|
48
|
+
const { identity } = this.context;
|
|
49
|
+
for (const doc of candidateDocs) {
|
|
50
|
+
if (matchingSourceTableIdentity(doc, identity)) {
|
|
51
|
+
this.retainDoc(doc);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
tables: this.tables,
|
|
56
|
+
narrowingUpdates: this.narrowingUpdates,
|
|
57
|
+
newTableMemberships: this.newTableMemberships(),
|
|
58
|
+
// Non-retained overlapping docs represent renames / relation-id changes /
|
|
59
|
+
// replica-identity changes. Same-identity stale docs are retained in production.
|
|
60
|
+
dropDocs: candidateDocs.filter((doc) => !this.retainedDocIds.has(doc._id.toHexString()) && !matchingSourceTableIdentity(doc, identity))
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
retainDoc(doc) {
|
|
64
|
+
const memberships = intersectMembershipIds(doc, this.context.desired);
|
|
65
|
+
const coversDesiredMembership = hasMembershipIds(memberships);
|
|
66
|
+
const coversEventOnlyTable = !this.desiredHasMembership() && this.context.desired.triggersEvent && !this.retainedEventOnlyTable;
|
|
67
|
+
this.recordCoverage(doc, memberships);
|
|
68
|
+
this.planNarrowingUpdate(doc, memberships, coversDesiredMembership, coversEventOnlyTable);
|
|
69
|
+
if (coversDesiredMembership || coversEventOnlyTable) {
|
|
70
|
+
this.retainedEventOnlyTable ||= coversEventOnlyTable;
|
|
71
|
+
this.retainedDocIds.add(doc._id.toHexString());
|
|
72
|
+
this.tables.push(this.sourceTableFor(doc, memberships));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
desiredHasMembership() {
|
|
76
|
+
const { desired } = this.context;
|
|
77
|
+
return desired.bucketSourceById.size > 0 || desired.parameterLookupSourceById.size > 0;
|
|
78
|
+
}
|
|
79
|
+
recordCoverage(doc, memberships) {
|
|
80
|
+
this.addCoverage(doc, 'bucket data source', this.coveredBucketDataSourceIds, memberships.bucketDataSourceIds);
|
|
81
|
+
this.addCoverage(doc, 'parameter lookup source', this.coveredParameterLookupSourceIds, memberships.parameterLookupSourceIds);
|
|
82
|
+
}
|
|
83
|
+
// Membership sets must be pairwise disjoint across the docs of one physical table:
|
|
84
|
+
// each desired id is covered by exactly one doc, so each definition receives each
|
|
85
|
+
// row exactly once. The algorithm maintains this (new docs only get uncovered ids,
|
|
86
|
+
// narrowing only removes ids) - overlap means the persisted state is corrupt.
|
|
87
|
+
addCoverage(doc, kind, covered, ids) {
|
|
88
|
+
const { schema, name } = this.context.identity;
|
|
89
|
+
for (const id of ids) {
|
|
90
|
+
if (covered.has(id)) {
|
|
91
|
+
throw new ReplicationAssertionError(`Source table ${doc._id} duplicates coverage of ${kind} ${id} for ${schema}.${name}`);
|
|
92
|
+
}
|
|
93
|
+
covered.add(id);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
planNarrowingUpdate(doc, memberships, coversDesiredMembership, coversEventOnlyTable) {
|
|
97
|
+
const shouldNarrow = (coversDesiredMembership || coversEventOnlyTable) && !doc.snapshot_done && !sameMembershipIds(doc, memberships);
|
|
98
|
+
if (!shouldNarrow) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.narrowingUpdates.push({
|
|
102
|
+
id: doc._id,
|
|
103
|
+
memberships
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
newTableMemberships() {
|
|
107
|
+
const { desired } = this.context;
|
|
108
|
+
const uncovered = {
|
|
109
|
+
bucketDataSourceIds: [...desired.bucketSourceById.keys()].filter((id) => !this.coveredBucketDataSourceIds.has(id)),
|
|
110
|
+
parameterLookupSourceIds: [...desired.parameterLookupSourceById.keys()].filter((id) => !this.coveredParameterLookupSourceIds.has(id))
|
|
111
|
+
};
|
|
112
|
+
if (hasMembershipIds(uncovered) || (desired.triggersEvent && this.tables.length == 0)) {
|
|
113
|
+
return uncovered;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
sourceTableFor(doc, memberships) {
|
|
118
|
+
const { connectionTag, syncConfig, mapping, desired, storeCurrentData } = this.context;
|
|
119
|
+
const table = sourceTableFromDocument(doc, connectionTag, syncConfig, mapping, matchingSourcesFor(desired, memberships), memberships);
|
|
120
|
+
table.storeCurrentData = storeCurrentData;
|
|
121
|
+
return table;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function sameReplicaIdColumns(left, right) {
|
|
125
|
+
return (left != null &&
|
|
126
|
+
left.length == right.length &&
|
|
127
|
+
left.every((column, index) => column.name == right[index].name && column.type == right[index].type && column.type_oid == right[index].type_oid));
|
|
128
|
+
}
|
|
129
|
+
function matchingSourceTableIdentity(doc, identity) {
|
|
130
|
+
return (doc.schema_name == identity.schema &&
|
|
131
|
+
doc.table_name == identity.name &&
|
|
132
|
+
(identity.objectId == null || doc.relation_id == identity.objectId) &&
|
|
133
|
+
sameReplicaIdColumns(doc.replica_id_columns, identity.replicaIdColumns));
|
|
134
|
+
}
|
|
135
|
+
export function overlappingSourceTableFilter(connectionId, identity) {
|
|
136
|
+
const clauses = [{ schema_name: identity.schema, table_name: identity.name }];
|
|
137
|
+
if (identity.objectId != null) {
|
|
138
|
+
clauses.push({ relation_id: identity.objectId });
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
connection_id: connectionId,
|
|
142
|
+
$or: clauses
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export function createNewSourceTable(id, memberships, context) {
|
|
146
|
+
const { connectionId, connectionTag, identity, syncConfig, mapping, desired, storeCurrentData } = context;
|
|
147
|
+
const doc = {
|
|
148
|
+
_id: id,
|
|
149
|
+
connection_id: connectionId,
|
|
150
|
+
relation_id: identity.objectId,
|
|
151
|
+
schema_name: identity.schema,
|
|
152
|
+
table_name: identity.name,
|
|
153
|
+
replica_id_columns: identity.replicaIdColumns,
|
|
154
|
+
snapshot_done: false,
|
|
155
|
+
snapshot_status: undefined,
|
|
156
|
+
bucket_data_source_ids: memberships.bucketDataSourceIds,
|
|
157
|
+
parameter_lookup_source_ids: memberships.parameterLookupSourceIds
|
|
158
|
+
};
|
|
159
|
+
const table = sourceTableFromDocument(doc, connectionTag, syncConfig, mapping, matchingSourcesFor(desired, memberships), memberships);
|
|
160
|
+
table.storeCurrentData = storeCurrentData;
|
|
161
|
+
return { doc, table };
|
|
162
|
+
}
|
|
163
|
+
export function designateEventCarrier(tables, triggersEvent) {
|
|
164
|
+
if (!triggersEvent) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const eventCarrier = tables.find((table) => table.snapshotComplete) ?? tables[0];
|
|
168
|
+
for (const table of tables) {
|
|
169
|
+
table.syncEvent = table === eventCarrier;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function sourceTableMembershipsFromDocument(doc, syncConfig, mapping) {
|
|
173
|
+
const bucketDataSourceIds = new Set(doc.bucket_data_source_ids);
|
|
174
|
+
const parameterLookupSourceIds = new Set(doc.parameter_lookup_source_ids);
|
|
175
|
+
return {
|
|
176
|
+
bucketDataSources: syncConfig.bucketDataSources.filter((source) => bucketDataSourceIds.has(mapping.bucketSourceId(source))),
|
|
177
|
+
parameterLookupSources: syncConfig.bucketParameterLookupSources.filter((source) => parameterLookupSourceIds.has(mapping.parameterLookupId(source)))
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export function sourceTableFromDocument(doc, connectionTag, syncConfig, mapping, memberships, membershipIds) {
|
|
181
|
+
const resolvedMemberships = memberships ?? sourceTableMembershipsFromDocument(doc, syncConfig, mapping);
|
|
182
|
+
const resolvedMembershipIds = membershipIds ?? {
|
|
183
|
+
bucketDataSourceIds: resolvedMemberships.bucketDataSources.map((source) => mapping.bucketSourceId(source)),
|
|
184
|
+
parameterLookupSourceIds: resolvedMemberships.parameterLookupSources.map((source) => mapping.parameterLookupId(source))
|
|
185
|
+
};
|
|
186
|
+
const table = new storage.SourceTable({
|
|
187
|
+
id: doc._id,
|
|
188
|
+
ref: {
|
|
189
|
+
connectionTag,
|
|
190
|
+
schema: doc.schema_name,
|
|
191
|
+
name: doc.table_name
|
|
192
|
+
},
|
|
193
|
+
objectId: doc.relation_id,
|
|
194
|
+
replicaIdColumns: doc.replica_id_columns.map((c) => ({ name: c.name, typeId: c.type_oid, type: c.type })),
|
|
195
|
+
snapshotComplete: doc.snapshot_done,
|
|
196
|
+
bucketDataSources: resolvedMemberships.bucketDataSources,
|
|
197
|
+
parameterLookupSources: resolvedMemberships.parameterLookupSources,
|
|
198
|
+
bucketDataSourceIds: new Set(resolvedMembershipIds.bucketDataSourceIds),
|
|
199
|
+
parameterLookupSourceIds: new Set(resolvedMembershipIds.parameterLookupSourceIds)
|
|
200
|
+
});
|
|
201
|
+
table.syncData = table.bucketDataSources.length > 0;
|
|
202
|
+
table.syncParameters = table.parameterLookupSources.length > 0;
|
|
203
|
+
table.syncEvent = syncConfig.tableTriggersEvent(table.ref);
|
|
204
|
+
table.snapshotStatus =
|
|
205
|
+
doc.snapshot_status == null
|
|
206
|
+
? undefined
|
|
207
|
+
: {
|
|
208
|
+
lastKey: doc.snapshot_status.last_key?.buffer ?? null,
|
|
209
|
+
totalEstimatedCount: doc.snapshot_status.total_estimated_count,
|
|
210
|
+
replicatedCount: doc.snapshot_status.replicated_count
|
|
211
|
+
};
|
|
212
|
+
return table;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=source-table-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-table-utils.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/source-table-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAA6C,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAiE7F,MAAM,UAAU,4BAA4B,CAC1C,UAA8B,EAC9B,GAAmB,EACnB,OAAgC;IAEhC,MAAM,eAAe,GAAG,UAAU,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC3D,OAAO;QACL,gBAAgB,EAAE,IAAI,GAAG,CACvB,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,CAAU,CAAC,CACrG;QACD,yBAAyB,EAAE,IAAI,GAAG,CAChC,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAU,CAAC,CAC7G;QACD,aAAa,EAAE,UAAU,CAAC,kBAAkB,CAAC,GAAG,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,6BAA6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AG,CAAC,qBAAqB,CAAC,mBAAmB,CAAC;QACvE,wBAAwB,EAAE,IAAI,GAAG,CAAC,qBAAqB,CAAC,wBAAwB,CAAC;KAClF,CAAC,CAAC;IACH,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC;IACpD,KAAK,CAAC,cAAc,GAAG,KAAK,CAAC,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/D,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3D,KAAK,CAAC,cAAc;QAClB,GAAG,CAAC,eAAe,IAAI,IAAI;YACzB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC;gBACE,OAAO,EAAE,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,IAAI,IAAI;gBACrD,mBAAmB,EAAE,GAAG,CAAC,eAAe,CAAC,qBAAqB;gBAC9D,eAAe,EAAE,GAAG,CAAC,eAAe,CAAC,gBAAgB;aACtD,CAAC;IACR,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export * as test_utils from '../utils/test-utils.js';
|
|
2
2
|
export * from '../utils/util.js';
|
|
3
|
-
export * from './implementation/BucketDefinitionMapping.js';
|
|
4
3
|
export * from './implementation/common/PersistedBatch.js';
|
|
5
4
|
export * from './implementation/createMongoSyncBucketStorage.js';
|
|
6
5
|
export * from './implementation/db.js';
|
|
7
6
|
export * from './implementation/models.js';
|
|
8
7
|
export * from './implementation/MongoIdSequence.js';
|
|
9
|
-
export * from './implementation/
|
|
10
|
-
export * from './implementation/
|
|
8
|
+
export * from './implementation/MongoParsedSyncConfigSet.js';
|
|
9
|
+
export * from './implementation/MongoPersistedReplicationStream.js';
|
|
11
10
|
export * from './implementation/MongoStorageProvider.js';
|
|
12
11
|
export * from './implementation/MongoSyncRulesLock.js';
|
|
13
12
|
export * from './implementation/OperationBatch.js';
|
|
14
13
|
export * from './implementation/v1/models.js';
|
|
15
|
-
export
|
|
14
|
+
export { loadBucketDataDocument, serializeBucketData } from './implementation/v3/bucket-format.js';
|
|
15
|
+
export { BucketDataDocumentV3, BucketOperation, RecordedLookupV3, ReplicationStreamDocumentV3, SyncConfigDefinition, SyncRuleConfigStateV3, taggedBucketParameterDocumentToTagged } from './implementation/v3/models.js';
|
|
16
16
|
export * from './MongoBucketStorage.js';
|
|
17
17
|
export * from './MongoReportStorage.js';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
export * as test_utils from '../utils/test-utils.js';
|
|
2
2
|
export * from '../utils/util.js';
|
|
3
|
-
export * from './implementation/BucketDefinitionMapping.js';
|
|
4
3
|
export * from './implementation/common/PersistedBatch.js';
|
|
5
4
|
export * from './implementation/createMongoSyncBucketStorage.js';
|
|
6
5
|
export * from './implementation/db.js';
|
|
7
6
|
export * from './implementation/models.js';
|
|
8
7
|
export * from './implementation/MongoIdSequence.js';
|
|
9
|
-
export * from './implementation/
|
|
10
|
-
export * from './implementation/
|
|
8
|
+
export * from './implementation/MongoParsedSyncConfigSet.js';
|
|
9
|
+
export * from './implementation/MongoPersistedReplicationStream.js';
|
|
11
10
|
export * from './implementation/MongoStorageProvider.js';
|
|
12
11
|
export * from './implementation/MongoSyncRulesLock.js';
|
|
13
12
|
export * from './implementation/OperationBatch.js';
|
|
14
13
|
export * from './implementation/v1/models.js';
|
|
15
|
-
export
|
|
14
|
+
export { loadBucketDataDocument, serializeBucketData } from './implementation/v3/bucket-format.js';
|
|
15
|
+
export { taggedBucketParameterDocumentToTagged } from './implementation/v3/models.js';
|
|
16
16
|
export * from './MongoBucketStorage.js';
|
|
17
17
|
export * from './MongoReportStorage.js';
|
|
18
18
|
//# sourceMappingURL=storage-index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,cAAc,kBAAkB,CAAC;AACjC,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qDAAqD,CAAC;AACpE,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AACnG,OAAO,EAOL,qCAAqC,EACtC,MAAM,+BAA+B,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as service_types from '@powersync/service-types';
|
|
2
2
|
import * as t from 'ts-codec';
|
|
3
3
|
export declare const MongoStorageConfig: t.Intersection<t.Codec<{
|
|
4
|
-
uri: string;
|
|
5
4
|
type: "mongodb";
|
|
5
|
+
uri: string;
|
|
6
6
|
database?: string | undefined;
|
|
7
7
|
username?: string | undefined;
|
|
8
8
|
password?: string | undefined;
|
|
9
9
|
reject_ip_ranges?: string[] | undefined;
|
|
10
10
|
}, {
|
|
11
|
-
uri: string;
|
|
12
11
|
type: "mongodb";
|
|
12
|
+
uri: string;
|
|
13
13
|
database?: string | undefined;
|
|
14
14
|
username?: string | undefined;
|
|
15
15
|
password?: string | undefined;
|