From 3edea49bb3b9340a24725fac97b88f069edbf61e Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 30 May 2018 15:57:58 -0700 Subject: [PATCH] Compile grpc-js to ES6 to improve debugging --- packages/grpc-js-core/src/index.ts | 24 ++++++++++++++++++++---- packages/grpc-js-core/tsconfig.json | 3 ++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/grpc-js-core/src/index.ts b/packages/grpc-js-core/src/index.ts index 9b6cea51..e8ec5834 100644 --- a/packages/grpc-js-core/src/index.ts +++ b/packages/grpc-js-core/src/index.ts @@ -8,6 +8,24 @@ import {Status} from './constants'; import {loadPackageDefinition, makeClientConstructor} from './make-client'; import {Metadata} from './metadata'; +interface IndexedObject { + [key: string]: any; + [key: number]: any; +} + +function mixin(...sources: IndexedObject[]) { + const result: {[key: string]: Function} = {}; + for(const source of sources) { + for(const propName of Object.getOwnPropertyNames(source)) { + const property: any = source[propName]; + if (typeof property === 'function') { + result[propName] = property; + } + } + } + return result; +} + export interface OAuth2Client { getRequestMetadata: (url: string, callback: (err: Error|null, headers?: { Authorization: string @@ -17,8 +35,7 @@ export interface OAuth2Client { /**** Client Credentials ****/ // Using assign only copies enumerable properties, which is what we want -export const credentials = Object.assign( - { +export const credentials = mixin({ /** * Create a gRPC credential from a Google credential object. * @param googleCredentials The authentication client to use. @@ -67,8 +84,7 @@ export const credentials = Object.assign( CallCredentials => { return additional.reduce((acc, other) => acc.compose(other), first); } - }, - ChannelCredentials, CallCredentials); + }, ChannelCredentials, CallCredentials); /**** Metadata ****/ diff --git a/packages/grpc-js-core/tsconfig.json b/packages/grpc-js-core/tsconfig.json index c47ad1de..807ef662 100644 --- a/packages/grpc-js-core/tsconfig.json +++ b/packages/grpc-js-core/tsconfig.json @@ -2,7 +2,8 @@ "extends": "./node_modules/gts/tsconfig-google.json", "compilerOptions": { "rootDir": ".", - "outDir": "build" + "outDir": "build", + "target": "es6" }, "include": [ "src/*.ts",