@opra/mongodb 1.4.3 → 1.4.4

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.
@@ -1,6 +1,6 @@
1
1
  import { DATATYPE_METADATA } from '@opra/common';
2
2
  import { ServiceBase } from '@opra/core';
3
- import { ObjectId } from 'mongodb';
3
+ import { ObjectId, } from 'mongodb';
4
4
  import { MongoAdapter } from '../adapter/mongo-adapter.js';
5
5
  const transactionKey = Symbol.for('transaction');
6
6
  /**
@@ -42,10 +42,12 @@ export class MongoService extends ServiceBase {
42
42
  for(context, overwriteProperties, overwriteContext) {
43
43
  if (overwriteProperties?.documentFilter && this.documentFilter) {
44
44
  overwriteProperties.documentFilter = [
45
- ...(Array.isArray(this.documentFilter) ? this.documentFilter : [this.documentFilter]),
45
+ ...(Array.isArray(this.documentFilter)
46
+ ? this.documentFilter
47
+ : [this.documentFilter]),
46
48
  ...(Array.isArray(overwriteProperties?.documentFilter)
47
- ? overwriteProperties?.documentFilter
48
- : [overwriteProperties?.documentFilter]),
49
+ ? overwriteProperties.documentFilter
50
+ : [overwriteProperties.documentFilter]),
49
51
  ];
50
52
  }
51
53
  return super.for(context, overwriteProperties, overwriteContext);
@@ -58,7 +60,9 @@ export class MongoService extends ServiceBase {
58
60
  * @throws {Error} If the collection name is not defined.
59
61
  */
