Skip to content

Commit

Permalink
fix(deps): drop dependency on through2 (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Jul 23, 2019
1 parent ef1aafe commit 879bf7b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 33 deletions.
3 changes: 1 addition & 2 deletions packages/google-cloud-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
"google-gax": "^1.0.0",
"protobufjs": "^6.8.6",
"pumpify": "^1.5.1",
"stream-events": "^1.0.4",
"through2": "^3.0.0"
"stream-events": "^1.0.4"
},
"devDependencies": {
"codecov": "^3.0.2",
Expand Down
34 changes: 19 additions & 15 deletions packages/google-cloud-node/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
const common = require('@google-cloud/common');
const pumpify = require('pumpify');
const streamEvents = require('stream-events');
const through = require('through2');
const {PassThrough} = require('stream');

/*!
* Return a dictionary-like object with helpers to augment the Speech
Expand Down Expand Up @@ -94,22 +94,26 @@ module.exports = () => {
// Format the user's input.
// This entails that the user sends raw audio; it is wrapped in
// the appropriate request structure.
through.obj((audioContent, _, next) => {
if (audioContent !== undefined) {
next(null, {audioContent});
return;
}

next();
new PassThrough({
objectMode: true,
transform: (audioContent, _, next) => {
if (audioContent !== undefined) {
next(null, {audioContent});
return;
}
next();
},
}),
requestStream,
through.obj((response, enc, next) => {
if (response.error) {
next(new common.util.ApiError(response.error));
return;
}

next(null, response);
new PassThrough({
objectMode: true,
transform: (response, enc, next) => {
if (response.error) {
next(new common.util.ApiError(response.error));
return;
}
next(null, response);
},
}),
]);
});
Expand Down
19 changes: 11 additions & 8 deletions packages/google-cloud-node/test/gapic-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const assert = require('assert');
const through2 = require('through2');
const {PassThrough} = require('stream');

const speechModule = require('../src');

Expand Down Expand Up @@ -311,13 +311,16 @@ function mockSimpleGrpcMethod(expectedRequest, response, error) {

function mockBidiStreamingGrpcMethod(expectedRequest, response, error) {
return () => {
const mockStream = through2.obj((chunk, enc, callback) => {
assert.deepStrictEqual(chunk, expectedRequest);
if (error) {
callback(error);
} else {
callback(null, response);
}
const mockStream = new PassThrough({
objectMode: true,
transform: (chunk, enc, callback) => {
assert.deepStrictEqual(chunk, expectedRequest);
if (error) {
callback(error);
} else {
callback(null, response);
}
},
});
return mockStream;
};
Expand Down
19 changes: 11 additions & 8 deletions packages/google-cloud-node/test/gapic-v1p1beta1.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const assert = require('assert');
const through2 = require('through2');
const {PassThrough} = require('stream');

const speechModule = require('../src');

Expand Down Expand Up @@ -311,13 +311,16 @@ function mockSimpleGrpcMethod(expectedRequest, response, error) {

function mockBidiStreamingGrpcMethod(expectedRequest, response, error) {
return () => {
const mockStream = through2.obj((chunk, enc, callback) => {
assert.deepStrictEqual(chunk, expectedRequest);
if (error) {
callback(error);
} else {
callback(null, response);
}
const mockStream = new PassThrough({
objectMode: true,
transform: (chunk, enc, callback) => {
assert.deepStrictEqual(chunk, expectedRequest);
if (error) {
callback(error);
} else {
callback(null, response);
}
},
});
return mockStream;
};
Expand Down

0 comments on commit 879bf7b

Please sign in to comment.