UNPKG

n8n

Version:

n8n Workflow Automation Tool

57 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractPush = void 0; const n8n_workflow_1 = require("n8n-workflow"); class AbstractPush { constructor(logger) { this.logger = logger; this.connections = {}; } add(pushRef, connection) { const { connections } = this; this.logger.debug('Add editor-UI session', { pushRef }); const existingConnection = connections[pushRef]; if (existingConnection) { this.close(existingConnection); } connections[pushRef] = connection; } remove(pushRef) { if (!pushRef) return; this.logger.debug('Removed editor-UI session', { pushRef }); delete this.connections[pushRef]; } sendTo(type, data, pushRefs) { this.logger.debug(`Send data of type "${type}" to editor-UI`, { dataType: type, pushRefs: pushRefs.join(', '), }); const stringifiedPayload = (0, n8n_workflow_1.jsonStringify)({ type, data }, { replaceCircularRefs: true }); for (const pushRef of pushRefs) { const connection = this.connections[pushRef]; (0, n8n_workflow_1.assert)(connection); this.sendToOneConnection(connection, stringifiedPayload); } } sendToAll(type, data) { this.sendTo(type, data, Object.keys(this.connections)); } sendToOne(type, data, pushRef) { if (this.connections[pushRef] === undefined) { this.logger.error(`The session "${pushRef}" is not registered.`, { pushRef }); return; } this.sendTo(type, data, [pushRef]); } closeAllConnections() { for (const pushRef in this.connections) { this.close(this.connections[pushRef]); } } hasPushRef(pushRef) { return this.connections[pushRef] !== undefined; } } exports.AbstractPush = AbstractPush; //# sourceMappingURL=abstract.push.js.map