/// import { EventEmitter } from "events"; import { ClientSession, DeleteOptions, UpdateOptions, Filter, UpdateFilter, BulkWriteOptions, InsertOneOptions, FindOneAndUpdateOptions, MongoClient, MongoError, TransactionOptions } from "mongodb"; import { ChangeStreamWrapper } from "./watch/ChangeStreamWrapper"; export type IDocumentMeta = { validationAction?: "warn" | "error"; validationLevel?: "off" | "strict" | "moderate"; collectionName: string; }; export type IDocumentFieldMeta = { expireAfterSeconds?: number; isRequired?: boolean; schema?: ISchema; index?: 1 | -1 | "text"; indexOptions?: IIndexOptions; }; export type IIndexObject = { [key: string]: 1 | -1 | "text"; }; export type IIndexOptions = { unique?: boolean; expireAfterSeconds?: number; partialFilterExpression?: any; sparse?: boolean; explicit?: boolean; }; export type IDocumentIndexMeta = IIndexOptions & { key: IIndexObject; }; export type IObject = { [key: string]: any; }; export type IDocumentInstance = { [key: string]: any; _id: any; }; export type IDocumentClass = new (...args: any[]) => IDocumentInstance; export type IDocumentObject = { [P in keyof T]: T[P]; }; export type IServerIndex = IDocumentIndexMeta & { name: string; ns: string; v: number; }; export type ICompareIndexResult = { existingIndexes: IServerIndex[]; dropIndexes: IServerIndex[]; createIndexes: IDocumentIndexMeta[]; }; export type ISchemaBsonType = "double" | "string" | "object" | "array" | "binData" | "undefined" | "objectId" | "bool" | "date" | "null" | "regex" | "dbPointer" | "javascript" | "symbol" | "javascriptWithScope" | "int" | "timestamp" | "long" | "decimal" | "minKey" | "maxKey"; export type ISchemaType = "object" | "array" | "number" | "boolean" | "string" | "null"; export type ISchema = Partial<{ bsonType: ISchemaBsonType | ISchemaBsonType[]; enum: any[]; type: ISchemaType | ISchemaType[]; allOf: ISchema[]; anyOf: ISchema[]; oneOf: ISchema[]; not: ISchema; multipleOf: number; maximum: number; exclusiveMaximum: boolean; minimum: number; exclusiveMinimum: boolean; maxLength: number; minLength: number; pattern: RegExp | string; maxProperties: number; minProperties: number; required: string[]; additionalProperties: boolean | { [key: string]: ISchema; }; properties: { [key: string]: ISchema; }; patternProperties: { [key: string]: RegExp | string; }; dependencies: any; additionalItems: boolean | { [key: string]: ISchema; }; items: { [key: string]: ISchema; } | ISchema[]; maxItems: number; minItems: number; uniqueItems: boolean; title: string; description: string; }>; export type IGetValidatorResult = { validator?: object; validationLevel?: "off" | "strict" | "moderate"; validationAction?: "warn" | "error"; }; export type IConnectionOptions = { mongoClient: MongoClient; dbName: string; }; export type ICreateCollectionOptions = { capped?: boolean; size?: number; max?: number; strict?: boolean; }; export type IGetRepositoryOptions = { dbName?: string; collectionName?: string; }; export type IRepositoryOptions = { classObject: T; mongoClient: MongoClient; dbName: string; collectionName: string; }; export type IGranularity = "R5" | "R10" | "$20" | "$40" | "R80" | "1-2-5" | "E6" | "E12" | "E24" | "E48" | "E96" | "E192" | "POWERSOF2"; export type IAggregateOptions = { weakType?: false; pipeline?: any[]; session?: ClientSession; allowDiskUse?: boolean; maxTimeMS?: number; bypassDocumentValidation?: boolean; }; export type IWeakTypeAggregateOptions = { weakType: true; pipeline?: any[]; session?: ClientSession; allowDiskUse?: boolean; maxTimeMS?: number; bypassDocumentValidation?: boolean; }; export type IQueryOptions = { weakType?: false; filter?: Filter>>; session?: ClientSession; }; export type IWeakTypeQueryOptions = { weakType: true; filter?: Filter>>; session?: ClientSession; }; export type IQueryUpdaterOptions = { weakType?: false; filter?: UpdateFilter>>; }; export type IWeakTypeQueryUpdaterOptions = { weakType: true; filter?: UpdateFilter>>; }; export type IInsertOneOptions = InsertOneOptions; export type IBulkWriteOptions = BulkWriteOptions; export type IUpdateOptions = UpdateOptions; export type IDeleteOptions = DeleteOptions & { bypassDocumentValidation?: boolean; }; export type IFindOneAndUpdateOptions = FindOneAndUpdateOptions; export type IChangeStreamWrapper = { [P in Exclude, keyof EventEmitter>]: ChangeStreamWrapper[P]; } & ITypedEventEmitter>>; export type IChangeSaveResult = { operationType: "insert" | "update"; documentKey: { _id: PropType; }; document: D; }; export type IChangeDeleteResult = { operationType: "delete"; documentKey: { _id: PropType; }; document?: D; }; export type IChangeOtherResult = { operationType: "replace" | "drop" | "dropDatabase" | "rename" | "invalidate"; documentKey: undefined; document: undefined; }; export interface IChangeStreamEvents { insert: (next: IChangeSaveResult) => void; update: (next: IChangeSaveResult) => void; delete: (next: IChangeDeleteResult) => void; change: (next: IChangeSaveResult | IChangeDeleteResult | IChangeOtherResult) => void; close: () => void; end: () => void; error: (err: MongoError) => void; } export type IGetTransactionManagerOptions = { maxRetry: number; transactionOptions: TransactionOptions; }; export type ITransactionMangerOptions = IGetTransactionManagerOptions & { mongoClient: MongoClient; }; export type ITransactionOptions = ITransactionMangerOptions; export type ITransactionCallback = (session: ClientSession) => Promise; export type ITransactionResult = { value: T; hasCommitted: boolean; totalRetry: number; }; export type IExplain = { queryPlanner: { plannerVersion: null; namespace: string; indexFilterSet: boolean; parsedQuery: object; winningPlan: { stage: string; filter: object; direction: string; }; rejectedPlans: object[]; }; executionStats: { executionSuccess: boolean; nReturned: number; executionTimeMillis: number; totalKeysExamined: number; totalDocsExamined: number; executionStages: { stage: string; filter: object[]; nReturned: number; executionTimeMillisEstimate: number; works: number; advanced: number; needTime: number; needYield: number; saveState: number; restoreState: number; isEOF: number; direction: string; docsExamined: number; }; allPlansExecution: object[]; }; serverInfo: { host: string; port: number; version: string; gitVersion: string; }; ok: number; $clusterTime: { clusterTime: object; signature: object; }; operationTime: object; }; export type IGetLockManagerOptions = { collectionName: string; expiresIn: number; maxRetry: number; retryDelay: number; }; export type ILockManagerOptions = IGetLockManagerOptions & { mongoClient: MongoClient; dbName: string; }; export type ILockOptions = ILockManagerOptions & { lockKey: string; }; export type ILockCallback = () => Promise; export type ILockResult = { value: T; totalRetry: number; }; export type IGetRankManagerOptions = { dbName?: string; collectionName?: string; skipTransaction?: boolean; transaction?: { transactionOptions: TransactionOptions; maxRetry: number; }; minScore: number; maxScore: number; branchFactor: number; }; export type IRankManagerOptions = Required & IGetRankManagerOptions & { mongoClient: MongoClient; }; export type PropType = T[K]; type EventArguments = [T] extends [(...args: infer U) => any] ? U : [T] extends [undefined] ? [] : [T]; export interface ITypedEventEmitter { addListener(event: E, listener: Events[E]): this; on(event: E, listener: Events[E]): this; once(event: E, listener: Events[E]): this; prependListener(event: E, listener: Events[E]): this; prependOnceListener(event: E, listener: Events[E]): this; removeListener(event: E, listener: Events[E]): this; off(event: E, listener: Events[E]): this; removeAllListeners(event?: E): this; setMaxListeners(maxListeners: number): this; getMaxListeners(): number; listeners(event: E): Function[]; rawListeners(event: E): Function[]; emit(event: E, ...args: EventArguments): boolean; eventNames(): Array; listenerCount(event: E): number; } export {};