Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mongodb] Added support for default generic types #16198

Merged
5 commits merged into from
Jun 7, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions types/acl/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/optimalbits/node_acl
// Definitions by: Qubo <https://github.com/tkQubo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="bluebird" />
/// <reference types="node"/>
Expand Down
1 change: 1 addition & 0 deletions types/agenda/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/rschmukler/agenda
// Definitions by: Meir Gottlieb <https://github.com/meirgottlieb>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="node" />

Expand Down
1 change: 1 addition & 0 deletions types/connect-mongo/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/kcbanner/connect-mongo
// Definitions by: Mizuki Yamamoto <https://github.com/Syati>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="express-session" />

Expand Down
11 changes: 6 additions & 5 deletions types/easy-jsend/easy-jsend-tests.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@


import mongoose = require('mongoose');
// import mongoose = require('mongoose');
import express = require('express');
import jSend = require('easy-jsend');

var schema = new mongoose.Schema({
name: {type: String}
});
// var schema = new mongoose.Schema({
// name: {type: String}
// });

var Model = mongoose.model('model', schema);
// var Model = mongoose.model('model', schema);
var Model = {};

jSend.init({partial: true});

Expand Down
6 changes: 3 additions & 3 deletions types/express-brute-mongo/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Project: https://github.com/auth0/express-brute-mongo
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3



import { Collection } from "mongodb";

/**
* @summary MongoDB store adapter.
Expand All @@ -17,5 +17,5 @@ export = class MongoStore {
* @param {Function} getCollection The collection.
* @param {Object} options The otpions.
*/
constructor(getCollection: (collection: any) => void, options?: Object);
constructor(getCollection: (collection: (c: Collection) => void) => void, options?: Object);
}
1 change: 1 addition & 0 deletions types/gridfs-stream/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/aheckmann/gridfs-stream
// Definitions by: Lior Mualem <https://github.com/liorm/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="node" />

Expand Down
26 changes: 14 additions & 12 deletions types/mongodb/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/mongodb/node-mongodb-native/tree/2.2
// Definitions by: Federico Caselli <https://github.com/CaselIT>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

// Documentation : http://mongodb.github.io/node-mongodb-native/2.2/api/

