UNPKG

@glandjs/core

Version:

Glands is a web framework for Node.js (@core)

47 lines (46 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DependencyGraph = void 0; class DependencyGraph { constructor() { this.nodes = new Map(); } addNode(id, type, parentId, metadata, instance) { if (this.nodes.has(id)) { const existingNode = this.nodes.get(id); existingNode.type = type; existingNode.metadata = { ...existingNode.metadata, ...metadata }; if (instance !== undefined) { existingNode.instance = instance; } if (parentId && !existingNode.parentId) { existingNode.parentId = parentId; const parentNode = this.getNode(parentId); if (parentNode) { parentNode.children.push(id); } } return existingNode; } const node = { id, type, metadata, instance, parentId, children: [], }; this.nodes.set(id, node); if (parentId) { const parentNode = this.getNode(parentId); if (parentNode) { parentNode.children.push(id); } } return node; } getNode(id) { return this.nodes.get(id); } } exports.DependencyGraph = DependencyGraph;