"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemoryStateAdapter = void 0;
class MemoryStateAdapter {
    constructor() {
        this.state = {};
    }
    async init() {
        this.state = {};
    }
    async get(traceId, key) {
        const fullKey = this._makeKey(traceId, key);
        return this.state[fullKey] ? this.state[fullKey] : null;
    }
    async set(traceId, key, value) {
        const fullKey = this._makeKey(traceId, key);
        this.state[fullKey] = value;
        return value;
    }
    async delete(traceId, key) {
        const fullKey = this._makeKey(traceId, key);
        const value = await this.get(traceId, key);
        if (value) {
            delete this.state[fullKey];
        }
        return value;
    }
    async clear(traceId) {
        const pattern = this._makeKey(traceId, '');
        for (const key in this.state) {
            if (key.startsWith(pattern)) {
                delete this.state[key];
            }
        }
    }
    async keys(traceId) {
        return Object.keys(this.state)
            .filter((key) => key.startsWith(this._makeKey(traceId, '')))
            .map((key) => key.replace(this._makeKey(traceId, ''), ''));
    }
    async traceIds() {
        const traceIds = new Set();
        Object.keys(this.state).forEach((key) => traceIds.add(key.split(':')[0]));
        return Array.from(traceIds);
    }
    async cleanup() {
        // No cleanup needed for file system
    }
    _makeKey(traceId, key) {
        return `${traceId}:${key}`;
    }
}
exports.MemoryStateAdapter = MemoryStateAdapter;
