// Type definitions for @seald-io/nedb 2.1.0 // Project: https://github.com/seald/nedb forked from https://github.com/louischatriot/nedb // Definitions by: Timothée Rebours // Mehdi Kouhen // Stefan Steinhart // Anthony Nichols // Alejandro Fernandez Haro // Pierre de la Martinière // TypeScript Version: 4.9 /// import { EventEmitter } from "events"; export default Nedb; export type Document = Schema & { _id: string; }; declare class Nedb> extends EventEmitter { constructor(pathOrOptions?: string | Nedb.DataStoreOptions); persistence: Nedb.Persistence; autoloadPromise: Promise | null; loadDatabase(callback?: (err: Error | null) => void): void; loadDatabaseAsync(): Promise; dropDatabase(callback?: (err: Error | null) => void): void; dropDatabaseAsync(): Promise; compactDatafile(callback?: (err: Error | null) => void): void; compactDatafileAsync(): Promise; setAutocompactionInterval(interval: number): void; stopAutocompaction(): void; getAllData(): Document[]; ensureIndex( options: Nedb.EnsureIndexOptions, callback?: (err: Error | null) => void ): void; ensureIndexAsync(options: Nedb.EnsureIndexOptions): Promise; removeIndex(fieldName: string | string[], callback?: (err: Error | null) => void): void; removeIndexAsync(fieldName: string | string[]): Promise; insert( newDoc: T, callback?: (err: Error | null, document: Document) => void ): void; insert( newDocs: T[], callback?: (err: Error | null, documents: Document[]) => void ): void; insertAsync(newDoc: T): Promise>; insertAsync(newDocs: T[]): Promise[]>; count(query: any, callback: (err: Error | null, n: number) => void): void; count(query: any): Nedb.CursorCount; countAsync(query: any): Nedb.Cursor; find( query: any, projection: any, callback?: (err: Error | null, documents: Document[]) => void ): void; find( query: any, projection?: any ): Nedb.Cursor; find( query: any, callback: (err: Error | null, documents: Document[]) => void ): void; findAsync( query: any, projection?: any ): Nedb.Cursor; findOne( query: any, projection: any, callback: (err: Error | null, document: Document) => void ): void; findOne( query: any, callback: (err: Error | null, document: Document) => void ): void; findOneAsync( query: any, projection?: any ): Nedb.Cursor; update( query: any, updateQuery: any, options?: O, callback?: ( err: Error | null, numberOfUpdated: number, affectedDocuments: O['returnUpdatedDocs'] extends true ? O['multi'] extends true ? Document[] | null : Document | null : null, upsert: boolean | null ) => void ): void; updateAsync( query: any, updateQuery: any, options?: O ): Promise<{ numAffected: number; affectedDocuments: O['returnUpdatedDocs'] extends true ? O['multi'] extends true ? Document[] | null : Document | null : null; upsert: boolean; }>; remove( query: any, options: Nedb.RemoveOptions, callback?: (err: Error | null, n: number) => void ): void; remove(query: any, callback?: (err: Error | null, n: number) => void): void; removeAsync(query: any, options: Nedb.RemoveOptions): Promise; addListener(event: "compaction.done", listener: () => void): this; on(event: "compaction.done", listener: () => void): this; once(event: "compaction.done", listener: () => void): this; prependListener(event: "compaction.done", listener: () => void): this; prependOnceListener(event: "compaction.done", listener: () => void): this; removeListener(event: "compaction.done", listener: () => void): this; off(event: "compaction.done", listener: () => void): this; listeners(event: "compaction.done"): Array<() => void>; rawListeners(event: "compaction.done"): Array<() => void>; listenerCount(type: "compaction.done"): number; } declare namespace Nedb { interface Cursor extends Promise> { sort(query: any): Cursor; skip(n: number): Cursor; limit(n: number): Cursor; projection(query: any): Cursor; exec(callback: (err: Error | null, documents: Document[]) => void): void; execAsync(): Promise>; } interface CursorCount { exec(callback: (err: Error | null, count: number) => void): void; } interface DataStoreOptions { filename?: string; timestampData?: boolean; inMemoryOnly?: boolean; autoload?: boolean; onload?(error: Error | null): any; beforeDeserialization?(line: string): string; afterSerialization?(line: string): string; corruptAlertThreshold?: number; compareStrings?(a: string, b: string): number; modes?: { fileMode: number; dirMode: number }; testSerializationHooks?: boolean; } interface UpdateOptions { multi?: boolean; upsert?: boolean; returnUpdatedDocs?: boolean; } interface RemoveOptions { multi?: boolean; } interface EnsureIndexOptions { fieldName: string | string[]; unique?: boolean; sparse?: boolean; expireAfterSeconds?: number; } interface Persistence { /** @deprecated */ compactDatafile(): void; /** @deprecated */ compactDatafileAsync(): Promise; /** @deprecated */ setAutocompactionInterval(interval: number): void; /** @deprecated */ stopAutocompaction(): void; } }