UNPKG

@vtexlab/planner-contracts

Version:

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

29 lines (28 loc) 868 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Context = Context; exports.Type = Type; exports.getMessageContext = getMessageContext; exports.getMessageType = getMessageType; const contextMap = new WeakMap(); const typeMap = new WeakMap(); function Context(name) { return (target) => { contextMap.set(target, name); return target; }; } function Type(type) { return (target) => { typeMap.set(target, type); return target; }; } function getMessageContext(target) { const constructor = typeof target === 'function' ? target : target.constructor; return contextMap.get(constructor) || 'mgmt-default'; } function getMessageType(target) { const constructor = typeof target === 'function' ? target : target.constructor; return typeMap.get(constructor) || 'mgmt-default'; }