@powersync/service-module-mongodb-storage 0.1.0 → 0.2.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/migrations/mongo-migration-store.d.ts +2 -2
  3. package/dist/migrations/mongo-migration-store.js.map +1 -1
  4. package/dist/storage/MongoBucketStorage.js +1 -2
  5. package/dist/storage/MongoBucketStorage.js.map +1 -1
  6. package/dist/storage/implementation/MongoBucketBatch.d.ts +1 -1
  7. package/dist/storage/implementation/MongoBucketBatch.js +1 -1
  8. package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
  9. package/dist/storage/implementation/MongoCompactor.js +7 -7
  10. package/dist/storage/implementation/MongoCompactor.js.map +1 -1
  11. package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +1 -1
  12. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +1 -1
  13. package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +1 -1
  14. package/dist/storage/implementation/MongoSyncBucketStorage.js +2 -3
  15. package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
  16. package/dist/storage/implementation/PersistedBatch.d.ts +1 -1
  17. package/dist/storage/implementation/PersistedBatch.js.map +1 -1
  18. package/dist/storage/implementation/db.d.ts +1 -1
  19. package/dist/storage/implementation/db.js.map +1 -1
  20. package/dist/storage/implementation/util.d.ts +2 -2
  21. package/dist/storage/implementation/util.js +2 -2
  22. package/dist/storage/implementation/util.js.map +1 -1
  23. package/package.json +2 -3
  24. package/src/migrations/mongo-migration-store.ts +3 -2
  25. package/src/storage/MongoBucketStorage.ts +3 -2
  26. package/src/storage/implementation/MongoBucketBatch.ts +1 -1
  27. package/src/storage/implementation/MongoCompactor.ts +11 -10
  28. package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +1 -1
  29. package/src/storage/implementation/MongoSyncBucketStorage.ts +4 -5
  30. package/src/storage/implementation/PersistedBatch.ts +1 -1
  31. package/src/storage/implementation/db.ts +1 -1
  32. package/src/storage/implementation/util.ts +4 -2
  33. package/tsconfig.tsbuildinfo +1 -1
@@ -1,12 +1,13 @@
1
+ import { mongo } from '@powersync/lib-service-mongodb';
1
2
  import { migrations } from '@powersync/lib-services-framework';
2
- import { Db } from 'mongodb';
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';
@@ -285,7 +286,7 @@ export class MongoBucketStorage
285
286
 
286
287
  async getStorageMetrics(): Promise<storage.StorageMetrics> {
287
288
  const ignoreNotExiting = (e: unknown) => {
288
- if (e instanceof mongo.MongoServerError && e.codeName == 'NamespaceNotFound') {
289
+ if (lib_mongo.isMongoServerError(e) && e.codeName == 'NamespaceNotFound') {
289
290
  // Collection doesn't exist - return 0
290
291
  return [{ storageStats: { size: 0 } }];
291
292
  } 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
- import { AnyBulkWriteOperation, MaxKey, MinKey } from 'mongodb';
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';
@@ -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 instanceof mongo.MongoServerError && e.codeName == 'MaxTimeMSExpired') {
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