"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpanRegistry = void 0;
class SpanRegistry {
    constructor() {
        this.spans = new Map();
    }
    static workflowKey(executionId) {
        return executionId;
    }
    static nodeKey(executionId, nodeId) {
        return `${executionId}:${nodeId}`;
    }
    addWorkflow(executionId, span) {
        this.spans.set(SpanRegistry.workflowKey(executionId), span);
    }
    getWorkflow(executionId) {
        return this.spans.get(SpanRegistry.workflowKey(executionId));
    }
    removeWorkflow(executionId) {
        const key = SpanRegistry.workflowKey(executionId);
        const span = this.spans.get(key);
        this.spans.delete(key);
        return span;
    }
    addNode(executionId, nodeId, span) {
        this.spans.set(SpanRegistry.nodeKey(executionId, nodeId), span);
    }
    getNode(executionId, nodeId) {
        return this.spans.get(SpanRegistry.nodeKey(executionId, nodeId));
    }
    removeNode(executionId, nodeId) {
        const key = SpanRegistry.nodeKey(executionId, nodeId);
        const span = this.spans.get(key);
        this.spans.delete(key);
        return span;
    }
    findUnendedNodeSpans(executionId) {
        const prefix = `${executionId}:`;
        const dangling = [];
        for (const [key, span] of this.spans.entries()) {
            if (key.startsWith(prefix)) {
                dangling.push(span);
                this.spans.delete(key);
            }
        }
        return dangling;
    }
    cleanup(executionId) {
        for (const key of this.spans.keys()) {
            if (key === executionId || key.startsWith(`${executionId}:`)) {
                this.spans.delete(key);
            }
        }
    }
}
exports.SpanRegistry = SpanRegistry;
//# sourceMappingURL=span-registry.js.map