import type { Collection, Document, OptionalUnlessRequiredId, WithId, UpdateFilter, InsertManyResult, UpdateResult, WithoutId, AggregationCursor, FindCursor, DeleteResult, InsertOneResult, ModifyResult } from 'mongodb'; import { HookedFindCursor, HookedFindCursorOptions } from "./hookedFindCursor.js"; import { HookedListenerCallback, AmendedFindOptions, AmendedDistinctOptions, AmendedAggregateOptions, AmendedInsertOneOptions, AmendedBulkWriteOptions, AmendedReplaceOptions, AmendedUpdateOptions, AmendedDeleteOptions, CollectionHookedEventMap, HookedCollectionInterface, ChainedCallbackEventMapWithCaller } from "./events/index.js"; import { AbstractHookedCollection } from "./abstractCollectionImpl.js"; import { CallbackAndOptionsOfEm, StandardInvokeHookOptions } from './awaiatableEventEmitter.js'; import { AmendedCountDocumentsOptions, AmendedCountOptions, AmendedEstimatedDocumentCountOptions, AmendedFindOneAndDeleteOptions, AmendedFindOneAndReplaceOptions, AmendedFindOneAndUpdateOptions, AmendedFindOneOptions, CollectionOnlyBeforeAfterErrorEventDefinitions, MaybeStrictFilter, ExternalBeforeAfterEvent } from './events/collectionEvents.js'; import { BeforeAfterErrorSharedEventDefinitions } from './events/sharedEvents.js'; import { BeforeAfterCallbackArgsAndReturn, CommonDefinition, ExtractStandardBeforeAfterEventDefinitions, KeysMatching, Merge } from './events/helpersTypes.js'; interface HookedFindCursorConstructor { new (filter: MaybeStrictFilter | undefined, cursor: FindCursor, options: HookedFindCursorOptions): HookedFindCursor; } type HookedCollectionOptions = { transform?: (doc: any) => any; findCursorImpl?: HookedFindCursorConstructor; interceptExecute?: boolean; }; export type StandardInvokeHookOptionsFromCollection = T extends HookedCollection ? StandardInvokeHookOptions : never; export type AllEventsFromCollection = T extends HookedCollection ? AllEvents : never; export declare class HookedCollection> = {}, ExtractedEvents extends ExtractStandardBeforeAfterEventDefinitions = ExtractStandardBeforeAfterEventDefinitions, ExtraEvents extends ChainedCallbackEventMapWithCaller = BeforeAfterCallbackArgsAndReturn, AllEvents extends (ChainedCallbackEventMapWithCaller & CollectionHookedEventMap) = Merge, ExtraEvents>> extends AbstractHookedCollection implements HookedCollectionInterface { #private; static Events: { before: { find: "before.find"; update: "before.update"; count: "before.count"; delete: "before.delete"; insert: "before.insert"; aggregate: "before.aggregate"; "find.cursor.next": "before.find.cursor.next"; "find.cursor.toArray": "before.find.cursor.toArray"; "find.cursor.forEach": "before.find.cursor.forEach"; "find.cursor.asyncIterator": "before.find.cursor.asyncIterator"; "aggregation.cursor.next": "before.aggregation.cursor.next"; "aggregation.cursor.toArray": "before.aggregation.cursor.toArray"; "aggregation.cursor.forEach": "before.aggregation.cursor.forEach"; "aggregation.cursor.asyncIterator": "before.aggregation.cursor.asyncIterator"; "aggregation.cursor.execute": "before.aggregation.cursor.execute"; "find.cursor.execute": "before.find.cursor.execute"; "aggregation.cursor.rewind": "before.aggregation.cursor.rewind"; "find.cursor.rewind": "before.find.cursor.rewind"; "aggregation.cursor.close": "before.aggregation.cursor.close"; "find.cursor.close": "before.find.cursor.close"; "cursor.execute": "before.cursor.execute"; "cursor.next": "before.cursor.next"; "cursor.toArray": "before.cursor.toArray"; "cursor.forEach": "before.cursor.forEach"; "cursor.asyncIterator": "before.cursor.asyncIterator"; "cursor.rewind": "before.cursor.rewind"; "cursor.close": "before.cursor.close"; "*": "before.*"; findOne: "before.findOne"; insertOne: "before.insertOne"; insertMany: "before.insertMany"; deleteOne: "before.deleteOne"; deleteMany: "before.deleteMany"; replaceOne: "before.replaceOne"; updateOne: "before.updateOne"; updateMany: "before.updateMany"; distinct: "before.distinct"; countDocuments: "before.countDocuments"; estimatedDocumentCount: "before.estimatedDocumentCount"; "count*": "before.count*"; "findOne*": "before.findOne*"; findOneAndDelete: "before.findOneAndDelete"; findOneAndUpdate: "before.findOneAndUpdate"; findOneAndReplace: "before.findOneAndReplace"; "find.cursor.count": "before.find.cursor.count"; }; afterSuccess: { find: "after.find.success"; update: "after.update.success"; count: "after.count.success"; delete: "after.delete.success"; insert: "after.insert.success"; aggregate: "after.aggregate.success"; "find.cursor.next": "after.find.cursor.next.success"; "find.cursor.toArray": "after.find.cursor.toArray.success"; "find.cursor.forEach": "after.find.cursor.forEach.success"; "find.cursor.asyncIterator": "after.find.cursor.asyncIterator.success"; "aggregation.cursor.next": "after.aggregation.cursor.next.success"; "aggregation.cursor.toArray": "after.aggregation.cursor.toArray.success"; "aggregation.cursor.forEach": "after.aggregation.cursor.forEach.success"; "aggregation.cursor.asyncIterator": "after.aggregation.cursor.asyncIterator.success"; "aggregation.cursor.execute": "after.aggregation.cursor.execute.success"; "find.cursor.execute": "after.find.cursor.execute.success"; "aggregation.cursor.rewind": "after.aggregation.cursor.rewind.success"; "find.cursor.rewind": "after.find.cursor.rewind.success"; "aggregation.cursor.close": "after.aggregation.cursor.close.success"; "find.cursor.close": "after.find.cursor.close.success"; "cursor.execute": "after.cursor.execute.success"; "cursor.next": "after.cursor.next.success"; "cursor.toArray": "after.cursor.toArray.success"; "cursor.forEach": "after.cursor.forEach.success"; "cursor.asyncIterator": "after.cursor.asyncIterator.success"; "cursor.rewind": "after.cursor.rewind.success"; "cursor.close": "after.cursor.close.success"; "*": "after.*.success"; findOne: "after.findOne.success"; insertOne: "after.insertOne.success"; insertMany: "after.insertMany.success"; deleteOne: "after.deleteOne.success"; deleteMany: "after.deleteMany.success"; replaceOne: "after.replaceOne.success"; updateOne: "after.updateOne.success"; updateMany: "after.updateMany.success"; distinct: "after.distinct.success"; countDocuments: "after.countDocuments.success"; estimatedDocumentCount: "after.estimatedDocumentCount.success"; "count*": "after.count*.success"; "findOne*": "after.findOne*.success"; findOneAndDelete: "after.findOneAndDelete.success"; findOneAndUpdate: "after.findOneAndUpdate.success"; findOneAndReplace: "after.findOneAndReplace.success"; "find.cursor.count": "after.find.cursor.count.success"; }; afterError: { find: "after.find.error"; update: "after.update.error"; count: "after.count.error"; delete: "after.delete.error"; insert: "after.insert.error"; aggregate: "after.aggregate.error"; "find.cursor.next": "after.find.cursor.next.error"; "find.cursor.toArray": "after.find.cursor.toArray.error"; "find.cursor.forEach": "after.find.cursor.forEach.error"; "find.cursor.asyncIterator": "after.find.cursor.asyncIterator.error"; "aggregation.cursor.next": "after.aggregation.cursor.next.error"; "aggregation.cursor.toArray": "after.aggregation.cursor.toArray.error"; "aggregation.cursor.forEach": "after.aggregation.cursor.forEach.error"; "aggregation.cursor.asyncIterator": "after.aggregation.cursor.asyncIterator.error"; "aggregation.cursor.execute": "after.aggregation.cursor.execute.error"; "find.cursor.execute": "after.find.cursor.execute.error"; "aggregation.cursor.rewind": "after.aggregation.cursor.rewind.error"; "find.cursor.rewind": "after.find.cursor.rewind.error"; "aggregation.cursor.close": "after.aggregation.cursor.close.error"; "find.cursor.close": "after.find.cursor.close.error"; "cursor.execute": "after.cursor.execute.error"; "cursor.next": "after.cursor.next.error"; "cursor.toArray": "after.cursor.toArray.error"; "cursor.forEach": "after.cursor.forEach.error"; "cursor.asyncIterator": "after.cursor.asyncIterator.error"; "cursor.rewind": "after.cursor.rewind.error"; "cursor.close": "after.cursor.close.error"; "*": "after.*.error"; findOne: "after.findOne.error"; insertOne: "after.insertOne.error"; insertMany: "after.insertMany.error"; deleteOne: "after.deleteOne.error"; deleteMany: "after.deleteMany.error"; replaceOne: "after.replaceOne.error"; updateOne: "after.updateOne.error"; updateMany: "after.updateMany.error"; distinct: "after.distinct.error"; countDocuments: "after.countDocuments.error"; estimatedDocumentCount: "after.estimatedDocumentCount.error"; "count*": "after.count*.error"; "findOne*": "after.findOne*.error"; findOneAndDelete: "after.findOneAndDelete.error"; findOneAndUpdate: "after.findOneAndUpdate.error"; findOneAndReplace: "after.findOneAndReplace.error"; "find.cursor.count": "after.find.cursor.count.error"; }; after: { find: "after.find"; update: "after.update"; count: "after.count"; delete: "after.delete"; insert: "after.insert"; aggregate: "after.aggregate"; "find.cursor.next": "after.find.cursor.next"; "find.cursor.toArray": "after.find.cursor.toArray"; "find.cursor.forEach": "after.find.cursor.forEach"; "find.cursor.asyncIterator": "after.find.cursor.asyncIterator"; "aggregation.cursor.next": "after.aggregation.cursor.next"; "aggregation.cursor.toArray": "after.aggregation.cursor.toArray"; "aggregation.cursor.forEach": "after.aggregation.cursor.forEach"; "aggregation.cursor.asyncIterator": "after.aggregation.cursor.asyncIterator"; "aggregation.cursor.execute": "after.aggregation.cursor.execute"; "find.cursor.execute": "after.find.cursor.execute"; "aggregation.cursor.rewind": "after.aggregation.cursor.rewind"; "find.cursor.rewind": "after.find.cursor.rewind"; "aggregation.cursor.close": "after.aggregation.cursor.close"; "find.cursor.close": "after.find.cursor.close"; "cursor.execute": "after.cursor.execute"; "cursor.next": "after.cursor.next"; "cursor.toArray": "after.cursor.toArray"; "cursor.forEach": "after.cursor.forEach"; "cursor.asyncIterator": "after.cursor.asyncIterator"; "cursor.rewind": "after.cursor.rewind"; "cursor.close": "after.cursor.close"; "*": "after.*"; findOne: "after.findOne"; insertOne: "after.insertOne"; insertMany: "after.insertMany"; deleteOne: "after.deleteOne"; deleteMany: "after.deleteMany"; replaceOne: "after.replaceOne"; updateOne: "after.updateOne"; updateMany: "after.updateMany"; distinct: "after.distinct"; countDocuments: "after.countDocuments"; estimatedDocumentCount: "after.estimatedDocumentCount"; "count*": "after.count*"; "findOne*": "after.findOne*"; findOneAndDelete: "after.findOneAndDelete"; findOneAndUpdate: "after.findOneAndUpdate"; findOneAndReplace: "after.findOneAndReplace"; "find.cursor.count": "after.find.cursor.count"; }; }; map: CollectionHookedEventMap; constructor(collection: Collection, options?: HookedCollectionOptions); aggregate(pipeline: Document[], options?: AmendedAggregateOptions): AggregationCursor; /** * This function should be used exclusively to allow for instrumentation * it should be called at most once and calling this arbitrarily at runtime has undefined behaviour * it's expected to be used as follows: myCollection._setCollection(instrument(myCollection.rawCollection())) * this can be combined with patching the AbstractHookedCollection's init to ensure that all collections created will have an instrumented base collection * @param collection the collection to use */ _setCollection(collection: Collection): void; rawCollection(): Collection; distinct>(key: Key, filter?: MaybeStrictFilter, options?: AmendedDistinctOptions): Promise["_id" | keyof import("mongodb").EnhancedOmit]>[]>; findOne(filter?: MaybeStrictFilter, options?: AmendedFindOneOptions | undefined): Promise; find(filter?: MaybeStrictFilter, options?: AmendedFindOptions): HookedFindCursor; protected _tryCatchEmit Promise, BE extends `before.${IE}` & keyof HEM, AE extends `after.${IE}.success` & keyof HEM, IE extends keyof CollectionOnlyBeforeAfterErrorEventDefinitions | keyof BeforeAfterErrorSharedEventDefinitions | (KeysMatching & string), OIE extends keyof CollectionOnlyBeforeAfterErrorEventDefinitions | keyof BeforeAfterErrorSharedEventDefinitions | (KeysMatching & string), EA extends HEM[BE]["emitArgs"], OEA extends Omit>(internalEvent: IE, emitArgs: OEA, beforeChainKey: (keyof OEA & HEM[BE]["returnEmitName"]) | undefined, fn: T, invocationOptions: StandardInvokeHookOptions | undefined, ...additionalInternalEvents: OIE[] | { event: OIE; emitArgs: Partial; }[]): Promise>>; insertOne(doc: OptionalUnlessRequiredId, options?: AmendedInsertOneOptions): Promise>; insertMany(docs: OptionalUnlessRequiredId[], options?: AmendedBulkWriteOptions): Promise>; replaceOne(filter: MaybeStrictFilter, replacement: WithoutId, options?: AmendedReplaceOptions | undefined): Promise>; updateOne(filter: MaybeStrictFilter, update: UpdateFilter | Partial, options?: AmendedUpdateOptions): Promise>; updateMany(filter: MaybeStrictFilter, update: UpdateFilter, options?: AmendedUpdateOptions | undefined): Promise>; deleteOne(filter?: MaybeStrictFilter, options?: AmendedDeleteOptions): Promise; deleteMany(filter?: MaybeStrictFilter, options?: AmendedDeleteOptions): Promise; hooks(eventName: K): CallbackAndOptionsOfEm[]; allHooksWithOptions(): { hook: import("./awaiatableEventEmitter.js").ChainedListenerCallback; eventName: keyof AllEvents; options: AllEvents[keyof AllEvents]["options"] | undefined; }[]; on(eventName: K, listener: HookedListenerCallback, options?: AllEvents[K]["options"]): this; off(eventName: K, listener: HookedListenerCallback): this; count(filter?: MaybeStrictFilter | undefined, options?: AmendedCountOptions | undefined): Promise; estimatedDocumentCount(options?: AmendedEstimatedDocumentCountOptions | undefined): Promise; countDocuments(filter?: MaybeStrictFilter | undefined, options?: AmendedCountDocumentsOptions | undefined): Promise; findOneAndDelete(filter: MaybeStrictFilter, options: AmendedFindOneAndDeleteOptions & { includeResultMetadata: true; }): Promise>; findOneAndDelete(filter: MaybeStrictFilter, options: AmendedFindOneAndDeleteOptions & { includeResultMetadata: false; }): Promise | null>; findOneAndDelete(filter: MaybeStrictFilter, options: AmendedFindOneAndDeleteOptions): Promise>; findOneAndDelete(filter: MaybeStrictFilter): Promise>; findOneAndUpdate(filter: MaybeStrictFilter, update: UpdateFilter, options: AmendedFindOneAndUpdateOptions & { includeResultMetadata: true; }): Promise>; findOneAndUpdate(filter: MaybeStrictFilter, update: UpdateFilter, options: AmendedFindOneAndUpdateOptions & { includeResultMetadata: false; }): Promise | null>; findOneAndUpdate(filter: MaybeStrictFilter, update: UpdateFilter, options: AmendedFindOneAndUpdateOptions): Promise | null>; findOneAndUpdate(filter: MaybeStrictFilter, update: UpdateFilter): Promise>; findOneAndReplace(filter: MaybeStrictFilter, replacement: WithoutId, options: AmendedFindOneAndReplaceOptions & { includeResultMetadata: true; }): Promise>; findOneAndReplace(filter: MaybeStrictFilter, replacement: WithoutId, options: AmendedFindOneAndReplaceOptions & { includeResultMetadata: false; }): Promise | null>; findOneAndReplace(filter: MaybeStrictFilter, replacement: WithoutId, options: AmendedFindOneAndReplaceOptions): Promise>; findOneAndReplace(filter: MaybeStrictFilter, replacement: WithoutId): Promise>; } export {};