@opra/nestjs 1.4.2 → 1.4.4
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/helpers/base-opra-nest-factory.js +6 -2
- package/cjs/http/opra-http-core.module.js +12 -10
- package/cjs/http/opra-http-nestjs-adapter.js +10 -3
- package/cjs/kafka/opra-kafka-core.module.js +6 -2
- package/esm/helpers/base-opra-nest-factory.js +7 -3
- package/esm/helpers/rpc-controller-factory.service.js +2 -2
- package/esm/http/opra-http-core.module.js +12 -10
- package/esm/http/opra-http-nestjs-adapter.js +11 -4
- package/esm/kafka/opra-kafka-core.module.js +6 -2
- package/package.json +5 -5
|
@@ -7,12 +7,16 @@ class BaseOpraNestFactory {
|
|
|
7
7
|
for (const parent of source) {
|
|
8
8
|
const metadataKeys = Reflect.getOwnMetadataKeys(parent);
|
|
9
9
|
for (const key of metadataKeys) {
|
|
10
|
-
if (typeof key === 'string' &&
|
|
10
|
+
if (typeof key === 'string' &&
|
|
11
|
+
key.startsWith('opra.') &&
|
|
12
|
+
!Reflect.hasOwnMetadata(key, target)) {
|
|
11
13
|
const metadata = Reflect.getMetadata(key, parent);
|
|
12
14
|
Reflect.defineMetadata(key, metadata, target);
|
|
13
15
|
continue;
|
|
14
16
|
}
|
|
15
|
-
if (key === constants_1.GUARDS_METADATA ||
|
|
17
|
+
if (key === constants_1.GUARDS_METADATA ||
|
|
18
|
+
key === constants_1.INTERCEPTORS_METADATA ||
|
|
19
|
+
key === constants_1.EXCEPTION_FILTERS_METADATA) {
|
|
16
20
|
const m1 = Reflect.getMetadata(key, target) || [];
|
|
17
21
|
const metadata = [...m1];
|
|
18
22
|
const m2 = Reflect.getOwnMetadata(key, parent) || [];
|
|
@@ -59,16 +59,18 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
59
59
|
provide: token,
|
|
60
60
|
inject: [core_1.ModuleRef, constants_js_1.OPRA_HTTP_API_CONFIG],
|
|
61
61
|
useFactory: async (moduleRef, apiConfig) => {
|
|
62
|
-
opraNestAdapter.logger =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
opraNestAdapter.logger =
|
|
63
|
+
opraNestAdapter.logger || new common_1.Logger(apiConfig.name);
|
|
64
|
+
opraNestAdapter._document =
|
|
65
|
+
await common_2.ApiDocumentFactory.createDocument({
|
|
66
|
+
...apiConfig,
|
|
67
|
+
api: {
|
|
68
|
+
transport: 'http',
|
|
69
|
+
name: apiConfig.name,
|
|
70
|
+
description: apiConfig.description,
|
|
71
|
+
controllers: moduleOptions.controllers,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
72
74
|
if (moduleOptions.interceptors) {
|
|
73
75
|
opraNestAdapter.interceptors = moduleOptions.interceptors.map(x => {
|
|
74
76
|
if ((0, objects_1.isConstructor)(x)) {
|
|
@@ -61,7 +61,9 @@ class OpraHttpNestjsAdapter extends http_1.HttpAdapter {
|
|
|
61
61
|
/** Copy metadata keys from source class to new one */
|
|
62
62
|
base_opra_nest_factory_js_1.BaseOpraNestFactory.copyDecoratorMetadata(newClass, ...parentTree);
|
|
63
63
|
(0, common_1.Controller)()(newClass);
|
|
64
|
-
const newPath = metadata.path
|
|
64
|
+
const newPath = metadata.path
|
|
65
|
+
? node_path_1.default.join(currentPath, metadata.path)
|
|
66
|
+
: currentPath;
|
|
65
67
|
const adapter = this;
|
|
66
68
|
// adapter.logger =
|
|
67
69
|
/** Disable default error handler. Errors will be handled by OpraExceptionFilter */
|
|
@@ -110,7 +112,9 @@ class OpraHttpNestjsAdapter extends http_1.HttpAdapter {
|
|
|
110
112
|
(0, common_1.Req)()(newClass.prototype, k, 0);
|
|
111
113
|
(0, common_1.Res)()(newClass.prototype, k, 1);
|
|
112
114
|
const descriptor = Object.getOwnPropertyDescriptor(newClass.prototype, k);
|
|
113
|
-
const operationPath = v.mergePath
|
|
115
|
+
const operationPath = v.mergePath
|
|
116
|
+
? newPath + (v.path || '')
|
|
117
|
+
: node_path_1.default.posix.join(newPath, v.path || '');
|
|
114
118
|
switch (v.method || 'GET') {
|
|
115
119
|
case 'DELETE':
|
|
116
120
|
/** Call @Delete decorator over new property */
|
|
@@ -153,7 +157,10 @@ class OpraHttpNestjsAdapter extends http_1.HttpAdapter {
|
|
|
153
157
|
for (const child of metadata.controllers) {
|
|
154
158
|
if (!(0, objects_1.isConstructor)(child))
|
|
155
159
|
throw new TypeError('Controllers should be injectable a class');
|
|
156
|
-
this._addToNestControllers(child, newPath, [
|
|
160
|
+
this._addToNestControllers(child, newPath, [
|
|
161
|
+
...parentTree,
|
|
162
|
+
sourceClass,
|
|
163
|
+
]);
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
166
|
}
|
|
@@ -57,7 +57,9 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
57
57
|
provide: token,
|
|
58
58
|
inject: [rpc_controller_factory_service_js_1.RpcControllerFactory, core_1.ModuleRef, constants_js_1.OPRA_KAFKA_MODULE_CONFIG],
|
|
59
59
|
useFactory: async (controllerFactory, moduleRef, config) => {
|
|
60
|
-
const controllers = controllerFactory
|
|
60
|
+
const controllers = controllerFactory
|
|
61
|
+
.exploreControllers()
|
|
62
|
+
.map(x => x.wrapper.instance.constructor);
|
|
61
63
|
const document = await common_2.ApiDocumentFactory.createDocument({
|
|
62
64
|
info: config.info,
|
|
63
65
|
types: config.types,
|
|
@@ -107,7 +109,9 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
107
109
|
* So we should update instance properties */
|
|
108
110
|
const rpcApi = this.adapter.document.rpcApi;
|
|
109
111
|
const controllers = Array.from(rpcApi.controllers.values());
|
|
110
|
-
for (const { wrapper } of this.controllerFactory
|
|
112
|
+
for (const { wrapper } of this.controllerFactory
|
|
113
|
+
.exploreControllers()
|
|
114
|
+
.values()) {
|
|
111
115
|
const ctor = wrapper.instance.constructor;
|
|
112
116
|
const controller = controllers.find(x => x.ctor === ctor);
|
|
113
117
|
if (controller) {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { EXCEPTION_FILTERS_METADATA, GUARDS_METADATA, INTERCEPTORS_METADATA } from '@nestjs/common/constants';
|
|
1
|
+
import { EXCEPTION_FILTERS_METADATA, GUARDS_METADATA, INTERCEPTORS_METADATA, } from '@nestjs/common/constants';
|
|
2
2
|
export class BaseOpraNestFactory {
|
|
3
3
|
static copyDecoratorMetadata(target, ...source) {
|
|
4
4
|
for (const parent of source) {
|
|
5
5
|
const metadataKeys = Reflect.getOwnMetadataKeys(parent);
|
|
6
6
|
for (const key of metadataKeys) {
|
|
7
|
-
if (typeof key === 'string' &&
|
|
7
|
+
if (typeof key === 'string' &&
|
|
8
|
+
key.startsWith('opra.') &&
|
|
9
|
+
!Reflect.hasOwnMetadata(key, target)) {
|
|
8
10
|
const metadata = Reflect.getMetadata(key, parent);
|
|
9
11
|
Reflect.defineMetadata(key, metadata, target);
|
|
10
12
|
continue;
|
|
11
13
|
}
|
|
12
|
-
if (key === GUARDS_METADATA ||
|
|
14
|
+
if (key === GUARDS_METADATA ||
|
|
15
|
+
key === INTERCEPTORS_METADATA ||
|
|
16
|
+
key === EXCEPTION_FILTERS_METADATA) {
|
|
13
17
|
const m1 = Reflect.getMetadata(key, target) || [];
|
|
14
18
|
const metadata = [...m1];
|
|
15
19
|
const m2 = Reflect.getOwnMetadata(key, parent) || [];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var RpcControllerFactory_1;
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
-
import { Controller, Inject, Injectable } from '@nestjs/common';
|
|
3
|
+
import { Controller, Inject, Injectable, } from '@nestjs/common';
|
|
4
4
|
import { createContextId, ModulesContainer, REQUEST } from '@nestjs/core';
|
|
5
|
-
import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator';
|
|
5
|
+
import { ExternalContextCreator, } from '@nestjs/core/helpers/external-context-creator';
|
|
6
6
|
import { Injector } from '@nestjs/core/injector/injector';
|
|
7
7
|
import { InternalCoreModule } from '@nestjs/core/injector/internal-core-module';
|
|
8
8
|
import { REQUEST_CONTEXT_ID } from '@nestjs/core/router/request/request-constants';
|
|
@@ -56,16 +56,18 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
56
56
|
provide: token,
|
|
57
57
|
inject: [ModuleRef, OPRA_HTTP_API_CONFIG],
|
|
58
58
|
useFactory: async (moduleRef, apiConfig) => {
|
|
59
|
-
opraNestAdapter.logger =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
opraNestAdapter.logger =
|
|
60
|
+
opraNestAdapter.logger || new Logger(apiConfig.name);
|
|
61
|
+
opraNestAdapter._document =
|
|
62
|
+
await ApiDocumentFactory.createDocument({
|
|
63
|
+
...apiConfig,
|
|
64
|
+
api: {
|
|
65
|
+
transport: 'http',
|
|
66
|
+
name: apiConfig.name,
|
|
67
|
+
description: apiConfig.description,
|
|
68
|
+
controllers: moduleOptions.controllers,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
69
71
|
if (moduleOptions.interceptors) {
|
|
70
72
|
opraNestAdapter.interceptors = moduleOptions.interceptors.map(x => {
|
|
71
73
|
if (isConstructor(x)) {
|
|
@@ -2,7 +2,7 @@ import { __decorate, __metadata, __param } from "tslib";
|
|
|
2
2
|
import nodePath from 'node:path';
|
|
3
3
|
import { isConstructor } from '@jsopen/objects';
|
|
4
4
|
import { Controller, Delete, Get, Head, Next, Options, Patch, Post, Put, Req, Res, Search, } from '@nestjs/common';
|
|
5
|
-
import { HTTP_CONTROLLER_METADATA, NotFoundError } from '@opra/common';
|
|
5
|
+
import { HTTP_CONTROLLER_METADATA, NotFoundError, } from '@opra/common';
|
|
6
6
|
import { HttpAdapter } from '@opra/http';
|
|
7
7
|
import { asMutable } from 'ts-gems';
|
|
8
8
|
import { Public } from '../decorators/public.decorator.js';
|
|
@@ -58,7 +58,9 @@ export class OpraHttpNestjsAdapter extends HttpAdapter {
|
|
|
58
58
|
/** Copy metadata keys from source class to new one */
|
|
59
59
|
BaseOpraNestFactory.copyDecoratorMetadata(newClass, ...parentTree);
|
|
60
60
|
Controller()(newClass);
|
|
61
|
-
const newPath = metadata.path
|
|
61
|
+
const newPath = metadata.path
|
|
62
|
+
? nodePath.join(currentPath, metadata.path)
|
|
63
|
+
: currentPath;
|
|
62
64
|
const adapter = this;
|
|
63
65
|
// adapter.logger =
|
|
64
66
|
/** Disable default error handler. Errors will be handled by OpraExceptionFilter */
|
|
@@ -107,7 +109,9 @@ export class OpraHttpNestjsAdapter extends HttpAdapter {
|
|
|
107
109
|
Req()(newClass.prototype, k, 0);
|
|
108
110
|
Res()(newClass.prototype, k, 1);
|
|
109
111
|
const descriptor = Object.getOwnPropertyDescriptor(newClass.prototype, k);
|
|
110
|
-
const operationPath = v.mergePath
|
|
112
|
+
const operationPath = v.mergePath
|
|
113
|
+
? newPath + (v.path || '')
|
|
114
|
+
: nodePath.posix.join(newPath, v.path || '');
|
|
111
115
|
switch (v.method || 'GET') {
|
|
112
116
|
case 'DELETE':
|
|
113
117
|
/** Call @Delete decorator over new property */
|
|
@@ -150,7 +154,10 @@ export class OpraHttpNestjsAdapter extends HttpAdapter {
|
|
|
150
154
|
for (const child of metadata.controllers) {
|
|
151
155
|
if (!isConstructor(child))
|
|
152
156
|
throw new TypeError('Controllers should be injectable a class');
|
|
153
|
-
this._addToNestControllers(child, newPath, [
|
|
157
|
+
this._addToNestControllers(child, newPath, [
|
|
158
|
+
...parentTree,
|
|
159
|
+
sourceClass,
|
|
160
|
+
]);
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
}
|
|
@@ -54,7 +54,9 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
54
54
|
provide: token,
|
|
55
55
|
inject: [RpcControllerFactory, ModuleRef, OPRA_KAFKA_MODULE_CONFIG],
|
|
56
56
|
useFactory: async (controllerFactory, moduleRef, config) => {
|
|
57
|
-
const controllers = controllerFactory
|
|
57
|
+
const controllers = controllerFactory
|
|
58
|
+
.exploreControllers()
|
|
59
|
+
.map(x => x.wrapper.instance.constructor);
|
|
58
60
|
const document = await ApiDocumentFactory.createDocument({
|
|
59
61
|
info: config.info,
|
|
60
62
|
types: config.types,
|
|
@@ -104,7 +106,9 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
104
106
|
* So we should update instance properties */
|
|
105
107
|
const rpcApi = this.adapter.document.rpcApi;
|
|
106
108
|
const controllers = Array.from(rpcApi.controllers.values());
|
|
107
|
-
for (const { wrapper } of this.controllerFactory
|
|
109
|
+
for (const { wrapper } of this.controllerFactory
|
|
110
|
+
.exploreControllers()
|
|
111
|
+
.values()) {
|
|
108
112
|
const ctor = wrapper.instance.constructor;
|
|
109
113
|
const controller = controllers.find(x => x.ctor === ctor);
|
|
110
114
|
if (controller) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/nestjs",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Opra NestJS module",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@jsopen/objects": "^1.5.0",
|
|
9
|
-
"@opra/common": "^1.4.
|
|
10
|
-
"@opra/core": "^1.4.
|
|
9
|
+
"@opra/common": "^1.4.4",
|
|
10
|
+
"@opra/core": "^1.4.4",
|
|
11
11
|
"fast-tokenizer": "^1.7.0",
|
|
12
12
|
"putil-promisify": "^1.10.1",
|
|
13
13
|
"reflect-metadata": "^0.2.2",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"optionalDependencies": {
|
|
21
21
|
"@nestjs/microservices": "^10.4.13",
|
|
22
|
-
"@opra/http": "^1.4.
|
|
23
|
-
"@opra/kafka": "^1.4.
|
|
22
|
+
"@opra/http": "^1.4.4",
|
|
23
|
+
"@opra/kafka": "^1.4.4"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"exports": {
|