// ╔═══════╗╔═══════╗╔════╗╔═╗╔════╗╔═╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔════╗╔═╗ ╔═══════╗╔═══════╗╔═══════╗╔═╗ ╔═╗╔═══════╗╔═══════╗ ╔═══════╗╔═══════╗ // ║ ╔═════╝║ ╔═══╗ ║║ ╔╗ ║║ ║║ ╔╗ ║║ ║║ ╔═════╝║ ╔═════╝╚══╗ ╔══╝╚══╗ ╔══╝║ ╔═══╗ ║║ ╔╗ ║║ ║ ║ ╔═════╝║ ╔═══╗ ║║ ╔═════╝║ ║ ║ ║║ ╔═════╝║ ╔═════╝ ╚══╗ ╔══╝║ ╔═════╝ // ║ ║ ║ ║ ║ ║║ ║║ ║║ ║║ ║║ ║║ ║║ ╚═════╗║ ║ ║ ║ ║ ║ ║ ║ ║ ║║ ║║ ║║ ║╔═══════╗║ ║ ║ ╚═══╝ ║║ ║ ║ ╚═══╝ ║║ ╚═════╗║ ╚═════╗ ║ ║ ║ ╚═════╗ // ║ ║ ║ ║ ║ ║║ ║║ ║║ ║║ ║║ ║║ ║║ ╔═════╝║ ║ ║ ║ ║ ║ ║ ║ ║ ║║ ║║ ║║ ║╚═══════╝║ ║ ║ ╔═══╗ ║║ ║ ║ ╔═══╗ ║║ ╔═════╝╚═════╗ ║ ║ ║ ╚═════╗ ║ // ║ ╚═════╗║ ╚═══╝ ║║ ║║ ╚╝ ║║ ║║ ╚╝ ║║ ╚═════╗║ ╚═════╗ ║ ║ ╔══╝ ╚══╗║ ╚═══╝ ║║ ║║ ╚╝ ║ ║ ╚═════╗║ ║ ║ ║║ ╚═════╗║ ║ ║ ║║ ╚═════╗╔═════╝ ║╔═╗ ║ ║ ╔═════╝ ║ // ╚═══════╝╚═══════╝╚═╝╚════╝╚═╝╚════╝╚═══════╝╚═══════╝ ╚═╝ ╚═══════╝╚═══════╝╚═╝╚════╝ ╚═══════╝╚═╝ ╚═╝╚═══════╝╚═╝ ╚═╝╚═══════╝╚═══════╝╚═╝ ╚═╝ ╚═══════╝ // ╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗ // ╚══╗ ╔══╝║ ╔╗ ╔╗ ║║ ╔═══╗ ║║ ╔═══╗ ║║ ╔═══╗ ║╚══╗ ╔══╝║ ╔═════╝ // ║ ║ ║ ║║ ║║ ║║ ╚═══╝ ║║ ║ ║ ║║ ╚═══╝ ║ ║ ║ ║ ╚═════╗ // ║ ║ ║ ║║ ║║ ║║ ╔═════╝║ ║ ║ ║║ ╔═╗ ╔═╝ ║ ║ ╚═════╗ ║ // ╔══╝ ╚══╗║ ║║ ║║ ║║ ║ ║ ╚═══╝ ║║ ║ ║ ╚═╗ ║ ║ ╔═════╝ ║ // ╚═══════╝╚═╝╚═╝╚═╝╚═╝ ╚═══════╝╚═╝ ╚═══╝ ╚═╝ ╚═══════╝ import * as connectionValidators from '../validators/connection-validators.js'; import * as connectionClasses from '../classes/connection-classes.js'; import * as connectionErrors from '../errors/connection-errors.js'; // ╔═══════╗╔════╗╔═╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗ // ║ ╔═════╝╚══╗ ║║ ║║ ╔═══╗ ║║ ╔═══╗ ║║ ╔═══╗ ║╚══╗ ╔══╝║ ╔═════╝ // ║ ╚═════╗╔══╝ ╚╝ ║║ ╚═══╝ ║║ ║ ║ ║║ ╚═══╝ ║ ║ ║ ║ ╚═════╗ // ║ ╔═════╝║ ╔╗ ╔══╝║ ╔═════╝║ ║ ║ ║║ ╔═╗ ╔═╝ ║ ║ ╚═════╗ ║ // ║ ╚═════╗║ ║║ ╚══╗║ ║ ║ ╚═══╝ ║║ ║ ║ ╚═╗ ║ ║ ╔═════╝ ║ // ╚═══════╝╚═╝╚════╝╚═╝ ╚═══════╝╚═╝ ╚═══╝ ╚═╝ ╚═══════╝ export { getCachedConnections as getConnections, getCachedConnection as getConnection, }; // ╔═══════╗╔═══════╗╔═══════╗╔═╗ ╔═══════╗╔═══════╗╔═══════╗ // ╚╗ ╔══╗ ║║ ╔═════╝║ ╔═════╝║ ║ ║ ╔═══╗ ║║ ╔═══╗ ║║ ╔═════╝ // ║ ║ ║ ║║ ╚═════╗║ ║ ║ ║ ║ ╚═══╝ ║║ ╚═══╝ ║║ ╚═════╗ // ║ ║ ║ ║║ ╔═════╝║ ║ ║ ║ ║ ╔═══╗ ║║ ╔═╗ ╔═╝║ ╔═════╝ // ╔╝ ╚══╝ ║║ ╚═════╗║ ╚═════╗║ ╚═════╗║ ║ ║ ║║ ║ ║ ╚═╗║ ╚═════╗ // ╚═══════╝╚═══════╝╚═══════╝╚═══════╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═══════╝ const _connectionByConnectionLabel = new Map(); // ╔═══════╗╔═══════╗╔═══════╗╔═╗ ╔═╗╔═══════╗ // ║ ╔═════╝║ ╔═══╗ ║║ ╔═════╝║ ║ ║ ║║ ╔═════╝ // ║ ║ ║ ╚═══╝ ║║ ║ ║ ╚═══╝ ║║ ╚═════╗ // ║ ║ ║ ╔═══╗ ║║ ║ ║ ╔═══╗ ║║ ╔═════╝ // ║ ╚═════╗║ ║ ║ ║║ ╚═════╗║ ║ ║ ║║ ╚═════╗ // ╚═══════╝╚═╝ ╚═╝╚═══════╝╚═╝ ╚═╝╚═══════╝ export function cacheConnection( connectionLabel: any, connection: connectionClasses.Connection, ) { connectionValidators.validateConnection(connection); _connectionByConnectionLabel.set(connectionLabel, connection); return connection; } // ╔═══════╗╔═══════╗╔═══════╗╔═╗ ╔═╗╔═══════╗╔═══════╗ // ║ ╔═════╝║ ╔═══╗ ║║ ╔═════╝║ ║ ║ ║║ ╔═════╝╚╗ ╔══╗ ║ // ║ ║ ║ ╚═══╝ ║║ ║ ║ ╚═══╝ ║║ ╚═════╗ ║ ║ ║ ║ // ║ ║ ║ ╔═══╗ ║║ ║ ║ ╔═══╗ ║║ ╔═════╝ ║ ║ ║ ║ // ║ ╚═════╗║ ║ ║ ║║ ╚═════╗║ ║ ║ ║║ ╚═════╗╔╝ ╚══╝ ║ // ╚═══════╝╚═╝ ╚═╝╚═══════╝╚═╝ ╚═╝╚═══════╝╚═══════╝ export function hasCachedConnection(connectionLabel?: any) { return _connectionByConnectionLabel.has(connectionLabel); } export function getCachedConnection(connectionLabel?: any) { if (!hasCachedConnection(connectionLabel)) { connectionErrors.throwUndeclaredMailgunConnectionLabel(); } return _connectionByConnectionLabel.get(connectionLabel); } export function getCachedConnections() { return [..._connectionByConnectionLabel.values()]; }