diff --git a/packages/grpc-js/package.json b/packages/grpc-js/package.json index 6f5b1f3a..aa2d6bfd 100644 --- a/packages/grpc-js/package.json +++ b/packages/grpc-js/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/grpc-js", - "version": "0.7.2", + "version": "0.7.3", "description": "gRPC Library for Node - pure JS implementation", "homepage": "https://grpc.io/", "repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js", diff --git a/packages/grpc-js/src/channel.ts b/packages/grpc-js/src/channel.ts index ad45f654..cdbc81a2 100644 --- a/packages/grpc-js/src/channel.ts +++ b/packages/grpc-js/src/channel.ts @@ -110,9 +110,9 @@ export interface Channel { */ createCall( method: string, - deadline: Deadline | null | undefined, + deadline: Deadline, host: string | null | undefined, - parentCall: Call | null | undefined, + parentCall: any, propagateFlags: number | null | undefined ): Call; } @@ -140,6 +140,15 @@ export class ChannelImplementation implements Channel { private readonly credentials: ChannelCredentials, 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 grpc.use_local_subchannel_pool channel option means. */ this.subchannelPool = getSubchannelPool( @@ -430,11 +439,17 @@ export class ChannelImplementation implements Channel { createCall( method: string, - deadline: Deadline | null | undefined, + deadline: Deadline, host: string | null | undefined, - parentCall: Call | null | undefined, + parentCall: any, propagateFlags: number | null | undefined ): 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) { throw new Error('Channel has been shut down'); } @@ -451,8 +466,7 @@ export class ChannelImplementation implements Channel { deadline ); const finalOptions: CallStreamOptions = { - deadline: - deadline === null || deadline === undefined ? Infinity : deadline, + deadline: deadline, flags: propagateFlags || 0, host: host || this.defaultAuthority, parentCall: parentCall || null, diff --git a/packages/grpc-js/src/client.ts b/packages/grpc-js/src/client.ts index 77a5571f..54679034 100644 --- a/packages/grpc-js/src/client.ts +++ b/packages/grpc-js/src/client.ts @@ -48,6 +48,7 @@ import { InterceptorArguments, InterceptingCallInterface, } from './client-interceptors'; +import { ServerUnaryCall, ServerReadableStream, ServerWritableStream, ServerDuplexStream } from './server-call'; const CHANNEL_SYMBOL = Symbol(); const INTERCEPTOR_SYMBOL = Symbol(); @@ -61,8 +62,7 @@ export interface UnaryCallback { export interface CallOptions { deadline?: Deadline; host?: string; - /* There should be a parent option here that will accept a server call, - * but the server is not yet implemented so it makes no sense to have it */ + parent?: ServerUnaryCall | ServerReadableStream | ServerWritableStream | ServerDuplexStream propagate_flags?: number; credentials?: CallCredentials; interceptors?: Interceptor[]; diff --git a/packages/grpc-js/src/index.ts b/packages/grpc-js/src/index.ts index a80b08b9..941174c0 100644 --- a/packages/grpc-js/src/index.ts +++ b/packages/grpc-js/src/index.ts @@ -28,7 +28,7 @@ import { CallCredentials } from './call-credentials'; import { Deadline, StatusObject } from './call-stream'; import { Channel, ConnectivityState, ChannelImplementation } from './channel'; import { ChannelCredentials } from './channel-credentials'; -import { CallOptions, Client } from './client'; +import { CallOptions, Client, CallInvocationTransformer, CallProperties } from './client'; import { LogVerbosity, Status } from './constants'; import * as logging from './logging'; import { @@ -199,7 +199,10 @@ export { loadPackageDefinition, makeClientConstructor, makeClientConstructor as makeGenericClientConstructor, + CallProperties, + CallInvocationTransformer, ChannelImplementation as Channel, + Channel as ChannelInterface }; /**