@opra/nestjs 1.0.0-alpha.21 → 1.0.0-alpha.23
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.
|
@@ -25,7 +25,7 @@ class OpraNestAdapter extends core_1.HttpAdapter {
|
|
|
25
25
|
basePath = '/' + basePath;
|
|
26
26
|
this._addRootController(basePath);
|
|
27
27
|
if (init.controllers)
|
|
28
|
-
init.controllers.forEach(c => this._addToNestControllers(c, basePath));
|
|
28
|
+
init.controllers.forEach(c => this._addToNestControllers(c, basePath, []));
|
|
29
29
|
}
|
|
30
30
|
async close() {
|
|
31
31
|
//
|
|
@@ -55,7 +55,7 @@ class OpraNestAdapter extends core_1.HttpAdapter {
|
|
|
55
55
|
}
|
|
56
56
|
this.nestControllers.push(RootController);
|
|
57
57
|
}
|
|
58
|
-
_addToNestControllers(sourceClass, currentPath,
|
|
58
|
+
_addToNestControllers(sourceClass, currentPath, parentTree) {
|
|
59
59
|
const metadata = Reflect.getMetadata(common_2.HTTP_CONTROLLER_METADATA, sourceClass);
|
|
60
60
|
if (!metadata)
|
|
61
61
|
return;
|
|
@@ -65,9 +65,7 @@ class OpraNestAdapter extends core_1.HttpAdapter {
|
|
|
65
65
|
}[sourceClass.name];
|
|
66
66
|
/** Copy metadata keys from source class to new one */
|
|
67
67
|
let metadataKeys;
|
|
68
|
-
|
|
69
|
-
OpraNestAdapter.copyDecoratorMetadataToChild(newClass, parentClass);
|
|
70
|
-
}
|
|
68
|
+
OpraNestAdapter.copyDecoratorMetadataToChild(newClass, parentTree);
|
|
71
69
|
const newPath = metadata.path ? path_1.default.join(currentPath, metadata.path) : currentPath;
|
|
72
70
|
const adapter = this;
|
|
73
71
|
/** Inject exception filter */
|
|
@@ -158,23 +156,27 @@ class OpraNestAdapter extends core_1.HttpAdapter {
|
|
|
158
156
|
for (const child of metadata.controllers) {
|
|
159
157
|
if (!(0, common_2.isConstructor)(child))
|
|
160
158
|
throw new TypeError('Controllers should be injectable a class');
|
|
161
|
-
this._addToNestControllers(child, newPath, sourceClass);
|
|
159
|
+
this._addToNestControllers(child, newPath, [...parentTree, sourceClass]);
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
162
|
}
|
|
165
|
-
static copyDecoratorMetadataToChild(target,
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
163
|
+
static copyDecoratorMetadataToChild(target, parentTree) {
|
|
164
|
+
for (const parent of parentTree) {
|
|
165
|
+
const metadataKeys = Reflect.getOwnMetadataKeys(parent);
|
|
166
|
+
for (const key of metadataKeys) {
|
|
167
|
+
if (key === constants_1.GUARDS_METADATA || key === constants_1.INTERCEPTORS_METADATA || key === constants_1.EXCEPTION_FILTERS_METADATA) {
|
|
168
|
+
const m1 = Reflect.getMetadata(key, target) || [];
|
|
169
|
+
const m2 = Reflect.getOwnMetadata(key, parent) || [];
|
|
170
|
+
const metadata = [...m1];
|
|
171
|
+
m2.forEach((t) => {
|
|
172
|
+
if (!metadata.includes(t)) {
|
|
173
|
+
metadata.push(t);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
Reflect.defineMetadata(key, metadata, target);
|
|
177
|
+
}
|
|
172
178
|
}
|
|
173
179
|
}
|
|
174
|
-
const subParent = Object.getPrototypeOf(parent.prototype).constructor;
|
|
175
|
-
if (subParent && subParent !== Object) {
|
|
176
|
-
this.copyDecoratorMetadataToChild(target, subParent);
|
|
177
|
-
}
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
182
|
exports.OpraNestAdapter = OpraNestAdapter;
|
|
@@ -22,7 +22,7 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
22
22
|
basePath = '/' + basePath;
|
|
23
23
|
this._addRootController(basePath);
|
|
24
24
|
if (init.controllers)
|
|
25
|
-
init.controllers.forEach(c => this._addToNestControllers(c, basePath));
|
|
25
|
+
init.controllers.forEach(c => this._addToNestControllers(c, basePath, []));
|
|
26
26
|
}
|
|
27
27
|
async close() {
|
|
28
28
|
//
|
|
@@ -52,7 +52,7 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
52
52
|
}
|
|
53
53
|
this.nestControllers.push(RootController);
|
|
54
54
|
}
|
|
55
|
-
_addToNestControllers(sourceClass, currentPath,
|
|
55
|
+
_addToNestControllers(sourceClass, currentPath, parentTree) {
|
|
56
56
|
const metadata = Reflect.getMetadata(HTTP_CONTROLLER_METADATA, sourceClass);
|
|
57
57
|
if (!metadata)
|
|
58
58
|
return;
|
|
@@ -62,9 +62,7 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
62
62
|
}[sourceClass.name];
|
|
63
63
|
/** Copy metadata keys from source class to new one */
|
|
64
64
|
let metadataKeys;
|
|
65
|
-
|
|
66
|
-
OpraNestAdapter.copyDecoratorMetadataToChild(newClass, parentClass);
|
|
67
|
-
}
|
|
65
|
+
OpraNestAdapter.copyDecoratorMetadataToChild(newClass, parentTree);
|
|
68
66
|
const newPath = metadata.path ? nodePath.join(currentPath, metadata.path) : currentPath;
|
|
69
67
|
const adapter = this;
|
|
70
68
|
/** Inject exception filter */
|
|
@@ -155,22 +153,26 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
155
153
|
for (const child of metadata.controllers) {
|
|
156
154
|
if (!isConstructor(child))
|
|
157
155
|
throw new TypeError('Controllers should be injectable a class');
|
|
158
|
-
this._addToNestControllers(child, newPath, sourceClass);
|
|
156
|
+
this._addToNestControllers(child, newPath, [...parentTree, sourceClass]);
|
|
159
157
|
}
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
|
-
static copyDecoratorMetadataToChild(target,
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
160
|
+
static copyDecoratorMetadataToChild(target, parentTree) {
|
|
161
|
+
for (const parent of parentTree) {
|
|
162
|
+
const metadataKeys = Reflect.getOwnMetadataKeys(parent);
|
|
163
|
+
for (const key of metadataKeys) {
|
|
164
|
+
if (key === GUARDS_METADATA || key === INTERCEPTORS_METADATA || key === EXCEPTION_FILTERS_METADATA) {
|
|
165
|
+
const m1 = Reflect.getMetadata(key, target) || [];
|
|
166
|
+
const m2 = Reflect.getOwnMetadata(key, parent) || [];
|
|
167
|
+
const metadata = [...m1];
|
|
168
|
+
m2.forEach((t) => {
|
|
169
|
+
if (!metadata.includes(t)) {
|
|
170
|
+
metadata.push(t);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
Reflect.defineMetadata(key, metadata, target);
|
|
174
|
+
}
|
|
169
175
|
}
|
|
170
176
|
}
|
|
171
|
-
const subParent = Object.getPrototypeOf(parent.prototype).constructor;
|
|
172
|
-
if (subParent && subParent !== Object) {
|
|
173
|
-
this.copyDecoratorMetadataToChild(target, subParent);
|
|
174
|
-
}
|
|
175
177
|
}
|
|
176
178
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/nestjs",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.23",
|
|
4
4
|
"description": "Opra NestJS module",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"clean:cover": "rimraf ../../coverage/client"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@opra/common": "^1.0.0-alpha.
|
|
31
|
-
"@opra/core": "^1.0.0-alpha.
|
|
30
|
+
"@opra/common": "^1.0.0-alpha.23",
|
|
31
|
+
"@opra/core": "^1.0.0-alpha.23",
|
|
32
32
|
"fast-tokenizer": "^1.3.0",
|
|
33
33
|
"lodash.head": "^4.0.1",
|
|
34
34
|
"reflect-metadata": "^0.2.2"
|
|
@@ -8,6 +8,6 @@ export declare class OpraNestAdapter extends HttpAdapter {
|
|
|
8
8
|
constructor(init: OpraHttpModule.Initiator, options?: OpraHttpModule.Options);
|
|
9
9
|
close(): Promise<void>;
|
|
10
10
|
protected _addRootController(basePath: string): void;
|
|
11
|
-
protected _addToNestControllers(sourceClass: Type, currentPath: string,
|
|
12
|
-
static copyDecoratorMetadataToChild(target: Type,
|
|
11
|
+
protected _addToNestControllers(sourceClass: Type, currentPath: string, parentTree: Type[]): void;
|
|
12
|
+
static copyDecoratorMetadataToChild(target: Type, parentTree: Type[]): void;
|
|
13
13
|
}
|