import { EventEmitter } from 'src/utils/index.js'; /** * Query options for find operations */ export type FindOptions = { limit: number; skip: number; sort: { [key: string]: 1 | -1 }; }; export type StorageEvent> = { insert: { key: string; value: T; }; update: { key: string; value: T; }; delete: { key: string; }; clear: undefined; }; export abstract class BaseStorage< T extends Record = Record, > extends EventEmitter> { /** * Insert a document into the store * @param id Unique identifier for the document * @param document The document to insert */ abstract insertOne(id: string, document: T): Promise; /** * Insert multiple documents into the store * @param documents Map of ID to document */ abstract insertMany(documents: Map): Promise; /** * Find a single document that matches the filter * @param filter MongoDB-like query filter */ abstract findOne(filter?: Partial): Promise; /** * Find all documents that match the filter * @param filter MongoDB-like query filter * @param options Query options (limit, skip, sort) */ abstract find(filter?: Partial, options?: FindOptions): Promise; /** * Update a document that matches the filter * @param filter Query to match the document to update * @param update Document or fields to update * @returns True if a document was updated, false otherwise */ abstract updateOne(filter: Partial, update: Partial): Promise; /** * Update all documents that match the filter * @param filter Query to match documents to update * @param update Document or fields to update * @param options Query options (limit, skip, sort) * @returns Number of documents updated */ abstract updateMany( filter: Partial, update: Partial, options: Partial, ): Promise; /** * Delete a document that matches the filter * @param filter Query to match the document to delete * @returns True if a document was deleted, false otherwise */ abstract deleteOne(filter: Partial): Promise; /** * Delete all documents that match the filter with options * @param filter Query to match documents to delete * @param options Query options (limit, skip, sort) * @returns Number of documents deleted */ abstract deleteMany( filter: Partial, options: Partial, ): Promise; /** * Derive a child storage from the current storage * @param path The path to derive the child storage from * @returns The child storage */ abstract deriveChild(path: string): BaseStorage; }