/** * Index management for in-memory database. * * Provides functions for building and maintaining indexes that accelerate * equality queries. Supports both single-field and compound indexes. */ import { Effect } from "effect"; import type { CollectionIndexes, NormalizedIndex } from "../types/index-types.js"; /** * Entity constraint: must have a readonly string `id` field. */ type HasId = { readonly id: string; }; /** * Build all indexes for a collection from initial data. * * For each normalized index, creates a Ref containing the mapping * from field values to entity IDs. The returned CollectionIndexes map is keyed * by the JSON.stringify'd field array (e.g., '["email"]' or '["userId","category"]'). * * @param normalizedIndexes - Array of normalized index definitions * @param initialData - Array of entities to build indexes from * @returns Effect producing a CollectionIndexes map */ export declare const buildIndexes: (normalizedIndexes: ReadonlyArray, initialData: ReadonlyArray) => Effect.Effect; /** * Normalize index definitions from user config format to internal format. * * User config can specify indexes as: * - Single field: "email" * - Compound: ["userId", "category"] * * This function normalizes all indexes to arrays: * - "email" -> ["email"] * - ["userId", "category"] -> ["userId", "category"] * * @param indexes - Raw index definitions from collection config * @returns Normalized array of index field arrays */ export declare const normalizeIndexes: (indexes: ReadonlyArray> | undefined) => ReadonlyArray; /** * Add an entity to all applicable indexes. * * For each index in the collection, computes the index key from the entity's * field values and adds the entity's ID to the corresponding Set in the index. * * Entities with null/undefined values in indexed fields are skipped for that index. * * @param indexes - The collection's indexes * @param entity - The entity to add * @returns Effect that updates all index Refs */ export declare const addToIndex: (indexes: CollectionIndexes, entity: T) => Effect.Effect; /** * Remove an entity from all applicable indexes. * * For each index in the collection, computes the index key from the entity's * field values and removes the entity's ID from the corresponding Set. * Empty Sets are cleaned up (deleted from the index). * * Entities with null/undefined values in indexed fields are skipped for that index * (they wouldn't have been indexed in the first place). * * @param indexes - The collection's indexes * @param entity - The entity to remove * @returns Effect that updates all index Refs */ export declare const removeFromIndex: (indexes: CollectionIndexes, entity: T) => Effect.Effect; /** * Add multiple entities to all applicable indexes in a single batch. * * For each index in the collection, computes all index keys and applies * all additions in one Ref.update call per index. This is more efficient * than calling addToIndex for each entity individually. * * Entities with null/undefined values in indexed fields are skipped for that index. * * @param indexes - The collection's indexes * @param entities - The entities to add * @returns Effect that updates all index Refs */ export declare const addManyToIndex: (indexes: CollectionIndexes, entities: ReadonlyArray) => Effect.Effect; /** * Remove multiple entities from all applicable indexes in a single batch. * * For each index in the collection, computes all index keys and applies * all removals in one Ref.update call per index. This is more efficient * than calling removeFromIndex for each entity individually. * Empty Sets are cleaned up (deleted from the index). * * Entities with null/undefined values in indexed fields are skipped for that index * (they wouldn't have been indexed in the first place). * * @param indexes - The collection's indexes * @param entities - The entities to remove * @returns Effect that updates all index Refs */ export declare const removeManyFromIndex: (indexes: CollectionIndexes, entities: ReadonlyArray) => Effect.Effect; /** * Update an entity's position in all applicable indexes after a mutation. * * For each index in the collection: * - Computes the old and new index keys * - If keys are the same (or both undefined), no action needed * - If keys differ, removes the old entry and adds the new entry * * This efficiently handles the common case where most indexed fields don't * change during an update. * * @param indexes - The collection's indexes * @param oldEntity - The entity before the update * @param newEntity - The entity after the update * @returns Effect that updates all affected index Refs */ export declare const updateInIndex: (indexes: CollectionIndexes, oldEntity: T, newEntity: T) => Effect.Effect; export {}; //# sourceMappingURL=index-manager.d.ts.map