@powersync/service-module-mongodb-storage 0.0.0-dev-20250108073049
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 +19 -0
- package/LICENSE +67 -0
- package/README.md +3 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/MongoMigrationAgent.d.ts +12 -0
- package/dist/migrations/MongoMigrationAgent.js +25 -0
- package/dist/migrations/MongoMigrationAgent.js.map +1 -0
- package/dist/migrations/db/migrations/1684951997326-init.d.ts +3 -0
- package/dist/migrations/db/migrations/1684951997326-init.js +30 -0
- package/dist/migrations/db/migrations/1684951997326-init.js.map +1 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +2 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +5 -0
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +1 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +3 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +54 -0
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +1 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +3 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +26 -0
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +1 -0
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.d.ts +3 -0
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js +28 -0
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js.map +1 -0
- package/dist/migrations/mongo-migration-store.d.ts +7 -0
- package/dist/migrations/mongo-migration-store.js +49 -0
- package/dist/migrations/mongo-migration-store.js.map +1 -0
- package/dist/module/MongoStorageModule.d.ts +10 -0
- package/dist/module/MongoStorageModule.js +31 -0
- package/dist/module/MongoStorageModule.js.map +1 -0
- package/dist/storage/MongoBucketStorage.d.ts +48 -0
- package/dist/storage/MongoBucketStorage.js +426 -0
- package/dist/storage/MongoBucketStorage.js.map +1 -0
- package/dist/storage/implementation/MongoBucketBatch.d.ts +72 -0
- package/dist/storage/implementation/MongoBucketBatch.js +681 -0
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -0
- package/dist/storage/implementation/MongoCompactor.d.ts +40 -0
- package/dist/storage/implementation/MongoCompactor.js +300 -0
- package/dist/storage/implementation/MongoCompactor.js.map +1 -0
- package/dist/storage/implementation/MongoIdSequence.d.ts +12 -0
- package/dist/storage/implementation/MongoIdSequence.js +21 -0
- package/dist/storage/implementation/MongoIdSequence.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +9 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js +9 -0
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +1 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +20 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +26 -0
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -0
- package/dist/storage/implementation/MongoStorageProvider.d.ts +5 -0
- package/dist/storage/implementation/MongoStorageProvider.js +33 -0
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -0
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +36 -0
- package/dist/storage/implementation/MongoSyncBucketStorage.js +529 -0
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -0
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +16 -0
- package/dist/storage/implementation/MongoSyncRulesLock.js +65 -0
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -0
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.d.ts +7 -0
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js +16 -0
- package/dist/storage/implementation/MongoTestStorageFactoryGenerator.js.map +1 -0
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +20 -0
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +104 -0
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -0
- package/dist/storage/implementation/OperationBatch.d.ts +34 -0
- package/dist/storage/implementation/OperationBatch.js +119 -0
- package/dist/storage/implementation/OperationBatch.js.map +1 -0
- package/dist/storage/implementation/PersistedBatch.d.ts +46 -0
- package/dist/storage/implementation/PersistedBatch.js +223 -0
- package/dist/storage/implementation/PersistedBatch.js.map +1 -0
- package/dist/storage/implementation/db.d.ts +36 -0
- package/dist/storage/implementation/db.js +47 -0
- package/dist/storage/implementation/db.js.map +1 -0
- package/dist/storage/implementation/models.d.ts +139 -0
- package/dist/storage/implementation/models.js +2 -0
- package/dist/storage/implementation/models.js.map +1 -0
- package/dist/storage/implementation/util.d.ts +46 -0
- package/dist/storage/implementation/util.js +155 -0
- package/dist/storage/implementation/util.js.map +1 -0
- package/dist/storage/storage-index.d.ts +14 -0
- package/dist/storage/storage-index.js +15 -0
- package/dist/storage/storage-index.js.map +1 -0
- package/dist/types/types.d.ts +18 -0
- package/dist/types/types.js +9 -0
- package/dist/types/types.js.map +1 -0
- package/package.json +48 -0
- package/src/index.ts +7 -0
- package/src/migrations/MongoMigrationAgent.ts +39 -0
- package/src/migrations/db/migrations/1684951997326-init.ts +39 -0
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +5 -0
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +105 -0
- package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +38 -0
- package/src/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.ts +40 -0
- package/src/migrations/mongo-migration-store.ts +62 -0
- package/src/module/MongoStorageModule.ts +37 -0
- package/src/storage/MongoBucketStorage.ts +531 -0
- package/src/storage/implementation/MongoBucketBatch.ts +896 -0
- package/src/storage/implementation/MongoCompactor.ts +381 -0
- package/src/storage/implementation/MongoIdSequence.ts +24 -0
- package/src/storage/implementation/MongoPersistedSyncRules.ts +16 -0
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +49 -0
- package/src/storage/implementation/MongoStorageProvider.ts +39 -0
- package/src/storage/implementation/MongoSyncBucketStorage.ts +612 -0
- package/src/storage/implementation/MongoSyncRulesLock.ts +88 -0
- package/src/storage/implementation/MongoTestStorageFactoryGenerator.ts +25 -0
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +146 -0
- package/src/storage/implementation/OperationBatch.ts +129 -0
- package/src/storage/implementation/PersistedBatch.ts +283 -0
- package/src/storage/implementation/db.ts +87 -0
- package/src/storage/implementation/models.ts +161 -0
- package/src/storage/implementation/util.ts +169 -0
- package/src/storage/storage-index.ts +14 -0
- package/src/types/types.ts +18 -0
- package/test/src/__snapshots__/storage_sync.test.ts.snap +332 -0
- package/test/src/env.ts +6 -0
- package/test/src/setup.ts +9 -0
- package/test/src/storage.test.ts +7 -0
- package/test/src/storage_compacting.test.ts +6 -0
- package/test/src/storage_sync.test.ts +113 -0
- package/test/src/util.ts +8 -0
- package/test/tsconfig.json +31 -0
- package/tsconfig.json +31 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +15 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @powersync/service-module-mongodb-storage
|
|
2
|
+
|
|
3
|
+
## 0.0.0-dev-20250108073049
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 697d44b: Moved MongoDB sync bucket storage implementation to the MongoDB module.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [697d44b]
|
|
12
|
+
- Updated dependencies [697d44b]
|
|
13
|
+
- Updated dependencies [48320b5]
|
|
14
|
+
- Updated dependencies [697d44b]
|
|
15
|
+
- @powersync/service-core@0.0.0-dev-20250108073049
|
|
16
|
+
- @powersync/lib-services-framework@0.0.0-dev-20250108073049
|
|
17
|
+
- @powersync/service-sync-rules@0.0.0-dev-20250108073049
|
|
18
|
+
- @powersync/service-types@0.0.0-dev-20250108073049
|
|
19
|
+
- @powersync/lib-service-mongodb@0.0.0-dev-20250108073049
|
package/LICENSE
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2023-2024 Journey Mobile, Inc.
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
|
|
20
|
+
|
|
21
|
+
### License Grant
|
|
22
|
+
|
|
23
|
+
Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
|
|
24
|
+
|
|
25
|
+
### Permitted Purpose
|
|
26
|
+
|
|
27
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
|
|
28
|
+
|
|
29
|
+
1. substitutes for the Software;
|
|
30
|
+
2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
|
|
31
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
32
|
+
|
|
33
|
+
Permitted Purposes specifically include using the Software:
|
|
34
|
+
|
|
35
|
+
1. for your internal use and access;
|
|
36
|
+
2. for non-commercial education;
|
|
37
|
+
3. for non-commercial research; and
|
|
38
|
+
4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
|
|
39
|
+
|
|
40
|
+
### Patents
|
|
41
|
+
|
|
42
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
|
|
43
|
+
|
|
44
|
+
### Redistribution
|
|
45
|
+
|
|
46
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of the Software.
|
|
47
|
+
If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
|
|
48
|
+
|
|
49
|
+
### Disclaimer
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
52
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
53
|
+
|
|
54
|
+
### Trademarks
|
|
55
|
+
|
|
56
|
+
Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
|
|
57
|
+
|
|
58
|
+
## Grant of Future License
|
|
59
|
+
|
|
60
|
+
We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply:
|
|
61
|
+
|
|
62
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
63
|
+
You may obtain a copy of the License at
|
|
64
|
+
|
|
65
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
66
|
+
|
|
67
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAE/C,cAAc,4BAA4B,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AAEtD,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as framework from '@powersync/lib-services-framework';
|
|
2
|
+
import { migrations } from '@powersync/service-core';
|
|
3
|
+
import { PowerSyncMongo } from '../storage/storage-index.js';
|
|
4
|
+
import { MongoStorageConfig } from '../types/types.js';
|
|
5
|
+
export declare class MongoMigrationAgent extends migrations.AbstractPowerSyncMigrationAgent {
|
|
6
|
+
store: framework.MigrationStore;
|
|
7
|
+
locks: framework.LockManager;
|
|
8
|
+
protected client: PowerSyncMongo;
|
|
9
|
+
constructor(mongoConfig: MongoStorageConfig);
|
|
10
|
+
getInternalScriptsDir(): string;
|
|
11
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
|
+
import { migrations } from '@powersync/service-core';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { createPowerSyncMongo } from '../storage/storage-index.js';
|
|
6
|
+
import { createMongoMigrationStore } from './mongo-migration-store.js';
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
const MONGO_LOCK_PROCESS = 'migrations';
|
|
10
|
+
const MIGRATIONS_DIR = path.join(__dirname, '/db/migrations');
|
|
11
|
+
export class MongoMigrationAgent extends migrations.AbstractPowerSyncMigrationAgent {
|
|
12
|
+
constructor(mongoConfig) {
|
|
13
|
+
super();
|
|
14
|
+
this.client = createPowerSyncMongo(mongoConfig);
|
|
15
|
+
this.store = createMongoMigrationStore(this.client.db);
|
|
16
|
+
this.locks = new lib_mongo.locks.MongoLockManager({ collection: this.client.locks, name: MONGO_LOCK_PROCESS });
|
|
17
|
+
}
|
|
18
|
+
getInternalScriptsDir() {
|
|
19
|
+
return MIGRATIONS_DIR;
|
|
20
|
+
}
|
|
21
|
+
async [Symbol.asyncDispose]() {
|
|
22
|
+
await this.client.client.close();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=MongoMigrationAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoMigrationAgent.js","sourceRoot":"","sources":["../../src/migrations/MongoMigrationAgent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAkB,MAAM,6BAA6B,CAAC;AAEnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAE3C,MAAM,kBAAkB,GAAG,YAAY,CAAC;AACxC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAE9D,MAAM,OAAO,mBAAoB,SAAQ,UAAU,CAAC,+BAA+B;IAMjF,YAAY,WAA+B;QACzC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAEhD,IAAI,CAAC,KAAK,GAAG,yBAAyB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,KAAK,GAAG,IAAI,SAAS,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACjH,CAAC;IAED,qBAAqB;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
|
+
import * as storage from '../../../storage/storage-index.js';
|
|
3
|
+
export const up = async (context) => {
|
|
4
|
+
const { service_context: { configuration } } = context;
|
|
5
|
+
const database = storage.createPowerSyncMongo(configuration.storage);
|
|
6
|
+
await lib_mongo.waitForAuth(database.db);
|
|
7
|
+
try {
|
|
8
|
+
await database.bucket_parameters.createIndex({
|
|
9
|
+
'key.g': 1,
|
|
10
|
+
lookup: 1,
|
|
11
|
+
_id: 1
|
|
12
|
+
}, { name: 'lookup1' });
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
await database.client.close();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export const down = async (context) => {
|
|
19
|
+
const { service_context: { configuration } } = context;
|
|
20
|
+
const database = storage.createPowerSyncMongo(configuration.storage);
|
|
21
|
+
try {
|
|
22
|
+
if (await database.bucket_parameters.indexExists('lookup')) {
|
|
23
|
+
await database.bucket_parameters.dropIndex('lookup1');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
await database.client.close();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=1684951997326-init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1684951997326-init.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1684951997326-init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAE5D,OAAO,KAAK,OAAO,MAAM,mCAAmC,CAAC;AAG7D,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,MAAM,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAA6B,CAAC,CAAC;IAC3F,MAAM,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAC1C;YACE,OAAO,EAAE,CAAC;YACV,MAAM,EAAE,CAAC;YACT,GAAG,EAAE,CAAC;SACP,EACD,EAAE,IAAI,EAAE,SAAS,EAAE,CACpB,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IAEZ,MAAM,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAA6B,CAAC,CAAC;IAC3F,IAAI,CAAC;QACH,IAAI,MAAM,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3D,MAAM,QAAQ,CAAC,iBAAiB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1688556755264-initial-sync-rules.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1688556755264-initial-sync-rules.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,EAAE;IAC3B,kDAAkD;AACpD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
|
+
import { storage as core_storage } from '@powersync/service-core';
|
|
3
|
+
import * as storage from '../../../storage/storage-index.js';
|
|
4
|
+
export const up = async (context) => {
|
|
5
|
+
const { service_context: { configuration } } = context;
|
|
6
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
7
|
+
await lib_mongo.waitForAuth(db.db);
|
|
8
|
+
try {
|
|
9
|
+
// We keep the old flags for existing deployments still shutting down.
|
|
10
|
+
// 1. New sync rules: `active = false, snapshot_done = false, replicating = true, auto_activate = true`
|
|
11
|
+
await db.sync_rules.updateMany({
|
|
12
|
+
active: { $ne: true },
|
|
13
|
+
replicating: true,
|
|
14
|
+
auto_activate: true
|
|
15
|
+
}, { $set: { state: core_storage.SyncRuleState.PROCESSING } });
|
|
16
|
+
// 2. Snapshot done: `active = true, snapshot_done = true, replicating = true, auto_activate = false`
|
|
17
|
+
await db.sync_rules.updateMany({
|
|
18
|
+
active: true
|
|
19
|
+
}, { $set: { state: core_storage.SyncRuleState.ACTIVE } });
|
|
20
|
+
// 3. Stopped: `active = false, snapshot_done = true, replicating = false, auto_activate = false`.
|
|
21
|
+
await db.sync_rules.updateMany({
|
|
22
|
+
active: { $ne: true },
|
|
23
|
+
replicating: { $ne: true },
|
|
24
|
+
auto_activate: { $ne: true }
|
|
25
|
+
}, { $set: { state: core_storage.SyncRuleState.STOP } });
|
|
26
|
+
const remaining = await db.sync_rules.find({ state: null }).toArray();
|
|
27
|
+
if (remaining.length > 0) {
|
|
28
|
+
const slots = remaining.map((doc) => doc.slot_name).join(', ');
|
|
29
|
+
throw new Error(`Invalid state for sync rules: ${slots}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
await db.client.close();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export const down = async (context) => {
|
|
37
|
+
const { service_context: { configuration } } = context;
|
|
38
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
39
|
+
try {
|
|
40
|
+
await db.sync_rules.updateMany({
|
|
41
|
+
state: core_storage.SyncRuleState.ACTIVE
|
|
42
|
+
}, { $set: { active: true, replicating: true } });
|
|
43
|
+
await db.sync_rules.updateMany({
|
|
44
|
+
state: core_storage.SyncRuleState.PROCESSING
|
|
45
|
+
}, { $set: { active: false, replicating: true, auto_activate: true } });
|
|
46
|
+
await db.sync_rules.updateMany({
|
|
47
|
+
$or: [{ state: core_storage.SyncRuleState.STOP }, { state: core_storage.SyncRuleState.TERMINATED }]
|
|
48
|
+
}, { $set: { active: false, replicating: false, auto_activate: false } });
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
await db.client.close();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=1702295701188-sync-rule-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1702295701188-sync-rule-state.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1702295701188-sync-rule-state.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as storage from '../../../storage/storage-index.js';
|
|
2
|
+
export const up = async (context) => {
|
|
3
|
+
const { service_context: { configuration } } = context;
|
|
4
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
5
|
+
try {
|
|
6
|
+
await db.write_checkpoints.createIndex({
|
|
7
|
+
user_id: 1
|
|
8
|
+
}, { name: 'user_id' });
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
await db.client.close();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const down = async (context) => {
|
|
15
|
+
const { service_context: { configuration } } = context;
|
|
16
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
17
|
+
try {
|
|
18
|
+
if (await db.write_checkpoints.indexExists('user_id')) {
|
|
19
|
+
await db.write_checkpoints.dropIndex('user_id');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
await db.client.close();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=1711543888062-write-checkpoint-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1711543888062-write-checkpoint-index.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,mCAAmC,CAAC;AAG7D,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAA6B,CAAC,CAAC;IAErF,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,iBAAiB,CAAC,WAAW,CACpC;YACE,OAAO,EAAE,CAAC;SACX,EACD,EAAE,IAAI,EAAE,SAAS,EAAE,CACpB,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IAEZ,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAA6B,CAAC,CAAC;IAErF,IAAI,CAAC;QACH,IAAI,MAAM,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;YACtD,MAAM,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as storage from '../../../storage/storage-index.js';
|
|
2
|
+
const INDEX_NAME = 'user_sync_rule_unique';
|
|
3
|
+
export const up = async (context) => {
|
|
4
|
+
const { service_context: { configuration } } = context;
|
|
5
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
6
|
+
try {
|
|
7
|
+
await db.custom_write_checkpoints.createIndex({
|
|
8
|
+
user_id: 1,
|
|
9
|
+
sync_rules_id: 1
|
|
10
|
+
}, { name: INDEX_NAME, unique: true });
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
await db.client.close();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export const down = async (context) => {
|
|
17
|
+
const { service_context: { configuration } } = context;
|
|
18
|
+
const db = storage.createPowerSyncMongo(configuration.storage);
|
|
19
|
+
try {
|
|
20
|
+
if (await db.custom_write_checkpoints.indexExists(INDEX_NAME)) {
|
|
21
|
+
await db.custom_write_checkpoints.dropIndex(INDEX_NAME);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
await db.client.close();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=1727099539247-custom-write-checkpoint-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1727099539247-custom-write-checkpoint-index.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,mCAAmC,CAAC;AAG7D,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IACzE,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IACZ,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAA6B,CAAC,CAAC;IAErF,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAC3C;YACE,OAAO,EAAE,CAAC;YACV,aAAa,EAAE,CAAC;SACjB,EACD,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,CACnC,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAA0C,KAAK,EAAE,OAAO,EAAE,EAAE;IAC3E,MAAM,EACJ,eAAe,EAAE,EAAE,aAAa,EAAE,EACnC,GAAG,OAAO,CAAC;IAEZ,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAA6B,CAAC,CAAC;IAErF,IAAI,CAAC;QACH,IAAI,MAAM,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9D,MAAM,EAAE,CAAC,wBAAwB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { migrations } from '@powersync/lib-services-framework';
|
|
2
|
+
import { Db } from 'mongodb';
|
|
3
|
+
/**
|
|
4
|
+
* A custom store for node-migrate which is used to save and load migrations that have
|
|
5
|
+
* been operated on to mongo.
|
|
6
|
+
*/
|
|
7
|
+
export declare const createMongoMigrationStore: (db: Db) => migrations.MigrationStore;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* A custom store for node-migrate which is used to save and load migrations that have
|
|
4
|
+
* been operated on to mongo.
|
|
5
|
+
*/
|
|
6
|
+
export const createMongoMigrationStore = (db) => {
|
|
7
|
+
const collection = db.collection('migrations');
|
|
8
|
+
return {
|
|
9
|
+
load: async () => {
|
|
10
|
+
const state_entry = await collection.findOne();
|
|
11
|
+
if (!state_entry) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const { _id, ...state } = state_entry;
|
|
15
|
+
/**
|
|
16
|
+
* This is for backwards compatibility. A previous version of the migration tool used to save
|
|
17
|
+
* state as `lastRun`.
|
|
18
|
+
*/
|
|
19
|
+
let last_run = state.last_run;
|
|
20
|
+
if ('lastRun' in state) {
|
|
21
|
+
last_run = state.lastRun;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This is for backwards compatibility. A previous version of the migration tool used to include the
|
|
25
|
+
* file extension in migration names. This strips that extension off if it exists
|
|
26
|
+
*/
|
|
27
|
+
const extension = path.extname(last_run);
|
|
28
|
+
if (extension) {
|
|
29
|
+
last_run = last_run.replace(extension, '');
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
last_run,
|
|
33
|
+
log: state.log || []
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
clear: async () => {
|
|
37
|
+
await collection.deleteMany({});
|
|
38
|
+
},
|
|
39
|
+
save: async (state) => {
|
|
40
|
+
await collection.replaceOne({}, {
|
|
41
|
+
last_run: state.last_run,
|
|
42
|
+
log: state.log
|
|
43
|
+
}, {
|
|
44
|
+
upsert: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=mongo-migration-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-migration-store.js","sourceRoot":"","sources":["../../src/migrations/mongo-migration-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,EAAM,EAA6B,EAAE;IAC7E,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAA4B,YAAY,CAAC,CAAC;IAE1E,OAAO;QACL,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC;YAC/C,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,OAAO;YACT,CAAC;YAED,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,WAAW,CAAC;YAEtC;;;eAGG;YACH,IAAI,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YAC9B,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;gBACvB,QAAQ,GAAI,KAAa,CAAC,OAAO,CAAC;YACpC,CAAC;YAED;;;eAGG;YACH,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACzC,IAAI,SAAS,EAAE,CAAC;gBACd,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO;gBACL,QAAQ;gBACR,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,EAAE;aACrB,CAAC;QACJ,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAClC,CAAC;QAED,IAAI,EAAE,KAAK,EAAE,KAAgC,EAAE,EAAE;YAC/C,MAAM,UAAU,CAAC,UAAU,CACzB,EAAE,EACF;gBACE,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,GAAG,EAAE,KAAK,CAAC,GAAG;aACf,EACD;gBACE,MAAM,EAAE,IAAI;aACb,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as core from '@powersync/service-core';
|
|
2
|
+
export declare class MongoStorageModule extends core.modules.AbstractModule {
|
|
3
|
+
constructor();
|
|
4
|
+
initialize(context: core.system.ServiceContextContainer): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Combines base config with normalized connection settings
|
|
7
|
+
*/
|
|
8
|
+
private resolveConfig;
|
|
9
|
+
teardown(options: core.modules.TearDownOptions): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
|
+
import * as core from '@powersync/service-core';
|
|
3
|
+
import { MongoMigrationAgent } from '../migrations/MongoMigrationAgent.js';
|
|
4
|
+
import { MongoStorageProvider } from '../storage/storage-index.js';
|
|
5
|
+
import * as types from '../types/types.js';
|
|
6
|
+
export class MongoStorageModule extends core.modules.AbstractModule {
|
|
7
|
+
constructor() {
|
|
8
|
+
super({
|
|
9
|
+
name: 'MongoDB Storage'
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async initialize(context) {
|
|
13
|
+
context.storageEngine.registerProvider(new MongoStorageProvider());
|
|
14
|
+
if (types.isMongoStorageConfig(context.configuration.storage)) {
|
|
15
|
+
context.migrations.registerMigrationAgent(new MongoMigrationAgent(this.resolveConfig(context.configuration.storage)));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Combines base config with normalized connection settings
|
|
20
|
+
*/
|
|
21
|
+
resolveConfig(config) {
|
|
22
|
+
return {
|
|
23
|
+
...config,
|
|
24
|
+
...lib_mongo.normalizeMongoConfig(config)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async teardown(options) {
|
|
28
|
+
// teardown is implemented in the storage engine
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=MongoStorageModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoStorageModule.js","sourceRoot":"","sources":["../../src/module/MongoStorageModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,IAAI,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,OAAO,CAAC,cAAc;IACjE;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,iBAAiB;SACxB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAA4C;QAC3D,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;QAEnE,IAAI,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9D,OAAO,CAAC,UAAU,CAAC,sBAAsB,CACvC,IAAI,mBAAmB,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAC3E,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,MAAgC;QACpD,OAAO;YACL,GAAG,MAAM;YACT,GAAG,SAAS,CAAC,oBAAoB,CAAC,MAAM,CAAC;SAC1C,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAqC;QAClD,gDAAgD;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { storage } from '@powersync/service-core';
|
|
2
|
+
import { DisposableObserver } from '@powersync/lib-services-framework';
|
|
3
|
+
import { PowerSyncMongo } from './implementation/db.js';
|
|
4
|
+
import { MongoPersistedSyncRulesContent } from './implementation/MongoPersistedSyncRulesContent.js';
|
|
5
|
+
import { MongoSyncBucketStorage } from './implementation/MongoSyncBucketStorage.js';
|
|
6
|
+
export declare class MongoBucketStorage extends DisposableObserver<storage.BucketStorageFactoryListener> implements storage.BucketStorageFactory {
|
|
7
|
+
private readonly client;
|
|
8
|
+
private readonly session;
|
|
9
|
+
readonly slot_name_prefix: string;
|
|
10
|
+
private readonly storageCache;
|
|
11
|
+
readonly db: PowerSyncMongo;
|
|
12
|
+
constructor(db: PowerSyncMongo, options: {
|
|
13
|
+
slot_name_prefix: string;
|
|
14
|
+
});
|
|
15
|
+
getInstance(options: storage.PersistedSyncRulesContent): MongoSyncBucketStorage;
|
|
16
|
+
configureSyncRules(sync_rules: string, options?: {
|
|
17
|
+
lock?: boolean;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
updated: boolean;
|
|
20
|
+
persisted_sync_rules?: undefined;
|
|
21
|
+
lock?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
updated: boolean;
|
|
24
|
+
persisted_sync_rules: MongoPersistedSyncRulesContent;
|
|
25
|
+
lock: import("./storage-index.js").MongoSyncRulesLock | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
slotRemoved(slot_name: string): Promise<void>;
|
|
28
|
+
updateSyncRules(options: storage.UpdateSyncRulesOptions): Promise<MongoPersistedSyncRulesContent>;
|
|
29
|
+
getActiveSyncRulesContent(): Promise<MongoPersistedSyncRulesContent | null>;
|
|
30
|
+
getActiveSyncRules(options: storage.ParseSyncRulesOptions): Promise<storage.PersistedSyncRules | null>;
|
|
31
|
+
getNextSyncRulesContent(): Promise<MongoPersistedSyncRulesContent | null>;
|
|
32
|
+
getNextSyncRules(options: storage.ParseSyncRulesOptions): Promise<storage.PersistedSyncRules | null>;
|
|
33
|
+
getReplicatingSyncRules(): Promise<storage.PersistedSyncRulesContent[]>;
|
|
34
|
+
getStoppedSyncRules(): Promise<storage.PersistedSyncRulesContent[]>;
|
|
35
|
+
getActiveCheckpoint(): Promise<storage.ActiveCheckpoint>;
|
|
36
|
+
getStorageMetrics(): Promise<storage.StorageMetrics>;
|
|
37
|
+
getPowerSyncInstanceId(): Promise<string>;
|
|
38
|
+
private makeActiveCheckpoint;
|
|
39
|
+
/**
|
|
40
|
+
* Instance-wide watch on the latest available checkpoint (op_id + lsn).
|
|
41
|
+
*/
|
|
42
|
+
private watchActiveCheckpoint;
|
|
43
|
+
private readonly sharedIter;
|
|
44
|
+
/**
|
|
45
|
+
* User-specific watch on the latest checkpoint and/or write checkpoint.
|
|
46
|
+
*/
|
|
47
|
+
watchWriteCheckpoint(user_id: string, signal: AbortSignal): AsyncIterable<storage.WriteCheckpoint>;
|
|
48
|
+
}
|