Skip to content

Commit 931a7c3

Browse files
authored
Merge pull request grpc#1459 from greenboxal/fix-credentials-type
grpc-js: Fix credentials type
2 parents f4cbe02 + 219ca8c commit 931a7c3

File tree

1 file changed

+40
-53
lines changed

1 file changed

+40
-53
lines changed

packages/grpc-js/src/index.ts

+40-53
Original file line numberDiff line numberDiff line change
@@ -69,65 +69,52 @@ if (!semver.satisfies(process.version, supportedNodeVersions)) {
6969
throw new Error(`@grpc/grpc-js only works on Node ${supportedNodeVersions}`);
7070
}
7171

72-
interface IndexedObject {
73-
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
74-
[key: number]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
75-
}
76-
77-
function mixin(...sources: IndexedObject[]) {
78-
const result: { [key: string]: Function } = {};
79-
for (const source of sources) {
80-
for (const propName of Object.getOwnPropertyNames(source)) {
81-
const property: any = source[propName]; // eslint-disable-line @typescript-eslint/no-explicit-any
82-
if (typeof property === 'function') {
83-
result[propName] = property;
84-
}
85-
}
86-
}
87-
return result;
88-
}
89-
9072
export { OAuth2Client };
9173

9274
/**** Client Credentials ****/
9375

9476
// Using assign only copies enumerable properties, which is what we want
95-
export const credentials = mixin(
96-
{
97-
/**
98-
* Combine a ChannelCredentials with any number of CallCredentials into a
99-
* single ChannelCredentials object.
100-
* @param channelCredentials The ChannelCredentials object.
101-
* @param callCredentials Any number of CallCredentials objects.
102-
* @return The resulting ChannelCredentials object.
103-
*/
104-
combineChannelCredentials: (
105-
channelCredentials: ChannelCredentials,
106-
...callCredentials: CallCredentials[]
107-
): ChannelCredentials => {
108-
return callCredentials.reduce(
109-
(acc, other) => acc.compose(other),
110-
channelCredentials
111-
);
112-
},
113-
114-
/**
115-
* Combine any number of CallCredentials into a single CallCredentials
116-
* object.
117-
* @param first The first CallCredentials object.
118-
* @param additional Any number of additional CallCredentials objects.
119-
* @return The resulting CallCredentials object.
120-
*/
121-
combineCallCredentials: (
122-
first: CallCredentials,
123-
...additional: CallCredentials[]
124-
): CallCredentials => {
125-
return additional.reduce((acc, other) => acc.compose(other), first);
126-
},
77+
export const credentials = {
78+
/**
79+
* Combine a ChannelCredentials with any number of CallCredentials into a
80+
* single ChannelCredentials object.
81+
* @param channelCredentials The ChannelCredentials object.
82+
* @param callCredentials Any number of CallCredentials objects.
83+
* @return The resulting ChannelCredentials object.
84+
*/
85+
combineChannelCredentials: (
86+
channelCredentials: ChannelCredentials,
87+
...callCredentials: CallCredentials[]
88+
): ChannelCredentials => {
89+
return callCredentials.reduce(
90+
(acc, other) => acc.compose(other),
91+
channelCredentials
92+
);
12793
},
128-
ChannelCredentials,
129-
CallCredentials
130-
);
94+
95+
/**
96+
* Combine any number of CallCredentials into a single CallCredentials
97+
* object.
98+
* @param first The first CallCredentials object.
99+
* @param additional Any number of additional CallCredentials objects.
100+
* @return The resulting CallCredentials object.
101+
*/
102+
combineCallCredentials: (
103+
first: CallCredentials,
104+
...additional: CallCredentials[]
105+
): CallCredentials => {
106+
return additional.reduce((acc, other) => acc.compose(other), first);
107+
},
108+
109+
// from channel-credentials.ts
110+
createInsecure: ChannelCredentials.createInsecure,
111+
createSsl: ChannelCredentials.createSsl,
112+
113+
// from call-credentials.ts
114+
createFromMetadataGenerator: CallCredentials.createFromMetadataGenerator,
115+
createFromGoogleCredential: CallCredentials.createFromGoogleCredential,
116+
createEmpty: CallCredentials.createEmpty,
117+
};
131118

132119
/**** Metadata ****/
133120

0 commit comments

Comments
 (0)