config-loader: add toString to all source implementations

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-04-03 14:37:06 +02:00
parent 5ee5cf8955
commit fd3f81c50a
6 changed files with 27 additions and 0 deletions
@@ -73,6 +73,13 @@ export class EnvConfigSource implements ConfigSource {
yield { configs };
return;
}
toString() {
const keys = Object.keys(this.env).filter(key =>
key.startsWith('APP_CONFIG_'),
);
return `EnvConfigSource{count=${keys.length}}`;
}
}
const ENV_PREFIX = 'APP_CONFIG_';
@@ -162,6 +162,10 @@ export class FileConfigSource implements ConfigSource {
}
}
toString() {
return `FileConfigSource{path="${this.#path}"}`;
}
#waitForEvent(
watcher: FSWatcher,
signal?: AbortSignal,
@@ -97,6 +97,10 @@ export class MergedConfigSource implements ConfigSource {
}
}
}
toString() {
return `MergedConfigSource{${this.sources.map(String).join(', ')}}`;
}
}
// Helper to wait for the next value of the iterator, while decorating the value
@@ -108,4 +108,8 @@ export class MutableConfigSource implements ConfigSource {
this.#currentData = undefined;
this.#abortController.abort();
}
toString() {
return `MutableConfigSource{}`;
}
}
@@ -116,6 +116,10 @@ export class RemoteConfigSource implements ConfigSource {
}
}
toString() {
return `RemoteConfigSource{path="${this.#url}"}`;
}
async #load(signal?: AbortSignal): Promise<JsonObject> {
const res = await fetch(this.#url, {
signal: signal as import('node-fetch').RequestInit['signal'],
@@ -138,4 +138,8 @@ export class StaticConfigSource implements ConfigSource {
yield { configs: [{ data: await this.promise, context: this.context }] };
return;
}
toString() {
return `StaticConfigSource{}`;
}
}