@opra/mongodb 0.16.1 → 0.17.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-collection-resource.js +2 -2
- package/esm/index.js +4 -7
- package/esm/mongo-adapter.js +18 -22
- package/esm/mongo-collection-resource.js +50 -54
- package/esm/mongo-entity-service.js +1 -5
- package/esm/mongo-singleton-resource.js +30 -34
- package/esm/transform-filter.js +15 -18
- package/esm/transform-key-values.js +1 -4
- package/esm/transform-patch.js +1 -4
- package/esm/transform-projection.js +9 -15
- package/esm/transform-sort.js +1 -4
- package/package.json +3 -3
- package/types/mongo-collection-resource.d.ts +1 -1
|
@@ -44,7 +44,7 @@ class MongoCollectionResource {
|
|
|
44
44
|
const service = await this.getService(ctx);
|
|
45
45
|
return service.updateMany(prepared.filter, prepared.update, prepared.options);
|
|
46
46
|
}
|
|
47
|
-
async
|
|
47
|
+
async findMany(ctx) {
|
|
48
48
|
const prepared = mongo_adapter_js_1.MongoAdapter.transformRequest(ctx.request);
|
|
49
49
|
const service = await this.getService(ctx);
|
|
50
50
|
if (prepared.count) {
|
|
@@ -99,5 +99,5 @@ tslib_1.__decorate([
|
|
|
99
99
|
tslib_1.__metadata("design:type", Function),
|
|
100
100
|
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
101
101
|
tslib_1.__metadata("design:returntype", Promise)
|
|
102
|
-
], MongoCollectionResource.prototype, "
|
|
102
|
+
], MongoCollectionResource.prototype, "findMany", null);
|
|
103
103
|
exports.MongoCollectionResource = MongoCollectionResource;
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tslib_1.__exportStar(require("./mongo-collection-resource.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./mongo-entity-service.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./mongo-singleton-resource.js"), exports);
|
|
1
|
+
export * from './mongo-adapter.js';
|
|
2
|
+
export * from './mongo-collection-resource.js';
|
|
3
|
+
export * from './mongo-entity-service.js';
|
|
4
|
+
export * from './mongo-singleton-resource.js';
|
package/esm/mongo-adapter.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const transform_patch_js_1 = tslib_1.__importDefault(require("./transform-patch.js"));
|
|
11
|
-
const transform_projection_js_1 = tslib_1.__importDefault(require("./transform-projection.js"));
|
|
12
|
-
const transform_sort_js_1 = tslib_1.__importDefault(require("./transform-sort.js"));
|
|
13
|
-
var MongoAdapter;
|
|
1
|
+
import isNil from 'lodash.isnil';
|
|
2
|
+
import omitBy from 'lodash.omitby';
|
|
3
|
+
import { Collection, Singleton } from '@opra/common';
|
|
4
|
+
import _transformFilter from './transform-filter.js';
|
|
5
|
+
import _transformKeyValues from './transform-key-values.js';
|
|
6
|
+
import _transformPatch from './transform-patch.js';
|
|
7
|
+
import _transformProjection from './transform-projection.js';
|
|
8
|
+
import _transformSort from './transform-sort.js';
|
|
9
|
+
export var MongoAdapter;
|
|
14
10
|
(function (MongoAdapter) {
|
|
15
|
-
MongoAdapter.transformFilter =
|
|
16
|
-
MongoAdapter.transformKeyValues =
|
|
17
|
-
MongoAdapter.transformPatch =
|
|
18
|
-
MongoAdapter.transformProjection =
|
|
19
|
-
MongoAdapter.transformSort =
|
|
11
|
+
MongoAdapter.transformFilter = _transformFilter;
|
|
12
|
+
MongoAdapter.transformKeyValues = _transformKeyValues;
|
|
13
|
+
MongoAdapter.transformPatch = _transformPatch;
|
|
14
|
+
MongoAdapter.transformProjection = _transformProjection;
|
|
15
|
+
MongoAdapter.transformSort = _transformSort;
|
|
20
16
|
function transformRequest(request) {
|
|
21
17
|
const { resource } = request;
|
|
22
|
-
if (resource instanceof
|
|
18
|
+
if (resource instanceof Collection || resource instanceof Singleton) {
|
|
23
19
|
const { args, operation } = request;
|
|
24
20
|
let options = {};
|
|
25
21
|
let filter;
|
|
@@ -27,7 +23,7 @@ var MongoAdapter;
|
|
|
27
23
|
operation === 'get' || operation === 'findMany') {
|
|
28
24
|
options.projection = MongoAdapter.transformProjection(resource.type, args);
|
|
29
25
|
}
|
|
30
|
-
if (resource instanceof
|
|
26
|
+
if (resource instanceof Collection &&
|
|
31
27
|
(operation === 'delete' || operation === 'get' || operation === 'update')) {
|
|
32
28
|
filter = MongoAdapter.transformKeyValues(resource, args.key);
|
|
33
29
|
}
|
|
@@ -42,7 +38,7 @@ var MongoAdapter;
|
|
|
42
38
|
options.distinct = args.distinct;
|
|
43
39
|
options.count = args.count;
|
|
44
40
|
}
|
|
45
|
-
options = (
|
|
41
|
+
options = omitBy(options, isNil);
|
|
46
42
|
switch (operation) {
|
|
47
43
|
case 'create': {
|
|
48
44
|
return {
|
|
@@ -106,4 +102,4 @@ var MongoAdapter;
|
|
|
106
102
|
throw new TypeError(`Unimplemented request kind (${request.resourceKind}.${request.operation})`);
|
|
107
103
|
}
|
|
108
104
|
MongoAdapter.transformRequest = transformRequest;
|
|
109
|
-
})(MongoAdapter
|
|
105
|
+
})(MongoAdapter || (MongoAdapter = {}));
|
|
@@ -1,51 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const common_1 = require("@opra/common");
|
|
6
|
-
const mongo_adapter_js_1 = require("./mongo-adapter.js");
|
|
7
|
-
class MongoCollectionResource {
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Collection, ResourceNotFoundError } from '@opra/common';
|
|
3
|
+
import { MongoAdapter } from './mongo-adapter.js';
|
|
4
|
+
export class MongoCollectionResource {
|
|
8
5
|
constructor() {
|
|
9
6
|
this.defaultLimit = 100;
|
|
10
7
|
}
|
|
11
8
|
async create(ctx) {
|
|
12
|
-
const prepared =
|
|
9
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
13
10
|
const service = await this.getService(ctx);
|
|
14
11
|
return service.insertOne(prepared.data, prepared.options);
|
|
15
12
|
}
|
|
16
13
|
async delete(ctx) {
|
|
17
|
-
const prepared =
|
|
14
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
18
15
|
const service = await this.getService(ctx);
|
|
19
16
|
return service.deleteOne(prepared.filter, prepared.options);
|
|
20
17
|
}
|
|
21
18
|
async deleteMany(ctx) {
|
|
22
|
-
const prepared =
|
|
19
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
23
20
|
const service = await this.getService(ctx);
|
|
24
21
|
return service.deleteMany(prepared.filter, prepared.options);
|
|
25
22
|
}
|
|
26
23
|
async get(ctx) {
|
|
27
|
-
const prepared =
|
|
24
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
28
25
|
const service = await this.getService(ctx);
|
|
29
26
|
const out = await service.findOne(prepared.filter, prepared.options);
|
|
30
27
|
if (!out)
|
|
31
|
-
throw new
|
|
28
|
+
throw new ResourceNotFoundError(service.collectionName, prepared.filter._id);
|
|
32
29
|
return out;
|
|
33
30
|
}
|
|
34
31
|
async update(ctx) {
|
|
35
|
-
const prepared =
|
|
32
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
36
33
|
const service = await this.getService(ctx);
|
|
37
34
|
const out = await service.updateOne(prepared.filter, prepared.update, prepared.options);
|
|
38
35
|
if (!out)
|
|
39
|
-
throw new
|
|
36
|
+
throw new ResourceNotFoundError(service.collectionName, prepared.filter._id);
|
|
40
37
|
return out;
|
|
41
38
|
}
|
|
42
39
|
async updateMany(ctx) {
|
|
43
|
-
const prepared =
|
|
40
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
44
41
|
const service = await this.getService(ctx);
|
|
45
42
|
return service.updateMany(prepared.filter, prepared.update, prepared.options);
|
|
46
43
|
}
|
|
47
|
-
async
|
|
48
|
-
const prepared =
|
|
44
|
+
async findMany(ctx) {
|
|
45
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
49
46
|
const service = await this.getService(ctx);
|
|
50
47
|
if (prepared.count) {
|
|
51
48
|
const [items, count] = await Promise.all([
|
|
@@ -58,46 +55,45 @@ class MongoCollectionResource {
|
|
|
58
55
|
return service.find(prepared.filter, prepared.options);
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
__decorate([
|
|
59
|
+
Collection.Create(),
|
|
60
|
+
__metadata("design:type", Function),
|
|
61
|
+
__metadata("design:paramtypes", [Object]),
|
|
62
|
+
__metadata("design:returntype", Promise)
|
|
66
63
|
], MongoCollectionResource.prototype, "create", null);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
__decorate([
|
|
65
|
+
Collection.Delete(),
|
|
66
|
+
__metadata("design:type", Function),
|
|
67
|
+
__metadata("design:paramtypes", [Object]),
|
|
68
|
+
__metadata("design:returntype", Promise)
|
|
72
69
|
], MongoCollectionResource.prototype, "delete", null);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
__decorate([
|
|
71
|
+
Collection.DeleteMany(),
|
|
72
|
+
__metadata("design:type", Function),
|
|
73
|
+
__metadata("design:paramtypes", [Object]),
|
|
74
|
+
__metadata("design:returntype", Promise)
|
|
78
75
|
], MongoCollectionResource.prototype, "deleteMany", null);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
__decorate([
|
|
77
|
+
Collection.Get(),
|
|
78
|
+
__metadata("design:type", Function),
|
|
79
|
+
__metadata("design:paramtypes", [Object]),
|
|
80
|
+
__metadata("design:returntype", Promise)
|
|
84
81
|
], MongoCollectionResource.prototype, "get", null);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
__decorate([
|
|
83
|
+
Collection.Update(),
|
|
84
|
+
__metadata("design:type", Function),
|
|
85
|
+
__metadata("design:paramtypes", [Object]),
|
|
86
|
+
__metadata("design:returntype", Promise)
|
|
90
87
|
], MongoCollectionResource.prototype, "update", null);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
__decorate([
|
|
89
|
+
Collection.UpdateMany(),
|
|
90
|
+
__metadata("design:type", Function),
|
|
91
|
+
__metadata("design:paramtypes", [Object]),
|
|
92
|
+
__metadata("design:returntype", Promise)
|
|
96
93
|
], MongoCollectionResource.prototype, "updateMany", null);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
], MongoCollectionResource.prototype, "
|
|
103
|
-
exports.MongoCollectionResource = MongoCollectionResource;
|
|
94
|
+
__decorate([
|
|
95
|
+
Collection.FindMany(),
|
|
96
|
+
__metadata("design:type", Function),
|
|
97
|
+
__metadata("design:paramtypes", [Object]),
|
|
98
|
+
__metadata("design:returntype", Promise)
|
|
99
|
+
], MongoCollectionResource.prototype, "findMany", null);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongoEntityService = void 0;
|
|
4
|
-
class MongoEntityService {
|
|
1
|
+
export class MongoEntityService {
|
|
5
2
|
constructor(collectionName, options) {
|
|
6
3
|
this.collectionName = collectionName;
|
|
7
4
|
this.db = options?.db;
|
|
@@ -176,4 +173,3 @@ class MongoEntityService {
|
|
|
176
173
|
return this.db;
|
|
177
174
|
}
|
|
178
175
|
}
|
|
179
|
-
exports.MongoEntityService = MongoEntityService;
|
|
@@ -1,63 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const common_1 = require("@opra/common");
|
|
6
|
-
const mongo_adapter_js_1 = require("./mongo-adapter.js");
|
|
7
|
-
class MongoSingletonResource {
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { ResourceNotFoundError, Singleton } from '@opra/common';
|
|
3
|
+
import { MongoAdapter } from './mongo-adapter.js';
|
|
4
|
+
export class MongoSingletonResource {
|
|
8
5
|
constructor() {
|
|
9
6
|
this.defaultLimit = 100;
|
|
10
7
|
}
|
|
11
8
|
async create(ctx) {
|
|
12
|
-
const prepared =
|
|
9
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
13
10
|
const service = await this.getService(ctx);
|
|
14
11
|
await service.deleteMany();
|
|
15
12
|
return service.insertOne(prepared.data, prepared.options);
|
|
16
13
|
}
|
|
17
14
|
async delete(ctx) {
|
|
18
|
-
const prepared =
|
|
15
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
19
16
|
const service = await this.getService(ctx);
|
|
20
17
|
return service.deleteOne(prepared.filter, prepared.options);
|
|
21
18
|
}
|
|
22
19
|
async get(ctx) {
|
|
23
|
-
const prepared =
|
|
20
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
24
21
|
const service = await this.getService(ctx);
|
|
25
22
|
const out = await service.findOne(prepared.filter, prepared.options);
|
|
26
23
|
if (!out)
|
|
27
|
-
throw new
|
|
24
|
+
throw new ResourceNotFoundError(service.collectionName);
|
|
28
25
|
return out;
|
|
29
26
|
}
|
|
30
27
|
async update(ctx) {
|
|
31
|
-
const prepared =
|
|
28
|
+
const prepared = MongoAdapter.transformRequest(ctx.request);
|
|
32
29
|
const service = await this.getService(ctx);
|
|
33
30
|
const out = await service.updateOne(prepared.filter, prepared.update, prepared.options);
|
|
34
31
|
if (!out)
|
|
35
|
-
throw new
|
|
32
|
+
throw new ResourceNotFoundError(service.collectionName, prepared.filter._id);
|
|
36
33
|
return out;
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
__decorate([
|
|
37
|
+
Singleton.Create(),
|
|
38
|
+
__metadata("design:type", Function),
|
|
39
|
+
__metadata("design:paramtypes", [Object]),
|
|
40
|
+
__metadata("design:returntype", Promise)
|
|
44
41
|
], MongoSingletonResource.prototype, "create", null);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
__decorate([
|
|
43
|
+
Singleton.Delete(),
|
|
44
|
+
__metadata("design:type", Function),
|
|
45
|
+
__metadata("design:paramtypes", [Object]),
|
|
46
|
+
__metadata("design:returntype", Promise)
|
|
50
47
|
], MongoSingletonResource.prototype, "delete", null);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
__decorate([
|
|
49
|
+
Singleton.Get(),
|
|
50
|
+
__metadata("design:type", Function),
|
|
51
|
+
__metadata("design:paramtypes", [Object]),
|
|
52
|
+
__metadata("design:returntype", Promise)
|
|
56
53
|
], MongoSingletonResource.prototype, "get", null);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
__decorate([
|
|
55
|
+
Singleton.Update(),
|
|
56
|
+
__metadata("design:type", Function),
|
|
57
|
+
__metadata("design:paramtypes", [Object]),
|
|
58
|
+
__metadata("design:returntype", Promise)
|
|
62
59
|
], MongoSingletonResource.prototype, "update", null);
|
|
63
|
-
exports.MongoSingletonResource = MongoSingletonResource;
|
package/esm/transform-filter.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
function transformFilter(str) {
|
|
5
|
-
const ast = typeof str === 'string' ? (0, common_1.parseFilter)(str) : str;
|
|
1
|
+
import { ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, LogicalExpression, NullLiteral, NumberLiteral, ParenthesesExpression, parseFilter, QualifiedIdentifier, StringLiteral, TimeLiteral } from '@opra/common';
|
|
2
|
+
export default function transformFilter(str) {
|
|
3
|
+
const ast = typeof str === 'string' ? parseFilter(str) : str;
|
|
6
4
|
if (!ast)
|
|
7
5
|
return;
|
|
8
|
-
if (ast instanceof
|
|
9
|
-
const left = ast.left instanceof
|
|
6
|
+
if (ast instanceof ComparisonExpression) {
|
|
7
|
+
const left = ast.left instanceof QualifiedIdentifier
|
|
10
8
|
? ast.left.value
|
|
11
9
|
: transformFilter(ast.left);
|
|
12
10
|
const right = transformFilter(ast.right);
|
|
@@ -69,28 +67,27 @@ function transformFilter(str) {
|
|
|
69
67
|
throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
|
-
if (ast instanceof
|
|
70
|
+
if (ast instanceof QualifiedIdentifier) {
|
|
73
71
|
return ast.value;
|
|
74
72
|
}
|
|
75
|
-
if (ast instanceof
|
|
76
|
-
ast instanceof
|
|
77
|
-
ast instanceof
|
|
78
|
-
ast instanceof
|
|
79
|
-
ast instanceof
|
|
80
|
-
ast instanceof
|
|
73
|
+
if (ast instanceof NumberLiteral ||
|
|
74
|
+
ast instanceof StringLiteral ||
|
|
75
|
+
ast instanceof BooleanLiteral ||
|
|
76
|
+
ast instanceof NullLiteral ||
|
|
77
|
+
ast instanceof DateLiteral ||
|
|
78
|
+
ast instanceof TimeLiteral) {
|
|
81
79
|
return ast.value;
|
|
82
80
|
}
|
|
83
|
-
if (ast instanceof
|
|
81
|
+
if (ast instanceof ArrayExpression) {
|
|
84
82
|
return ast.items.map(transformFilter);
|
|
85
83
|
}
|
|
86
|
-
if (ast instanceof
|
|
84
|
+
if (ast instanceof LogicalExpression) {
|
|
87
85
|
if (ast.op === 'or')
|
|
88
86
|
return { $or: ast.items.map(transformFilter) };
|
|
89
87
|
return { $and: ast.items.map(transformFilter) };
|
|
90
88
|
}
|
|
91
|
-
if (ast instanceof
|
|
89
|
+
if (ast instanceof ParenthesesExpression) {
|
|
92
90
|
return transformFilter(ast.expression);
|
|
93
91
|
}
|
|
94
92
|
throw new Error(`${ast.type} is not implemented yet`);
|
|
95
93
|
}
|
|
96
|
-
exports.default = transformFilter;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function transformKeyValues(resource, keyValues) {
|
|
1
|
+
export default function transformKeyValues(resource, keyValues) {
|
|
4
2
|
const { primaryKey } = resource;
|
|
5
3
|
if (primaryKey.length > 1) {
|
|
6
4
|
const query = {};
|
|
@@ -11,4 +9,3 @@ function transformKeyValues(resource, keyValues) {
|
|
|
11
9
|
}
|
|
12
10
|
return { [primaryKey[0]]: keyValues };
|
|
13
11
|
}
|
|
14
|
-
exports.default = transformKeyValues;
|
package/esm/transform-patch.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function transformPatch(doc) {
|
|
1
|
+
export default function transformPatch(doc) {
|
|
4
2
|
const trg = {};
|
|
5
3
|
_transformPatch(doc, trg);
|
|
6
4
|
return trg;
|
|
7
5
|
}
|
|
8
|
-
exports.default = transformPatch;
|
|
9
6
|
function _transformPatch(src, trg = {}, path = '') {
|
|
10
7
|
let fieldName;
|
|
11
8
|
for (const [k, v] of Object.entries(src)) {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports._transformExclusionProjection = exports._transformInclusionProjection = void 0;
|
|
4
|
-
const common_1 = require("@opra/common");
|
|
5
|
-
function transformProjection(dataType, args) {
|
|
1
|
+
import { ComplexType, pathToObjectTree } from '@opra/common';
|
|
2
|
+
export default function transformProjection(dataType, args) {
|
|
6
3
|
const out = {};
|
|
7
4
|
// omitExclusiveFields(dataType, out);
|
|
8
|
-
const pick = args.pick &&
|
|
9
|
-
const include = !args.pick && args.include &&
|
|
10
|
-
const omit = args.omit &&
|
|
5
|
+
const pick = args.pick && pathToObjectTree(args.include ? [...args.pick, ...args.include] : args.pick);
|
|
6
|
+
const include = !args.pick && args.include && pathToObjectTree(args.include);
|
|
7
|
+
const omit = args.omit && pathToObjectTree(args.omit);
|
|
11
8
|
if (pick || include) {
|
|
12
9
|
_transformInclusionProjection(dataType, out, pick, include, omit);
|
|
13
10
|
}
|
|
@@ -15,8 +12,7 @@ function transformProjection(dataType, args) {
|
|
|
15
12
|
_transformExclusionProjection(dataType, out, omit, !omit);
|
|
16
13
|
return Object.keys(out).length ? out : undefined;
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
function _transformInclusionProjection(dataType, target, pick, include, omit, defaultFields) {
|
|
15
|
+
export function _transformInclusionProjection(dataType, target, pick, include, omit, defaultFields) {
|
|
20
16
|
defaultFields = defaultFields ?? !pick;
|
|
21
17
|
let n;
|
|
22
18
|
for (const [k, f] of dataType.fields.entries()) {
|
|
@@ -25,7 +21,7 @@ function _transformInclusionProjection(dataType, target, pick, include, omit, de
|
|
|
25
21
|
n = (defaultFields && !f.exclusive) ||
|
|
26
22
|
pick === true || pick?.[k] || include === true || include?.[k];
|
|
27
23
|
if (n) {
|
|
28
|
-
if (f.type instanceof
|
|
24
|
+
if (f.type instanceof ComplexType && (typeof n === 'object' || typeof omit?.[k] === 'object')) {
|
|
29
25
|
target[k] = {};
|
|
30
26
|
_transformInclusionProjection(f.type, target[k], pick?.[k] || include?.[k], undefined, omit?.[k], defaultFields);
|
|
31
27
|
continue;
|
|
@@ -34,13 +30,12 @@ function _transformInclusionProjection(dataType, target, pick, include, omit, de
|
|
|
34
30
|
}
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
function _transformExclusionProjection(dataType, target, omit, omitExclusiveFields) {
|
|
33
|
+
export function _transformExclusionProjection(dataType, target, omit, omitExclusiveFields) {
|
|
39
34
|
let n;
|
|
40
35
|
for (const [k, f] of dataType.fields.entries()) {
|
|
41
36
|
n = omit?.[k] || (omitExclusiveFields && f.exclusive);
|
|
42
37
|
if (n) {
|
|
43
|
-
if (f.type instanceof
|
|
38
|
+
if (f.type instanceof ComplexType && typeof n === 'object') {
|
|
44
39
|
target[k] = {};
|
|
45
40
|
_transformExclusionProjection(f.type, target[k], omit?.[k], omitExclusiveFields);
|
|
46
41
|
continue;
|
|
@@ -49,4 +44,3 @@ function _transformExclusionProjection(dataType, target, omit, omitExclusiveFiel
|
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
|
-
exports._transformExclusionProjection = _transformExclusionProjection;
|
package/esm/transform-sort.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function transformSort(sort) {
|
|
1
|
+
export default function transformSort(sort) {
|
|
4
2
|
if (!(sort && sort.length))
|
|
5
3
|
return;
|
|
6
4
|
const out = {};
|
|
@@ -15,4 +13,3 @@ function transformSort(sort) {
|
|
|
15
13
|
});
|
|
16
14
|
return out;
|
|
17
15
|
}
|
|
18
|
-
exports.default = transformSort;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Opra MongoDB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"ts-gems": "^2.3.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@opra/common": "^0.
|
|
37
|
-
"@opra/core": "^0.
|
|
36
|
+
"@opra/common": "^0.17.0",
|
|
37
|
+
"@opra/core": "^0.17.0",
|
|
38
38
|
"mongodb": ">=4.x.x"
|
|
39
39
|
},
|
|
40
40
|
"type": "module",
|
|
@@ -10,6 +10,6 @@ export declare abstract class MongoCollectionResource<T extends mongodb.Document
|
|
|
10
10
|
get(ctx: RequestContext): Promise<TOutput>;
|
|
11
11
|
update(ctx: RequestContext): Promise<TOutput>;
|
|
12
12
|
updateMany(ctx: RequestContext): Promise<number>;
|
|
13
|
-
|
|
13
|
+
findMany(ctx: RequestContext): Promise<TOutput[]>;
|
|
14
14
|
abstract getService(ctx: RequestContext): MongoEntityService<T, TOutput> | Promise<MongoEntityService<T, TOutput>>;
|
|
15
15
|
}
|