@opra/mongodb 0.25.5 → 0.26.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/cjs/mongo-adapter.js
CHANGED
|
@@ -20,22 +20,22 @@ 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, operation } = request;
|
|
24
24
|
let options = {};
|
|
25
25
|
let filter;
|
|
26
|
-
if (
|
|
27
|
-
|
|
26
|
+
if (operation === 'create' || operation === 'update' ||
|
|
27
|
+
operation === 'get' || operation === 'findMany') {
|
|
28
28
|
options.projection = MongoAdapter.transformProjection(resource.type, params);
|
|
29
29
|
}
|
|
30
30
|
if (resource instanceof common_1.Collection &&
|
|
31
|
-
(
|
|
31
|
+
(operation === 'delete' || operation === 'get' || operation === 'update')) {
|
|
32
32
|
filter = MongoAdapter.transformKeyValues(resource, request.key);
|
|
33
33
|
}
|
|
34
34
|
if (params?.filter) {
|
|
35
35
|
const f = MongoAdapter.transformFilter(params.filter);
|
|
36
36
|
filter = filter ? { $and: [filter, f] } : f;
|
|
37
37
|
}
|
|
38
|
-
if (
|
|
38
|
+
if (operation === 'findMany') {
|
|
39
39
|
options.sort = params?.sort;
|
|
40
40
|
options.limit = params?.limit;
|
|
41
41
|
options.skip = params?.skip;
|
|
@@ -43,7 +43,7 @@ var MongoAdapter;
|
|
|
43
43
|
options.count = params?.count;
|
|
44
44
|
}
|
|
45
45
|
options = (0, lodash_omitby_1.default)(options, lodash_isnil_1.default);
|
|
46
|
-
switch (
|
|
46
|
+
switch (operation) {
|
|
47
47
|
case 'create': {
|
|
48
48
|
return {
|
|
49
49
|
method: 'insertOne',
|
|
@@ -55,7 +55,7 @@ var MongoAdapter;
|
|
|
55
55
|
case 'delete':
|
|
56
56
|
case 'deleteMany': {
|
|
57
57
|
return {
|
|
58
|
-
method: (
|
|
58
|
+
method: (operation === 'delete' ? 'deleteOne' : 'deleteMany'),
|
|
59
59
|
filter,
|
|
60
60
|
options,
|
|
61
61
|
args: [filter, options]
|
|
@@ -102,7 +102,7 @@ var MongoAdapter;
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
throw new TypeError(`Unimplemented request kind (${request.resource.kind}.${request.
|
|
105
|
+
throw new TypeError(`Unimplemented request kind (${request.resource.kind}.${request.operation})`);
|
|
106
106
|
}
|
|
107
107
|
MongoAdapter.transformRequest = transformRequest;
|
|
108
108
|
})(MongoAdapter || (exports.MongoAdapter = MongoAdapter = {}));
|
package/esm/mongo-adapter.js
CHANGED
|
@@ -16,22 +16,22 @@ 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, operation } = request;
|
|
20
20
|
let options = {};
|
|
21
21
|
let filter;
|
|
22
|
-
if (
|
|
23
|
-
|
|
22
|
+
if (operation === 'create' || operation === 'update' ||
|
|
23
|
+
operation === 'get' || operation === 'findMany') {
|
|
24
24
|
options.projection = MongoAdapter.transformProjection(resource.type, params);
|
|
25
25
|
}
|
|
26
26
|
if (resource instanceof Collection &&
|
|
27
|
-
(
|
|
27
|
+
(operation === 'delete' || operation === 'get' || operation === 'update')) {
|
|
28
28
|
filter = MongoAdapter.transformKeyValues(resource, request.key);
|
|
29
29
|
}
|
|
30
30
|
if (params?.filter) {
|
|
31
31
|
const f = MongoAdapter.transformFilter(params.filter);
|
|
32
32
|
filter = filter ? { $and: [filter, f] } : f;
|
|
33
33
|
}
|
|
34
|
-
if (
|
|
34
|
+
if (operation === 'findMany') {
|
|
35
35
|
options.sort = params?.sort;
|
|
36
36
|
options.limit = params?.limit;
|
|
37
37
|
options.skip = params?.skip;
|
|
@@ -39,7 +39,7 @@ export var MongoAdapter;
|
|
|
39
39
|
options.count = params?.count;
|
|
40
40
|
}
|
|
41
41
|
options = omitBy(options, isNil);
|
|
42
|
-
switch (
|
|
42
|
+
switch (operation) {
|
|
43
43
|
case 'create': {
|
|
44
44
|
return {
|
|
45
45
|
method: 'insertOne',
|
|
@@ -51,7 +51,7 @@ export var MongoAdapter;
|
|
|
51
51
|
case 'delete':
|
|
52
52
|
case 'deleteMany': {
|
|
53
53
|
return {
|
|
54
|
-
method: (
|
|
54
|
+
method: (operation === 'delete' ? 'deleteOne' : 'deleteMany'),
|
|
55
55
|
filter,
|
|
56
56
|
options,
|
|
57
57
|
args: [filter, options]
|
|
@@ -98,7 +98,7 @@ export var MongoAdapter;
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
throw new TypeError(`Unimplemented request kind (${request.resource.kind}.${request.
|
|
101
|
+
throw new TypeError(`Unimplemented request kind (${request.resource.kind}.${request.operation})`);
|
|
102
102
|
}
|
|
103
103
|
MongoAdapter.transformRequest = transformRequest;
|
|
104
104
|
})(MongoAdapter || (MongoAdapter = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Opra MongoDB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@faker-js/faker": "^8.0.2",
|
|
32
32
|
"mongodb": "^6.0.0",
|
|
33
|
-
"ts-gems": "^2.
|
|
33
|
+
"ts-gems": "^2.5.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@opra/common": "^0.
|
|
37
|
-
"@opra/core": "^0.
|
|
36
|
+
"@opra/common": "^0.26.0",
|
|
37
|
+
"@opra/core": "^0.26.0",
|
|
38
38
|
"mongodb": ">=6.x.x"
|
|
39
39
|
},
|
|
40
40
|
"type": "module",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongodb from 'mongodb';
|
|
2
2
|
import { Maybe } from 'ts-gems';
|
|
3
3
|
import { Collection, ICollection, PartialOutput } from '@opra/common';
|
|
4
|
-
import {
|
|
4
|
+
import { RequestContext } from '@opra/core';
|
|
5
5
|
import { MongoEntityService } from './mongo-entity-service.js';
|
|
6
6
|
export declare namespace MongoCollection {
|
|
7
7
|
interface Options {
|
|
@@ -12,13 +12,13 @@ export declare abstract class MongoCollection<T extends mongodb.Document> implem
|
|
|
12
12
|
defaultLimit?: number;
|
|
13
13
|
constructor(options?: MongoCollection.Options);
|
|
14
14
|
create?(ctx: Collection.Create.Context): Promise<PartialOutput<T>>;
|
|
15
|
-
delete?(ctx:
|
|
16
|
-
deleteMany?(ctx:
|
|
17
|
-
get?(ctx:
|
|
18
|
-
update?(ctx:
|
|
19
|
-
updateMany?(ctx:
|
|
20
|
-
findMany?(ctx:
|
|
21
|
-
abstract getService(ctx:
|
|
22
|
-
onPrepare?(ctx:
|
|
23
|
-
protected _onPrepare(ctx:
|
|
15
|
+
delete?(ctx: RequestContext): Promise<number>;
|
|
16
|
+
deleteMany?(ctx: RequestContext): Promise<number>;
|
|
17
|
+
get?(ctx: RequestContext): Promise<Maybe<PartialOutput<T>>>;
|
|
18
|
+
update?(ctx: RequestContext): Promise<Maybe<PartialOutput<T>>>;
|
|
19
|
+
updateMany?(ctx: RequestContext): Promise<number>;
|
|
20
|
+
findMany?(ctx: RequestContext): Promise<PartialOutput<T>[]>;
|
|
21
|
+
abstract getService(ctx: RequestContext): MongoEntityService<T> | Promise<MongoEntityService<T>>;
|
|
22
|
+
onPrepare?(ctx: RequestContext, prepared: any): any;
|
|
23
|
+
protected _onPrepare(ctx: RequestContext, prepared: any): any;
|
|
24
24
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import mongodb, { UpdateFilter } from 'mongodb';
|
|
2
2
|
import { StrictOmit } from 'ts-gems';
|
|
3
|
-
import {
|
|
3
|
+
import { PartialOutput, RequestContext } from '@opra/core';
|
|
4
4
|
export declare namespace MongoEntityService {
|
|
5
5
|
interface Options {
|
|
6
6
|
db?: mongodb.Db;
|
|
@@ -9,7 +9,7 @@ export declare namespace MongoEntityService {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class MongoEntityService<T extends mongodb.Document> {
|
|
11
11
|
protected _collectionName: string;
|
|
12
|
-
context:
|
|
12
|
+
context: RequestContext;
|
|
13
13
|
defaultLimit: number;
|
|
14
14
|
db?: mongodb.Db;
|
|
15
15
|
session?: mongodb.ClientSession;
|
|
@@ -23,7 +23,7 @@ export declare class MongoEntityService<T extends mongodb.Document> {
|
|
|
23
23
|
insertOne(doc: mongodb.OptionalUnlessRequiredId<T>, options?: mongodb.InsertOneOptions): Promise<PartialOutput<T>>;
|
|
24
24
|
updateOne(filter: mongodb.Filter<T>, doc: UpdateFilter<T> | Partial<T>, options?: mongodb.UpdateOptions): Promise<PartialOutput<T> | undefined>;
|
|
25
25
|
updateMany(filter: mongodb.Filter<T>, doc: UpdateFilter<T> | Partial<T>, options?: StrictOmit<mongodb.UpdateOptions, 'upsert'>): Promise<number>;
|
|
26
|
-
with(context:
|
|
26
|
+
with(context: RequestContext, db?: mongodb.Db, session?: mongodb.ClientSession): MongoEntityService<T>;
|
|
27
27
|
protected _onError(error: unknown): Promise<void>;
|
|
28
28
|
protected getDatabase(): mongodb.Db | Promise<mongodb.Db>;
|
|
29
29
|
protected getCollection(db: mongodb.Db): Promise<mongodb.Collection<T>>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import mongodb from 'mongodb';
|
|
2
2
|
import { Maybe } from 'ts-gems';
|
|
3
3
|
import { PartialOutput } from '@opra/common';
|
|
4
|
-
import {
|
|
4
|
+
import { RequestContext } from '@opra/core';
|
|
5
5
|
import { MongoEntityService } from './mongo-entity-service.js';
|
|
6
6
|
export declare abstract class MongoSingleton<T extends mongodb.Document> {
|
|
7
7
|
defaultLimit: number;
|
|
8
|
-
create?(ctx:
|
|
9
|
-
delete?(ctx:
|
|
10
|
-
get?(ctx:
|
|
11
|
-
update?(ctx:
|
|
12
|
-
abstract getService(ctx:
|
|
8
|
+
create?(ctx: RequestContext): Promise<PartialOutput<T>>;
|
|
9
|
+
delete?(ctx: RequestContext): Promise<number>;
|
|
10
|
+
get?(ctx: RequestContext): Promise<Maybe<PartialOutput<T>>>;
|
|
11
|
+
update?(ctx: RequestContext): Promise<Maybe<PartialOutput<T>>>;
|
|
12
|
+
abstract getService(ctx: RequestContext): MongoEntityService<T> | Promise<MongoEntityService<T>>;
|
|
13
13
|
}
|