diff --git a/dev/src/index.ts b/dev/src/index.ts index 4477dec15..05ae3a9ac 100644 --- a/dev/src/index.ts +++ b/dev/src/index.ts @@ -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'; @@ -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); diff --git a/dev/src/reference.ts b/dev/src/reference.ts index fc87e3a37..184b37889 100644 --- a/dev/src/reference.ts +++ b/dev/src/reference.ts @@ -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'; @@ -1865,13 +1865,11 @@ export class Query { } 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); @@ -2000,31 +1998,30 @@ export class Query { */ _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 diff --git a/package.json b/package.json index 2c69274a6..413382302 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } }