From e949e6fec637b2cc0cd8cbce6747b32c16abf7a1 Mon Sep 17 00:00:00 2001 From: Hossein Saniei Date: Thu, 8 Aug 2019 01:49:46 +0430 Subject: [PATCH] fix(@types/mongodb): make _id optional for collection.insertX functions (#37402) --- types/agenda/index.d.ts | 2 +- types/connect-mongodb-session/index.d.ts | 4 +-- types/gridfs-stream/index.d.ts | 4 +-- types/mongodb/index.d.ts | 30 ++++++++++++++--------- types/mongoose/v4/index.d.ts | 2 +- types/mongorito/index.d.ts | 2 +- types/mongration/index.d.ts | 2 +- types/multer-gridfs-storage/v1/index.d.ts | 2 +- types/multer-gridfs-storage/v2/index.d.ts | 2 +- 9 files changed, 27 insertions(+), 23 deletions(-) diff --git a/types/agenda/index.d.ts b/types/agenda/index.d.ts index 37b9ce6b2c..598020e9e6 100644 --- a/types/agenda/index.d.ts +++ b/types/agenda/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Meir Gottlieb // Jeff Principe // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 /// diff --git a/types/connect-mongodb-session/index.d.ts b/types/connect-mongodb-session/index.d.ts index c328a211b2..61a2d07e9a 100644 --- a/types/connect-mongodb-session/index.d.ts +++ b/types/connect-mongodb-session/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/kcbanner/connect-mongodb-session // Definitions by: Nattapong Sirilappanich // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 /// @@ -28,4 +28,4 @@ declare namespace connectMongodbSession { } } -export = connect \ No newline at end of file +export = connect diff --git a/types/gridfs-stream/index.d.ts b/types/gridfs-stream/index.d.ts index be056a3cef..12952f88ee 100644 --- a/types/gridfs-stream/index.d.ts +++ b/types/gridfs-stream/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/aheckmann/gridfs-stream // Definitions by: Lior Mualem // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 /// @@ -66,5 +66,3 @@ declare namespace g { } export = g; - - diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 430541b21d..bb48efefd5 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -24,8 +24,9 @@ // Nick Zahn // Jarom Loveridge // Luis Pais +// Hossein Saniei // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 // Documentation: https://mongodb.github.io/node-mongodb-native/3.1/api/ @@ -36,6 +37,9 @@ import { EventEmitter } from 'events'; import { Readable, Writable } from "stream"; import { checkServerIdentity } from "tls"; +// This line can be removed after minimum required TypeScript Version is above 3.5 +type Omit = Pick>; + export function connect(uri: string, options?: MongoClientOptions): Promise; export function connect(uri: string, callback: MongoCallback): void; export function connect(uri: string, options: MongoClientOptions, callback: MongoCallback): void; @@ -127,7 +131,7 @@ export interface ClientSession extends EventEmitter { * Starts a new transaction with the given options. */ startTransaction(options?: TransactionOptions): void; - + /** * Runs a provided lambda within a transaction, retrying either the commit operation * or entire transaction as needed (and when the error permits) to better ensure that @@ -135,7 +139,7 @@ export interface ClientSession extends EventEmitter { * * IMPORTANT: This method requires the user to return a Promise, all lambdas that do not * return a Promise will result in undefined behavior. - * + * * @param fn Function to execute with the new session. * @param options Optional settings for the transaction */ @@ -846,6 +850,8 @@ export interface FSyncOptions extends CommonOptions { fsync?: boolean; } +type OptionalId = Omit & { _id?: any }; + /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html */ export interface Collection { /** @@ -994,19 +1000,19 @@ export interface Collection { initializeUnorderedBulkOp(options?: CommonOptions): UnorderedBulkOperation; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#insertOne */ /** @deprecated Use insertOne, insertMany or bulkWrite */ - insert(docs: TSchema, callback: MongoCallback): void; + insert(docs: OptionalId, callback: MongoCallback): void; /** @deprecated Use insertOne, insertMany or bulkWrite */ - insert(docs: TSchema, options?: CollectionInsertOneOptions): Promise; + insert(docs: OptionalId, options?: CollectionInsertOneOptions): Promise; /** @deprecated Use insertOne, insertMany or bulkWrite */ - insert(docs: TSchema, options: CollectionInsertOneOptions, callback: MongoCallback): void; + insert(docs: OptionalId, options: CollectionInsertOneOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#insertMany */ - insertMany(docs: TSchema[], callback: MongoCallback): void; - insertMany(docs: TSchema[], options?: CollectionInsertManyOptions): Promise; - insertMany(docs: TSchema[], options: CollectionInsertManyOptions, callback: MongoCallback): void; + insertMany(docs: Array>, callback: MongoCallback): void; + insertMany(docs: Array>, options?: CollectionInsertManyOptions): Promise; + insertMany(docs: Array>, options: CollectionInsertManyOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#insertOne */ - insertOne(docs: TSchema, callback: MongoCallback): void; - insertOne(docs: TSchema, options?: CollectionInsertOneOptions): Promise; - insertOne(docs: TSchema, options: CollectionInsertOneOptions, callback: MongoCallback): void; + insertOne(docs: OptionalId, callback: MongoCallback): void; + insertOne(docs: OptionalId, options?: CollectionInsertOneOptions): Promise; + insertOne(docs: OptionalId, options: CollectionInsertOneOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#isCapped */ isCapped(options?: { session: ClientSession }): Promise; isCapped(callback: MongoCallback): void; diff --git a/types/mongoose/v4/index.d.ts b/types/mongoose/v4/index.d.ts index 601dab393f..b714e1d728 100644 --- a/types/mongoose/v4/index.d.ts +++ b/types/mongoose/v4/index.d.ts @@ -5,7 +5,7 @@ // lukasz-zak // murbanowicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 /// /// diff --git a/types/mongorito/index.d.ts b/types/mongorito/index.d.ts index 3a34eec617..12b2f7d073 100644 --- a/types/mongorito/index.d.ts +++ b/types/mongorito/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/vadimdemedes/mongorito, https://github.com/vdemedes/mongorito // Definitions by: Pinguet62 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 +// TypeScript Version: 2.8 import { Collection, CommonOptions, Db, IndexOptions, Long, MongoClientOptions, ReadPreference } from 'mongodb'; diff --git a/types/mongration/index.d.ts b/types/mongration/index.d.ts index 7f46f3edc3..fa96c1c9ea 100644 --- a/types/mongration/index.d.ts +++ b/types/mongration/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/awapps/mongration#readme // Definitions by: Anton Lobashev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import { Db } from 'mongodb'; diff --git a/types/multer-gridfs-storage/v1/index.d.ts b/types/multer-gridfs-storage/v1/index.d.ts index c68e464a4c..94b028145b 100644 --- a/types/multer-gridfs-storage/v1/index.d.ts +++ b/types/multer-gridfs-storage/v1/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/devconcept/multer-gridfs-storage // Definitions by: devconcept // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import { EventEmitter } from 'events'; import { Express } from 'express'; diff --git a/types/multer-gridfs-storage/v2/index.d.ts b/types/multer-gridfs-storage/v2/index.d.ts index 0a827bedcb..175d5a7fb0 100644 --- a/types/multer-gridfs-storage/v2/index.d.ts +++ b/types/multer-gridfs-storage/v2/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/devconcept/multer-gridfs-storage // Definitions by: devconcept // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.8 import { EventEmitter } from 'events'; import { Express } from 'express';