Skip to content

Commit df49928

Browse files
fix: reduce through2 usage
1 parent 4125e06 commit df49928

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"docs-test": "linkinator docs",
3434
"fix": "gts fix",
3535
"prelint": "cd samples; npm link ../; npm install",
36-
"lint": "gts fix",
36+
"lint": "gts check",
3737
"prepare": "npm run compile",
3838
"samples-test": "cd samples/ && npm link ../ && npm install && npm test && cd ../",
3939
"snippet-test": "mocha samples/document-snippets/tests/*.js --timeout 600000",

src/table.ts

+24-19
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const concat = require('concat-stream');
2424
import * as is from 'is';
2525
// eslint-disable-next-line @typescript-eslint/no-var-requires
2626
const pumpify = require('pumpify');
27-
import * as through from 'through2';
2827

2928
import {
3029
Family,
@@ -814,19 +813,22 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
814813
rowStream = pumpify.obj([
815814
requestStream,
816815
chunkTransformer,
817-
through.obj((rowData, enc, next) => {
818-
if (
819-
chunkTransformer._destroyed ||
820-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
821-
(userStream as any)._writableState.ended
822-
) {
823-
return next();
824-
}
825-
numRequestsMade = 0;
826-
rowsRead++;
827-
const row = this.row(rowData.key);
828-
row.data = rowData.data;
829-
next(null, row);
816+
new PassThrough({
817+
objectMode: true,
818+
transform: (rowData, enc, next) => {
819+
if (
820+
chunkTransformer._destroyed ||
821+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
822+
(userStream as any)._writableState.ended
823+
) {
824+
return next();
825+
}
826+
numRequestsMade = 0;
827+
rowsRead++;
828+
const row = this.row(rowData.key);
829+
row.data = rowData.data;
830+
next(null, row);
831+
},
830832
}),
831833
]);
832834

@@ -1571,11 +1573,14 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
15711573
reqOpts,
15721574
gaxOpts: gaxOptions,
15731575
}),
1574-
through.obj((key, enc, next) => {
1575-
next(null, {
1576-
key: key.rowKey,
1577-
offset: key.offsetBytes,
1578-
});
1576+
new PassThrough({
1577+
objectMode: true,
1578+
transform: (key, enc, next) => {
1579+
next(null, {
1580+
key: key.rowKey,
1581+
offset: key.offsetBytes,
1582+
});
1583+
},
15791584
}),
15801585
]);
15811586
}

system-test/mutate-rows.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {PartialFailureError} from '@google-cloud/common/build/src/util';
2929
import {Entry} from '../src/table';
3030
import {CancellableStream, GrpcClient} from 'google-gax';
3131
import {BigtableClient} from '../src/v2';
32-
import { PassThrough } from 'stream';
32+
import {PassThrough} from 'stream';
3333

3434
const {grpc} = new GrpcClient();
3535

0 commit comments

Comments
 (0)