Skip to content

Commit a54be7a

Browse files
author
Thomas Reggi
authored
feat!: remove Cursor#transformStream
NODE-2324
1 parent ae1fc1a commit a54be7a

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

src/cursor/cursor.ts

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { emitDeprecatedOptionWarning } from '../utils';
22
import { ReadPreference, ReadPreferenceLike } from '../read_preference';
3-
import { Transform, PassThrough, Readable } from 'stream';
3+
import { Readable } from 'stream';
44
import { deprecate } from 'util';
55
import { MongoError, AnyError } from '../error';
66
import {
@@ -886,32 +886,9 @@ export class Cursor<
886886

887887
/** Return a modified Readable stream including a possible transform method. */
888888
stream(options?: CursorStreamOptions): CursorStream {
889-
// TODO: replace this method with transformStream in next major release
890889
return new CursorStream(this, options);
891890
}
892891

893-
/**
894-
* Return a modified Readable stream that applies a given transform function, if supplied. If none supplied,
895-
* returns a stream of unmodified docs.
896-
*/
897-
transformStream(options?: CursorStreamOptions): Transform {
898-
const streamOptions: typeof options = options || {};
899-
if (typeof streamOptions.transform === 'function') {
900-
const stream = new Transform({
901-
objectMode: true,
902-
transform(chunk, encoding, callback) {
903-
if (streamOptions.transform) {
904-
this.push(streamOptions.transform(chunk));
905-
}
906-
callback();
907-
}
908-
});
909-
return this.stream().pipe(stream);
910-
}
911-
912-
return this.stream(options).pipe(new PassThrough({ objectMode: true }));
913-
}
914-
915892
/**
916893
* Execute the explain for the cursor
917894
*

test/functional/cursor.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4121,7 +4121,7 @@ describe('Cursor', function () {
41214121
.then(() => collection.insertMany(docs))
41224122
.then(() => {
41234123
cursor = collection.find();
4124-
return cursor.transformStream(transformParam);
4124+
return cursor.stream(transformParam);
41254125
})
41264126
.then(stream => {
41274127
stream.on('data', function (doc) {
@@ -4141,7 +4141,7 @@ describe('Cursor', function () {
41414141
});
41424142
};
41434143

4144-
it('transformStream should apply the supplied transformation function to each document in the stream', function (done) {
4144+
it('stream should apply the supplied transformation function to each document in the stream', function (done) {
41454145
const configuration = this.configuration;
41464146
const client = configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false });
41474147
const expectedDocs = [
@@ -4152,15 +4152,15 @@ describe('Cursor', function () {
41524152
const config = {
41534153
client: client,
41544154
configuration: configuration,
4155-
collectionName: 'transformStream-test-transform',
4155+
collectionName: 'stream-test-transform',
41564156
transformFunc: doc => ({ _id: doc._id, b: doc.a.b, c: doc.a.c }),
41574157
expectedSet: new Set(expectedDocs)
41584158
};
41594159

41604160
testTransformStream(config, done);
41614161
});
41624162

4163-
it('transformStream should return a stream of unmodified docs if no transform function applied', function (done) {
4163+
it('stream should return a stream of unmodified docs if no transform function applied', function (done) {
41644164
const configuration = this.configuration;
41654165
const client = configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: false });
41664166
const expectedDocs = [

0 commit comments

Comments
 (0)