import {HookRegisterConsumer} from "../../HookRegisterConsumer"; import {HookRegister} from "../../HookRegister"; import {ReverseMutationFactory} from "../../hook-struct/ReverseMutationFactory"; import {BitMutation} from "../../hook-struct/BitMutation"; import {Doc} from "../../hook-struct/Doc"; import {Field} from "../../hook-struct/Field"; export function createReverseIndexFactory(): HookRegisterConsumer { return { name: 'ReverseIndex', async init(hookRegister: HookRegister): Promise { hookRegister.register({ id: 'ReverseIndex', name: 'reverse.mutations.factory', hook: { async processAdd(doc: Doc, docId: number, oldDoc: Doc | null): Promise> { const fields = hookRegister.getHooks('index.field'); const fullMutations: Array = []; for (let field of fields) { const mutations = await field.hook.parseAdd(doc, oldDoc, docId); fullMutations.push(...mutations); } return fullMutations; }, async processDelete(doc: Doc, docId: number): Promise> { const fields = hookRegister.getHooks('index.field'); const fullMutations: Array = []; for (let field of fields) { const mutations = await field.hook.parseDelete(doc, docId); fullMutations.push(...mutations); } return fullMutations; } } }) } } }