@@ -12,7 +12,6 @@ limitations under the License.
1212*/
1313
1414import GRPCClient from "./GRPCClient" ;
15- import * as grpc from "@grpc/grpc-js" ;
1615import {
1716 GetConfigurationRequest ,
1817 GetConfigurationResponse ,
@@ -28,7 +27,7 @@ import { SubscribeConfigurationResponse as SubscribeConfigurationResponseResult
2827import { SubscribeConfigurationCallback } from "../../../types/configuration/SubscribeConfigurationCallback" ;
2928import { SubscribeConfigurationStream } from "../../../types/configuration/SubscribeConfigurationStream" ;
3029import { ConfigurationItem } from "../../../types/configuration/ConfigurationItem" ;
31- import { createConfigurationType } from "../../../utils/Client.util" ;
30+ import { addMetadataToMap , createConfigurationType } from "../../../utils/Client.util" ;
3231
3332export default class GRPCClientConfiguration implements IClientConfiguration {
3433 client : GRPCClient ;
@@ -38,25 +37,18 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
3837 }
3938
4039 async get ( storeName : string , keys : string [ ] , metadataObj ?: KeyValueType ) : Promise < GetConfigurationResponseResult > {
41- const metadata = new grpc . Metadata ( ) ;
42-
4340 const msg = new GetConfigurationRequest ( ) ;
4441 msg . setStoreName ( storeName ) ;
4542
4643 if ( keys && keys . length > 0 ) {
4744 msg . setKeysList ( keys . filter ( ( i ) => i !== "" ) ) ;
4845 }
49-
50- if ( metadataObj ) {
51- for ( const [ key , value ] of Object . entries ( metadataObj ) ) {
52- metadata . add ( key , value ) ;
53- }
54- }
46+ addMetadataToMap ( msg . getMetadataMap ( ) , metadataObj ) ;
5547
5648 const client = await this . client . getClient ( ) ;
5749
5850 return new Promise ( ( resolve , reject ) => {
59- client . getConfiguration ( msg , metadata , ( err , res : GetConfigurationResponse ) => {
51+ client . getConfiguration ( msg , ( err , res : GetConfigurationResponse ) => {
6052 if ( err ) {
6153 return reject ( err ) ;
6254 }
@@ -99,8 +91,6 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
9991 keys ?: string [ ] ,
10092 metadataObj ?: KeyValueType ,
10193 ) : Promise < SubscribeConfigurationStream > {
102- const metadata = new grpc . Metadata ( ) ;
103-
10494 const msg = new SubscribeConfigurationRequest ( ) ;
10595 msg . setStoreName ( storeName ) ;
10696
@@ -109,20 +99,15 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
10999 } else {
110100 msg . setKeysList ( [ ] ) ;
111101 }
112-
113- if ( metadataObj ) {
114- for ( const [ key , value ] of Object . entries ( metadataObj ) ) {
115- metadata . add ( key , value ) ;
116- }
117- }
102+ addMetadataToMap ( msg . getMetadataMap ( ) , metadataObj ) ;
118103
119104 const client = await this . client . getClient ( ) ;
120105
121106 // Open a stream. Note that this is a never-ending stream
122107 // and will stay open as long as the client is open
123108 // we will thus create a set with our listeners so we don't
124109 // break on multi listeners
125- const stream = client . subscribeConfiguration ( msg , metadata ) ;
110+ const stream = client . subscribeConfiguration ( msg ) ;
126111 let streamId : string ;
127112
128113 stream . on ( "data" , async ( data : SubscribeConfigurationResponse ) => {
0 commit comments