///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
import type { SearchResponse, SearchParams, Index } from 'meilisearch';
import type { CallbackWithoutResultAndOptionalError, Document, Schema, Model } from 'mongoose';
import type { IConversation, IMessage } from '~/types';
interface MongoMeiliOptions {
host: string;
apiKey: string;
indexName: string;
primaryKey: string;
mongoose: typeof import('mongoose');
syncBatchSize?: number;
syncDelayMs?: number;
}
interface MeiliIndexable {
[key: string]: unknown;
_meiliIndex?: boolean;
}
interface SyncProgress {
lastSyncedId?: string;
totalProcessed: number;
totalDocuments: number;
isComplete: boolean;
}
interface _DocumentWithMeiliIndex extends Document {
_meiliIndex?: boolean;
preprocessObjectForIndex?: () => Record;
addObjectToMeili?: (next: CallbackWithoutResultAndOptionalError) => Promise;
updateObjectToMeili?: (next: CallbackWithoutResultAndOptionalError) => Promise;
deleteObjectFromMeili?: (next: CallbackWithoutResultAndOptionalError) => Promise;
postSaveHook?: (next: CallbackWithoutResultAndOptionalError) => void;
postUpdateHook?: (next: CallbackWithoutResultAndOptionalError) => void;
postRemoveHook?: (next: CallbackWithoutResultAndOptionalError) => void;
}
export type DocumentWithMeiliIndex = _DocumentWithMeiliIndex & IConversation & Partial;
export interface SchemaWithMeiliMethods extends Model {
syncWithMeili(): Promise;
getSyncProgress(): Promise;
processSyncBatch(index: Index, documents: Array>): Promise;
cleanupMeiliIndex(index: Index, primaryKey: string, batchSize: number, delayMs: number): Promise;
setMeiliIndexSettings(settings: Record): Promise;
meiliSearch(q: string, params?: SearchParams, populate?: boolean): Promise>>;
}
/**
* Mongoose plugin to synchronize MongoDB collections with a MeiliSearch index.
*
* This plugin:
* - Validates the provided options.
* - Adds a `_meiliIndex` field to the schema to track indexing status.
* - Sets up a MeiliSearch client and creates an index if it doesn't already exist.
* - Loads class methods for syncing, searching, and managing documents in MeiliSearch.
* - Registers Mongoose hooks (post-save, post-update, post-remove, etc.) to maintain index consistency.
*
* @param schema - The Mongoose schema to which the plugin is applied.
* @param options - Configuration options.
* @param options.host - The MeiliSearch host.
* @param options.apiKey - The MeiliSearch API key.
* @param options.indexName - The name of the MeiliSearch index.
* @param options.primaryKey - The primary key field for indexing.
* @param options.syncBatchSize - Batch size for sync operations.
* @param options.syncDelayMs - Delay between batches in milliseconds.
*/
export default function mongoMeili(schema: Schema, options: MongoMeiliOptions): void;
export {};