@@ -12,7 +12,6 @@ limitations under the License.
12
12
*/
13
13
14
14
import GRPCClient from "./GRPCClient" ;
15
- import * as grpc from "@grpc/grpc-js" ;
16
15
import {
17
16
GetConfigurationRequest ,
18
17
GetConfigurationResponse ,
@@ -28,7 +27,7 @@ import { SubscribeConfigurationResponse as SubscribeConfigurationResponseResult
28
27
import { SubscribeConfigurationCallback } from "../../../types/configuration/SubscribeConfigurationCallback" ;
29
28
import { SubscribeConfigurationStream } from "../../../types/configuration/SubscribeConfigurationStream" ;
30
29
import { ConfigurationItem } from "../../../types/configuration/ConfigurationItem" ;
31
- import { createConfigurationType } from "../../../utils/Client.util" ;
30
+ import { addMetadataToMap , createConfigurationType } from "../../../utils/Client.util" ;
32
31
33
32
export default class GRPCClientConfiguration implements IClientConfiguration {
34
33
client : GRPCClient ;
@@ -38,25 +37,18 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
38
37
}
39
38
40
39
async get ( storeName : string , keys : string [ ] , metadataObj ?: KeyValueType ) : Promise < GetConfigurationResponseResult > {
41
- const metadata = new grpc . Metadata ( ) ;
42
-
43
40
const msg = new GetConfigurationRequest ( ) ;
44
41
msg . setStoreName ( storeName ) ;
45
42
46
43
if ( keys && keys . length > 0 ) {
47
44
msg . setKeysList ( keys . filter ( ( i ) => i !== "" ) ) ;
48
45
}
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 ) ;
55
47
56
48
const client = await this . client . getClient ( ) ;
57
49
58
50
return new Promise ( ( resolve , reject ) => {
59
- client . getConfiguration ( msg , metadata , ( err , res : GetConfigurationResponse ) => {
51
+ client . getConfiguration ( msg , ( err , res : GetConfigurationResponse ) => {
60
52
if ( err ) {
61
53
return reject ( err ) ;
62
54
}
@@ -99,8 +91,6 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
99
91
keys ?: string [ ] ,
100
92
metadataObj ?: KeyValueType ,
101
93
) : Promise < SubscribeConfigurationStream > {
102
- const metadata = new grpc . Metadata ( ) ;
103
-
104
94
const msg = new SubscribeConfigurationRequest ( ) ;
105
95
msg . setStoreName ( storeName ) ;
106
96
@@ -109,20 +99,15 @@ export default class GRPCClientConfiguration implements IClientConfiguration {
109
99
} else {
110
100
msg . setKeysList ( [ ] ) ;
111
101
}
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 ) ;
118
103
119
104
const client = await this . client . getClient ( ) ;
120
105
121
106
// Open a stream. Note that this is a never-ending stream
122
107
// and will stay open as long as the client is open
123
108
// we will thus create a set with our listeners so we don't
124
109
// break on multi listeners
125
- const stream = client . subscribeConfiguration ( msg , metadata ) ;
110
+ const stream = client . subscribeConfiguration ( msg ) ;
126
111
let streamId : string ;
127
112
128
113
stream . on ( "data" , async ( data : SubscribeConfigurationResponse ) => {
0 commit comments