Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions types/collection.d.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
declare module 'mongoose' {
import mongodb = require('mongodb');

/*
* section collection.js
*/
interface CollectionBase<T extends mongodb.Document> extends mongodb.Collection<T> {
/*
* Abstract methods. Some of these are already defined on the
* mongodb.Collection interface so they've been commented out.
export class BaseCollection<T extends mongodb.Document> extends mongodb.Collection<T> {
/**
* 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<T extends mongodb.Document> = CollectionBase<T>;

/*
* section drivers/node-mongodb-native/collection.js
*/
interface Collection<T extends mongodb.Document = mongodb.Document> extends CollectionBase<T> {
class Collection<T extends mongodb.Document = mongodb.Document> extends BaseCollection<T> {
/**
* 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<T>;
/** 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<mongodb.Collection<T>['indexInformation']>;
}
let Collection: Collection;
}
3 changes: 1 addition & 2 deletions types/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResultType = unknown>(pipeline?: PipelineStage[] | null, options?: AggregateOptions): Aggregate<Array<ResultType>>;
Expand Down Expand Up @@ -286,4 +284,5 @@ declare module 'mongoose' {
withSession<T = any>(executor: (session: ClientSession) => Promise<T>): Promise<T>;
}

export class BaseConnection extends Connection {}
}