@rsdk/kafka.producer 3.0.2 → 3.1.0-next.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/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.1.0-next.1](https://github.com/R-Vision/rsdk/compare/v3.1.0-next.0...v3.1.0-next.1) (2023-08-08)
7
+
8
+ **Note:** Version bump only for package @rsdk/kafka.producer
9
+
10
+ ## [3.1.0-next.0](https://github.com/R-Vision/rsdk/compare/v3.0.2...v3.1.0-next.0) (2023-08-08)
11
+
12
+ ### Features
13
+
14
+ * **kafka:** added option to consume by topic name ([#93](https://github.com/R-Vision/rsdk/issues/93)) ([09b4c1b](https://github.com/R-Vision/rsdk/commit/09b4c1bd515c1c2c3ccda17851fbe79e64ea8ac5))
15
+
6
16
  ## [3.0.2](https://github.com/R-Vision/rsdk/compare/v3.0.1...v3.0.2) (2023-08-07)
7
17
 
8
18
  **Note:** Version bump only for package @rsdk/kafka.producer
@@ -1,9 +1,9 @@
1
1
  import type { EventType } from '@rsdk/kafka.common';
2
2
  import type { KafkaProducer, OutboxTable, PublishOptions } from './types';
3
- export declare abstract class BaseProducer<T extends EventType> implements KafkaProducer<T> {
3
+ export declare abstract class BaseProducer<T extends EventType, P = T extends EventType<infer X> ? X : never> implements KafkaProducer<P> {
4
4
  readonly eventType: T;
5
5
  constructor(eventType: T);
6
- protected getPartitionKey(payload: T, partitionKeyField: string | null): string;
7
- protected parsePayload(payload: T, options?: PublishOptions): Partial<OutboxTable>;
8
- abstract publish(payload: T, options?: PublishOptions | undefined): Promise<void>;
6
+ protected getPartitionKey(payload: P, partitionKeyField: string | null): string;
7
+ protected parsePayload(payload: P, options?: PublishOptions): Partial<OutboxTable>;
8
+ abstract publish(payload: P, options?: PublishOptions | undefined): Promise<void>;
9
9
  }
@@ -14,8 +14,8 @@ class BaseProducer {
14
14
  getPartitionKey(payload, partitionKeyField) {
15
15
  const partitionKey = typeof partitionKeyField === 'string' && partitionKeyField.length > 0
16
16
  ? (0, get_1.default)(payload, partitionKeyField, (0, node_crypto_1.randomUUID)())
17
- : (0, get_1.default)(payload, 'id') ||
18
- (0, get_1.default)(payload, 'uuid') ||
17
+ : (0, get_1.default)(payload, 'id') ??
18
+ (0, get_1.default)(payload, 'uuid') ??
19
19
  (0, get_1.default)(payload, 'guid', (0, node_crypto_1.randomUUID)());
20
20
  return String(partitionKey);
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base.producer.js","sourceRoot":"","sources":["../src/base.producer.ts"],"names":[],"mappings":";;;;;;AACA,qDAA6B;AAC7B,6CAAyC;AAIzC,MAAsB,YAAY;IAGX;IAArB,YAAqB,SAAY;QAAZ,cAAS,GAAT,SAAS,CAAG;IAAG,CAAC;IAE3B,eAAe,CACvB,OAAU,EACV,iBAAgC;QAEhC,MAAM,YAAY,GAChB,OAAO,iBAAiB,KAAK,QAAQ,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC;YACnE,CAAC,CAAC,IAAA,aAAG,EAAC,OAAO,EAAE,iBAAiB,EAAE,IAAA,wBAAU,GAAE,CAAC;YAC/C,CAAC,CAAC,IAAA,aAAG,EAAC,OAAO,EAAE,IAAI,CAAC;gBAClB,IAAA,aAAG,EAAC,OAAO,EAAE,MAAM,CAAC;gBACpB,IAAA,aAAG,EAAC,OAAO,EAAE,MAAM,EAAE,IAAA,wBAAU,GAAE,CAAC,CAAC;QAEzC,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC;IAC9B,CAAC;IAES,YAAY,CACpB,OAAU,EACV,OAAwB;QAExB,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM;YAC5B,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,IAAI;YACnC,aAAa,EAAE,OAAO,EAAE,YAAY;gBAClC,CAAC,CAAC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Y,CAAC;gBAC9B,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC;YACpE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;YAC7D,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK;SAC3B,CAAC;IACJ,CAAC;CAMF;AAxCD,oCAwCC"}
package/dist/types.d.ts CHANGED
@@ -11,6 +11,6 @@ export interface OutboxTable {
11
11
  metadata: Record<string, any> | null;
12
12
  payload: Buffer;
13
13
  }
14
- export interface KafkaProducer<T> {
15
- publish(payload: T, options?: PublishOptions | undefined): Promise<void>;
14
+ export interface KafkaProducer<P> {
15
+ publish(payload: P, options?: PublishOptions | undefined): Promise<void>;
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/kafka.producer",
3
- "version": "3.0.2",
3
+ "version": "3.1.0-next.1",
4
4
  "description": "Publishers for kafka (different direct and outbox strategies)",
5
5
  "license": "Apache License 2.0",
6
6
  "publishConfig": {
@@ -14,11 +14,11 @@
14
14
  "@nestjs/common": "^10.1.3",
15
15
  "@nestjs/microservices": "^10.1.3",
16
16
  "@nestjs/typeorm": "^10.0.0",
17
- "@rsdk/common": "^3.0.2",
18
- "@rsdk/core": "^3.0.2",
19
- "@rsdk/kafka.common": "^3.0.2",
20
- "@rsdk/logging": "^3.0.2",
17
+ "@rsdk/common": "^3.1.0-next.0",
18
+ "@rsdk/core": "^3.1.0-next.1",
19
+ "@rsdk/kafka.common": "^3.1.0-next.1",
20
+ "@rsdk/logging": "^3.1.0-next.0",
21
21
  "lodash": "^4.17.21"
22
22
  },
23
- "gitHead": "3ee33710bf18bfadf87a6da92b060e6a17481110"
23
+ "gitHead": "e9002b175fb3d24b9bae5169df59bd250091672c"
24
24
  }
@@ -4,27 +4,29 @@ import { randomUUID } from 'node:crypto';
4
4
 
5
5
  import type { KafkaProducer, OutboxTable, PublishOptions } from './types';
6
6
 
7
- export abstract class BaseProducer<T extends EventType>
8
- implements KafkaProducer<T>
7
+ export abstract class BaseProducer<
8
+ T extends EventType,
9
+ P = T extends EventType<infer X> ? X : never,
10
+ > implements KafkaProducer<P>
9
11
  {
10
12
  constructor(readonly eventType: T) {}
11
13
 
12
14
  protected getPartitionKey(
13
- payload: T,
15
+ payload: P,
14
16
  partitionKeyField: string | null,
15
17
  ): string {
16
18
  const partitionKey =
17
19
  typeof partitionKeyField === 'string' && partitionKeyField.length > 0
18
20
  ? get(payload, partitionKeyField, randomUUID())
19
- : get(payload, 'id') ||
20
- get(payload, 'uuid') ||
21
+ : get(payload, 'id') ??
22
+ get(payload, 'uuid') ??
21
23
  get(payload, 'guid', randomUUID());
22
24
 
23
25
  return String(partitionKey);
24
26
  }
25
27
 
26
28
  protected parsePayload(
27
- payload: T,
29
+ payload: P,
28
30
  options?: PublishOptions,
29
31
  ): Partial<OutboxTable> {
30
32
  return {
@@ -39,7 +41,7 @@ export abstract class BaseProducer<T extends EventType>
39
41
  }
40
42
 
41
43
  abstract publish(
42
- payload: T,
44
+ payload: P,
43
45
  options?: PublishOptions | undefined,
44
46
  ): Promise<void>;
45
47
  }
package/src/types.ts CHANGED
@@ -15,6 +15,6 @@ export interface OutboxTable {
15
15
 
16
16
  // TODO: Добавить типизацию T extends EventType. Но с текущим генерируемым кодом это не работает
17
17
  // т. к. интерфейс события по факту не экстендит EventType
18
- export interface KafkaProducer<T> {
19
- publish(payload: T, options?: PublishOptions | undefined): Promise<void>;
18
+ export interface KafkaProducer<P> {
19
+ publish(payload: P, options?: PublishOptions | undefined): Promise<void>;
20
20
  }
@@ -1,2 +0,0 @@
1
- export declare class KafkaProducerModule {
2
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.KafkaProducerModule = void 0;
10
- const common_1 = require("@nestjs/common");
11
- const KafkaProducerStrategyToken = Symbol('KafkaProducerStrategy');
12
- let KafkaProducerModule = class KafkaProducerModule {
13
- };
14
- KafkaProducerModule = __decorate([
15
- (0, common_1.Module)({})
16
- ], KafkaProducerModule);
17
- exports.KafkaProducerModule = KafkaProducerModule;
18
- //# sourceMappingURL=kafka-producer.module.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kafka-producer.module.js","sourceRoot":"","sources":["../src/kafka-producer.module.ts"],"names":[],"mappings":";;;;;;;;;AACA,2CAAwC;AAIxC,MAAM,0BAA0B,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAG5D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;CAAG,CAAA;AAAtB,mBAAmB;IAD/B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,mBAAmB,CAAG;AAAtB,kDAAmB"}
@@ -1,4 +0,0 @@
1
- import type { AppropriateTransports, PlatformAppPlugin } from '@rsdk/core';
2
- export declare class KafkaProducerPlugin implements PlatformAppPlugin {
3
- forTransports(): AppropriateTransports;
4
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KafkaProducerPlugin = void 0;
4
- class KafkaProducerPlugin {
5
- forTransports() {
6
- return 'any';
7
- }
8
- }
9
- exports.KafkaProducerPlugin = KafkaProducerPlugin;
10
- //# sourceMappingURL=kafka-producer.plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kafka-producer.plugin.js","sourceRoot":"","sources":["../src/kafka-producer.plugin.ts"],"names":[],"mappings":";;;AAEA,MAAa,mBAAmB;IAC9B,aAAa;QACX,OAAO,KAAK,CAAC;IACf,CAAC;CAOF;AAVD,kDAUC"}