@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,101 @@
|
|
|
1
|
+
import { InternalOpId, SerializedSyncPlan, SyncRuleState } from '@powersync/service-core';
|
|
2
|
+
import { BucketDefinitionId, ParameterIndexId } from '@powersync/service-sync-rules';
|
|
3
|
+
import * as bson from 'bson';
|
|
4
|
+
import { BucketDataDoc, BucketKey } from '../common/BucketDataDoc.js';
|
|
5
|
+
import { BucketDataDocumentBase, BucketDataKey, BucketParameterDocumentBase, BucketStateDocumentBase, CurrentBucket, ReplicaId, SourceTableDocument, SourceTableKey, SyncRuleCheckpointFields, SyncRuleDocumentBase, TaggedBucketParameterDocument } from '../models.js';
|
|
6
|
+
/**
|
|
7
|
+
* Embedded in sync_rules.sync_configs.
|
|
8
|
+
*/
|
|
9
|
+
export interface SyncRuleConfigStateV3 extends SyncRuleCheckpointFields<bigint | null> {
|
|
10
|
+
_id: bson.ObjectId;
|
|
11
|
+
/**
|
|
12
|
+
* If false, we cannot create any checkpoints.
|
|
13
|
+
*/
|
|
14
|
+
snapshot_done: boolean;
|
|
15
|
+
state: SyncRuleState;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Represents the state of a replication stream, in the sync_rules collection.
|
|
19
|
+
*
|
|
20
|
+
* Differences from V1:
|
|
21
|
+
* 1. The static config is moved into a separate sync_configs collection.
|
|
22
|
+
* 2. The same replication stream may be shared by multiple sync config instances.
|
|
23
|
+
*/
|
|
24
|
+
export interface ReplicationStreamDocumentV3 extends SyncRuleDocumentBase {
|
|
25
|
+
storage_version: number;
|
|
26
|
+
/**
|
|
27
|
+
* These contain the checkpoint/state per sync config.
|
|
28
|
+
*
|
|
29
|
+
* In common cases we'd have one active config or one active + one processing config,
|
|
30
|
+
* but the model allows multiple configs in any state.
|
|
31
|
+
*/
|
|
32
|
+
sync_configs: SyncRuleConfigStateV3[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Static sync config definition.
|
|
36
|
+
*
|
|
37
|
+
* This should be treated as immutable - we don't update this after initial creation.
|
|
38
|
+
*/
|
|
39
|
+
export interface SyncConfigDefinition {
|
|
40
|
+
_id: bson.ObjectId;
|
|
41
|
+
created_at: Date;
|
|
42
|
+
storage_version: number;
|
|
43
|
+
/**
|
|
44
|
+
* The related SyncRuleDocumentV3.
|
|
45
|
+
*
|
|
46
|
+
* Note that a specific sync config definition never moves between replication streams. Instead, we can create a new copy for the new replication stream.
|
|
47
|
+
*
|
|
48
|
+
* When terminating a specific sync config definition, we remove the reference from replication stream -> sync config, but this reference here remains as a historical record.
|
|
49
|
+
*/
|
|
50
|
+
replication_stream_id: number;
|
|
51
|
+
content: string;
|
|
52
|
+
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
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export interface CurrentBucketV3 extends CurrentBucket {
|
|
65
|
+
def: BucketDefinitionId;
|
|
66
|
+
}
|
|
67
|
+
export interface RecordedLookupV3 {
|
|
68
|
+
i: ParameterIndexId;
|
|
69
|
+
l: bson.Binary;
|
|
70
|
+
}
|
|
71
|
+
export interface CurrentDataDocumentV3 {
|
|
72
|
+
_id: ReplicaId;
|
|
73
|
+
data: bson.Binary | null;
|
|
74
|
+
buckets: CurrentBucketV3[];
|
|
75
|
+
lookups: RecordedLookupV3[];
|
|
76
|
+
/**
|
|
77
|
+
* If set, this can be deleted, once there is a consistent checkpoint >= pending_delete.
|
|
78
|
+
*
|
|
79
|
+
* This must only be set if buckets = [], lookups = [].
|
|
80
|
+
*/
|
|
81
|
+
pending_delete?: bigint;
|
|
82
|
+
}
|
|
83
|
+
export interface BucketParameterDocumentV3 extends BucketParameterDocumentBase<SourceTableKey> {
|
|
84
|
+
}
|
|
85
|
+
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
|
+
export declare function taggedBucketParameterDocumentToV3(document: TaggedBucketParameterDocument): BucketParameterDocumentV3;
|
|
92
|
+
export interface SourceTableDocumentV3 extends SourceTableDocument {
|
|
93
|
+
bucket_data_source_ids: BucketDefinitionId[];
|
|
94
|
+
parameter_lookup_source_ids: ParameterIndexId[];
|
|
95
|
+
latest_pending_delete?: InternalOpId | undefined;
|
|
96
|
+
}
|
|
97
|
+
export interface BucketStateDocumentV3 extends BucketStateDocumentBase {
|
|
98
|
+
_id: BucketStateDocumentBase['_id'] & {
|
|
99
|
+
d: BucketDefinitionId;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function serializeBucketDataV3(document) {
|
|
2
|
+
const { bucketKey, o } = document;
|
|
3
|
+
return {
|
|
4
|
+
_id: {
|
|
5
|
+
b: bucketKey.bucket,
|
|
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
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function loadBucketDataDocumentV3(context, doc) {
|
|
20
|
+
const { _id, ...rest } = doc;
|
|
21
|
+
return {
|
|
22
|
+
bucketKey: {
|
|
23
|
+
...context,
|
|
24
|
+
bucket: _id.b
|
|
25
|
+
},
|
|
26
|
+
o: _id.o,
|
|
27
|
+
...rest
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function taggedBucketParameterDocumentToV3(document) {
|
|
31
|
+
const { index: _index, ...rest } = document;
|
|
32
|
+
return rest;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/models.ts"],"names":[],"mappings":"AAkHA,MAAM,UAAU,qBAAqB,CAAC,QAAuB;IAC3D,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC;IAClC,OAAO;QACL,GAAG,EAAE;YACH,CAAC,EAAE,SAAS,CAAC,MAAM;YACnB,CAAC,EAAE,CAAC;SACL;QACD,iFAAiF;QACjF,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,SAAS,EAAE,QAAQ,CAAC,SAAS;KAC9B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,OAAgE,EAChE,GAAyB;IAEzB,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;IAC7B,OAAO;QACL,SAAS,EAAE;YACT,GAAG,OAAO;YACV,MAAM,EAAE,GAAG,CAAC,CAAC;SACd;QACD,CAAC,EAAE,GAAG,CAAC,CAAC;QACR,GAAG,IAAI;KACR,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,QAAuC;IACvF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC5C,OAAO,IAAiC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,14 +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
|
+
export * from './implementation/common/PersistedBatch.js';
|
|
5
|
+
export * from './implementation/createMongoSyncBucketStorage.js';
|
|
3
6
|
export * from './implementation/db.js';
|
|
4
7
|
export * from './implementation/models.js';
|
|
5
|
-
export * from './implementation/MongoBucketBatch.js';
|
|
6
8
|
export * from './implementation/MongoIdSequence.js';
|
|
9
|
+
export * from './implementation/MongoPersistedSyncRules.js';
|
|
7
10
|
export * from './implementation/MongoPersistedSyncRulesContent.js';
|
|
8
11
|
export * from './implementation/MongoStorageProvider.js';
|
|
9
|
-
export * from './implementation/MongoSyncBucketStorage.js';
|
|
10
12
|
export * from './implementation/MongoSyncRulesLock.js';
|
|
11
13
|
export * from './implementation/OperationBatch.js';
|
|
12
|
-
export * from './implementation/
|
|
14
|
+
export * from './implementation/v1/models.js';
|
|
15
|
+
export * from './implementation/v3/models.js';
|
|
13
16
|
export * from './MongoBucketStorage.js';
|
|
14
17
|
export * from './MongoReportStorage.js';
|
|
@@ -1,15 +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
|
+
export * from './implementation/common/PersistedBatch.js';
|
|
5
|
+
export * from './implementation/createMongoSyncBucketStorage.js';
|
|
3
6
|
export * from './implementation/db.js';
|
|
4
7
|
export * from './implementation/models.js';
|
|
5
|
-
export * from './implementation/MongoBucketBatch.js';
|
|
6
8
|
export * from './implementation/MongoIdSequence.js';
|
|
9
|
+
export * from './implementation/MongoPersistedSyncRules.js';
|
|
7
10
|
export * from './implementation/MongoPersistedSyncRulesContent.js';
|
|
8
11
|
export * from './implementation/MongoStorageProvider.js';
|
|
9
|
-
export * from './implementation/MongoSyncBucketStorage.js';
|
|
10
12
|
export * from './implementation/MongoSyncRulesLock.js';
|
|
11
13
|
export * from './implementation/OperationBatch.js';
|
|
12
|
-
export * from './implementation/
|
|
14
|
+
export * from './implementation/v1/models.js';
|
|
15
|
+
export * from './implementation/v3/models.js';
|
|
13
16
|
export * from './MongoBucketStorage.js';
|
|
14
17
|
export * from './MongoReportStorage.js';
|
|
15
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,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,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,6CAA6C,CAAC;AAC5D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oDAAoD,CAAC;AACnE,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
package/dist/utils/util.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
1
2
|
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
3
|
import { storage, utils } from '@powersync/service-core';
|
|
3
4
|
import * as bson from 'bson';
|
|
4
|
-
import {
|
|
5
|
+
import { BucketDataDoc } from '../storage/implementation/common/BucketDataDoc.js';
|
|
5
6
|
export declare function idPrefixFilter<T>(prefix: Partial<T>, rest: (keyof T)[]): mongo.Condition<T>;
|
|
6
7
|
export declare function generateSlotName(prefix: string, sync_rules_id: number): string;
|
|
7
8
|
/**
|
|
@@ -19,12 +20,18 @@ export declare function readSingleBatch<T>(cursor: mongo.AbstractCursor<T>): Pro
|
|
|
19
20
|
data: T[];
|
|
20
21
|
hasMore: boolean;
|
|
21
22
|
}>;
|
|
22
|
-
export declare function mapOpEntry(row:
|
|
23
|
+
export declare function mapOpEntry(row: BucketDataDoc): utils.OplogEntry;
|
|
23
24
|
export declare function replicaIdToSubkey(table: storage.SourceTableId, id: storage.ReplicaId): string;
|
|
24
25
|
export declare function mongoTableId(table: storage.SourceTableId): bson.ObjectId;
|
|
25
26
|
export declare function setSessionSnapshotTime(session: mongo.ClientSession, time: bson.Timestamp): void;
|
|
27
|
+
export declare function retryOnMongoMaxTimeMSExpired<T>(operation: () => Promise<T>, options: {
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
abortMessage?: string;
|
|
30
|
+
retryDelayMs: number;
|
|
31
|
+
onRetry?: (retryCount: number) => void;
|
|
32
|
+
}): Promise<T>;
|
|
26
33
|
export declare const createPaginatedConnectionQuery: <T extends mongo.Document>(query: mongo.Filter<T>, collection: mongo.Collection<T>, limit: number, cursor?: string) => Promise<{
|
|
27
|
-
items: mongo.WithId<T>[];
|
|
34
|
+
items: lib_mongo.mongo.WithId<T>[];
|
|
28
35
|
count: number;
|
|
29
36
|
/** Setting the cursor to the connected at date of the last item in the list */
|
|
30
37
|
cursor: any;
|
package/dist/utils/util.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
|
+
import { ReplicationAbortedError, ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
2
3
|
import { storage, utils } from '@powersync/service-core';
|
|
3
4
|
import * as bson from 'bson';
|
|
4
5
|
import * as crypto from 'crypto';
|
|
6
|
+
import * as timers from 'node:timers/promises';
|
|
5
7
|
import * as uuid from 'uuid';
|
|
6
8
|
export function idPrefixFilter(prefix, rest) {
|
|
7
9
|
let filter = {
|
|
@@ -65,7 +67,7 @@ export async function readSingleBatch(cursor) {
|
|
|
65
67
|
export function mapOpEntry(row) {
|
|
66
68
|
if (row.op == 'PUT' || row.op == 'REMOVE') {
|
|
67
69
|
return {
|
|
68
|
-
op_id: utils.internalToExternalOpId(row.
|
|
70
|
+
op_id: utils.internalToExternalOpId(row.o),
|
|
69
71
|
op: row.op,
|
|
70
72
|
object_type: row.table,
|
|
71
73
|
object_id: row.row_id,
|
|
@@ -77,7 +79,7 @@ export function mapOpEntry(row) {
|
|
|
77
79
|
else {
|
|
78
80
|
// MOVE, CLEAR
|
|
79
81
|
return {
|
|
80
|
-
op_id: utils.internalToExternalOpId(row.
|
|
82
|
+
op_id: utils.internalToExternalOpId(row.o),
|
|
81
83
|
op: row.op,
|
|
82
84
|
checksum: Number(row.checksum)
|
|
83
85
|
};
|
|
@@ -120,6 +122,25 @@ export function setSessionSnapshotTime(session, time) {
|
|
|
120
122
|
throw new ServiceAssertionError(`Session snapshotTime is already set`);
|
|
121
123
|
}
|
|
122
124
|
}
|
|
125
|
+
export async function retryOnMongoMaxTimeMSExpired(operation, options) {
|
|
126
|
+
let retryCount = 0;
|
|
127
|
+
while (true) {
|
|
128
|
+
if (options.signal?.aborted) {
|
|
129
|
+
throw new ReplicationAbortedError(options.abortMessage ?? 'Aborted MongoDB operation', options.signal.reason);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
return await operation();
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
if (!lib_mongo.isMongoServerError(e) || e.codeName !== 'MaxTimeMSExpired') {
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
138
|
+
retryCount += 1;
|
|
139
|
+
options.onRetry?.(retryCount);
|
|
140
|
+
await timers.setTimeout(options.retryDelayMs);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
123
144
|
export const createPaginatedConnectionQuery = async (query, collection, limit, cursor) => {
|
|
124
145
|
const createQuery = (cursor) => {
|
|
125
146
|
if (!cursor) {
|
package/dist/utils/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/utils/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/utils/util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AAK;YACR,YAAY;SACM,CAAC;IACvB,CAAC,CAAC;IAEF,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;QACtD,IAAI,EAAE;YACJ,6FAA6F;YAC7F,YAAY,EAAE,CAAC,CAAC;SACjB;KACF,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IACtD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;IAC3B;;SAEK;IACL,OAAO;QACL,KAAK;QACL,KAAK;QACL,+EAA+E;QAC/E,MAAM,EAAE,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;QACxF,IAAI,EAAE,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC;KACzB,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@powersync/service-module-mongodb-storage",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.17.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"license": "FSL-1.1-ALv2",
|
|
8
8
|
"type": "module",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"ix": "^5.0.0",
|
|
27
27
|
"lru-cache": "^10.2.2",
|
|
28
28
|
"ts-codec": "^1.3.0",
|
|
29
|
-
"uuid": "^
|
|
30
|
-
"@powersync/lib-
|
|
31
|
-
"@powersync/lib-
|
|
32
|
-
"@powersync/service-
|
|
33
|
-
"@powersync/service-
|
|
34
|
-
"@powersync/service-sync-rules": "0.
|
|
35
|
-
"@powersync/service-types": "0.15.
|
|
29
|
+
"uuid": "^14.0.0",
|
|
30
|
+
"@powersync/lib-services-framework": "0.9.5",
|
|
31
|
+
"@powersync/lib-service-mongodb": "0.6.26",
|
|
32
|
+
"@powersync/service-jsonbig": "0.17.13",
|
|
33
|
+
"@powersync/service-core": "1.22.0",
|
|
34
|
+
"@powersync/service-sync-rules": "0.37.0",
|
|
35
|
+
"@powersync/service-types": "0.15.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@powersync/service-core-tests": "0.
|
|
38
|
+
"@powersync/service-core-tests": "0.16.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -b",
|
|
@@ -4,23 +4,23 @@ import { storage as core_storage, migrations } from '@powersync/service-core';
|
|
|
4
4
|
import * as storage from '../../../storage/storage-index.js';
|
|
5
5
|
import { MongoStorageConfig } from '../../../types/types.js';
|
|
6
6
|
|
|
7
|
-
interface LegacySyncRulesDocument extends storage.
|
|
7
|
+
interface LegacySyncRulesDocument extends storage.SyncRuleDocumentV1 {
|
|
8
8
|
/**
|
|
9
|
-
* True if this is the active
|
|
9
|
+
* True if this is the active replication stream.
|
|
10
10
|
* requires `snapshot_done == true` and `replicating == true`.
|
|
11
11
|
*/
|
|
12
12
|
active?: boolean;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* True if this
|
|
15
|
+
* True if this replication stream should be used for replication.
|
|
16
16
|
*
|
|
17
|
-
* During reprocessing, there is one
|
|
17
|
+
* During reprocessing, there is one replication stream with `replicating = true, active = true`,
|
|
18
18
|
* and one with `replicating = true, active = false, auto_activate = true`.
|
|
19
19
|
*/
|
|
20
20
|
replicating?: boolean;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* True if the
|
|
23
|
+
* True if the replication stream should set `active = true` when `snapshot_done` = true.
|
|
24
24
|
*/
|
|
25
25
|
auto_activate?: boolean;
|
|
26
26
|
}
|
|
@@ -35,7 +35,7 @@ export const up: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
|
35
35
|
try {
|
|
36
36
|
// We keep the old flags for existing deployments still shutting down.
|
|
37
37
|
|
|
38
|
-
// 1. New
|
|
38
|
+
// 1. New replication stream: `active = false, snapshot_done = false, replicating = true, auto_activate = true`
|
|
39
39
|
await db.sync_rules.updateMany(
|
|
40
40
|
{
|
|
41
41
|
active: { $ne: true },
|
|
@@ -66,7 +66,7 @@ export const up: migrations.PowerSyncMigrationFunction = async (context) => {
|
|
|
66
66
|
const remaining = await db.sync_rules.find({ state: null as any }).toArray();
|
|
67
67
|
if (remaining.length > 0) {
|
|
68
68
|
const slots = remaining.map((doc) => doc.slot_name).join(', ');
|
|
69
|
-
throw new ServiceAssertionError(`Invalid state for
|
|
69
|
+
throw new ServiceAssertionError(`Invalid state for replication stream: ${slots}`);
|
|
70
70
|
}
|
|
71
71
|
} finally {
|
|
72
72
|
await db.client.close();
|