Skip to content

Commit 5c66956

Browse files
authored
Hide private properties (#37)
1 parent f881f58 commit 5c66956

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

src/AzureAppConfigurationImpl.ts

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,63 @@ import { createCorrelationContextHeader, requestTracingEnabled } from "./request
1313
import { SettingSelector } from "./types";
1414

1515
export class AzureAppConfigurationImpl extends Map<string, unknown> implements AzureAppConfiguration {
16-
private adapters: IKeyValueAdapter[] = [];
16+
#adapters: IKeyValueAdapter[] = [];
1717
/**
1818
* Trim key prefixes sorted in descending order.
1919
* Since multiple prefixes could start with the same characters, we need to trim the longest prefix first.
2020
*/
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;
2426

2527
constructor(
26-
private client: AppConfigurationClient,
27-
private options: AzureAppConfigurationOptions | undefined
28+
client: AppConfigurationClient,
29+
options: AzureAppConfigurationOptions | undefined
2830
) {
2931
super();
32+
this.#client = client;
33+
this.#options = options;
34+
3035
// 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();
3439
}
3540

3641
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));
3843
}
3944
// TODO: should add more adapters to process different type of values
4045
// 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());
4348
}
4449

45-
public async load() {
50+
async load() {
4651
const keyValues: [key: string, value: unknown][] = [];
4752

4853
// validate selectors
49-
const selectors = getValidSelectors(this.options?.selectors);
54+
const selectors = getValidSelectors(this.#options?.selectors);
5055

5156
for (const selector of selectors) {
5257
const listOptions: ListConfigurationSettingsOptions = {
5358
keyFilter: selector.keyFilter,
5459
labelFilter: selector.labelFilter
5560
};
56-
if (this.requestTracingEnabled) {
61+
if (this.#requestTracingEnabled) {
5762
listOptions.requestOptions = {
58-
customHeaders: this.customHeaders()
63+
customHeaders: this.#customHeaders()
5964
}
6065
}
6166

62-
const settings = this.client.listConfigurationSettings(listOptions);
67+
const settings = this.#client.listConfigurationSettings(listOptions);
6368

6469
for await (const setting of settings) {
6570
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);
6873
keyValues.push([trimmedKey, value]);
6974
}
7075
}
@@ -74,18 +79,18 @@ export class AzureAppConfigurationImpl extends Map<string, unknown> implements A
7479
}
7580
}
7681

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) {
7984
if (adapter.canProcess(setting)) {
8085
return adapter.processKeyValue(setting);
8186
}
8287
}
8388
return [setting.key, setting.value];
8489
}
8590

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) {
8994
if (key.startsWith(prefix)) {
9095
return key.slice(prefix.length);
9196
}
@@ -94,17 +99,17 @@ export class AzureAppConfigurationImpl extends Map<string, unknown> implements A
9499
return key;
95100
}
96101

97-
private enableRequestTracing() {
98-
this.correlationContextHeader = createCorrelationContextHeader(this.options);
102+
#enableRequestTracing() {
103+
this.#correlationContextHeader = createCorrelationContextHeader(this.#options);
99104
}
100105

101-
private customHeaders() {
102-
if (!this.requestTracingEnabled) {
106+
#customHeaders() {
107+
if (!this.#requestTracingEnabled) {
103108
return undefined;
104109
}
105110

106111
const headers = {};
107-
headers[CorrelationContextHeaderName] = this.correlationContextHeader;
112+
headers[CorrelationContextHeaderName] = this.#correlationContextHeader;
108113
return headers;
109114
}
110115
}

0 commit comments

Comments
 (0)