grpc-js: Update some types and type checks for compatibility with grpc-gcp

This commit is contained in:
Michael Lumish 2020-03-23 14:09:20 -07:00
parent 11e2e048b5
commit 91dc475dd5
4 changed files with 27 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@grpc/grpc-js", "name": "@grpc/grpc-js",
"version": "0.7.2", "version": "0.7.3",
"description": "gRPC Library for Node - pure JS implementation", "description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/", "homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js", "repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

View File

@ -110,9 +110,9 @@ export interface Channel {
*/ */
createCall( createCall(
method: string, method: string,
deadline: Deadline | null | undefined, deadline: Deadline,
host: string | null | undefined, host: string | null | undefined,
parentCall: Call | null | undefined, parentCall: any,
propagateFlags: number | null | undefined propagateFlags: number | null | undefined
): Call; ): Call;
} }
@ -140,6 +140,15 @@ export class ChannelImplementation implements Channel {
private readonly credentials: ChannelCredentials, private readonly credentials: ChannelCredentials,
private readonly options: ChannelOptions private readonly options: ChannelOptions
) { ) {
if (typeof target !== 'string') {
throw new TypeError('Channel target must be a string');
}
if (!(credentials instanceof ChannelCredentials)) {
throw new TypeError('Channel credentials must be a ChannelCredentials object');
}
if ((typeof options !== 'object') || !Object.values(options).every(value => typeof value === 'string' || typeof value === 'number')) {
throw new TypeError('Channel options must be an object with string or number values');
}
/* The global boolean parameter to getSubchannelPool has the inverse meaning to what /* The global boolean parameter to getSubchannelPool has the inverse meaning to what
* the grpc.use_local_subchannel_pool channel option means. */ * the grpc.use_local_subchannel_pool channel option means. */
this.subchannelPool = getSubchannelPool( this.subchannelPool = getSubchannelPool(
@ -430,11 +439,17 @@ export class ChannelImplementation implements Channel {
createCall( createCall(
method: string, method: string,
deadline: Deadline | null | undefined, deadline: Deadline,
host: string | null | undefined, host: string | null | undefined,
parentCall: Call | null | undefined, parentCall: any,
propagateFlags: number | null | undefined propagateFlags: number | null | undefined
): Call { ): Call {
if (typeof method !== 'string') {
throw new TypeError('Channel#createCall: method must be a string');
}
if (!(typeof deadline === 'number' || deadline instanceof Date)) {
throw new TypeError('Channel#createCall: deadline must be a number or Date');
}
if (this.connectivityState === ConnectivityState.SHUTDOWN) { if (this.connectivityState === ConnectivityState.SHUTDOWN) {
throw new Error('Channel has been shut down'); throw new Error('Channel has been shut down');
} }
@ -451,8 +466,7 @@ export class ChannelImplementation implements Channel {
deadline deadline
); );
const finalOptions: CallStreamOptions = { const finalOptions: CallStreamOptions = {
deadline: deadline: deadline,
deadline === null || deadline === undefined ? Infinity : deadline,
flags: propagateFlags || 0, flags: propagateFlags || 0,
host: host || this.defaultAuthority, host: host || this.defaultAuthority,
parentCall: parentCall || null, parentCall: parentCall || null,

View File

@ -48,6 +48,7 @@ import {
InterceptorArguments, InterceptorArguments,
InterceptingCallInterface, InterceptingCallInterface,
} from './client-interceptors'; } from './client-interceptors';
import { ServerUnaryCall, ServerReadableStream, ServerWritableStream, ServerDuplexStream } from './server-call';
const CHANNEL_SYMBOL = Symbol(); const CHANNEL_SYMBOL = Symbol();
const INTERCEPTOR_SYMBOL = Symbol(); const INTERCEPTOR_SYMBOL = Symbol();
@ -61,8 +62,7 @@ export interface UnaryCallback<ResponseType> {
export interface CallOptions { export interface CallOptions {
deadline?: Deadline; deadline?: Deadline;
host?: string; host?: string;
/* There should be a parent option here that will accept a server call, parent?: ServerUnaryCall<any, any> | ServerReadableStream<any, any> | ServerWritableStream<any, any> | ServerDuplexStream<any, any>
* but the server is not yet implemented so it makes no sense to have it */
propagate_flags?: number; propagate_flags?: number;
credentials?: CallCredentials; credentials?: CallCredentials;
interceptors?: Interceptor[]; interceptors?: Interceptor[];

View File

@ -28,7 +28,7 @@ import { CallCredentials } from './call-credentials';
import { Deadline, StatusObject } from './call-stream'; import { Deadline, StatusObject } from './call-stream';
import { Channel, ConnectivityState, ChannelImplementation } from './channel'; import { Channel, ConnectivityState, ChannelImplementation } from './channel';
import { ChannelCredentials } from './channel-credentials'; import { ChannelCredentials } from './channel-credentials';
import { CallOptions, Client } from './client'; import { CallOptions, Client, CallInvocationTransformer, CallProperties } from './client';
import { LogVerbosity, Status } from './constants'; import { LogVerbosity, Status } from './constants';
import * as logging from './logging'; import * as logging from './logging';
import { import {
@ -199,7 +199,10 @@ export {
loadPackageDefinition, loadPackageDefinition,
makeClientConstructor, makeClientConstructor,
makeClientConstructor as makeGenericClientConstructor, makeClientConstructor as makeGenericClientConstructor,
CallProperties,
CallInvocationTransformer,
ChannelImplementation as Channel, ChannelImplementation as Channel,
Channel as ChannelInterface
}; };
/** /**