@opra/nestjs 1.10.0 → 1.11.1
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/constants.js +1 -4
- package/cjs/index.js +3 -4
- package/cjs/{helpers/base-opra-nest-factory.js → opra-nest-utils.js} +9 -7
- package/cjs/{helpers/rpc-controller-factory.service.js → rpc-controller.factory.js} +4 -6
- package/esm/constants.js +0 -3
- package/esm/index.js +3 -4
- package/esm/{helpers/base-opra-nest-factory.js → opra-nest-utils.js} +4 -2
- package/esm/{helpers/rpc-controller-factory.service.js → rpc-controller.factory.js} +4 -6
- package/package.json +11 -15
- package/types/constants.d.ts +0 -3
- package/types/index.d.cts +3 -4
- package/types/index.d.ts +3 -4
- package/types/{helpers/base-opra-nest-factory.d.ts → opra-nest-utils.d.ts} +1 -1
- package/types/{helpers/rpc-controller-factory.service.d.ts → rpc-controller.factory.d.ts} +1 -2
- package/cjs/http/opra-http-core.module.js +0 -119
- package/cjs/http/opra-http-nestjs-adapter.js +0 -168
- package/cjs/http/opra-http.module.js +0 -33
- package/cjs/http/services/opra-exception-filter.js +0 -27
- package/cjs/http/services/opra-middleware.js +0 -33
- package/cjs/kafka/opra-kafka-core.module.js +0 -137
- package/cjs/kafka/opra-kafka.module.js +0 -33
- package/cjs/rabbitmq/opra-rabbitmq-core.module.js +0 -137
- package/cjs/rabbitmq/opra-rabbitmq.module.js +0 -33
- package/esm/http/opra-http-core.module.js +0 -116
- package/esm/http/opra-http-nestjs-adapter.js +0 -164
- package/esm/http/opra-http.module.js +0 -30
- package/esm/http/services/opra-exception-filter.js +0 -24
- package/esm/http/services/opra-middleware.js +0 -30
- package/esm/kafka/opra-kafka-core.module.js +0 -134
- package/esm/kafka/opra-kafka.module.js +0 -30
- package/esm/rabbitmq/opra-rabbitmq-core.module.js +0 -134
- package/esm/rabbitmq/opra-rabbitmq.module.js +0 -30
- package/types/http/opra-http-core.module.d.ts +0 -12
- package/types/http/opra-http-nestjs-adapter.d.ts +0 -12
- package/types/http/opra-http.module.d.ts +0 -36
- package/types/http/services/opra-exception-filter.d.ts +0 -7
- package/types/http/services/opra-middleware.d.ts +0 -8
- package/types/kafka/opra-kafka-core.module.d.ts +0 -16
- package/types/kafka/opra-kafka.module.d.ts +0 -34
- package/types/rabbitmq/opra-rabbitmq-core.module.d.ts +0 -16
- package/types/rabbitmq/opra-rabbitmq.module.d.ts +0 -38
- /package/cjs/{helpers/rpc-params.factory.js → rpc-params.factory.js} +0 -0
- /package/esm/{helpers/rpc-params.factory.js → rpc-params.factory.js} +0 -0
- /package/types/{helpers/rpc-params.factory.d.ts → rpc-params.factory.d.ts} +0 -0
package/cjs/constants.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.IS_PUBLIC_KEY = void 0;
|
|
4
4
|
exports.IS_PUBLIC_KEY = 'opra:isPublic';
|
|
5
|
-
exports.OPRA_HTTP_API_CONFIG = 'OPRA_HTTP_API_CONFIG';
|
|
6
|
-
exports.OPRA_KAFKA_MODULE_CONFIG = 'OPRA_KAFKA_MODULE_CONFIG';
|
|
7
|
-
exports.OPRA_RMQ_MODULE_CONFIG = 'OPRA_RMQ_MODULE_CONFIG';
|
package/cjs/index.js
CHANGED
|
@@ -5,7 +5,6 @@ require("reflect-metadata");
|
|
|
5
5
|
require("./augmentation/nestjs.augmentation.js");
|
|
6
6
|
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./decorators/public.decorator.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./
|
|
9
|
-
tslib_1.__exportStar(require("./
|
|
10
|
-
tslib_1.__exportStar(require("./
|
|
11
|
-
tslib_1.__exportStar(require("./rabbitmq/opra-rabbitmq.module.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./opra-nest-utils.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./rpc-controller.factory.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./rpc-params.factory.js"), exports);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
exports.OpraNestUtils = void 0;
|
|
4
|
+
const GUARDS_METADATA = '__guards__';
|
|
5
|
+
const INTERCEPTORS_METADATA = '__interceptors__';
|
|
6
|
+
const EXCEPTION_FILTERS_METADATA = '__exceptionFilters__';
|
|
7
|
+
class OpraNestUtils {
|
|
6
8
|
static copyDecoratorMetadata(target, ...source) {
|
|
7
9
|
for (const parent of source) {
|
|
8
10
|
const metadataKeys = Reflect.getOwnMetadataKeys(parent);
|
|
@@ -14,9 +16,9 @@ class BaseOpraNestFactory {
|
|
|
14
16
|
Reflect.defineMetadata(key, metadata, target);
|
|
15
17
|
continue;
|
|
16
18
|
}
|
|
17
|
-
if (key ===
|
|
18
|
-
key ===
|
|
19
|
-
key ===
|
|
19
|
+
if (key === GUARDS_METADATA ||
|
|
20
|
+
key === INTERCEPTORS_METADATA ||
|
|
21
|
+
key === EXCEPTION_FILTERS_METADATA) {
|
|
20
22
|
const m1 = Reflect.getMetadata(key, target) || [];
|
|
21
23
|
const metadata = [...m1];
|
|
22
24
|
const m2 = Reflect.getOwnMetadata(key, parent) || [];
|
|
@@ -31,4 +33,4 @@ class BaseOpraNestFactory {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
exports.
|
|
36
|
+
exports.OpraNestUtils = OpraNestUtils;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var RpcControllerFactory_1;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.RpcControllerFactory = void 0;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
@@ -11,11 +10,10 @@ const index_js_1 = require("@nestjs/core/injector/internal-core-module/index.js"
|
|
|
11
10
|
const request_constants_js_1 = require("@nestjs/core/router/request/request-constants.js");
|
|
12
11
|
const constants_js_1 = require("@nestjs/microservices/constants.js");
|
|
13
12
|
const common_2 = require("@opra/common");
|
|
14
|
-
const
|
|
13
|
+
const opra_nest_utils_js_1 = require("./opra-nest-utils.js");
|
|
15
14
|
const rpc_params_factory_js_1 = require("./rpc-params.factory.js");
|
|
16
|
-
let RpcControllerFactory =
|
|
15
|
+
let RpcControllerFactory = class RpcControllerFactory {
|
|
17
16
|
constructor(modulesContainer, externalContextCreator) {
|
|
18
|
-
super();
|
|
19
17
|
this.modulesContainer = modulesContainer;
|
|
20
18
|
this.externalContextCreator = externalContextCreator;
|
|
21
19
|
this.paramsFactory = new rpc_params_factory_js_1.RpcParamsFactory();
|
|
@@ -34,7 +32,7 @@ let RpcControllerFactory = RpcControllerFactory_1 = class RpcControllerFactory e
|
|
|
34
32
|
},
|
|
35
33
|
}[sourceClass.name];
|
|
36
34
|
/** Copy metadata keys from source class to new one */
|
|
37
|
-
|
|
35
|
+
opra_nest_utils_js_1.OpraNestUtils.copyDecoratorMetadata(newClass, sourceClass);
|
|
38
36
|
(0, common_1.Controller)()(newClass);
|
|
39
37
|
out.push(newClass);
|
|
40
38
|
if (metadata.operations) {
|
|
@@ -114,7 +112,7 @@ let RpcControllerFactory = RpcControllerFactory_1 = class RpcControllerFactory e
|
|
|
114
112
|
}
|
|
115
113
|
};
|
|
116
114
|
exports.RpcControllerFactory = RpcControllerFactory;
|
|
117
|
-
exports.RpcControllerFactory = RpcControllerFactory =
|
|
115
|
+
exports.RpcControllerFactory = RpcControllerFactory = tslib_1.__decorate([
|
|
118
116
|
(0, common_1.Injectable)(),
|
|
119
117
|
tslib_1.__param(0, (0, common_1.Inject)()),
|
|
120
118
|
tslib_1.__param(1, (0, common_1.Inject)()),
|
package/esm/constants.js
CHANGED
package/esm/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import 'reflect-metadata';
|
|
|
2
2
|
import './augmentation/nestjs.augmentation.js';
|
|
3
3
|
export * from './constants.js';
|
|
4
4
|
export * from './decorators/public.decorator.js';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './rabbitmq/opra-rabbitmq.module.js';
|
|
5
|
+
export * from './opra-nest-utils.js';
|
|
6
|
+
export * from './rpc-controller.factory.js';
|
|
7
|
+
export * from './rpc-params.factory.js';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const GUARDS_METADATA = '__guards__';
|
|
2
|
+
const INTERCEPTORS_METADATA = '__interceptors__';
|
|
3
|
+
const EXCEPTION_FILTERS_METADATA = '__exceptionFilters__';
|
|
4
|
+
export class OpraNestUtils {
|
|
3
5
|
static copyDecoratorMetadata(target, ...source) {
|
|
4
6
|
for (const parent of source) {
|
|
5
7
|
const metadataKeys = Reflect.getOwnMetadataKeys(parent);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
var RpcControllerFactory_1;
|
|
2
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
2
|
import { Controller, Inject, Injectable, } from '@nestjs/common';
|
|
4
3
|
import { createContextId, ModulesContainer, REQUEST } from '@nestjs/core';
|
|
@@ -8,11 +7,10 @@ import { InternalCoreModule } from '@nestjs/core/injector/internal-core-module/i
|
|
|
8
7
|
import { REQUEST_CONTEXT_ID } from '@nestjs/core/router/request/request-constants.js';
|
|
9
8
|
import { PARAM_ARGS_METADATA } from '@nestjs/microservices/constants.js';
|
|
10
9
|
import { RPC_CONTROLLER_METADATA } from '@opra/common';
|
|
11
|
-
import {
|
|
10
|
+
import { OpraNestUtils } from './opra-nest-utils.js';
|
|
12
11
|
import { RpcParamsFactory } from './rpc-params.factory.js';
|
|
13
|
-
let RpcControllerFactory =
|
|
12
|
+
let RpcControllerFactory = class RpcControllerFactory {
|
|
14
13
|
constructor(modulesContainer, externalContextCreator) {
|
|
15
|
-
super();
|
|
16
14
|
this.modulesContainer = modulesContainer;
|
|
17
15
|
this.externalContextCreator = externalContextCreator;
|
|
18
16
|
this.paramsFactory = new RpcParamsFactory();
|
|
@@ -31,7 +29,7 @@ let RpcControllerFactory = RpcControllerFactory_1 = class RpcControllerFactory e
|
|
|
31
29
|
},
|
|
32
30
|
}[sourceClass.name];
|
|
33
31
|
/** Copy metadata keys from source class to new one */
|
|
34
|
-
|
|
32
|
+
OpraNestUtils.copyDecoratorMetadata(newClass, sourceClass);
|
|
35
33
|
Controller()(newClass);
|
|
36
34
|
out.push(newClass);
|
|
37
35
|
if (metadata.operations) {
|
|
@@ -110,7 +108,7 @@ let RpcControllerFactory = RpcControllerFactory_1 = class RpcControllerFactory e
|
|
|
110
108
|
return Array.from(controllers);
|
|
111
109
|
}
|
|
112
110
|
};
|
|
113
|
-
RpcControllerFactory =
|
|
111
|
+
RpcControllerFactory = __decorate([
|
|
114
112
|
Injectable(),
|
|
115
113
|
__param(0, Inject()),
|
|
116
114
|
__param(1, Inject()),
|
package/package.json
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/nestjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
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.10.0",
|
|
10
|
-
"@opra/core": "^1.10.0",
|
|
11
|
-
"fast-tokenizer": "^1.7.0",
|
|
12
|
-
"putil-promisify": "^1.10.1",
|
|
13
9
|
"reflect-metadata": "^0.2.2",
|
|
14
10
|
"tslib": "^2.8.1"
|
|
15
11
|
},
|
|
16
12
|
"peerDependencies": {
|
|
13
|
+
"@opra/common": "^1.11.1",
|
|
14
|
+
"@opra/core": "^1.11.1",
|
|
17
15
|
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
18
|
-
"@nestjs/core": "^10.0.0 || ^11.0.0"
|
|
19
|
-
|
|
20
|
-
"optionalDependencies": {
|
|
21
|
-
"@nestjs/microservices": "^10.0.0 || ^11.0.0",
|
|
22
|
-
"@opra/http": "^1.10.0",
|
|
23
|
-
"@opra/kafka": "^1.10.0",
|
|
24
|
-
"amqplib": ">=0.10.0 <1.0.0",
|
|
25
|
-
"kafkajs": "^2.2.4"
|
|
16
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
17
|
+
"@nestjs/microservices": "^10.0.0 || ^11.0.0"
|
|
26
18
|
},
|
|
27
19
|
"type": "module",
|
|
28
20
|
"exports": {
|
|
@@ -61,6 +53,10 @@
|
|
|
61
53
|
],
|
|
62
54
|
"keywords": [
|
|
63
55
|
"opra",
|
|
64
|
-
"nestjs"
|
|
65
|
-
|
|
56
|
+
"nestjs",
|
|
57
|
+
"common"
|
|
58
|
+
],
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
}
|
|
66
62
|
}
|
package/types/constants.d.ts
CHANGED
package/types/index.d.cts
CHANGED
|
@@ -2,7 +2,6 @@ import 'reflect-metadata';
|
|
|
2
2
|
import './augmentation/nestjs.augmentation.js';
|
|
3
3
|
export * from './constants.js';
|
|
4
4
|
export * from './decorators/public.decorator.js';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './rabbitmq/opra-rabbitmq.module.js';
|
|
5
|
+
export * from './opra-nest-utils.js';
|
|
6
|
+
export * from './rpc-controller.factory.js';
|
|
7
|
+
export * from './rpc-params.factory.js';
|
package/types/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import 'reflect-metadata';
|
|
|
2
2
|
import './augmentation/nestjs.augmentation.js';
|
|
3
3
|
export * from './constants.js';
|
|
4
4
|
export * from './decorators/public.decorator.js';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './rabbitmq/opra-rabbitmq.module.js';
|
|
5
|
+
export * from './opra-nest-utils.js';
|
|
6
|
+
export * from './rpc-controller.factory.js';
|
|
7
|
+
export * from './rpc-params.factory.js';
|
|
@@ -3,8 +3,7 @@ import { ModulesContainer } from '@nestjs/core';
|
|
|
3
3
|
import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator.js';
|
|
4
4
|
import type { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper.js';
|
|
5
5
|
import type { Module } from '@nestjs/core/injector/module.js';
|
|
6
|
-
|
|
7
|
-
export declare class RpcControllerFactory extends BaseOpraNestFactory {
|
|
6
|
+
export declare class RpcControllerFactory {
|
|
8
7
|
private readonly modulesContainer;
|
|
9
8
|
private readonly externalContextCreator;
|
|
10
9
|
private _coreModuleRef?;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var OpraHttpCoreModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraHttpCoreModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const objects_1 = require("@jsopen/objects");
|
|
7
|
-
const common_1 = require("@nestjs/common");
|
|
8
|
-
const core_1 = require("@nestjs/core");
|
|
9
|
-
const common_2 = require("@opra/common");
|
|
10
|
-
const constants_js_1 = require("../constants.js");
|
|
11
|
-
const opra_http_nestjs_adapter_js_1 = require("./opra-http-nestjs-adapter.js");
|
|
12
|
-
const opra_exception_filter_js_1 = require("./services/opra-exception-filter.js");
|
|
13
|
-
const opra_middleware_js_1 = require("./services/opra-middleware.js");
|
|
14
|
-
const opraHttpNestjsAdapterToken = Symbol('OpraHttpNestjsAdapter');
|
|
15
|
-
let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
16
|
-
constructor(opraAdapter) {
|
|
17
|
-
this.opraAdapter = opraAdapter;
|
|
18
|
-
}
|
|
19
|
-
configure(consumer) {
|
|
20
|
-
consumer.apply(opra_middleware_js_1.OpraMiddleware).forRoutes({
|
|
21
|
-
path: '*',
|
|
22
|
-
method: common_1.RequestMethod.ALL,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
static forRoot(moduleOptions) {
|
|
26
|
-
return this._getDynamicModule({
|
|
27
|
-
...moduleOptions,
|
|
28
|
-
providers: [
|
|
29
|
-
...(moduleOptions?.providers || []),
|
|
30
|
-
{
|
|
31
|
-
provide: constants_js_1.OPRA_HTTP_API_CONFIG,
|
|
32
|
-
useValue: { ...moduleOptions },
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
static forRootAsync(moduleOptions) {
|
|
38
|
-
if (!moduleOptions.useFactory)
|
|
39
|
-
throw new Error('Invalid configuration. Must provide "useFactory"');
|
|
40
|
-
return this._getDynamicModule({
|
|
41
|
-
...moduleOptions,
|
|
42
|
-
providers: [
|
|
43
|
-
...(moduleOptions?.providers || []),
|
|
44
|
-
{
|
|
45
|
-
provide: constants_js_1.OPRA_HTTP_API_CONFIG,
|
|
46
|
-
inject: moduleOptions.inject,
|
|
47
|
-
useFactory: moduleOptions.useFactory,
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
static _getDynamicModule(moduleOptions) {
|
|
53
|
-
const token = moduleOptions?.token || opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter;
|
|
54
|
-
const opraNestAdapter = new opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter({
|
|
55
|
-
...moduleOptions,
|
|
56
|
-
interceptors: undefined,
|
|
57
|
-
});
|
|
58
|
-
const adapterProvider = {
|
|
59
|
-
provide: token,
|
|
60
|
-
inject: [core_1.ModuleRef, constants_js_1.OPRA_HTTP_API_CONFIG],
|
|
61
|
-
useFactory: async (moduleRef, apiConfig) => {
|
|
62
|
-
opraNestAdapter.scope = apiConfig.scope;
|
|
63
|
-
opraNestAdapter.logger =
|
|
64
|
-
opraNestAdapter.logger || new common_1.Logger(apiConfig.name);
|
|
65
|
-
opraNestAdapter._document =
|
|
66
|
-
await common_2.ApiDocumentFactory.createDocument({
|
|
67
|
-
...apiConfig,
|
|
68
|
-
api: {
|
|
69
|
-
transport: 'http',
|
|
70
|
-
name: apiConfig.name,
|
|
71
|
-
description: apiConfig.description,
|
|
72
|
-
controllers: moduleOptions.controllers,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
if (moduleOptions.interceptors) {
|
|
76
|
-
opraNestAdapter.interceptors = moduleOptions.interceptors.map(x => {
|
|
77
|
-
if ((0, objects_1.isConstructor)(x)) {
|
|
78
|
-
return async (ctx, next) => {
|
|
79
|
-
const interceptor = moduleRef.get(x);
|
|
80
|
-
if (typeof interceptor.intercept === 'function')
|
|
81
|
-
return interceptor.intercept(ctx, next);
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return x;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return opraNestAdapter;
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
return {
|
|
91
|
-
global: moduleOptions.global,
|
|
92
|
-
module: OpraHttpCoreModule_1,
|
|
93
|
-
controllers: opraNestAdapter.nestControllers,
|
|
94
|
-
providers: [
|
|
95
|
-
...(moduleOptions?.providers || []),
|
|
96
|
-
adapterProvider,
|
|
97
|
-
{
|
|
98
|
-
provide: opraHttpNestjsAdapterToken,
|
|
99
|
-
useExisting: token,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
provide: core_1.APP_FILTER,
|
|
103
|
-
useClass: opra_exception_filter_js_1.OpraExceptionFilter,
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
imports: [...(moduleOptions?.imports || [])],
|
|
107
|
-
exports: [...(moduleOptions?.exports || []), adapterProvider],
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
async onModuleDestroy() {
|
|
111
|
-
await this.opraAdapter.close();
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
exports.OpraHttpCoreModule = OpraHttpCoreModule;
|
|
115
|
-
exports.OpraHttpCoreModule = OpraHttpCoreModule = OpraHttpCoreModule_1 = tslib_1.__decorate([
|
|
116
|
-
(0, common_1.Module)({}),
|
|
117
|
-
(0, common_1.Global)(),
|
|
118
|
-
tslib_1.__metadata("design:paramtypes", [opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter])
|
|
119
|
-
], OpraHttpCoreModule);
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraHttpNestjsAdapter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
-
const objects_1 = require("@jsopen/objects");
|
|
7
|
-
const common_1 = require("@nestjs/common");
|
|
8
|
-
const common_2 = require("@opra/common");
|
|
9
|
-
const http_1 = require("@opra/http");
|
|
10
|
-
const ts_gems_1 = require("ts-gems");
|
|
11
|
-
const public_decorator_js_1 = require("../decorators/public.decorator.js");
|
|
12
|
-
const base_opra_nest_factory_js_1 = require("../helpers/base-opra-nest-factory.js");
|
|
13
|
-
class OpraHttpNestjsAdapter extends http_1.HttpAdapter {
|
|
14
|
-
constructor(options) {
|
|
15
|
-
super(options);
|
|
16
|
-
this.nestControllers = [];
|
|
17
|
-
this._addRootController(options.schemaIsPublic);
|
|
18
|
-
if (options.controllers) {
|
|
19
|
-
for (const c of options.controllers) {
|
|
20
|
-
this._addToNestControllers(c, this.basePath, []);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async close() {
|
|
25
|
-
//
|
|
26
|
-
}
|
|
27
|
-
_addRootController(isPublic) {
|
|
28
|
-
const _this = this;
|
|
29
|
-
let RootController = class RootController {
|
|
30
|
-
schema(_req, next) {
|
|
31
|
-
_this.handler.sendDocumentSchema(_req.opraContext).catch(() => next());
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
tslib_1.__decorate([
|
|
35
|
-
(0, common_1.Get)('/\\$schema'),
|
|
36
|
-
tslib_1.__param(0, (0, common_1.Req)()),
|
|
37
|
-
tslib_1.__param(1, (0, common_1.Next)()),
|
|
38
|
-
tslib_1.__metadata("design:type", Function),
|
|
39
|
-
tslib_1.__metadata("design:paramtypes", [Object, Function]),
|
|
40
|
-
tslib_1.__metadata("design:returntype", void 0)
|
|
41
|
-
], RootController.prototype, "schema", null);
|
|
42
|
-
RootController = tslib_1.__decorate([
|
|
43
|
-
(0, common_1.Controller)({
|
|
44
|
-
path: this.basePath,
|
|
45
|
-
})
|
|
46
|
-
], RootController);
|
|
47
|
-
if (isPublic) {
|
|
48
|
-
(0, public_decorator_js_1.Public)()(RootController.prototype, 'schema', Object.getOwnPropertyDescriptor(RootController.prototype, 'schema'));
|
|
49
|
-
}
|
|
50
|
-
this.nestControllers.push(RootController);
|
|
51
|
-
}
|
|
52
|
-
_addToNestControllers(sourceClass, currentPath, parentTree) {
|
|
53
|
-
const metadata = Reflect.getMetadata(common_2.HTTP_CONTROLLER_METADATA, sourceClass);
|
|
54
|
-
if (!metadata)
|
|
55
|
-
return;
|
|
56
|
-
/** Create a new controller class */
|
|
57
|
-
const newClass = {
|
|
58
|
-
[sourceClass.name]: class extends sourceClass {
|
|
59
|
-
},
|
|
60
|
-
}[sourceClass.name];
|
|
61
|
-
/** Copy metadata keys from source class to new one */
|
|
62
|
-
base_opra_nest_factory_js_1.BaseOpraNestFactory.copyDecoratorMetadata(newClass, ...parentTree);
|
|
63
|
-
(0, common_1.Controller)()(newClass);
|
|
64
|
-
const newPath = metadata.path
|
|
65
|
-
? node_path_1.default.join(currentPath, metadata.path)
|
|
66
|
-
: currentPath;
|
|
67
|
-
const adapter = this;
|
|
68
|
-
// adapter.logger =
|
|
69
|
-
/** Disable default error handler. Errors will be handled by OpraExceptionFilter */
|
|
70
|
-
adapter.handler.onError = (context, error) => {
|
|
71
|
-
throw error;
|
|
72
|
-
};
|
|
73
|
-
this.nestControllers.push(newClass);
|
|
74
|
-
let metadataKeys;
|
|
75
|
-
if (metadata.operations) {
|
|
76
|
-
for (const [k, v] of Object.entries(metadata.operations)) {
|
|
77
|
-
const operationHandler = sourceClass.prototype[k];
|
|
78
|
-
Object.defineProperty(newClass.prototype, k, {
|
|
79
|
-
writable: true,
|
|
80
|
-
/** NestJS handler method */
|
|
81
|
-
async value(_req, _res) {
|
|
82
|
-
_res.statusCode = 200;
|
|
83
|
-
const api = adapter.document.api;
|
|
84
|
-
const controller = api.findController(sourceClass);
|
|
85
|
-
const operation = controller?.operations.get(k);
|
|
86
|
-
const context = (0, ts_gems_1.asMutable)(_req.opraContext);
|
|
87
|
-
if (!(context && operation && typeof operationHandler === 'function')) {
|
|
88
|
-
throw new common_2.NotFoundError({
|
|
89
|
-
message: `No endpoint found for [${_req.method}]${_req.baseUrl}`,
|
|
90
|
-
details: {
|
|
91
|
-
path: _req.baseUrl,
|
|
92
|
-
method: _req.method,
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/** Configure the HttpContext */
|
|
97
|
-
context.operation = operation;
|
|
98
|
-
context.controller = operation.owner;
|
|
99
|
-
context.controllerInstance = this;
|
|
100
|
-
context.operationHandler = operationHandler;
|
|
101
|
-
/** Handle request */
|
|
102
|
-
await adapter.handler.handleRequest(context);
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
/** Copy metadata keys from source function to new one */
|
|
106
|
-
metadataKeys = Reflect.getOwnMetadataKeys(operationHandler);
|
|
107
|
-
const newFn = newClass.prototype[k];
|
|
108
|
-
for (const key of metadataKeys) {
|
|
109
|
-
const m = Reflect.getMetadata(key, operationHandler);
|
|
110
|
-
Reflect.defineMetadata(key, m, newFn);
|
|
111
|
-
}
|
|
112
|
-
(0, common_1.Req)()(newClass.prototype, k, 0);
|
|
113
|
-
(0, common_1.Res)()(newClass.prototype, k, 1);
|
|
114
|
-
const descriptor = Object.getOwnPropertyDescriptor(newClass.prototype, k);
|
|
115
|
-
const operationPath = v.mergePath
|
|
116
|
-
? newPath + (v.path || '')
|
|
117
|
-
: node_path_1.default.posix.join(newPath, v.path || '');
|
|
118
|
-
switch (v.method || 'GET') {
|
|
119
|
-
case 'DELETE':
|
|
120
|
-
/** Call @Delete decorator over new property */
|
|
121
|
-
(0, common_1.Delete)(operationPath)(newClass.prototype, k, descriptor);
|
|
122
|
-
break;
|
|
123
|
-
case 'GET':
|
|
124
|
-
/** Call @Get decorator over new property */
|
|
125
|
-
(0, common_1.Get)(operationPath)(newClass.prototype, k, descriptor);
|
|
126
|
-
break;
|
|
127
|
-
case 'HEAD':
|
|
128
|
-
/** Call @Head decorator over new property */
|
|
129
|
-
(0, common_1.Head)(operationPath)(newClass.prototype, k, descriptor);
|
|
130
|
-
break;
|
|
131
|
-
case 'OPTIONS':
|
|
132
|
-
/** Call @Options decorator over new property */
|
|
133
|
-
(0, common_1.Options)(operationPath)(newClass.prototype, k, descriptor);
|
|
134
|
-
break;
|
|
135
|
-
case 'PATCH':
|
|
136
|
-
/** Call @Patch decorator over new property */
|
|
137
|
-
(0, common_1.Patch)(operationPath)(newClass.prototype, k, descriptor);
|
|
138
|
-
break;
|
|
139
|
-
case 'POST':
|
|
140
|
-
/** Call @Post decorator over new property */
|
|
141
|
-
(0, common_1.Post)(operationPath)(newClass.prototype, k, descriptor);
|
|
142
|
-
break;
|
|
143
|
-
case 'PUT':
|
|
144
|
-
/** Call @Put decorator over new property */
|
|
145
|
-
(0, common_1.Put)(operationPath)(newClass.prototype, k, descriptor);
|
|
146
|
-
break;
|
|
147
|
-
case 'SEARCH':
|
|
148
|
-
/** Call @Search decorator over new property */
|
|
149
|
-
(0, common_1.Search)(operationPath)(newClass.prototype, k, descriptor);
|
|
150
|
-
break;
|
|
151
|
-
default:
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (metadata.controllers) {
|
|
157
|
-
for (const child of metadata.controllers) {
|
|
158
|
-
if (!(0, objects_1.isConstructor)(child))
|
|
159
|
-
throw new TypeError('Controllers should be injectable a class');
|
|
160
|
-
this._addToNestControllers(child, newPath, [
|
|
161
|
-
...parentTree,
|
|
162
|
-
sourceClass,
|
|
163
|
-
]);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
exports.OpraHttpNestjsAdapter = OpraHttpNestjsAdapter;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var OpraHttpModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraHttpModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const opra_http_core_module_js_1 = require("./opra-http-core.module.js");
|
|
8
|
-
let OpraHttpModule = OpraHttpModule_1 = class OpraHttpModule {
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param init
|
|
12
|
-
*/
|
|
13
|
-
static forRoot(init) {
|
|
14
|
-
return {
|
|
15
|
-
module: OpraHttpModule_1,
|
|
16
|
-
imports: [opra_http_core_module_js_1.OpraHttpCoreModule.forRoot(init)],
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param options
|
|
22
|
-
*/
|
|
23
|
-
static forRootAsync(options) {
|
|
24
|
-
return {
|
|
25
|
-
module: OpraHttpModule_1,
|
|
26
|
-
imports: [opra_http_core_module_js_1.OpraHttpCoreModule.forRootAsync(options)],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
exports.OpraHttpModule = OpraHttpModule;
|
|
31
|
-
exports.OpraHttpModule = OpraHttpModule = OpraHttpModule_1 = tslib_1.__decorate([
|
|
32
|
-
(0, common_1.Module)({})
|
|
33
|
-
], OpraHttpModule);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraExceptionFilter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const core_1 = require("@nestjs/core");
|
|
7
|
-
const opra_http_nestjs_adapter_js_1 = require("../opra-http-nestjs-adapter.js");
|
|
8
|
-
let OpraExceptionFilter = class OpraExceptionFilter extends core_1.BaseExceptionFilter {
|
|
9
|
-
constructor(moduleRef) {
|
|
10
|
-
super();
|
|
11
|
-
this.moduleRef = moduleRef;
|
|
12
|
-
}
|
|
13
|
-
catch(exception, host) {
|
|
14
|
-
const ctx = host.switchToHttp().getRequest().opraContext;
|
|
15
|
-
if (ctx) {
|
|
16
|
-
const adapter = this.moduleRef.get(opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter);
|
|
17
|
-
ctx.errors.push(exception);
|
|
18
|
-
return adapter.handler.sendResponse(ctx);
|
|
19
|
-
}
|
|
20
|
-
super.catch(exception, host);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
exports.OpraExceptionFilter = OpraExceptionFilter;
|
|
24
|
-
exports.OpraExceptionFilter = OpraExceptionFilter = tslib_1.__decorate([
|
|
25
|
-
(0, common_1.Catch)(),
|
|
26
|
-
tslib_1.__metadata("design:paramtypes", [core_1.ModuleRef])
|
|
27
|
-
], OpraExceptionFilter);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpraMiddleware = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const http_1 = require("@opra/http");
|
|
7
|
-
const opra_http_nestjs_adapter_js_1 = require("../opra-http-nestjs-adapter.js");
|
|
8
|
-
let OpraMiddleware = class OpraMiddleware {
|
|
9
|
-
constructor(opraAdapter) {
|
|
10
|
-
this.opraAdapter = opraAdapter;
|
|
11
|
-
}
|
|
12
|
-
use(req, res, next) {
|
|
13
|
-
const request = http_1.HttpIncoming.from(req);
|
|
14
|
-
const response = http_1.HttpOutgoing.from(res);
|
|
15
|
-
/** Create the HttpContext */
|
|
16
|
-
const context = new http_1.HttpContext({
|
|
17
|
-
adapter: this.opraAdapter,
|
|
18
|
-
platform: req.route ? 'express' : 'fastify',
|
|
19
|
-
request,
|
|
20
|
-
response,
|
|
21
|
-
});
|
|
22
|
-
req.opraContext = context;
|
|
23
|
-
this.opraAdapter
|
|
24
|
-
.emitAsync('createContext', context)
|
|
25
|
-
.then(() => next())
|
|
26
|
-
.catch(next);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
exports.OpraMiddleware = OpraMiddleware;
|
|
30
|
-
exports.OpraMiddleware = OpraMiddleware = tslib_1.__decorate([
|
|
31
|
-
(0, common_1.Injectable)(),
|
|
32
|
-
tslib_1.__metadata("design:paramtypes", [opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter])
|
|
33
|
-
], OpraMiddleware);
|