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

fix(NODE-3559): incorrect GridFS stream type #2981

Merged
merged 1 commit into from
Sep 13, 2021
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
2 changes: 1 addition & 1 deletion src/gridfs/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface GridFSBucketReadStreamPrivate {
* Do not instantiate this class directly. Use `openDownloadStream()` instead.
* @public
*/
export class GridFSBucketReadStream extends Readable {
export class GridFSBucketReadStream extends Readable implements NodeJS.ReadableStream {
/** @internal */
s: GridFSBucketReadStreamPrivate;

Expand Down
18 changes: 11 additions & 7 deletions src/gridfs/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
* Do not instantiate this class directly. Use `openUploadStream()` instead.
* @public
*/
export class GridFSBucketWriteStream extends Writable {
export class GridFSBucketWriteStream extends Writable implements NodeJS.WritableStream {
bucket: GridFSBucket;
chunks: Collection<GridFSChunk>;
filename: string;
Expand Down Expand Up @@ -118,12 +118,16 @@ export class GridFSBucketWriteStream extends Writable {
* @param callback - Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.
* @returns False if this write required flushing a chunk to MongoDB. True otherwise.
*/
write(chunk: Buffer): boolean;
write(chunk: Buffer, callback: Callback<void>): boolean;
write(chunk: Buffer, encoding: BufferEncoding | undefined): boolean;
write(chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback<void>): boolean;
write(chunk: Buffer | string): boolean;
write(chunk: Buffer | string, callback: Callback<void>): boolean;
write(chunk: Buffer | string, encoding: BufferEncoding | undefined): boolean;
write(
chunk: Buffer,
chunk: Buffer | string,
encoding: BufferEncoding | undefined,
callback: Callback<void>
): boolean;
write(
chunk: Buffer | string,
encodingOrCallback?: Callback<void> | BufferEncoding,
callback?: Callback<void>
): boolean {
Expand Down Expand Up @@ -417,7 +421,7 @@ function createFilesDoc(

function doWrite(
stream: GridFSBucketWriteStream,
chunk: Buffer,
chunk: Buffer | string,
encoding?: BufferEncoding,
callback?: Callback<void>
): boolean {
Expand Down
13 changes: 13 additions & 0 deletions test/types/gridfs_types.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Readable } from 'stream';
import { expectType } from 'tsd';
import type { GridFSBucket, GridFSBucketWriteStream } from '../../src';

(function test(bucket: GridFSBucket) {
const readable = new Readable();

const uploadStream = bucket.openUploadStream('test');
expectType<GridFSBucketWriteStream>(uploadStream);

// should be pipeable as a WriteStream
readable.pipe(uploadStream);
})({} as GridFSBucket);