@opra/nestjs-kafka 1.22.0 → 1.22.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/constants.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const OPRA_KAFKA_MODULE_CONFIG = "OPRA_KAFKA_MODULE_CONFIG";
package/constants.js ADDED
@@ -0,0 +1 @@
1
+ export const OPRA_KAFKA_MODULE_CONFIG = 'OPRA_KAFKA_MODULE_CONFIG';
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import 'reflect-metadata';
2
+ import { IS_PUBLIC_KEY, OpraNestUtils, Public } from '@opra/nestjs';
3
+ export * from './constants.js';
4
+ export * from './opra-kafka.module.js';
5
+ export { IS_PUBLIC_KEY, OpraNestUtils, Public };
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import 'reflect-metadata';
2
+ import { IS_PUBLIC_KEY, OpraNestUtils, Public } from '@opra/nestjs';
3
+ export * from './constants.js';
4
+ export * from './opra-kafka.module.js';
5
+ export { IS_PUBLIC_KEY, OpraNestUtils, Public };
@@ -0,0 +1,16 @@
1
+ import { type DynamicModule, OnApplicationBootstrap, OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
2
+ import { KafkaAdapter } from '@opra/kafka';
3
+ import { MQControllerFactory } from '@opra/nestjs';
4
+ import type { OpraKafkaModule } from './opra-kafka.module.js';
5
+ export declare class OpraKafkaCoreModule implements OnModuleInit, OnApplicationBootstrap, OnApplicationShutdown {
6
+ private controllerFactory;
7
+ protected adapter: KafkaAdapter;
8
+ protected config: OpraKafkaModule.ApiConfig;
9
+ constructor(controllerFactory: MQControllerFactory, adapter: KafkaAdapter, config: OpraKafkaModule.ApiConfig);
10
+ static forRoot(moduleOptions: OpraKafkaModule.ModuleOptions): DynamicModule;
11
+ static forRootAsync(moduleOptions: OpraKafkaModule.AsyncModuleOptions): DynamicModule;
12
+ protected static _getDynamicModule(moduleOptions: OpraKafkaModule.ModuleOptions | OpraKafkaModule.AsyncModuleOptions): DynamicModule;
13
+ onModuleInit(): any;
14
+ onApplicationBootstrap(): Promise<void>;
15
+ onApplicationShutdown(): Promise<void>;
16
+ }
@@ -0,0 +1,137 @@
1
+ var OpraKafkaCoreModule_1;
2
+ import { __decorate, __metadata, __param } from "tslib";
3
+ import { isConstructor } from '@jsopen/objects';
4
+ import { Global, Inject, Logger, Module, } from '@nestjs/common';
5
+ import { ModuleRef } from '@nestjs/core';
6
+ import { ApiDocumentFactory } from '@opra/common';
7
+ import { KafkaAdapter } from '@opra/kafka';
8
+ import { MQControllerFactory } from '@opra/nestjs';
9
+ import { OPRA_KAFKA_MODULE_CONFIG } from './constants.js';
10
+ const opraKafkaNestjsAdapterToken = Symbol('OpraKafkaNestjsAdapter');
11
+ let OpraKafkaCoreModule = OpraKafkaCoreModule_1 = class OpraKafkaCoreModule {
12
+ controllerFactory;
13
+ adapter;
14
+ config;
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: OPRA_KAFKA_MODULE_CONFIG,
27
+ useValue: {
28
+ ...moduleOptions,
29
+ logger: moduleOptions.logger || new 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: 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 Logger(result.name);
48
+ return result;
49
+ },
50
+ },
51
+ ],
52
+ });
53
+ }
54
+ static _getDynamicModule(moduleOptions) {
55
+ const token = moduleOptions.id || KafkaAdapter;
56
+ const adapterProvider = {
57
+ provide: token,
58
+ inject: [MQControllerFactory, ModuleRef, OPRA_KAFKA_MODULE_CONFIG],
59
+ useFactory: async (controllerFactory, moduleRef, config) => {
60
+ const controllers = controllerFactory
61
+ .exploreControllers()
62
+ .map(x => x.wrapper.instance);
63
+ const document = await 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: 'mq',
71
+ platform: KafkaAdapter.PlatformName,
72
+ controllers,
73
+ },
74
+ });
75
+ const interceptors = moduleOptions.interceptors
76
+ ? moduleOptions.interceptors.map(x => {
77
+ if (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 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
+ MQControllerFactory,
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 mqApi = this.adapter.document.getMqApi();
111
+ const controllers = Array.from(mqApi.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
+ OpraKafkaCoreModule = OpraKafkaCoreModule_1 = __decorate([
130
+ Module({}),
131
+ Global(),
132
+ __param(1, Inject(opraKafkaNestjsAdapterToken)),
133
+ __param(2, Inject(OPRA_KAFKA_MODULE_CONFIG)),
134
+ __metadata("design:paramtypes", [MQControllerFactory,
135
+ KafkaAdapter, Object])
136
+ ], OpraKafkaCoreModule);
137
+ export { OpraKafkaCoreModule };
@@ -0,0 +1,34 @@
1
+ import { type DynamicModule, Logger, type Type } from '@nestjs/common';
2
+ import { ApiDocumentFactory } from '@opra/common';
3
+ import type { KafkaAdapter } from '@opra/kafka';
4
+ export declare namespace OpraKafkaModule {
5
+ export interface ModuleOptions extends BaseModuleOptions, ApiConfig {
6
+ }
7
+ export interface AsyncModuleOptions extends BaseModuleOptions {
8
+ inject?: any[];
9
+ useFactory?: (...args: any[]) => Promise<ApiConfig> | ApiConfig;
10
+ }
11
+ interface BaseModuleOptions extends Pick<DynamicModule, 'imports' | 'providers' | 'exports' | 'controllers' | 'global'> {
12
+ id?: any;
13
+ interceptors?: (KafkaAdapter.InterceptorFunction | KafkaAdapter.IKafkaInterceptor | Type<KafkaAdapter.IKafkaInterceptor>)[];
14
+ }
15
+ export interface ApiConfig extends Pick<ApiDocumentFactory.InitArguments, 'types' | 'references' | 'info'>, Pick<KafkaAdapter.Config, 'client' | 'consumers' | 'logExtra' | 'defaults'> {
16
+ name: string;
17
+ description?: string;
18
+ scope?: string;
19
+ logger?: Logger;
20
+ }
21
+ export {};
22
+ }
23
+ export declare class OpraKafkaModule {
24
+ /**
25
+ *
26
+ * @param options
27
+ */
28
+ static forRoot(options: OpraKafkaModule.ModuleOptions): DynamicModule;
29
+ /**
30
+ *
31
+ * @param options
32
+ */
33
+ static forRootAsync(options: OpraKafkaModule.AsyncModuleOptions): DynamicModule;
34
+ }
@@ -0,0 +1,30 @@
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 options
9
+ */
10
+ static forRoot(options) {
11
+ return {
12
+ module: OpraKafkaModule_1,
13
+ imports: [OpraKafkaCoreModule.forRoot(options)],
14
+ };
15
+ }
16
+ /**
17
+ *
18
+ * @param options
19
+ */
20
+ static forRootAsync(options) {
21
+ return {
22
+ module: OpraKafkaModule_1,
23
+ imports: [OpraKafkaCoreModule.forRootAsync(options)],
24
+ };
25
+ }
26
+ };
27
+ OpraKafkaModule = OpraKafkaModule_1 = __decorate([
28
+ Module({})
29
+ ], OpraKafkaModule);
30
+ export { OpraKafkaModule };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs-kafka",
3
- "version": "1.22.0",
3
+ "version": "1.22.1",
4
4
  "description": "Opra NestJS Kafka Module",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -12,10 +12,10 @@
12
12
  "tslib": "^2.8.1"
13
13
  },
14
14
  "peerDependencies": {
15
- "@opra/common": "^1.22.0",
16
- "@opra/core": "^1.22.0",
17
- "@opra/nestjs": "^1.22.0",
18
- "@opra/kafka": "^1.22.0",
15
+ "@opra/common": "^1.22.1",
16
+ "@opra/core": "^1.22.1",
17
+ "@opra/nestjs": "^1.22.1",
18
+ "@opra/kafka": "^1.22.1",
19
19
  "@nestjs/common": "^10.0.0 || ^11.0.0",
20
20
  "@nestjs/core": "^10.0.0 || ^11.0.0",
21
21
  "@nestjs/microservices": "^10.0.0 || ^11.0.0",
@@ -39,14 +39,6 @@
39
39
  "url": "git+https://github.com/panates/opra.git",
40
40
  "directory": "packages/nestjs-kafka"
41
41
  },
42
- "files": [
43
- "bin/",
44
- "cjs/",
45
- "esm/",
46
- "types/",
47
- "LICENSE",
48
- "README.md"
49
- ],
50
42
  "keywords": [
51
43
  "opra",
52
44
  "nestjs",