Skip to content

Commit 312bc14

Browse files
fix util for changes to channel-credentials.ts in grpc-js
Signed-off-by: Kartikay <kartikay_2101ce32@iitp.ac.in>
1 parent 4814269 commit 312bc14

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"build-js-client": "tsc --declaration false --outDir js-dist"
3939
},
4040
"dependencies": {
41-
"@grpc/grpc-js": "~1.12.5",
41+
"@grpc/grpc-js": "^1.12.5",
4242
"@protobuf-ts/runtime": "^2.9.6",
4343
"@protobuf-ts/runtime-rpc": "^2.9.6",
4444
"google-protobuf": "^3.21.4"

src/util.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import * as grpc from "@grpc/grpc-js";
22
import { NextCall } from "@grpc/grpc-js/build/src/client-interceptors.js";
33
import { ConnectionOptions } from "tls";
4+
import * as net from "net";
5+
import { SecureConnector } from "@grpc/grpc-js/build/src/channel-credentials.js";
46

57
// NOTE: Copied from channel-credentials.ts in gRPC Node package because its not exported:
68
// https://github.com/grpc/grpc-node/blob/3106057f5ad8f79a71d2ae411e116ad308a2e835/packages/grpc-js/src/call-credentials.ts#L143
79
class ComposedChannelCredentials extends grpc.ChannelCredentials {
810
constructor(
911
private channelCredentials: KnownInsecureChannelCredentialsImpl,
10-
callCreds: grpc.CallCredentials
12+
private callCreds: grpc.CallCredentials
1113
) {
12-
super(callCreds);
14+
super();
1315
}
1416
compose(callCredentials: grpc.CallCredentials) {
1517
const combinedCallCredentials =
16-
this.callCredentials.compose(callCredentials);
18+
this.callCreds.compose(callCredentials);
1719
return new ComposedChannelCredentials(
1820
this.channelCredentials,
1921
combinedCallCredentials
@@ -26,14 +28,30 @@ class ComposedChannelCredentials extends grpc.ChannelCredentials {
2628
_isSecure(): boolean {
2729
return false;
2830
}
31+
32+
_createSecureConnector(
33+
_channelTarget,
34+
_options,
35+
callCredentials?: grpc.CallCredentials
36+
): SecureConnector {
37+
return {
38+
connect: async (socket: net.Socket) => {
39+
return { socket, secure: false };
40+
},
41+
waitForReady: async () => {},
42+
getCallCredentials: () => callCredentials || this.callCreds,
43+
destroy: () => {}
44+
};
45+
}
46+
2947
_equals(other: grpc.ChannelCredentials): boolean {
3048
if (this === other) {
3149
return true;
3250
}
3351
if (other instanceof ComposedChannelCredentials) {
3452
return (
3553
this.channelCredentials._equals(other.channelCredentials) &&
36-
this.callCredentials._equals(other.callCredentials)
54+
this.callCreds._equals(other.callCreds)
3755
);
3856
} else {
3957
return false;
@@ -44,14 +62,9 @@ class ComposedChannelCredentials extends grpc.ChannelCredentials {
4462
// Create our own known insecure channel creds.
4563
// See https://github.com/grpc/grpc-node/issues/543 for why this is necessary.
4664
class KnownInsecureChannelCredentialsImpl extends grpc.ChannelCredentials {
47-
constructor(callCredentials?: grpc.CallCredentials) {
48-
super(callCredentials);
49-
}
5065

5166
compose(callCredentials: grpc.CallCredentials): grpc.ChannelCredentials {
52-
const combinedCallCredentials =
53-
this.callCredentials.compose(callCredentials);
54-
return new ComposedChannelCredentials(this, combinedCallCredentials);
67+
return new ComposedChannelCredentials(this, callCredentials);
5568
}
5669

5770
_getConnectionOptions(): ConnectionOptions {

0 commit comments

Comments
 (0)