-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJsonKeyValueAdapter.ts
More file actions
42 lines (37 loc) · 1.39 KB
/
JsonKeyValueAdapter.ts
File metadata and controls
42 lines (37 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { ConfigurationSetting, featureFlagContentType, secretReferenceContentType } from "@azure/app-configuration";
import { parseContentType, isJsonContentType } from "./common/contentType.js";
import { IKeyValueAdapter } from "./IKeyValueAdapter.js";
export class JsonKeyValueAdapter implements IKeyValueAdapter {
static readonly #ExcludedJsonContentTypes: string[] = [
secretReferenceContentType,
featureFlagContentType
];
canProcess(setting: ConfigurationSetting): boolean {
if (!setting.contentType) {
return false;
}
if (JsonKeyValueAdapter.#ExcludedJsonContentTypes.includes(setting.contentType)) {
return false;
}
const contentType = parseContentType(setting.contentType);
return isJsonContentType(contentType);
}
async processKeyValue(setting: ConfigurationSetting): Promise<[string, unknown]> {
let parsedValue: unknown;
if (setting.value !== undefined) {
try {
parsedValue = JSON.parse(setting.value);
} catch (error) {
parsedValue = setting.value;
}
} else {
parsedValue = setting.value;
}
return [setting.key, parsedValue];
}
async onChangeDetected(): Promise<void> {
return;
}
}