@opra/nestjs 1.0.0-alpha.18 → 1.0.0-alpha.19

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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpraNestAdapter = exports.kHandler = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@nestjs/common");
6
+ const constants_1 = require("@nestjs/common/constants");
6
7
  const common_2 = require("@opra/common");
7
8
  const core_1 = require("@opra/core");
8
9
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -65,11 +66,7 @@ class OpraNestAdapter extends core_1.HttpAdapter {
65
66
  /** Copy metadata keys from source class to new one */
66
67
  let metadataKeys;
67
68
  if (parentClass) {
68
- metadataKeys = Reflect.getOwnMetadataKeys(parentClass);
69
- for (const key of metadataKeys) {
70
- const m = Reflect.getMetadata(key, parentClass);
71
- Reflect.defineMetadata(key, m, newClass);
72
- }
69
+ OpraNestAdapter.copyDecoratorMetadataToChild(newClass, sourceClass, parentClass);
73
70
  }
74
71
  const newPath = metadata.path ? path_1.default.join(currentPath, metadata.path) : currentPath;
75
72
  const adapter = this;
@@ -165,5 +162,15 @@ class OpraNestAdapter extends core_1.HttpAdapter {
165
162
  }
166
163
  }
167
164
  }
165
+ static copyDecoratorMetadataToChild(target, source, parent) {
166
+ const metadataKeys = Reflect.getOwnMetadataKeys(parent);
167
+ for (const key of metadataKeys) {
168
+ if (key === constants_1.GUARDS_METADATA || key === constants_1.INTERCEPTORS_METADATA || key === constants_1.EXCEPTION_FILTERS_METADATA) {
169
+ const m1 = Reflect.getMetadata(key, source) || [];
170
+ const m2 = Reflect.getMetadata(key, parent) || [];
171
+ Reflect.defineMetadata(key, [...m1, ...m2], target);
172
+ }
173
+ }
174
+ }
168
175
  }
169
176
  exports.OpraNestAdapter = OpraNestAdapter;
@@ -1,5 +1,6 @@
1
1
  import { __decorate, __metadata, __param } from "tslib";
2
2
  import { Controller, Delete, Get, Head, Next, Options, Patch, Post, Put, Req, Res, Search, UseFilters, } from '@nestjs/common';
3
+ import { EXCEPTION_FILTERS_METADATA, GUARDS_METADATA, INTERCEPTORS_METADATA } from '@nestjs/common/constants';
3
4
  import { ApiDocument, HTTP_CONTROLLER_METADATA, HttpApi, isConstructor, NotFoundError, } from '@opra/common';
4
5
  import { HttpAdapter } from '@opra/core';
5
6
  import nodePath from 'path';
@@ -62,11 +63,7 @@ export class OpraNestAdapter extends HttpAdapter {
62
63
  /** Copy metadata keys from source class to new one */
63
64
  let metadataKeys;
64
65
  if (parentClass) {
65
- metadataKeys = Reflect.getOwnMetadataKeys(parentClass);
66
- for (const key of metadataKeys) {
67
- const m = Reflect.getMetadata(key, parentClass);
68
- Reflect.defineMetadata(key, m, newClass);
69
- }
66
+ OpraNestAdapter.copyDecoratorMetadataToChild(newClass, sourceClass, parentClass);
70
67
  }
71
68
  const newPath = metadata.path ? nodePath.join(currentPath, metadata.path) : currentPath;
72
69
  const adapter = this;
@@ -162,4 +159,14 @@ export class OpraNestAdapter extends HttpAdapter {
162
159
  }
163
160
  }
164
161
  }
162
+ static copyDecoratorMetadataToChild(target, source, parent) {
163
+ const metadataKeys = Reflect.getOwnMetadataKeys(parent);
164
+ for (const key of metadataKeys) {
165
+ if (key === GUARDS_METADATA || key === INTERCEPTORS_METADATA || key === EXCEPTION_FILTERS_METADATA) {
166
+ const m1 = Reflect.getMetadata(key, source) || [];
167
+ const m2 = Reflect.getMetadata(key, parent) || [];
168
+ Reflect.defineMetadata(key, [...m1, ...m2], target);
169
+ }
170
+ }
171
+ }
165
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "1.0.0-alpha.18",
3
+ "version": "1.0.0-alpha.19",
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.18",
31
- "@opra/core": "^1.0.0-alpha.18",
30
+ "@opra/common": "^1.0.0-alpha.19",
31
+ "@opra/core": "^1.0.0-alpha.19",
32
32
  "fast-tokenizer": "^1.3.0",
33
33
  "lodash.head": "^4.0.1",
34
34
  "reflect-metadata": "^0.2.2"
@@ -9,4 +9,5 @@ export declare class OpraNestAdapter extends HttpAdapter {
9
9
  close(): Promise<void>;
10
10
  protected _addRootController(basePath: string): void;
11
11
  protected _addToNestControllers(sourceClass: Type, currentPath: string, parentClass?: Type): void;
12
+ static copyDecoratorMetadataToChild(target: Type, source: Type, parent: Type): void;
12
13
  }