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

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.
@@ -7,7 +7,7 @@ const common_2 = require("@opra/common");
7
7
  const core_1 = require("@opra/core");
8
8
  const path_1 = tslib_1.__importDefault(require("path"));
9
9
  const ts_gems_1 = require("ts-gems");
10
- const public_decorator_1 = require("./decorators/public.decorator");
10
+ const public_decorator_js_1 = require("./decorators/public.decorator.js");
11
11
  const opra_exception_filter_js_1 = require("./services/opra-exception-filter.js");
12
12
  exports.kHandler = Symbol.for('kHandler');
13
13
  class OpraNestAdapter extends core_1.HttpAdapter {
@@ -50,11 +50,11 @@ class OpraNestAdapter extends core_1.HttpAdapter {
50
50
  })
51
51
  ], RootController);
52
52
  if (this.options?.schemaRouteIsPublic) {
53
- (0, public_decorator_1.Public)()(RootController.prototype, 'schema', Object.getOwnPropertyDescriptor(RootController.prototype, 'schema'));
53
+ (0, public_decorator_js_1.Public)()(RootController.prototype, 'schema', Object.getOwnPropertyDescriptor(RootController.prototype, 'schema'));
54
54
  }
55
55
  this.nestControllers.push(RootController);
56
56
  }
57
- _addToNestControllers(sourceClass, currentPath) {
57
+ _addToNestControllers(sourceClass, currentPath, parentClass) {
58
58
  const metadata = Reflect.getMetadata(common_2.HTTP_CONTROLLER_METADATA, sourceClass);
59
59
  if (!metadata)
60
60
  return;
@@ -62,6 +62,15 @@ class OpraNestAdapter extends core_1.HttpAdapter {
62
62
  [sourceClass.name]: class extends sourceClass {
63
63
  },
64
64
  }[sourceClass.name];
65
+ /** Copy metadata keys from source class to new one */
66
+ let metadataKeys;
67
+ 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
+ }
73
+ }
65
74
  const newPath = metadata.path ? path_1.default.join(currentPath, metadata.path) : currentPath;
66
75
  const adapter = this;
67
76
  /** Inject exception filter */
@@ -100,7 +109,7 @@ class OpraNestAdapter extends core_1.HttpAdapter {
100
109
  },
101
110
  });
102
111
  /** Copy metadata keys from source function to new one */
103
- const metadataKeys = Reflect.getOwnMetadataKeys(operationHandler);
112
+ metadataKeys = Reflect.getOwnMetadataKeys(operationHandler);
104
113
  const newFn = newClass.prototype[k];
105
114
  for (const key of metadataKeys) {
106
115
  const m = Reflect.getMetadata(key, operationHandler);
@@ -152,7 +161,7 @@ class OpraNestAdapter extends core_1.HttpAdapter {
152
161
  for (const child of metadata.controllers) {
153
162
  if (!(0, common_2.isConstructor)(child))
154
163
  throw new TypeError('Controllers should be injectable a class');
155
- this._addToNestControllers(child, newPath);
164
+ this._addToNestControllers(child, newPath, sourceClass);
156
165
  }
157
166
  }
158
167
  }
@@ -4,7 +4,7 @@ import { ApiDocument, HTTP_CONTROLLER_METADATA, HttpApi, isConstructor, NotFound
4
4
  import { HttpAdapter } from '@opra/core';
5
5
  import nodePath from 'path';
6
6
  import { asMutable } from 'ts-gems';
7
- import { Public } from './decorators/public.decorator';
7
+ import { Public } from './decorators/public.decorator.js';
8
8
  import { OpraExceptionFilter } from './services/opra-exception-filter.js';
9
9
  export const kHandler = Symbol.for('kHandler');
10
10
  export class OpraNestAdapter extends HttpAdapter {
@@ -51,7 +51,7 @@ export class OpraNestAdapter extends HttpAdapter {
51
51
  }
52
52
  this.nestControllers.push(RootController);
53
53
  }
54
- _addToNestControllers(sourceClass, currentPath) {
54
+ _addToNestControllers(sourceClass, currentPath, parentClass) {
55
55
  const metadata = Reflect.getMetadata(HTTP_CONTROLLER_METADATA, sourceClass);
56
56
  if (!metadata)
57
57
  return;
@@ -59,6 +59,15 @@ export class OpraNestAdapter extends HttpAdapter {
59
59
  [sourceClass.name]: class extends sourceClass {
60
60
  },
61
61
  }[sourceClass.name];
62
+ /** Copy metadata keys from source class to new one */
63
+ let metadataKeys;
64
+ 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
+ }
70
+ }
62
71
  const newPath = metadata.path ? nodePath.join(currentPath, metadata.path) : currentPath;
63
72
  const adapter = this;
64
73
  /** Inject exception filter */
@@ -97,7 +106,7 @@ export class OpraNestAdapter extends HttpAdapter {
97
106
  },
98
107
  });
99
108
  /** Copy metadata keys from source function to new one */
100
- const metadataKeys = Reflect.getOwnMetadataKeys(operationHandler);
109
+ metadataKeys = Reflect.getOwnMetadataKeys(operationHandler);
101
110
  const newFn = newClass.prototype[k];
102
111
  for (const key of metadataKeys) {
103
112
  const m = Reflect.getMetadata(key, operationHandler);
@@ -149,7 +158,7 @@ export class OpraNestAdapter extends HttpAdapter {
149
158
  for (const child of metadata.controllers) {
150
159
  if (!isConstructor(child))
151
160
  throw new TypeError('Controllers should be injectable a class');
152
- this._addToNestControllers(child, newPath);
161
+ this._addToNestControllers(child, newPath, sourceClass);
153
162
  }
154
163
  }
155
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "1.0.0-alpha.16",
3
+ "version": "1.0.0-alpha.18",
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.16",
31
- "@opra/core": "^1.0.0-alpha.16",
30
+ "@opra/common": "^1.0.0-alpha.18",
31
+ "@opra/core": "^1.0.0-alpha.18",
32
32
  "fast-tokenizer": "^1.3.0",
33
33
  "lodash.head": "^4.0.1",
34
34
  "reflect-metadata": "^0.2.2"
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, MiddlewareConsumer, NestModule, OnModuleDestroy } from '@nestjs/common';
2
- import type { OpraHttpModule } from './opra-http.module';
2
+ import type { OpraHttpModule } from './opra-http.module.js';
3
3
  import { OpraNestAdapter } from './opra-nestjs-adapter.js';
4
4
  export declare class OpraHttpCoreModule implements OnModuleDestroy, NestModule {
5
5
  protected opraAdapter: OpraNestAdapter;
@@ -1,6 +1,6 @@
1
1
  import { Type } from '@nestjs/common';
2
2
  import { HttpAdapter } from '@opra/core';
3
- import type { OpraHttpModule } from './opra-http.module';
3
+ import type { OpraHttpModule } from './opra-http.module.js';
4
4
  export declare const kHandler: unique symbol;
5
5
  export declare class OpraNestAdapter extends HttpAdapter {
6
6
  readonly nestControllers: Type[];
@@ -8,5 +8,5 @@ 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): void;
11
+ protected _addToNestControllers(sourceClass: Type, currentPath: string, parentClass?: Type): void;
12
12
  }