@powersync/service-module-mongodb-storage 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/migrations/mongo-migration-store.d.ts +2 -2
- package/dist/migrations/mongo-migration-store.js.map +1 -1
- package/dist/storage/MongoBucketStorage.d.ts +1 -0
- package/dist/storage/MongoBucketStorage.js +4 -3
- package/dist/storage/MongoBucketStorage.js.map +1 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +1 -1
- package/dist/storage/implementation/MongoBucketBatch.js +1 -1
- package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
- package/dist/storage/implementation/MongoCompactor.js +7 -7
- package/dist/storage/implementation/MongoCompactor.js.map +1 -1
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +1 -1
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/implementation/MongoStorageProvider.js +9 -5
- package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +1 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.js +2 -3
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
- package/dist/storage/implementation/PersistedBatch.d.ts +1 -1
- package/dist/storage/implementation/PersistedBatch.js.map +1 -1
- package/dist/storage/implementation/db.d.ts +1 -1
- package/dist/storage/implementation/db.js.map +1 -1
- package/dist/storage/implementation/util.d.ts +2 -2
- package/dist/storage/implementation/util.js +2 -2
- package/dist/storage/implementation/util.js.map +1 -1
- package/package.json +5 -6
- package/src/migrations/mongo-migration-store.ts +3 -2
- package/src/storage/MongoBucketStorage.ts +7 -3
- package/src/storage/implementation/MongoBucketBatch.ts +1 -1
- package/src/storage/implementation/MongoCompactor.ts +11 -10
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +1 -1
- package/src/storage/implementation/MongoStorageProvider.ts +9 -6
- package/src/storage/implementation/MongoSyncBucketStorage.ts +4 -5
- package/src/storage/implementation/PersistedBatch.ts +1 -1
- package/src/storage/implementation/db.ts +1 -1
- package/src/storage/implementation/util.ts +4 -2
- package/test/src/__snapshots__/storage.test.ts.snap +9 -0
- package/test/src/migrations.test.ts +10 -0
- package/test/src/setup.ts +5 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { storage, utils } from '@powersync/service-core';
|
|
2
1
|
import * as bson from 'bson';
|
|
3
|
-
import
|
|
2
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
3
|
+
import { storage, utils } from '@powersync/service-core';
|
|
4
4
|
import { PowerSyncMongo } from './db.js';
|
|
5
5
|
import { BucketDataDocument } from './models.js';
|
|
6
6
|
export declare function idPrefixFilter<T>(prefix: Partial<T>, rest: (keyof T)[]): mongo.Condition<T>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { storage, utils } from '@powersync/service-core';
|
|
2
1
|
import * as bson from 'bson';
|
|
3
2
|
import * as crypto from 'crypto';
|
|
4
|
-
import * as mongo from 'mongodb';
|
|
5
3
|
import * as uuid from 'uuid';
|
|
4
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
5
|
+
import { storage, utils } from '@powersync/service-core';
|
|
6
6
|
import { PowerSyncMongo } from './db.js';
|
|
7
7
|
export function idPrefixFilter(prefix, rest) {
|
|
8
8
|
let filter = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/storage/implementation/util.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/storage/implementation/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OA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AAM,OAAO,GAAG,CAAC,CAAC;IAClB,KAAK,IAAI,EAAE,IAAI,UAAU,EAAE,CAAC;QAC1B,MAAM,QAAQ,GACZ,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE,EAAE;YACjC,SAAS,EAAE,KAAK;YAChB,eAAe,EAAE,IAAI;SACf,CAAC,GAAG,OAAO,CAAC;QACtB,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,GAAG,QAAQ,GAAG,gBAAgB,EAAE,CAAC;YAClE,MAAM,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC3C,WAAW,GAAG,CAAC,CAAC;YAChB,KAAK,GAAG,EAAE,CAAC;QACb,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,WAAW,IAAI,QAAQ,CAAC;IAC1B,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@powersync/service-module-mongodb-storage",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.3.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"license": "FSL-1.1-Apache-2.0",
|
|
8
8
|
"type": "module",
|
|
@@ -22,22 +22,21 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"mongodb": "^6.11.0",
|
|
26
25
|
"bson": "^6.8.0",
|
|
27
26
|
"ts-codec": "^1.3.0",
|
|
28
27
|
"ix": "^5.0.0",
|
|
29
28
|
"lru-cache": "^10.2.2",
|
|
30
29
|
"uuid": "^9.0.1",
|
|
31
|
-
"@powersync/lib-services-framework": "0.
|
|
32
|
-
"@powersync/service-core": "0.
|
|
30
|
+
"@powersync/lib-services-framework": "0.4.0",
|
|
31
|
+
"@powersync/service-core": "0.15.0",
|
|
33
32
|
"@powersync/service-jsonbig": "0.17.10",
|
|
34
33
|
"@powersync/service-sync-rules": "0.23.1",
|
|
35
34
|
"@powersync/service-types": "0.7.0",
|
|
36
|
-
"@powersync/lib-service-mongodb": "0.
|
|
35
|
+
"@powersync/lib-service-mongodb": "0.3.1"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"@types/uuid": "^9.0.4",
|
|
40
|
-
"@powersync/service-core-tests": "0.
|
|
39
|
+
"@powersync/service-core-tests": "0.3.0"
|
|
41
40
|
},
|
|
42
41
|
"scripts": {
|
|
43
42
|
"build": "tsc -b",
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
1
2
|
import { migrations } from '@powersync/lib-services-framework';
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import * as path from 'path';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A custom store for node-migrate which is used to save and load migrations that have
|
|
7
8
|
* been operated on to mongo.
|
|
8
9
|
*/
|
|
9
|
-
export const createMongoMigrationStore = (db: Db): migrations.MigrationStore => {
|
|
10
|
+
export const createMongoMigrationStore = (db: mongo.Db): migrations.MigrationStore => {
|
|
10
11
|
const collection = db.collection<migrations.MigrationState>('migrations');
|
|
11
12
|
|
|
12
13
|
return {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SqlSyncRules } from '@powersync/service-sync-rules';
|
|
2
2
|
import { wrapWithAbort } from 'ix/asynciterable/operators/withabort.js';
|
|
3
3
|
import { LRUCache } from 'lru-cache/min';
|
|
4
|
-
import * as mongo from 'mongodb';
|
|
5
4
|
import * as timers from 'timers/promises';
|
|
6
5
|
|
|
7
6
|
import { storage, sync, utils } from '@powersync/service-core';
|
|
@@ -10,6 +9,8 @@ import { DisposableObserver, logger } from '@powersync/lib-services-framework';
|
|
|
10
9
|
import { v4 as uuid } from 'uuid';
|
|
11
10
|
|
|
12
11
|
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
12
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
13
|
+
|
|
13
14
|
import { PowerSyncMongo } from './implementation/db.js';
|
|
14
15
|
import { SyncRuleDocument } from './implementation/models.js';
|
|
15
16
|
import { MongoPersistedSyncRulesContent } from './implementation/MongoPersistedSyncRulesContent.js';
|
|
@@ -61,6 +62,10 @@ export class MongoBucketStorage
|
|
|
61
62
|
this.slot_name_prefix = options.slot_name_prefix;
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
async [Symbol.asyncDispose]() {
|
|
66
|
+
super[Symbol.dispose]();
|
|
67
|
+
}
|
|
68
|
+
|
|
64
69
|
getInstance(options: storage.PersistedSyncRulesContent): MongoSyncBucketStorage {
|
|
65
70
|
let { id, slot_name } = options;
|
|
66
71
|
if ((typeof id as any) == 'bigint') {
|
|
@@ -105,7 +110,6 @@ export class MongoBucketStorage
|
|
|
105
110
|
|
|
106
111
|
// In both the below cases, we create a new sync rules instance.
|
|
107
112
|
// The current one will continue erroring until the next one has finished processing.
|
|
108
|
-
// TODO: Update
|
|
109
113
|
if (next != null && next.slot_name == slot_name) {
|
|
110
114
|
// We need to redo the "next" sync rules
|
|
111
115
|
await this.updateSyncRules({
|
|
@@ -285,7 +289,7 @@ export class MongoBucketStorage
|
|
|
285
289
|
|
|
286
290
|
async getStorageMetrics(): Promise<storage.StorageMetrics> {
|
|
287
291
|
const ignoreNotExiting = (e: unknown) => {
|
|
288
|
-
if (e
|
|
292
|
+
if (lib_mongo.isMongoServerError(e) && e.codeName == 'NamespaceNotFound') {
|
|
289
293
|
// Collection doesn't exist - return 0
|
|
290
294
|
return [{ storageStats: { size: 0 } }];
|
|
291
295
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
1
2
|
import { SqlEventDescriptor, SqliteRow, SqlSyncRules } from '@powersync/service-sync-rules';
|
|
2
3
|
import * as bson from 'bson';
|
|
3
|
-
import * as mongo from 'mongodb';
|
|
4
4
|
|
|
5
5
|
import { container, DisposableObserver, errors, logger } from '@powersync/lib-services-framework';
|
|
6
6
|
import { SaveOperationTag, storage, utils } from '@powersync/service-core';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
1
2
|
import { logger } from '@powersync/lib-services-framework';
|
|
2
3
|
import { storage, utils } from '@powersync/service-core';
|
|
3
|
-
|
|
4
|
+
|
|
4
5
|
import { PowerSyncMongo } from './db.js';
|
|
5
6
|
import { BucketDataDocument, BucketDataKey } from './models.js';
|
|
6
7
|
import { cacheKey } from './OperationBatch.js';
|
|
@@ -49,7 +50,7 @@ const DEFAULT_MOVE_BATCH_QUERY_LIMIT = 10_000;
|
|
|
49
50
|
const DEFAULT_MEMORY_LIMIT_MB = 64;
|
|
50
51
|
|
|
51
52
|
export class MongoCompactor {
|
|
52
|
-
private updates: AnyBulkWriteOperation<BucketDataDocument>[] = [];
|
|
53
|
+
private updates: mongo.AnyBulkWriteOperation<BucketDataDocument>[] = [];
|
|
53
54
|
|
|
54
55
|
private idLimitBytes: number;
|
|
55
56
|
private moveBatchLimit: number;
|
|
@@ -94,12 +95,12 @@ export class MongoCompactor {
|
|
|
94
95
|
|
|
95
96
|
let currentState: CurrentBucketState | null = null;
|
|
96
97
|
|
|
97
|
-
let bucketLower: string | MinKey;
|
|
98
|
-
let bucketUpper: string | MaxKey;
|
|
98
|
+
let bucketLower: string | mongo.MinKey;
|
|
99
|
+
let bucketUpper: string | mongo.MaxKey;
|
|
99
100
|
|
|
100
101
|
if (bucket == null) {
|
|
101
|
-
bucketLower = new MinKey();
|
|
102
|
-
bucketUpper = new MaxKey();
|
|
102
|
+
bucketLower = new mongo.MinKey();
|
|
103
|
+
bucketUpper = new mongo.MaxKey();
|
|
103
104
|
} else if (bucket.includes('[')) {
|
|
104
105
|
// Exact bucket name
|
|
105
106
|
bucketLower = bucket;
|
|
@@ -114,14 +115,14 @@ export class MongoCompactor {
|
|
|
114
115
|
const lowerBound: BucketDataKey = {
|
|
115
116
|
g: this.group_id,
|
|
116
117
|
b: bucketLower as string,
|
|
117
|
-
o: new MinKey() as any
|
|
118
|
+
o: new mongo.MinKey() as any
|
|
118
119
|
};
|
|
119
120
|
|
|
120
121
|
// Upper bound is adjusted for each batch
|
|
121
122
|
let upperBound: BucketDataKey = {
|
|
122
123
|
g: this.group_id,
|
|
123
124
|
b: bucketUpper as string,
|
|
124
|
-
o: new MaxKey() as any
|
|
125
|
+
o: new mongo.MaxKey() as any
|
|
125
126
|
};
|
|
126
127
|
|
|
127
128
|
while (true) {
|
|
@@ -287,7 +288,7 @@ export class MongoCompactor {
|
|
|
287
288
|
$gte: {
|
|
288
289
|
g: this.group_id,
|
|
289
290
|
b: bucket,
|
|
290
|
-
o: new MinKey() as any
|
|
291
|
+
o: new mongo.MinKey() as any
|
|
291
292
|
},
|
|
292
293
|
$lte: {
|
|
293
294
|
g: this.group_id,
|
|
@@ -349,7 +350,7 @@ export class MongoCompactor {
|
|
|
349
350
|
$gte: {
|
|
350
351
|
g: this.group_id,
|
|
351
352
|
b: bucket,
|
|
352
|
-
o: new MinKey() as any
|
|
353
|
+
o: new mongo.MinKey() as any
|
|
353
354
|
},
|
|
354
355
|
$lte: lastOpId!
|
|
355
356
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
1
2
|
import { storage } from '@powersync/service-core';
|
|
2
3
|
import { SqlSyncRules } from '@powersync/service-sync-rules';
|
|
3
|
-
import * as mongo from 'mongodb';
|
|
4
4
|
import { MongoPersistedSyncRules } from './MongoPersistedSyncRules.js';
|
|
5
5
|
import { MongoSyncRulesLock } from './MongoSyncRulesLock.js';
|
|
6
6
|
import { PowerSyncMongo } from './db.js';
|
|
@@ -23,13 +23,16 @@ export class MongoStorageProvider implements storage.BucketStorageProvider {
|
|
|
23
23
|
const client = lib_mongo.db.createMongoClient(decodedConfig);
|
|
24
24
|
|
|
25
25
|
const database = new PowerSyncMongo(client, { database: resolvedConfig.storage.database });
|
|
26
|
-
|
|
26
|
+
const factory = new MongoBucketStorage(database, {
|
|
27
|
+
// TODO currently need the entire resolved config due to this
|
|
28
|
+
slot_name_prefix: resolvedConfig.slot_name_prefix
|
|
29
|
+
});
|
|
27
30
|
return {
|
|
28
|
-
storage:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
storage: factory,
|
|
32
|
+
shutDown: async () => {
|
|
33
|
+
await factory[Symbol.asyncDispose]();
|
|
34
|
+
await client.close();
|
|
35
|
+
},
|
|
33
36
|
tearDown: () => {
|
|
34
37
|
logger.info(`Tearing down storage: ${database.db.namespace}...`);
|
|
35
38
|
return database.db.dropDatabase();
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { SqliteJsonRow, SqliteJsonValue, SqlSyncRules } from '@powersync/service-sync-rules';
|
|
2
|
-
import * as bson from 'bson';
|
|
3
|
-
import * as mongo from 'mongodb';
|
|
4
|
-
|
|
5
1
|
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
6
3
|
import { DisposableObserver, logger } from '@powersync/lib-services-framework';
|
|
7
4
|
import { storage, utils } from '@powersync/service-core';
|
|
5
|
+
import { SqliteJsonRow, SqliteJsonValue, SqlSyncRules } from '@powersync/service-sync-rules';
|
|
6
|
+
import * as bson from 'bson';
|
|
8
7
|
import * as timers from 'timers/promises';
|
|
9
8
|
import { MongoBucketStorage } from '../MongoBucketStorage.js';
|
|
10
9
|
import { PowerSyncMongo } from './db.js';
|
|
@@ -498,7 +497,7 @@ export class MongoSyncBucketStorage
|
|
|
498
497
|
logger.info(`${this.slot_name} Done clearing data`);
|
|
499
498
|
return;
|
|
500
499
|
} catch (e: unknown) {
|
|
501
|
-
if (e
|
|
500
|
+
if (lib_mongo.isMongoServerError(e) && e.codeName == 'MaxTimeMSExpired') {
|
|
502
501
|
logger.info(
|
|
503
502
|
`${this.slot_name} Cleared batch of data in ${lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS}ms, continuing...`
|
|
504
503
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
1
2
|
import { JSONBig } from '@powersync/service-jsonbig';
|
|
2
3
|
import { EvaluatedParameters, EvaluatedRow } from '@powersync/service-sync-rules';
|
|
3
4
|
import * as bson from 'bson';
|
|
4
|
-
import * as mongo from 'mongodb';
|
|
5
5
|
|
|
6
6
|
import { logger } from '@powersync/lib-services-framework';
|
|
7
7
|
import { storage, utils } from '@powersync/service-core';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as lib_mongo from '@powersync/lib-service-mongodb';
|
|
2
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
2
3
|
import { storage } from '@powersync/service-core';
|
|
3
|
-
import * as mongo from 'mongodb';
|
|
4
4
|
|
|
5
5
|
import { MongoStorageConfig } from '../../types/types.js';
|
|
6
6
|
import {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { storage, utils } from '@powersync/service-core';
|
|
2
1
|
import * as bson from 'bson';
|
|
3
2
|
import * as crypto from 'crypto';
|
|
4
|
-
import * as mongo from 'mongodb';
|
|
5
3
|
import * as uuid from 'uuid';
|
|
4
|
+
|
|
5
|
+
import { mongo } from '@powersync/lib-service-mongodb';
|
|
6
|
+
import { storage, utils } from '@powersync/service-core';
|
|
7
|
+
|
|
6
8
|
import { PowerSyncMongo } from './db.js';
|
|
7
9
|
import { BucketDataDocument } from './models.js';
|
|
8
10
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { register } from '@powersync/service-core-tests';
|
|
2
|
+
import { describe } from 'vitest';
|
|
3
|
+
import { MongoMigrationAgent } from '../../src/migrations/MongoMigrationAgent.js';
|
|
4
|
+
import { env } from './env.js';
|
|
5
|
+
|
|
6
|
+
const MIGRATION_AGENT_FACTORY = () => {
|
|
7
|
+
return new MongoMigrationAgent({ type: 'mongodb', uri: env.MONGO_TEST_URL });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
describe('Mongo Migrations Store', () => register.registerMigrationTests(MIGRATION_AGENT_FACTORY));
|
package/test/src/setup.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { container } from '@powersync/lib-services-framework';
|
|
2
2
|
import { test_utils } from '@powersync/service-core-tests';
|
|
3
|
-
import { beforeAll } from 'vitest';
|
|
3
|
+
import { beforeAll, beforeEach } from 'vitest';
|
|
4
4
|
|
|
5
5
|
beforeAll(async () => {
|
|
6
6
|
// Executes for every test file
|
|
7
7
|
container.registerDefaults();
|
|
8
8
|
await test_utils.initMetrics();
|
|
9
9
|
});
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
await test_utils.resetMetrics();
|
|
13
|
+
});
|