@rsdk/kafka.common 5.4.0-next.0 → 5.4.0-next.2
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 +10 -0
- package/dist/client/kafka.metadata.d.ts +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.js +5 -9
- package/dist/index.js.map +1 -1
- package/dist/kafka-producer-plugin.d.ts +10 -0
- package/dist/kafka-producer-plugin.js +18 -0
- package/dist/kafka-producer-plugin.js.map +1 -0
- package/dist/options/di.d.ts +1 -0
- package/dist/options/di.js +5 -0
- package/dist/options/di.js.map +1 -0
- package/dist/options/index.d.ts +3 -0
- package/dist/options/index.js +20 -0
- package/dist/options/index.js.map +1 -0
- package/dist/options/kafka-producer-options.d.ts +4 -0
- package/dist/options/kafka-producer-options.js +3 -0
- package/dist/options/kafka-producer-options.js.map +1 -0
- package/dist/options/kafka-producer-options.module.d.ts +5 -0
- package/dist/options/kafka-producer-options.module.js +31 -0
- package/dist/options/kafka-producer-options.module.js.map +1 -0
- package/dist/utils/get-topic-name.fn.d.ts +5 -0
- package/dist/utils/get-topic-name.fn.js +11 -0
- package/dist/utils/get-topic-name.fn.js.map +1 -0
- package/package.json +3 -2
- package/src/client/kafka.metadata.ts +1 -1
- package/src/index.ts +3 -10
- package/src/kafka-producer-plugin.ts +18 -0
- package/src/options/di.ts +1 -0
- package/src/options/index.ts +3 -0
- package/src/options/kafka-producer-options.module.ts +22 -0
- package/src/options/kafka-producer-options.ts +5 -0
- package/src/utils/get-topic-name.fn.ts +8 -0
- package/dist/event.type.d.ts +0 -23
- package/dist/event.type.js +0 -18
- package/dist/event.type.js.map +0 -1
- package/dist/exceptions/payload-format.exception.d.ts +0 -5
- package/dist/exceptions/payload-format.exception.js +0 -11
- package/dist/exceptions/payload-format.exception.js.map +0 -1
- package/dist/payload-format.d.ts +0 -27
- package/dist/payload-format.js +0 -42
- package/dist/payload-format.js.map +0 -1
- package/dist/utils/event.codec.d.ts +0 -21
- package/dist/utils/event.codec.js +0 -32
- package/dist/utils/event.codec.js.map +0 -1
- package/src/event.type.ts +0 -35
- package/src/exceptions/payload-format.exception.ts +0 -10
- package/src/payload-format.ts +0 -46
- package/src/utils/event.codec.ts +0 -35
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
|
+
## [5.4.0-next.2](https://github.com/R-Vision/rsdk/compare/v5.4.0-next.1...v5.4.0-next.2) (2024-11-25)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **nats:** nats transport/kv/os + examples + docs ([#306](https://github.com/R-Vision/rsdk/issues/306)) ([de67eed](https://github.com/R-Vision/rsdk/commit/de67eed8b4cb17ec9d359067eae1e0c35d6cc736))
|
|
11
|
+
|
|
12
|
+
## [5.4.0-next.1](https://github.com/R-Vision/rsdk/compare/v5.4.0-next.0...v5.4.0-next.1) (2024-11-08)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rsdk/kafka.common
|
|
15
|
+
|
|
6
16
|
## [5.4.0-next.0](https://github.com/R-Vision/rsdk/compare/v5.3.0...v5.4.0-next.0) (2024-11-08)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rsdk/kafka.common
|
package/dist/index.d.ts
CHANGED
|
@@ -3,16 +3,14 @@ export { InjectKafka } from './client/decorators/inject-kafka.decorator';
|
|
|
3
3
|
export { InjectKafkaProducer } from './client/decorators/inject-producer.decorator';
|
|
4
4
|
export { KAFKA_PRODUCER_INJECTION_TOKEN, KAFKA_CLIENT_INJECTION_TOKEN, } from './client/constants';
|
|
5
5
|
export { INFINITE_RETRIES } from './utils/retry-policy.infinite';
|
|
6
|
-
export { EventPayload } from './event.type';
|
|
7
|
-
export { ProtoEventCodec, EventCodec, JSONEventCodec, } from './utils/event.codec';
|
|
8
6
|
export { KafkaClientModule } from './client/kafka-client.module';
|
|
9
7
|
export { KafkaConfig } from './client/kafka.config';
|
|
10
8
|
export { TopicsService } from './client/providers/topics.service';
|
|
11
9
|
export { KAFKA_TOPIC_RSDK_METADATA_SCOPE, KafkaTopicMetadata, TopicType, } from './client/kafka.metadata';
|
|
12
10
|
export { handleKafkaError } from './utils/handle-kafka.error.fn';
|
|
13
11
|
export { createLoggerAdapter } from './utils/create-logger-adapter.fn';
|
|
14
|
-
export { getTopicName
|
|
12
|
+
export { getTopicName } from './utils/get-topic-name.fn';
|
|
15
13
|
export { KafkaBaseIndicator } from './client/kafka.base-indicator';
|
|
16
|
-
export * from './payload-format';
|
|
17
|
-
export * from './exceptions/payload-format.exception';
|
|
18
14
|
export * from './exceptions/missing-topics.exception';
|
|
15
|
+
export * from './options';
|
|
16
|
+
export * from './kafka-producer-plugin';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.KafkaBaseIndicator = exports.
|
|
17
|
+
exports.KafkaBaseIndicator = exports.getTopicName = exports.createLoggerAdapter = exports.handleKafkaError = exports.TopicType = exports.KAFKA_TOPIC_RSDK_METADATA_SCOPE = exports.TopicsService = exports.KafkaConfig = exports.KafkaClientModule = exports.INFINITE_RETRIES = exports.KAFKA_CLIENT_INJECTION_TOKEN = exports.KAFKA_PRODUCER_INJECTION_TOKEN = exports.InjectKafkaProducer = exports.InjectKafka = void 0;
|
|
18
18
|
var inject_kafka_decorator_1 = require("./client/decorators/inject-kafka.decorator");
|
|
19
19
|
Object.defineProperty(exports, "InjectKafka", { enumerable: true, get: function () { return inject_kafka_decorator_1.InjectKafka; } });
|
|
20
20
|
var inject_producer_decorator_1 = require("./client/decorators/inject-producer.decorator");
|
|
@@ -24,9 +24,6 @@ Object.defineProperty(exports, "KAFKA_PRODUCER_INJECTION_TOKEN", { enumerable: t
|
|
|
24
24
|
Object.defineProperty(exports, "KAFKA_CLIENT_INJECTION_TOKEN", { enumerable: true, get: function () { return constants_1.KAFKA_CLIENT_INJECTION_TOKEN; } });
|
|
25
25
|
var retry_policy_infinite_1 = require("./utils/retry-policy.infinite");
|
|
26
26
|
Object.defineProperty(exports, "INFINITE_RETRIES", { enumerable: true, get: function () { return retry_policy_infinite_1.INFINITE_RETRIES; } });
|
|
27
|
-
var event_codec_1 = require("./utils/event.codec");
|
|
28
|
-
Object.defineProperty(exports, "ProtoEventCodec", { enumerable: true, get: function () { return event_codec_1.ProtoEventCodec; } });
|
|
29
|
-
Object.defineProperty(exports, "JSONEventCodec", { enumerable: true, get: function () { return event_codec_1.JSONEventCodec; } });
|
|
30
27
|
var kafka_client_module_1 = require("./client/kafka-client.module");
|
|
31
28
|
Object.defineProperty(exports, "KafkaClientModule", { enumerable: true, get: function () { return kafka_client_module_1.KafkaClientModule; } });
|
|
32
29
|
var kafka_config_1 = require("./client/kafka.config");
|
|
@@ -40,12 +37,11 @@ var handle_kafka_error_fn_1 = require("./utils/handle-kafka.error.fn");
|
|
|
40
37
|
Object.defineProperty(exports, "handleKafkaError", { enumerable: true, get: function () { return handle_kafka_error_fn_1.handleKafkaError; } });
|
|
41
38
|
var create_logger_adapter_fn_1 = require("./utils/create-logger-adapter.fn");
|
|
42
39
|
Object.defineProperty(exports, "createLoggerAdapter", { enumerable: true, get: function () { return create_logger_adapter_fn_1.createLoggerAdapter; } });
|
|
43
|
-
var
|
|
44
|
-
Object.defineProperty(exports, "getTopicName", { enumerable: true, get: function () { return
|
|
45
|
-
Object.defineProperty(exports, "isEventType", { enumerable: true, get: function () { return event_type_1.isEventType; } });
|
|
40
|
+
var get_topic_name_fn_1 = require("./utils/get-topic-name.fn");
|
|
41
|
+
Object.defineProperty(exports, "getTopicName", { enumerable: true, get: function () { return get_topic_name_fn_1.getTopicName; } });
|
|
46
42
|
var kafka_base_indicator_1 = require("./client/kafka.base-indicator");
|
|
47
43
|
Object.defineProperty(exports, "KafkaBaseIndicator", { enumerable: true, get: function () { return kafka_base_indicator_1.KafkaBaseIndicator; } });
|
|
48
|
-
__exportStar(require("./payload-format"), exports);
|
|
49
|
-
__exportStar(require("./exceptions/payload-format.exception"), exports);
|
|
50
44
|
__exportStar(require("./exceptions/missing-topics.exception"), exports);
|
|
45
|
+
__exportStar(require("./options"), exports);
|
|
46
|
+
__exportStar(require("./kafka-producer-plugin"), exports);
|
|
51
47
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,qFAAyE;AAAhE,qHAAA,WAAW,OAAA;AACpB,2FAAoF;AAA3E,gIAAA,mBAAmB,OAAA;AAC5B,gDAG4B;AAF1B,2HAAA,8BAA8B,OAAA;AAC9B,yHAAA,4BAA4B,OAAA;AAE9B,uEAAiE;AAAxD,yHAAA,gBAAgB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,qFAAyE;AAAhE,qHAAA,WAAW,OAAA;AACpB,2FAAoF;AAA3E,gIAAA,mBAAmB,OAAA;AAC5B,gDAG4B;AAF1B,2HAAA,8BAA8B,OAAA;AAC9B,yHAAA,4BAA4B,OAAA;AAE9B,uEAAiE;AAAxD,yHAAA,gBAAgB,OAAA;AAEzB,oEAAiE;AAAxD,wHAAA,iBAAiB,OAAA;AAE1B,sDAAoD;AAA3C,2GAAA,WAAW,OAAA;AAEpB,oEAAkE;AAAzD,+GAAA,aAAa,OAAA;AACtB,0DAIiC;AAH/B,iIAAA,+BAA+B,OAAA;AAE/B,2GAAA,SAAS,OAAA;AAGX,uEAAiE;AAAxD,yHAAA,gBAAgB,OAAA;AAEzB,6EAAuE;AAA9D,+HAAA,mBAAmB,OAAA;AAE5B,+DAAyD;AAAhD,iHAAA,YAAY,OAAA;AAErB,sEAAmE;AAA1D,0HAAA,kBAAkB,OAAA;AAE3B,wEAAsD;AACtD,4CAA0B;AAC1B,0DAAwC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import type { Constructor } from '@rsdk/common';
|
|
3
|
+
import type { AppropriateTransports, PlatformAppPlugin } from '@rsdk/core';
|
|
4
|
+
import type { KafkaProducerOptions } from './options/kafka-producer-options';
|
|
5
|
+
export declare class KafkaProducerPlugin implements PlatformAppPlugin {
|
|
6
|
+
private readonly options?;
|
|
7
|
+
constructor(options?: KafkaProducerOptions | undefined);
|
|
8
|
+
forTransports(): AppropriateTransports;
|
|
9
|
+
modules(): (DynamicModule | Constructor)[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KafkaProducerPlugin = void 0;
|
|
4
|
+
const kafka_producer_options_module_1 = require("./options/kafka-producer-options.module");
|
|
5
|
+
class KafkaProducerPlugin {
|
|
6
|
+
options;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
forTransports() {
|
|
11
|
+
return 'any';
|
|
12
|
+
}
|
|
13
|
+
modules() {
|
|
14
|
+
return [kafka_producer_options_module_1.KafkaProducerOptionsModule.forRoot(this.options || {})];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.KafkaProducerPlugin = KafkaProducerPlugin;
|
|
18
|
+
//# sourceMappingURL=kafka-producer-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kafka-producer-plugin.js","sourceRoot":"","sources":["../src/kafka-producer-plugin.ts"],"names":[],"mappings":";;;AAKA,2FAAqF;AAErF,MAAa,mBAAmB;IACD;IAA7B,YAA6B,OAA8B;QAA9B,YAAO,GAAP,OAAO,CAAuB;IAAG,CAAC;IAE/D,aAAa;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,OAAO,CAAC,0DAA0B,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;CACF;AAVD,kDAUC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const KAFKA_PRODUCER_OPTIONS: unique symbol;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"di.js","sourceRoot":"","sources":["../../src/options/di.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./kafka-producer-options"), exports);
|
|
18
|
+
__exportStar(require("./di"), exports);
|
|
19
|
+
__exportStar(require("./kafka-producer-options.module"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/options/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,uCAAqB;AACrB,kEAAgD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kafka-producer-options.js","sourceRoot":"","sources":["../../src/options/kafka-producer-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
var KafkaProducerOptionsModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.KafkaProducerOptionsModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const di_1 = require("./di");
|
|
13
|
+
let KafkaProducerOptionsModule = KafkaProducerOptionsModule_1 = class KafkaProducerOptionsModule {
|
|
14
|
+
static forRoot(options) {
|
|
15
|
+
const optionsProvider = {
|
|
16
|
+
provide: di_1.KAFKA_PRODUCER_OPTIONS,
|
|
17
|
+
useValue: options,
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
global: true,
|
|
21
|
+
module: KafkaProducerOptionsModule_1,
|
|
22
|
+
providers: [optionsProvider],
|
|
23
|
+
exports: [optionsProvider],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.KafkaProducerOptionsModule = KafkaProducerOptionsModule;
|
|
28
|
+
exports.KafkaProducerOptionsModule = KafkaProducerOptionsModule = KafkaProducerOptionsModule_1 = __decorate([
|
|
29
|
+
(0, common_1.Module)({})
|
|
30
|
+
], KafkaProducerOptionsModule);
|
|
31
|
+
//# sourceMappingURL=kafka-producer-options.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kafka-producer-options.module.js","sourceRoot":"","sources":["../../src/options/kafka-producer-options.module.ts"],"names":[],"mappings":";;;;;;;;;;AACA,2CAAwC;AAExC,6BAA8C;AAIvC,IAAM,0BAA0B,kCAAhC,MAAM,0BAA0B;IACrC,MAAM,CAAC,OAAO,CAAC,OAA6B;QAC1C,MAAM,eAAe,GAAG;YACtB,OAAO,EAAE,2BAAsB;YAC/B,QAAQ,EAAE,OAAO;SAClB,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,4BAA0B;YAClC,SAAS,EAAE,CAAC,eAAe,CAAC;YAC5B,OAAO,EAAE,CAAC,eAAe,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF,CAAA;AAdY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,0BAA0B,CActC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTopicName = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Генерирует имя топика из EventType
|
|
6
|
+
*/
|
|
7
|
+
const getTopicName = (eventType) => {
|
|
8
|
+
return `events.${eventType.$group}`;
|
|
9
|
+
};
|
|
10
|
+
exports.getTopicName = getTopicName;
|
|
11
|
+
//# sourceMappingURL=get-topic-name.fn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-topic-name.fn.js","sourceRoot":"","sources":["../../src/utils/get-topic-name.fn.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACI,MAAM,YAAY,GAAG,CAAC,SAAoB,EAAU,EAAE;IAC3D,OAAO,UAAU,SAAS,CAAC,MAAM,EAAE,CAAC;AACtC,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/kafka.common",
|
|
3
|
-
"version": "5.4.0-next.
|
|
3
|
+
"version": "5.4.0-next.2",
|
|
4
4
|
"description": "Common functionality for kafka consumers and producers",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"@nestjs/microservices": "^10.0.0",
|
|
17
17
|
"@rsdk/common": "*",
|
|
18
18
|
"@rsdk/core": "*",
|
|
19
|
+
"@rsdk/events.common": "*",
|
|
19
20
|
"@rsdk/logging": "*",
|
|
20
21
|
"@rsdk/metadata": "*",
|
|
21
22
|
"kafkajs": "^2.2.4",
|
|
@@ -26,5 +27,5 @@
|
|
|
26
27
|
"lodash": "^4.17.21",
|
|
27
28
|
"protobufjs": "^7.2.3"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "be4deac03b38b3f923a08116e1dc2b55838905b0"
|
|
30
31
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,13 +7,6 @@ export {
|
|
|
7
7
|
KAFKA_CLIENT_INJECTION_TOKEN,
|
|
8
8
|
} from './client/constants';
|
|
9
9
|
export { INFINITE_RETRIES } from './utils/retry-policy.infinite';
|
|
10
|
-
export { EventPayload } from './event.type';
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
ProtoEventCodec,
|
|
14
|
-
EventCodec,
|
|
15
|
-
JSONEventCodec,
|
|
16
|
-
} from './utils/event.codec';
|
|
17
10
|
|
|
18
11
|
export { KafkaClientModule } from './client/kafka-client.module';
|
|
19
12
|
|
|
@@ -30,10 +23,10 @@ export { handleKafkaError } from './utils/handle-kafka.error.fn';
|
|
|
30
23
|
|
|
31
24
|
export { createLoggerAdapter } from './utils/create-logger-adapter.fn';
|
|
32
25
|
|
|
33
|
-
export { getTopicName
|
|
26
|
+
export { getTopicName } from './utils/get-topic-name.fn';
|
|
34
27
|
|
|
35
28
|
export { KafkaBaseIndicator } from './client/kafka.base-indicator';
|
|
36
29
|
|
|
37
|
-
export * from './payload-format';
|
|
38
|
-
export * from './exceptions/payload-format.exception';
|
|
39
30
|
export * from './exceptions/missing-topics.exception';
|
|
31
|
+
export * from './options';
|
|
32
|
+
export * from './kafka-producer-plugin';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import type { Constructor } from '@rsdk/common';
|
|
3
|
+
import type { AppropriateTransports, PlatformAppPlugin } from '@rsdk/core';
|
|
4
|
+
|
|
5
|
+
import type { KafkaProducerOptions } from './options/kafka-producer-options';
|
|
6
|
+
import { KafkaProducerOptionsModule } from './options/kafka-producer-options.module';
|
|
7
|
+
|
|
8
|
+
export class KafkaProducerPlugin implements PlatformAppPlugin {
|
|
9
|
+
constructor(private readonly options?: KafkaProducerOptions) {}
|
|
10
|
+
|
|
11
|
+
forTransports(): AppropriateTransports {
|
|
12
|
+
return 'any';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
modules(): (DynamicModule | Constructor)[] {
|
|
16
|
+
return [KafkaProducerOptionsModule.forRoot(this.options || {})];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const KAFKA_PRODUCER_OPTIONS = Symbol('KAFKA_PRODUCER_OPTIONS');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { Module } from '@nestjs/common';
|
|
3
|
+
|
|
4
|
+
import { KAFKA_PRODUCER_OPTIONS } from './di';
|
|
5
|
+
import type { KafkaProducerOptions } from './kafka-producer-options';
|
|
6
|
+
|
|
7
|
+
@Module({})
|
|
8
|
+
export class KafkaProducerOptionsModule {
|
|
9
|
+
static forRoot(options: KafkaProducerOptions): DynamicModule {
|
|
10
|
+
const optionsProvider = {
|
|
11
|
+
provide: KAFKA_PRODUCER_OPTIONS,
|
|
12
|
+
useValue: options,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
global: true,
|
|
17
|
+
module: KafkaProducerOptionsModule,
|
|
18
|
+
providers: [optionsProvider],
|
|
19
|
+
exports: [optionsProvider],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/event.type.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Reader, Writer } from 'protobufjs/minimal';
|
|
2
|
-
/**
|
|
3
|
-
* Генерируется при компиляции proto-файлов
|
|
4
|
-
*/
|
|
5
|
-
export interface EventType<T = any> {
|
|
6
|
-
$group: string;
|
|
7
|
-
$partitionKeyField: string | null;
|
|
8
|
-
$type: string;
|
|
9
|
-
encode(message: T): Writer;
|
|
10
|
-
decode(data: Uint8Array | Reader): T;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Выводит тип payload из EventType
|
|
14
|
-
*/
|
|
15
|
-
export type EventPayload<E extends EventType> = E extends EventType<infer P> ? P : never;
|
|
16
|
-
/**
|
|
17
|
-
* Проверяет, является ли переданный тип EventType
|
|
18
|
-
*/
|
|
19
|
-
export declare const isEventType: <T = any>(x: any) => x is EventType<T>;
|
|
20
|
-
/**
|
|
21
|
-
* Генерирует имя топика из EventType
|
|
22
|
-
*/
|
|
23
|
-
export declare const getTopicName: (eventType: EventType) => string;
|
package/dist/event.type.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTopicName = exports.isEventType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Проверяет, является ли переданный тип EventType
|
|
6
|
-
*/
|
|
7
|
-
const isEventType = (x) => typeof x === 'object' &&
|
|
8
|
-
typeof x.$type === 'string' &&
|
|
9
|
-
typeof x.$group === 'string';
|
|
10
|
-
exports.isEventType = isEventType;
|
|
11
|
-
/**
|
|
12
|
-
* Генерирует имя топика из EventType
|
|
13
|
-
*/
|
|
14
|
-
const getTopicName = (eventType) => {
|
|
15
|
-
return `events.${eventType.$group}`;
|
|
16
|
-
};
|
|
17
|
-
exports.getTopicName = getTopicName;
|
|
18
|
-
//# sourceMappingURL=event.type.js.map
|
package/dist/event.type.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event.type.js","sourceRoot":"","sources":["../src/event.type.ts"],"names":[],"mappings":";;;AAqBA;;GAEG;AACI,MAAM,WAAW,GAAG,CAAU,CAAM,EAAqB,EAAE,CAChE,OAAO,CAAC,KAAK,QAAQ;IACrB,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;IAC3B,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC;AAHlB,QAAA,WAAW,eAGO;AAE/B;;GAEG;AACI,MAAM,YAAY,GAAG,CAAC,SAAoB,EAAU,EAAE;IAC3D,OAAO,UAAU,SAAS,CAAC,MAAM,EAAE,CAAC;AACtC,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PayloadFormatException = void 0;
|
|
4
|
-
const core_1 = require("@rsdk/core");
|
|
5
|
-
class PayloadFormatException extends core_1.BootstrapException {
|
|
6
|
-
constructor(value, allowed) {
|
|
7
|
-
super(`PayloadFormat has wrong value: ${value}, allowed: ${allowed.join(',')}`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.PayloadFormatException = PayloadFormatException;
|
|
11
|
-
//# sourceMappingURL=payload-format.exception.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payload-format.exception.js","sourceRoot":"","sources":["../../src/exceptions/payload-format.exception.ts"],"names":[],"mappings":";;;AACA,qCAAgD;AAEhD,MAAa,sBAAuB,SAAQ,yBAAkB;IAC5D,YAAY,KAAa,EAAE,OAAoB;QAC7C,KAAK,CACH,kCAAkC,KAAK,cAAc,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CACzE,CAAC;IACJ,CAAC;CACF;AAND,wDAMC"}
|
package/dist/payload-format.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Способ сериализации данных события
|
|
3
|
-
*/
|
|
4
|
-
export declare enum PayloadFormat {
|
|
5
|
-
PROTOBUF = "protobuf",
|
|
6
|
-
JSON = "json"
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Проверяет, является ли переданная строка - одним
|
|
10
|
-
* из значений перечисления PayloadFormat
|
|
11
|
-
*/
|
|
12
|
-
export declare const isPayloadFormat: (value: string) => value is PayloadFormat;
|
|
13
|
-
/**
|
|
14
|
-
* Проверяет, является ли переданная строка - одним
|
|
15
|
-
* из значений перечисления PayloadFormat. В случае,
|
|
16
|
-
* если передано неверное значение - бросает ошибку
|
|
17
|
-
*/
|
|
18
|
-
export declare const assertIsPayloadFormat: (value: string) => asserts value is PayloadFormat;
|
|
19
|
-
/**
|
|
20
|
-
* Заголовок в kafka, через который передаётся способ
|
|
21
|
-
* сериализации
|
|
22
|
-
*/
|
|
23
|
-
export declare const X_FORMAT_HEADER = "X-Format";
|
|
24
|
-
/**
|
|
25
|
-
* Сериализация по умолчанию (protobuf)
|
|
26
|
-
*/
|
|
27
|
-
export declare const DEFAULT_PAYLOAD_FORMAT = PayloadFormat.PROTOBUF;
|
package/dist/payload-format.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_PAYLOAD_FORMAT = exports.X_FORMAT_HEADER = exports.assertIsPayloadFormat = exports.isPayloadFormat = exports.PayloadFormat = void 0;
|
|
4
|
-
const common_1 = require("@rsdk/common");
|
|
5
|
-
const payload_format_exception_1 = require("./exceptions/payload-format.exception");
|
|
6
|
-
/**
|
|
7
|
-
* Способ сериализации данных события
|
|
8
|
-
*/
|
|
9
|
-
var PayloadFormat;
|
|
10
|
-
(function (PayloadFormat) {
|
|
11
|
-
PayloadFormat["PROTOBUF"] = "protobuf";
|
|
12
|
-
PayloadFormat["JSON"] = "json";
|
|
13
|
-
})(PayloadFormat || (exports.PayloadFormat = PayloadFormat = {}));
|
|
14
|
-
const allowed = common_1.Enum.values(PayloadFormat);
|
|
15
|
-
/**
|
|
16
|
-
* Проверяет, является ли переданная строка - одним
|
|
17
|
-
* из значений перечисления PayloadFormat
|
|
18
|
-
*/
|
|
19
|
-
const isPayloadFormat = (value) => allowed.includes(value);
|
|
20
|
-
exports.isPayloadFormat = isPayloadFormat;
|
|
21
|
-
/**
|
|
22
|
-
* Проверяет, является ли переданная строка - одним
|
|
23
|
-
* из значений перечисления PayloadFormat. В случае,
|
|
24
|
-
* если передано неверное значение - бросает ошибку
|
|
25
|
-
*/
|
|
26
|
-
const assertIsPayloadFormat = (value) => {
|
|
27
|
-
if ((0, exports.isPayloadFormat)(value)) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
throw new payload_format_exception_1.PayloadFormatException(value, allowed);
|
|
31
|
-
};
|
|
32
|
-
exports.assertIsPayloadFormat = assertIsPayloadFormat;
|
|
33
|
-
/**
|
|
34
|
-
* Заголовок в kafka, через который передаётся способ
|
|
35
|
-
* сериализации
|
|
36
|
-
*/
|
|
37
|
-
exports.X_FORMAT_HEADER = 'X-Format';
|
|
38
|
-
/**
|
|
39
|
-
* Сериализация по умолчанию (protobuf)
|
|
40
|
-
*/
|
|
41
|
-
exports.DEFAULT_PAYLOAD_FORMAT = PayloadFormat.PROTOBUF;
|
|
42
|
-
//# sourceMappingURL=payload-format.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payload-format.js","sourceRoot":"","sources":["../src/payload-format.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAEpC,oFAA+E;AAE/E;;GAEG;AACH,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,8BAAa,CAAA;AACf,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAED,MAAM,OAAO,GAAG,aAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAE3C;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAC,KAAa,EAA0B,EAAE,CACvE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AADb,QAAA,eAAe,mBACF;AAE1B;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CACnC,KAAa,EACmB,EAAE;IAClC,IAAI,IAAA,uBAAe,EAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO;IACT,CAAC;IAED,MAAM,IAAI,iDAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC,CAAC;AARW,QAAA,qBAAqB,yBAQhC;AAEF;;;GAGG;AACU,QAAA,eAAe,GAAG,UAAU,CAAC;AAE1C;;GAEG;AACU,QAAA,sBAAsB,GAAG,aAAa,CAAC,QAAQ,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { EventPayload, EventType } from '../event.type';
|
|
2
|
-
export interface EventCodec<E extends EventType> {
|
|
3
|
-
decode<P extends EventPayload<E> = EventPayload<E>>(buffer: Buffer): P;
|
|
4
|
-
encode<P extends EventPayload<E> = EventPayload<E>>(payload: P): Buffer;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Protobuf-encoding strategy
|
|
8
|
-
*/
|
|
9
|
-
export declare class ProtoEventCodec<E extends EventType> implements EventCodec<E> {
|
|
10
|
-
readonly eventType: E;
|
|
11
|
-
constructor(eventType: E);
|
|
12
|
-
decode<P extends EventPayload<E>>(buffer: Buffer): P;
|
|
13
|
-
encode<P extends EventPayload<E>>(payload: P): Buffer;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* JSON-encoding strategy
|
|
17
|
-
*/
|
|
18
|
-
export declare class JSONEventCodec<E extends EventType> implements EventCodec<E> {
|
|
19
|
-
decode<P extends EventPayload<E>>(buffer: Buffer): P;
|
|
20
|
-
encode<P extends EventPayload<E>>(payload: P): Buffer;
|
|
21
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSONEventCodec = exports.ProtoEventCodec = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Protobuf-encoding strategy
|
|
6
|
-
*/
|
|
7
|
-
class ProtoEventCodec {
|
|
8
|
-
eventType;
|
|
9
|
-
constructor(eventType) {
|
|
10
|
-
this.eventType = eventType;
|
|
11
|
-
}
|
|
12
|
-
decode(buffer) {
|
|
13
|
-
return this.eventType.decode(buffer);
|
|
14
|
-
}
|
|
15
|
-
encode(payload) {
|
|
16
|
-
return Buffer.from(this.eventType.encode(payload).finish());
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.ProtoEventCodec = ProtoEventCodec;
|
|
20
|
-
/**
|
|
21
|
-
* JSON-encoding strategy
|
|
22
|
-
*/
|
|
23
|
-
class JSONEventCodec {
|
|
24
|
-
decode(buffer) {
|
|
25
|
-
return JSON.parse(buffer.toString());
|
|
26
|
-
}
|
|
27
|
-
encode(payload) {
|
|
28
|
-
return Buffer.from(JSON.stringify(payload));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.JSONEventCodec = JSONEventCodec;
|
|
32
|
-
//# sourceMappingURL=event.codec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event.codec.js","sourceRoot":"","sources":["../../src/utils/event.codec.ts"],"names":[],"mappings":";;;AAQA;;GAEG;AACH,MAAa,eAAe;IACL;IAArB,YAAqB,SAAY;QAAZ,cAAS,GAAT,SAAS,CAAG;IAAG,CAAC;IAErC,MAAM,CAA4B,MAAc;QAC9C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAA4B,OAAU;QAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF;AAVD,0CAUC;AAED;;GAEG;AACH,MAAa,cAAc;IACzB,MAAM,CAA4B,MAAc;QAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAA4B,OAAU;QAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9C,CAAC;CACF;AARD,wCAQC"}
|
package/src/event.type.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Reader, Writer } from 'protobufjs/minimal';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Генерируется при компиляции proto-файлов
|
|
5
|
-
*/
|
|
6
|
-
export interface EventType<T = any> {
|
|
7
|
-
$group: string;
|
|
8
|
-
$partitionKeyField: string | null;
|
|
9
|
-
$type: string;
|
|
10
|
-
|
|
11
|
-
encode(message: T): Writer;
|
|
12
|
-
|
|
13
|
-
decode(data: Uint8Array | Reader): T;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Выводит тип payload из EventType
|
|
18
|
-
*/
|
|
19
|
-
export type EventPayload<E extends EventType> =
|
|
20
|
-
E extends EventType<infer P> ? P : never;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Проверяет, является ли переданный тип EventType
|
|
24
|
-
*/
|
|
25
|
-
export const isEventType = <T = any>(x: any): x is EventType<T> =>
|
|
26
|
-
typeof x === 'object' &&
|
|
27
|
-
typeof x.$type === 'string' &&
|
|
28
|
-
typeof x.$group === 'string';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Генерирует имя топика из EventType
|
|
32
|
-
*/
|
|
33
|
-
export const getTopicName = (eventType: EventType): string => {
|
|
34
|
-
return `events.${eventType.$group}`;
|
|
35
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { EnumValue } from '@rsdk/common';
|
|
2
|
-
import { BootstrapException } from '@rsdk/core';
|
|
3
|
-
|
|
4
|
-
export class PayloadFormatException extends BootstrapException {
|
|
5
|
-
constructor(value: string, allowed: EnumValue[]) {
|
|
6
|
-
super(
|
|
7
|
-
`PayloadFormat has wrong value: ${value}, allowed: ${allowed.join(',')}`,
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
}
|
package/src/payload-format.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Enum } from '@rsdk/common';
|
|
2
|
-
|
|
3
|
-
import { PayloadFormatException } from './exceptions/payload-format.exception';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Способ сериализации данных события
|
|
7
|
-
*/
|
|
8
|
-
export enum PayloadFormat {
|
|
9
|
-
PROTOBUF = 'protobuf',
|
|
10
|
-
JSON = 'json',
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const allowed = Enum.values(PayloadFormat);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Проверяет, является ли переданная строка - одним
|
|
17
|
-
* из значений перечисления PayloadFormat
|
|
18
|
-
*/
|
|
19
|
-
export const isPayloadFormat = (value: string): value is PayloadFormat =>
|
|
20
|
-
allowed.includes(value);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Проверяет, является ли переданная строка - одним
|
|
24
|
-
* из значений перечисления PayloadFormat. В случае,
|
|
25
|
-
* если передано неверное значение - бросает ошибку
|
|
26
|
-
*/
|
|
27
|
-
export const assertIsPayloadFormat = (
|
|
28
|
-
value: string,
|
|
29
|
-
): asserts value is PayloadFormat => {
|
|
30
|
-
if (isPayloadFormat(value)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
throw new PayloadFormatException(value, allowed);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Заголовок в kafka, через который передаётся способ
|
|
39
|
-
* сериализации
|
|
40
|
-
*/
|
|
41
|
-
export const X_FORMAT_HEADER = 'X-Format';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Сериализация по умолчанию (protobuf)
|
|
45
|
-
*/
|
|
46
|
-
export const DEFAULT_PAYLOAD_FORMAT = PayloadFormat.PROTOBUF;
|
package/src/utils/event.codec.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { EventPayload, EventType } from '../event.type';
|
|
2
|
-
|
|
3
|
-
export interface EventCodec<E extends EventType> {
|
|
4
|
-
decode<P extends EventPayload<E> = EventPayload<E>>(buffer: Buffer): P;
|
|
5
|
-
|
|
6
|
-
encode<P extends EventPayload<E> = EventPayload<E>>(payload: P): Buffer;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Protobuf-encoding strategy
|
|
11
|
-
*/
|
|
12
|
-
export class ProtoEventCodec<E extends EventType> implements EventCodec<E> {
|
|
13
|
-
constructor(readonly eventType: E) {}
|
|
14
|
-
|
|
15
|
-
decode<P extends EventPayload<E>>(buffer: Buffer): P {
|
|
16
|
-
return this.eventType.decode(buffer);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
encode<P extends EventPayload<E>>(payload: P): Buffer {
|
|
20
|
-
return Buffer.from(this.eventType.encode(payload).finish());
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* JSON-encoding strategy
|
|
26
|
-
*/
|
|
27
|
-
export class JSONEventCodec<E extends EventType> implements EventCodec<E> {
|
|
28
|
-
decode<P extends EventPayload<E>>(buffer: Buffer): P {
|
|
29
|
-
return JSON.parse(buffer.toString());
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
encode<P extends EventPayload<E>>(payload: P): Buffer {
|
|
33
|
-
return Buffer.from(JSON.stringify(payload));
|
|
34
|
-
}
|
|
35
|
-
}
|