// storage/vector-store/backend-factory.ts — Factory for selecting storage backend.
// SPEC-075 AC-06: Returns SQLite if available, JSON fallback otherwise.
import { createSqliteBackend } from './sqlite-adapter.js';
import { JsonFallbackBackend } from './json-fallback.js';
const backends = new Map();
/**
 * Get or create a storage backend for the given project.
 * Tries SQLite first, falls back to JSON.
 */
export async function getOrCreateBackend(projectId) {
    const existing = backends.get(projectId);
    if (existing) {
        return existing;
    }
    // Try SQLite first
    const sqlite = await createSqliteBackend(projectId);
    if (sqlite) {
        backends.set(projectId, sqlite);
        return sqlite;
    }
    // Fall back to JSON
    const json = new JsonFallbackBackend(projectId);
    backends.set(projectId, json);
    return json;
}
/** Clear all cached backends (for testing). */
export function clearBackendCache() {
    for (const backend of backends.values()) {
        backend.close?.();
    }
    backends.clear();
}
//# sourceMappingURL=backend-factory.js.map