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", "@types/semver": "^6.0.1",
"clang-format": "^1.0.55", "clang-format": "^1.0.55",
"execa": "^2.0.3", "execa": "^2.0.3",
"gts": "^1.0.0", "gts": "^1.1.0",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-mocha": "^6.0.0", "gulp-mocha": "^6.0.0",
"lodash": "^4.17.4", "lodash": "^4.17.4",

View File

@ -348,7 +348,11 @@ export class Http2CallStream extends Duplex implements Call {
* call. This should ensure that this endCall happens sooner than the one * call. This should ensure that this endCall happens sooner than the one
* in the stream.on('close', ...) handler. */ * in the stream.on('close', ...) handler. */
stream.session.socket.on('close', () => { 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) { if (!this.pendingRead) {
stream.pause(); stream.pause();

View File

@ -38,10 +38,19 @@ import {
Serialize, Serialize,
} from './make-client'; } from './make-client';
import { Metadata } from './metadata'; import { Metadata } from './metadata';
import { Server, UntypedHandleCall, UntypedServiceImplementation } from './server'; import {
Server,
UntypedHandleCall,
UntypedServiceImplementation,
} from './server';
import { KeyCertPair, ServerCredentials } from './server-credentials'; import { KeyCertPair, ServerCredentials } from './server-credentials';
import { StatusBuilder } from './status-builder'; 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; const supportedNodeVersions = require('../../package.json').engines.node;
if (!semver.satisfies(process.version, supportedNodeVersions)) { if (!semver.satisfies(process.version, supportedNodeVersions)) {
@ -219,7 +228,7 @@ export {
ServerWritableStream, ServerWritableStream,
ServerDuplexStream, ServerDuplexStream,
UntypedHandleCall, UntypedHandleCall,
UntypedServiceImplementation UntypedServiceImplementation,
}; };
/* tslint:disable:no-any */ /* tslint:disable:no-any */

View File

@ -76,9 +76,11 @@ export type ServerReadableStream<
export type ServerWritableStream< export type ServerWritableStream<
RequestType, RequestType,
ResponseType ResponseType
> = ServerSurfaceCall & ObjectWritable<ResponseType> & { request: RequestType | null }; > = ServerSurfaceCall &
ObjectWritable<ResponseType> & { request: RequestType | null };
export type ServerDuplexStream<RequestType, ResponseType> = ServerSurfaceCall & export type ServerDuplexStream<RequestType, ResponseType> = ServerSurfaceCall &
ObjectReadable<RequestType> & ObjectWritable<ResponseType>; ObjectReadable<RequestType> &
ObjectWritable<ResponseType>;
export class ServerUnaryCallImpl<RequestType, ResponseType> extends EventEmitter export class ServerUnaryCallImpl<RequestType, ResponseType> extends EventEmitter
implements ServerUnaryCall<RequestType, ResponseType> { implements ServerUnaryCall<RequestType, ResponseType> {
@ -497,15 +499,18 @@ export class Http2ServerCallStream<
sendError(error: ServerErrorResponse | ServerStatusResponse) { sendError(error: ServerErrorResponse | ServerStatusResponse) {
const status: StatusObject = { const status: StatusObject = {
code: Status.UNKNOWN, code: Status.UNKNOWN,
details: ('message' in error) details: 'message' in error ? error.message : 'Unknown Error',
? error.message metadata:
: 'Unknown Error', 'metadata' in error && error.metadata !== undefined
metadata: ('metadata' in error && error.metadata !== undefined)
? error.metadata ? error.metadata
: new 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; status.code = error.code;
if ('details' in error && typeof error.details === 'string') { 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'); throw new Error('Not implemented. Use addService() instead');
} }
addService(service: ServiceDefinition, implementation: UntypedServiceImplementation): void { addService(
service: ServiceDefinition,
implementation: UntypedServiceImplementation
): void {
if (this.started === true) { if (this.started === true) {
throw new Error("Can't add a service to a started server."); throw new Error("Can't add a service to a started server.");
} }