UNPKG

@grubou/bussy

Version:

Command & query bus implementations

31 lines 997 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoggingQueryBusMiddleware = void 0; class LoggingQueryBusMiddleware { constructor(logger, next) { this.logger = logger; this.next = next; } static build(logger) { return { chainWith(next) { return new LoggingQueryBusMiddleware(logger, next); } }; } async handle(query) { const queryName = query.label(); this.logger.info(`Executing query ${queryName}`, { query }); try { const result = await this.next.handle(query); this.logger.info(`Success on query ${queryName}`, { query }); return result; } catch (error) { this.logger.error(`Error on query ${queryName}`, { error }); throw error; } } } exports.LoggingQueryBusMiddleware = LoggingQueryBusMiddleware; //# sourceMappingURL=LoggingQueryBusMiddleware.js.map