import { classify } from "./classify.js";
/**
 * Handles doc store upserts by checking hashes and ids.
 */ export class UpsertsStrategy {
    docStore;
    vectorStores;
    constructor(docStore, vectorStores){
        this.docStore = docStore;
        this.vectorStores = vectorStores;
    }
    async transform(nodes) {
        const { dedupedNodes, unusedDocs } = await classify(this.docStore, nodes);
        // remove unused docs
        for (const refDocId of unusedDocs){
            await this.docStore.deleteRefDoc(refDocId, false);
            if (this.vectorStores) {
                for (const vectorStore of this.vectorStores){
                    await vectorStore.delete(refDocId);
                }
            }
        }
        // add non-duplicate docs
        await this.docStore.addDocuments(dedupedNodes, true);
        return dedupedNodes;
    }
}