Expand Down Expand Up @@ -496,14 +497,13 @@ export interface Collection {
dropIndexes(): Promise<any>;
dropIndexes(callback?: MongoCallback<any>): void;
//http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#find
find(query?: Object): Cursor<any>;
find<T>(query?: Object): Cursor<T>;
find<T = Default>(query?: Object): Cursor<T>;
/** @deprecated */
find(query: Object, fields?: Object, skip?: number, limit?: number, timeout?: number): Cursor<any>;
find<T = Default>(query: Object, fields?: Object, skip?: number, limit?: number, timeout?: number): Cursor<T>;
//http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#findOne
findOne(filter: Object, callback: MongoCallback<any>): void;
findOne(filter: Object, options?: FindOneOptions): Promise<any>;
findOne(filter: Object, options: FindOneOptions, callback: MongoCallback<any>): void;
findOne<T = Default>(filter: Object, callback: MongoCallback<T>): void;
findOne<T = Default>(filter: Object, options?: FindOneOptions): Promise<T>;
findOne<T = Default>(filter: Object, options: FindOneOptions, callback: MongoCallback<T>): void;
//http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#findOneAndDelete
findOneAndDelete(filter: Object, callback: MongoCallback<FindAndModifyWriteOpResultObject>): void;
findOneAndDelete(filter: Object, options?: { projection?: Object, sort?: Object, maxTimeMS?: number }): Promise<FindAndModifyWriteOpResultObject>;
Expand Down Expand Up @@ -996,8 +996,10 @@ export interface WriteOpResult {
//http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#~resultCallback
export type CursorResult = any | void | boolean;

type Default = { [key: string]: any };

//http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html
export class Cursor<T> extends Readable {
export class Cursor<T = Default> extends Readable {
Copy link
Contributor

@hinell hinell Jun 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to do the same for AggregationCursor<T>and remove overriding methods of Collection (like find()) that return Cursor<any> and AggregationCursor<any>. They are unnecessary now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I forgot to update the AggregationCursor. I'll try to do it today. Thanks for the reminder!


sortValue: string;
timeout: boolean;
Expand Down Expand Up @@ -1048,8 +1050,8 @@ export class Cursor<T> extends Readable {
// http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#min
min(min: number): Cursor<T>;
// http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#next
next(): Promise<CursorResult>;
next(callback: MongoCallback<CursorResult>): void;
next(): Promise<T>;
next(callback: MongoCallback<T>): void;
//http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#project
project(value: Object): Cursor<T>;
//http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#read
Expand Down Expand Up @@ -1101,7 +1103,7 @@ export interface EndCallback {
//http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#~resultCallback
export type AggregationCursorResult = any | void;
//http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html
export class AggregationCursor<T> extends Readable {
export class AggregationCursor<T = Default> extends Readable {
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#batchSize
batchSize(value: number): AggregationCursor<T>;
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#clone
Expand All @@ -1127,8 +1129,8 @@ export class AggregationCursor<T> extends Readable {
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#maxTimeMS
maxTimeMS(value: number): AggregationCursor<T>;
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#next
next(): Promise<AggregationCursorResult>;
next(callback: MongoCallback<AggregationCursorResult>): void;
next(): Promise<T>;
next(callback: MongoCallback<T>): void;
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#out
out(destination: string): AggregationCursor<T>;
//http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#project
Expand Down
8 changes: 5 additions & 3 deletions types/mongodb/mongodb-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let options = {
});

{
let cursor: mongodb.Cursor <any>;
let cursor: mongodb.Cursor;
cursor = collection.find();
cursor = cursor.addCursorFlag('',true);
cursor = cursor.addQueryModifier('',true);
Expand Down Expand Up @@ -81,14 +81,16 @@ let options = {
// Collection .findM<T>() & .agggregate<T>() generic tests
{
let bag : {cost: number, color: string};
type bag = typeof bag;
type bag = typeof bag;
let cursor: mongodb.Cursor<bag> = collection.find<bag>({color: 'black'})
cursor.toArray(function (err,r) { r[0].cost} );
cursor.forEach(function (bag ) { bag.color }, () => {});
collection.findOne({ color: 'white' }).then(() => { })
collection.findOne<bag>({ color: 'white' }).then(b => { b.cost; })
}
{
let payment: {total: number};
type payment = typeof payment;
type payment = typeof payment;
let cursor: mongodb.AggregationCursor<payment> = collection.aggregate<payment>([{}])
}
})
2 changes: 1 addition & 1 deletion types/mongoose-auto-increment/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Project: https://github.com/codetunnel/mongoose-auto-increment
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// TypeScript Version: 2.3

import { Connection, Schema, Mongoose } from 'mongoose';

Expand Down
2 changes: 1 addition & 1 deletion types/mongoose-deep-populate/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Project: https://github.com/buunguyen/mongoose-deep-populate
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// TypeScript Version: 2.3

import { Mongoose, Schema } from 'mongoose';

Expand Down
2 changes: 1 addition & 1 deletion types/mongoose-mock/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Project: https://github.com/JohanObrink/mongoose-mock
// Definitions by: jt000 <https://github.com/jt000>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// TypeScript Version: 2.3

import mongoose = require('mongoose');

Expand Down
1 change: 1 addition & 0 deletions types/mongoose-paginate/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/edwardhotchkiss/mongoose-paginate
// Definitions by: Linus Brolin <https://github.com/linusbrolin/>, simonxca <https://github.com/simonxca/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="mongoose" />

Expand Down
1 change: 1 addition & 0 deletions types/mongoose-promise/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: http://mongoosejs.com/
// Definitions by: simonxca <https://github.com/simonxca/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="mongoose" />
/// <reference types="mpromise" />
Expand Down
1 change: 1 addition & 0 deletions types/mongoose-sequence/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/ramiel/mongoose-sequence
// Definitions by: Linus Brolin <https://github.com/linusbrolin/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="mongoose" />

Expand Down
2 changes: 1 addition & 1 deletion types/mongoose/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Project: http://mongoosejs.com/
// Definitions by: simonxca <https://github.com/simonxca/>, horiuchi <https://github.com/horiuchi/>, sindrenm <https://github.com/sindrenm>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3

/// <reference types="mongodb" />
/// <reference types="node" />
Expand Down
1 change: 1 addition & 0 deletions types/passport-local-mongoose/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/saintedlama/passport-local-mongoose
// Definitions by: Linus Brolin <https://github.com/linusbrolin/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

/// <reference types="mongoose" />
/// <reference types="passport-local" />
Expand Down