import path from 'path-browserify';
import { v4 as uuid } from 'uuid';
import { LocalDocument } from './LocalDocument.js';
export class LocalDocumentStore {
    workspace;
    uri;
    constructor(workspace, uri) {
        this.workspace = workspace;
        this.uri = uri;
    }
    add(data) {
        const id = uuid();
        const document = new LocalDocument(id, {
            uri: path.join(this.uri, id),
            workspace: this.workspace,
        });
        document.save({
            text: data.text,
            vector: data.vector,
            metadata: data.metadata,
        });
        return document;
    }
    list() {
        const ids = this.workspace.readdirSync(this.uri).map(entry => entry.name);
        return ids.map(id => new LocalDocument(id, {
            uri: path.join(this.uri, id),
            workspace: this.workspace,
        }));
    }
}
