config-loader: document source types
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -16,6 +16,11 @@
|
||||
|
||||
import { AppConfig } from '@backstage/config';
|
||||
|
||||
/**
|
||||
* The data returned by {@link ConfigSource.readConfigData}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ConfigSourceData extends AppConfig {
|
||||
/**
|
||||
* The file path that this configuration was loaded from, if it was loaded from a file.
|
||||
@@ -23,10 +28,20 @@ export interface ConfigSourceData extends AppConfig {
|
||||
path?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for {@link ConfigSource.readConfigData}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ReadConfigDataOptions {
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the iterator returned by {@link ConfigSource.readConfigData}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface AsyncConfigSourceIterator
|
||||
extends AsyncIterator<{ data: ConfigSourceData[] }, void, void> {
|
||||
[Symbol.asyncIterator](): AsyncIterator<
|
||||
@@ -36,8 +51,44 @@ export interface AsyncConfigSourceIterator
|
||||
>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A source of configuration data.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* It is recommended to implement the `readConfigData` method as an async generator.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* class MyConfigSource implements ConfigSource {
|
||||
* async *readConfigData() {
|
||||
* yield {
|
||||
* data: [{
|
||||
* context: 'example',
|
||||
* data: { backend: { baseUrl: 'http://localhost' } }
|
||||
* }]
|
||||
* };
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ConfigSource {
|
||||
readConfigData(options?: ReadConfigDataOptions): AsyncConfigSourceIterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom function to be used for substitution withing configuration files.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* Substitutions use the following syntax: `baseUrl: https://${HOSTNAME}`, where
|
||||
* `'HOSTNAME'` is the name of the variable to be substituted.
|
||||
*
|
||||
* The default substitution function will read the value of the environment.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type SubstitutionFunc = (name: string) => Promise<string | undefined>;
|
||||
|
||||
Reference in New Issue
Block a user