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

deps: drop through2 #1014

Merged
merged 3 commits into from
Apr 17, 2020
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
22 changes: 12 additions & 10 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

import {CallOptions, grpc} from 'google-gax';
import {Duplex, PassThrough} from 'stream';
import * as through2 from 'through2';
import {Duplex, PassThrough, Transform} from 'stream';
import {URL} from 'url';

import {google} from '../protos/firestore_v1_proto_api';
Expand Down Expand Up @@ -1335,14 +1334,17 @@ export class Firestore {
const stream = bidirectional
? gapicClient[methodName](callOptions)
: gapicClient[methodName](request, callOptions);
const logStream = through2.obj((chunk, enc, callback) => {
logger(
'Firestore.requestStream',
requestTag,
'Received response: %j',
chunk
);
callback();
const logStream = new Transform({
objectMode: true,
transform: (chunk, encoding, callback) => {
logger(
'Firestore.requestStream',
requestTag,
'Received response: %j',
chunk
);
callback();
},
});
stream.pipe(logStream);

Expand Down
63 changes: 30 additions & 33 deletions dev/src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as through2 from 'through2';
import {Transform} from 'stream';
import * as deepEqual from 'fast-deep-equal';

import * as proto from '../protos/firestore_v1_proto_api';
Expand Down Expand Up @@ -1865,13 +1865,11 @@ export class Query<T = DocumentData> {
}

const responseStream = this._stream();

const transform = through2.obj(function (this, chunk, encoding, callback) {
// Only send chunks with documents.
if (chunk.document) {
this.push(chunk.document);
}
callback();
const transform = new Transform({
objectMode: true,
transform(chunk, encoding, callback) {
callback(undefined, chunk.document);
},
});

responseStream.pipe(transform);
Expand Down Expand Up @@ -2000,31 +1998,30 @@ export class Query<T = DocumentData> {
*/
_stream(transactionId?: Uint8Array): NodeJS.ReadableStream {
const tag = requestTag();
// TODO(mrschmidt): Remove through2
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;

const stream = through2.obj(function (this, proto, enc, callback) {
const readTime = Timestamp.fromProto(proto.readTime);
if (proto.document) {
const document = self.firestore.snapshot_(
proto.document,
proto.readTime
);
const finalDoc = new DocumentSnapshotBuilder(
document.ref.withConverter(self._queryOptions.converter)
);
// Recreate the QueryDocumentSnapshot with the DocumentReference
// containing the original converter.
finalDoc.fieldsProto = document._fieldsProto;
finalDoc.readTime = document.readTime;
finalDoc.createTime = document.createTime;
finalDoc.updateTime = document.updateTime;
this.push({document: finalDoc.build(), readTime});
} else {
this.push({readTime});
}
callback();

const stream = new Transform({
objectMode: true,
transform: (proto, enc, callback) => {
const readTime = Timestamp.fromProto(proto.readTime);
if (proto.document) {
const document = this.firestore.snapshot_(
proto.document,
proto.readTime
);
const finalDoc = new DocumentSnapshotBuilder(
document.ref.withConverter(this._queryOptions.converter)
);
// Recreate the QueryDocumentSnapshot with the DocumentReference
// containing the original converter.
finalDoc.fieldsProto = document._fieldsProto;
finalDoc.readTime = document.readTime;
finalDoc.createTime = document.createTime;
finalDoc.updateTime = document.updateTime;
callback(undefined, {document: finalDoc.build(), readTime});
} else {
callback(undefined, {readTime});
}
},
});

this.firestore
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
"dependencies": {
"fast-deep-equal": "^3.1.1",
"functional-red-black-tree": "^1.0.1",
"google-gax": "^2.2.0",
"readable-stream": "^3.4.0",
"through2": "^3.0.0"
"google-gax": "^2.2.0"
},
"devDependencies": {
"@types/assert": "^1.4.0",
Expand Down Expand Up @@ -82,6 +80,7 @@
"proxyquire": "^2.1.3",
"sinon": "^9.0.2",
"ts-node": "^8.5.4",
"typescript": "3.8.3"
"typescript": "3.8.3",
"through2": "^3.0.0"
}
}