@powersync/service-module-mongodb 0.0.0-dev-20250102111825 → 0.0.0-dev-20250108084515
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 +8 -5
- package/dist/api/MongoRouteAPIAdapter.d.ts +1 -1
- package/dist/api/MongoRouteAPIAdapter.js +4 -3
- package/dist/api/MongoRouteAPIAdapter.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/module/MongoModule.d.ts +0 -1
- package/dist/module/MongoModule.js +2 -10
- package/dist/module/MongoModule.js.map +1 -1
- package/dist/replication/MongoRelation.js +15 -5
- package/dist/replication/MongoRelation.js.map +1 -1
- package/dist/types/types.d.ts +16 -22
- package/dist/types/types.js +4 -24
- package/dist/types/types.js.map +1 -1
- package/package.json +9 -10
- package/src/api/MongoRouteAPIAdapter.ts +4 -4
- package/src/index.ts +3 -4
- package/src/module/MongoModule.ts +2 -14
- package/src/replication/MongoRelation.ts +13 -5
- package/src/types/types.ts +8 -34
- package/test/src/change_stream.test.ts +2 -4
- package/test/src/env.ts +1 -1
- package/test/src/mongo_test.test.ts +69 -10
- package/test/src/setup.ts +4 -1
- package/test/src/slow_tests.test.ts +5 -12
- package/test/src/util.ts +5 -38
- package/test/tsconfig.json +1 -2
- package/tsconfig.json +6 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/db/db-index.d.ts +0 -1
- package/dist/db/db-index.js +0 -2
- package/dist/db/db-index.js.map +0 -1
- package/dist/db/mongo.d.ts +0 -35
- package/dist/db/mongo.js +0 -73
- package/dist/db/mongo.js.map +0 -1
- package/dist/locks/MongoLockManager.d.ts +0 -25
- package/dist/locks/MongoLockManager.js +0 -79
- package/dist/locks/MongoLockManager.js.map +0 -1
- package/dist/migrations/MongoMigrationAgent.d.ts +0 -12
- package/dist/migrations/MongoMigrationAgent.js +0 -25
- package/dist/migrations/MongoMigrationAgent.js.map +0 -1
- package/dist/migrations/db/migrations/1684951997326-init.d.ts +0 -3
- package/dist/migrations/db/migrations/1684951997326-init.js +0 -30
- package/dist/migrations/db/migrations/1684951997326-init.js.map +0 -1
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +0 -2
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +0 -5
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +0 -1
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +0 -3
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +0 -54
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +0 -1
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +0 -3
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +0 -26
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +0 -1
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.d.ts +0 -3
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js +0 -28
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js.map +0 -1
- package/dist/migrations/mongo-migration-store.d.ts +0 -7
- package/dist/migrations/mongo-migration-store.js +0 -49
- package/dist/migrations/mongo-migration-store.js.map +0 -1
- package/dist/storage/MongoBucketStorage.d.ts +0 -48
- package/dist/storage/MongoBucketStorage.js +0 -426
- package/dist/storage/MongoBucketStorage.js.map +0 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +0 -72
- package/dist/storage/implementation/MongoBucketBatch.js +0 -681
- package/dist/storage/implementation/MongoBucketBatch.js.map +0 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +0 -40
- package/dist/storage/implementation/MongoCompactor.js +0 -300
- package/dist/storage/implementation/MongoCompactor.js.map +0 -1
- package/dist/storage/implementation/MongoIdSequence.d.ts +0 -12
- package/dist/storage/implementation/MongoIdSequence.js +0 -21
- package/dist/storage/implementation/MongoIdSequence.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -9
- package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -9
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -20
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -26
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
- package/dist/storage/implementation/MongoStorageProvider.d.ts +0 -6
- package/dist/storage/implementation/MongoStorageProvider.js +0 -34
- package/dist/storage/implementation/MongoStorageProvider.js.map +0 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +0 -36
- package/dist/storage/implementation/MongoSyncBucketStorage.js +0 -529
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +0 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +0 -16
- package/dist/storage/implementation/MongoSyncRulesLock.js +0 -65
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +0 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +0 -20
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +0 -104
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +0 -1
- package/dist/storage/implementation/OperationBatch.d.ts +0 -34
- package/dist/storage/implementation/OperationBatch.js +0 -119
- package/dist/storage/implementation/OperationBatch.js.map +0 -1
- package/dist/storage/implementation/PersistedBatch.d.ts +0 -46
- package/dist/storage/implementation/PersistedBatch.js +0 -223
- package/dist/storage/implementation/PersistedBatch.js.map +0 -1
- package/dist/storage/implementation/config.d.ts +0 -19
- package/dist/storage/implementation/config.js +0 -26
- package/dist/storage/implementation/config.js.map +0 -1
- package/dist/storage/implementation/db.d.ts +0 -36
- package/dist/storage/implementation/db.js +0 -47
- package/dist/storage/implementation/db.js.map +0 -1
- package/dist/storage/implementation/models.d.ts +0 -139
- package/dist/storage/implementation/models.js +0 -2
- package/dist/storage/implementation/models.js.map +0 -1
- package/dist/storage/implementation/util.d.ts +0 -41
- package/dist/storage/implementation/util.js +0 -141
- package/dist/storage/implementation/util.js.map +0 -1
- package/dist/storage/storage-index.d.ts +0 -14
- package/dist/storage/storage-index.js +0 -15
- package/dist/storage/storage-index.js.map +0 -1
- package/src/db/db-index.ts +0 -1
- package/src/db/mongo.ts +0 -81
- package/src/locks/MongoLockManager.ts +0 -123
- package/src/migrations/MongoMigrationAgent.ts +0 -39
- package/src/migrations/db/migrations/1684951997326-init.ts +0 -39
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +0 -5
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +0 -105
- package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +0 -38
- package/src/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.ts +0 -40
- package/src/migrations/mongo-migration-store.ts +0 -62
- package/src/storage/MongoBucketStorage.ts +0 -531
- package/src/storage/implementation/MongoBucketBatch.ts +0 -896
- package/src/storage/implementation/MongoCompactor.ts +0 -381
- package/src/storage/implementation/MongoIdSequence.ts +0 -24
- package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -16
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -49
- package/src/storage/implementation/MongoStorageProvider.ts +0 -42
- package/src/storage/implementation/MongoSyncBucketStorage.ts +0 -612
- package/src/storage/implementation/MongoSyncRulesLock.ts +0 -88
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +0 -146
- package/src/storage/implementation/OperationBatch.ts +0 -129
- package/src/storage/implementation/PersistedBatch.ts +0 -283
- package/src/storage/implementation/config.ts +0 -40
- package/src/storage/implementation/db.ts +0 -87
- package/src/storage/implementation/models.ts +0 -161
- package/src/storage/implementation/util.ts +0 -154
- package/src/storage/storage-index.ts +0 -14
- package/test/src/__snapshots__/storage_sync.test.ts.snap +0 -332
- package/test/src/storage.test.ts +0 -7
- package/test/src/storage_compacting.test.ts +0 -6
- package/test/src/storage_sync.test.ts +0 -113
package/dist/db/db-index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as mongo from './mongo.js';
|
package/dist/db/db-index.js
DELETED
package/dist/db/db-index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-index.js","sourceRoot":"","sources":["../../src/db/db-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC"}
|
package/dist/db/mongo.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as mongo from 'mongodb';
|
|
2
|
-
import { configFile } from '@powersync/service-types';
|
|
3
|
-
/**
|
|
4
|
-
* Time for new connection to timeout.
|
|
5
|
-
*/
|
|
6
|
-
export declare const MONGO_CONNECT_TIMEOUT_MS = 10000;
|
|
7
|
-
/**
|
|
8
|
-
* Time for individual requests to timeout the socket.
|
|
9
|
-
*/
|
|
10
|
-
export declare const MONGO_SOCKET_TIMEOUT_MS = 60000;
|
|
11
|
-
/**
|
|
12
|
-
* Time for individual requests to timeout the operation.
|
|
13
|
-
*
|
|
14
|
-
* This is time spent on the cursor, not total time.
|
|
15
|
-
*
|
|
16
|
-
* Must be less than MONGO_SOCKET_TIMEOUT_MS to ensure proper error handling.
|
|
17
|
-
*/
|
|
18
|
-
export declare const MONGO_OPERATION_TIMEOUT_MS = 30000;
|
|
19
|
-
/**
|
|
20
|
-
* Same as above, but specifically for clear operations.
|
|
21
|
-
*
|
|
22
|
-
* These are retried when reaching the timeout.
|
|
23
|
-
*/
|
|
24
|
-
export declare const MONGO_CLEAR_OPERATION_TIMEOUT_MS = 5000;
|
|
25
|
-
export declare function createMongoClient(config: configFile.MongoStorageConfig): mongo.MongoClient;
|
|
26
|
-
/**
|
|
27
|
-
* Wait up to a minute for authentication errors to resolve.
|
|
28
|
-
*
|
|
29
|
-
* There can be a delay between an Atlas user being created, and that user being
|
|
30
|
-
* available on the database cluster. This works around it.
|
|
31
|
-
*
|
|
32
|
-
* This is specifically relevant for migrations and teardown - other parts of the stack
|
|
33
|
-
* can generate handle these failures and just retry or restart.
|
|
34
|
-
*/
|
|
35
|
-
export declare function waitForAuth(db: mongo.Db): Promise<void>;
|
package/dist/db/mongo.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import * as mongo from 'mongodb';
|
|
2
|
-
import * as timers from 'timers/promises';
|
|
3
|
-
import { normalizeMongoConfig } from '../storage/storage-index.js';
|
|
4
|
-
/**
|
|
5
|
-
* Time for new connection to timeout.
|
|
6
|
-
*/
|
|
7
|
-
export const MONGO_CONNECT_TIMEOUT_MS = 10000;
|
|
8
|
-
/**
|
|
9
|
-
* Time for individual requests to timeout the socket.
|
|
10
|
-
*/
|
|
11
|
-
export const MONGO_SOCKET_TIMEOUT_MS = 60000;
|
|
12
|
-
/**
|
|
13
|
-
* Time for individual requests to timeout the operation.
|
|
14
|
-
*
|
|
15
|
-
* This is time spent on the cursor, not total time.
|
|
16
|
-
*
|
|
17
|
-
* Must be less than MONGO_SOCKET_TIMEOUT_MS to ensure proper error handling.
|
|
18
|
-
*/
|
|
19
|
-
export const MONGO_OPERATION_TIMEOUT_MS = 30000;
|
|
20
|
-
/**
|
|
21
|
-
* Same as above, but specifically for clear operations.
|
|
22
|
-
*
|
|
23
|
-
* These are retried when reaching the timeout.
|
|
24
|
-
*/
|
|
25
|
-
export const MONGO_CLEAR_OPERATION_TIMEOUT_MS = 5000;
|
|
26
|
-
export function createMongoClient(config) {
|
|
27
|
-
const normalized = normalizeMongoConfig(config);
|
|
28
|
-
return new mongo.MongoClient(normalized.uri, {
|
|
29
|
-
auth: {
|
|
30
|
-
username: normalized.username,
|
|
31
|
-
password: normalized.password
|
|
32
|
-
},
|
|
33
|
-
// Time for connection to timeout
|
|
34
|
-
connectTimeoutMS: MONGO_CONNECT_TIMEOUT_MS,
|
|
35
|
-
// Time for individual requests to timeout
|
|
36
|
-
socketTimeoutMS: MONGO_SOCKET_TIMEOUT_MS,
|
|
37
|
-
// How long to wait for new primary selection
|
|
38
|
-
serverSelectionTimeoutMS: 30000,
|
|
39
|
-
// Avoid too many connections:
|
|
40
|
-
// 1. It can overwhelm the source database.
|
|
41
|
-
// 2. Processing too many queries in parallel can cause the process to run out of memory.
|
|
42
|
-
maxPoolSize: 8,
|
|
43
|
-
maxConnecting: 3,
|
|
44
|
-
maxIdleTimeMS: 60000
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Wait up to a minute for authentication errors to resolve.
|
|
49
|
-
*
|
|
50
|
-
* There can be a delay between an Atlas user being created, and that user being
|
|
51
|
-
* available on the database cluster. This works around it.
|
|
52
|
-
*
|
|
53
|
-
* This is specifically relevant for migrations and teardown - other parts of the stack
|
|
54
|
-
* can generate handle these failures and just retry or restart.
|
|
55
|
-
*/
|
|
56
|
-
export async function waitForAuth(db) {
|
|
57
|
-
const start = Date.now();
|
|
58
|
-
while (Date.now() - start < 60000) {
|
|
59
|
-
try {
|
|
60
|
-
await db.command({ ping: 1 });
|
|
61
|
-
// Success
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
if (e.codeName == 'AuthenticationFailed') {
|
|
66
|
-
await timers.setTimeout(1000);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
throw e;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=mongo.js.map
|
package/dist/db/mongo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongo.js","sourceRoot":"","sources":["../../src/db/mongo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,iBAAiB,CAAC;AAG1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAM,CAAC;AAE/C;;GAEG;AACH,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AAC;QACV,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as framework from '@powersync/lib-services-framework';
|
|
2
|
-
import * as bson from 'bson';
|
|
3
|
-
import * as mongo from 'mongodb';
|
|
4
|
-
/**
|
|
5
|
-
* Lock Document Schema
|
|
6
|
-
*/
|
|
7
|
-
export type Lock = {
|
|
8
|
-
name: string;
|
|
9
|
-
active_lock?: {
|
|
10
|
-
lock_id: bson.ObjectId;
|
|
11
|
-
ts: Date;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export type Collection = mongo.Collection<Lock>;
|
|
15
|
-
export type MongoLockManagerParams = framework.locks.LockManagerParams & {
|
|
16
|
-
collection: Collection;
|
|
17
|
-
};
|
|
18
|
-
export declare class MongoLockManager extends framework.locks.AbstractLockManager {
|
|
19
|
-
collection: Collection;
|
|
20
|
-
constructor(params: MongoLockManagerParams);
|
|
21
|
-
protected acquireHandle(options?: framework.LockAcquireOptions): Promise<framework.LockHandle | null>;
|
|
22
|
-
protected refreshHandle(lock_id: bson.ObjectId): Promise<void>;
|
|
23
|
-
protected getHandle(): Promise<bson.ObjectId | null>;
|
|
24
|
-
protected releaseHandle(lock_id: bson.ObjectId): Promise<void>;
|
|
25
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import * as framework from '@powersync/lib-services-framework';
|
|
2
|
-
import * as bson from 'bson';
|
|
3
|
-
const DEFAULT_LOCK_TIMEOUT = 60 * 1000; // 1 minute
|
|
4
|
-
export class MongoLockManager extends framework.locks.AbstractLockManager {
|
|
5
|
-
constructor(params) {
|
|
6
|
-
super(params);
|
|
7
|
-
this.collection = params.collection;
|
|
8
|
-
}
|
|
9
|
-
async acquireHandle(options) {
|
|
10
|
-
const lock_id = await this.getHandle();
|
|
11
|
-
if (!lock_id) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
refresh: () => this.refreshHandle(lock_id),
|
|
16
|
-
release: () => this.releaseHandle(lock_id)
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
async refreshHandle(lock_id) {
|
|
20
|
-
const res = await this.collection.updateOne({
|
|
21
|
-
'active_lock.lock_id': lock_id
|
|
22
|
-
}, {
|
|
23
|
-
$set: {
|
|
24
|
-
'active_lock.ts': new Date()
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
if (res.modifiedCount === 0) {
|
|
28
|
-
throw new Error('Lock not found, could not refresh');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async getHandle() {
|
|
32
|
-
const now = new Date();
|
|
33
|
-
const lock_timeout = this.params.timeout ?? DEFAULT_LOCK_TIMEOUT;
|
|
34
|
-
const lock_id = new bson.ObjectId();
|
|
35
|
-
const { name } = this.params;
|
|
36
|
-
await this.collection.updateOne({
|
|
37
|
-
name
|
|
38
|
-
}, {
|
|
39
|
-
$setOnInsert: {
|
|
40
|
-
name
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
upsert: true
|
|
44
|
-
});
|
|
45
|
-
const expired_ts = now.getTime() - lock_timeout;
|
|
46
|
-
const res = await this.collection.updateOne({
|
|
47
|
-
$and: [
|
|
48
|
-
{ name: name },
|
|
49
|
-
{
|
|
50
|
-
$or: [{ active_lock: { $exists: false } }, { 'active_lock.ts': { $lte: new Date(expired_ts) } }]
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
}, {
|
|
54
|
-
$set: {
|
|
55
|
-
active_lock: {
|
|
56
|
-
lock_id: lock_id,
|
|
57
|
-
ts: now
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
if (res.modifiedCount === 0) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
return lock_id;
|
|
65
|
-
}
|
|
66
|
-
async releaseHandle(lock_id) {
|
|
67
|
-
const res = await this.collection.updateOne({
|
|
68
|
-
'active_lock.lock_id': lock_id
|
|
69
|
-
}, {
|
|
70
|
-
$unset: {
|
|
71
|
-
active_lock: true
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
if (res.modifiedCount === 0) {
|
|
75
|
-
throw new Error('Lock not found, could not release');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=MongoLockManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MongoLockManager.js","sourceRoot":"","sources":["../../src/locks/MongoLockManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAC/D,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAoB7B,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,WAAW;AAEnD,MAAM,OAAO,gBAAiB,SAAQ,SAAS,CAAC,KAAK,CAAC,mBAAmB;IAEvE,YAAY,MAA8B;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACtC,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,OAAsC;QAClE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACvC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO;YACL,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAC1C,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;SAC3C,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,OAAsB;QAClD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CACzC;YACE,qBAAqB,EAAE,OAAO;SAC/B,EACD;YACE,IAAI,EAAE;gBACJ,gBAAgB,EAAE,IAAI,IAAI,EAAE;aAC7B;SACF,CACF,CAAC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AG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CACzC;YACE,qBAAqB,EAAE,OAAO;SAC/B,EACD;YACE,MAAM,EAAE;gBACN,WAAW,EAAE,IAAI;aAClB;SACF,CACF,CAAC;QAEF,IAAI,GAAG,CAAC,aAAa,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as framework from '@powersync/lib-services-framework';
|
|
2
|
-
import { migrations } from '@powersync/service-core';
|
|
3
|
-
import { configFile } from '@powersync/service-types';
|
|
4
|
-
import { PowerSyncMongo } from '../storage/storage-index.js';
|
|
5
|
-
export declare class MongoMigrationAgent extends migrations.AbstractPowerSyncMigrationAgent {
|
|
6
|
-
store: framework.MigrationStore;
|
|
7
|
-
locks: framework.LockManager;
|
|
8
|
-
protected client: PowerSyncMongo;
|
|
9
|
-
constructor(mongoConfig: configFile.MongoStorageConfig);
|
|
10
|
-
getInternalScriptsDir(): string;
|
|
11
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { migrations } from '@powersync/service-core';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { MongoLockManager } from '../locks/MongoLockManager.js';
|
|
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 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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MongoMigrationAgent.js","sourceRoot":"","sources":["../../src/migrations/MongoMigrationAgent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAkB,MAAM,6BAA6B,CAAC;AACnF,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,WAA0C;QACpD,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,gBAAgB,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACjG,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"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as mongo from '../../../db/mongo.js';
|
|
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 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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3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EAAE,CAAC;IAChC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { storage as core_storage } from '@powersync/service-core';
|
|
2
|
-
import * as mongo from '../../../db/mongo.js';
|
|
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 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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"1702295701188-sync-rule-state.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1702295701188-sync-rule-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAc,MAAM,yBAAyB,CAAC;AAE9E,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,mCAAmC,CAAC;AAuB7D,MAAM,CAAC,MAAM,EAAE,GAA0C,KAAK,EAAE,OAAO,EAAE,E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EAAE,KAAK,EAAE,EAAE,CACtE,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"1711543888062-write-checkpoint-index.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,mCAAmC,CAAC;AAE7D,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,OAAwC,CAAC,CAAC;IAEhG,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,OAAwC,CAAC,CAAC;IAEhG,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"}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"1727099539247-custom-write-checkpoint-index.js","sourceRoot":"","sources":["../../../../src/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,mCAAmC,CAAC;AAE7D,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,OAAwC,CAAC,CAAC;IAEhG,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,OAAwC,CAAC,CAAC;IAEhG,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"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
}
|