@rsdk/kafka.producer 3.0.1-next.0 → 3.1.0-next.0
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 +16 -0
- package/dist/base.producer.d.ts +4 -4
- package/dist/base.producer.js +2 -2
- package/dist/base.producer.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/package.json +6 -6
- package/src/base.producer.ts +9 -7
- package/src/types.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.0](https://github.com/R-Vision/rsdk/compare/v3.0.2...v3.1.0-next.0) (2023-08-08)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **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))
|
|
11
|
+
|
|
12
|
+
## [3.0.2](https://github.com/R-Vision/rsdk/compare/v3.0.1...v3.0.2) (2023-08-07)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rsdk/kafka.producer
|
|
15
|
+
|
|
16
|
+
## [3.0.1](https://github.com/R-Vision/rsdk/compare/v3.0.0...v3.0.1) (2023-08-07)
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **deps:** correctly peerDependencies ([349628f](https://github.com/R-Vision/rsdk/commit/349628f10da46a30d6c8b9f9387e010869318212))
|
|
21
|
+
|
|
6
22
|
## [3.0.1-next.0](https://github.com/R-Vision/rsdk/compare/v3.0.0...v3.0.1-next.0) (2023-08-07)
|
|
7
23
|
|
|
8
24
|
### Bug Fixes
|
package/dist/base.producer.d.ts
CHANGED
|
@@ -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<
|
|
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:
|
|
7
|
-
protected parsePayload(payload:
|
|
8
|
-
abstract publish(payload:
|
|
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
|
}
|
package/dist/base.producer.js
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"base.producer.js","sourceRoot":"","sources":["../src/base.producer.ts"],"names":[],"mappings":";;;;;;AACA,qDAA6B;AAC7B,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|
}
|
|
14
|
-
export interface KafkaProducer<
|
|
15
|
-
publish(payload:
|
|
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
|
|
3
|
+
"version": "3.1.0-next.0",
|
|
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.0",
|
|
18
|
-
"@rsdk/core": "^3.0
|
|
19
|
-
"@rsdk/kafka.common": "^3.0
|
|
20
|
-
"@rsdk/logging": "^3.0.0",
|
|
17
|
+
"@rsdk/common": "^3.1.0-next.0",
|
|
18
|
+
"@rsdk/core": "^3.1.0-next.0",
|
|
19
|
+
"@rsdk/kafka.common": "^3.1.0-next.0",
|
|
20
|
+
"@rsdk/logging": "^3.1.0-next.0",
|
|
21
21
|
"lodash": "^4.17.21"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "55598931db264fb6d5b5c4787c48298ed86bbc0d"
|
|
24
24
|
}
|
package/src/base.producer.ts
CHANGED
|
@@ -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<
|
|
8
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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<
|
|
19
|
-
publish(payload:
|
|
18
|
+
export interface KafkaProducer<P> {
|
|
19
|
+
publish(payload: P, options?: PublishOptions | undefined): Promise<void>;
|
|
20
20
|
}
|