@opra/nestjs 1.0.4 → 1.0.6
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/http/opra-http-core.module.js +1 -2
- package/cjs/http/opra-http-nestjs-adapter.js +6 -7
- package/cjs/index.js +0 -1
- package/cjs/kafka/helpers/initialize-adapter.js +44 -0
- package/cjs/kafka/opra-kafka-core.module.js +22 -17
- package/esm/http/opra-http-core.module.js +1 -2
- package/esm/http/opra-http-nestjs-adapter.js +7 -8
- package/esm/index.js +0 -1
- package/esm/kafka/helpers/initialize-adapter.js +41 -0
- package/esm/kafka/opra-kafka-core.module.js +22 -17
- package/package.json +9 -9
- package/types/index.d.cts +0 -1
- package/types/index.d.ts +0 -1
- package/types/kafka/helpers/initialize-adapter.d.ts +4 -0
- package/types/kafka/opra-kafka-core.module.d.ts +6 -4
- package/cjs/kafka/opra-kafka-nestjs-adapter.js +0 -82
- package/esm/kafka/opra-kafka-nestjs-adapter.js +0 -78
- package/types/kafka/opra-kafka-nestjs-adapter.d.ts +0 -19
|
@@ -6,7 +6,6 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
7
|
const core_1 = require("@nestjs/core");
|
|
8
8
|
const common_2 = require("@opra/common");
|
|
9
|
-
const ts_gems_1 = require("ts-gems");
|
|
10
9
|
const constants_js_1 = require("../constants.js");
|
|
11
10
|
const opra_http_nestjs_adapter_js_1 = require("./opra-http-nestjs-adapter.js");
|
|
12
11
|
const opra_exception_filter_js_1 = require("./services/opra-exception-filter.js");
|
|
@@ -60,7 +59,7 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
60
59
|
inject: [core_1.ModuleRef, constants_js_1.OPRA_HTTP_API_CONFIG],
|
|
61
60
|
useFactory: async (moduleRef, apiConfig) => {
|
|
62
61
|
opraNestAdapter.logger = opraNestAdapter.logger || new common_1.Logger(apiConfig.name);
|
|
63
|
-
|
|
62
|
+
opraNestAdapter._document = await common_2.ApiDocumentFactory.createDocument({
|
|
64
63
|
...apiConfig,
|
|
65
64
|
api: {
|
|
66
65
|
transport: 'http',
|
|
@@ -11,15 +11,14 @@ const ts_gems_1 = require("ts-gems");
|
|
|
11
11
|
const public_decorator_js_1 = require("../decorators/public.decorator.js");
|
|
12
12
|
class OpraHttpNestjsAdapter extends http_1.HttpAdapter {
|
|
13
13
|
constructor(options) {
|
|
14
|
-
super(
|
|
15
|
-
const document = new common_2.ApiDocument();
|
|
16
|
-
document.api = new common_2.HttpApi({ owner: document, name: '', transport: 'http' });
|
|
17
|
-
return document;
|
|
18
|
-
})(), options);
|
|
14
|
+
super(options);
|
|
19
15
|
this.nestControllers = [];
|
|
20
16
|
this._addRootController(options.schemaIsPublic);
|
|
21
|
-
if (options.controllers)
|
|
22
|
-
|
|
17
|
+
if (options.controllers) {
|
|
18
|
+
for (const c of options.controllers) {
|
|
19
|
+
this._addToNestControllers(c, this.basePath, []);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
23
22
|
}
|
|
24
23
|
async close() {
|
|
25
24
|
//
|
package/cjs/index.js
CHANGED
|
@@ -8,4 +8,3 @@ tslib_1.__exportStar(require("./decorators/public.decorator.js"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./http/opra-http.module.js"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./http/opra-http-nestjs-adapter.js"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./kafka/opra-kafka.module.js"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./kafka/opra-kafka-nestjs-adapter.js"), exports);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeAdapter = initializeAdapter;
|
|
4
|
+
const common_1 = require("@opra/common");
|
|
5
|
+
async function initializeAdapter(moduleRef, adapter, config) {
|
|
6
|
+
const controllers = scanControllers(moduleRef);
|
|
7
|
+
const document = await common_1.ApiDocumentFactory.createDocument({
|
|
8
|
+
info: config.info,
|
|
9
|
+
types: config.types,
|
|
10
|
+
references: config.references,
|
|
11
|
+
api: {
|
|
12
|
+
name: config.name,
|
|
13
|
+
description: config.description,
|
|
14
|
+
transport: 'rpc',
|
|
15
|
+
platform: 'kafka',
|
|
16
|
+
controllers,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
await adapter.initialize(document);
|
|
20
|
+
}
|
|
21
|
+
function scanControllers(moduleRef) {
|
|
22
|
+
const container = moduleRef.container;
|
|
23
|
+
const modules = container.getModules();
|
|
24
|
+
const out = [];
|
|
25
|
+
modules.forEach(({ controllers }) => {
|
|
26
|
+
controllers.forEach(wrapper => {
|
|
27
|
+
const ctor = Object.getPrototypeOf(wrapper.instance).constructor;
|
|
28
|
+
const metadata = Reflect.getMetadata(common_1.RPC_CONTROLLER_METADATA, ctor);
|
|
29
|
+
if (!metadata)
|
|
30
|
+
return;
|
|
31
|
+
const instance = {};
|
|
32
|
+
Object.setPrototypeOf(instance, wrapper.instance);
|
|
33
|
+
out.push(wrapper.instance);
|
|
34
|
+
// if (metadata.operations) {
|
|
35
|
+
// for (const [k, _] of Object.keys(metadata.operations)) {
|
|
36
|
+
// const isRequestScoped = !wrapper.isDependencyTreeStatic();
|
|
37
|
+
// // const fn = instance[k];
|
|
38
|
+
// // instance[k] = fn;
|
|
39
|
+
// }
|
|
40
|
+
// }
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
@@ -6,13 +6,15 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
7
|
const core_1 = require("@nestjs/core");
|
|
8
8
|
const common_2 = require("@opra/common");
|
|
9
|
+
const kafka_1 = require("@opra/kafka");
|
|
9
10
|
const constants_js_1 = require("../constants.js");
|
|
10
|
-
const
|
|
11
|
+
const initialize_adapter_js_1 = require("./helpers/initialize-adapter.js");
|
|
11
12
|
const opraKafkaNestjsAdapterToken = Symbol('OpraKafkaNestjsAdapter');
|
|
12
13
|
let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
13
|
-
constructor(adapter,
|
|
14
|
+
constructor(moduleRef, adapter, config) {
|
|
15
|
+
this.moduleRef = moduleRef;
|
|
14
16
|
this.adapter = adapter;
|
|
15
|
-
this.
|
|
17
|
+
this.config = config;
|
|
16
18
|
}
|
|
17
19
|
static forRoot(moduleOptions) {
|
|
18
20
|
return this._getDynamicModule({
|
|
@@ -49,15 +51,13 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
53
|
static _getDynamicModule(moduleOptions) {
|
|
52
|
-
const token = moduleOptions.id ||
|
|
54
|
+
const token = moduleOptions.id || kafka_1.KafkaAdapter;
|
|
53
55
|
const adapterProvider = {
|
|
54
56
|
provide: token,
|
|
55
57
|
inject: [core_1.ModuleRef, constants_js_1.OPRA_KAFKA_MODULE_CONFIG],
|
|
56
58
|
useFactory: async (moduleRef, config) => {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
if (moduleOptions.interceptors) {
|
|
60
|
-
adapter.adapter.interceptors = moduleOptions.interceptors.map(x => {
|
|
59
|
+
const interceptors = moduleOptions.interceptors
|
|
60
|
+
? moduleOptions.interceptors.map(x => {
|
|
61
61
|
if ((0, common_2.isConstructor)(x)) {
|
|
62
62
|
return async (ctx, next) => {
|
|
63
63
|
const interceptor = moduleRef.get(x);
|
|
@@ -66,9 +66,9 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
return x;
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
return
|
|
69
|
+
})
|
|
70
|
+
: undefined;
|
|
71
|
+
return new kafka_1.KafkaAdapter({ ...config, interceptors });
|
|
72
72
|
},
|
|
73
73
|
};
|
|
74
74
|
return {
|
|
@@ -88,20 +88,25 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
async onModuleInit() {
|
|
91
|
-
|
|
91
|
+
/** Check if not initialized before */
|
|
92
|
+
if (!this.adapter.document) {
|
|
93
|
+
await (0, initialize_adapter_js_1.initializeAdapter)(this.moduleRef, this.adapter, this.config);
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
async onApplicationBootstrap() {
|
|
94
|
-
|
|
97
|
+
if (this.adapter.document)
|
|
98
|
+
await this.adapter.start();
|
|
95
99
|
}
|
|
96
100
|
async onApplicationShutdown() {
|
|
97
|
-
await this.adapter.
|
|
101
|
+
await this.adapter.close();
|
|
98
102
|
}
|
|
99
103
|
};
|
|
100
104
|
exports.OpraKafkaCoreModule = OpraKafkaCoreModule;
|
|
101
105
|
exports.OpraKafkaCoreModule = OpraKafkaCoreModule = OpraKafkaCoreModule_1 = tslib_1.__decorate([
|
|
102
106
|
(0, common_1.Module)({}),
|
|
103
107
|
(0, common_1.Global)(),
|
|
104
|
-
tslib_1.__param(
|
|
105
|
-
tslib_1.__param(
|
|
106
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
108
|
+
tslib_1.__param(1, (0, common_1.Inject)(opraKafkaNestjsAdapterToken)),
|
|
109
|
+
tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_KAFKA_MODULE_CONFIG)),
|
|
110
|
+
tslib_1.__metadata("design:paramtypes", [core_1.ModuleRef,
|
|
111
|
+
kafka_1.KafkaAdapter, Object])
|
|
107
112
|
], OpraKafkaCoreModule);
|
|
@@ -3,7 +3,6 @@ import { __decorate, __metadata } from "tslib";
|
|
|
3
3
|
import { Global, Logger, Module, RequestMethod, } from '@nestjs/common';
|
|
4
4
|
import { APP_FILTER, ModuleRef } from '@nestjs/core';
|
|
5
5
|
import { ApiDocumentFactory, isConstructor } from '@opra/common';
|
|
6
|
-
import { asMutable } from 'ts-gems';
|
|
7
6
|
import { OPRA_HTTP_API_CONFIG } from '../constants.js';
|
|
8
7
|
import { OpraHttpNestjsAdapter } from './opra-http-nestjs-adapter.js';
|
|
9
8
|
import { OpraExceptionFilter } from './services/opra-exception-filter.js';
|
|
@@ -57,7 +56,7 @@ let OpraHttpCoreModule = OpraHttpCoreModule_1 = class OpraHttpCoreModule {
|
|
|
57
56
|
inject: [ModuleRef, OPRA_HTTP_API_CONFIG],
|
|
58
57
|
useFactory: async (moduleRef, apiConfig) => {
|
|
59
58
|
opraNestAdapter.logger = opraNestAdapter.logger || new Logger(apiConfig.name);
|
|
60
|
-
|
|
59
|
+
opraNestAdapter._document = await ApiDocumentFactory.createDocument({
|
|
61
60
|
...apiConfig,
|
|
62
61
|
api: {
|
|
63
62
|
transport: 'http',
|
|
@@ -2,21 +2,20 @@ import { __decorate, __metadata, __param } from "tslib";
|
|
|
2
2
|
import nodePath from 'node:path';
|
|
3
3
|
import { Controller, Delete, Get, Head, Next, Options, Patch, Post, Put, Req, Res, Search, } from '@nestjs/common';
|
|
4
4
|
import { EXCEPTION_FILTERS_METADATA, GUARDS_METADATA, INTERCEPTORS_METADATA } from '@nestjs/common/constants.js';
|
|
5
|
-
import {
|
|
5
|
+
import { HTTP_CONTROLLER_METADATA, isConstructor, NotFoundError } from '@opra/common';
|
|
6
6
|
import { HttpAdapter } from '@opra/http';
|
|
7
7
|
import { asMutable } from 'ts-gems';
|
|
8
8
|
import { Public } from '../decorators/public.decorator.js';
|
|
9
9
|
export class OpraHttpNestjsAdapter extends HttpAdapter {
|
|
10
10
|
constructor(options) {
|
|
11
|
-
super(
|
|
12
|
-
const document = new ApiDocument();
|
|
13
|
-
document.api = new HttpApi({ owner: document, name: '', transport: 'http' });
|
|
14
|
-
return document;
|
|
15
|
-
})(), options);
|
|
11
|
+
super(options);
|
|
16
12
|
this.nestControllers = [];
|
|
17
13
|
this._addRootController(options.schemaIsPublic);
|
|
18
|
-
if (options.controllers)
|
|
19
|
-
|
|
14
|
+
if (options.controllers) {
|
|
15
|
+
for (const c of options.controllers) {
|
|
16
|
+
this._addToNestControllers(c, this.basePath, []);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
20
19
|
}
|
|
21
20
|
async close() {
|
|
22
21
|
//
|
package/esm/index.js
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ApiDocumentFactory, RPC_CONTROLLER_METADATA } from '@opra/common';
|
|
2
|
+
export async function initializeAdapter(moduleRef, adapter, config) {
|
|
3
|
+
const controllers = scanControllers(moduleRef);
|
|
4
|
+
const document = await ApiDocumentFactory.createDocument({
|
|
5
|
+
info: config.info,
|
|
6
|
+
types: config.types,
|
|
7
|
+
references: config.references,
|
|
8
|
+
api: {
|
|
9
|
+
name: config.name,
|
|
10
|
+
description: config.description,
|
|
11
|
+
transport: 'rpc',
|
|
12
|
+
platform: 'kafka',
|
|
13
|
+
controllers,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
await adapter.initialize(document);
|
|
17
|
+
}
|
|
18
|
+
function scanControllers(moduleRef) {
|
|
19
|
+
const container = moduleRef.container;
|
|
20
|
+
const modules = container.getModules();
|
|
21
|
+
const out = [];
|
|
22
|
+
modules.forEach(({ controllers }) => {
|
|
23
|
+
controllers.forEach(wrapper => {
|
|
24
|
+
const ctor = Object.getPrototypeOf(wrapper.instance).constructor;
|
|
25
|
+
const metadata = Reflect.getMetadata(RPC_CONTROLLER_METADATA, ctor);
|
|
26
|
+
if (!metadata)
|
|
27
|
+
return;
|
|
28
|
+
const instance = {};
|
|
29
|
+
Object.setPrototypeOf(instance, wrapper.instance);
|
|
30
|
+
out.push(wrapper.instance);
|
|
31
|
+
// if (metadata.operations) {
|
|
32
|
+
// for (const [k, _] of Object.keys(metadata.operations)) {
|
|
33
|
+
// const isRequestScoped = !wrapper.isDependencyTreeStatic();
|
|
34
|
+
// // const fn = instance[k];
|
|
35
|
+
// // instance[k] = fn;
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
@@ -3,13 +3,15 @@ import { __decorate, __metadata, __param } from "tslib";
|
|
|
3
3
|
import { Global, Inject, Logger, Module, } from '@nestjs/common';
|
|
4
4
|
import { ModuleRef } from '@nestjs/core';
|
|
5
5
|
import { isConstructor } from '@opra/common';
|
|
6
|
+
import { KafkaAdapter } from '@opra/kafka';
|
|
6
7
|
import { OPRA_KAFKA_MODULE_CONFIG } from '../constants.js';
|
|
7
|
-
import {
|
|
8
|
+
import { initializeAdapter } from './helpers/initialize-adapter.js';
|
|
8
9
|
const opraKafkaNestjsAdapterToken = Symbol('OpraKafkaNestjsAdapter');
|
|
9
10
|
let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
10
|
-
constructor(adapter,
|
|
11
|
+
constructor(moduleRef, adapter, config) {
|
|
12
|
+
this.moduleRef = moduleRef;
|
|
11
13
|
this.adapter = adapter;
|
|
12
|
-
this.
|
|
14
|
+
this.config = config;
|
|
13
15
|
}
|
|
14
16
|
static forRoot(moduleOptions) {
|
|
15
17
|
return this._getDynamicModule({
|
|
@@ -46,15 +48,13 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
static _getDynamicModule(moduleOptions) {
|
|
49
|
-
const token = moduleOptions.id ||
|
|
51
|
+
const token = moduleOptions.id || KafkaAdapter;
|
|
50
52
|
const adapterProvider = {
|
|
51
53
|
provide: token,
|
|
52
54
|
inject: [ModuleRef, OPRA_KAFKA_MODULE_CONFIG],
|
|
53
55
|
useFactory: async (moduleRef, config) => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
if (moduleOptions.interceptors) {
|
|
57
|
-
adapter.adapter.interceptors = moduleOptions.interceptors.map(x => {
|
|
56
|
+
const interceptors = moduleOptions.interceptors
|
|
57
|
+
? moduleOptions.interceptors.map(x => {
|
|
58
58
|
if (isConstructor(x)) {
|
|
59
59
|
return async (ctx, next) => {
|
|
60
60
|
const interceptor = moduleRef.get(x);
|
|
@@ -63,9 +63,9 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
return x;
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
return
|
|
66
|
+
})
|
|
67
|
+
: undefined;
|
|
68
|
+
return new KafkaAdapter({ ...config, interceptors });
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
return {
|
|
@@ -85,20 +85,25 @@ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
async onModuleInit() {
|
|
88
|
-
|
|
88
|
+
/** Check if not initialized before */
|
|
89
|
+
if (!this.adapter.document) {
|
|
90
|
+
await initializeAdapter(this.moduleRef, this.adapter, this.config);
|
|
91
|
+
}
|
|
89
92
|
}
|
|
90
93
|
async onApplicationBootstrap() {
|
|
91
|
-
|
|
94
|
+
if (this.adapter.document)
|
|
95
|
+
await this.adapter.start();
|
|
92
96
|
}
|
|
93
97
|
async onApplicationShutdown() {
|
|
94
|
-
await this.adapter.
|
|
98
|
+
await this.adapter.close();
|
|
95
99
|
}
|
|
96
100
|
};
|
|
97
101
|
OpraKafkaCoreModule = OpraKafkaCoreModule_1 = __decorate([
|
|
98
102
|
Module({}),
|
|
99
103
|
Global(),
|
|
100
|
-
__param(
|
|
101
|
-
__param(
|
|
102
|
-
__metadata("design:paramtypes", [
|
|
104
|
+
__param(1, Inject(opraKafkaNestjsAdapterToken)),
|
|
105
|
+
__param(2, Inject(OPRA_KAFKA_MODULE_CONFIG)),
|
|
106
|
+
__metadata("design:paramtypes", [ModuleRef,
|
|
107
|
+
KafkaAdapter, Object])
|
|
103
108
|
], OpraKafkaCoreModule);
|
|
104
109
|
export { OpraKafkaCoreModule };
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/nestjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Opra NestJS module",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@opra/common": "^1.0.
|
|
9
|
-
"@opra/core": "^1.0.
|
|
8
|
+
"@opra/common": "^1.0.6",
|
|
9
|
+
"@opra/core": "^1.0.6",
|
|
10
10
|
"fast-tokenizer": "^1.7.0",
|
|
11
11
|
"lodash.head": "^4.0.1",
|
|
12
12
|
"putil-promisify": "^1.10.1",
|
|
13
13
|
"reflect-metadata": "^0.2.2",
|
|
14
|
-
"tslib": "^2.
|
|
14
|
+
"tslib": "^2.8.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@nestjs/common": "^10.4.
|
|
18
|
-
"@nestjs/core": "^10.4.
|
|
17
|
+
"@nestjs/common": "^10.4.5",
|
|
18
|
+
"@nestjs/core": "^10.4.5"
|
|
19
19
|
},
|
|
20
20
|
"optionalDependencies": {
|
|
21
|
-
"@nestjs/microservices": "^10.4.
|
|
22
|
-
"@opra/http": "^1.0.
|
|
23
|
-
"@opra/kafka": "^1.0.
|
|
21
|
+
"@nestjs/microservices": "^10.4.5",
|
|
22
|
+
"@opra/http": "^1.0.6",
|
|
23
|
+
"@opra/kafka": "^1.0.6"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"exports": {
|
package/types/index.d.cts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModuleRef } from '@nestjs/core';
|
|
2
|
+
import { KafkaAdapter } from '@opra/kafka';
|
|
3
|
+
import type { OpraKafkaModule } from '../opra-kafka.module.js';
|
|
4
|
+
export declare function initializeAdapter(moduleRef: ModuleRef, adapter: KafkaAdapter, config: OpraKafkaModule.ApiConfig): Promise<void>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type DynamicModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { ModuleRef } from '@nestjs/core';
|
|
3
|
+
import { KafkaAdapter } from '@opra/kafka';
|
|
2
4
|
import type { OpraKafkaModule } from './opra-kafka.module.js';
|
|
3
|
-
import { OpraKafkaNestjsAdapter } from './opra-kafka-nestjs-adapter.js';
|
|
4
5
|
export declare class OpraKafkaCoreModule implements OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown {
|
|
5
|
-
protected
|
|
6
|
-
protected
|
|
7
|
-
|
|
6
|
+
protected moduleRef: ModuleRef;
|
|
7
|
+
protected adapter: KafkaAdapter;
|
|
8
|
+
protected config: OpraKafkaModule.ApiConfig;
|
|
9
|
+
constructor(moduleRef: ModuleRef, adapter: KafkaAdapter, config: OpraKafkaModule.ApiConfig);
|
|
8
10
|
static forRoot(moduleOptions: OpraKafkaModule.ModuleOptions): DynamicModule;
|
|
9
11
|
static forRootAsync(moduleOptions: OpraKafkaModule.AsyncModuleOptions): DynamicModule;
|
|
10
12
|
protected static _getDynamicModule(moduleOptions: OpraKafkaModule.ModuleOptions | OpraKafkaModule.AsyncModuleOptions): DynamicModule;
|
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
const base_nestjs_adapter_js_1 = require("../base-nestjs-adapter.js");
|
|
8
|
-
/**
|
|
9
|
-
* @class
|
|
10
|
-
*/
|
|
11
|
-
class OpraKafkaNestjsAdapter extends base_nestjs_adapter_js_1.BaseNestAdapter {
|
|
12
|
-
constructor(moduleRef) {
|
|
13
|
-
super(moduleRef);
|
|
14
|
-
}
|
|
15
|
-
get document() {
|
|
16
|
-
if (!this._document)
|
|
17
|
-
throw new index_1.RuntimeException('Not initialized yet');
|
|
18
|
-
return this._document;
|
|
19
|
-
}
|
|
20
|
-
get adapter() {
|
|
21
|
-
if (!this._adapter)
|
|
22
|
-
throw new index_1.RuntimeException('Not initialized yet');
|
|
23
|
-
return this._adapter;
|
|
24
|
-
}
|
|
25
|
-
async start() {
|
|
26
|
-
if (!this._adapter) {
|
|
27
|
-
throw new index_1.RuntimeException('Not initialized yet');
|
|
28
|
-
}
|
|
29
|
-
return this._adapter.start();
|
|
30
|
-
}
|
|
31
|
-
async stop() {
|
|
32
|
-
return this._adapter?.close();
|
|
33
|
-
}
|
|
34
|
-
async initialize(init) {
|
|
35
|
-
const controllers = this._scanControllers();
|
|
36
|
-
this._document = await common_1.ApiDocumentFactory.createDocument({
|
|
37
|
-
info: init.info,
|
|
38
|
-
types: init.types,
|
|
39
|
-
references: init.references,
|
|
40
|
-
api: {
|
|
41
|
-
name: init.name,
|
|
42
|
-
description: init.description,
|
|
43
|
-
transport: 'rpc',
|
|
44
|
-
platform: 'kafka',
|
|
45
|
-
controllers,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
this._adapter = new kafka_1.KafkaAdapter({
|
|
49
|
-
client: init.client,
|
|
50
|
-
logger: init.logger,
|
|
51
|
-
logExtra: init.logExtra,
|
|
52
|
-
consumers: init.consumers,
|
|
53
|
-
document: this._document,
|
|
54
|
-
defaults: init.defaults,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
_scanControllers() {
|
|
58
|
-
const container = this.moduleRef.container;
|
|
59
|
-
const modules = container.getModules();
|
|
60
|
-
const out = [];
|
|
61
|
-
modules.forEach(({ controllers }) => {
|
|
62
|
-
controllers.forEach(wrapper => {
|
|
63
|
-
const ctor = Object.getPrototypeOf(wrapper.instance).constructor;
|
|
64
|
-
const metadata = Reflect.getMetadata(common_1.RPC_CONTROLLER_METADATA, ctor);
|
|
65
|
-
if (!metadata)
|
|
66
|
-
return;
|
|
67
|
-
const instance = {};
|
|
68
|
-
Object.setPrototypeOf(instance, wrapper.instance);
|
|
69
|
-
out.push(wrapper.instance);
|
|
70
|
-
// if (metadata.operations) {
|
|
71
|
-
// for (const [k, _] of Object.keys(metadata.operations)) {
|
|
72
|
-
// const isRequestScoped = !wrapper.isDependencyTreeStatic();
|
|
73
|
-
// // const fn = instance[k];
|
|
74
|
-
// // instance[k] = fn;
|
|
75
|
-
// }
|
|
76
|
-
// }
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
return out;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.OpraKafkaNestjsAdapter = OpraKafkaNestjsAdapter;
|
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
import { BaseNestAdapter } from '../base-nestjs-adapter.js';
|
|
5
|
-
/**
|
|
6
|
-
* @class
|
|
7
|
-
*/
|
|
8
|
-
export class OpraKafkaNestjsAdapter extends BaseNestAdapter {
|
|
9
|
-
constructor(moduleRef) {
|
|
10
|
-
super(moduleRef);
|
|
11
|
-
}
|
|
12
|
-
get document() {
|
|
13
|
-
if (!this._document)
|
|
14
|
-
throw new RuntimeException('Not initialized yet');
|
|
15
|
-
return this._document;
|
|
16
|
-
}
|
|
17
|
-
get adapter() {
|
|
18
|
-
if (!this._adapter)
|
|
19
|
-
throw new RuntimeException('Not initialized yet');
|
|
20
|
-
return this._adapter;
|
|
21
|
-
}
|
|
22
|
-
async start() {
|
|
23
|
-
if (!this._adapter) {
|
|
24
|
-
throw new RuntimeException('Not initialized yet');
|
|
25
|
-
}
|
|
26
|
-
return this._adapter.start();
|
|
27
|
-
}
|
|
28
|
-
async stop() {
|
|
29
|
-
return this._adapter?.close();
|
|
30
|
-
}
|
|
31
|
-
async initialize(init) {
|
|
32
|
-
const controllers = this._scanControllers();
|
|
33
|
-
this._document = await ApiDocumentFactory.createDocument({
|
|
34
|
-
info: init.info,
|
|
35
|
-
types: init.types,
|
|
36
|
-
references: init.references,
|
|
37
|
-
api: {
|
|
38
|
-
name: init.name,
|
|
39
|
-
description: init.description,
|
|
40
|
-
transport: 'rpc',
|
|
41
|
-
platform: 'kafka',
|
|
42
|
-
controllers,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
this._adapter = new KafkaAdapter({
|
|
46
|
-
client: init.client,
|
|
47
|
-
logger: init.logger,
|
|
48
|
-
logExtra: init.logExtra,
|
|
49
|
-
consumers: init.consumers,
|
|
50
|
-
document: this._document,
|
|
51
|
-
defaults: init.defaults,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
_scanControllers() {
|
|
55
|
-
const container = this.moduleRef.container;
|
|
56
|
-
const modules = container.getModules();
|
|
57
|
-
const out = [];
|
|
58
|
-
modules.forEach(({ controllers }) => {
|
|
59
|
-
controllers.forEach(wrapper => {
|
|
60
|
-
const ctor = Object.getPrototypeOf(wrapper.instance).constructor;
|
|
61
|
-
const metadata = Reflect.getMetadata(RPC_CONTROLLER_METADATA, ctor);
|
|
62
|
-
if (!metadata)
|
|
63
|
-
return;
|
|
64
|
-
const instance = {};
|
|
65
|
-
Object.setPrototypeOf(instance, wrapper.instance);
|
|
66
|
-
out.push(wrapper.instance);
|
|
67
|
-
// if (metadata.operations) {
|
|
68
|
-
// for (const [k, _] of Object.keys(metadata.operations)) {
|
|
69
|
-
// const isRequestScoped = !wrapper.isDependencyTreeStatic();
|
|
70
|
-
// // const fn = instance[k];
|
|
71
|
-
// // instance[k] = fn;
|
|
72
|
-
// }
|
|
73
|
-
// }
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
return out;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ModuleRef } from '@nestjs/core';
|
|
2
|
-
import { ApiDocument } from '@opra/common';
|
|
3
|
-
import { KafkaAdapter } from '@opra/kafka';
|
|
4
|
-
import { BaseNestAdapter } from '../base-nestjs-adapter.js';
|
|
5
|
-
import type { OpraKafkaModule } from './opra-kafka.module.js';
|
|
6
|
-
/**
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
export declare class OpraKafkaNestjsAdapter extends BaseNestAdapter {
|
|
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.ApiConfig): Promise<void>;
|
|
18
|
-
protected _scanControllers(): any[];
|
|
19
|
-
}
|