@opra/mongodb 0.31.12 → 0.31.13
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.
|
@@ -45,16 +45,17 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
45
45
|
return r.deletedCount;
|
|
46
46
|
}
|
|
47
47
|
async get(id, options) {
|
|
48
|
-
const out = await this.findOne(id, options);
|
|
49
|
-
if (!out)
|
|
50
|
-
throw new common_1.ResourceNotFoundError(this.resourceName || this.getCollectionName(), id);
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
|
-
async findOne(id, options) {
|
|
54
48
|
const filter = mongo_adapter_js_1.MongoAdapter.prepareKeyValues(id, this.keyFields);
|
|
55
49
|
const optionsFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter(options?.filter);
|
|
56
50
|
if (optionsFilter)
|
|
57
51
|
filter.$and = [...(Array.isArray(optionsFilter) ? optionsFilter : [optionsFilter])];
|
|
52
|
+
const out = await this.findOne({ ...options, filter });
|
|
53
|
+
if (!out)
|
|
54
|
+
throw new common_1.ResourceNotFoundError(this.resourceName || this.getCollectionName(), id);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
async findOne(options) {
|
|
58
|
+
const filter = mongo_adapter_js_1.MongoAdapter.prepareFilter(options?.filter) || {};
|
|
58
59
|
const mongoOptions = {
|
|
59
60
|
...(0, lodash_omit_1.default)(options, ['sort', 'skip', 'limit', 'filter']),
|
|
60
61
|
projection: mongo_adapter_js_1.MongoAdapter.prepareProjection(this.getDataType(), options),
|
|
@@ -41,16 +41,17 @@ export class MongoCollectionService extends MongoService {
|
|
|
41
41
|
return r.deletedCount;
|
|
42
42
|
}
|
|
43
43
|
async get(id, options) {
|
|
44
|
-
const out = await this.findOne(id, options);
|
|
45
|
-
if (!out)
|
|
46
|
-
throw new ResourceNotFoundError(this.resourceName || this.getCollectionName(), id);
|
|
47
|
-
return out;
|
|
48
|
-
}
|
|
49
|
-
async findOne(id, options) {
|
|
50
44
|
const filter = MongoAdapter.prepareKeyValues(id, this.keyFields);
|
|
51
45
|
const optionsFilter = MongoAdapter.prepareFilter(options?.filter);
|
|
52
46
|
if (optionsFilter)
|
|
53
47
|
filter.$and = [...(Array.isArray(optionsFilter) ? optionsFilter : [optionsFilter])];
|
|
48
|
+
const out = await this.findOne({ ...options, filter });
|
|
49
|
+
if (!out)
|
|
50
|
+
throw new ResourceNotFoundError(this.resourceName || this.getCollectionName(), id);
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
async findOne(options) {
|
|
54
|
+
const filter = MongoAdapter.prepareFilter(options?.filter) || {};
|
|
54
55
|
const mongoOptions = {
|
|
55
56
|
...omit(options, ['sort', 'skip', 'limit', 'filter']),
|
|
56
57
|
projection: MongoAdapter.prepareProjection(this.getDataType(), options),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/mongodb",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.13",
|
|
4
4
|
"description": "Opra MongoDB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"ts-gems": "^2.5.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@opra/common": "^0.31.
|
|
36
|
-
"@opra/core": "^0.31.
|
|
35
|
+
"@opra/common": "^0.31.13",
|
|
36
|
+
"@opra/core": "^0.31.13",
|
|
37
37
|
"mongodb": ">=6.x.x"
|
|
38
38
|
},
|
|
39
39
|
"type": "module",
|
|
@@ -15,8 +15,8 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
|
|
|
15
15
|
protected count(options?: MongoCollectionService.CountOptions<T>): Promise<number>;
|
|
16
16
|
protected delete(id: any, options?: MongoCollectionService.DeleteOptions<T>): Promise<number>;
|
|
17
17
|
protected deleteMany(options?: MongoCollectionService.DeleteManyOptions<T>): Promise<number>;
|
|
18
|
-
protected get(id: any, options?: MongoCollectionService.
|
|
19
|
-
protected findOne(
|
|
18
|
+
protected get(id: any, options?: MongoCollectionService.FindOneOptions): Promise<PartialOutput<T>>;
|
|
19
|
+
protected findOne(options?: MongoCollectionService.FindOneOptions): Promise<PartialOutput<T> | undefined>;
|
|
20
20
|
protected findMany(options?: MongoCollectionService.FindManyOptions<T>): Promise<PartialOutput<T>[]>;
|
|
21
21
|
protected update(id: any, doc: PartialInput<T>, options?: MongoCollectionService.UpdateOptions<T>): Promise<PartialOutput<T> | undefined>;
|
|
22
22
|
protected updateMany(doc: OpraCommon.PartialInput<T>, options?: MongoCollectionService.UpdateManyOptions<T>): Promise<number>;
|
|
@@ -44,7 +44,7 @@ export declare namespace MongoCollectionService {
|
|
|
44
44
|
interface DeleteManyOptions<T> extends mongodb.DeleteOptions {
|
|
45
45
|
filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
|
|
46
46
|
}
|
|
47
|
-
interface
|
|
47
|
+
interface FindOneOptions<T = any> extends StrictOmit<mongodb.FindOptions, 'sort' | 'limit' | 'skip' | 'projection'> {
|
|
48
48
|
filter?: mongodb.Filter<T> | OpraCommon.OpraFilter.Ast | string;
|
|
49
49
|
pick?: string[];
|
|
50
50
|
omit?: string[];
|