UNPKG

@flowlab/all

Version:

A cool library focusing on handling various flows

52 lines (51 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NodeRegistry = void 0; var baseNode_1 = require("../nodes/baseNode"); var errors_1 = require("../errors"); var NodeRegistry = /** @class */ (function () { function NodeRegistry() { this.nodes = new Map(); } NodeRegistry.prototype.register = function (idOrNode, func, description) { var id; var implementation; var isClassInstance = false; var nodeDescription = description; if (typeof idOrNode === 'string') { // Function registration id = idOrNode; if (!func) throw new errors_1.ConfigurationError("Node function is required when registering by ID '".concat(id, "'.")); implementation = func; nodeDescription = description; } else if (idOrNode instanceof baseNode_1.BaseNode) { // Class instance registration id = idOrNode.metadata.id; implementation = idOrNode; isClassInstance = true; nodeDescription = idOrNode.metadata.description || description; // Prefer metadata description } else { throw new errors_1.ConfigurationError('Invalid arguments for node registration.'); } if (this.nodes.has(id)) { console.warn("[NodeRegistry] Node with ID '".concat(id, "' is already registered. Overwriting.")); } this.nodes.set(id, { id: id, implementation: implementation, isClassInstance: isClassInstance, description: nodeDescription }); console.log("[NodeRegistry] Node '".concat(id, "' registered.")); }; NodeRegistry.prototype.get = function (id) { return this.nodes.get(id); }; NodeRegistry.prototype.getNodeImplementation = function (id) { var _a; return (_a = this.nodes.get(id)) === null || _a === void 0 ? void 0 : _a.implementation; }; NodeRegistry.prototype.listNodeIds = function () { return Array.from(this.nodes.keys()); }; return NodeRegistry; }()); exports.NodeRegistry = NodeRegistry;