@@ -13,58 +13,63 @@ import { createCorrelationContextHeader, requestTracingEnabled } from "./request
13
13
import { SettingSelector } from "./types" ;
14
14
15
15
export class AzureAppConfigurationImpl extends Map < string , unknown > implements AzureAppConfiguration {
16
- private adapters : IKeyValueAdapter [ ] = [ ] ;
16
+ # adapters: IKeyValueAdapter [ ] = [ ] ;
17
17
/**
18
18
* Trim key prefixes sorted in descending order.
19
19
* Since multiple prefixes could start with the same characters, we need to trim the longest prefix first.
20
20
*/
21
- private sortedTrimKeyPrefixes : string [ ] | undefined ;
22
- private readonly requestTracingEnabled : boolean ;
23
- private correlationContextHeader : string | undefined ;
21
+ #sortedTrimKeyPrefixes: string [ ] | undefined ;
22
+ readonly #requestTracingEnabled: boolean ;
23
+ #correlationContextHeader: string | undefined ;
24
+ #client: AppConfigurationClient ;
25
+ #options: AzureAppConfigurationOptions | undefined ;
24
26
25
27
constructor (
26
- private client : AppConfigurationClient ,
27
- private options : AzureAppConfigurationOptions | undefined
28
+ client : AppConfigurationClient ,
29
+ options : AzureAppConfigurationOptions | undefined
28
30
) {
29
31
super ( ) ;
32
+ this . #client = client ;
33
+ this . #options = options ;
34
+
30
35
// Enable request tracing if not opt-out
31
- this . requestTracingEnabled = requestTracingEnabled ( ) ;
32
- if ( this . requestTracingEnabled ) {
33
- this . enableRequestTracing ( ) ;
36
+ this . # requestTracingEnabled = requestTracingEnabled ( ) ;
37
+ if ( this . # requestTracingEnabled) {
38
+ this . # enableRequestTracing( ) ;
34
39
}
35
40
36
41
if ( options ?. trimKeyPrefixes ) {
37
- this . sortedTrimKeyPrefixes = [ ...options . trimKeyPrefixes ] . sort ( ( a , b ) => b . localeCompare ( a ) ) ;
42
+ this . # sortedTrimKeyPrefixes = [ ...options . trimKeyPrefixes ] . sort ( ( a , b ) => b . localeCompare ( a ) ) ;
38
43
}
39
44
// TODO: should add more adapters to process different type of values
40
45
// feature flag, others
41
- this . adapters . push ( new AzureKeyVaultKeyValueAdapter ( options ?. keyVaultOptions ) ) ;
42
- this . adapters . push ( new JsonKeyValueAdapter ( ) ) ;
46
+ this . # adapters. push ( new AzureKeyVaultKeyValueAdapter ( options ?. keyVaultOptions ) ) ;
47
+ this . # adapters. push ( new JsonKeyValueAdapter ( ) ) ;
43
48
}
44
49
45
- public async load ( ) {
50
+ async load ( ) {
46
51
const keyValues : [ key : string , value : unknown ] [ ] = [ ] ;
47
52
48
53
// validate selectors
49
- const selectors = getValidSelectors ( this . options ?. selectors ) ;
54
+ const selectors = getValidSelectors ( this . # options?. selectors ) ;
50
55
51
56
for ( const selector of selectors ) {
52
57
const listOptions : ListConfigurationSettingsOptions = {
53
58
keyFilter : selector . keyFilter ,
54
59
labelFilter : selector . labelFilter
55
60
} ;
56
- if ( this . requestTracingEnabled ) {
61
+ if ( this . # requestTracingEnabled) {
57
62
listOptions . requestOptions = {
58
- customHeaders : this . customHeaders ( )
63
+ customHeaders : this . # customHeaders( )
59
64
}
60
65
}
61
66
62
- const settings = this . client . listConfigurationSettings ( listOptions ) ;
67
+ const settings = this . # client. listConfigurationSettings ( listOptions ) ;
63
68
64
69
for await ( const setting of settings ) {
65
70
if ( setting . key ) {
66
- const [ key , value ] = await this . processAdapters ( setting ) ;
67
- const trimmedKey = this . keyWithPrefixesTrimmed ( key ) ;
71
+ const [ key , value ] = await this . # processAdapters( setting ) ;
72
+ const trimmedKey = this . # keyWithPrefixesTrimmed( key ) ;
68
73
keyValues . push ( [ trimmedKey , value ] ) ;
69
74
}
70
75
}
@@ -74,18 +79,18 @@ export class AzureAppConfigurationImpl extends Map<string, unknown> implements A
74
79
}
75
80
}
76
81
77
- private async processAdapters ( setting : ConfigurationSetting < string > ) : Promise < [ string , unknown ] > {
78
- for ( const adapter of this . adapters ) {
82
+ async # processAdapters( setting : ConfigurationSetting < string > ) : Promise < [ string , unknown ] > {
83
+ for ( const adapter of this . # adapters) {
79
84
if ( adapter . canProcess ( setting ) ) {
80
85
return adapter . processKeyValue ( setting ) ;
81
86
}
82
87
}
83
88
return [ setting . key , setting . value ] ;
84
89
}
85
90
86
- private keyWithPrefixesTrimmed ( key : string ) : string {
87
- if ( this . sortedTrimKeyPrefixes ) {
88
- for ( const prefix of this . sortedTrimKeyPrefixes ) {
91
+ # keyWithPrefixesTrimmed( key : string ) : string {
92
+ if ( this . # sortedTrimKeyPrefixes) {
93
+ for ( const prefix of this . # sortedTrimKeyPrefixes) {
89
94
if ( key . startsWith ( prefix ) ) {
90
95
return key . slice ( prefix . length ) ;
91
96
}
@@ -94,17 +99,17 @@ export class AzureAppConfigurationImpl extends Map<string, unknown> implements A
94
99
return key ;
95
100
}
96
101
97
- private enableRequestTracing ( ) {
98
- this . correlationContextHeader = createCorrelationContextHeader ( this . options ) ;
102
+ # enableRequestTracing( ) {
103
+ this . # correlationContextHeader = createCorrelationContextHeader ( this . # options) ;
99
104
}
100
105
101
- private customHeaders ( ) {
102
- if ( ! this . requestTracingEnabled ) {
106
+ # customHeaders( ) {
107
+ if ( ! this . # requestTracingEnabled) {
103
108
return undefined ;
104
109
}
105
110
106
111
const headers = { } ;
107
- headers [ CorrelationContextHeaderName ] = this . correlationContextHeader ;
112
+ headers [ CorrelationContextHeaderName ] = this . # correlationContextHeader;
108
113
return headers ;
109
114
}
110
115
}
0 commit comments