UNPKG

@vtexlab/planner-contracts

Version:

Contracts to use in an Eventual-Driven Architecture (EDA)

23 lines (22 loc) 683 B
const contextMap = new WeakMap(); const typeMap = new WeakMap(); export function Context(name) { return (target) => { contextMap.set(target, name); return target; }; } export function Type(type) { return (target) => { typeMap.set(target, type); return target; }; } export function getMessageContext(target) { const constructor = typeof target === 'function' ? target : target.constructor; return contextMap.get(constructor) || 'mgmt-default'; } export function getMessageType(target) { const constructor = typeof target === 'function' ? target : target.constructor; return typeMap.get(constructor) || 'mgmt-default'; }