Skip to content

Commit

Permalink
feat: remove through2 dependency (#770)
Browse files Browse the repository at this point in the history
* drop: through2 dependency
  • Loading branch information
laljikanjareeya committed Jul 22, 2020
1 parent 3d046b5 commit 29c85d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -62,8 +62,7 @@
"long": "^4.0.0",
"pumpify": "^2.0.0",
"retry-request": "^4.0.0",
"stream-events": "^1.0.2",
"through2": "^3.0.0"
"stream-events": "^1.0.2"
},
"devDependencies": {
"@types/escape-string-regexp": "^1.0.0",
Expand All @@ -75,7 +74,6 @@
"@types/proxyquire": "^1.3.28",
"@types/pumpify": "^1.4.1",
"@types/sinon": "^9.0.0",
"@types/through2": "^2.0.34",
"@types/uuid": "^8.0.0",
"c8": "^7.1.0",
"codecov": "^3.6.5",
Expand Down
33 changes: 19 additions & 14 deletions src/table.ts
Expand Up @@ -16,14 +16,13 @@ import {promisifyAll} from '@google-cloud/promisify';
import arrify = require('arrify');
import {ServiceError} from 'google-gax';
import {decorateStatus} from './decorateStatus';
import {PassThrough} from 'stream';
import {PassThrough, Transform} from 'stream';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const concat = require('concat-stream');
import * as is from 'is';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pumpify = require('pumpify');
import * as through from 'through2';

import {
Family,
Expand Down Expand Up @@ -810,10 +809,8 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);

requestStream!.on('request', () => numRequestsMade++);

rowStream = pumpify.obj([
requestStream,
chunkTransformer,
through.obj((rowData, enc, next) => {
const toRowStream = new Transform({
transform: (rowData, _, next) => {
if (
chunkTransformer._destroyed ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -826,8 +823,11 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
const row = this.row(rowData.key);
row.data = rowData.data;
next(null, row);
}),
]);
},
objectMode: true,
});

rowStream = pumpify.obj([requestStream, chunkTransformer, toRowStream]);

rowStream.on('error', (error: ServiceError) => {
if (IGNORED_STATUS_CODES.has(error.code)) {
Expand Down Expand Up @@ -1561,19 +1561,24 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
appProfileId: this.bigtable.appProfileId,
};

const rowKeysStream = new Transform({
transform(key, enc, next) {
next(null, {
key: key.rowKey,
offset: key.offsetBytes,
});
},
objectMode: true,
});

return pumpify.obj([
this.bigtable.request({
client: 'BigtableClient',
method: 'sampleRowKeys',
reqOpts,
gaxOpts: gaxOptions,
}),
through.obj((key, enc, next) => {
next(null, {
key: key.rowKey,
offset: key.offsetBytes,
});
}),
rowKeysStream,
]);
}

Expand Down
16 changes: 0 additions & 16 deletions system-test/read-rows-acceptance-test.json
Expand Up @@ -378,14 +378,6 @@
"name": "invalid - duplicate row key",
"chunks_base64": ["CgRSS18xEgMKAUEaAwoBQyBkMgl2YWx1ZS1WQUxIAQ==", "CgRSS18xEgMKAUIaAwoBRCBkMgl2YWx1ZS1WQUxIAQ=="],
"results": [{
"fm": "A",
"rk": "RK_1",
"qual": "C",
"label": "",
"error": false,
"value": "value-VAL",
"ts": 100
}, {
"fm": "",
"rk": "",
"qual": "",
Expand All @@ -399,14 +391,6 @@
"name": "invalid - new row missing row key",
"chunks_base64": ["CgRSS18xEgMKAUEaAwoBQyBkMgl2YWx1ZS1WQUxIAQ==", "IGQyCXZhbHVlLVZBTEgB"],
"results": [{
"fm": "A",
"rk": "RK_1",
"qual": "C",
"label": "",
"error": false,
"value": "value-VAL",
"ts": 100
}, {
"fm": "",
"rk": "",
"qual": "",
Expand Down

0 comments on commit 29c85d8

Please sign in to comment.