From 37d3474c8080042c0482fd4add4e8955cb90050e Mon Sep 17 00:00:00 2001 From: Nick Zahn Date: Thu, 21 Feb 2019 14:15:34 +0000 Subject: [PATCH] Remove rule `ban-types`, but keep `Function` exception for now --- types/mongodb/index.d.ts | 264 ++++++++++++++++----------------- types/mongodb/mongodb-tests.ts | 11 +- types/mongodb/tslint.json | 10 +- 3 files changed, 142 insertions(+), 143 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 19f9b509c4..2547fbee28 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -24,14 +24,14 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -// Documentation: http://mongodb.github.io/node-mongodb-native/3.1/api/ +// Documentation: https://mongodb.github.io/node-mongodb-native/3.1/api/ /// -/// import { ObjectID, Timestamp } from 'bson'; import { EventEmitter } from 'events'; import { Readable, Writable } from "stream"; +import { checkServerIdentity } from "tls"; export function connect(uri: string, options?: MongoClientOptions): Promise; export function connect(uri: string, callback: MongoCallback): void; @@ -54,7 +54,7 @@ export class MongoClient extends EventEmitter { close(force?: boolean): Promise; close(force: boolean, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#db */ - db(dbName?: string, options?: MongoClientCommonOption): Db + db(dbName?: string, options?: MongoClientCommonOption): Db; /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#isConnected */ isConnected(options?: MongoClientCommonOption): boolean; /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#logout */ @@ -64,7 +64,7 @@ export class MongoClient extends EventEmitter { /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#startSession */ startSession(options?: SessionOptions): ClientSession; /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#watch */ - watch(pipeline?: Object[], options?: ChangeStreamOptions & { startAtClusterTime?: Timestamp, session?: ClientSession }): ChangeStream; + watch(pipeline?: object[], options?: ChangeStreamOptions & { startAtClusterTime?: Timestamp, session?: ClientSession }): ChangeStream; /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#withSession */ withSession(operation: (session: ClientSession) => Promise): Promise; /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html#withSession */ @@ -208,7 +208,7 @@ export interface MongoCallback { /** http://mongodb.github.io/node-mongodb-native/3.1/api/MongoError.html */ export class MongoError extends Error { constructor(message: string); - static create(options: Object): MongoError; + static create(options: object): MongoError; code?: number; /** * While not documented, the 'errmsg' prop is AFAIK the only way to find out @@ -249,13 +249,13 @@ export interface MongoClientOptions extends /** * Custom logger object */ - logger?: Object | log; + logger?: object | log; /** * Validate MongoClient passed in options for correctness. * Default: false */ - validateOptions?: Object; + validateOptions?: object; /** * The name of the application that created this MongoClient instance. @@ -315,7 +315,7 @@ export interface SSLOptions { /** * Default: true; Server identity checking during SSL */ - checkServerIdentity?: boolean | Function; + checkServerIdentity?: boolean | typeof checkServerIdentity; /** * Array of valid certificates either as Buffers or Strings */ @@ -359,7 +359,7 @@ export interface HighAvailabilityOptions { // See http://mongodb.github.io/node-mongodb-native/3.1/api/ReadPreference.html export class ReadPreference { - constructor(mode: string, tags: Object); + constructor(mode: string, tags: object); mode: string; tags: any; options: { @@ -418,15 +418,15 @@ export interface DbCreateOptions extends CommonOptions { /** * Default: true; Promotes BSON values to native types where possible, set to false to only receive wrapper types. */ - promoteValues?: Object; + promoteValues?: boolean; /** * Custom primary key factory to generate _id values (see Custom primary keys). */ - pkFactory?: Object; + pkFactory?: object; /** * ES6 compatible promise constructor */ - promiseLibrary?: Object; + promiseLibrary?: object; /** * https://docs.mongodb.com/manual/reference/read-concern/#read-concern **/ @@ -562,17 +562,17 @@ export class Db extends EventEmitter { collections(): Promise[]>; collections(callback: MongoCallback[]>): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#command */ - command(command: Object, callback: MongoCallback): void; - command(command: Object, options?: { readPreference: ReadPreference | string }): Promise; - command(command: Object, options: { readPreference: ReadPreference | string }, callback: MongoCallback): void; + command(command: object, callback: MongoCallback): void; + command(command: object, options?: { readPreference: ReadPreference | string, session?: ClientSession }): Promise; + command(command: object, options: { readPreference: ReadPreference | string, session?: ClientSession }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#createCollection */ createCollection(name: string, callback: MongoCallback>): void; createCollection(name: string, options?: CollectionCreateOptions): Promise>; createCollection(name: string, options: CollectionCreateOptions, callback: MongoCallback>): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#createIndex */ - createIndex(name: string, fieldOrSpec: string | Object, callback: MongoCallback): void; - createIndex(name: string, fieldOrSpec: string | Object, options?: IndexOptions): Promise; - createIndex(name: string, fieldOrSpec: string | Object, options: IndexOptions, callback: MongoCallback): void; + createIndex(name: string, fieldOrSpec: string | object, callback: MongoCallback): void; + createIndex(name: string, fieldOrSpec: string | object, options?: IndexOptions): Promise; + createIndex(name: string, fieldOrSpec: string | object, options: IndexOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#dropCollection */ dropCollection(name: string): Promise; dropCollection(name: string, callback: MongoCallback): void; @@ -580,15 +580,15 @@ export class Db extends EventEmitter { dropDatabase(): Promise; dropDatabase(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#executeDbAdminCommand */ - executeDbAdminCommand(command: Object, callback: MongoCallback): void; - executeDbAdminCommand(command: Object, options?: { readPreference?: ReadPreference | string, maxTimeMS?: number }): Promise; - executeDbAdminCommand(command: Object, options: { readPreference?: ReadPreference | string, maxTimeMS?: number }, callback: MongoCallback): void; + executeDbAdminCommand(command: object, callback: MongoCallback): void; + executeDbAdminCommand(command: object, options?: { readPreference?: ReadPreference | string, session?: ClientSession }): Promise; + executeDbAdminCommand(command: object, options: { readPreference?: ReadPreference | string, session?: ClientSession }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#indexInformation */ indexInformation(name: string, callback: MongoCallback): void; indexInformation(name: string, options?: { full?: boolean, readPreference?: ReadPreference | string }): Promise; indexInformation(name: string, options: { full?: boolean, readPreference?: ReadPreference | string }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#listCollections */ - listCollections(filter?: Object, options?: { nameOnly?: boolean, batchSize?: number, readPreference?: ReadPreference | string, session?: ClientSession }): CommandCursor; + listCollections(filter?: object, options?: { nameOnly?: boolean, batchSize?: number, readPreference?: ReadPreference | string, session?: ClientSession }): CommandCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#profilingInfo */ /** @deprecated Query the system.profile collection directly. */ profilingInfo(callback: MongoCallback): void; @@ -655,14 +655,14 @@ export class Mongos extends EventEmitter { * @see http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#addUser */ export interface DbAddUserOptions extends CommonOptions { - customData?: Object; - roles?: Object[]; + customData?: object; + roles?: object[]; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#createCollection */ export interface CollectionCreateOptions extends CommonOptions { raw?: boolean; - pkFactory?: Object; + pkFactory?: object; readPreference?: ReadPreference | string; serializeFunctions?: boolean; strict?: boolean; @@ -684,7 +684,7 @@ export interface CollectionCreateOptions extends CommonOptions { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Db.html#collection */ export interface DbCollectionOptions extends CommonOptions { raw?: boolean; - pkFactory?: Object; + pkFactory?: object; readPreference?: ReadPreference | string; serializeFunctions?: boolean; strict?: boolean; @@ -750,9 +750,9 @@ export interface Admin { buildInfo(): Promise; buildInfo(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Admin.html#command */ - command(command: Object, callback: MongoCallback): void; - command(command: Object, options?: { readPreference?: ReadPreference | string, maxTimeMS?: number }): Promise; - command(command: Object, options: { readPreference?: ReadPreference | string, maxTimeMS?: number }, callback: MongoCallback): void; + command(command: object, callback: MongoCallback): void; + command(command: object, options?: { readPreference?: ReadPreference | string, maxTimeMS?: number }): Promise; + command(command: object, options: { readPreference?: ReadPreference | string, maxTimeMS?: number }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Admin.html#listDatabases */ listDatabases(): Promise; listDatabases(callback: MongoCallback): void; @@ -774,15 +774,15 @@ export interface Admin { serverStatus(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Admin.html#validateCollection */ validateCollection(collectionNme: string, callback: MongoCallback): void; - validateCollection(collectionNme: string, options?: Object): Promise; - validateCollection(collectionNme: string, options: Object, callback: MongoCallback): void; + validateCollection(collectionNme: string, options?: object): Promise; + validateCollection(collectionNme: string, options: object, callback: MongoCallback): void; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Admin.html#addUser */ export interface AddUserOptions extends CommonOptions { fsync: boolean; - customData?: Object; - roles?: Object[] + customData?: object; + roles?: object[] } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Admin.html#removeUser */ @@ -814,12 +814,12 @@ export interface Collection { hint: any; /** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#aggregate */ aggregate(callback: MongoCallback>): AggregationCursor; - aggregate(pipeline: Object[], callback: MongoCallback>): AggregationCursor; - aggregate(pipeline?: Object[], options?: CollectionAggregationOptions, callback?: MongoCallback>): AggregationCursor; + aggregate(pipeline: object[], callback: MongoCallback>): AggregationCursor; + aggregate(pipeline?: object[], options?: CollectionAggregationOptions, callback?: MongoCallback>): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#bulkWrite */ - bulkWrite(operations: Object[], callback: MongoCallback): void; - bulkWrite(operations: Object[], options?: CollectionBulkWriteOptions): Promise; - bulkWrite(operations: Object[], options: CollectionBulkWriteOptions, callback: MongoCallback): void; + bulkWrite(operations: object[], callback: MongoCallback): void; + bulkWrite(operations: object[], options?: CollectionBulkWriteOptions): Promise; + bulkWrite(operations: object[], options: CollectionBulkWriteOptions, callback: MongoCallback): void; /** * http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#count * @deprecated Use countDocuments or estimatedDocumentCount @@ -880,12 +880,12 @@ export interface Collection { findOne(filter: FilterQuery, options: FindOneOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndDelete */ findOneAndDelete(filter: FilterQuery, callback: MongoCallback>): void; - findOneAndDelete(filter: FilterQuery, options?: { projection?: Object, sort?: Object, maxTimeMS?: number, session?: ClientSession }): Promise>; - findOneAndDelete(filter: FilterQuery, options: { projection?: Object, sort?: Object, maxTimeMS?: number, session?: ClientSession }, callback: MongoCallback>): void; + findOneAndDelete(filter: FilterQuery, options?: { projection?: object, sort?: object, maxTimeMS?: number, session?: ClientSession }): Promise>; + findOneAndDelete(filter: FilterQuery, options: { projection?: object, sort?: object, maxTimeMS?: number, session?: ClientSession }, callback: MongoCallback>): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndReplace */ - findOneAndReplace(filter: FilterQuery, replacement: Object, callback: MongoCallback>): void; - findOneAndReplace(filter: FilterQuery, replacement: Object, options?: FindOneAndReplaceOption): Promise>; - findOneAndReplace(filter: FilterQuery, replacement: Object, options: FindOneAndReplaceOption, callback: MongoCallback>): void; + findOneAndReplace(filter: FilterQuery, replacement: object, callback: MongoCallback>): void; + findOneAndReplace(filter: FilterQuery, replacement: object, options?: FindOneAndReplaceOption): Promise>; + findOneAndReplace(filter: FilterQuery, replacement: object, options: FindOneAndReplaceOption, callback: MongoCallback>): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate */ findOneAndUpdate(filter: FilterQuery, update: UpdateQuery | TSchema, callback: MongoCallback>): void; findOneAndUpdate(filter: FilterQuery, update: UpdateQuery | TSchema, options?: FindOneAndUpdateOption): Promise>; @@ -894,14 +894,13 @@ export interface Collection { geoHaystackSearch(x: number, y: number, callback: MongoCallback): void; geoHaystackSearch(x: number, y: number, options?: GeoHaystackSearchOptions): Promise; geoHaystackSearch(x: number, y: number, options: GeoHaystackSearchOptions, callback: MongoCallback): void; - /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#geoNear */ - geoNear(x: number, y: number, callback: MongoCallback): void; - geoNear(x: number, y: number, options?: GeoNearOptions): Promise; - geoNear(x: number, y: number, options: GeoNearOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#group */ - group(keys: Object | Array | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, callback: MongoCallback): void; - group(keys: Object | Array | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, options?: { readPreference?: ReadPreference | string }): Promise; - group(keys: Object | Array | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, options: { readPreference?: ReadPreference | string }, callback: MongoCallback): void; + /** @deprecated MongoDB 3.6 or higher no longer supports the group command. We recommend rewriting using the aggregation framework. */ + group(keys: object | Array | Function | Code, condition: object, initial: object, reduce: Function | Code, finalize: Function | Code, command: boolean, callback: MongoCallback): void; + /** @deprecated MongoDB 3.6 or higher no longer supports the group command. We recommend rewriting using the aggregation framework. */ + group(keys: object | Array | Function | Code, condition: object, initial: object, reduce: Function | Code, finalize: Function | Code, command: boolean, options?: { readPreference?: ReadPreference | string, session?: ClientSession }): Promise; + /** @deprecated MongoDB 3.6 or higher no longer supports the group command. We recommend rewriting using the aggregation framework. */ + group(keys: object | Array | Function | Code, condition: object, initial: object, reduce: Function | Code, finalize: Function | Code, command: boolean, options: { readPreference?: ReadPreference | string, session?: ClientSession }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#indexes */ indexes(options?: { session: ClientSession }): Promise; indexes(callback: MongoCallback): void; @@ -940,9 +939,9 @@ export interface Collection { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#listIndexes */ listIndexes(options?: { batchSize?: number, readPreference?: ReadPreference | string, session?: ClientSession }): CommandCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#mapReduce */ - mapReduce(map: Function | string, reduce: Function | string, callback: MongoCallback): void; - mapReduce(map: Function | string, reduce: Function | string, options?: MapReduceOptions): Promise; - mapReduce(map: Function | string, reduce: Function | string, options: MapReduceOptions, callback: MongoCallback): void; + mapReduce(map: CollectionMapFunction | string, reduce: CollectionReduceFunction | string, callback: MongoCallback): void; + mapReduce(map: CollectionMapFunction | string, reduce: CollectionReduceFunction | string, options?: MapReduceOptions): Promise; + mapReduce(map: CollectionMapFunction | string, reduce: CollectionReduceFunction | string, options: MapReduceOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#options */ options(options?: { session: ClientSession }): Promise; options(callback: MongoCallback): void; @@ -957,11 +956,11 @@ export interface Collection { reIndex(options: { session: ClientSession }, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#remove */ /** @deprecated Use use deleteOne, deleteMany or bulkWrite */ - remove(selector: Object, callback: MongoCallback): void; + remove(selector: object, callback: MongoCallback): void; /** @deprecated Use use deleteOne, deleteMany or bulkWrite */ - remove(selector: Object, options?: CommonOptions & { single?: boolean }): Promise; + remove(selector: object, options?: CommonOptions & { single?: boolean }): Promise; /** @deprecated Use use deleteOne, deleteMany or bulkWrite */ - remove(selector: Object, options?: CommonOptions & { single?: boolean }, callback?: MongoCallback): void; + remove(selector: object, options?: CommonOptions & { single?: boolean }, callback?: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#rename */ rename(newName: string, callback: MongoCallback>): void; rename(newName: string, options?: { dropTarget?: boolean, session?: ClientSession }): Promise>; @@ -997,7 +996,7 @@ export interface Collection { updateOne(filter: FilterQuery, update: UpdateQuery | TSchema, options?: UpdateOneOptions): Promise; updateOne(filter: FilterQuery, update: UpdateQuery | TSchema, options: UpdateOneOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#watch */ - watch(pipeline?: Object[], options?: ChangeStreamOptions & { startAtClusterTime?: Timestamp, session?: ClientSession }): ChangeStream; + watch(pipeline?: object[], options?: ChangeStreamOptions & { startAtClusterTime?: Timestamp, session?: ClientSession }): ChangeStream; } export type Condition = { @@ -1023,17 +1022,17 @@ export type Condition = { $caseSensitive?: boolean; $diacraticSensitive?: boolean; }; - $where?: Object; - $geoIntersects?: Object; - $geoWithin?: Object; - $near?: Object; - $nearSphere?: Object; - $elemMatch?: Object; + $where?: object; + $geoIntersects?: object; + $geoWithin?: object; + $near?: object; + $nearSphere?: object; + $elemMatch?: object; $size?: number; - $bitsAllClear?: Object; - $bitsAllSet?: Object; - $bitsAnyClear?: Object; - $bitsAnySet?: Object; + $bitsAllClear?: object; + $bitsAllSet?: object; + $bitsAnyClear?: object; + $bitsAnySet?: object; [key: string]: any; }; @@ -1403,8 +1402,8 @@ export interface FindAndModifyWriteOpResultObject { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndReplace */ export interface FindOneAndReplaceOption extends CommonOptions { - projection?: Object; - sort?: Object; + projection?: object; + sort?: object; maxTimeMS?: number; upsert?: boolean; returnOriginal?: boolean; @@ -1412,34 +1411,21 @@ export interface FindOneAndReplaceOption extends CommonOptions { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOneAndUpdate */ export interface FindOneAndUpdateOption extends FindOneAndReplaceOption { - arrayFilters?: Object[]; + arrayFilters?: object[]; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#geoHaystackSearch */ export interface GeoHaystackSearchOptions { readPreference?: ReadPreference | string; maxDistance?: number; - search?: Object; + search?: object; limit?: number; session?: ClientSession; } -/** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#geoNear */ -export interface GeoNearOptions { - readPreference?: ReadPreference | string; - num?: number; - minDistance?: number; - maxDistance?: number; - distanceMultiplier?: number; - query?: Object; - spherical?: boolean; - uniqueDocs?: boolean; - includeLocs?: boolean; -} - /** http://mongodb.github.io/node-mongodb-native/3.1/api/Code.html */ export class Code { - constructor(code: string | Function, scope?: Object) + constructor(code: string | Function, scope?: object) code: string | Function; scope: any; } @@ -1452,9 +1438,9 @@ export interface OrderedBulkOperation { execute(options?: FSyncOptions): Promise; execute(options: FSyncOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/OrderedBulkOperation.html#find */ - find(selector: Object): FindOperatorsOrdered; + find(selector: object): FindOperatorsOrdered; /** http://mongodb.github.io/node-mongodb-native/3.1/api/OrderedBulkOperation.html#insert */ - insert(doc: Object): OrderedBulkOperation; + insert(doc: object): OrderedBulkOperation; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/BulkWriteResult.html */ @@ -1466,15 +1452,15 @@ export interface BulkWriteResult { nModified: number; nRemoved: number; - getInsertedIds(): Array; - getLastOp(): Object; - getRawResponse(): Object; - getUpsertedIdAt(index: number): Object; - getUpsertedIds(): Array; + getInsertedIds(): Array; + getLastOp(): object; + getRawResponse(): object; + getUpsertedIdAt(index: number): object; + getUpsertedIds(): Array; getWriteConcernError(): WriteConcernError; getWriteErrorAt(index: number): WriteError; getWriteErrorCount(): number; - getWriteErrors(): Array; + getWriteErrors(): Array; hasWriteErrors(): boolean; } @@ -1500,9 +1486,9 @@ export interface WriteConcernError { export interface FindOperatorsOrdered { delete(): OrderedBulkOperation; deleteOne(): OrderedBulkOperation; - replaceOne(doc: Object): OrderedBulkOperation; - update(doc: Object): OrderedBulkOperation; - updateOne(doc: Object): OrderedBulkOperation; + replaceOne(doc: object): OrderedBulkOperation; + update(doc: object): OrderedBulkOperation; + updateOne(doc: object): OrderedBulkOperation; upsert(): FindOperatorsOrdered; } @@ -1515,9 +1501,9 @@ export interface UnorderedBulkOperation { execute(options?: FSyncOptions): Promise; execute(options: FSyncOptions, callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/UnorderedBulkOperation.html#find */ - find(selector: Object): FindOperatorsUnordered; + find(selector: object): FindOperatorsUnordered; /** http://mongodb.github.io/node-mongodb-native/3.1/api/UnorderedBulkOperation.html#insert */ - insert(doc: Object): UnorderedBulkOperation; + insert(doc: object): UnorderedBulkOperation; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/FindOperatorsUnordered.html */ @@ -1525,23 +1511,23 @@ export interface FindOperatorsUnordered { length: number; remove(): UnorderedBulkOperation; removeOne(): UnorderedBulkOperation; - replaceOne(doc: Object): UnorderedBulkOperation; - update(doc: Object): UnorderedBulkOperation; - updateOne(doc: Object): UnorderedBulkOperation; + replaceOne(doc: object): UnorderedBulkOperation; + update(doc: object): UnorderedBulkOperation; + updateOne(doc: object): UnorderedBulkOperation; upsert(): FindOperatorsUnordered; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findOne */ export interface FindOneOptions { limit?: number; - sort?: Array | Object; - projection?: Object; + sort?: Array | object; + projection?: object; /** * @deprecated Use options.projection instead */ - fields?: Object; + fields?: object; skip?: number; - hint?: Object; + hint?: object; explain?: boolean; snapshot?: boolean; timeout?: boolean; @@ -1611,13 +1597,13 @@ export interface ReplaceOneOptions extends CommonOptions { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#updateOne */ export interface UpdateOneOptions extends ReplaceOneOptions { - arrayFilters?: Object[]; + arrayFilters?: object[]; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#updateMany */ export interface UpdateManyOptions extends CommonOptions { upsert?: boolean; - arrayFilters?: Object[]; + arrayFilters?: object[]; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#~updateWriteOpResult */ @@ -1638,19 +1624,23 @@ export interface ReplaceWriteOpResult extends UpdateWriteOpResult { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#mapReduce */ export interface MapReduceOptions { readPreference?: ReadPreference | string; - out?: Object; - query?: Object; - sort?: Object; + out?: object; + query?: object; + sort?: object; limit?: number; keeptemp?: boolean; finalize?: Function | string; - scope?: Object; + scope?: object; jsMode?: boolean; verbose?: boolean; bypassDocumentValidation?: boolean; session?: ClientSession; } +export type CollectionMapFunction = () => void; + +export type CollectionReduceFunction = (key: string, values: any) => any; + /** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#~WriteOpResult */ export interface WriteOpResult { ops: Array; @@ -1694,7 +1684,7 @@ export class Cursor extends Readable { explain(): Promise; explain(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#filter */ - filter(filter: Object): Cursor; + filter(filter: object): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#forEach */ forEach(iterator: IteratorCallback, callback: EndCallback): void; forEach(iterator: IteratorCallback): Promise; @@ -1702,7 +1692,7 @@ export class Cursor extends Readable { hasNext(): Promise; hasNext(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#hint */ - hint(hint: Object): Cursor; + hint(hint: string | object): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#isClosed */ isClosed(): boolean; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#limit */ @@ -1714,7 +1704,7 @@ export class Cursor extends Readable { /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#maxAwaitTimeMS */ maxAwaitTimeMS(value: number): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#maxScan */ - maxScan(maxScan: Object): Cursor; + maxScan(maxScan: object): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#maxTimeMS */ maxTimeMS(value: number): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#min */ @@ -1723,27 +1713,27 @@ export class Cursor extends Readable { next(): Promise; next(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#project */ - project(value: Object): Cursor; + project(value: object): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#read */ read(size: number): string | Buffer | void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#next */ - returnKey(returnKey: Object): Cursor; + returnKey(returnKey: object): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#rewind */ rewind(): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#setCursorOption */ - setCursorOption(field: string, value: Object): Cursor; + setCursorOption(field: string, value: object): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#setReadPreference */ setReadPreference(readPreference: string | ReadPreference): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#showRecordId */ - showRecordId(showRecordId: Object): Cursor; + showRecordId(showRecordId: object): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#skip */ skip(value: number): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#snapshot */ - snapshot(snapshot: Object): Cursor; + snapshot(snapshot: object): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#sort */ - sort(keyOrList: string | Object[] | Object, direction?: number): Cursor; + sort(keyOrList: string | object[] | object, direction?: number): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#stream */ - stream(options?: { transform?: Function }): Cursor; + stream(options?: { transform?: (document: T) => any }): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/Cursor.html#toArray */ toArray(): Promise; toArray(callback: MongoCallback): void; @@ -1787,9 +1777,9 @@ export class AggregationCursor extends Readable { explain(): Promise; explain(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#geoNear */ - geoNear(document: Object): AggregationCursor; + geoNear(document: object): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#group */ - group(document: Object): AggregationCursor; + group(document: object): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#hasNext */ hasNext(): Promise; hasNext(callback: MongoCallback): void; @@ -1798,7 +1788,7 @@ export class AggregationCursor extends Readable { /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#limit */ limit(value: number): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#match */ - match(document: Object): AggregationCursor; + match(document: object): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#maxTimeMS */ maxTimeMS(value: number): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#next */ @@ -1807,17 +1797,17 @@ export class AggregationCursor extends Readable { /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#out */ out(destination: string): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#project */ - project(document: Object): AggregationCursor; + project(document: object): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#read */ read(size: number): string | Buffer | void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#redact */ - redact(document: Object): AggregationCursor; + redact(document: object): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#rewind */ rewind(): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#setEncoding */ skip(value: number): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#sort */ - sort(document: Object): AggregationCursor; + sort(document: object): AggregationCursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/AggregationCursor.html#toArray */ toArray(): Promise; toArray(callback: MongoCallback): void; @@ -1872,7 +1862,7 @@ export class GridFSBucket { /** http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html#drop */ drop(callback?: GridFSBucketErrorCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html#find */ - find(filter?: Object, options?: GridFSBucketFindOptions): Cursor; + find(filter?: object, options?: GridFSBucketFindOptions): Cursor; /** http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html#openDownloadStream */ openDownloadStream(id: ObjectID, options?: { start: number, end: number }): GridFSBucketReadStream; /** http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html#openDownloadStreamByName */ @@ -1889,8 +1879,8 @@ export class GridFSBucket { export interface GridFSBucketOptions { bucketName?: string; chunkSizeBytes?: number; - writeConcern?: Object; - ReadPreference?: Object; + writeConcern?: object; + ReadPreference?: object; } /** http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html#~errorCallback */ @@ -1905,13 +1895,13 @@ export interface GridFSBucketFindOptions { maxTimeMS?: number; noCursorTimeout?: boolean; skip?: number; - sort?: Object; + sort?: object; } /** https://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html#openUploadStream */ export interface GridFSBucketOpenUploadStreamOptions { chunkSizeBytes?: number, - metadata?: Object, + metadata?: object, contentType?: string, aliases?: Array } @@ -1919,7 +1909,7 @@ export interface GridFSBucketOpenUploadStreamOptions { /** https://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucketReadStream.html */ export class GridFSBucketReadStream extends Readable { id: ObjectID; - constructor(chunks: Collection, files: Collection, readPreference: Object, filter: Object, options?: GridFSBucketReadStreamOptions); + constructor(chunks: Collection, files: Collection, readPreference: object, filter: object, options?: GridFSBucketReadStreamOptions); } /** https://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucketReadStream.html */ @@ -1966,7 +1956,7 @@ export interface GridFSBucketWriteStreamOptions { /** http://mongodb.github.io/node-mongodb-native/3.1/api/ChangeStream.html */ export class ChangeStream extends Readable { - constructor(changeDomain: Db | Collection, pipeline: Object[], options?: ChangeStreamOptions); + constructor(changeDomain: Db | Collection, pipeline: object[], options?: ChangeStreamOptions); /** http://mongodb.github.io/node-mongodb-native/3.1/api/ChangeStream.html#close */ close(): Promise; @@ -1984,19 +1974,19 @@ export class ChangeStream extends Readable { next(callback: MongoCallback): void; /** http://mongodb.github.io/node-mongodb-native/3.1/api/ChangeStream.html#stream */ - stream(options?: { transform: Function }): Cursor; + stream(options?: { transform?: Function }): Cursor; } export interface ChangeStreamOptions { fullDocument?: string; maxAwaitTimeMS?: number; - resumeAfter?: Object; + resumeAfter?: object; batchSize?: number; collation?: CollationDocument; readPreference?: ReadPreference; } -type GridFSBucketWriteStreamId = string | number | Object | ObjectID; +type GridFSBucketWriteStreamId = string | number | object | ObjectID; export interface LoggerOptions { /** diff --git a/types/mongodb/mongodb-tests.ts b/types/mongodb/mongodb-tests.ts index 7518a652c5..32066a1aec 100644 --- a/types/mongodb/mongodb-tests.ts +++ b/types/mongodb/mongodb-tests.ts @@ -12,8 +12,8 @@ const options: mongodb.MongoClientOptions = { wtimeout: 300, j: true, bufferMaxEntries: 1000, - readPreference: 'ReadPreference | string', - promoteValues: {}, + readPreference: true ? mongodb.ReadPreference.NEAREST : 'string', + promoteValues: true, pkFactory: {}, poolSize: 1, @@ -24,7 +24,7 @@ const options: mongodb.MongoClientOptions = { reconnectInterval: 123456, ssl: true, sslValidate: false, - checkServerIdentity: () => {}, + checkServerIdentity: true ? true : (host, cert) => { return undefined; }, sslCA: ['str'], sslCRL: ['str'], sslCert: new Buffer(999), @@ -95,8 +95,9 @@ mongodb.MongoClient.connect(connectionString, options, (err: mongodb.MongoError, cursor = cursor.addQueryModifier('', true); cursor = cursor.batchSize(1); cursor = cursor.comment(''); - cursor = cursor.filter(1); - cursor = cursor.hint({}); + cursor = cursor.filter({a: 1}); + cursor = cursor.hint({ age: 1 }); + cursor = cursor.hint('age_1'); cursor = cursor.limit(1); cursor = cursor.map((result) => {}); cursor = cursor.max(1); diff --git a/types/mongodb/tslint.json b/types/mongodb/tslint.json index e3610fefae..0f70133371 100644 --- a/types/mongodb/tslint.json +++ b/types/mongodb/tslint.json @@ -4,7 +4,15 @@ "adjacent-overload-signatures": false, "array-type": false, "arrow-return-shorthand": false, - "ban-types": false, + "ban-types": { + "options": [ + ["Object", "Avoid using the `Object` type. Did you mean `object`?"], + ["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"], + ["Number", "Avoid using the `Number` type. Did you mean `number`?"], + ["String", "Avoid using the `String` type. Did you mean `string`?"], + ["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"] + ] + }, "callable-types": false, "comment-format": false, "dt-header": false,