@powersync/service-module-mongodb-storage 0.0.0-dev-20260602073133 → 0.0.0-dev-20260803144812
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 +101 -5
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.d.ts +3 -0
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.js +41 -0
- package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.js.map +1 -0
- package/dist/storage/MongoBucketStorage.d.ts +41 -16
- package/dist/storage/MongoBucketStorage.js +226 -71
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +56 -25
- package/dist/storage/implementation/MongoBucketBatch.js +110 -62
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoChecksums.d.ts +41 -13
- package/dist/storage/implementation/MongoChecksums.js +36 -121
- package/dist/storage/implementation/MongoChecksums.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +17 -19
- package/dist/storage/implementation/MongoCompactor.js +80 -263
- 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 +7 -6
- package/dist/storage/implementation/MongoParameterCompactor.js +25 -2
- 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 +39 -4
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +57 -29
- package/dist/storage/implementation/MongoSyncBucketStorage.js +87 -61
- 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/MongoWriteCheckpointAPI.d.ts +2 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +171 -24
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +8 -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 +7 -2
- package/dist/storage/implementation/common/PersistedBatch.js +12 -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 +17 -15
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/models.d.ts +20 -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 +61 -29
- package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoChecksumsV1.d.ts +4 -4
- package/dist/storage/implementation/v1/MongoChecksumsV1.js +119 -7
- package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +11 -2
- package/dist/storage/implementation/v1/MongoCompactorV1.js +251 -2
- package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -1
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +18 -19
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +82 -58
- package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
- package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +9 -10
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js +2 -8
- package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -1
- package/dist/storage/implementation/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/BucketDataContextV3.d.ts +13 -0
- package/dist/storage/implementation/v3/BucketDataContextV3.js +23 -0
- package/dist/storage/implementation/v3/BucketDataContextV3.js.map +1 -0
- package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +8 -4
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js +309 -259
- package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +30 -9
- package/dist/storage/implementation/v3/MongoChecksumsV3.js +161 -20
- package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +40 -2
- package/dist/storage/implementation/v3/MongoCompactorV3.js +647 -23
- package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +67 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +351 -0
- package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -0
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +45 -30
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +272 -140
- package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
- package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +6 -3
- package/dist/storage/implementation/v3/PersistedBatchV3.js +84 -21
- package/dist/storage/implementation/v3/PersistedBatchV3.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 +15 -13
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +32 -27
- package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
- package/dist/storage/implementation/v3/bucket-format.d.ts +13 -0
- package/dist/storage/implementation/v3/bucket-format.js +77 -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 +30 -0
- package/dist/storage/implementation/v3/chunking.js.map +1 -0
- package/dist/storage/implementation/v3/models.d.ts +101 -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/object-storage/BucketDataObjectStorage.d.ts +21 -0
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js +44 -0
- package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.d.ts +30 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.js +12 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorage.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.d.ts +70 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js +146 -0
- package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js.map +1 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.d.ts +42 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js +285 -0
- package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js.map +1 -0
- package/dist/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 +49 -3
- package/dist/types/types.js +48 -1
- package/dist/types/types.js.map +1 -1
- package/dist/utils/test-utils.d.ts +1 -2
- package/dist/utils/test-utils.js +7 -1
- package/dist/utils/test-utils.js.map +1 -1
- package/dist/utils/util.d.ts +9 -2
- package/dist/utils/util.js +128 -4
- package/dist/utils/util.js.map +1 -1
- package/package.json +12 -19
- package/src/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.ts +55 -0
- package/src/storage/MongoBucketStorage.ts +347 -88
- package/src/storage/implementation/MongoBucketBatch.ts +147 -82
- package/src/storage/implementation/MongoChecksums.ts +93 -153
- package/src/storage/implementation/MongoCompactor.ts +102 -316
- package/src/storage/implementation/MongoHydrationState.ts +61 -0
- package/src/storage/implementation/MongoParameterCompactor.ts +25 -6
- 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 +46 -4
- package/src/storage/implementation/MongoSyncBucketStorage.ts +121 -87
- package/src/storage/implementation/MongoSyncRulesLock.ts +7 -4
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +202 -28
- package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +9 -0
- package/src/storage/implementation/common/PersistedBatch.ts +19 -3
- package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +1 -1
- package/src/storage/implementation/createMongoSyncBucketStorage.ts +21 -7
- package/src/storage/implementation/db.ts +19 -20
- package/src/storage/implementation/models.ts +20 -14
- package/src/storage/implementation/v1/MongoBucketBatchV1.ts +75 -37
- package/src/storage/implementation/v1/MongoChecksumsV1.ts +154 -12
- package/src/storage/implementation/v1/MongoCompactorV1.ts +294 -9
- package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +142 -105
- package/src/storage/implementation/v1/SingleBucketStoreV1.ts +18 -27
- package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +11 -1
- package/src/storage/implementation/v1/models.ts +11 -1
- package/src/storage/implementation/v3/BucketDataContextV3.ts +32 -0
- package/src/storage/implementation/v3/MongoBucketBatchV3.ts +382 -321
- package/src/storage/implementation/v3/MongoChecksumsV3.ts +250 -32
- package/src/storage/implementation/v3/MongoCompactorV3.ts +847 -32
- package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +482 -0
- package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +359 -187
- package/src/storage/implementation/v3/PersistedBatchV3.ts +118 -37
- package/src/storage/implementation/v3/SourceRecordStoreV3.ts +12 -12
- package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +46 -36
- package/src/storage/implementation/v3/bucket-format.ts +97 -0
- package/src/storage/implementation/v3/chunking.ts +40 -0
- package/src/storage/implementation/v3/models.ts +132 -55
- package/src/storage/implementation/v3/object-storage/BucketDataObjectStorage.ts +54 -0
- package/src/storage/implementation/v3/object-storage/ObjectStorage.ts +29 -0
- package/src/storage/implementation/v3/object-storage/ObjectStorageLifecycle.ts +171 -0
- package/src/storage/implementation/v3/object-storage/S3ObjectStorage.ts +343 -0
- package/src/storage/implementation/v3/source-table-utils.ts +392 -0
- package/src/storage/storage-index.ts +12 -4
- package/src/types/types.ts +58 -1
- package/src/utils/test-utils.ts +8 -3
- package/src/utils/util.ts +185 -6
- package/test/src/__snapshots__/storage.test.ts.snap +0 -75
- package/test/src/__snapshots__/storage_sync.test.ts.snap +35 -617
- package/test/src/cleanup-stopped-sync-configs.test.ts +671 -0
- package/test/src/helpers/MemoryObjectStorage.ts +53 -0
- package/test/src/helpers/s3TestFactory.ts +69 -0
- package/test/src/object_storage_lifecycle.test.ts +59 -0
- package/test/src/setup.ts +6 -1
- package/test/src/storage.test.ts +227 -13
- package/test/src/storage_compacting.test.ts +1951 -12
- package/test/src/storage_object_storage_inline_threshold.test.ts +116 -0
- package/test/src/storage_s3_checksums.test.ts +191 -0
- package/test/src/storage_s3_compaction_lifecycle.test.ts +417 -0
- package/test/src/storage_s3_reading.test.ts +526 -0
- package/test/src/storage_s3_writing.test.ts +135 -0
- package/test/src/storage_sync.test.ts +1180 -73
- package/test/src/storeCurrentData.test.ts +227 -0
- 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/common/SingleBucketStore.d.ts +0 -54
- package/dist/storage/implementation/common/SingleBucketStore.js +0 -3
- package/dist/storage/implementation/common/SingleBucketStore.js.map +0 -1
- package/dist/storage/implementation/v3/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/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +0 -18
- package/dist/storage/implementation/v3/SingleBucketStoreV3.js +0 -48
- package/dist/storage/implementation/v3/SingleBucketStoreV3.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/common/SingleBucketStore.ts +0 -63
- package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +0 -24
- package/src/storage/implementation/v3/MongoParameterLookupV3.ts +0 -11
- package/src/storage/implementation/v3/SingleBucketStoreV3.ts +0 -68
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import * as sqlite from 'node:sqlite';
|
|
2
|
-
|
|
3
|
-
import { ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
4
|
-
import { storage } from '@powersync/service-core';
|
|
5
|
-
import {
|
|
6
|
-
BucketDataScope,
|
|
7
|
-
BucketDataSource,
|
|
8
|
-
CompatibilityOption,
|
|
9
|
-
DEFAULT_HYDRATION_STATE,
|
|
10
|
-
HydratedSyncConfig,
|
|
11
|
-
HydrationState,
|
|
12
|
-
nodeSqlite,
|
|
13
|
-
ParameterIndexLookupCreator,
|
|
14
|
-
ParameterLookupScope,
|
|
15
|
-
SyncConfigWithErrors,
|
|
16
|
-
versionedHydrationState
|
|
17
|
-
} from '@powersync/service-sync-rules';
|
|
18
|
-
import { BucketDefinitionMapping } from './BucketDefinitionMapping.js';
|
|
19
|
-
import { StorageConfig } from './models.js';
|
|
20
|
-
|
|
21
|
-
export class MongoPersistedSyncRules implements storage.PersistedSyncRules {
|
|
22
|
-
public readonly hydrationState: HydrationState;
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
public readonly id: number,
|
|
26
|
-
public readonly syncConfigWithErrors: SyncConfigWithErrors,
|
|
27
|
-
public readonly slot_name: string,
|
|
28
|
-
private readonly mapping: BucketDefinitionMapping | null,
|
|
29
|
-
private readonly storageConfig: StorageConfig
|
|
30
|
-
) {
|
|
31
|
-
if (this.storageConfig.incrementalReprocessing) {
|
|
32
|
-
if (this.mapping == null) {
|
|
33
|
-
throw new ServiceAssertionError(`mapping is required for v3 storage`);
|
|
34
|
-
}
|
|
35
|
-
this.hydrationState = new MongoHydrationState(this.mapping, this.id);
|
|
36
|
-
} else if (
|
|
37
|
-
!this.syncConfigWithErrors.config.compatibility.isEnabled(CompatibilityOption.versionedBucketIds) &&
|
|
38
|
-
!this.storageConfig.versionedBuckets
|
|
39
|
-
) {
|
|
40
|
-
this.hydrationState = DEFAULT_HYDRATION_STATE;
|
|
41
|
-
} else {
|
|
42
|
-
this.hydrationState = versionedHydrationState(this.id);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
hydratedSyncConfig(): HydratedSyncConfig {
|
|
47
|
-
return this.syncConfigWithErrors.config.hydrate({
|
|
48
|
-
hydrationState: this.hydrationState,
|
|
49
|
-
sqlite: nodeSqlite(sqlite)
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
class MongoHydrationState implements HydrationState {
|
|
55
|
-
constructor(
|
|
56
|
-
private readonly mapping: BucketDefinitionMapping,
|
|
57
|
-
private readonly version: number
|
|
58
|
-
) {}
|
|
59
|
-
|
|
60
|
-
getBucketSourceScope(source: BucketDataSource): BucketDataScope {
|
|
61
|
-
// Keep this aligned with versionedHydrationState() for now.
|
|
62
|
-
//
|
|
63
|
-
// Previous Mongo-specific behavior:
|
|
64
|
-
// return {
|
|
65
|
-
// bucketPrefix: defId,
|
|
66
|
-
// source
|
|
67
|
-
// };
|
|
68
|
-
return {
|
|
69
|
-
bucketPrefix: `${this.version}#${source.uniqueName}`,
|
|
70
|
-
source
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getParameterIndexLookupScope(source: ParameterIndexLookupCreator): ParameterLookupScope {
|
|
75
|
-
const defId = this.mapping.parameterLookupId(source);
|
|
76
|
-
return {
|
|
77
|
-
lookupName: defId,
|
|
78
|
-
queryId: '',
|
|
79
|
-
source
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
-
import { ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
3
|
-
import { storage, SyncRuleState } from '@powersync/service-core';
|
|
4
|
-
import * as bson from 'bson';
|
|
5
|
-
import { ReplicationStreamDocumentV3, SyncConfigDefinition } from '../storage-index.js';
|
|
6
|
-
import { BucketDefinitionMapping } from './BucketDefinitionMapping.js';
|
|
7
|
-
import { MongoPersistedSyncRules } from './MongoPersistedSyncRules.js';
|
|
8
|
-
import { MongoSyncRulesLock } from './MongoSyncRulesLock.js';
|
|
9
|
-
import { PowerSyncMongo } from './db.js';
|
|
10
|
-
import { getMongoStorageConfig } from './models.js';
|
|
11
|
-
import { SyncRuleDocumentV1 } from './v1/models.js';
|
|
12
|
-
|
|
13
|
-
abstract class MongoPersistedSyncRulesContentBase extends storage.PersistedSyncRulesContent {
|
|
14
|
-
public current_lock: MongoSyncRulesLock | null = null;
|
|
15
|
-
public readonly mapping: BucketDefinitionMapping;
|
|
16
|
-
public readonly syncConfigId: bson.ObjectId | null;
|
|
17
|
-
|
|
18
|
-
protected constructor(
|
|
19
|
-
protected readonly db: PowerSyncMongo,
|
|
20
|
-
options: ConstructorParameters<typeof storage.PersistedSyncRulesContent>[0] & {
|
|
21
|
-
mapping: BucketDefinitionMapping;
|
|
22
|
-
syncConfigId: bson.ObjectId | null;
|
|
23
|
-
}
|
|
24
|
-
) {
|
|
25
|
-
const { mapping, syncConfigId, ...base } = options;
|
|
26
|
-
super(base);
|
|
27
|
-
this.mapping = mapping;
|
|
28
|
-
this.syncConfigId = syncConfigId;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getStorageConfig() {
|
|
32
|
-
return getMongoStorageConfig(this.storageVersion);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
parsed(options: storage.ParseSyncRulesOptions): storage.PersistedSyncRules {
|
|
36
|
-
const parsed = super.parsed(options);
|
|
37
|
-
const storageConfig = this.getStorageConfig();
|
|
38
|
-
|
|
39
|
-
return new MongoPersistedSyncRules(
|
|
40
|
-
parsed.id,
|
|
41
|
-
parsed.syncConfigWithErrors,
|
|
42
|
-
parsed.slot_name,
|
|
43
|
-
storageConfig.incrementalReprocessing ? this.mapping : null,
|
|
44
|
-
storageConfig
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async lock(session?: mongo.ClientSession) {
|
|
49
|
-
const lock = await MongoSyncRulesLock.createLock(this.db.versioned(this.getStorageConfig()), this, session);
|
|
50
|
-
this.current_lock = lock;
|
|
51
|
-
return lock;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export class MongoPersistedSyncRulesContentV1 extends MongoPersistedSyncRulesContentBase {
|
|
56
|
-
constructor(db: PowerSyncMongo, doc: SyncRuleDocumentV1) {
|
|
57
|
-
super(db, {
|
|
58
|
-
id: doc._id,
|
|
59
|
-
sync_rules_content: doc.content,
|
|
60
|
-
compiled_plan: doc.serialized_plan ?? null,
|
|
61
|
-
last_checkpoint_lsn: doc.last_checkpoint_lsn,
|
|
62
|
-
// Handle legacy values
|
|
63
|
-
slot_name: doc.slot_name ?? `powersync_${doc._id}`,
|
|
64
|
-
last_fatal_error: doc.last_fatal_error,
|
|
65
|
-
last_fatal_error_ts: doc.last_fatal_error_ts,
|
|
66
|
-
last_checkpoint_ts: doc.last_checkpoint_ts,
|
|
67
|
-
last_keepalive_ts: doc.last_keepalive_ts,
|
|
68
|
-
active: doc.state == SyncRuleState.ACTIVE,
|
|
69
|
-
storageVersion: doc.storage_version ?? storage.LEGACY_STORAGE_VERSION,
|
|
70
|
-
mapping: new BucketDefinitionMapping(),
|
|
71
|
-
syncConfigId: null
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export class MongoPersistedSyncRulesContentV3 extends MongoPersistedSyncRulesContentBase {
|
|
77
|
-
declare public readonly syncConfigId: bson.ObjectId;
|
|
78
|
-
|
|
79
|
-
constructor(db: PowerSyncMongo, doc: ReplicationStreamDocumentV3, config: SyncConfigDefinition) {
|
|
80
|
-
const state = doc.sync_configs.find((c) => c._id.equals(config._id));
|
|
81
|
-
if (state == null) {
|
|
82
|
-
throw new ServiceAssertionError(`Cannot find sync config ${config._id} in replication stream ${doc._id}`);
|
|
83
|
-
}
|
|
84
|
-
super(db, {
|
|
85
|
-
id: doc._id,
|
|
86
|
-
sync_rules_content: config.content,
|
|
87
|
-
compiled_plan: config.serialized_plan ?? null,
|
|
88
|
-
|
|
89
|
-
last_checkpoint_lsn: state?.last_checkpoint_lsn ?? null,
|
|
90
|
-
slot_name: doc.slot_name ?? `powersync_${doc._id}`,
|
|
91
|
-
last_fatal_error: doc.last_fatal_error,
|
|
92
|
-
last_fatal_error_ts: doc.last_fatal_error_ts,
|
|
93
|
-
last_checkpoint_ts: doc.last_checkpoint_ts,
|
|
94
|
-
last_keepalive_ts: doc.last_keepalive_ts,
|
|
95
|
-
active: doc.state == SyncRuleState.ACTIVE && state.state == SyncRuleState.ACTIVE,
|
|
96
|
-
storageVersion: doc.storage_version,
|
|
97
|
-
mapping: BucketDefinitionMapping.fromSyncConfig(config),
|
|
98
|
-
syncConfigId: config._id
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { InternalOpId } from '@powersync/service-core';
|
|
2
|
-
import * as bson from 'bson';
|
|
3
|
-
import { BucketDefinitionMapping } from '../BucketDefinitionMapping.js';
|
|
4
|
-
import type { VersionedPowerSyncMongo } from '../db.js';
|
|
5
|
-
|
|
6
|
-
export interface MongoSyncBucketStorageContext<TDb extends VersionedPowerSyncMongo = VersionedPowerSyncMongo> {
|
|
7
|
-
db: TDb;
|
|
8
|
-
group_id: number;
|
|
9
|
-
mapping: BucketDefinitionMapping;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface MongoSyncBucketStorageCheckpoint {
|
|
13
|
-
checkpoint: InternalOpId;
|
|
14
|
-
snapshotTime: bson.Timestamp;
|
|
15
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
-
import { InternalOpId } from '@powersync/service-core';
|
|
3
|
-
import { BucketDataProperties } from '../models.js';
|
|
4
|
-
import { BucketDataDoc, BucketKey } from './BucketDataDoc.js';
|
|
5
|
-
|
|
6
|
-
const GENERIC_ID = Symbol('BucketDataDocumentGenericId');
|
|
7
|
-
export type BucketDataDocumentGenericId = {
|
|
8
|
-
b: string;
|
|
9
|
-
o: InternalOpId;
|
|
10
|
-
// Hack to ensure this can't be constructed directly
|
|
11
|
-
[GENERIC_ID]: true;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* This document is never actually constructed - we use it as a "virtual" type.
|
|
16
|
-
*
|
|
17
|
-
* The actual implementations are BucketDataDocumentV1 or BucketDataDocumentV3.
|
|
18
|
-
* They don't fully satisfy this interface, but this works to share common implementations.
|
|
19
|
-
*
|
|
20
|
-
* The idea is that we can have a common implementation between V1 & V3, using this type,
|
|
21
|
-
* and operate on MongoDB collections.
|
|
22
|
-
*
|
|
23
|
-
* This interface serves two primary purposes:
|
|
24
|
-
* 1. Captures properties that exist on both V1 and V3 storage models.
|
|
25
|
-
* 2. Gives a common reference when querying or modifying collections.
|
|
26
|
-
*
|
|
27
|
-
* Generics would've been ideal, but they don't play well with MongoDB collections.
|
|
28
|
-
*/
|
|
29
|
-
export interface BucketDataDocumentGeneric extends BucketDataProperties {
|
|
30
|
-
_id: BucketDataDocumentGenericId;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Represent read/write access for a single bucket.
|
|
35
|
-
*
|
|
36
|
-
* This does not implement the actual collection operations, but supports the required conversions
|
|
37
|
-
* between in-memory BucketDataDoc and the specific storage formats.
|
|
38
|
-
*/
|
|
39
|
-
export interface SingleBucketStore {
|
|
40
|
-
readonly key: BucketKey;
|
|
41
|
-
|
|
42
|
-
readonly collection: mongo.Collection<BucketDataDocumentGeneric>;
|
|
43
|
-
docId(o: InternalOpId): BucketDataDocumentGenericId;
|
|
44
|
-
readonly minId: BucketDataDocumentGenericId;
|
|
45
|
-
readonly maxId: BucketDataDocumentGenericId;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Convert in-memory document -> persisted document.
|
|
49
|
-
*/
|
|
50
|
-
toPersistedDocument(source: Omit<BucketDataDoc, 'bucketKey'>): BucketDataDocumentGeneric;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Convert persisted document -> in-memory document.
|
|
54
|
-
*/
|
|
55
|
-
fromPersistedDocument(doc: BucketDataDocumentGeneric): BucketDataDoc;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Convert partial persisted document -> partial in-memory document.
|
|
59
|
-
*/
|
|
60
|
-
fromPartialPersistedDocument<T extends keyof BucketDataProperties>(
|
|
61
|
-
doc: Pick<BucketDataDocumentGeneric, '_id' | T>
|
|
62
|
-
): Pick<BucketDataDoc, 'bucketKey' | 'o' | T>;
|
|
63
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
-
import { MongoParameterCompactor } from '../MongoParameterCompactor.js';
|
|
3
|
-
import { VersionedPowerSyncMongoV3 } from './VersionedPowerSyncMongoV3.js';
|
|
4
|
-
|
|
5
|
-
export class MongoParameterCompactorV3 extends MongoParameterCompactor {
|
|
6
|
-
declare protected readonly db: VersionedPowerSyncMongoV3;
|
|
7
|
-
|
|
8
|
-
protected async getCollections(): Promise<mongo.Collection<mongo.Document>[]> {
|
|
9
|
-
const collections = await this.db.listParameterIndexCollectionsV3(this.group_id);
|
|
10
|
-
return collections.map((collection) => collection.collection as unknown as mongo.Collection<mongo.Document>);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
protected collectionFilter(): mongo.Document {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
protected deleteFilter(doc: mongo.Document): mongo.Document {
|
|
18
|
-
return {
|
|
19
|
-
lookup: doc.lookup,
|
|
20
|
-
_id: { $lte: doc._id },
|
|
21
|
-
key: doc.key
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { deserializeParameterLookup } from '@powersync/service-core';
|
|
2
|
-
import { ParameterIndexId, ScopedParameterLookup, SqliteJsonValue } from '@powersync/service-sync-rules';
|
|
3
|
-
import * as bson from 'bson';
|
|
4
|
-
|
|
5
|
-
export function serializeParameterLookupV3(lookup: ScopedParameterLookup): bson.Binary {
|
|
6
|
-
return new bson.Binary(bson.serialize({ l: lookup.values.slice(2) }));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function deserializeParameterLookupV3(lookup: bson.Binary, indexId: ParameterIndexId): SqliteJsonValue[] {
|
|
10
|
-
return [indexId, '', ...deserializeParameterLookup(lookup)];
|
|
11
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
|
-
import { InternalOpId } from '@powersync/service-core';
|
|
3
|
-
import { BucketDataDoc, BucketKey } from '../common/BucketDataDoc.js';
|
|
4
|
-
import {
|
|
5
|
-
BucketDataDocumentGeneric,
|
|
6
|
-
BucketDataDocumentGenericId,
|
|
7
|
-
SingleBucketStore
|
|
8
|
-
} from '../common/SingleBucketStore.js';
|
|
9
|
-
import { BucketDataProperties } from '../models.js';
|
|
10
|
-
import { VersionedPowerSyncMongoV3 } from './VersionedPowerSyncMongoV3.js';
|
|
11
|
-
import { BucketDataDocumentV3, BucketDataKeyV3, loadBucketDataDocumentV3, serializeBucketDataV3 } from './models.js';
|
|
12
|
-
|
|
13
|
-
export class SingleBucketStoreV3 implements SingleBucketStore {
|
|
14
|
-
public readonly collection: mongo.Collection<BucketDataDocumentGeneric>;
|
|
15
|
-
|
|
16
|
-
constructor(
|
|
17
|
-
private db: VersionedPowerSyncMongoV3,
|
|
18
|
-
public readonly key: BucketKey
|
|
19
|
-
) {
|
|
20
|
-
this.collection = db.bucketDataV3(
|
|
21
|
-
key.replicationStreamId,
|
|
22
|
-
key.definitionId
|
|
23
|
-
) as unknown as mongo.Collection<BucketDataDocumentGeneric>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
docId(o: InternalOpId): BucketDataDocumentGenericId {
|
|
27
|
-
// `satisfies BucketDataKeyV3` checks that we use the correct type for V3 storage
|
|
28
|
-
// `as BucketDataDocumentGenericId` does a cast to get the interface virtual type
|
|
29
|
-
return {
|
|
30
|
-
b: this.key.bucket,
|
|
31
|
-
o
|
|
32
|
-
} satisfies BucketDataKeyV3 as BucketDataDocumentGenericId;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get minId(): BucketDataDocumentGenericId {
|
|
36
|
-
return {
|
|
37
|
-
b: this.key.bucket,
|
|
38
|
-
o: new mongo.MinKey()
|
|
39
|
-
} as any; // No way to properly type this
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get maxId(): BucketDataDocumentGenericId {
|
|
43
|
-
return {
|
|
44
|
-
b: this.key.bucket,
|
|
45
|
-
o: new mongo.MaxKey()
|
|
46
|
-
} as any; // No way to properly type this
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
toPersistedDocument(source: Omit<BucketDataDoc, 'bucketKey'>): BucketDataDocumentGeneric {
|
|
50
|
-
return serializeBucketDataV3({ bucketKey: this.key, ...source }) as BucketDataDocumentGeneric;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
fromPersistedDocument(doc: BucketDataDocumentGeneric): BucketDataDoc {
|
|
54
|
-
return loadBucketDataDocumentV3(this.key, doc as BucketDataDocumentV3);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fromPartialPersistedDocument<T extends keyof BucketDataProperties>(
|
|
58
|
-
doc: Pick<BucketDataDocumentGeneric, '_id' | T>
|
|
59
|
-
): Pick<BucketDataDoc, 'bucketKey' | 'o' | T> {
|
|
60
|
-
const document = doc as Pick<BucketDataDocumentV3, '_id' | T>;
|
|
61
|
-
const { _id, ...rest } = document;
|
|
62
|
-
return {
|
|
63
|
-
bucketKey: this.key,
|
|
64
|
-
o: _id.o,
|
|
65
|
-
...rest
|
|
66
|
-
} as Pick<BucketDataDoc, 'bucketKey' | 'o' | T>;
|
|
67
|
-
}
|
|
68
|
-
}
|