@opra/mongodb 1.0.0-alpha.33 → 1.0.0-alpha.34
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/cjs/mongo-service.js +15 -1
- package/esm/mongo-service.js +15 -1
- package/package.json +3 -3
- package/types/mongo-service.d.ts +5 -3
package/cjs/mongo-service.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.MongoService = void 0;
|
|
|
4
4
|
const common_1 = require("@opra/common");
|
|
5
5
|
const core_1 = require("@opra/core");
|
|
6
6
|
const mongodb_1 = require("mongodb");
|
|
7
|
+
const mongo_adapter_js_1 = require("./mongo-adapter.js");
|
|
7
8
|
/**
|
|
8
9
|
* Class representing a MongoDB service for interacting with a collection.
|
|
9
10
|
* @extends ServiceBase
|
|
@@ -38,6 +39,17 @@ class MongoService extends core_1.ServiceBase {
|
|
|
38
39
|
this.resourceName = options?.resourceName;
|
|
39
40
|
this.idGenerator = options?.idGenerator;
|
|
40
41
|
}
|
|
42
|
+
for(context, overwriteProperties, overwriteContext) {
|
|
43
|
+
if (overwriteProperties?.documentFilter && this.documentFilter) {
|
|
44
|
+
overwriteProperties.documentFilter = [
|
|
45
|
+
...(Array.isArray(this.documentFilter) ? this.documentFilter : [this.documentFilter]),
|
|
46
|
+
...(Array.isArray(overwriteProperties?.documentFilter)
|
|
47
|
+
? overwriteProperties?.documentFilter
|
|
48
|
+
: [overwriteProperties?.documentFilter]),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
return super.for(context, overwriteProperties, overwriteContext);
|
|
52
|
+
}
|
|
41
53
|
/**
|
|
42
54
|
* Retrieves the collection name.
|
|
43
55
|
*
|
|
@@ -380,7 +392,9 @@ class MongoService extends core_1.ServiceBase {
|
|
|
380
392
|
* that resolves to the common filter, or undefined if not available.
|
|
381
393
|
*/
|
|
382
394
|
_getDocumentFilter(command) {
|
|
383
|
-
|
|
395
|
+
const commonFilter = Array.isArray(this.documentFilter) ? this.documentFilter : [this.documentFilter];
|
|
396
|
+
const mapped = commonFilter.map(f => (typeof f === 'function' ? f(command, this) : f));
|
|
397
|
+
return mapped.length > 1 ? mongo_adapter_js_1.MongoAdapter.prepareFilter(mapped) : mapped[0];
|
|
384
398
|
}
|
|
385
399
|
async _executeCommand(command, commandFn) {
|
|
386
400
|
let proto;
|
package/esm/mongo-service.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DATATYPE_METADATA } from '@opra/common';
|
|
2
2
|
import { ServiceBase } from '@opra/core';
|
|
3
3
|
import { ObjectId } from 'mongodb';
|
|
4
|
+
import { MongoAdapter } from './mongo-adapter.js';
|
|
4
5
|
/**
|
|
5
6
|
* Class representing a MongoDB service for interacting with a collection.
|
|
6
7
|
* @extends ServiceBase
|
|
@@ -35,6 +36,17 @@ export class MongoService extends ServiceBase {
|
|
|
35
36
|
this.resourceName = options?.resourceName;
|
|
36
37
|
this.idGenerator = options?.idGenerator;
|
|
37
38
|
}
|
|
39
|
+
for(context, overwriteProperties, overwriteContext) {
|
|
40
|
+
if (overwriteProperties?.documentFilter && this.documentFilter) {
|
|
41
|
+
overwriteProperties.documentFilter = [
|
|
42
|
+
...(Array.isArray(this.documentFilter) ? this.documentFilter : [this.documentFilter]),
|
|
43
|
+
...(Array.isArray(overwriteProperties?.documentFilter)
|
|
44
|
+
? overwriteProperties?.documentFilter
|
|
45
|
+
: [overwriteProperties?.documentFilter]),
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
return super.for(context, overwriteProperties, overwriteContext);
|
|
49
|
+
}
|
|
38
50
|
/**
|
|
39
51
|
* Retrieves the collection name.
|
|
40
52
|
*
|
|
@@ -377,7 +389,9 @@ export class MongoService extends ServiceBase {
|
|
|
377
389
|
* that resolves to the common filter, or undefined if not available.
|
|
378
390
|
*/
|
|
379
391
|
_getDocumentFilter(command) {
|
|
380
|
-
|
|
392
|
+
const commonFilter = Array.isArray(this.documentFilter) ? this.documentFilter : [this.documentFilter];
|
|
393
|
+
const mapped = commonFilter.map(f => (typeof f === 'function' ? f(command, this) : f));
|
|
394
|
+
return mapped.length > 1 ? MongoAdapter.prepareFilter(mapped) : mapped[0];
|
|
381
395
|
}
|
|
382
396
|
async _executeCommand(command, commandFn) {
|
|
383
397
|
let proto;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/mongodb",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.34",
|
|
4
4
|
"description": "Opra MongoDB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"valgen": "^5.8.2"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@opra/common": "^1.0.0-alpha.
|
|
15
|
-
"@opra/core": "^1.0.0-alpha.
|
|
14
|
+
"@opra/common": "^1.0.0-alpha.34",
|
|
15
|
+
"@opra/core": "^1.0.0-alpha.34",
|
|
16
16
|
"mongodb": ">= 6.0.0"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|
package/types/mongo-service.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as OpraCommon from '@opra/common';
|
|
2
2
|
import { ComplexType } from '@opra/common';
|
|
3
|
-
import { ServiceBase } from '@opra/core';
|
|
3
|
+
import { HttpContext, ServiceBase } from '@opra/core';
|
|
4
4
|
import mongodb, { Document, TransactionOptions } from 'mongodb';
|
|
5
|
-
import { PartialDTO, StrictOmit, Type } from 'ts-gems';
|
|
5
|
+
import { Nullish, PartialDTO, StrictOmit, Type } from 'ts-gems';
|
|
6
6
|
import { IsObject } from 'valgen';
|
|
7
7
|
import { MongoAdapter } from './mongo-adapter.js';
|
|
8
8
|
/**
|
|
@@ -31,6 +31,7 @@ export declare namespace MongoService {
|
|
|
31
31
|
input?: any;
|
|
32
32
|
options?: any;
|
|
33
33
|
}
|
|
34
|
+
type CommonFilter = MongoAdapter.FilterInput | ((args: MongoService.CommandInfo, _this: MongoService<any>) => MongoAdapter.FilterInput | Promise<MongoAdapter.FilterInput> | undefined);
|
|
34
35
|
/**
|
|
35
36
|
* Represents options for "create" operation
|
|
36
37
|
*
|
|
@@ -187,7 +188,7 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
|
|
|
187
188
|
*
|
|
188
189
|
* @type {FilterInput | Function}
|
|
189
190
|
*/
|
|
190
|
-
documentFilter?:
|
|
191
|
+
documentFilter?: MongoService.CommonFilter | MongoService.CommonFilter[];
|
|
191
192
|
/**
|
|
192
193
|
* Constructs a new instance
|
|
193
194
|
*
|
|
@@ -196,6 +197,7 @@ export declare class MongoService<T extends mongodb.Document = mongodb.Document>
|
|
|
196
197
|
* @constructor
|
|
197
198
|
*/
|
|
198
199
|
constructor(dataType: Type | string, options?: MongoService.Options);
|
|
200
|
+
for<C extends HttpContext, P extends Partial<this>>(context: C, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
|
|
199
201
|
/**
|
|
200
202
|
* Retrieves the collection name.
|
|
201
203
|
*
|