@opra/kafka 1.19.4 → 1.19.7

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.
@@ -4,7 +4,7 @@ require("@opra/core");
4
4
  const common_1 = require("@opra/common");
5
5
  const constants_js_1 = require("../constants.js");
6
6
  /** Implementation **/
7
- common_1.classes.RpcOperationDecoratorFactory.augment((decorator, decoratorChain) => {
7
+ common_1.classes.MQOperationDecoratorFactory.augment((decorator, decoratorChain) => {
8
8
  decorator.Kafka = (config) => {
9
9
  decoratorChain.push((_, target, propertyKey) => {
10
10
  if (typeof config === 'function') {
@@ -29,11 +29,11 @@ class KafkaAdapter extends core_1.PlatformAdapter {
29
29
  this._consumers = new Map();
30
30
  this._handlerArgs = [];
31
31
  this._status = 'idle';
32
- this.protocol = 'rpc';
32
+ this.protocol = 'mq';
33
33
  this.platform = KafkaAdapter.PlatformName;
34
34
  this._document = document;
35
35
  this._config = config;
36
- if (!(this.document.api instanceof common_1.RpcApi &&
36
+ if (!(this.document.api instanceof common_1.MQApi &&
37
37
  this.document.api.platform === KafkaAdapter.PlatformName)) {
38
38
  throw new TypeError(`The document doesn't expose a Kafka Api`);
39
39
  }
@@ -50,7 +50,7 @@ class KafkaAdapter extends core_1.PlatformAdapter {
50
50
  });
51
51
  }
52
52
  get api() {
53
- return this.document.rpcApi;
53
+ return this.document.mqApi;
54
54
  }
55
55
  get kafka() {
56
56
  return this._kafka;
@@ -173,7 +173,7 @@ class KafkaAdapter extends core_1.PlatformAdapter {
173
173
  if (typeof instance[operation.name] !== 'function')
174
174
  return;
175
175
  const proto = controller.ctor?.prototype || Object.getPrototypeOf(instance);
176
- if (Reflect.hasMetadata(common_1.RPC_CONTROLLER_METADATA, proto, operation.name))
176
+ if (Reflect.hasMetadata(common_1.MQ_CONTROLLER_METADATA, proto, operation.name))
177
177
  return;
178
178
  const operationConfig = {
179
179
  consumer: {
@@ -221,7 +221,7 @@ class KafkaAdapter extends core_1.PlatformAdapter {
221
221
  * @protected
222
222
  */
223
223
  async _createAllConsumers() {
224
- for (const controller of this.document.rpcApi.controllers.values()) {
224
+ for (const controller of this.document.mqApi.controllers.values()) {
225
225
  let instance = controller.instance;
226
226
  if (!instance && controller.ctor)
227
227
  instance = new controller.ctor();
@@ -16,11 +16,11 @@ class KafkaContext extends core_1.ExecutionContext {
16
16
  ...init,
17
17
  document: init.adapter.document,
18
18
  documentNode: init.controller?.node,
19
- protocol: 'rpc',
19
+ protocol: 'mq',
20
20
  });
21
21
  this.adapter = init.adapter;
22
22
  this.platform = init.adapter.platform;
23
- this.protocol = 'rpc';
23
+ this.protocol = 'mq';
24
24
  if (init.controller)
25
25
  this.controller = init.controller;
26
26
  if (init.controllerInstance)
@@ -2,7 +2,7 @@ import '@opra/core';
2
2
  import { classes } from '@opra/common';
3
3
  import { KAFKA_OPERATION_METADATA, KAFKA_OPERATION_METADATA_RESOLVER, } from '../constants.js';
4
4
  /** Implementation **/
5
- classes.RpcOperationDecoratorFactory.augment((decorator, decoratorChain) => {
5
+ classes.MQOperationDecoratorFactory.augment((decorator, decoratorChain) => {
6
6
  decorator.Kafka = (config) => {
7
7
  decoratorChain.push((_, target, propertyKey) => {
8
8
  if (typeof config === 'function') {
@@ -1,4 +1,4 @@
1
- import { OpraException, RPC_CONTROLLER_METADATA, RpcApi, } from '@opra/common';
1
+ import { MQ_CONTROLLER_METADATA, MQApi, OpraException, } from '@opra/common';
2
2
  import { kAssetCache, PlatformAdapter } from '@opra/core';
3
3
  import { Kafka, logLevel, } from 'kafkajs';
4
4
  import { vg } from 'valgen';
@@ -26,11 +26,11 @@ export class KafkaAdapter extends PlatformAdapter {
26
26
  this._consumers = new Map();
27
27
  this._handlerArgs = [];
28
28
  this._status = 'idle';
29
- this.protocol = 'rpc';
29
+ this.protocol = 'mq';
30
30
  this.platform = KafkaAdapter.PlatformName;
31
31
  this._document = document;
32
32
  this._config = config;
33
- if (!(this.document.api instanceof RpcApi &&
33
+ if (!(this.document.api instanceof MQApi &&
34
34
  this.document.api.platform === KafkaAdapter.PlatformName)) {
35
35
  throw new TypeError(`The document doesn't expose a Kafka Api`);
36
36
  }
@@ -47,7 +47,7 @@ export class KafkaAdapter extends PlatformAdapter {
47
47
  });
48
48
  }
49
49
  get api() {
50
- return this.document.rpcApi;
50
+ return this.document.mqApi;
51
51
  }
52
52
  get kafka() {
53
53
  return this._kafka;
@@ -170,7 +170,7 @@ export class KafkaAdapter extends PlatformAdapter {
170
170
  if (typeof instance[operation.name] !== 'function')
171
171
  return;
172
172
  const proto = controller.ctor?.prototype || Object.getPrototypeOf(instance);
173
- if (Reflect.hasMetadata(RPC_CONTROLLER_METADATA, proto, operation.name))
173
+ if (Reflect.hasMetadata(MQ_CONTROLLER_METADATA, proto, operation.name))
174
174
  return;
175
175
  const operationConfig = {
176
176
  consumer: {
@@ -218,7 +218,7 @@ export class KafkaAdapter extends PlatformAdapter {
218
218
  * @protected
219
219
  */
220
220
  async _createAllConsumers() {
221
- for (const controller of this.document.rpcApi.controllers.values()) {
221
+ for (const controller of this.document.mqApi.controllers.values()) {
222
222
  let instance = controller.instance;
223
223
  if (!instance && controller.ctor)
224
224
  instance = new controller.ctor();
@@ -13,11 +13,11 @@ export class KafkaContext extends ExecutionContext {
13
13
  ...init,
14
14
  document: init.adapter.document,
15
15
  documentNode: init.controller?.node,
16
- protocol: 'rpc',
16
+ protocol: 'mq',
17
17
  });
18
18
  this.adapter = init.adapter;
19
19
  this.platform = init.adapter.platform;
20
- this.protocol = 'rpc';
20
+ this.protocol = 'mq';
21
21
  if (init.controller)
22
22
  this.controller = init.controller;
23
23
  if (init.controllerInstance)
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@opra/kafka",
3
- "version": "1.19.4",
4
- "description": "Opra Kafka package",
3
+ "version": "1.19.7",
4
+ "description": "Opra Kafka adapter",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "node-events-async": "^1.2.0",
9
9
  "tslib": "^2.8.1",
10
- "valgen": "^5.18.0"
10
+ "valgen": "^5.18.2"
11
11
  },
12
12
  "peerDependencies": {
13
- "@opra/common": "^1.19.4",
14
- "@opra/core": "^1.19.4",
13
+ "@opra/common": "^1.19.7",
14
+ "@opra/core": "^1.19.7",
15
15
  "kafkajs": ">=2.2.4 <3"
16
16
  },
17
17
  "type": "module",
@@ -1,7 +1,7 @@
1
1
  import '@opra/core';
2
2
  import { KafkaAdapter } from '../kafka-adapter.js';
3
3
  declare module '@opra/common' {
4
- interface RpcOperationDecorator {
4
+ interface MQOperationDecorator {
5
5
  Kafka(config: KafkaAdapter.OperationOptions | (() => KafkaAdapter.OperationOptions | Promise<KafkaAdapter.OperationOptions>)): this;
6
6
  }
7
7
  }
@@ -1,4 +1,4 @@
1
- import { ApiDocument, OpraException, OpraSchema, RpcApi, RpcController, RpcOperation } from '@opra/common';
1
+ import { ApiDocument, MQApi, MQController, MQOperation, OpraException, OpraSchema } from '@opra/common';
2
2
  import { type ILogger, PlatformAdapter } from '@opra/core';
3
3
  import { type Consumer, type ConsumerConfig, type EachMessageHandler, EachMessagePayload, Kafka, type KafkaConfig } from 'kafkajs';
4
4
  import type { StrictOmit } from 'ts-gems';
@@ -10,9 +10,9 @@ export interface OperationConfig {
10
10
  }
11
11
  interface HandlerArguments {
12
12
  consumer: Consumer;
13
- controller: RpcController;
13
+ controller: MQController;
14
14
  instance: any;
15
- operation: RpcOperation;
15
+ operation: MQOperation;
16
16
  operationConfig: OperationConfig;
17
17
  handler: EachMessageHandler;
18
18
  topics: (string | RegExp)[];
@@ -24,7 +24,7 @@ interface HandlerArguments {
24
24
  export declare class KafkaAdapter extends PlatformAdapter<KafkaAdapter.Events> {
25
25
  static readonly PlatformName = "kafka";
26
26
  protected _config: KafkaAdapter.Config;
27
- protected _controllerInstances: Map<RpcController, any>;
27
+ protected _controllerInstances: Map<MQController, any>;
28
28
  protected _consumers: Map<string, Consumer>;
29
29
  protected _handlerArgs: HandlerArguments[];
30
30
  protected _kafka: Kafka;
@@ -39,7 +39,7 @@ export declare class KafkaAdapter extends PlatformAdapter<KafkaAdapter.Events> {
39
39
  * @constructor
40
40
  */
41
41
  constructor(document: ApiDocument, config: KafkaAdapter.Config);
42
- get api(): RpcApi;
42
+ get api(): MQApi;
43
43
  get kafka(): Kafka;
44
44
  get scope(): string | undefined;
45
45
  get status(): KafkaAdapter.Status;
@@ -60,7 +60,7 @@ export declare class KafkaAdapter extends PlatformAdapter<KafkaAdapter.Events> {
60
60
  * @param operation
61
61
  * @protected
62
62
  */
63
- protected _getOperationConfig(controller: RpcController, instance: any, operation: RpcOperation): Promise<OperationConfig | undefined>;
63
+ protected _getOperationConfig(controller: MQController, instance: any, operation: MQOperation): Promise<OperationConfig | undefined>;
64
64
  /**
65
65
  *
66
66
  * @protected
@@ -125,10 +125,10 @@ export declare namespace KafkaAdapter {
125
125
  intercept(context: KafkaContext, next: NextCallback): Promise<any>;
126
126
  };
127
127
  interface Events {
128
- error: [Error, KafkaContext | undefined];
129
- finish: [KafkaContext, any];
130
- execute: [KafkaContext];
131
- message: [EachMessagePayload];
128
+ error: [error: Error, context: KafkaContext | undefined];
129
+ finish: [context: KafkaContext, result: any];
130
+ execute: [context: KafkaContext];
131
+ message: [content: EachMessagePayload];
132
132
  }
133
133
  }
134
134
  export {};
@@ -1,4 +1,4 @@
1
- import { OpraSchema, RpcController, RpcOperation } from '@opra/common';
1
+ import { MQController, MQOperation, OpraSchema } from '@opra/common';
2
2
  import { ExecutionContext } from '@opra/core';
3
3
  import type { KafkaMessage } from 'kafkajs';
4
4
  import type { AsyncEventEmitter } from 'node-events-async';
@@ -11,9 +11,9 @@ export declare class KafkaContext extends ExecutionContext implements AsyncEvent
11
11
  readonly protocol: OpraSchema.Transport;
12
12
  readonly platform: string;
13
13
  readonly adapter: KafkaAdapter;
14
- readonly controller?: RpcController;
14
+ readonly controller?: MQController;
15
15
  readonly controllerInstance?: any;
16
- readonly operation?: RpcOperation;
16
+ readonly operation?: MQOperation;
17
17
  readonly operationHandler?: Function;
18
18
  readonly topic: string;
19
19
  readonly key: any;
@@ -32,9 +32,9 @@ export declare class KafkaContext extends ExecutionContext implements AsyncEvent
32
32
  export declare namespace KafkaContext {
33
33
  interface Initiator extends Omit<ExecutionContext.Initiator, 'document' | 'protocol' | 'documentNode'> {
34
34
  adapter: KafkaAdapter;
35
- controller?: RpcController;
35
+ controller?: MQController;
36
36
  controllerInstance?: any;
37
- operation?: RpcOperation;
37
+ operation?: MQOperation;
38
38
  operationHandler?: Function;
39
39
  topic: string;
40
40
  partition: number;