diff --git a/packages/grpc-js-core/src/channel-options.ts b/packages/grpc-js-core/src/channel-options.ts new file mode 100644 index 00000000..43491166 --- /dev/null +++ b/packages/grpc-js-core/src/channel-options.ts @@ -0,0 +1,25 @@ +/** + * An interface that contains options used when initializing a Channel instance. + */ +export interface ChannelOptions { + 'grpc.ssl_target_name_override': string; + 'grpc.primary_user_agent': string; + 'grpc.secondary_user_agent': string; + 'grpc.default_authority': string; + 'grpc.keepalive_time_ms': number; + 'grpc.keepalive_timeout_ms': number; + [key: string]: string|number; +} + +/** + * This is for checking provided options at runtime. This is an object for + * easier membership checking. + */ +export const recognizedOptions = { + 'grpc.ssl_target_name_override': true, + 'grpc.primary_user_agent': true, + 'grpc.secondary_user_agent': true, + 'grpc.default_authority': true, + 'grpc.keepalive_time_ms': true, + 'grpc.keepalive_timeout_ms': true +}; diff --git a/packages/grpc-js-core/src/channel.ts b/packages/grpc-js-core/src/channel.ts index 5c1b2d25..a27ef8f2 100644 --- a/packages/grpc-js-core/src/channel.ts +++ b/packages/grpc-js-core/src/channel.ts @@ -14,6 +14,7 @@ import {FilterStackFactory} from './filter-stack'; import {Metadata, MetadataObject} from './metadata'; import {MetadataStatusFilterFactory} from './metadata-status-filter'; import { Http2SubChannel } from './subchannel'; +import {ChannelOptions, recognizedOptions} from './channel-options'; const {version: clientVersion} = require('../../package'); @@ -35,19 +36,6 @@ const { HTTP2_HEADER_USER_AGENT } = http2.constants; -/** - * An interface that contains options used when initializing a Channel instance. - */ -export interface ChannelOptions { - 'grpc.ssl_target_name_override': string; - 'grpc.primary_user_agent': string; - 'grpc.secondary_user_agent': string; - 'grpc.default_authority': string; - 'grpc.keepalive_time_ms': number; - 'grpc.keepalive_timeout_ms': number; - [key: string]: string|number; -} - export enum ConnectivityState { CONNECTING, READY, @@ -212,6 +200,13 @@ export class Http2Channel extends EventEmitter implements Channel { address: string, readonly credentials: ChannelCredentials, private readonly options: Partial) { super(); + for (let option in options) { + if (options.hasOwnProperty(option)) { + if (!recognizedOptions.hasOwnProperty(option)) { + console.warn(`Unrecognized channel argument '${option}' will be ignored.`); + } + } + } if (credentials.isSecure()) { this.target = new url.URL(`https://${address}`); } else { diff --git a/packages/grpc-js-core/src/client.ts b/packages/grpc-js-core/src/client.ts index 39ff9fd9..55f63f16 100644 --- a/packages/grpc-js-core/src/client.ts +++ b/packages/grpc-js-core/src/client.ts @@ -3,10 +3,11 @@ import {URL} from 'url'; import {ClientDuplexStream, ClientDuplexStreamImpl, ClientReadableStream, ClientReadableStreamImpl, ClientUnaryCall, ClientUnaryCallImpl, ClientWritableStream, ClientWritableStreamImpl, ServiceError} from './call'; import {CallOptions, CallStream, StatusObject, WriteObject} from './call-stream'; -import {Channel, ChannelOptions, Http2Channel} from './channel'; +import {Channel, Http2Channel} from './channel'; import {ChannelCredentials} from './channel-credentials'; import {Status} from './constants'; import {Metadata} from './metadata'; +import {ChannelOptions} from './channel-options'; // This symbol must be exported (for now). // See: https://github.com/Microsoft/TypeScript/issues/20080 diff --git a/packages/grpc-js-core/src/make-client.ts b/packages/grpc-js-core/src/make-client.ts index 98f338a2..b3165ad8 100644 --- a/packages/grpc-js-core/src/make-client.ts +++ b/packages/grpc-js-core/src/make-client.ts @@ -1,7 +1,7 @@ import * as _ from 'lodash'; import {CallOptions} from './call-stream'; -import {ChannelOptions} from './channel'; +import {ChannelOptions} from './channel-options'; import {ChannelCredentials} from './channel-credentials'; import {Client, UnaryCallback} from './client'; import {Metadata} from './metadata'; diff --git a/packages/grpc-js-core/src/subchannel.ts b/packages/grpc-js-core/src/subchannel.ts index c0487ab7..bbce38c9 100644 --- a/packages/grpc-js-core/src/subchannel.ts +++ b/packages/grpc-js-core/src/subchannel.ts @@ -5,7 +5,7 @@ import { EventEmitter } from "events"; import { Metadata } from "./metadata"; import { CallStream, CallOptions, Http2CallStream } from "./call-stream"; import { EmitterAugmentation1, EmitterAugmentation0 } from "./events"; -import { ChannelOptions } from './channel'; +import { ChannelOptions } from './channel-options'; const { HTTP2_HEADER_AUTHORITY,