UNPKG

@vpriem/kafka-broker

Version:

Easily compose and manage your kafka resources in one place

25 lines 989 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeMessage = void 0; const types_1 = require("./types"); const BrokerError_1 = require("./BrokerError"); const decodeMessage = async (message, registry, contentTypeOverride) => { if (!message.value) return message.value; const contentType = contentTypeOverride || message.headers?.['content-type']?.toString(); if (contentType === types_1.ContentTypes.JSON) { return JSON.parse(message.value.toString()); } if (contentType === types_1.ContentTypes.SCHEMA_REGISTRY) { if (typeof registry === 'undefined') { throw new BrokerError_1.BrokerError('Registry not found'); } return (await registry.decode(message.value)); } if (contentType === types_1.ContentTypes.TEXT) { return message.value.toString(); } return message.value; }; exports.decodeMessage = decodeMessage; //# sourceMappingURL=decodeMessage.js.map