Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: drop through2
Browse files Browse the repository at this point in the history
schmidt-sebastian committed Apr 13, 2020
1 parent 28d3549 commit 896963d
Showing 3 changed files with 44 additions and 46 deletions.
22 changes: 12 additions & 10 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
@@ -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);

61 changes: 29 additions & 32 deletions dev/src/reference.ts
Original file line number Diff line number Diff line change
@@ -14,8 +14,8 @@
* limitations under the License.
*/

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

import * as proto from '../protos/firestore_v1_proto_api';

@@ -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);
@@ -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});

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});
}
}
callback();
});

this.firestore
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
@@ -80,6 +78,7 @@
"protobufjs": "^6.8.6",
"proxyquire": "^2.1.3",
"ts-node": "^8.5.4",
"typescript": "3.8.3"
"typescript": "3.8.3",
"through2": "^3.0.0"
}
}

0 comments on commit 896963d

Please sign in to comment.