60
62
  getCollectionName() {
61
- const out = typeof this.collectionName === 'function' ? this.collectionName(this) : this.collectionName;
63
+ const out = typeof this.collectionName === 'function'
64
+ ? this.collectionName(this)
65
+ : this.collectionName;
62
66
  if (out)
63
67
  return out;
64
68
  throw new Error('collectionName is not defined');
@@ -71,7 +75,9 @@ export class MongoService extends ServiceBase {
71
75
  * @throws {Error} If the resource name is not defined.
72
76
  */
73
77
  getResourceName() {
74
- const out = typeof this.resourceName === 'function' ? this.resourceName(this) : this.resourceName || this.getCollectionName();
78
+ const out = typeof this.resourceName === 'function'
79
+ ? this.resourceName(this)
80
+ : this.resourceName || this.getCollectionName();
75
81
  if (out)
76
82
  return out;
77
83
  throw new Error('resourceName is not defined');
@@ -181,7 +187,9 @@ export class MongoService extends ServiceBase {
181
187
  * @returns {MongoAdapter.AnyId} The generated ID.
182
188
  */
183
189
  _generateId(command) {
184
- return typeof this.idGenerator === 'function' ? this.idGenerator(command, this) : new ObjectId();
190
+ return typeof this.idGenerator === 'function'
191
+ ? this.idGenerator(command, this)
192
+ : new ObjectId();
185
193
  }
186
194
  /**
187
195
  * Retrieves the common filter used for querying documents.
@@ -192,8 +200,10 @@ export class MongoService extends ServiceBase {
192
200
  * that resolves to the common filter, or undefined if not available.
193
201
  */
194
202
  _getDocumentFilter(command) {
195
- const commonFilter = Array.isArray(this.documentFilter) ? this.documentFilter : [this.documentFilter];
196
- const mapped = commonFilter.map(f => (typeof f === 'function' ? f(command, this) : f));
203
+ const commonFilter = Array.isArray(this.documentFilter)
204
+ ? this.documentFilter
205
+ : [this.documentFilter];
206
+ const mapped = commonFilter.map(f => typeof f === 'function' ? f(command, this) : f);
197
207
  return mapped.length > 1 ? MongoAdapter.prepareFilter(mapped) : mapped[0];
198
208
  }
199
209
  async _executeCommand(command, commandFn) {
@@ -201,7 +211,8 @@ export class MongoService extends ServiceBase {
201
211
  const next = async () => {
202
212
  proto = proto ? Object.getPrototypeOf(proto) : this;
203
213
  while (proto) {
204
- if (proto.interceptor && Object.prototype.hasOwnProperty.call(proto, 'interceptor')) {
214
+ if (proto.interceptor &&
215
+ Object.prototype.hasOwnProperty.call(proto, 'interceptor')) {
205
216
  return await proto.interceptor.call(this, next, command, this);
206
217
  }
207
218
  proto = Object.getPrototypeOf(proto);
@@ -245,7 +256,11 @@ export class MongoService extends ServiceBase {
245
256
  let validator = this._outputCodecs[operation];
246
257
  if (validator)
247
258
  return validator;
248
- const options = { projection: '*', partial: 'deep', ignoreHiddenFields: true };
259
+ const options = {
260
+ projection: '*',
261
+ partial: 'deep',
262
+ ignoreHiddenFields: true,
263
+ };
249
264
  const dataType = this.dataType;
250
265
  validator = dataType.generateCodec('decode', options);
251
266
  this._outputCodecs[operation] = validator;
@@ -91,7 +91,10 @@ export class MongoSingletonService extends MongoEntityService {
91
91
  options,
92
92
  };
93
93
  return this._executeCommand(command, async () => {
94
- const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
94
+ const filter = MongoAdapter.prepareFilter([
95
+ await this._getDocumentFilter(command),
96
+ command.options?.filter,
97
+ ]);
95
98
  command.options = { ...command.options, filter };
96
99
  return this._delete(command);
97
100
  });
@@ -112,7 +115,10 @@ export class MongoSingletonService extends MongoEntityService {
112
115
  };
113
116
  return this._executeCommand(command, async () => {
114
117
  const documentFilter = await this._getDocumentFilter(command);
115
- const filter = MongoAdapter.prepareFilter([documentFilter, command.options?.filter]);
118
+ const filter = MongoAdapter.prepareFilter([
119
+ documentFilter,
120
+ command.options?.filter,
121
+ ]);
116
122
  const findCommand = command;
117
123
  findCommand.options = { ...command.options, filter, projection: ['_id'] };
118
124
  return !!(await this._findById(findCommand));
@@ -128,7 +134,10 @@ export class MongoSingletonService extends MongoEntityService {
128
134
  };
129
135
  return this._executeCommand(command, async () => {
130
136
  const documentFilter = await this._getDocumentFilter(command);
131
- const filter = MongoAdapter.prepareFilter([documentFilter, command.options?.filter]);
137
+ const filter = MongoAdapter.prepareFilter([
138
+ documentFilter,
139
+ command.options?.filter,
140
+ ]);
132
141
  command.options = { ...command.options, filter };
133
142
  return this._findById(command);
134
143
  });
@@ -151,7 +160,10 @@ export class MongoSingletonService extends MongoEntityService {
151
160
  options,
152
161
  };
153
162
  return this._executeCommand(command, async () => {
154
- const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
163
+ const filter = MongoAdapter.prepareFilter([
164
+ await this._getDocumentFilter(command),
165
+ command.options?.filter,
166
+ ]);
155
167
  command.options = { ...command.options, filter };
156
168
  const matchCount = await this._updateOnly(command);
157
169
  if (matchCount) {
@@ -186,7 +198,10 @@ export class MongoSingletonService extends MongoEntityService {
186
198
  options,
187
199
  };
188
200
  return this._executeCommand(command, async () => {
189
- const filter = MongoAdapter.prepareFilter([await this._getDocumentFilter(command), command.options?.filter]);
201
+ const filter = MongoAdapter.prepareFilter([
202
+ await this._getDocumentFilter(command),
203
+ command.options?.filter,
204
+ ]);
190
205
  command.options = { ...command.options, filter };
191
206
  return this._updateOnly(command);
192
207
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/mongodb",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Opra MongoDB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -10,9 +10,9 @@
10
10
  "valgen": "^5.12.0"
11
11
  },
12
12
  "peerDependencies": {
13
- "@opra/common": "^1.4.3",
14
- "@opra/core": "^1.4.3",
15
- "@opra/http": "^1.4.3",
13
+ "@opra/common": "^1.4.4",
14
+ "@opra/core": "^1.4.4",
15
+ "@opra/http": "^1.4.4",
16
16
  "mongodb": ">= 6.0.0"
17
17
  },
18
18
  "type": "module",