config-loader: inital refactor to async iterator
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -16,24 +16,25 @@
|
||||
|
||||
import { AppConfig } from '@backstage/config';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import { JsonObject, Observable } from '@backstage/types';
|
||||
import ObservableImpl from 'zen-observable';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { ConfigSource, ConfigSourceData } from './types';
|
||||
|
||||
export function createConfigSource(
|
||||
observable: Observable<{ data: ConfigSourceData[] }>,
|
||||
): ConfigSource {
|
||||
return { configData$: observable };
|
||||
}
|
||||
|
||||
export class EnvConfigSource {
|
||||
export class EnvConfigSource implements ConfigSource {
|
||||
static create(options: {
|
||||
env?: {
|
||||
[name: string]: string | undefined;
|
||||
};
|
||||
}): ConfigSource {
|
||||
const data = readEnvConfig(options?.env ?? process.env);
|
||||
return createConfigSource(ObservableImpl.of({ data }));
|
||||
return new EnvConfigSource(options?.env ?? process.env);
|
||||
}
|
||||
|
||||
private constructor(
|
||||
private readonly env: { [name: string]: string | undefined },
|
||||
) {}
|
||||
|
||||
async *readConfigData(): AsyncIterator<{ data: ConfigSourceData[] }> {
|
||||
const data = readEnvConfig(this.env);
|
||||
return { data };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
import { AppConfig } from '@backstage/config';
|
||||
import { Observable } from '@backstage/types';
|
||||
|
||||
export interface ConfigSourceData extends AppConfig {
|
||||
/**
|
||||
@@ -24,6 +23,12 @@ export interface ConfigSourceData extends AppConfig {
|
||||
path?: string;
|
||||
}
|
||||
|
||||
export interface ConfigSource {
|
||||
configData$: Observable<{ data: ConfigSourceData[] }>;
|
||||
export interface ReadConfigDataOptions {
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
export interface ConfigSource {
|
||||
readConfigData(
|
||||
options?: ReadConfigDataOptions,
|
||||
): AsyncIterator<{ data: ConfigSourceData[] }>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user