diff --git a/types/collection.d.ts b/types/collection.d.ts index 611233c759..7b61079392 100644 --- a/types/collection.d.ts +++ b/types/collection.d.ts @@ -1,46 +1,49 @@ declare module 'mongoose' { import mongodb = require('mongodb'); - /* - * section collection.js - */ - interface CollectionBase extends mongodb.Collection { - /* - * Abstract methods. Some of these are already defined on the - * mongodb.Collection interface so they've been commented out. + export class BaseCollection extends mongodb.Collection { + /** + * Collection constructor + * @param name name of the collection + * @param conn A MongooseConnection instance + * @param opts optional collection options */ + constructor(name: string, conn: Connection, opts?: any); + + /* + * Abstract methods. Some of these are already defined on the + * mongodb.Collection interface so they've been commented out. + */ ensureIndex(...args: any[]): any; findAndModify(...args: any[]): any; getIndexes(...args: any[]): any; + /** Formatter for debug print args */ + $format(arg: any, color?: boolean, shell?: boolean): string; + /** Debug print helper */ + $print(name: string, i: string | number, args: any[], color?: boolean, shell?: boolean): void; + /** The collection name */ - collectionName: string; + get collectionName(): string; /** The Connection instance */ conn: Connection; /** The collection name */ name: string; } - export type BaseCollection = CollectionBase; - /* * section drivers/node-mongodb-native/collection.js */ - interface Collection extends CollectionBase { + class Collection extends BaseCollection { /** * Collection constructor * @param name name of the collection * @param conn A MongooseConnection instance * @param opts optional collection options */ - // eslint-disable-next-line @typescript-eslint/no-misused-new - new(name: string, conn: Connection, opts?: any): Collection; - /** Formatter for debug print args */ - $format(arg: any, color?: boolean, shell?: boolean): string; - /** Debug print helper */ - $print(name: string, i: string | number, args: any[], color?: boolean, shell?: boolean): void; + constructor(name: string, conn: Connection, opts?: any); + /** Retrieves information about this collections indexes. */ getIndexes(): ReturnType['indexInformation']>; } - let Collection: Collection; } diff --git a/types/connection.d.ts b/types/connection.d.ts index 4eafbf14ac..d7ee4638ed 100644 --- a/types/connection.d.ts +++ b/types/connection.d.ts @@ -71,8 +71,6 @@ declare module 'mongoose' { }; }[keyof SchemaMap]; - export type BaseConnection = Connection; - class Connection extends events.EventEmitter implements SessionStarter { /** Runs a [db-level aggregate()](https://www.mongodb.com/docs/manual/reference/method/db.aggregate/) on this connection's underlying `db` */ aggregate(pipeline?: PipelineStage[] | null, options?: AggregateOptions): Aggregate>; @@ -286,4 +284,5 @@ declare module 'mongoose' { withSession(executor: (session: ClientSession) => Promise): Promise; } + export class BaseConnection extends Connection {} }