@opra/nestjs 1.0.0-beta.3 → 1.0.0-beta.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/augmentation/nestjs.augmentation.js +8 -0
- package/cjs/constants.js +2 -1
- package/cjs/{opra-http-core.module.js → http/opra-http-core.module.js} +9 -9
- package/cjs/{opra-nestjs-adapter.js → http/opra-http-nestjs-adapter.js} +10 -10
- package/cjs/{opra-http.module.js → http/opra-http.module.js} +2 -3
- package/cjs/{services → http/services}/opra-exception-filter.js +2 -2
- package/cjs/{services → http/services}/opra-middleware.js +3 -3
- package/cjs/index.js +4 -2
- package/cjs/rpc/kafka/opra-kafka-core.module.js +60 -0
- package/cjs/rpc/kafka/opra-kafka-nestjs-adapter.js +79 -0
- package/cjs/rpc/kafka/opra-kafka.module.js +23 -0
- package/esm/augmentation/nestjs.augmentation.js +8 -0
- package/esm/constants.js +1 -0
- package/esm/{opra-http-core.module.js → http/opra-http-core.module.js} +9 -9
- package/esm/{opra-nestjs-adapter.js → http/opra-http-nestjs-adapter.js} +8 -8
- package/esm/{opra-http.module.js → http/opra-http.module.js} +2 -3
- package/esm/{services → http/services}/opra-exception-filter.js +2 -2
- package/esm/{services → http/services}/opra-middleware.js +3 -3
- package/esm/index.js +4 -2
- package/esm/rpc/kafka/opra-kafka-core.module.js +57 -0
- package/esm/rpc/kafka/opra-kafka-nestjs-adapter.js +75 -0
- package/esm/rpc/kafka/opra-kafka.module.js +20 -0
- package/package.json +8 -4
- package/types/constants.d.ts +1 -0
- package/types/{opra-http-core.module.d.ts → http/opra-http-core.module.d.ts} +4 -4
- package/types/{opra-nestjs-adapter.d.ts → http/opra-http-nestjs-adapter.d.ts} +2 -2
- package/types/{opra-http.module.d.ts → http/opra-http.module.d.ts} +2 -2
- package/types/{services → http/services}/opra-middleware.d.ts +3 -3
- package/types/index.d.cts +4 -2
- package/types/index.d.ts +4 -2
- package/types/rpc/kafka/opra-kafka-core.module.d.ts +12 -0
- package/types/rpc/kafka/opra-kafka-nestjs-adapter.d.ts +19 -0
- package/types/rpc/kafka/opra-kafka.module.d.ts +21 -0
- /package/types/{services → http/services}/opra-exception-filter.d.ts +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("@nestjs/common");
|
|
3
4
|
const external_exception_filter_js_1 = require("@nestjs/core/exceptions/external-exception-filter.js");
|
|
5
|
+
const common_2 = require("@opra/common");
|
|
6
|
+
const { RpcControllerDecoratorFactory } = common_2.classes;
|
|
4
7
|
const oldCatchMethod = external_exception_filter_js_1.ExternalExceptionFilter.prototype.catch;
|
|
5
8
|
external_exception_filter_js_1.ExternalExceptionFilter.prototype.catch = function (exception, host) {
|
|
6
9
|
const opraContext = host.getArgByIndex(3);
|
|
@@ -9,3 +12,8 @@ external_exception_filter_js_1.ExternalExceptionFilter.prototype.catch = functio
|
|
|
9
12
|
throw exception;
|
|
10
13
|
oldCatchMethod(exception, host);
|
|
11
14
|
};
|
|
15
|
+
RpcControllerDecoratorFactory.augment((decorator, decoratorChain) => {
|
|
16
|
+
decoratorChain.push((_, target) => {
|
|
17
|
+
(0, common_1.Controller)()(target);
|
|
18
|
+
});
|
|
19
|
+
});
|
package/cjs/constants.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OPRA_HTTP_MODULE_OPTIONS = exports.IS_PUBLIC_KEY = void 0;
|
|
3
|
+
exports.OPRA_KAFKA_MODULE_OPTIONS = exports.OPRA_HTTP_MODULE_OPTIONS = exports.IS_PUBLIC_KEY = void 0;
|
|
4
4
|
exports.IS_PUBLIC_KEY = 'opra:isPublic';
|
|
5
5
|
exports.OPRA_HTTP_MODULE_OPTIONS = 'OPRA_HTTP_MODULE_OPTIONS';
|
|
6
|
+
exports.OPRA_KAFKA_MODULE_OPTIONS = 'OPRA_KAFKA_MODULE_OPTIONS';
|
|
@@ -7,8 +7,8 @@ const common_1 = require("@nestjs/common");
|
|
|
7
7
|
const core_1 = require("@nestjs/core");
|
|
8
8
|
const common_2 = require("@opra/common");
|
|
9
9
|
const ts_gems_1 = require("ts-gems");
|
|
10
|
-
const constants_js_1 = require("
|
|
11
|
-
const
|
|
10
|
+
const constants_js_1 = require("../constants.js");
|
|
11
|
+
const opra_http_nestjs_adapter_js_1 = require("./opra-http-nestjs-adapter.js");
|
|
12
12
|
const opra_exception_filter_js_1 = require("./services/opra-exception-filter.js");
|
|
13
13
|
const opra_middleware_js_1 = require("./services/opra-middleware.js");
|
|
14
14
|
let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
@@ -21,17 +21,17 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
21
21
|
method: common_1.RequestMethod.ALL,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
static forRoot(init
|
|
25
|
-
const opraAdapter = new
|
|
26
|
-
const token = init?.id ||
|
|
24
|
+
static forRoot(init) {
|
|
25
|
+
const opraAdapter = new opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter(init);
|
|
26
|
+
const token = init?.id || opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter;
|
|
27
27
|
const providers = [
|
|
28
28
|
...(init?.providers || []),
|
|
29
29
|
{
|
|
30
30
|
provide: constants_js_1.OPRA_HTTP_MODULE_OPTIONS,
|
|
31
|
-
useValue: { ...options },
|
|
31
|
+
useValue: { ...init.options },
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
|
-
provide:
|
|
34
|
+
provide: token,
|
|
35
35
|
inject: [core_1.ModuleRef],
|
|
36
36
|
useFactory: async (moduleRef) => {
|
|
37
37
|
(0, ts_gems_1.asMutable)(opraAdapter).document = await common_2.ApiDocumentFactory.createDocument({
|
|
@@ -56,7 +56,7 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
56
56
|
useClass: opra_exception_filter_js_1.OpraExceptionFilter,
|
|
57
57
|
},
|
|
58
58
|
];
|
|
59
|
-
if (token !==
|
|
59
|
+
if (token !== opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter) {
|
|
60
60
|
providers.push({
|
|
61
61
|
provide: token,
|
|
62
62
|
useValue: opraAdapter,
|
|
@@ -78,5 +78,5 @@ exports.OpraHttpCoreModule = OpraHttpCoreModule;
|
|
|
78
78
|
exports.OpraHttpCoreModule = OpraHttpCoreModule = OpraHttpCoreModule_1 = tslib_1.__decorate([
|
|
79
79
|
(0, common_1.Module)({}),
|
|
80
80
|
(0, common_1.Global)(),
|
|
81
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
81
|
+
tslib_1.__metadata("design:paramtypes", [opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter])
|
|
82
82
|
], OpraHttpCoreModule);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.OpraHttpNestjsAdapter = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
@@ -8,20 +8,20 @@ const constants_js_1 = require("@nestjs/common/constants.js");
|
|
|
8
8
|
const common_2 = require("@opra/common");
|
|
9
9
|
const http_1 = require("@opra/http");
|
|
10
10
|
const ts_gems_1 = require("ts-gems");
|
|
11
|
-
const public_decorator_js_1 = require("
|
|
12
|
-
class
|
|
13
|
-
constructor(init
|
|
11
|
+
const public_decorator_js_1 = require("../decorators/public.decorator.js");
|
|
12
|
+
class OpraHttpNestjsAdapter extends http_1.HttpAdapter {
|
|
13
|
+
constructor(init) {
|
|
14
14
|
super((function () {
|
|
15
15
|
const document = new common_2.ApiDocument();
|
|
16
16
|
document.api = new common_2.HttpApi({ owner: document, name: init.name, transport: 'http' });
|
|
17
17
|
return document;
|
|
18
18
|
})(), {
|
|
19
|
-
...options,
|
|
20
|
-
interceptors: options?.interceptors,
|
|
19
|
+
...init.options,
|
|
20
|
+
interceptors: init.options?.interceptors,
|
|
21
21
|
});
|
|
22
22
|
this.nestControllers = [];
|
|
23
|
-
this.options = options;
|
|
24
|
-
let basePath = options?.basePath || '/';
|
|
23
|
+
this.options = init.options;
|
|
24
|
+
let basePath = init.options?.basePath || '/';
|
|
25
25
|
if (!basePath.startsWith('/'))
|
|
26
26
|
basePath = '/' + basePath;
|
|
27
27
|
this._addRootController(basePath);
|
|
@@ -66,7 +66,7 @@ class OpraNestAdapter extends http_1.HttpAdapter {
|
|
|
66
66
|
}[sourceClass.name];
|
|
67
67
|
/** Copy metadata keys from source class to new one */
|
|
68
68
|
let metadataKeys;
|
|
69
|
-
|
|
69
|
+
OpraHttpNestjsAdapter.copyDecoratorMetadataToChild(newClass, parentTree);
|
|
70
70
|
const newPath = metadata.path ? node_path_1.default.join(currentPath, metadata.path) : currentPath;
|
|
71
71
|
const adapter = this;
|
|
72
72
|
// adapter.logger =
|
|
@@ -187,4 +187,4 @@ class OpraNestAdapter extends http_1.HttpAdapter {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
-
exports.
|
|
190
|
+
exports.OpraHttpNestjsAdapter = OpraHttpNestjsAdapter;
|
|
@@ -9,12 +9,11 @@ let OpraHttpModule = OpraHttpModule_1 = class OpraHttpModule {
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
11
|
* @param init
|
|
12
|
-
* @param options
|
|
13
12
|
*/
|
|
14
|
-
static forRoot(init
|
|
13
|
+
static forRoot(init) {
|
|
15
14
|
return {
|
|
16
15
|
module: OpraHttpModule_1,
|
|
17
|
-
imports: [opra_http_core_module_js_1.OpraHttpCoreModule.forRoot(init
|
|
16
|
+
imports: [opra_http_core_module_js_1.OpraHttpCoreModule.forRoot(init)],
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
19
|
};
|
|
@@ -4,7 +4,7 @@ exports.OpraExceptionFilter = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const core_1 = require("@nestjs/core");
|
|
7
|
-
const
|
|
7
|
+
const opra_http_nestjs_adapter_js_1 = require("../opra-http-nestjs-adapter.js");
|
|
8
8
|
let OpraExceptionFilter = class OpraExceptionFilter extends core_1.BaseExceptionFilter {
|
|
9
9
|
constructor(moduleRef) {
|
|
10
10
|
super();
|
|
@@ -13,7 +13,7 @@ let OpraExceptionFilter = class OpraExceptionFilter extends core_1.BaseException
|
|
|
13
13
|
catch(exception, host) {
|
|
14
14
|
const ctx = host.switchToHttp().getRequest().opraContext;
|
|
15
15
|
if (ctx) {
|
|
16
|
-
const adapter = this.moduleRef.get(
|
|
16
|
+
const adapter = this.moduleRef.get(opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter);
|
|
17
17
|
ctx.errors.push(exception);
|
|
18
18
|
return adapter.handler.sendResponse(ctx);
|
|
19
19
|
}
|
|
@@ -4,8 +4,8 @@ exports.OpraMiddleware = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const http_1 = require("@opra/http");
|
|
7
|
-
const constants_js_1 = require("
|
|
8
|
-
const
|
|
7
|
+
const constants_js_1 = require("../../constants.js");
|
|
8
|
+
const opra_http_nestjs_adapter_js_1 = require("../opra-http-nestjs-adapter.js");
|
|
9
9
|
let OpraMiddleware = class OpraMiddleware {
|
|
10
10
|
constructor(opraAdapter, options) {
|
|
11
11
|
this.opraAdapter = opraAdapter;
|
|
@@ -32,5 +32,5 @@ exports.OpraMiddleware = OpraMiddleware;
|
|
|
32
32
|
exports.OpraMiddleware = OpraMiddleware = tslib_1.__decorate([
|
|
33
33
|
(0, common_1.Injectable)(),
|
|
34
34
|
tslib_1.__param(1, (0, common_1.Inject)(constants_js_1.OPRA_HTTP_MODULE_OPTIONS)),
|
|
35
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
35
|
+
tslib_1.__metadata("design:paramtypes", [opra_http_nestjs_adapter_js_1.OpraHttpNestjsAdapter, Object])
|
|
36
36
|
], OpraMiddleware);
|
package/cjs/index.js
CHANGED
|
@@ -5,5 +5,7 @@ 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("./opra-http.module.js"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./opra-nestjs-adapter.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./http/opra-http.module.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./http/opra-http-nestjs-adapter.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./rpc/kafka/opra-kafka.module.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./rpc/kafka/opra-kafka-nestjs-adapter.js"), exports);
|
|
@@ -0,0 +1,60 @@
|
|
|
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 common_1 = require("@nestjs/common");
|
|
7
|
+
const core_1 = require("@nestjs/core");
|
|
8
|
+
const constants_js_1 = require("../../constants.js");
|
|
9
|
+
const opra_kafka_nestjs_adapter_js_1 = require("./opra-kafka-nestjs-adapter.js");
|
|
10
|
+
const opraKafkaNestjsAdapterToken = Symbol('OpraKafkaNestjsAdapter');
|
|
11
|
+
let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
12
|
+
constructor(adapter, init) {
|
|
13
|
+
this.adapter = adapter;
|
|
14
|
+
this.init = init;
|
|
15
|
+
}
|
|
16
|
+
static forRoot(init) {
|
|
17
|
+
const adapterProvider = {
|
|
18
|
+
provide: init.id || opra_kafka_nestjs_adapter_js_1.OpraKafkaNestjsAdapter,
|
|
19
|
+
inject: [core_1.ModuleRef],
|
|
20
|
+
useFactory: (moduleRef) => new opra_kafka_nestjs_adapter_js_1.OpraKafkaNestjsAdapter(moduleRef),
|
|
21
|
+
};
|
|
22
|
+
const providers = [
|
|
23
|
+
...(init?.providers || []),
|
|
24
|
+
{
|
|
25
|
+
provide: constants_js_1.OPRA_KAFKA_MODULE_OPTIONS,
|
|
26
|
+
useValue: { ...init },
|
|
27
|
+
},
|
|
28
|
+
adapterProvider,
|
|
29
|
+
{
|
|
30
|
+
provide: opraKafkaNestjsAdapterToken,
|
|
31
|
+
useExisting: adapterProvider.provide,
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
return {
|
|
35
|
+
global: true,
|
|
36
|
+
module: OpraKafkaCoreModule_1,
|
|
37
|
+
controllers: init.controllers,
|
|
38
|
+
providers,
|
|
39
|
+
imports: [...(init?.imports || [])],
|
|
40
|
+
exports: [...(init?.exports || []), adapterProvider],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async onModuleInit() {
|
|
44
|
+
await this.adapter.initialize(this.init);
|
|
45
|
+
}
|
|
46
|
+
async onApplicationBootstrap() {
|
|
47
|
+
await this.adapter.start();
|
|
48
|
+
}
|
|
49
|
+
async onApplicationShutdown() {
|
|
50
|
+
await this.adapter.stop();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.OpraKafkaCoreModule = OpraKafkaCoreModule;
|
|
54
|
+
exports.OpraKafkaCoreModule = OpraKafkaCoreModule = OpraKafkaCoreModule_1 = tslib_1.__decorate([
|
|
55
|
+
(0, common_1.Module)({}),
|
|
56
|
+
(0, common_1.Global)(),
|
|
57
|
+
tslib_1.__param(0, (0, common_1.Inject)(opraKafkaNestjsAdapterToken)),
|
|
58
|
+
tslib_1.__param(1, (0, common_1.Inject)(constants_js_1.OPRA_KAFKA_MODULE_OPTIONS)),
|
|
59
|
+
tslib_1.__metadata("design:paramtypes", [opra_kafka_nestjs_adapter_js_1.OpraKafkaNestjsAdapter, Object])
|
|
60
|
+
], OpraKafkaCoreModule);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpraKafkaNestjsAdapter = void 0;
|
|
4
|
+
const index_1 = require("@nestjs/core/errors/exceptions/index");
|
|
5
|
+
const common_1 = require("@opra/common");
|
|
6
|
+
const kafka_1 = require("@opra/kafka");
|
|
7
|
+
/**
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
class OpraKafkaNestjsAdapter {
|
|
11
|
+
constructor(moduleRef) {
|
|
12
|
+
this.moduleRef = moduleRef;
|
|
13
|
+
}
|
|
14
|
+
get document() {
|
|
15
|
+
if (!this._document)
|
|
16
|
+
throw new index_1.RuntimeException('Not initialized yet');
|
|
17
|
+
return this._document;
|
|
18
|
+
}
|
|
19
|
+
get adapter() {
|
|
20
|
+
if (!this._adapter)
|
|
21
|
+
throw new index_1.RuntimeException('Not initialized yet');
|
|
22
|
+
return this._adapter;
|
|
23
|
+
}
|
|
24
|
+
async start() {
|
|
25
|
+
if (!this._adapter) {
|
|
26
|
+
throw new index_1.RuntimeException('Not initialized yet');
|
|
27
|
+
}
|
|
28
|
+
return this._adapter.start();
|
|
29
|
+
}
|
|
30
|
+
async stop() {
|
|
31
|
+
return this._adapter?.close();
|
|
32
|
+
}
|
|
33
|
+
async initialize(init) {
|
|
34
|
+
const controllers = this._scanControllers();
|
|
35
|
+
this._document = await common_1.ApiDocumentFactory.createDocument({
|
|
36
|
+
info: init.info,
|
|
37
|
+
types: init.types,
|
|
38
|
+
references: init.references,
|
|
39
|
+
api: {
|
|
40
|
+
name: init.name,
|
|
41
|
+
description: init.description,
|
|
42
|
+
transport: 'rpc',
|
|
43
|
+
platform: 'kafka',
|
|
44
|
+
controllers,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
this._adapter = new kafka_1.KafkaAdapter({
|
|
48
|
+
client: init.client,
|
|
49
|
+
logger: init.logger,
|
|
50
|
+
logExtra: init.logExtra,
|
|
51
|
+
consumers: init.consumers,
|
|
52
|
+
document: this._document,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
_scanControllers() {
|
|
56
|
+
const container = this.moduleRef.container;
|
|
57
|
+
const modules = container.getModules();
|
|
58
|
+
const controllerInstances = [];
|
|
59
|
+
modules.forEach(({ controllers }) => {
|
|
60
|
+
controllers.forEach(wrapper => {
|
|
61
|
+
const ctor = Object.getPrototypeOf(wrapper.instance).constructor;
|
|
62
|
+
const metadata = Reflect.getMetadata(common_1.RPC_CONTROLLER_METADATA, ctor);
|
|
63
|
+
if (metadata) {
|
|
64
|
+
const instance = {};
|
|
65
|
+
Object.setPrototypeOf(instance, wrapper.instance);
|
|
66
|
+
controllerInstances.push(instance);
|
|
67
|
+
if (metadata.operations) {
|
|
68
|
+
// for (const [k, _] of Object.keys(metadata.operations)) {
|
|
69
|
+
// const fn = instance[k];
|
|
70
|
+
// instance[k] = fn;
|
|
71
|
+
// }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return controllerInstances;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.OpraKafkaNestjsAdapter = OpraKafkaNestjsAdapter;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 init
|
|
12
|
+
*/
|
|
13
|
+
static forRoot(init) {
|
|
14
|
+
return {
|
|
15
|
+
module: OpraKafkaModule_1,
|
|
16
|
+
imports: [opra_kafka_core_module_js_1.OpraKafkaCoreModule.forRoot(init)],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.OpraKafkaModule = OpraKafkaModule;
|
|
21
|
+
exports.OpraKafkaModule = OpraKafkaModule = OpraKafkaModule_1 = tslib_1.__decorate([
|
|
22
|
+
(0, common_1.Module)({})
|
|
23
|
+
], OpraKafkaModule);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { Controller } from '@nestjs/common';
|
|
1
2
|
import { ExternalExceptionFilter } from '@nestjs/core/exceptions/external-exception-filter.js';
|
|
3
|
+
import { classes } from '@opra/common';
|
|
4
|
+
const { RpcControllerDecoratorFactory } = classes;
|
|
2
5
|
const oldCatchMethod = ExternalExceptionFilter.prototype.catch;
|
|
3
6
|
ExternalExceptionFilter.prototype.catch = function (exception, host) {
|
|
4
7
|
const opraContext = host.getArgByIndex(3);
|
|
@@ -7,3 +10,8 @@ ExternalExceptionFilter.prototype.catch = function (exception, host) {
|
|
|
7
10
|
throw exception;
|
|
8
11
|
oldCatchMethod(exception, host);
|
|
9
12
|
};
|
|
13
|
+
RpcControllerDecoratorFactory.augment((decorator, decoratorChain) => {
|
|
14
|
+
decoratorChain.push((_, target) => {
|
|
15
|
+
Controller()(target);
|
|
16
|
+
});
|
|
17
|
+
});
|
package/esm/constants.js
CHANGED
|
@@ -4,8 +4,8 @@ import { Global, Module, RequestMethod, } from '@nestjs/common';
|
|
|
4
4
|
import { APP_FILTER, ModuleRef } from '@nestjs/core';
|
|
5
5
|
import { ApiDocumentFactory, isConstructor } from '@opra/common';
|
|
6
6
|
import { asMutable } from 'ts-gems';
|
|
7
|
-
import { OPRA_HTTP_MODULE_OPTIONS } from '
|
|
8
|
-
import {
|
|
7
|
+
import { OPRA_HTTP_MODULE_OPTIONS } from '../constants.js';
|
|
8
|
+
import { OpraHttpNestjsAdapter } from './opra-http-nestjs-adapter.js';
|
|
9
9
|
import { OpraExceptionFilter } from './services/opra-exception-filter.js';
|
|
10
10
|
import { OpraMiddleware } from './services/opra-middleware.js';
|
|
11
11
|
let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
@@ -18,17 +18,17 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
18
18
|
method: RequestMethod.ALL,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
static forRoot(init
|
|
22
|
-
const opraAdapter = new
|
|
23
|
-
const token = init?.id ||
|
|
21
|
+
static forRoot(init) {
|
|
22
|
+
const opraAdapter = new OpraHttpNestjsAdapter(init);
|
|
23
|
+
const token = init?.id || OpraHttpNestjsAdapter;
|
|
24
24
|
const providers = [
|
|
25
25
|
...(init?.providers || []),
|
|
26
26
|
{
|
|
27
27
|
provide: OPRA_HTTP_MODULE_OPTIONS,
|
|
28
|
-
useValue: { ...options },
|
|
28
|
+
useValue: { ...init.options },
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
provide:
|
|
31
|
+
provide: token,
|
|
32
32
|
inject: [ModuleRef],
|
|
33
33
|
useFactory: async (moduleRef) => {
|
|
34
34
|
asMutable(opraAdapter).document = await ApiDocumentFactory.createDocument({
|
|
@@ -53,7 +53,7 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
53
53
|
useClass: OpraExceptionFilter,
|
|
54
54
|
},
|
|
55
55
|
];
|
|
56
|
-
if (token !==
|
|
56
|
+
if (token !== OpraHttpNestjsAdapter) {
|
|
57
57
|
providers.push({
|
|
58
58
|
provide: token,
|
|
59
59
|
useValue: opraAdapter,
|
|
@@ -74,6 +74,6 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
74
74
|
OpraHttpCoreModule = OpraHttpCoreModule_1 = __decorate([
|
|
75
75
|
Module({}),
|
|
76
76
|
Global(),
|
|
77
|
-
__metadata("design:paramtypes", [
|
|
77
|
+
__metadata("design:paramtypes", [OpraHttpNestjsAdapter])
|
|
78
78
|
], OpraHttpCoreModule);
|
|
79
79
|
export { OpraHttpCoreModule };
|
|
@@ -5,20 +5,20 @@ import { EXCEPTION_FILTERS_METADATA, GUARDS_METADATA, INTERCEPTORS_METADATA } fr
|
|
|
5
5
|
import { ApiDocument, HTTP_CONTROLLER_METADATA, HttpApi, isConstructor, NotFoundError, } from '@opra/common';
|
|
6
6
|
import { HttpAdapter } from '@opra/http';
|
|
7
7
|
import { asMutable } from 'ts-gems';
|
|
8
|
-
import { Public } from '
|
|
9
|
-
export class
|
|
10
|
-
constructor(init
|
|
8
|
+
import { Public } from '../decorators/public.decorator.js';
|
|
9
|
+
export class OpraHttpNestjsAdapter extends HttpAdapter {
|
|
10
|
+
constructor(init) {
|
|
11
11
|
super((function () {
|
|
12
12
|
const document = new ApiDocument();
|
|
13
13
|
document.api = new HttpApi({ owner: document, name: init.name, transport: 'http' });
|
|
14
14
|
return document;
|
|
15
15
|
})(), {
|
|
16
|
-
...options,
|
|
17
|
-
interceptors: options?.interceptors,
|
|
16
|
+
...init.options,
|
|
17
|
+
interceptors: init.options?.interceptors,
|
|
18
18
|
});
|
|
19
19
|
this.nestControllers = [];
|
|
20
|
-
this.options = options;
|
|
21
|
-
let basePath = options?.basePath || '/';
|
|
20
|
+
this.options = init.options;
|
|
21
|
+
let basePath = init.options?.basePath || '/';
|
|
22
22
|
if (!basePath.startsWith('/'))
|
|
23
23
|
basePath = '/' + basePath;
|
|
24
24
|
this._addRootController(basePath);
|
|
@@ -63,7 +63,7 @@ export class OpraNestAdapter extends HttpAdapter {
|
|
|
63
63
|
}[sourceClass.name];
|
|
64
64
|
/** Copy metadata keys from source class to new one */
|
|
65
65
|
let metadataKeys;
|
|
66
|
-
|
|
66
|
+
OpraHttpNestjsAdapter.copyDecoratorMetadataToChild(newClass, parentTree);
|
|
67
67
|
const newPath = metadata.path ? nodePath.join(currentPath, metadata.path) : currentPath;
|
|
68
68
|
const adapter = this;
|
|
69
69
|
// adapter.logger =
|
|
@@ -6,12 +6,11 @@ let OpraHttpModule = OpraHttpModule_1 = class OpraHttpModule {
|
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
* @param init
|
|
9
|
-
* @param options
|
|
10
9
|
*/
|
|
11
|
-
static forRoot(init
|
|
10
|
+
static forRoot(init) {
|
|
12
11
|
return {
|
|
13
12
|
module: OpraHttpModule_1,
|
|
14
|
-
imports: [OpraHttpCoreModule.forRoot(init
|
|
13
|
+
imports: [OpraHttpCoreModule.forRoot(init)],
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
16
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Catch } from '@nestjs/common';
|
|
3
3
|
import { BaseExceptionFilter, ModuleRef } from '@nestjs/core';
|
|
4
|
-
import {
|
|
4
|
+
import { OpraHttpNestjsAdapter } from '../opra-http-nestjs-adapter.js';
|
|
5
5
|
let OpraExceptionFilter = class OpraExceptionFilter extends BaseExceptionFilter {
|
|
6
6
|
constructor(moduleRef) {
|
|
7
7
|
super();
|
|
@@ -10,7 +10,7 @@ let OpraExceptionFilter = class OpraExceptionFilter extends BaseExceptionFilter
|
|
|
10
10
|
catch(exception, host) {
|
|
11
11
|
const ctx = host.switchToHttp().getRequest().opraContext;
|
|
12
12
|
if (ctx) {
|
|
13
|
-
const adapter = this.moduleRef.get(
|
|
13
|
+
const adapter = this.moduleRef.get(OpraHttpNestjsAdapter);
|
|
14
14
|
ctx.errors.push(exception);
|
|
15
15
|
return adapter.handler.sendResponse(ctx);
|
|
16
16
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
2
|
import { Inject, Injectable } from '@nestjs/common';
|
|
3
3
|
import { HttpContext, HttpIncoming, HttpOutgoing } from '@opra/http';
|
|
4
|
-
import { OPRA_HTTP_MODULE_OPTIONS } from '
|
|
5
|
-
import {
|
|
4
|
+
import { OPRA_HTTP_MODULE_OPTIONS } from '../../constants.js';
|
|
5
|
+
import { OpraHttpNestjsAdapter } from '../opra-http-nestjs-adapter.js';
|
|
6
6
|
let OpraMiddleware = class OpraMiddleware {
|
|
7
7
|
constructor(opraAdapter, options) {
|
|
8
8
|
this.opraAdapter = opraAdapter;
|
|
@@ -28,6 +28,6 @@ let OpraMiddleware = class OpraMiddleware {
|
|
|
28
28
|
OpraMiddleware = __decorate([
|
|
29
29
|
Injectable(),
|
|
30
30
|
__param(1, Inject(OPRA_HTTP_MODULE_OPTIONS)),
|
|
31
|
-
__metadata("design:paramtypes", [
|
|
31
|
+
__metadata("design:paramtypes", [OpraHttpNestjsAdapter, Object])
|
|
32
32
|
], OpraMiddleware);
|
|
33
33
|
export { OpraMiddleware };
|
package/esm/index.js
CHANGED
|
@@ -2,5 +2,7 @@ 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 './opra-http.module.js';
|
|
6
|
-
export * from './opra-nestjs-adapter.js';
|
|
5
|
+
export * from './http/opra-http.module.js';
|
|
6
|
+
export * from './http/opra-http-nestjs-adapter.js';
|
|
7
|
+
export * from './rpc/kafka/opra-kafka.module.js';
|
|
8
|
+
export * from './rpc/kafka/opra-kafka-nestjs-adapter.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var OpraKafkaCoreModule_1;
|
|
2
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
+
import { Global, Inject, Module, } from '@nestjs/common';
|
|
4
|
+
import { ModuleRef } from '@nestjs/core';
|
|
5
|
+
import { OPRA_KAFKA_MODULE_OPTIONS } from '../../constants.js';
|
|
6
|
+
import { OpraKafkaNestjsAdapter } from './opra-kafka-nestjs-adapter.js';
|
|
7
|
+
const opraKafkaNestjsAdapterToken = Symbol('OpraKafkaNestjsAdapter');
|
|
8
|
+
let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
9
|
+
constructor(adapter, init) {
|
|
10
|
+
this.adapter = adapter;
|
|
11
|
+
this.init = init;
|
|
12
|
+
}
|
|
13
|
+
static forRoot(init) {
|
|
14
|
+
const adapterProvider = {
|
|
15
|
+
provide: init.id || OpraKafkaNestjsAdapter,
|
|
16
|
+
inject: [ModuleRef],
|
|
17
|
+
useFactory: (moduleRef) => new OpraKafkaNestjsAdapter(moduleRef),
|
|
18
|
+
};
|
|
19
|
+
const providers = [
|
|
20
|
+
...(init?.providers || []),
|
|
21
|
+
{
|
|
22
|
+
provide: OPRA_KAFKA_MODULE_OPTIONS,
|
|
23
|
+
useValue: { ...init },
|
|
24
|
+
},
|
|
25
|
+
adapterProvider,
|
|
26
|
+
{
|
|
27
|
+
provide: opraKafkaNestjsAdapterToken,
|
|
28
|
+
useExisting: adapterProvider.provide,
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
return {
|
|
32
|
+
global: true,
|
|
33
|
+
module: OpraKafkaCoreModule_1,
|
|
34
|
+
controllers: init.controllers,
|
|
35
|
+
providers,
|
|
36
|
+
imports: [...(init?.imports || [])],
|
|
37
|
+
exports: [...(init?.exports || []), adapterProvider],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async onModuleInit() {
|
|
41
|
+
await this.adapter.initialize(this.init);
|
|
42
|
+
}
|
|
43
|
+
async onApplicationBootstrap() {
|
|
44
|
+
await this.adapter.start();
|
|
45
|
+
}
|
|
46
|
+
async onApplicationShutdown() {
|
|
47
|
+
await this.adapter.stop();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
OpraKafkaCoreModule = OpraKafkaCoreModule_1 = __decorate([
|
|
51
|
+
Module({}),
|
|
52
|
+
Global(),
|
|
53
|
+
__param(0, Inject(opraKafkaNestjsAdapterToken)),
|
|
54
|
+
__param(1, Inject(OPRA_KAFKA_MODULE_OPTIONS)),
|
|
55
|
+
__metadata("design:paramtypes", [OpraKafkaNestjsAdapter, Object])
|
|
56
|
+
], OpraKafkaCoreModule);
|
|
57
|
+
export { OpraKafkaCoreModule };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { RuntimeException } from '@nestjs/core/errors/exceptions/index';
|
|
2
|
+
import { ApiDocumentFactory, RPC_CONTROLLER_METADATA } from '@opra/common';
|
|
3
|
+
import { KafkaAdapter } from '@opra/kafka';
|
|
4
|
+
/**
|
|
5
|
+
* @class
|
|
6
|
+
*/
|
|
7
|
+
export class OpraKafkaNestjsAdapter {
|
|
8
|
+
constructor(moduleRef) {
|
|
9
|
+
this.moduleRef = moduleRef;
|
|
10
|
+
}
|
|
11
|
+
get document() {
|
|
12
|
+
if (!this._document)
|
|
13
|
+
throw new RuntimeException('Not initialized yet');
|
|
14
|
+
return this._document;
|
|
15
|
+
}
|
|
16
|
+
get adapter() {
|
|
17
|
+
if (!this._adapter)
|
|
18
|
+
throw new RuntimeException('Not initialized yet');
|
|
19
|
+
return this._adapter;
|
|
20
|
+
}
|
|
21
|
+
async start() {
|
|
22
|
+
if (!this._adapter) {
|
|
23
|
+
throw new RuntimeException('Not initialized yet');
|
|
24
|
+
}
|
|
25
|
+
return this._adapter.start();
|
|
26
|
+
}
|
|
27
|
+
async stop() {
|
|
28
|
+
return this._adapter?.close();
|
|
29
|
+
}
|
|
30
|
+
async initialize(init) {
|
|
31
|
+
const controllers = this._scanControllers();
|
|
32
|
+
this._document = await ApiDocumentFactory.createDocument({
|
|
33
|
+
info: init.info,
|
|
34
|
+
types: init.types,
|
|
35
|
+
references: init.references,
|
|
36
|
+
api: {
|
|
37
|
+
name: init.name,
|
|
38
|
+
description: init.description,
|
|
39
|
+
transport: 'rpc',
|
|
40
|
+
platform: 'kafka',
|
|
41
|
+
controllers,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
this._adapter = new KafkaAdapter({
|
|
45
|
+
client: init.client,
|
|
46
|
+
logger: init.logger,
|
|
47
|
+
logExtra: init.logExtra,
|
|
48
|
+
consumers: init.consumers,
|
|
49
|
+
document: this._document,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
_scanControllers() {
|
|
53
|
+
const container = this.moduleRef.container;
|
|
54
|
+
const modules = container.getModules();
|
|
55
|
+
const controllerInstances = [];
|
|
56
|
+
modules.forEach(({ controllers }) => {
|
|
57
|
+
controllers.forEach(wrapper => {
|
|
58
|
+
const ctor = Object.getPrototypeOf(wrapper.instance).constructor;
|
|
59
|
+
const metadata = Reflect.getMetadata(RPC_CONTROLLER_METADATA, ctor);
|
|
60
|
+
if (metadata) {
|
|
61
|
+
const instance = {};
|
|
62
|
+
Object.setPrototypeOf(instance, wrapper.instance);
|
|
63
|
+
controllerInstances.push(instance);
|
|
64
|
+
if (metadata.operations) {
|
|
65
|
+
// for (const [k, _] of Object.keys(metadata.operations)) {
|
|
66
|
+
// const fn = instance[k];
|
|
67
|
+
// instance[k] = fn;
|
|
68
|
+
// }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
return controllerInstances;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var OpraKafkaModule_1;
|
|
2
|
+
import { __decorate } from "tslib";
|
|
3
|
+
import { Module } from '@nestjs/common';
|
|
4
|
+
import { OpraKafkaCoreModule } from './opra-kafka-core.module.js';
|
|
5
|
+
let OpraKafkaModule = OpraKafkaModule_1 = class OpraKafkaModule {
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param init
|
|
9
|
+
*/
|
|
10
|
+
static forRoot(init) {
|
|
11
|
+
return {
|
|
12
|
+
module: OpraKafkaModule_1,
|
|
13
|
+
imports: [OpraKafkaCoreModule.forRoot(init)],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
OpraKafkaModule = OpraKafkaModule_1 = __decorate([
|
|
18
|
+
Module({})
|
|
19
|
+
], OpraKafkaModule);
|
|
20
|
+
export { OpraKafkaModule };
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/nestjs",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"description": "Opra NestJS module",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@opra/common": "^1.0.0-beta.
|
|
9
|
-
"@opra/core": "^1.0.0-beta.
|
|
10
|
-
"@opra/http": "^1.0.0-beta.3",
|
|
8
|
+
"@opra/common": "^1.0.0-beta.4",
|
|
9
|
+
"@opra/core": "^1.0.0-beta.4",
|
|
11
10
|
"fast-tokenizer": "^1.7.0",
|
|
12
11
|
"lodash.head": "^4.0.1",
|
|
13
12
|
"putil-promisify": "^1.10.1",
|
|
@@ -18,6 +17,11 @@
|
|
|
18
17
|
"@nestjs/common": "^10.4.4",
|
|
19
18
|
"@nestjs/core": "^10.4.4"
|
|
20
19
|
},
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"@nestjs/microservices": "^10.4.4",
|
|
22
|
+
"@opra/http": "^1.0.0-beta.4",
|
|
23
|
+
"@opra/kafka": "^1.0.0-beta.4"
|
|
24
|
+
},
|
|
21
25
|
"type": "module",
|
|
22
26
|
"exports": {
|
|
23
27
|
".": {
|
package/types/constants.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type DynamicModule, type MiddlewareConsumer, type NestModule, type OnModuleDestroy } from '@nestjs/common';
|
|
2
2
|
import type { OpraHttpModule } from './opra-http.module.js';
|
|
3
|
-
import {
|
|
3
|
+
import { OpraHttpNestjsAdapter } from './opra-http-nestjs-adapter.js';
|
|
4
4
|
export declare class OpraHttpCoreModule implements OnModuleDestroy, NestModule {
|
|
5
|
-
protected opraAdapter:
|
|
6
|
-
constructor(opraAdapter:
|
|
5
|
+
protected opraAdapter: OpraHttpNestjsAdapter;
|
|
6
|
+
constructor(opraAdapter: OpraHttpNestjsAdapter);
|
|
7
7
|
configure(consumer: MiddlewareConsumer): void;
|
|
8
|
-
static forRoot(init: OpraHttpModule.Initiator
|
|
8
|
+
static forRoot(init: OpraHttpModule.Initiator): DynamicModule;
|
|
9
9
|
onModuleDestroy(): Promise<void>;
|
|
10
10
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type Type } from '@nestjs/common';
|
|
2
2
|
import { HttpAdapter } from '@opra/http';
|
|
3
3
|
import type { OpraHttpModule } from './opra-http.module.js';
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class OpraHttpNestjsAdapter extends HttpAdapter {
|
|
5
5
|
readonly nestControllers: Type[];
|
|
6
6
|
readonly options?: OpraHttpModule.Options;
|
|
7
|
-
constructor(init: OpraHttpModule.Initiator
|
|
7
|
+
constructor(init: OpraHttpModule.Initiator);
|
|
8
8
|
close(): Promise<void>;
|
|
9
9
|
protected _addRootController(basePath: string): void;
|
|
10
10
|
protected _addToNestControllers(sourceClass: Type, currentPath: string, parentTree: Type[]): void;
|
|
@@ -5,6 +5,7 @@ export declare namespace OpraHttpModule {
|
|
|
5
5
|
interface Initiator extends Pick<DynamicModule, 'imports' | 'providers' | 'exports' | 'controllers'>, Pick<ApiDocumentFactory.InitArguments, 'types' | 'references' | 'info'> {
|
|
6
6
|
id?: any;
|
|
7
7
|
name: string;
|
|
8
|
+
options?: Options;
|
|
8
9
|
}
|
|
9
10
|
interface Options {
|
|
10
11
|
basePath?: string;
|
|
@@ -16,7 +17,6 @@ export declare class OpraHttpModule {
|
|
|
16
17
|
/**
|
|
17
18
|
*
|
|
18
19
|
* @param init
|
|
19
|
-
* @param options
|
|
20
20
|
*/
|
|
21
|
-
static forRoot(init: OpraHttpModule.Initiator
|
|
21
|
+
static forRoot(init: OpraHttpModule.Initiator): DynamicModule;
|
|
22
22
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type NestMiddleware } from '@nestjs/common';
|
|
2
2
|
import type { NextFunction, Request, Response } from 'express';
|
|
3
3
|
import type { OpraHttpModule } from '../opra-http.module.js';
|
|
4
|
-
import {
|
|
4
|
+
import { OpraHttpNestjsAdapter } from '../opra-http-nestjs-adapter.js';
|
|
5
5
|
export declare class OpraMiddleware implements NestMiddleware {
|
|
6
|
-
protected opraAdapter:
|
|
6
|
+
protected opraAdapter: OpraHttpNestjsAdapter;
|
|
7
7
|
protected options: OpraHttpModule.Options;
|
|
8
|
-
constructor(opraAdapter:
|
|
8
|
+
constructor(opraAdapter: OpraHttpNestjsAdapter, options: OpraHttpModule.Options);
|
|
9
9
|
use(req: Request, res: Response, next: NextFunction): void;
|
|
10
10
|
}
|
package/types/index.d.cts
CHANGED
|
@@ -2,5 +2,7 @@ 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 './opra-http.module.js';
|
|
6
|
-
export * from './opra-nestjs-adapter.js';
|
|
5
|
+
export * from './http/opra-http.module.js';
|
|
6
|
+
export * from './http/opra-http-nestjs-adapter.js';
|
|
7
|
+
export * from './rpc/kafka/opra-kafka.module.js';
|
|
8
|
+
export * from './rpc/kafka/opra-kafka-nestjs-adapter.js';
|
package/types/index.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ 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 './opra-http.module.js';
|
|
6
|
-
export * from './opra-nestjs-adapter.js';
|
|
5
|
+
export * from './http/opra-http.module.js';
|
|
6
|
+
export * from './http/opra-http-nestjs-adapter.js';
|
|
7
|
+
export * from './rpc/kafka/opra-kafka.module.js';
|
|
8
|
+
export * from './rpc/kafka/opra-kafka-nestjs-adapter.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DynamicModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import type { OpraKafkaModule } from './opra-kafka.module.js';
|
|
3
|
+
import { OpraKafkaNestjsAdapter } from './opra-kafka-nestjs-adapter.js';
|
|
4
|
+
export declare class OpraKafkaCoreModule implements OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown {
|
|
5
|
+
protected adapter: OpraKafkaNestjsAdapter;
|
|
6
|
+
protected init: OpraKafkaModule.Initiator;
|
|
7
|
+
constructor(adapter: OpraKafkaNestjsAdapter, init: OpraKafkaModule.Initiator);
|
|
8
|
+
static forRoot(init: OpraKafkaModule.Initiator): DynamicModule;
|
|
9
|
+
onModuleInit(): Promise<void>;
|
|
10
|
+
onApplicationBootstrap(): Promise<void>;
|
|
11
|
+
onApplicationShutdown(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ModuleRef } from '@nestjs/core';
|
|
2
|
+
import { ApiDocument } from '@opra/common';
|
|
3
|
+
import { KafkaAdapter } from '@opra/kafka';
|
|
4
|
+
import type { OpraKafkaModule } from './opra-kafka.module.js';
|
|
5
|
+
/**
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export declare class OpraKafkaNestjsAdapter {
|
|
9
|
+
protected moduleRef: ModuleRef;
|
|
10
|
+
private _adapter?;
|
|
11
|
+
private _document?;
|
|
12
|
+
constructor(moduleRef: ModuleRef);
|
|
13
|
+
get document(): ApiDocument;
|
|
14
|
+
get adapter(): KafkaAdapter;
|
|
15
|
+
start(): Promise<void>;
|
|
16
|
+
stop(): Promise<void | undefined>;
|
|
17
|
+
initialize(init: OpraKafkaModule.Initiator): Promise<void>;
|
|
18
|
+
protected _scanControllers(): any[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type DynamicModule, Logger, type Type } from '@nestjs/common';
|
|
2
|
+
import { ApiDocumentFactory } from '@opra/common';
|
|
3
|
+
import { KafkaAdapter } from '@opra/kafka';
|
|
4
|
+
import type { StrictOmit } from 'ts-gems';
|
|
5
|
+
export declare namespace OpraKafkaModule {
|
|
6
|
+
interface Initiator extends Pick<DynamicModule, 'imports' | 'providers' | 'exports' | 'controllers'>, Pick<ApiDocumentFactory.InitArguments, 'types' | 'references' | 'info'>, StrictOmit<KafkaAdapter.Config, 'document' | 'logger' | 'interceptors'> {
|
|
7
|
+
id?: any;
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
types?: ApiDocumentFactory.InitArguments['types'];
|
|
11
|
+
logger?: Logger;
|
|
12
|
+
interceptors?: (KafkaAdapter.InterceptorFunction | KafkaAdapter.IKafkaInterceptor | Type<KafkaAdapter.IKafkaInterceptor>)[];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare class OpraKafkaModule {
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param init
|
|
19
|
+
*/
|
|
20
|
+
static forRoot(init: OpraKafkaModule.Initiator): DynamicModule;
|
|
21
|
+
}
|
|
File without changes
|