Minor fix for the config package too

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2021-10-26 19:36:17 +02:00
parent d5fb02775a
commit 10d267a1b7
3 changed files with 24 additions and 17 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/config': patch
---
Minor exports cleanup
-17
View File
@@ -46,39 +46,22 @@ export class ConfigReader implements Config {
fallback?: ConfigReader | undefined,
prefix?: string,
);
// (undocumented)
static fromConfigs(configs: AppConfig[]): ConfigReader;
// (undocumented)
get<T = JsonValue_2>(key?: string): T;
// (undocumented)
getBoolean(key: string): boolean;
// (undocumented)
getConfig(key: string): ConfigReader;
// (undocumented)
getConfigArray(key: string): ConfigReader[];
// (undocumented)
getNumber(key: string): number;
// (undocumented)
getOptional<T = JsonValue_2>(key?: string): T | undefined;
// (undocumented)
getOptionalBoolean(key: string): boolean | undefined;
// (undocumented)
getOptionalConfig(key: string): ConfigReader | undefined;
// (undocumented)
getOptionalConfigArray(key: string): ConfigReader[] | undefined;
// (undocumented)
getOptionalNumber(key: string): number | undefined;
// (undocumented)
getOptionalString(key: string): string | undefined;
// (undocumented)
getOptionalStringArray(key: string): string[] | undefined;
// (undocumented)
getString(key: string): string;
// (undocumented)
getStringArray(key: string): string[];
// (undocumented)
has(key: string): boolean;
// (undocumented)
keys(): string[];
}
+19
View File
@@ -72,6 +72,9 @@ export class ConfigReader implements Config {
private filteredKeys?: string[];
private notifiedFilteredKeys = new Set<string>();
/**
* Instantiates the config reader from a list of application config objects.
*/
static fromConfigs(configs: AppConfig[]): ConfigReader {
if (configs.length === 0) {
return new ConfigReader(undefined);
@@ -96,6 +99,7 @@ export class ConfigReader implements Config {
private readonly prefix: string = '',
) {}
/** {@inheritdoc Config.has} */
has(key: string): boolean {
const value = this.readValue(key);
if (value !== undefined) {
@@ -104,12 +108,14 @@ export class ConfigReader implements Config {
return this.fallback?.has(key) ?? false;
}
/** {@inheritdoc Config.keys} */
keys(): string[] {
const localKeys = this.data ? Object.keys(this.data) : [];
const fallbackKeys = this.fallback?.keys() ?? [];
return [...new Set([...localKeys, ...fallbackKeys])];
}
/** {@inheritdoc Config.get} */
get<T = JsonValue>(key?: string): T {
const value = this.getOptional(key);
if (value === undefined) {
@@ -118,6 +124,7 @@ export class ConfigReader implements Config {
return value as T;
}
/** {@inheritdoc Config.getOptional} */
getOptional<T = JsonValue>(key?: string): T | undefined {
const value = this.readValue(key);
const fallbackValue = this.fallback?.getOptional<T>(key);
@@ -154,6 +161,7 @@ export class ConfigReader implements Config {
).value as T;
}
/** {@inheritdoc Config.getConfig} */
getConfig(key: string): ConfigReader {
const value = this.getOptionalConfig(key);
if (value === undefined) {
@@ -162,6 +170,7 @@ export class ConfigReader implements Config {
return value;
}
/** {@inheritdoc Config.getOptionalConfig} */
getOptionalConfig(key: string): ConfigReader | undefined {
const value = this.readValue(key);
const fallbackConfig = this.fallback?.getOptionalConfig(key);
@@ -177,6 +186,7 @@ export class ConfigReader implements Config {
return fallbackConfig;
}
/** {@inheritdoc Config.getConfigArray} */
getConfigArray(key: string): ConfigReader[] {
const value = this.getOptionalConfigArray(key);
if (value === undefined) {
@@ -185,6 +195,7 @@ export class ConfigReader implements Config {
return value;
}
/** {@inheritdoc Config.getOptionalConfigArray} */
getOptionalConfigArray(key: string): ConfigReader[] | undefined {
const configs = this.readConfigValue<JsonObject[]>(key, values => {
if (!Array.isArray(values)) {
@@ -220,6 +231,7 @@ export class ConfigReader implements Config {
return configs.map((obj, index) => this.copy(obj, `${key}[${index}]`));
}
/** {@inheritdoc Config.getNumber} */
getNumber(key: string): number {
const value = this.getOptionalNumber(key);
if (value === undefined) {
@@ -228,6 +240,7 @@ export class ConfigReader implements Config {
return value;
}
/** {@inheritdoc Config.getOptionalNumber} */
getOptionalNumber(key: string): number | undefined {
const value = this.readConfigValue<string | number>(
key,
@@ -247,6 +260,7 @@ export class ConfigReader implements Config {
return number;
}
/** {@inheritdoc Config.getBoolean} */
getBoolean(key: string): boolean {
const value = this.getOptionalBoolean(key);
if (value === undefined) {
@@ -255,6 +269,7 @@ export class ConfigReader implements Config {
return value;
}
/** {@inheritdoc Config.getOptionalBoolean} */
getOptionalBoolean(key: string): boolean | undefined {
return this.readConfigValue(
key,
@@ -262,6 +277,7 @@ export class ConfigReader implements Config {
);
}
/** {@inheritdoc Config.getString} */
getString(key: string): string {
const value = this.getOptionalString(key);
if (value === undefined) {
@@ -270,6 +286,7 @@ export class ConfigReader implements Config {
return value;
}
/** {@inheritdoc Config.getOptionalString} */
getOptionalString(key: string): string | undefined {
return this.readConfigValue(
key,
@@ -278,6 +295,7 @@ export class ConfigReader implements Config {
);
}
/** {@inheritdoc Config.getStringArray} */
getStringArray(key: string): string[] {
const value = this.getOptionalStringArray(key);
if (value === undefined) {
@@ -286,6 +304,7 @@ export class ConfigReader implements Config {
return value;
}
/** {@inheritdoc Config.getOptionalStringArray} */
getOptionalStringArray(key: string): string[] | undefined {
return this.readConfigValue(key, values => {
if (!Array.isArray(values)) {