UNPKG

trade360-nodejs-sdk

Version:
66 lines 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BodyHandler = void 0; const lodash_1 = require("lodash"); const _utilities_1 = require("../../../../utilities"); /** * Class that represent the body handler of an * entity message structure to process the body * property of an entity and handle the entity * type with the entityHandler call-back function * for the entityConstructor class type entity type * and process them with the entityHandler call-back * function for the entityConstructor class type * entity type and check message consumption latency * and log warning if it exceeds the threshold value * in seconds or log info if it's within the threshold * value in seconds * @implements IBodyHandler interface that represent * the body handler of an entity message structure to * process the body property of an entity * @param TEntity entity type for the entityConstructor * class type entity type to be used in the body handler * class * @param entityHandler entity handler to be used in the * body handler class to handle the entity type with the * entityHandler call-back function for the entityConstructor * class type entity type * @param entityConstructor entity constructor class type * to be used in the body handler class to handle the entity * type with the entityHandler call-back function for the * entityConstructor class type entity type * @param logger logger instance to be used in the body * handler class to log the warning and info messages * for the message consumption latency */ class BodyHandler { constructor(entityHandler, entityConstructor, logger) { this.entityHandler = entityHandler; this.entityConstructor = entityConstructor; this.logger = logger; } /** * process the inner procedure for the body property of an * entity message structure to handle the entity type with * the entityHandler call-back function for the entityConstructor * class type entity type and process them with the entityHandler * call-back function for the entityConstructor class type entity * type * @param messageStructure object that contains the message * structure with header and body to be processed by the body * handler class to handle */ async processAsync({ header, body, transportHeaders, }) { try { const entity = !(0, lodash_1.isNil)(body) ? _utilities_1.TransformerUtil.transform(body, this.entityConstructor) : undefined; return await this.entityHandler.processAsync({ header, entity, transportHeaders }); } catch (err) { this.logger?.warn(`Failed to deserialize ${typeof this.entityConstructor} entity, Due to: ${err}`); } } } exports.BodyHandler = BodyHandler; //# sourceMappingURL=body-handler.js.map