'use strict' const Hemera = require('./../../packages/hemera') const nats = require('nats').connect() const hemera = new Hemera(nats, { logLevel: 'info' }) hemera.ready(() => { // assume these options come from a hemera plugin const options = { prefix: 'e', defaultType: 'order' } hemera.decorate('pub', (eventType, msg) => { if (typeof eventType === 'object') { msg = eventType; eventType = options.defaultType; } // build a topic unless provided if (!msg.topic) { msg.topic = [ options.prefix, eventType ]; // add an id and status if we have them if (msg.id) { msg.topic.push(msg.id); } if (msg.status) { msg.topic.push(msg.status); } msg.topic = msg.topic.join('.'); } // force pubsub$ msg.pubsub$ = true; // and that's a wrap! this.act(msg); }) // global namespace // topic should be e.order.abc123.created hemera.pub({ id: 'abc123', status: 'created', name: 'Test User', items: [] }); })