1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.NatsRecordSerializer = void 0;
|
4 | const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
5 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
6 | const record_builders_1 = require("../record-builders");
|
7 | let natsPackage = {};
|
8 | class NatsRecordSerializer {
|
9 | constructor() {
|
10 | natsPackage = (0, load_package_util_1.loadPackage)('nats', NatsRecordSerializer.name, () => require('nats'));
|
11 | this.jsonCodec = natsPackage.JSONCodec();
|
12 | }
|
13 | serialize(packet) {
|
14 | const natsMessage = packet?.data && (0, shared_utils_1.isObject)(packet.data) && packet.data instanceof record_builders_1.NatsRecord
|
15 | ? packet.data
|
16 | : new record_builders_1.NatsRecordBuilder(packet?.data).build();
|
17 | return {
|
18 | data: this.jsonCodec.encode({ ...packet, data: natsMessage.data }),
|
19 | headers: natsMessage.headers,
|
20 | };
|
21 | }
|
22 | }
|
23 | exports.NatsRecordSerializer = NatsRecordSerializer;
|