liwi-mongo 8.3.1 → 9.1.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/.eslintrc.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "root": true,
3
- "extends": ["@pob/eslint-config/root", "@pob/eslint-config-node"],
3
+ "extends": ["@pob/eslint-config/root-module"],
4
4
  "ignorePatterns": ["*.d.ts", "/dist"]
5
5
  }
package/CHANGELOG.md CHANGED
@@ -3,6 +3,41 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [9.1.0](https://github.com/liwijs/liwi/compare/v9.0.0...v9.1.0) (2022-10-08)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * redact connectionString in logs ([236ecb2](https://github.com/liwijs/liwi/commit/236ecb2b812c4d48ae0028b91e93528ddc899f1b))
12
+ * update dev dependencies, fix ts remix, fix next babel config ([fadb30e](https://github.com/liwijs/liwi/commit/fadb30e9620fbbcb99cfbc6a7db78d9ef2dad5e2))
13
+
14
+
15
+
16
+
17
+
18
+ # [9.0.0](https://github.com/liwijs/liwi/compare/v8.3.1...v9.0.0) (2022-03-05)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * update meta when params change ([7c260a8](https://github.com/liwijs/liwi/commit/7c260a84cc8daae0113fbbf30f5a9e7ca921ee3e))
24
+
25
+
26
+ ### Features
27
+
28
+ * **deps:** update dependency mongodb to v4 ([#22](https://github.com/liwijs/liwi/issues/22)) ([cdf9204](https://github.com/liwijs/liwi/commit/cdf920461156e5dd6dceaf5bf26b24c206385634))
29
+ * refactor and use node 14 ([101c861](https://github.com/liwijs/liwi/commit/101c861063420fc5a83ff5a45322b9529962dcc2))
30
+
31
+
32
+ ### BREAKING CHANGES
33
+
34
+ * **deps:** cursor.count() is removed and replaced by store.count()
35
+ * requires node 14
36
+
37
+
38
+
39
+
40
+
6
41
  ## [8.3.1](https://github.com/liwijs/liwi/compare/v8.3.0...v8.3.1) (2021-11-28)
7
42
 
8
43
 
package/README.md CHANGED
@@ -8,6 +8,9 @@
8
8
 
9
9
  <p align="center">
10
10
  <a href="https://npmjs.org/package/liwi-mongo"><img src="https://img.shields.io/npm/v/liwi-mongo.svg?style=flat-square"></a>
11
+ <a href="https://npmjs.org/package/liwi-mongo"><img src="https://img.shields.io/npm/dw/liwi-mongo.svg?style=flat-square"></a>
12
+ <a href="https://npmjs.org/package/liwi-mongo"><img src="https://img.shields.io/node/v/liwi-mongo.svg?style=flat-square"></a>
13
+ <a href="https://npmjs.org/package/liwi-mongo"><img src="https://img.shields.io/npm/types/liwi-mongo.svg?style=flat-square"></a>
11
14
  </p>
12
15
 
13
16
  ## Install
@@ -5,7 +5,7 @@ export default class MongoConnection extends AbstractConnection {
5
5
  _connecting?: Promise<mongodb.MongoClient>;
6
6
  connectionFailed?: boolean;
7
7
  constructor(config: Map<string, string | number>);
8
- connect(connectionString: string): void;
8
+ connect(connectionString: string, connectionStringRedacted: string): void;
9
9
  getConnection(): Promise<mongodb.MongoClient>;
10
10
  close(): Promise<void>;
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MongoConnection.d.ts","sourceRoot":"","sources":["../src/MongoConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,kBAAkB;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAElC,WAAW,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE3C,gBAAgB,CAAC,EAAE,OAAO,CAAC;gBAGf,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IA4BhD,OAAO,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI;IAoDvC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;IAIvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
1
+ {"version":3,"file":"MongoConnection.d.ts","sourceRoot":"","sources":["../src/MongoConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,kBAAkB;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAElC,WAAW,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE3C,gBAAgB,CAAC,EAAE,OAAO,CAAC;gBAGf,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAqChD,OAAO,CAAC,gBAAgB,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,GAAG,IAAI;IAkDzE,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;IAIvC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
@@ -1,16 +1,15 @@
1
1
  import { AbstractStoreCursor } from 'liwi-store';
2
2
  import type { AllowedKeyValue } from 'liwi-types';
3
- import type { Cursor } from 'mongodb';
3
+ import type { FindCursor } from 'mongodb';
4
4
  import type { MongoBaseModel } from './MongoBaseModel';
5
5
  import type MongoStore from './MongoStore';
6
6
  export default class MongoCursor<Model extends MongoBaseModel<KeyValue>, Result extends Partial<Model> = Model, KeyValue extends AllowedKeyValue = Model['_id']> extends AbstractStoreCursor<MongoStore<Model, KeyValue>, KeyValue, Model, Result> {
7
7
  private readonly cursor;
8
8
  private _result?;
9
- constructor(store: MongoStore<Model, KeyValue>, cursor: Cursor);
9
+ constructor(store: MongoStore<Model, KeyValue>, cursor: FindCursor<Result>);
10
10
  advance(count: number): void;
11
- next(): Promise<any>;
11
+ next(): Promise<KeyValue | undefined>;
12
12
  limit(newLimit: number): Promise<this>;
13
- count(applySkipLimit?: boolean): Promise<number>;
14
13
  result(): Promise<Result>;
15
14
  close(): Promise<void>;
16
15
  toArray(): Promise<Result[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"MongoCursor.d.ts","sourceRoot":"","sources":["../src/MongoCursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,WAAW,CAC9B,KAAK,SAAS,cAAc,CAAC,QAAQ,CAAC,EACtC,MAAM,SAAS,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,EACrC,QAAQ,SAAS,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,CAC/C,SAAQ,mBAAmB,CAC3B,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,EAC3B,QAAQ,EACR,KAAK,EACL,MAAM,CACP;IAGC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC,OAAO,CAAC,OAAO,CAAC,CAAS;gBAEb,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM;IAK9D,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI5B,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAQpB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtC,KAAK,CAAC,cAAc,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAI9C,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAKzB,KAAK,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8B;IAEpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAE9C,OAAO,CAAC,YAAY,CAAC,CAAe;IAEpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2B;gBAGrD,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,EAClC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,EAC5B,WAAW,GAAE,WAAW,CAAC,KAAK,EAAE,IAAI,CAAuB;IAQ7D,kBAAkB,IAAI,YAAY;IAY5B,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAiB3E,UAAU,CACR,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,EAC7C,eAAe,EAAE,OAAO,GACvB,iBAAiB;YAiHN,iBAAiB;CAkBhC"}
@@ -15,23 +15,24 @@ export default class MongoStore<Model extends MongoBaseModel<KeyValue>, KeyValue
15
15
  readonly connection: MongoConnection;
16
16
  private _collection;
17
17
  constructor(connection: MongoConnection, collectionName: string);
18
- get collection(): Promise<Collection>;
18
+ get collection(): Promise<Collection<Model>>;
19
19
  createQuerySingleItem<Result extends Record<MongoKeyPath, KeyValue> = Model, Params extends QueryParams<Params> = never>(options: QueryOptions<Model>, transformer?: Transformer<Model, Result>): MongoQuerySingleItem<Model, Params, Result, KeyValue>;
20
20
  createQueryCollection<Item extends Record<MongoKeyPath, KeyValue> = Model, Params extends QueryParams<Params> = never>(options: QueryOptions<Model>, transformer?: Transformer<Model, Item>): MongoQueryCollection<Model, Params, Model['_id'], Item>;
21
21
  insertOne(object: MongoInsertType<Model>): Promise<Model>;
22
22
  replaceOne(object: Model): Promise<Model>;
23
- upsertOne<K extends Exclude<keyof Model, MongoKeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<MongoKeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Pick<Model, K>): Promise<Model>;
24
- upsertOneWithInfo<K extends Exclude<keyof Model, MongoKeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<MongoKeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Pick<Model, K>): Promise<MongoUpsertResult<KeyValue, Model>>;
23
+ upsertOne<K extends Exclude<keyof Model, MongoKeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<MongoKeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>['$setOnInsert']): Promise<Model>;
24
+ upsertOneWithInfo<K extends Exclude<keyof Model, MongoKeyPath | OptionalBaseModelKeysForInsert>>(object: UpsertPartialObject<MongoKeyPath, KeyValue, Model, K>, setOnInsertPartialObject?: Update<Model>['$setOnInsert']): Promise<MongoUpsertResult<KeyValue, Model>>;
25
25
  replaceSeveral(objects: Model[]): Promise<Model[]>;
26
- partialUpdateByKey(key: any, partialUpdate: Update<Model>, criteria?: Criteria<Model>): Promise<Model>;
26
+ partialUpdateByKey(key: KeyValue, partialUpdate: Update<Model>, criteria?: Criteria<Model>): Promise<Model>;
27
27
  partialUpdateOne(object: Model, partialUpdate: Update<Model>): Promise<Model>;
28
28
  partialUpdateMany(criteria: Criteria<Model>, partialUpdate: Update<Model>): Promise<void>;
29
- deleteByKey(key: any, criteria?: Criteria<Model>): Promise<void>;
29
+ deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void>;
30
30
  deleteOne(object: Model): Promise<void>;
31
31
  deleteMany(selector: Criteria<Model>): Promise<void>;
32
- cursor<Result = Model>(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<MongoCursor<Model, Result, KeyValue>>;
33
- findByKey(key: any, criteria?: Criteria<Model>): Promise<Model | undefined>;
32
+ count(filter?: Criteria<Model>): Promise<number>;
33
+ cursor<Result extends Partial<Model> = Model>(filter?: Criteria<Model>, sort?: Sort<Model>): Promise<MongoCursor<Model, Result, KeyValue>>;
34
+ findByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<Model | undefined>;
34
35
  findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]>;
35
- findOne(criteria: Criteria<Model>, sort?: Sort<Model>): Promise<Model | undefined>;
36
+ findOne(filter: Criteria<Model>, sort?: Sort<Model>): Promise<Model | undefined>;
36
37
  }
37
38
  //# sourceMappingURL=MongoStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MongoStore.d.ts","sourceRoot":"","sources":["../src/MongoStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACpB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,WAAW,EACX,eAAe,EACf,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,SAAS,CAAC;AAEvD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AACrD,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAC1D,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D,MAAM,WAAW,iBAAiB,CAChC,QAAQ,SAAS,eAAe,EAChC,KAAK,SAAS,cAAc,CAAC,QAAQ,CAAC,CACtC,SAAQ,YAAY,CAAC,KAAK,CAAC;IAC3B,MAAM,EAAE,KAAK,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,CAAC,OAAO,OAAO,UAAU,CAC7B,KAAK,SAAS,cAAc,CAAC,QAAQ,CAAC,EACtC,QAAQ,SAAS,eAAe,GAAG,KAAK,CAAC,YAAY,CAAC,CACtD,YACE,iBAAiB,CACf,YAAY,EACZ,QAAQ,EACR,KAAK,E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AG,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrE,SAAS,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAM9C,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAOhD,MAAM,CAAC,MAAM,SAAS,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,EAChD,MAAM,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,EACxB,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GACjB,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAS1C,SAAS,CACb,GAAG,EAAE,QAAQ,EACb,QAAQ,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GACzB,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAS7B,OAAO,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAMnE,OAAO,CACX,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,EACvB,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GACjB,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;CAO9B"}
@@ -6,13 +6,12 @@ const mongodb = require('mongodb');
6
6
  const liwiStore = require('liwi-store');
7
7
  const liwiSubscribeStore = require('liwi-subscribe-store');
8
8
  const mingo = require('mingo');
9
- const Logger = require('nightingale-logger');
9
+ const nightingaleLogger = require('nightingale-logger');
10
10
 
11
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
12
12
 
13
13
  const mongodb__default = /*#__PURE__*/_interopDefaultLegacy(mongodb);
14
14
  const mingo__default = /*#__PURE__*/_interopDefaultLegacy(mingo);
15
- const Logger__default = /*#__PURE__*/_interopDefaultLegacy(Logger);
16
15
 
17
16
  class MongoCursor extends liwiStore.AbstractStoreCursor {
18
17
  // key in AbstractCursor
@@ -28,7 +27,7 @@ class MongoCursor extends liwiStore.AbstractStoreCursor {
28
27
  next() {
29
28
  return this.cursor.next().then(value => {
30
29
  this._result = value;
31
- this.key = value === null || value === void 0 ? void 0 : value._id;
30
+ this.key = value?._id;
32
31
  return this.key;
33
32
  });
34
33
  }
@@ -38,10 +37,6 @@ class MongoCursor extends liwiStore.AbstractStoreCursor {
38
37
  return Promise.resolve(this);
39
38
  }
40
39
 
41
- count(applySkipLimit = false) {
42
- return this.cursor.count(applySkipLimit);
43
- }
44
-
45
40
  result() {
46
41
  if (!this._result) throw new Error('Cannot call result() before next()');
47
42
  return Promise.resolve(this._result);
@@ -87,8 +82,7 @@ class MongoQueryCollection extends liwiSubscribeStore.AbstractSubscribableStoreQ
87
82
  }
88
83
 
89
84
  async fetch(onFulfilled) {
90
- const cursor = await this.createMongoCursor();
91
- const [result, count] = await Promise.all([cursor.toArray(), cursor.count()]);
85
+ const [result, count] = await Promise.all([this.createMongoCursor().then(cursor => cursor.toArray()), this.store.count()]);
92
86
  return onFulfilled({
93
87
  result: result.map(this.transformer),
94
88
  meta: {
@@ -155,22 +149,21 @@ class MongoQueryCollection extends liwiSubscribeStore.AbstractSubscribableStoreQ
155
149
  deleted,
156
150
  updated,
157
151
  inserted
158
- } = action.changes.reduce((acc, [prevObject, nextObject]) => {
152
+ } = {
153
+ deleted: [],
154
+ updated: [],
155
+ inserted: []
156
+ };
157
+ action.changes.forEach(([prevObject, nextObject]) => {
159
158
  if (testCriteria(prevObject)) {
160
159
  if (!testCriteria(nextObject)) {
161
- acc.deleted.push(prevObject[this.store.keyPath]);
160
+ deleted.push(prevObject[this.store.keyPath]);
162
161
  } else {
163
- acc.updated.push(this.transformer(nextObject));
162
+ updated.push(this.transformer(nextObject));
164
163
  }
165
164
  } else if (testCriteria(nextObject)) {
166
- acc.inserted.push(this.transformer(nextObject));
165
+ inserted.push(this.transformer(nextObject));
167
166
  }
168
-
169
- return acc;
170
- }, {
171
- deleted: [],
172
- updated: [],
173
- inserted: []
174
167
  });
175
168
 
176
169
  if (deleted.length > 0) {
@@ -389,8 +382,9 @@ class MongoQuerySingleItem extends liwiSubscribeStore.AbstractSubscribableStoreQ
389
382
 
390
383
  /* eslint-disable max-lines */
391
384
  class MongoStore {
385
+ keyPath = '_id';
386
+
392
387
  constructor(connection, collectionName) {
393
- this.keyPath = '_id';
394
388
  this.connection = connection;
395
389
 
396
390
  if (!collectionName) {
@@ -424,17 +418,18 @@ class MongoStore {
424
418
 
425
419
  async insertOne(object) {
426
420
  if (!object._id) {
427
- object._id = new mongodb__default.ObjectID().toString();
421
+ object._id = new mongodb__default.ObjectId().toString();
428
422
  }
429
423
 
430
424
  if (!object.created) object.created = new Date();
431
425
  if (!object.updated) object.updated = new Date();
432
426
  const collection = await this.collection;
433
427
  const {
434
- result
435
- } = await collection.insertOne(object);
428
+ acknowledged: isAcknowledged
429
+ } = await collection.insertOne( // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
430
+ object);
436
431
 
437
- if (!result.ok || result.n !== 1) {
432
+ if (!isAcknowledged) {
438
433
  throw new Error('Fail to insert');
439
434
  }
440
435
 
@@ -501,7 +496,7 @@ class MongoStore {
501
496
  ...criteria
502
497
  }, partialUpdate);
503
498
 
504
- if (!commandResult.result.ok) {
499
+ if (!commandResult.acknowledged) {
505
500
  console.error(commandResult);
506
501
  throw new Error('Update failed');
507
502
  }
@@ -515,7 +510,8 @@ class MongoStore {
515
510
  }
516
511
 
517
512
  partialUpdateMany(criteria, partialUpdate) {
518
- return this.collection.then(collection => collection.updateMany(criteria, partialUpdate)).then(() => undefined); // TODO return updated object
513
+ return this.collection.then(collection => // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
514
+ collection.updateMany(criteria, partialUpdate)).then(() => undefined); // TODO return updated object
519
515
  }
520
516
 
521
517
  deleteByKey(key, criteria) {
@@ -533,28 +529,42 @@ class MongoStore {
533
529
  return this.collection.then(collection => collection.deleteMany(selector)).then(() => undefined);
534
530
  }
535
531
 
536
- cursor(criteria, sort) {
537
- return this.collection.then(collection => collection.find(criteria)).then(sort && (cursor => cursor.sort(sort))).then(cursor => new MongoCursor(this, cursor));
532
+ async count(filter) {
533
+ const collection = await this.collection;
534
+ return filter ? collection.countDocuments(filter) : collection.countDocuments();
535
+ }
536
+
537
+ async cursor(filter, sort) {
538
+ const collection = await this.collection;
539
+ const findCursor = filter ? collection.find(filter) : collection.find();
540
+ if (sort) findCursor.sort(sort);
541
+ return new MongoCursor(this, findCursor);
538
542
  }
539
543
 
540
- findByKey(key, criteria) {
541
- return this.collection.then(collection => collection.findOne({
544
+ async findByKey(key, criteria) {
545
+ const collection = await this.collection;
546
+ const result = await collection.findOne({
542
547
  _id: key,
543
548
  ...criteria
544
- })).then(result => result || undefined);
549
+ });
550
+ return result || undefined;
545
551
  }
546
552
 
547
553
  findAll(criteria, sort) {
548
554
  return this.cursor(criteria, sort).then(cursor => cursor.toArray());
549
555
  }
550
556
 
551
- findOne(criteria, sort) {
552
- return this.collection.then(collection => collection.find(criteria)).then(sort && (cursor => cursor.sort(sort))).then(cursor => cursor.limit(1).next());
557
+ async findOne(filter, sort) {
558
+ const collection = await this.collection;
559
+ const result = await collection.findOne(filter, {
560
+ sort
561
+ });
562
+ return result || undefined;
553
563
  }
554
564
 
555
565
  }
556
566
 
557
- const logger = new Logger__default('liwi:mongo:MongoConnection');
567
+ const logger = new nightingaleLogger.Logger('liwi:mongo:MongoConnection');
558
568
  class MongoConnection extends liwiStore.AbstractConnection {
559
569
  // TODO interface
560
570
  constructor(config) {
@@ -572,23 +582,24 @@ class MongoConnection extends liwiStore.AbstractConnection {
572
582
  throw new Error('Missing config database');
573
583
  }
574
584
 
575
- const connectionString = `mongodb://${config.has('user') ? `${config.get('user')}:${config.get('password')}@` : ''}` + `${config.get('host')}:${config.get('port')}/${config.get('database')}`;
576
- this.connect(connectionString);
585
+ const buildConnectionString = redactCredentials => `mongodb://${config.has('user') ? `${redactCredentials ? `${config.get('user').slice(0, 2)}[redacted]` : config.get('user')}:${redactCredentials ? '[redacted]' : config.get('password')}@` : ''}` + `${config.get('host')}:${config.get('port')}/${config.get('database')}`;
586
+
587
+ const connectionString = buildConnectionString(false);
588
+ const connectionStringRedacted = buildConnectionString(true);
589
+ this.connect(connectionString, connectionStringRedacted);
577
590
  }
578
591
 
579
- connect(connectionString) {
592
+ connect(connectionString, connectionStringRedacted) {
580
593
  logger.info('connecting', {
581
- connectionString
594
+ connectionStringRedacted
582
595
  });
583
- const connectPromise = mongodb__default.MongoClient.connect(connectionString, {
584
- useNewUrlParser: true
585
- }).then(connection => {
596
+ const connectPromise = mongodb__default.MongoClient.connect(connectionString).then(connection => {
586
597
  logger.info('connected', {
587
- connectionString
598
+ connectionStringRedacted
588
599
  });
589
600
  connection.on('close', () => {
590
601
  logger.warn('close', {
591
- connectionString
602
+ connectionStringRedacted
592
603
  });
593
604
  this.connectionFailed = true;
594
605
 
@@ -598,7 +609,7 @@ class MongoConnection extends liwiStore.AbstractConnection {
598
609
  });
599
610
  connection.on('timeout', () => {
600
611
  logger.warn('timeout', {
601
- connectionString
612
+ connectionStringRedacted
602
613
  });
603
614
  this.connectionFailed = true;
604
615
 
@@ -608,7 +619,7 @@ class MongoConnection extends liwiStore.AbstractConnection {
608
619
  });
609
620
  connection.on('reconnect', () => {
610
621
  logger.warn('reconnect', {
611
- connectionString
622
+ connectionStringRedacted
612
623
  });
613
624
  this.connectionFailed = false;
614
625
 
@@ -616,7 +627,7 @@ class MongoConnection extends liwiStore.AbstractConnection {
616
627
  });
617
628
  connection.on('error', err => {
618
629
  logger.warn('error', {
619
- connectionString,
630
+ connectionStringRedacted,
620
631
  err
621
632
  });
622
633
  });
@@ -628,7 +639,7 @@ class MongoConnection extends liwiStore.AbstractConnection {
628
639
  return connection;
629
640
  }).catch(err => {
630
641
  logger.info('not connected', {
631
- connectionString
642
+ connectionStringRedacted
632
643
  });
633
644
  console.error(err.message || err); // throw err;
634
645
 
@@ -669,4 +680,4 @@ function createMongoSubscribeStore(mongoStore) {
669
680
  exports.MongoConnection = MongoConnection;
670
681
  exports.MongoStore = MongoStore;
671
682
  exports.createMongoSubscribeStore = createMongoSubscribeStore;
672
- //# sourceMappingURL=index-node12-dev.cjs.js.map
683
+ //# sourceMappingURL=index-node14.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-node14.cjs","sources":["../src/MongoCursor.ts","../src/MongoQueryCollection.ts","../src/MongoQuerySingleItem.ts","../src/MongoStore.ts","../src/MongoConnection.ts","../src/createMongoSubscribeStore.ts"],"sourcesContent":["import { AbstractStoreCursor } from 'liwi-store';\nimport type { AllowedKeyValue } from 'liwi-types';\nimport type { FindCursor } from 'mongodb';\nimport type { MongoBaseModel } from './MongoBaseModel';\nimport type MongoStore from './MongoStore';\n\nexport default class MongoCursor<\n Model extends MongoBaseModel<KeyValue>,\n Result extends Partial<Model> = Model,\n KeyValue extends AllowedKeyValue = Model['_id'],\n> extends AbstractStoreCursor<\n MongoStore<Model, KeyValue>,\n KeyValue,\n Model,\n Result\n> {\n // key in AbstractCursor\n\n private readonly cursor: FindCursor<Result>;\n\n private _result?: Result | null;\n\n constructor(store: MongoStore<Model, KeyValue>, cursor: FindCursor<Result>) {\n super(store);\n this.cursor = cursor;\n }\n\n advance(count: number): void {\n this.cursor.skip(count);\n }\n\n next(): Promise<KeyValue | undefined> {\n return this.cursor.next().then((value) => {\n this._result = value;\n this.key = value?._id;\n return this.key;\n });\n }\n\n limit(newLimit: number): Promise<this> {\n this.cursor.limit(newLimit);\n return Promise.resolve(this);\n }\n\n result(): Promise<Result> {\n if (!this._result) throw new Error('Cannot call result() before next()');\n return Promise.resolve(this._result);\n }\n\n close(): Promise<void> {\n if (this.cursor) {\n this.cursor.close();\n }\n\n return Promise.resolve();\n }\n\n toArray(): Promise<Result[]> {\n return this.cursor.toArray();\n }\n}\n","/* eslint-disable complexity, max-lines */\nimport type {\n QuerySubscription,\n SubscribeCallback,\n QueryResult,\n QueryParams,\n} from 'liwi-store';\nimport type { Actions } from 'liwi-subscribe-store';\nimport { AbstractSubscribableStoreQuery } from 'liwi-subscribe-store';\nimport type {\n Changes,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n} from 'liwi-types';\nimport mingo from 'mingo';\nimport type {\n MongoBaseModel,\n MongoInsertType,\n MongoKeyPath,\n} from './MongoBaseModel';\nimport type MongoCursor from './MongoCursor';\nimport type MongoStore from './MongoStore';\n\nconst identityTransformer = <\n Model extends MongoBaseModel<any>,\n Transformed = Model,\n>(\n model: Model,\n): Transformed => model as unknown as Transformed;\n\ntype TestCriteria = (obj: any) => boolean;\n\nexport default class MongoQueryCollection<\n Model extends MongoBaseModel<KeyValue>,\n Params extends QueryParams<Params> = never,\n KeyValue extends AllowedKeyValue = Model['_id'],\n Item extends Record<MongoKeyPath, KeyValue> = Model,\n> extends AbstractSubscribableStoreQuery<\n MongoKeyPath,\n KeyValue,\n Model,\n MongoInsertType<Model, KeyValue>,\n Params,\n Item[]\n> {\n private readonly store: MongoStore<Model, KeyValue>;\n\n private readonly options: QueryOptions<Model>;\n\n private testCriteria?: TestCriteria;\n\n private readonly transformer: Transformer<Model, Item>;\n\n constructor(\n store: MongoStore<Model, KeyValue>,\n options: QueryOptions<Model>,\n transformer: Transformer<Model, Item> = identityTransformer,\n ) {\n super();\n this.store = store;\n this.options = options;\n this.transformer = transformer;\n }\n\n createTestCriteria(): TestCriteria {\n if (!this.testCriteria) {\n if (!this.options.criteria) {\n return () => true;\n }\n\n const mingoQuery = new mingo.Query(this.options.criteria);\n this.testCriteria = mingoQuery.test.bind(mingoQuery);\n }\n return this.testCriteria;\n }\n\n async fetch<T>(onFulfilled: (result: QueryResult<Item[]>) => T): Promise<T> {\n const [result, count] = await Promise.all([\n this.createMongoCursor().then((cursor) => cursor.toArray()),\n this.store.count(),\n ]);\n\n return onFulfilled({\n result: result.map(this.transformer),\n meta: { total: count },\n info: {\n sort: this.options.sort,\n limit: this.options.limit,\n keyPath: this.store.keyPath,\n },\n });\n }\n\n _subscribe(\n callback: SubscribeCallback<KeyValue, Item[]>,\n _includeInitial: boolean,\n ): QuerySubscription {\n const store = super.getSubscribeStore();\n const testCriteria: TestCriteria = this.createTestCriteria();\n\n const promise: Promise<void> = _includeInitial\n ? this.fetch(({ result, meta, info }: QueryResult<Item[]>) => {\n callback(null, [\n {\n type: 'initial',\n initial: result,\n queryInfo: info,\n meta,\n },\n ]);\n })\n : Promise.resolve();\n\n const unsubscribe = store.subscribe((action: Actions<Model>) => {\n const changes: Changes<KeyValue, Item[]> = [];\n switch (action.type) {\n case 'inserted': {\n const filtered = action.next.filter(testCriteria);\n if (filtered.length > 0) {\n changes.push({\n type: 'inserted',\n result: filtered.map(this.transformer),\n });\n }\n break;\n }\n case 'deleted': {\n const filtered = action.prev.filter(testCriteria);\n if (filtered.length > 0) {\n changes.push({\n type: 'deleted',\n keys: filtered.map((object) => object[this.store.keyPath]),\n });\n }\n break;\n }\n case 'updated': {\n const {\n deleted,\n updated,\n inserted,\n }: {\n deleted: KeyValue[];\n updated: Item[];\n inserted: Item[];\n } = { deleted: [], updated: [], inserted: [] };\n\n action.changes.forEach(([prevObject, nextObject]: [Model, Model]) => {\n if (testCriteria(prevObject)) {\n if (!testCriteria(nextObject)) {\n deleted.push(prevObject[this.store.keyPath]);\n } else {\n updated.push(this.transformer(nextObject));\n }\n } else if (testCriteria(nextObject)) {\n inserted.push(this.transformer(nextObject));\n }\n });\n\n if (deleted.length > 0) {\n changes.push({ type: 'deleted', keys: deleted });\n }\n if (updated.length > 0) {\n changes.push({ type: 'updated', result: updated });\n }\n if (inserted.length > 0) {\n changes.push({ type: 'inserted', result: inserted });\n }\n\n break;\n }\n default:\n throw new Error('Unsupported type');\n }\n\n if (changes.length === 0) return;\n\n callback(null, changes);\n });\n // let _feed;\n // const promise = this.queryCallback(this.store.query(), this.store.r)\n // .changes({\n // includeInitial: _includeInitial,\n // includeStates: true,\n // includeTypes: true,\n // includeOffsets: true,\n // })\n // .then((feed) => {\n // if (args.length === 0) {\n // _feed = feed;\n // delete this._promise;\n // }\n //\n // feed.each(callback);\n // return feed;\n // });\n //\n // if (args.length === 0) this._promise = promise;\n\n return {\n stop: unsubscribe,\n cancel: unsubscribe,\n then: <T, U>(\n onFulfilled: () => T | Promise<T>,\n onRejected?: (error: any) => U | Promise<U>,\n ): Promise<T | U> => promise.then(onFulfilled, onRejected),\n };\n }\n\n private async createMongoCursor(): Promise<\n MongoCursor<Model, Model, KeyValue>\n > {\n const cursor = await this.store.cursor(\n this.options.criteria,\n this.options.sort,\n );\n\n if (this.options.skip) {\n cursor.advance(this.options.skip);\n }\n\n if (this.options.limit) {\n await cursor.limit(this.options.limit);\n }\n\n return cursor;\n }\n}\n","import type {\n QuerySubscription,\n SubscribeCallback,\n QueryResult,\n QueryParams,\n} from 'liwi-store';\nimport type { Actions } from 'liwi-subscribe-store';\nimport { AbstractSubscribableStoreQuery } from 'liwi-subscribe-store';\nimport type {\n Changes,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n} from 'liwi-types';\nimport mingo from 'mingo';\nimport type {\n MongoBaseModel,\n MongoInsertType,\n MongoKeyPath,\n} from './MongoBaseModel';\nimport type MongoCursor from './MongoCursor';\nimport type MongoStore from './MongoStore';\n\nconst identityTransformer = <\n Model extends MongoBaseModel<any>,\n Transformed = Model,\n>(\n model: Model,\n): Transformed => model as unknown as Transformed;\n\ntype TestCriteria = (obj: any) => boolean;\n\nexport default class MongoQuerySingleItem<\n Model extends MongoBaseModel<KeyValue>,\n Params extends QueryParams<Params> = never,\n Result extends Record<MongoKeyPath, KeyValue> | null = Model | null,\n KeyValue extends AllowedKeyValue = Model['_id'],\n> extends AbstractSubscribableStoreQuery<\n MongoKeyPath,\n KeyValue,\n Model,\n MongoInsertType<Model, KeyValue>,\n Params,\n Result\n> {\n private readonly store: MongoStore<Model, KeyValue>;\n\n private readonly options: QueryOptions<Model>;\n\n private testCriteria?: TestCriteria;\n\n private readonly transformer: Transformer<Model, Result>;\n\n constructor(\n store: MongoStore<Model, KeyValue>,\n options: QueryOptions<Model>,\n transformer: Transformer<Model, Result> = identityTransformer,\n ) {\n super();\n this.store = store;\n this.options = options;\n this.transformer = transformer;\n }\n\n createMingoTestCriteria(): TestCriteria {\n if (!this.testCriteria) {\n if (!this.options.criteria) {\n return () => true;\n }\n\n const mingoQuery = new mingo.Query(this.options.criteria);\n this.testCriteria = mingoQuery.test.bind(mingoQuery);\n }\n\n return this.testCriteria;\n }\n\n async fetch<T>(onFulfilled: (result: QueryResult<Result>) => T): Promise<T> {\n const cursor = await this.createMongoCursor();\n await cursor.limit(1);\n return cursor.toArray().then((result: Model[]) => {\n const item: Result =\n result.length === 0 ? (null as Result) : this.transformer(result[0]);\n return onFulfilled({\n result: item,\n meta: { total: result === null ? 0 : 1 },\n info: {\n limit: 1,\n keyPath: this.store.keyPath,\n },\n });\n });\n }\n\n _subscribe(\n callback: SubscribeCallback<KeyValue, Result>,\n _includeInitial: boolean,\n ): QuerySubscription {\n const store = super.getSubscribeStore();\n const testCriteria: TestCriteria = this.createMingoTestCriteria();\n\n const promise: Promise<void> = _includeInitial\n ? this.fetch(({ result, meta, info }: QueryResult<Result>) => {\n callback(null, [\n {\n type: 'initial',\n initial: result,\n queryInfo: info,\n meta,\n },\n ]);\n })\n : Promise.resolve();\n\n const unsubscribe = store.subscribe(async (action: Actions<Model>) => {\n const changes: Changes<KeyValue, Result> = [];\n switch (action.type) {\n case 'inserted': {\n const filtered = action.next.filter(testCriteria);\n if (filtered.length > 0) {\n changes.push({\n type: 'updated',\n result: this.transformer(filtered[0]),\n });\n }\n break;\n }\n case 'deleted': {\n const filtered = action.prev.filter(testCriteria);\n if (filtered.length > 0) {\n changes.push({\n type: 'deleted',\n keys: filtered.map((object) => object[this.store.keyPath]),\n });\n }\n break;\n }\n case 'updated': {\n const filtered = action.changes.filter(([prev, next]) =>\n testCriteria(prev),\n );\n if (filtered.length > 0) {\n if (this.options.sort) {\n const { result } = await this.fetch((res) => res);\n changes.push({\n type: 'updated',\n result,\n });\n } else if (filtered.length !== 1) {\n throw new Error(\n 'should not match more than 1, use sort if you can have multiple match',\n );\n } else {\n const [, next] = filtered[0];\n changes.push({\n type: 'updated',\n result: testCriteria(next) ? this.transformer(next) : null!,\n });\n }\n } else if (filtered.length === 0) {\n }\n break;\n }\n default:\n throw new Error('Unsupported type');\n }\n\n if (changes.length === 0) return;\n\n callback(null, changes);\n });\n\n return {\n stop: unsubscribe,\n cancel: unsubscribe,\n then: <T, U>(\n onFulfilled: () => T | Promise<T>,\n onRejected?: (error: any) => U | Promise<U>,\n ): Promise<T | U> => promise.then(onFulfilled, onRejected),\n };\n }\n\n private async createMongoCursor(): Promise<\n MongoCursor<Model, Model, KeyValue>\n > {\n const cursor = await this.store.cursor(\n this.options.criteria,\n this.options.sort,\n );\n\n if (this.options.limit) {\n await cursor.limit(this.options.limit);\n }\n\n return cursor;\n }\n}\n","/* eslint-disable max-lines */\nimport type {\n UpsertResult,\n SubscribableStore,\n QueryParams,\n UpsertPartialObject,\n} from 'liwi-store';\nimport type {\n Criteria,\n Sort,\n Update,\n QueryOptions,\n Transformer,\n AllowedKeyValue,\n OptionalBaseModelKeysForInsert,\n} from 'liwi-types';\nimport type {\n Collection,\n FindCursor,\n MongoClient,\n UpdateFilter,\n} from 'mongodb';\nimport mongodb from 'mongodb';\nimport type {\n MongoBaseModel,\n MongoKeyPath,\n MongoInsertType,\n} from './MongoBaseModel';\nimport type MongoConnection from './MongoConnection';\nimport MongoCursor from './MongoCursor';\nimport MongoQueryCollection from './MongoQueryCollection';\nimport MongoQuerySingleItem from './MongoQuerySingleItem';\n\nexport interface MongoUpsertResult<\n KeyValue extends AllowedKeyValue,\n Model extends MongoBaseModel<KeyValue>,\n> extends UpsertResult<Model> {\n object: Model;\n inserted: boolean;\n}\n\nexport default class MongoStore<\n Model extends MongoBaseModel<KeyValue>,\n KeyValue extends AllowedKeyValue = Model[MongoKeyPath],\n> implements\n SubscribableStore<\n MongoKeyPath,\n KeyValue,\n Model,\n MongoInsertType<Model>,\n MongoConnection\n >\n{\n readonly keyPath: MongoKeyPath = '_id';\n\n readonly connection: MongoConnection;\n\n private _collection: Collection<Model> | Promise<Collection<Model>>;\n\n constructor(connection: MongoConnection, collectionName: string) {\n this.connection = connection;\n\n if (!collectionName) {\n throw new Error(`Invalid collectionName: \"${collectionName}\"`);\n }\n\n this._collection = connection.getConnection().then(\n (client: MongoClient) => {\n this._collection = client.db().collection(collectionName);\n return this._collection;\n },\n (err: any) => {\n this._collection = Promise.reject(err);\n return this._collection;\n },\n );\n }\n\n get collection(): Promise<Collection<Model>> {\n if (this.connection.connectionFailed) {\n return Promise.reject(new Error('MongoDB connection failed'));\n }\n\n return Promise.resolve(this._collection);\n }\n\n createQuerySingleItem<\n Result extends Record<MongoKeyPath, KeyValue> = Model,\n Params extends QueryParams<Params> = never,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Result>,\n ): MongoQuerySingleItem<Model, Params, Result, KeyValue> {\n return new MongoQuerySingleItem<Model, Params, Result, KeyValue>(\n this,\n options,\n transformer,\n );\n }\n\n createQueryCollection<\n Item extends Record<MongoKeyPath, KeyValue> = Model,\n Params extends QueryParams<Params> = never,\n >(\n options: QueryOptions<Model>,\n transformer?: Transformer<Model, Item>,\n ): MongoQueryCollection<Model, Params, Model['_id'], Item> {\n return new MongoQueryCollection<Model, Params, KeyValue, Item>(\n this,\n options,\n transformer,\n );\n }\n\n async insertOne(object: MongoInsertType<Model>): Promise<Model> {\n if (!object._id) {\n object._id = new mongodb.ObjectId().toString() as Model['_id'];\n }\n\n if (!object.created) object.created = new Date();\n if (!object.updated) object.updated = new Date();\n\n const collection = await this.collection;\n const { acknowledged: isAcknowledged } = await collection.insertOne(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n object as any,\n );\n if (!isAcknowledged) {\n throw new Error('Fail to insert');\n }\n\n return object as Model;\n }\n\n async replaceOne(object: Model): Promise<Model> {\n if (!object.updated) object.updated = new Date();\n\n const collection = await this.collection;\n await collection.replaceOne({ _id: object._id } as Criteria<Model>, object);\n return object;\n }\n\n async upsertOne<\n K extends Exclude<\n keyof Model,\n MongoKeyPath | OptionalBaseModelKeysForInsert\n >,\n >(\n object: UpsertPartialObject<MongoKeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<Model> {\n const result = await this.upsertOneWithInfo(\n object,\n setOnInsertPartialObject,\n );\n return result.object;\n }\n\n async upsertOneWithInfo<\n K extends Exclude<\n keyof Model,\n MongoKeyPath | OptionalBaseModelKeysForInsert\n >,\n >(\n object: UpsertPartialObject<MongoKeyPath, KeyValue, Model, K>,\n setOnInsertPartialObject?: Update<Model>['$setOnInsert'],\n ): Promise<MongoUpsertResult<KeyValue, Model>> {\n const $setOnInsert = {\n created: object.created || new Date(),\n ...setOnInsertPartialObject,\n };\n\n if (!object.updated) {\n (object as MongoBaseModel).updated = new Date();\n }\n\n const $set: Partial<typeof object> = { ...object };\n delete $set.created;\n\n const collection = await this.collection;\n\n const { upsertedCount } = await collection.updateOne(\n { _id: object._id } as Criteria<Model>,\n { $set, $setOnInsert } as UpdateFilter<Model>,\n { upsert: true },\n );\n\n if (upsertedCount) {\n Object.assign(object, $setOnInsert);\n }\n\n return { object: object as unknown as Model, inserted: !!upsertedCount };\n }\n\n replaceSeveral(objects: Model[]): Promise<Model[]> {\n return Promise.all(objects.map((object: Model) => this.replaceOne(object)));\n }\n\n async partialUpdateByKey(\n key: KeyValue,\n partialUpdate: Update<Model>,\n criteria?: Criteria<Model>,\n ): Promise<Model> {\n const collection = await this.collection;\n const commandResult = await collection.updateOne(\n { _id: key, ...criteria } as Criteria<Model>,\n partialUpdate as UpdateFilter<Model>,\n );\n if (!commandResult.acknowledged) {\n console.error(commandResult);\n throw new Error('Update failed');\n }\n const object = await this.findByKey(key);\n return object!;\n }\n\n partialUpdateOne(\n object: Model,\n partialUpdate: Update<Model>,\n ): Promise<Model> {\n return this.partialUpdateByKey(object._id, partialUpdate);\n }\n\n partialUpdateMany(\n criteria: Criteria<Model>,\n partialUpdate: Update<Model>,\n ): Promise<void> {\n return this.collection\n .then((collection) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n collection.updateMany(criteria, partialUpdate as any),\n )\n .then((res) => undefined); // TODO return updated object\n }\n\n deleteByKey(key: KeyValue, criteria?: Criteria<Model>): Promise<void> {\n return this.collection\n .then((collection) =>\n collection.deleteOne({ _id: key, ...criteria } as Criteria<Model>),\n )\n .then(() => undefined);\n }\n\n deleteOne(object: Model): Promise<void> {\n return this.deleteByKey(object._id);\n }\n\n deleteMany(selector: Criteria<Model>): Promise<void> {\n return this.collection\n .then((collection) => collection.deleteMany(selector))\n .then(() => undefined);\n }\n\n async count(filter?: Criteria<Model>): Promise<number> {\n const collection = await this.collection;\n return filter\n ? collection.countDocuments(filter)\n : collection.countDocuments();\n }\n\n async cursor<Result extends Partial<Model> = Model>(\n filter?: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<MongoCursor<Model, Result, KeyValue>> {\n const collection = await this.collection;\n const findCursor = filter\n ? collection.find<Result>(filter)\n : (collection.find() as unknown as FindCursor<Result>);\n if (sort) findCursor.sort(sort);\n return new MongoCursor<Model, Result, KeyValue>(this, findCursor);\n }\n\n async findByKey(\n key: KeyValue,\n criteria?: Criteria<Model>,\n ): Promise<Model | undefined> {\n const collection = await this.collection;\n const result = await collection.findOne<Model>({\n _id: key,\n ...criteria,\n } as Criteria<Model>);\n return result || undefined;\n }\n\n findAll(criteria?: Criteria<Model>, sort?: Sort<Model>): Promise<Model[]> {\n return this.cursor<Model>(criteria, sort).then((cursor) =>\n cursor.toArray(),\n );\n }\n\n async findOne(\n filter: Criteria<Model>,\n sort?: Sort<Model>,\n ): Promise<Model | undefined> {\n const collection = await this.collection;\n const result = await collection.findOne<Model>(filter, {\n sort,\n });\n return result || undefined;\n }\n}\n","import { AbstractConnection } from 'liwi-store';\nimport mongodb from 'mongodb';\nimport { Logger } from 'nightingale-logger';\n\nconst logger = new Logger('liwi:mongo:MongoConnection');\n\nexport default class MongoConnection extends AbstractConnection {\n _connection?: mongodb.MongoClient;\n\n _connecting?: Promise<mongodb.MongoClient>;\n\n connectionFailed?: boolean;\n\n // TODO interface\n constructor(config: Map<string, string | number>) {\n super();\n\n if (!config.has('host')) {\n config.set('host', 'localhost');\n }\n if (!config.has('port')) {\n config.set('port', '27017');\n }\n if (!config.has('database')) {\n throw new Error('Missing config database');\n }\n\n const buildConnectionString = (redactCredentials: boolean): string =>\n `mongodb://${\n config.has('user')\n ? `${\n redactCredentials\n ? `${(config.get('user') as string).slice(0, 2)}[redacted]`\n : (config.get('user') as string)\n }:${\n redactCredentials\n ? '[redacted]'\n : (config.get('password') as string)\n }@`\n : ''\n }` +\n `${config.get('host') as string}:${config.get('port') as string}/${\n config.get('database') as string\n }`;\n\n const connectionString = buildConnectionString(false);\n const connectionStringRedacted = buildConnectionString(true);\n\n this.connect(connectionString, connectionStringRedacted);\n }\n\n connect(connectionString: string, connectionStringRedacted: string): void {\n logger.info('connecting', { connectionStringRedacted });\n\n const connectPromise = mongodb.MongoClient.connect(connectionString)\n .then((connection) => {\n logger.info('connected', { connectionStringRedacted });\n connection.on('close', () => {\n logger.warn('close', { connectionStringRedacted });\n this.connectionFailed = true;\n this.getConnection = () => {\n throw new Error('MongoDB connection closed');\n };\n });\n connection.on('timeout', () => {\n logger.warn('timeout', { connectionStringRedacted });\n this.connectionFailed = true;\n this.getConnection = () => {\n throw new Error('MongoDB connection timeout');\n };\n });\n connection.on('reconnect', () => {\n logger.warn('reconnect', { connectionStringRedacted });\n this.connectionFailed = false;\n this.getConnection = () => Promise.resolve(this._connection!);\n });\n connection.on('error', (err) => {\n logger.warn('error', { connectionStringRedacted, err });\n });\n\n this._connection = connection;\n this._connecting = undefined;\n this.getConnection = () => Promise.resolve(this._connection!);\n return connection;\n })\n .catch((err) => {\n logger.info('not connected', { connectionStringRedacted });\n console.error(err.message || err);\n // throw err;\n process.nextTick(() => {\n // eslint-disable-next-line unicorn/no-process-exit\n process.exit(1);\n });\n\n throw err;\n });\n\n this.getConnection = () => Promise.resolve(connectPromise);\n this._connecting = this.getConnection();\n }\n\n getConnection(): Promise<mongodb.MongoClient> {\n throw new Error('call connect()');\n }\n\n async close(): Promise<void> {\n this.getConnection = () => Promise.reject(new Error('Connection closed'));\n if (this._connection) {\n await this._connection.close();\n this._connection = undefined;\n } else if (this._connecting) {\n await this._connecting;\n await this.close();\n }\n }\n}\n","import { SubscribeStore } from 'liwi-subscribe-store';\nimport type { AllowedKeyValue } from 'liwi-types';\nimport type {\n MongoBaseModel,\n MongoInsertType,\n MongoKeyPath,\n} from './MongoBaseModel';\nimport type MongoConnection from './MongoConnection';\nimport type MongoStore from './MongoStore';\n\nexport default function createMongoSubscribeStore<\n Model extends MongoBaseModel<KeyValue>,\n KeyValue extends AllowedKeyValue = Model[MongoKeyPath],\n>(\n mongoStore: MongoStore<Model, KeyValue>,\n): SubscribeStore<\n MongoKeyPath,\n KeyValue,\n Model,\n MongoInsertType<Model, KeyValue>,\n MongoConnection,\n MongoStore<Model, KeyValue>\n> {\n return new SubscribeStore(mongoStore);\n}\n"],"names":["MongoCursor","AbstractStoreCursor","constructor","store","cursor","advance","count","skip","next","then","value","_result","key","_id","limit","newLimit","Promise","resolve","result","Error","close","toArray","identityTransformer","model","MongoQueryCollection","AbstractSubscribableStoreQuery","options","transformer","createTestCriteria","testCriteria","criteria","mingoQuery","mingo","Query","test","bind","fetch","onFulfilled","all","createMongoCursor","map","meta","total","info","sort","keyPath","_subscribe","callback","_includeInitial","getSubscribeStore","promise","type","initial","queryInfo","unsubscribe","subscribe","action","changes","filtered","filter","length","push","prev","keys","object","deleted","updated","inserted","forEach","prevObject","nextObject","stop","cancel","onRejected","MongoQuerySingleItem","createMingoTestCriteria","item","res","MongoStore","connection","collectionName","_collection","getConnection","client","db","collection","err","reject","connectionFailed","createQuerySingleItem","createQueryCollection","insertOne","mongodb","ObjectId","toString","created","Date","acknowledged","isAcknowledged","replaceOne","upsertOne","setOnInsertPartialObject","upsertOneWithInfo","$setOnInsert","$set","upsertedCount","updateOne","upsert","Object","assign","replaceSeveral","objects","partialUpdateByKey","partialUpdate","commandResult","console","error","findByKey","partialUpdateOne","partialUpdateMany","updateMany","undefined","deleteByKey","deleteOne","deleteMany","selector","countDocuments","findCursor","find","findOne","findAll","logger","Logger","MongoConnection","AbstractConnection","config","has","set","buildConnectionString","redactCredentials","get","slice","connectionString","connectionStringRedacted","connect","connectPromise","MongoClient","on","warn","_connection","_connecting","catch","message","process","nextTick","exit","createMongoSubscribeStore","mongoStore","SubscribeStore"],"mappings":";;;;;;;;;;;;;;;AAMe,MAAMA,WAAN,SAILC,6BAJK,CASb;AACA;AAMAC,EAAAA,WAAW,CAACC,KAAD,EAAqCC,MAArC,EAAiE;AAC1E,IAAA,KAAA,CAAMD,KAAN,CAAA,CAAA;IACA,IAAKC,CAAAA,MAAL,GAAcA,MAAd,CAAA;AACD,GAAA;;EAEDC,OAAO,CAACC,KAAD,EAAsB;AAC3B,IAAA,IAAA,CAAKF,MAAL,CAAYG,IAAZ,CAAiBD,KAAjB,CAAA,CAAA;AACD,GAAA;;AAEDE,EAAAA,IAAI,GAAkC;IACpC,OAAO,IAAA,CAAKJ,MAAL,CAAYI,IAAZ,GAAmBC,IAAnB,CAAyBC,KAAD,IAAW;MACxC,IAAKC,CAAAA,OAAL,GAAeD,KAAf,CAAA;AACA,MAAA,IAAA,CAAKE,GAAL,GAAWF,KAAK,EAAEG,GAAlB,CAAA;AACA,MAAA,OAAO,KAAKD,GAAZ,CAAA;AACD,KAJM,C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