From fc032c0226b4e6375c448c06b3394623e08d7086 Mon Sep 17 00:00:00 2001 From: Bjorn Stromberg Date: Fri, 13 Sep 2019 12:31:33 +0900 Subject: [PATCH] grpc-js: Update gts and apply fixes --- packages/grpc-js/package.json | 2 +- packages/grpc-js/src/call-stream.ts | 14 +++++++++----- packages/grpc-js/src/index.ts | 15 ++++++++++++--- packages/grpc-js/src/server-call.ts | 23 ++++++++++++++--------- packages/grpc-js/src/server.ts | 5 ++++- packages/grpc-js/test/test-call-stream.ts | 2 +- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/packages/grpc-js/package.json b/packages/grpc-js/package.json index 893fd46d..a9c5c253 100644 --- a/packages/grpc-js/package.json +++ b/packages/grpc-js/package.json @@ -26,7 +26,7 @@ "@types/semver": "^6.0.1", "clang-format": "^1.0.55", "execa": "^2.0.3", - "gts": "^1.0.0", + "gts": "^1.1.0", "gulp": "^4.0.2", "gulp-mocha": "^6.0.0", "lodash": "^4.17.4", diff --git a/packages/grpc-js/src/call-stream.ts b/packages/grpc-js/src/call-stream.ts index d04eb9b6..74442e7a 100644 --- a/packages/grpc-js/src/call-stream.ts +++ b/packages/grpc-js/src/call-stream.ts @@ -343,12 +343,16 @@ export class Http2CallStream extends Duplex implements Call { * "close" events, where we will handle the error more granularly */ }); /* If the underlying TLS or TCP connection closes, we want to end the - * call with an UNAVAILABLE status to match the behavior of the other - * library. In this handler we don't wait for trailers before ending the - * call. This should ensure that this endCall happens sooner than the one - * in the stream.on('close', ...) handler. */ + * call with an UNAVAILABLE status to match the behavior of the other + * library. In this handler we don't wait for trailers before ending the + * call. This should ensure that this endCall happens sooner than the one + * in the stream.on('close', ...) handler. */ stream.session.socket.on('close', () => { - this.endCall({code: Status.UNAVAILABLE, details: 'Connection dropped', metadata: new Metadata()}); + this.endCall({ + code: Status.UNAVAILABLE, + details: 'Connection dropped', + metadata: new Metadata(), + }); }); if (!this.pendingRead) { stream.pause(); diff --git a/packages/grpc-js/src/index.ts b/packages/grpc-js/src/index.ts index 8c5851bf..b7ce2e0d 100644 --- a/packages/grpc-js/src/index.ts +++ b/packages/grpc-js/src/index.ts @@ -38,10 +38,19 @@ import { Serialize, } from './make-client'; import { Metadata } from './metadata'; -import { Server, UntypedHandleCall, UntypedServiceImplementation } from './server'; +import { + Server, + UntypedHandleCall, + UntypedServiceImplementation, +} from './server'; import { KeyCertPair, ServerCredentials } from './server-credentials'; import { StatusBuilder } from './status-builder'; -import { ServerUnaryCall, ServerReadableStream, ServerWritableStream, ServerDuplexStream } from './server-call'; +import { + ServerUnaryCall, + ServerReadableStream, + ServerWritableStream, + ServerDuplexStream, +} from './server-call'; const supportedNodeVersions = require('../../package.json').engines.node; if (!semver.satisfies(process.version, supportedNodeVersions)) { @@ -219,7 +228,7 @@ export { ServerWritableStream, ServerDuplexStream, UntypedHandleCall, - UntypedServiceImplementation + UntypedServiceImplementation, }; /* tslint:disable:no-any */ diff --git a/packages/grpc-js/src/server-call.ts b/packages/grpc-js/src/server-call.ts index c9a6b3f7..02353bbe 100644 --- a/packages/grpc-js/src/server-call.ts +++ b/packages/grpc-js/src/server-call.ts @@ -76,9 +76,11 @@ export type ServerReadableStream< export type ServerWritableStream< RequestType, ResponseType -> = ServerSurfaceCall & ObjectWritable & { request: RequestType | null }; +> = ServerSurfaceCall & + ObjectWritable & { request: RequestType | null }; export type ServerDuplexStream = ServerSurfaceCall & - ObjectReadable & ObjectWritable; + ObjectReadable & + ObjectWritable; export class ServerUnaryCallImpl extends EventEmitter implements ServerUnaryCall { @@ -497,15 +499,18 @@ export class Http2ServerCallStream< sendError(error: ServerErrorResponse | ServerStatusResponse) { const status: StatusObject = { code: Status.UNKNOWN, - details: ('message' in error) - ? error.message - : 'Unknown Error', - metadata: ('metadata' in error && error.metadata !== undefined) - ? error.metadata - : new Metadata(), + details: 'message' in error ? error.message : 'Unknown Error', + metadata: + 'metadata' in error && error.metadata !== undefined + ? error.metadata + : new Metadata(), }; - if ('code' in error && typeof error.code === 'number' && Number.isInteger(error.code)) { + if ( + 'code' in error && + typeof error.code === 'number' && + Number.isInteger(error.code) + ) { status.code = error.code; if ('details' in error && typeof error.details === 'string') { diff --git a/packages/grpc-js/src/server.ts b/packages/grpc-js/src/server.ts index a568f9c1..780b8f86 100644 --- a/packages/grpc-js/src/server.ts +++ b/packages/grpc-js/src/server.ts @@ -102,7 +102,10 @@ export class Server { throw new Error('Not implemented. Use addService() instead'); } - addService(service: ServiceDefinition, implementation: UntypedServiceImplementation): void { + addService( + service: ServiceDefinition, + implementation: UntypedServiceImplementation + ): void { if (this.started === true) { throw new Error("Can't add a service to a started server."); } diff --git a/packages/grpc-js/test/test-call-stream.ts b/packages/grpc-js/test/test-call-stream.ts index e2fa43f3..cd51674d 100644 --- a/packages/grpc-js/test/test-call-stream.ts +++ b/packages/grpc-js/test/test-call-stream.ts @@ -70,7 +70,7 @@ class ClientHttp2StreamMock extends stream.Duplex readonly sentInfoHeaders?: OutgoingHttpHeaders[] = []; readonly sentTrailers?: OutgoingHttpHeaders = undefined; // tslint:disable:no-any - session: http2.Http2Session = {socket: new EventEmitter()} as any; + session: http2.Http2Session = { socket: new EventEmitter() } as any; state: http2.StreamState = {} as any; // tslint:enable:no-any close = mockFunction;