@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
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var OpraKafkaCoreModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraKafkaCoreModule = 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 kafka_1 = require("@opra/kafka");
|
|
11
|
-
const constants_js_1 = require("../constants.js");
|
|
12
|
-
const rpc_controller_factory_service_js_1 = require("../helpers/rpc-controller-factory.service.js");
|
|
13
|
-
const opraKafkaNestjsAdapterToken = Symbol('OpraKafkaNestjsAdapter');
|
|
14
|
-
let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
15
|
-
constructor(controllerFactory, adapter, config) {
|
|
16
|
-
this.controllerFactory = controllerFactory;
|
|
17
|
-
this.adapter = adapter;
|
|
18
|
-
this.config = config;
|
|
19
|
-
}
|
|
20
|
-
static forRoot(moduleOptions) {
|
|
21
|
-
return this._getDynamicModule({
|
|
22
|
-
...moduleOptions,
|
|
23
|
-
providers: [
|
|
24
|
-
...(moduleOptions?.providers || []),
|
|
25
|
-
{
|
|
26
|
-
provide: constants_js_1.OPRA_KAFKA_MODULE_CONFIG,
|
|
27
|
-
useValue: {
|
|
28
|
-
...moduleOptions,
|
|
29
|
-
logger: moduleOptions.logger || new common_1.Logger(moduleOptions.name),
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
static forRootAsync(moduleOptions) {
|
|
36
|
-
if (!moduleOptions.useFactory)
|
|
37
|
-
throw new Error('Invalid configuration. Must provide "useFactory"');
|
|
38
|
-
return this._getDynamicModule({
|
|
39
|
-
...moduleOptions,
|
|
40
|
-
providers: [
|
|
41
|
-
...(moduleOptions?.providers || []),
|
|
42
|
-
{
|
|
43
|
-
provide: constants_js_1.OPRA_KAFKA_MODULE_CONFIG,
|
|
44
|
-
inject: moduleOptions.inject,
|
|
45
|
-
useFactory: async (...args) => {
|
|
46
|
-
const result = await moduleOptions.useFactory(...args);
|
|
47
|
-
result.logger = result.logger || new common_1.Logger(result.name);
|
|
48
|
-
return result;
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
static _getDynamicModule(moduleOptions) {
|
|
55
|
-
const token = moduleOptions.id || kafka_1.KafkaAdapter;
|
|
56
|
-
const adapterProvider = {
|
|
57
|
-
provide: token,
|
|
58
|
-
inject: [rpc_controller_factory_service_js_1.RpcControllerFactory, core_1.ModuleRef, constants_js_1.OPRA_KAFKA_MODULE_CONFIG],
|
|
59
|
-
useFactory: async (controllerFactory, moduleRef, config) => {
|
|
60
|
-
const controllers = controllerFactory
|
|
61
|
-
.exploreControllers()
|
|
62
|
-
.map(x => x.wrapper.instance.constructor);
|
|
63
|
-
const document = await common_2.ApiDocumentFactory.createDocument({
|
|
64
|
-
info: config.info,
|
|
65
|
-
types: config.types,
|
|
66
|
-
references: config.references,
|
|
67
|
-
api: {
|
|
68
|
-
name: config.name,
|
|
69
|
-
description: config.description,
|
|
70
|
-
transport: 'rpc',
|
|
71
|
-
platform: kafka_1.KafkaAdapter.PlatformName,
|
|
72
|
-
controllers,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
const interceptors = moduleOptions.interceptors
|
|
76
|
-
? 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
|
-
: undefined;
|
|
87
|
-
return new kafka_1.KafkaAdapter(document, { ...config, interceptors });
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
return {
|
|
91
|
-
global: moduleOptions.global,
|
|
92
|
-
module: OpraKafkaCoreModule_1,
|
|
93
|
-
controllers: moduleOptions.controllers,
|
|
94
|
-
providers: [
|
|
95
|
-
...(moduleOptions?.providers || []),
|
|
96
|
-
rpc_controller_factory_service_js_1.RpcControllerFactory,
|
|
97
|
-
adapterProvider,
|
|
98
|
-
{
|
|
99
|
-
provide: opraKafkaNestjsAdapterToken,
|
|
100
|
-
useExisting: token,
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
imports: [...(moduleOptions?.imports || [])],
|
|
104
|
-
exports: [...(moduleOptions?.exports || []), adapterProvider],
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
onModuleInit() {
|
|
108
|
-
/** NestJS initialize controller instances on init stage.
|
|
109
|
-
* So we should update instance properties */
|
|
110
|
-
const rpcApi = this.adapter.document.rpcApi;
|
|
111
|
-
const controllers = Array.from(rpcApi.controllers.values());
|
|
112
|
-
for (const { wrapper } of this.controllerFactory
|
|
113
|
-
.exploreControllers()
|
|
114
|
-
.values()) {
|
|
115
|
-
const ctor = wrapper.instance.constructor;
|
|
116
|
-
const controller = controllers.find(x => x.ctor === ctor);
|
|
117
|
-
if (controller) {
|
|
118
|
-
controller.instance = wrapper.instance;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async onApplicationBootstrap() {
|
|
123
|
-
await this.adapter.start();
|
|
124
|
-
}
|
|
125
|
-
async onApplicationShutdown() {
|
|
126
|
-
await this.adapter.close();
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
exports.OpraKafkaCoreModule = OpraKafkaCoreModule;
|
|
130
|
-
exports.OpraKafkaCoreModule = OpraKafkaCoreModule = OpraKafkaCoreModule_1 = tslib_1.__decorate([
|
|
131
|
-
(0, common_1.Module)({}),
|
|
132
|
-
(0, common_1.Global)(),
|
|
133
|
-
tslib_1.__param(1, (0, common_1.Inject)(opraKafkaNestjsAdapterToken)),
|
|
134
|
-
tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_KAFKA_MODULE_CONFIG)),
|
|
135
|
-
tslib_1.__metadata("design:paramtypes", [rpc_controller_factory_service_js_1.RpcControllerFactory,
|
|
136
|
-
kafka_1.KafkaAdapter, Object])
|
|
137
|
-
], OpraKafkaCoreModule);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var OpraKafkaModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraKafkaModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const opra_kafka_core_module_js_1 = require("./opra-kafka-core.module.js");
|
|
8
|
-
let OpraKafkaModule = OpraKafkaModule_1 = class OpraKafkaModule {
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param options
|
|
12
|
-
*/
|
|
13
|
-
static forRoot(options) {
|
|
14
|
-
return {
|
|
15
|
-
module: OpraKafkaModule_1,
|
|
16
|
-
imports: [opra_kafka_core_module_js_1.OpraKafkaCoreModule.forRoot(options)],
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param options
|
|
22
|
-
*/
|
|
23
|
-
static forRootAsync(options) {
|
|
24
|
-
return {
|
|
25
|
-
module: OpraKafkaModule_1,
|
|
26
|
-
imports: [opra_kafka_core_module_js_1.OpraKafkaCoreModule.forRootAsync(options)],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
exports.OpraKafkaModule = OpraKafkaModule;
|
|
31
|
-
exports.OpraKafkaModule = OpraKafkaModule = OpraKafkaModule_1 = tslib_1.__decorate([
|
|
32
|
-
(0, common_1.Module)({})
|
|
33
|
-
], OpraKafkaModule);
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var OpraRabbitmqCoreModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraRabbitmqCoreModule = 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 rabbitmq_1 = require("@opra/rabbitmq");
|
|
11
|
-
const constants_js_1 = require("../constants.js");
|
|
12
|
-
const rpc_controller_factory_service_js_1 = require("../helpers/rpc-controller-factory.service.js");
|
|
13
|
-
const opraRabbitmqNestjsAdapterToken = Symbol('OpraRabbitmqNestjsAdapter');
|
|
14
|
-
let OpraRabbitmqCoreModule = OpraRabbitmqCoreModule_1 = class OpraRabbitmqCoreModule {
|
|
15
|
-
constructor(controllerFactory, adapter, config) {
|
|
16
|
-
this.controllerFactory = controllerFactory;
|
|
17
|
-
this.adapter = adapter;
|
|
18
|
-
this.config = config;
|
|
19
|
-
}
|
|
20
|
-
static forRoot(moduleOptions) {
|
|
21
|
-
return this._getDynamicModule({
|
|
22
|
-
...moduleOptions,
|
|
23
|
-
providers: [
|
|
24
|
-
...(moduleOptions?.providers || []),
|
|
25
|
-
{
|
|
26
|
-
provide: constants_js_1.OPRA_RMQ_MODULE_CONFIG,
|
|
27
|
-
useValue: {
|
|
28
|
-
...moduleOptions,
|
|
29
|
-
logger: moduleOptions.logger || new common_1.Logger(moduleOptions.name),
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
static forRootAsync(moduleOptions) {
|
|
36
|
-
if (!moduleOptions.useFactory)
|
|
37
|
-
throw new Error('Invalid configuration. Must provide "useFactory"');
|
|
38
|
-
return this._getDynamicModule({
|
|
39
|
-
...moduleOptions,
|
|
40
|
-
providers: [
|
|
41
|
-
...(moduleOptions?.providers || []),
|
|
42
|
-
{
|
|
43
|
-
provide: constants_js_1.OPRA_RMQ_MODULE_CONFIG,
|
|
44
|
-
inject: moduleOptions.inject,
|
|
45
|
-
useFactory: async (...args) => {
|
|
46
|
-
const result = await moduleOptions.useFactory(...args);
|
|
47
|
-
result.logger = result.logger || new common_1.Logger(result.name);
|
|
48
|
-
return result;
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
static _getDynamicModule(moduleOptions) {
|
|
55
|
-
const token = moduleOptions.id || rabbitmq_1.RabbitmqAdapter;
|
|
56
|
-
const adapterProvider = {
|
|
57
|
-
provide: token,
|
|
58
|
-
inject: [rpc_controller_factory_service_js_1.RpcControllerFactory, core_1.ModuleRef, constants_js_1.OPRA_RMQ_MODULE_CONFIG],
|
|
59
|
-
useFactory: async (controllerFactory, moduleRef, config) => {
|
|
60
|
-
const controllers = controllerFactory
|
|
61
|
-
.exploreControllers()
|
|
62
|
-
.map(x => x.wrapper.instance.constructor);
|
|
63
|
-
const document = await common_2.ApiDocumentFactory.createDocument({
|
|
64
|
-
info: config.info,
|
|
65
|
-
types: config.types,
|
|
66
|
-
references: config.references,
|
|
67
|
-
api: {
|
|
68
|
-
name: config.name,
|
|
69
|
-
description: config.description,
|
|
70
|
-
transport: 'rpc',
|
|
71
|
-
platform: rabbitmq_1.RabbitmqAdapter.PlatformName,
|
|
72
|
-
controllers,
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
const interceptors = moduleOptions.interceptors
|
|
76
|
-
? 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
|
-
: undefined;
|
|
87
|
-
return new rabbitmq_1.RabbitmqAdapter(document, { ...config, interceptors });
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
return {
|
|
91
|
-
global: moduleOptions.global,
|
|
92
|
-
module: OpraRabbitmqCoreModule_1,
|
|
93
|
-
controllers: moduleOptions.controllers,
|
|
94
|
-
providers: [
|
|
95
|
-
...(moduleOptions?.providers || []),
|
|
96
|
-
rpc_controller_factory_service_js_1.RpcControllerFactory,
|
|
97
|
-
adapterProvider,
|
|
98
|
-
{
|
|
99
|
-
provide: opraRabbitmqNestjsAdapterToken,
|
|
100
|
-
useExisting: token,
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
imports: [...(moduleOptions?.imports || [])],
|
|
104
|
-
exports: [...(moduleOptions?.exports || []), adapterProvider],
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
onModuleInit() {
|
|
108
|
-
/** NestJS initialize controller instances on init stage.
|
|
109
|
-
* So we should update instance properties */
|
|
110
|
-
const rpcApi = this.adapter.document.rpcApi;
|
|
111
|
-
const controllers = Array.from(rpcApi.controllers.values());
|
|
112
|
-
for (const { wrapper } of this.controllerFactory
|
|
113
|
-
.exploreControllers()
|
|
114
|
-
.values()) {
|
|
115
|
-
const ctor = wrapper.instance.constructor;
|
|
116
|
-
const controller = controllers.find(x => x.ctor === ctor);
|
|
117
|
-
if (controller) {
|
|
118
|
-
controller.instance = wrapper.instance;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async onApplicationBootstrap() {
|
|
123
|
-
await this.adapter.start();
|
|
124
|
-
}
|
|
125
|
-
async onApplicationShutdown() {
|
|
126
|
-
await this.adapter.close();
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
exports.OpraRabbitmqCoreModule = OpraRabbitmqCoreModule;
|
|
130
|
-
exports.OpraRabbitmqCoreModule = OpraRabbitmqCoreModule = OpraRabbitmqCoreModule_1 = tslib_1.__decorate([
|
|
131
|
-
(0, common_1.Module)({}),
|
|
132
|
-
(0, common_1.Global)(),
|
|
133
|
-
tslib_1.__param(1, (0, common_1.Inject)(opraRabbitmqNestjsAdapterToken)),
|
|
134
|
-
tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_RMQ_MODULE_CONFIG)),
|
|
135
|
-
tslib_1.__metadata("design:paramtypes", [rpc_controller_factory_service_js_1.RpcControllerFactory,
|
|
136
|
-
rabbitmq_1.RabbitmqAdapter, Object])
|
|
137
|
-
], OpraRabbitmqCoreModule);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var OpraRabbitmqModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.OpraRabbitmqModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const opra_rabbitmq_core_module_js_1 = require("./opra-rabbitmq-core.module.js");
|
|
8
|
-
let OpraRabbitmqModule = OpraRabbitmqModule_1 = class OpraRabbitmqModule {
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param options
|
|
12
|
-
*/
|
|
13
|
-
static forRoot(options) {
|
|
14
|
-
return {
|
|
15
|
-
module: OpraRabbitmqModule_1,
|
|
16
|
-
imports: [opra_rabbitmq_core_module_js_1.OpraRabbitmqCoreModule.forRoot(options)],
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param options
|
|
22
|
-
*/
|
|
23
|
-
static forRootAsync(options) {
|
|
24
|
-
return {
|
|
25
|
-
module: OpraRabbitmqModule_1,
|
|
26
|
-
imports: [opra_rabbitmq_core_module_js_1.OpraRabbitmqCoreModule.forRootAsync(options)],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
exports.OpraRabbitmqModule = OpraRabbitmqModule;
|
|
31
|
-
exports.OpraRabbitmqModule = OpraRabbitmqModule = OpraRabbitmqModule_1 = tslib_1.__decorate([
|
|
32
|
-
(0, common_1.Module)({})
|
|
33
|
-
], OpraRabbitmqModule);
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
var OpraHttpCoreModule_1;
|
|
2
|
-
import { __decorate, __metadata } from "tslib";
|
|
3
|
-
import { isConstructor } from '@jsopen/objects';
|
|
4
|
-
import { Global, Logger, Module, RequestMethod, } from '@nestjs/common';
|
|
5
|
-
import { APP_FILTER, ModuleRef } from '@nestjs/core';
|
|
6
|
-
import { ApiDocumentFactory } from '@opra/common';
|
|
7
|
-
import { OPRA_HTTP_API_CONFIG } from '../constants.js';
|
|
8
|
-
import { OpraHttpNestjsAdapter } from './opra-http-nestjs-adapter.js';
|
|
9
|
-
import { OpraExceptionFilter } from './services/opra-exception-filter.js';
|
|
10
|
-
import { OpraMiddleware } from './services/opra-middleware.js';
|
|
11
|
-
const opraHttpNestjsAdapterToken = Symbol('OpraHttpNestjsAdapter');
|
|
12
|
-
let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
13
|
-
constructor(opraAdapter) {
|
|
14
|
-
this.opraAdapter = opraAdapter;
|
|
15
|
-
}
|
|
16
|
-
configure(consumer) {
|
|
17
|
-
consumer.apply(OpraMiddleware).forRoutes({
|
|
18
|
-
path: '*',
|
|
19
|
-
method: RequestMethod.ALL,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
static forRoot(moduleOptions) {
|
|
23
|
-
return this._getDynamicModule({
|
|
24
|
-
...moduleOptions,
|
|
25
|
-
providers: [
|
|
26
|
-
...(moduleOptions?.providers || []),
|
|
27
|
-
{
|
|
28
|
-
provide: OPRA_HTTP_API_CONFIG,
|
|
29
|
-
useValue: { ...moduleOptions },
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
static forRootAsync(moduleOptions) {
|
|
35
|
-
if (!moduleOptions.useFactory)
|
|
36
|
-
throw new Error('Invalid configuration. Must provide "useFactory"');
|
|
37
|
-
return this._getDynamicModule({
|
|
38
|
-
...moduleOptions,
|
|
39
|
-
providers: [
|
|
40
|
-
...(moduleOptions?.providers || []),
|
|
41
|
-
{
|
|
42
|
-
provide: OPRA_HTTP_API_CONFIG,
|
|
43
|
-
inject: moduleOptions.inject,
|
|
44
|
-
useFactory: moduleOptions.useFactory,
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
static _getDynamicModule(moduleOptions) {
|
|
50
|
-
const token = moduleOptions?.token || OpraHttpNestjsAdapter;
|
|
51
|
-
const opraNestAdapter = new OpraHttpNestjsAdapter({
|
|
52
|
-
...moduleOptions,
|
|
53
|
-
interceptors: undefined,
|
|
54
|
-
});
|
|
55
|
-
const adapterProvider = {
|
|
56
|
-
provide: token,
|
|
57
|
-
inject: [ModuleRef, OPRA_HTTP_API_CONFIG],
|
|
58
|
-
useFactory: async (moduleRef, apiConfig) => {
|
|
59
|
-
opraNestAdapter.scope = apiConfig.scope;
|
|
60
|
-
opraNestAdapter.logger =
|
|
61
|
-
opraNestAdapter.logger || new Logger(apiConfig.name);
|
|
62
|
-
opraNestAdapter._document =
|
|
63
|
-
await ApiDocumentFactory.createDocument({
|
|
64
|
-
...apiConfig,
|
|
65
|
-
api: {
|
|
66
|
-
transport: 'http',
|
|
67
|
-
name: apiConfig.name,
|
|
68
|
-
description: apiConfig.description,
|
|
69
|
-
controllers: moduleOptions.controllers,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
if (moduleOptions.interceptors) {
|
|
73
|
-
opraNestAdapter.interceptors = moduleOptions.interceptors.map(x => {
|
|
74
|
-
if (isConstructor(x)) {
|
|
75
|
-
return async (ctx, next) => {
|
|
76
|
-
const interceptor = moduleRef.get(x);
|
|
77
|
-
if (typeof interceptor.intercept === 'function')
|
|
78
|
-
return interceptor.intercept(ctx, next);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return x;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return opraNestAdapter;
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
return {
|
|
88
|
-
global: moduleOptions.global,
|
|
89
|
-
module: OpraHttpCoreModule_1,
|
|
90
|
-
controllers: opraNestAdapter.nestControllers,
|
|
91
|
-
providers: [
|
|
92
|
-
...(moduleOptions?.providers || []),
|
|
93
|
-
adapterProvider,
|
|
94
|
-
{
|
|
95
|
-
provide: opraHttpNestjsAdapterToken,
|
|
96
|
-
useExisting: token,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
provide: APP_FILTER,
|
|
100
|
-
useClass: OpraExceptionFilter,
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
imports: [...(moduleOptions?.imports || [])],
|
|
104
|
-
exports: [...(moduleOptions?.exports || []), adapterProvider],
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
async onModuleDestroy() {
|
|
108
|
-
await this.opraAdapter.close();
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
OpraHttpCoreModule = OpraHttpCoreModule_1 = __decorate([
|
|
112
|
-
Module({}),
|
|
113
|
-
Global(),
|
|
114
|
-
__metadata("design:paramtypes", [OpraHttpNestjsAdapter])
|
|
115
|
-
], OpraHttpCoreModule);
|
|
116
|
-
export { OpraHttpCoreModule };
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import nodePath from 'node:path';
|
|
3
|
-
import { isConstructor } from '@jsopen/objects';
|
|
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';
|
|
6
|
-
import { HttpAdapter } from '@opra/http';
|
|
7
|
-
import { asMutable } from 'ts-gems';
|
|
8
|
-
import { Public } from '../decorators/public.decorator.js';
|
|
9
|
-
import { BaseOpraNestFactory } from '../helpers/base-opra-nest-factory.js';
|
|
10
|
-
export class OpraHttpNestjsAdapter extends HttpAdapter {
|
|
11
|
-
constructor(options) {
|
|
12
|
-
super(options);
|
|
13
|
-
this.nestControllers = [];
|
|
14
|
-
this._addRootController(options.schemaIsPublic);
|
|
15
|
-
if (options.controllers) {
|
|
16
|
-
for (const c of options.controllers) {
|
|
17
|
-
this._addToNestControllers(c, this.basePath, []);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
async close() {
|
|
22
|
-
//
|
|
23
|
-
}
|
|
24
|
-
_addRootController(isPublic) {
|
|
25
|
-
const _this = this;
|
|
26
|
-
let RootController = class RootController {
|
|
27
|
-
schema(_req, next) {
|
|
28
|
-
_this.handler.sendDocumentSchema(_req.opraContext).catch(() => next());
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
__decorate([
|
|
32
|
-
Get('/\\$schema'),
|
|
33
|
-
__param(0, Req()),
|
|
34
|
-
__param(1, Next()),
|
|
35
|
-
__metadata("design:type", Function),
|
|
36
|
-
__metadata("design:paramtypes", [Object, Function]),
|
|
37
|
-
__metadata("design:returntype", void 0)
|
|
38
|
-
], RootController.prototype, "schema", null);
|
|
39
|
-
RootController = __decorate([
|
|
40
|
-
Controller({
|
|
41
|
-
path: this.basePath,
|
|
42
|
-
})
|
|
43
|
-
], RootController);
|
|
44
|
-
if (isPublic) {
|
|
45
|
-
Public()(RootController.prototype, 'schema', Object.getOwnPropertyDescriptor(RootController.prototype, 'schema'));
|
|
46
|
-
}
|
|
47
|
-
this.nestControllers.push(RootController);
|
|
48
|
-
}
|
|
49
|
-
_addToNestControllers(sourceClass, currentPath, parentTree) {
|
|
50
|
-
const metadata = Reflect.getMetadata(HTTP_CONTROLLER_METADATA, sourceClass);
|
|
51
|
-
if (!metadata)
|
|
52
|
-
return;
|
|
53
|
-
/** Create a new controller class */
|
|
54
|
-
const newClass = {
|
|
55
|
-
[sourceClass.name]: class extends sourceClass {
|
|
56
|
-
},
|
|
57
|
-
}[sourceClass.name];
|
|
58
|
-
/** Copy metadata keys from source class to new one */
|
|
59
|
-
BaseOpraNestFactory.copyDecoratorMetadata(newClass, ...parentTree);
|
|
60
|
-
Controller()(newClass);
|
|
61
|
-
const newPath = metadata.path
|
|
62
|
-
? nodePath.join(currentPath, metadata.path)
|
|
63
|
-
: currentPath;
|
|
64
|
-
const adapter = this;
|
|
65
|
-
// adapter.logger =
|
|
66
|
-
/** Disable default error handler. Errors will be handled by OpraExceptionFilter */
|
|
67
|
-
adapter.handler.onError = (context, error) => {
|
|
68
|
-
throw error;
|
|
69
|
-
};
|
|
70
|
-
this.nestControllers.push(newClass);
|
|
71
|
-
let metadataKeys;
|
|
72
|
-
if (metadata.operations) {
|
|
73
|
-
for (const [k, v] of Object.entries(metadata.operations)) {
|
|
74
|
-
const operationHandler = sourceClass.prototype[k];
|
|
75
|
-
Object.defineProperty(newClass.prototype, k, {
|
|
76
|
-
writable: true,
|
|
77
|
-
/** NestJS handler method */
|
|
78
|
-
async value(_req, _res) {
|
|
79
|
-
_res.statusCode = 200;
|
|
80
|
-
const api = adapter.document.api;
|
|
81
|
-
const controller = api.findController(sourceClass);
|
|
82
|
-
const operation = controller?.operations.get(k);
|
|
83
|
-
const context = asMutable(_req.opraContext);
|
|
84
|
-
if (!(context && operation && typeof operationHandler === 'function')) {
|
|
85
|
-
throw new NotFoundError({
|
|
86
|
-
message: `No endpoint found for [${_req.method}]${_req.baseUrl}`,
|
|
87
|
-
details: {
|
|
88
|
-
path: _req.baseUrl,
|
|
89
|
-
method: _req.method,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
/** Configure the HttpContext */
|
|
94
|
-
context.operation = operation;
|
|
95
|
-
context.controller = operation.owner;
|
|
96
|
-
context.controllerInstance = this;
|
|
97
|
-
context.operationHandler = operationHandler;
|
|
98
|
-
/** Handle request */
|
|
99
|
-
await adapter.handler.handleRequest(context);
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
/** Copy metadata keys from source function to new one */
|
|
103
|
-
metadataKeys = Reflect.getOwnMetadataKeys(operationHandler);
|
|
104
|
-
const newFn = newClass.prototype[k];
|
|
105
|
-
for (const key of metadataKeys) {
|
|
106
|
-
const m = Reflect.getMetadata(key, operationHandler);
|
|
107
|
-
Reflect.defineMetadata(key, m, newFn);
|
|
108
|
-
}
|
|
109
|
-
Req()(newClass.prototype, k, 0);
|
|
110
|
-
Res()(newClass.prototype, k, 1);
|
|
111
|
-
const descriptor = Object.getOwnPropertyDescriptor(newClass.prototype, k);
|
|
112
|
-
const operationPath = v.mergePath
|
|
113
|
-
? newPath + (v.path || '')
|
|
114
|
-
: nodePath.posix.join(newPath, v.path || '');
|
|
115
|
-
switch (v.method || 'GET') {
|
|
116
|
-
case 'DELETE':
|
|
117
|
-
/** Call @Delete decorator over new property */
|
|
118
|
-
Delete(operationPath)(newClass.prototype, k, descriptor);
|
|
119
|
-
break;
|
|
120
|
-
case 'GET':
|
|
121
|
-
/** Call @Get decorator over new property */
|
|
122
|
-
Get(operationPath)(newClass.prototype, k, descriptor);
|
|
123
|
-
break;
|
|
124
|
-
case 'HEAD':
|
|
125
|
-
/** Call @Head decorator over new property */
|
|
126
|
-
Head(operationPath)(newClass.prototype, k, descriptor);
|
|
127
|
-
break;
|
|
128
|
-
case 'OPTIONS':
|
|
129
|
-
/** Call @Options decorator over new property */
|
|
130
|
-
Options(operationPath)(newClass.prototype, k, descriptor);
|
|
131
|
-
break;
|
|
132
|
-
case 'PATCH':
|
|
133
|
-
/** Call @Patch decorator over new property */
|
|
134
|
-
Patch(operationPath)(newClass.prototype, k, descriptor);
|
|
135
|
-
break;
|
|
136
|
-
case 'POST':
|
|
137
|
-
/** Call @Post decorator over new property */
|
|
138
|
-
Post(operationPath)(newClass.prototype, k, descriptor);
|
|
139
|
-
break;
|
|
140
|
-
case 'PUT':
|
|
141
|
-
/** Call @Put decorator over new property */
|
|
142
|
-
Put(operationPath)(newClass.prototype, k, descriptor);
|
|
143
|
-
break;
|
|
144
|
-
case 'SEARCH':
|
|
145
|
-
/** Call @Search decorator over new property */
|
|
146
|
-
Search(operationPath)(newClass.prototype, k, descriptor);
|
|
147
|
-
break;
|
|
148
|
-
default:
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (metadata.controllers) {
|
|
154
|
-
for (const child of metadata.controllers) {
|
|
155
|
-
if (!isConstructor(child))
|
|
156
|
-
throw new TypeError('Controllers should be injectable a class');
|
|
157
|
-
this._addToNestControllers(child, newPath, [
|
|
158
|
-
...parentTree,
|
|
159
|
-
sourceClass,
|
|
160
|
-
]);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
var OpraHttpModule_1;
|
|
2
|
-
import { __decorate } from "tslib";
|
|
3
|
-
import { Module } from '@nestjs/common';
|
|
4
|
-
import { OpraHttpCoreModule } from './opra-http-core.module.js';
|
|
5
|
-
let OpraHttpModule = OpraHttpModule_1 = class OpraHttpModule {
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param init
|
|
9
|
-
*/
|
|
10
|
-
static forRoot(init) {
|
|
11
|
-
return {
|
|
12
|
-
module: OpraHttpModule_1,
|
|
13
|
-
imports: [OpraHttpCoreModule.forRoot(init)],
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param options
|
|
19
|
-
*/
|
|
20
|
-
static forRootAsync(options) {
|
|
21
|
-
return {
|
|
22
|
-
module: OpraHttpModule_1,
|
|
23
|
-
imports: [OpraHttpCoreModule.forRootAsync(options)],
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
OpraHttpModule = OpraHttpModule_1 = __decorate([
|
|
28
|
-
Module({})
|
|
29
|
-
], OpraHttpModule);
|
|
30
|
-
export { OpraHttpModule };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { Catch } from '@nestjs/common';
|
|
3
|
-
import { BaseExceptionFilter, ModuleRef } from '@nestjs/core';
|
|
4
|
-
import { OpraHttpNestjsAdapter } from '../opra-http-nestjs-adapter.js';
|
|
5
|
-
let OpraExceptionFilter = class OpraExceptionFilter extends BaseExceptionFilter {
|
|
6
|
-
constructor(moduleRef) {
|
|
7
|
-
super();
|
|
8
|
-
this.moduleRef = moduleRef;
|
|
9
|
-
}
|
|
10
|
-
catch(exception, host) {
|
|
11
|
-
const ctx = host.switchToHttp().getRequest().opraContext;
|
|
12
|
-
if (ctx) {
|
|
13
|
-
const adapter = this.moduleRef.get(OpraHttpNestjsAdapter);
|
|
14
|
-
ctx.errors.push(exception);
|
|
15
|
-
return adapter.handler.sendResponse(ctx);
|
|
16
|
-
}
|
|
17
|
-
super.catch(exception, host);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
OpraExceptionFilter = __decorate([
|
|
21
|
-
Catch(),
|
|
22
|
-
__metadata("design:paramtypes", [ModuleRef])
|
|
23
|
-
], OpraExceptionFilter);
|
|
24
|
-
export { OpraExceptionFilter };
|