/**
 * Lightweight FalkorDB client for beam queries.
 *
 * Wraps a connection to the semantic-{project} graph with a generic query
 * method. The beam needs ad-hoc Cypher queries that don't fit the
 * SemanticGraphClient's event-replay API.
 */
import { FalkorDB } from "falkordb";
const DEFAULT_HOST = "localhost";
const DEFAULT_PORT = 6379;
export class BeamGraphClient {
    host;
    port;
    db;
    graph;
    graphName;
    constructor(projectName, host = DEFAULT_HOST, port = DEFAULT_PORT) {
        this.host = host;
        this.port = port;
        this.graphName = `semantic-${projectName}`;
    }
    async connect() {
        if (this.db && this.graph)
            return;
        this.db = await FalkorDB.connect({ socket: { host: this.host, port: this.port } });
        this.graph = this.db.selectGraph(this.graphName);
    }
    async query(cypher, params) {
        if (!this.graph)
            throw new Error("BeamGraphClient: call connect() first");
        const result = await this.graph.query(cypher, params ? { params } : undefined);
        return result.data ?? [];
    }
    async close() {
        if (this.db) {
            await this.db.close();
            this.db = undefined;
            this.graph = undefined;
        }
    }
}
