Skip to content

Commit

Permalink
grpc-js: Fix credentials type
Browse files Browse the repository at this point in the history
  • Loading branch information
greenboxal committed Jun 4, 2020
1 parent 136626a commit 219ca8c
Showing 1 changed file with 40 additions and 53 deletions.
93 changes: 40 additions & 53 deletions packages/grpc-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,65 +69,52 @@ if (!semver.satisfies(process.version, supportedNodeVersions)) {
throw new Error(`@grpc/grpc-js only works on Node ${supportedNodeVersions}`);
}

interface IndexedObject {
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
[key: number]: any; // eslint-disable-line @typescript-eslint/no-explicit-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]; // eslint-disable-line @typescript-eslint/no-explicit-any
if (typeof property === 'function') {
result[propName] = property;
}
}
}
return result;
}

export { OAuth2Client };

/**** Client Credentials ****/

// Using assign only copies enumerable properties, which is what we want
export const credentials = mixin(
{
/**
* Combine a ChannelCredentials with any number of CallCredentials into a
* single ChannelCredentials object.
* @param channelCredentials The ChannelCredentials object.
* @param callCredentials Any number of CallCredentials objects.
* @return The resulting ChannelCredentials object.
*/
combineChannelCredentials: (
channelCredentials: ChannelCredentials,
...callCredentials: CallCredentials[]
): ChannelCredentials => {
return callCredentials.reduce(
(acc, other) => acc.compose(other),
channelCredentials
);
},

/**
* Combine any number of CallCredentials into a single CallCredentials
* object.
* @param first The first CallCredentials object.
* @param additional Any number of additional CallCredentials objects.
* @return The resulting CallCredentials object.
*/
combineCallCredentials: (
first: CallCredentials,
...additional: CallCredentials[]
): CallCredentials => {
return additional.reduce((acc, other) => acc.compose(other), first);
},
export const credentials = {
/**
* Combine a ChannelCredentials with any number of CallCredentials into a
* single ChannelCredentials object.
* @param channelCredentials The ChannelCredentials object.
* @param callCredentials Any number of CallCredentials objects.
* @return The resulting ChannelCredentials object.
*/
combineChannelCredentials: (
channelCredentials: ChannelCredentials,
...callCredentials: CallCredentials[]
): ChannelCredentials => {
return callCredentials.reduce(
(acc, other) => acc.compose(other),
channelCredentials
);
},
ChannelCredentials,
CallCredentials
);

/**
* Combine any number of CallCredentials into a single CallCredentials
* object.
* @param first The first CallCredentials object.
* @param additional Any number of additional CallCredentials objects.
* @return The resulting CallCredentials object.
*/
combineCallCredentials: (
first: CallCredentials,
...additional: CallCredentials[]
): CallCredentials => {
return additional.reduce((acc, other) => acc.compose(other), first);
},

// from channel-credentials.ts
createInsecure: ChannelCredentials.createInsecure,
createSsl: ChannelCredentials.createSsl,

// from call-credentials.ts
createFromMetadataGenerator: CallCredentials.createFromMetadataGenerator,
createFromGoogleCredential: CallCredentials.createFromGoogleCredential,
createEmpty: CallCredentials.createEmpty,
};

/**** Metadata ****/

Expand Down

0 comments on commit 219ca8c

Please sign in to comment.