import { ClientSession, Collection, CollectionOptions, CreateCollectionOptions, Document, MongoClient, } from 'mongodb'; export type DbChangeType = 'create' | 'update' | 'delete'; export type InMemoryEventHandler = (evt: InMemoryEvent) => Promise | void; export type OnUpdatedProperties = Array | string>; export type PublishEventOptions = { session: ClientSession | undefined }; export type IChangePublisher = { publishDbChange: ( collectionName: string, changeType: DbChangeType, eventData: DbChangeData, options?: PublishEventOptions, ) => Promise, publishDbChanges: ( collectionName: string, changeType: DbChangeType, eventsData: DbChangeData[], options?: PublishEventOptions, ) => Promise, }; export interface DbChangeData { doc: T, prevDoc?: T } export type OutboxEvent = { _id: string, type: 'create' | 'update' | 'delete', doc: T, prevDoc?: T, createdOn: Date }; export type InMemoryEvent = { doc: T, prevDoc?: T, name: string, createdOn: Date }; export interface IDocument extends Document { _id: string; updatedOn?: Date; deletedOn?: Date | null; createdOn?: Date; } export type FindResult = { results: T[]; pagesCount: number; count: number; }; export type CreateConfig = { validateSchema?: boolean, publishEvents?: boolean, }; export type ReadConfig = { skipDeletedOnDocs?: boolean, }; export type UpdateConfig = { skipDeletedOnDocs?: boolean, validateSchema?: boolean, publishEvents?: boolean, }; export type DeleteConfig = { skipDeletedOnDocs?: boolean, publishEvents?: boolean, }; interface IDatabase { getOutboxService: () => IChangePublisher; waitForConnection: () => Promise; getOrCreateCollection: ( name: string, opt: { collectionCreateOptions: CreateCollectionOptions; collectionOptions: CollectionOptions; }, ) => Promise | null>; getClient: () => Promise; withTransaction: ( transactionFn: (session: ClientSession) => Promise, ) => Promise, } interface ServiceOptions { skipDeletedOnDocs?: boolean, schemaValidator?: (obj: any) => Promise, publishEvents?: boolean, addCreatedOnField?: boolean, addUpdatedOnField?: boolean, outbox?: boolean, collectionOptions?: CollectionOptions; collectionCreateOptions?: CreateCollectionOptions; escapeRegExp?: boolean; } export { IDatabase, ServiceOptions, };