11import * as grpc from "@grpc/grpc-js" ;
22import { NextCall } from "@grpc/grpc-js/build/src/client-interceptors.js" ;
33import { 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
79class 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.
4664class 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