grpc-js: Update gts and apply fixes

This commit is contained in:
Bjorn Stromberg 2019-09-13 12:31:33 +09:00
parent a5e12074e2
commit fc032c0226
6 changed files with 41 additions and 20 deletions

View File

@ -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",

View File

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

View File

@ -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 */

View File

@ -76,9 +76,11 @@ export type ServerReadableStream<
export type ServerWritableStream<
RequestType,
ResponseType
> = ServerSurfaceCall & ObjectWritable<ResponseType> & { request: RequestType | null };
> = ServerSurfaceCall &
ObjectWritable<ResponseType> & { request: RequestType | null };
export type ServerDuplexStream<RequestType, ResponseType> = ServerSurfaceCall &
ObjectReadable<RequestType> & ObjectWritable<ResponseType>;
ObjectReadable<RequestType> &
ObjectWritable<ResponseType>;
export class ServerUnaryCallImpl<RequestType, ResponseType> extends EventEmitter
implements ServerUnaryCall<RequestType, ResponseType> {
@ -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') {

View File

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

View File

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