@opra/kafka 1.4.3 → 1.4.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.
@@ -33,7 +33,8 @@ class KafkaAdapter extends core_1.PlatformAdapter {
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 && this.document.api.platform === KafkaAdapter.PlatformName)) {
36
+ if (!(this.document.api instanceof common_1.RpcApi &&
37
+ this.document.api.platform === KafkaAdapter.PlatformName)) {
37
38
  throw new TypeError(`The document doesn't expose a Kafka Api`);
38
39
  }
39
40
  // this._config = config;
@@ -62,7 +63,9 @@ class KafkaAdapter extends core_1.PlatformAdapter {
62
63
  return;
63
64
  this._kafka = new kafkajs_1.Kafka({
64
65
  ...this._config.client,
65
- logCreator: this.logger ? () => this._createLogCreator(this.logger, this._config.logExtra) : undefined,
66
+ logCreator: this.logger
67
+ ? () => this._createLogCreator(this.logger, this._config.logExtra)
68
+ : undefined,
66
69
  });
67
70
  await this._createAllConsumers();
68
71
  }
@@ -85,7 +88,9 @@ class KafkaAdapter extends core_1.PlatformAdapter {
85
88
  /** Subscribe to channels */
86
89
  for (const args of this._handlerArgs) {
87
90
  const { consumer, operation, operationConfig } = args;
88
- args.topics = Array.isArray(operation.channel) ? operation.channel : [operation.channel];
91
+ args.topics = Array.isArray(operation.channel)
92
+ ? operation.channel
93
+ : [operation.channel];
89
94
  await consumer
90
95
  .subscribe({
91
96
  ...operationConfig.subscribe,
@@ -110,7 +115,7 @@ class KafkaAdapter extends core_1.PlatformAdapter {
110
115
  let handlerArgsArray = topicMap.get(topicCacheKey);
111
116
  if (!handlerArgsArray) {
112
117
  handlerArgsArray = this._handlerArgs.filter(args => args.consumer === consumer &&
113
- args.topics.find(t => (t instanceof RegExp ? t.test(topic) : t === topic)));
118
+ args.topics.find(t => t instanceof RegExp ? t.test(topic) : t === topic));
114
119
  /* istanbul ignore next */
115
120
  if (!handlerArgsArray) {
116
121
  this._emitError(new Error(`Unhandled topic (${topic})`));
@@ -274,12 +279,19 @@ class KafkaAdapter extends core_1.PlatformAdapter {
274
279
  const parseKey = request_parser_js_1.RequestParser.STRING;
275
280
  const parsePayload = request_parser_js_1.RequestParser.STRING;
276
281
  /** Prepare decoders */
277
- const decodeKey = operation.keyType?.generateCodec('decode', { ignoreWriteonlyFields: true }) || valgen_1.vg.isAny();
278
- const decodePayload = operation.payloadType?.generateCodec('decode', { ignoreWriteonlyFields: true }) || valgen_1.vg.isAny();
282
+ const decodeKey = operation.keyType?.generateCodec('decode', {
283
+ ignoreWriteonlyFields: true,
284
+ }) || valgen_1.vg.isAny();
285
+ const decodePayload = operation.payloadType?.generateCodec('decode', {
286
+ ignoreWriteonlyFields: true,
287
+ }) || valgen_1.vg.isAny();
279
288
  operation.headers.forEach(header => {
280
289
  let decode = this[core_1.kAssetCache].get(header, 'decode');
281
290
  if (!decode) {
282
- decode = header.type?.generateCodec('decode', { ignoreReadonlyFields: true }) || valgen_1.vg.isAny();
291
+ decode =
292
+ header.type?.generateCodec('decode', {
293
+ ignoreReadonlyFields: true,
294
+ }) || valgen_1.vg.isAny();
283
295
  this[core_1.kAssetCache].set(header, 'decode', decode);
284
296
  }
285
297
  });
@@ -363,7 +375,7 @@ class KafkaAdapter extends core_1.PlatformAdapter {
363
375
  .catch(noOp);
364
376
  }
365
377
  _wrapExceptions(exceptions) {
366
- const wrappedErrors = exceptions.map(e => (e instanceof common_1.OpraException ? e : new common_1.OpraException(e)));
378
+ const wrappedErrors = exceptions.map(e => e instanceof common_1.OpraException ? e : new common_1.OpraException(e));
367
379
  if (!wrappedErrors.length)
368
380
  wrappedErrors.push(new common_1.OpraException('Internal Server Error'));
369
381
  return wrappedErrors;
@@ -1,6 +1,6 @@
1
1
  import '@opra/core';
2
2
  import { classes } from '@opra/common';
3
- import { KAFKA_OPERATION_METADATA, KAFKA_OPERATION_METADATA_RESOLVER } from '../constants.js';
3
+ import { KAFKA_OPERATION_METADATA, KAFKA_OPERATION_METADATA_RESOLVER, } from '../constants.js';
4
4
  /** Implementation **/
5
5
  classes.RpcOperationDecoratorFactory.augment((decorator, decoratorChain) => {
6
6
  decorator.Kafka = (config) => {
@@ -1,8 +1,8 @@
1
1
  import { OpraException, RPC_CONTROLLER_METADATA, RpcApi, } from '@opra/common';
2
2
  import { kAssetCache, PlatformAdapter } from '@opra/core';
3
- import { Kafka, logLevel } from 'kafkajs';
3
+ import { Kafka, logLevel, } from 'kafkajs';
4
4
  import { vg } from 'valgen';
5
- import { KAFKA_DEFAULT_GROUP, KAFKA_OPERATION_METADATA, KAFKA_OPERATION_METADATA_RESOLVER } from './constants.js';
5
+ import { KAFKA_DEFAULT_GROUP, KAFKA_OPERATION_METADATA, KAFKA_OPERATION_METADATA_RESOLVER, } from './constants.js';
6
6
  import { KafkaContext } from './kafka-context.js';
7
7
  import { RequestParser } from './request-parser.js';
8
8
  const globalErrorTypes = ['unhandledRejection', 'uncaughtException'];
@@ -30,7 +30,8 @@ export class KafkaAdapter extends PlatformAdapter {
30
30
  this.platform = KafkaAdapter.PlatformName;
31
31
  this._document = document;
32
32
  this._config = config;
33
- if (!(this.document.api instanceof RpcApi && this.document.api.platform === KafkaAdapter.PlatformName)) {
33
+ if (!(this.document.api instanceof RpcApi &&
34
+ this.document.api.platform === KafkaAdapter.PlatformName)) {
34
35
  throw new TypeError(`The document doesn't expose a Kafka Api`);
35
36
  }
36
37
  // this._config = config;
@@ -59,7 +60,9 @@ export class KafkaAdapter extends PlatformAdapter {
59
60
  return;
60
61
  this._kafka = new Kafka({
61
62
  ...this._config.client,
62
- logCreator: this.logger ? () => this._createLogCreator(this.logger, this._config.logExtra) : undefined,
63
+ logCreator: this.logger
64
+ ? () => this._createLogCreator(this.logger, this._config.logExtra)
65
+ : undefined,
63
66
  });
64
67
  await this._createAllConsumers();
65
68
  }
@@ -82,7 +85,9 @@ export class KafkaAdapter extends PlatformAdapter {
82
85
  /** Subscribe to channels */
83
86
  for (const args of this._handlerArgs) {
84
87
  const { consumer, operation, operationConfig } = args;
85
- args.topics = Array.isArray(operation.channel) ? operation.channel : [operation.channel];
88
+ args.topics = Array.isArray(operation.channel)
89
+ ? operation.channel
90
+ : [operation.channel];
86
91
  await consumer
87
92
  .subscribe({
88
93
  ...operationConfig.subscribe,
@@ -107,7 +112,7 @@ export class KafkaAdapter extends PlatformAdapter {
107
112
  let handlerArgsArray = topicMap.get(topicCacheKey);
108
113
  if (!handlerArgsArray) {
109
114
  handlerArgsArray = this._handlerArgs.filter(args => args.consumer === consumer &&
110
- args.topics.find(t => (t instanceof RegExp ? t.test(topic) : t === topic)));
115
+ args.topics.find(t => t instanceof RegExp ? t.test(topic) : t === topic));
111
116
  /* istanbul ignore next */
112
117
  if (!handlerArgsArray) {
113
118
  this._emitError(new Error(`Unhandled topic (${topic})`));
@@ -271,12 +276,19 @@ export class KafkaAdapter extends PlatformAdapter {
271
276
  const parseKey = RequestParser.STRING;
272
277
  const parsePayload = RequestParser.STRING;
273
278
  /** Prepare decoders */
274
- const decodeKey = operation.keyType?.generateCodec('decode', { ignoreWriteonlyFields: true }) || vg.isAny();
275
- const decodePayload = operation.payloadType?.generateCodec('decode', { ignoreWriteonlyFields: true }) || vg.isAny();
279
+ const decodeKey = operation.keyType?.generateCodec('decode', {
280
+ ignoreWriteonlyFields: true,
281
+ }) || vg.isAny();
282
+ const decodePayload = operation.payloadType?.generateCodec('decode', {
283
+ ignoreWriteonlyFields: true,
284
+ }) || vg.isAny();
276
285
  operation.headers.forEach(header => {
277
286
  let decode = this[kAssetCache].get(header, 'decode');
278
287
  if (!decode) {
279
- decode = header.type?.generateCodec('decode', { ignoreReadonlyFields: true }) || vg.isAny();
288
+ decode =
289
+ header.type?.generateCodec('decode', {
290
+ ignoreReadonlyFields: true,
291
+ }) || vg.isAny();
280
292
  this[kAssetCache].set(header, 'decode', decode);
281
293
  }
282
294
  });
@@ -360,7 +372,7 @@ export class KafkaAdapter extends PlatformAdapter {
360
372
  .catch(noOp);
361
373
  }
362
374
  _wrapExceptions(exceptions) {
363
- const wrappedErrors = exceptions.map(e => (e instanceof OpraException ? e : new OpraException(e)));
375
+ const wrappedErrors = exceptions.map(e => e instanceof OpraException ? e : new OpraException(e));
364
376
  if (!wrappedErrors.length)
365
377
  wrappedErrors.push(new OpraException('Internal Server Error'));
366
378
  return wrappedErrors;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@opra/kafka",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Opra Kafka package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@opra/common": "^1.4.3",
9
- "@opra/core": "^1.4.3",
8
+ "@opra/common": "^1.4.4",
9
+ "@opra/core": "^1.4.4",
10
10
  "node-events-async": "^1.0.0",
11
11
  "tslib": "^2.8.1",
12
12
  "valgen": "^5.12.0"