@opra/mongodb 0.26.3 → 0.26.5
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-adapter.js
CHANGED
|
@@ -20,9 +20,10 @@ var MongoAdapter;
|
|
|
20
20
|
function transformRequest(request) {
|
|
21
21
|
const { resource } = request;
|
|
22
22
|
if (resource instanceof common_1.Collection || resource instanceof common_1.Singleton) {
|
|
23
|
-
const { params,
|
|
23
|
+
const { params, endpoint } = request;
|
|
24
24
|
let options = {};
|
|
25
25
|
let filter;
|
|
26
|
+
const operation = endpoint.name;
|
|
26
27
|
if (operation === 'create' || operation === 'update' ||
|
|
27
28
|
operation === 'get' || operation === 'findMany') {
|
|
28
29
|
options.projection = MongoAdapter.transformProjection(resource.type, params);
|
|
@@ -100,7 +101,7 @@ var MongoAdapter;
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
throw new TypeError(`Unimplemented request kind (${request.resource.kind}.${request.
|
|
104
|
+
throw new TypeError(`Unimplemented request kind (${request.resource.kind}.${request.endpoint.name})`);
|
|
104
105
|
}
|
|
105
106
|
MongoAdapter.transformRequest = transformRequest;
|
|
106
107
|
})(MongoAdapter || (exports.MongoAdapter = MongoAdapter = {}));
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MongoEntityService = void 0;
|
|
4
|
-
|
|
4
|
+
const core_1 = require("@opra/core");
|
|
5
|
+
class MongoEntityService extends core_1.ApiService {
|
|
5
6
|
constructor(arg0, arg1) {
|
|
7
|
+
super();
|
|
6
8
|
const options = typeof arg0 === 'object' ? arg0 : arg1;
|
|
7
9
|
if (typeof arg0 === 'string')
|
|
8
10
|
this._collectionName = arg0;
|
|
@@ -168,17 +170,9 @@ class MongoEntityService {
|
|
|
168
170
|
return this.forContext(context, db, session);
|
|
169
171
|
}
|
|
170
172
|
forContext(context, db, session) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// Should reset session if db changed
|
|
175
|
-
if (db) {
|
|
176
|
-
instance.db = db;
|
|
177
|
-
instance.session = session;
|
|
178
|
-
}
|
|
179
|
-
if (session)
|
|
180
|
-
instance.session = session;
|
|
181
|
-
Object.setPrototypeOf(instance, this);
|
|
173
|
+
const instance = super.forContext(context);
|
|
174
|
+
instance.db = db || this.db;
|
|
175
|
+
instance.session = session || this.session;
|
|
182
176
|
return instance;
|
|
183
177
|
}
|
|
184
178
|
async _onError(error) {
|
package/esm/mongo-adapter.js
CHANGED
|
@@ -16,9 +16,10 @@ export var MongoAdapter;
|
|
|
16
16
|
function transformRequest(request) {
|
|
17
17
|
const { resource } = request;
|
|
18
18
|
if (resource instanceof Collection || resource instanceof Singleton) {
|
|
19
|
-
const { params,
|
|
19
|
+
const { params, endpoint } = request;
|
|
20
20
|
let options = {};
|
|
21
21
|
let filter;
|
|
22
|
+
const operation = endpoint.name;
|
|
22
23
|
if (operation === 'create' || operation === 'update' ||
|
|
23
24
|
operation === 'get' || operation === 'findMany') {
|
|
24
25
|
options.projection = MongoAdapter.transformProjection(resource.type, params);
|
|
@@ -96,7 +97,7 @@ export var MongoAdapter;
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
throw new TypeError(`Unimplemented request kind (${request.resource.kind}.${request.
|
|
100
|
+
throw new TypeError(`Unimplemented request kind (${request.resource.kind}.${request.endpoint.name})`);
|
|
100
101
|
}
|
|
101
102
|
MongoAdapter.transformRequest = transformRequest;
|
|
102
103
|
})(MongoAdapter || (MongoAdapter = {}));
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { ApiService } from '@opra/core';
|
|
2
|
+
export class MongoEntityService extends ApiService {
|
|
2
3
|
constructor(arg0, arg1) {
|
|
4
|
+
super();
|
|
3
5
|
const options = typeof arg0 === 'object' ? arg0 : arg1;
|
|
4
6
|
if (typeof arg0 === 'string')
|
|
5
7
|
this._collectionName = arg0;
|
|
@@ -165,17 +167,9 @@ export class MongoEntityService {
|
|
|
165
167
|
return this.forContext(context, db, session);
|
|
166
168
|
}
|
|
167
169
|
forContext(context, db, session) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// Should reset session if db changed
|
|
172
|
-
if (db) {
|
|
173
|
-
instance.db = db;
|
|
174
|
-
instance.session = session;
|
|
175
|
-
}
|
|
176
|
-
if (session)
|
|
177
|
-
instance.session = session;
|
|
178
|
-
Object.setPrototypeOf(instance, this);
|
|
170
|
+
const instance = super.forContext(context);
|
|
171
|
+
instance.db = db || this.db;
|
|
172
|
+
instance.session = session || this.session;
|
|
179
173
|
return instance;
|
|
180
174
|
}
|
|
181
175
|
async _onError(error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/mongodb",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.5",
|
|
4
4
|
"description": "Opra MongoDB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"ts-gems": "^2.5.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@opra/common": "^0.26.
|
|
37
|
-
"@opra/core": "^0.26.
|
|
36
|
+
"@opra/common": "^0.26.5",
|
|
37
|
+
"@opra/core": "^0.26.5",
|
|
38
38
|
"mongodb": ">=6.x.x"
|
|
39
39
|
},
|
|
40
40
|
"type": "module",
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import mongodb, { UpdateFilter } from 'mongodb';
|
|
2
2
|
import { StrictOmit } from 'ts-gems';
|
|
3
|
-
import { PartialOutput, RequestContext } from '@opra/core';
|
|
3
|
+
import { ApiService, PartialOutput, RequestContext } from '@opra/core';
|
|
4
4
|
export declare namespace MongoEntityService {
|
|
5
5
|
interface Options {
|
|
6
6
|
db?: mongodb.Db;
|
|
7
7
|
defaultLimit?: number;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
export declare class MongoEntityService<T extends mongodb.Document> {
|
|
10
|
+
export declare class MongoEntityService<T extends mongodb.Document> extends ApiService {
|
|
11
11
|
protected _collectionName: string;
|
|
12
|
-
context: RequestContext;
|
|
13
12
|
defaultLimit: number;
|
|
14
13
|
db?: mongodb.Db;
|
|
15
14
|
session?: mongodb.ClientSession;
|
|
@@ -24,7 +23,7 @@ export declare class MongoEntityService<T extends mongodb.Document> {
|
|
|
24
23
|
updateOne(filter: mongodb.Filter<T>, doc: UpdateFilter<T> | Partial<T>, options?: mongodb.UpdateOptions): Promise<PartialOutput<T> | undefined>;
|
|
25
24
|
updateMany(filter: mongodb.Filter<T>, doc: UpdateFilter<T> | Partial<T>, options?: StrictOmit<mongodb.UpdateOptions, 'upsert'>): Promise<number>;
|
|
26
25
|
with(context: RequestContext, db?: mongodb.Db, session?: mongodb.ClientSession): MongoEntityService<T>;
|
|
27
|
-
forContext(context: RequestContext, db?: mongodb.Db, session?: mongodb.ClientSession):
|
|
26
|
+
forContext(context: RequestContext, db?: mongodb.Db, session?: mongodb.ClientSession): typeof this;
|
|
28
27
|
protected _onError(error: unknown): Promise<void>;
|
|
29
28
|
protected getDatabase(): mongodb.Db | Promise<mongodb.Db>;
|
|
30
29
|
protected getCollection(db: mongodb.Db): Promise<mongodb.Collection<T>>;
|