From 17d8fcc76fc92969b0df61397dfef10ff2189c7c Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Wed, 17 Jan 2018 18:46:52 +0100 Subject: [PATCH] Add id to mongodb gridfs upload streams (#22930) As seen in http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#openUploadStream: ```js var uploadStream = bucket.openUploadStream('test.dat'); var license = fs.readFileSync('./LICENSE'); var id = uploadStream.id; ``` The resulting stream from `openUploadStream` *has* an id. --- types/mongodb/index.d.ts | 12 ++++++++---- types/mongodb/v2/index.d.ts | 8 ++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index ae52d70e14..7fcbecf754 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -31,7 +31,7 @@ export class MongoClient extends EventEmitter { static connect(uri: string, callback: MongoCallback): void; static connect(uri: string, options?: MongoClientOptions): Promise; static connect(uri: string, options: MongoClientOptions, callback: MongoCallback): void; - /** + /** * @deprecated * http://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html#connect */ @@ -830,7 +830,7 @@ export interface CollectionAggregationOptions { collation?: Object; comment?: string session?: ClientSession; - + } /** http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html#insertMany */ @@ -1353,7 +1353,7 @@ export class GridFSBucket { /** http://mongodb.github.io/node-mongodb-native/3.0/api/GridFSBucket.html#openUploadStream */ openUploadStream(filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream; /** http://mongodb.github.io/node-mongodb-native/3.0/api/GridFSBucket.html#openUploadStreamWithId */ - openUploadStreamWithId(id: string | number | Object, filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream; + openUploadStreamWithId(id: GridFSBucketWriteStreamId, filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream; /** http://mongodb.github.io/node-mongodb-native/3.0/api/GridFSBucket.html#rename */ rename(id: ObjectID, filename: string, callback?: GridFSBucketErrorCallback): void; } @@ -1391,6 +1391,7 @@ export interface GridFSBucketOpenUploadStreamOptions { /** https://mongodb.github.io/node-mongodb-native/3.0/api/GridFSBucketReadStream.html */ export class GridFSBucketReadStream extends Readable { + id: ObjectID; constructor(chunks: Collection, files: Collection, readPreference: Object, filter: Object, options?: GridFSBucketReadStreamOptions); } @@ -1404,14 +1405,17 @@ export interface GridFSBucketReadStreamOptions { /** https://mongodb.github.io/node-mongodb-native/3.0/api/GridFSBucketWriteStream.html */ export class GridFSBucketWriteStream extends Writable { + id: GridFSBucketWriteStreamId; constructor(bucket: GridFSBucket, filename: string, options?: GridFSBucketWriteStreamOptions); } /** https://mongodb.github.io/node-mongodb-native/3.0/api/GridFSBucketWriteStream.html */ export interface GridFSBucketWriteStreamOptions { - id?: string | number | Object, + id?: GridFSBucketWriteStreamId, chunkSizeBytes?: number, w?: number, wtimeout?: number, j?: number } + +type GridFSBucketWriteStreamId = string | number | Object | ObjectID; diff --git a/types/mongodb/v2/index.d.ts b/types/mongodb/v2/index.d.ts index 6cf21c04b9..ec3e3965ba 100644 --- a/types/mongodb/v2/index.d.ts +++ b/types/mongodb/v2/index.d.ts @@ -1371,7 +1371,7 @@ export class GridFSBucket { // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#openUploadStream openUploadStream(filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream; // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#openUploadStreamWithId - openUploadStreamWithId(id: string | number | Object, filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream; + openUploadStreamWithId(id: GridFSBucketWriteStreamId, filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream; // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#rename rename(id: ObjectID, filename: string, callback?: GridFSBucketErrorCallback): void; } @@ -1409,6 +1409,7 @@ export interface GridFSBucketOpenUploadStreamOptions { // https://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucketReadStream.html export class GridFSBucketReadStream extends Readable { + id: ObjectID; constructor(chunks: Collection, files: Collection, readPreference: Object, filter: Object, options?: GridFSBucketReadStreamOptions); } @@ -1422,14 +1423,17 @@ export interface GridFSBucketReadStreamOptions { // https://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucketWriteStream.html export class GridFSBucketWriteStream extends Writable { + id: GridFSBucketWriteStreamId; constructor(bucket: GridFSBucket, filename: string, options?: GridFSBucketWriteStreamOptions); } // https://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucketWriteStream.html export interface GridFSBucketWriteStreamOptions { - id?: string | number | Object, + id?: GridFSBucketWriteStreamId, chunkSizeBytes?: number, w?: number, wtimeout?: number, j?: number } + +type GridFSBucketWriteStreamId = string | number | Object | ObjectID;