@m-ld/gateway
Version:
m-ld gateway for services
79 lines (78 loc) • 2.76 kB
TypeScript
import { Paths } from 'env-paths';
import createYargs from 'yargs';
/** General configuration */
export interface Config {
[key: Exclude<string, '_' | '$0'>]: unknown;
}
/** paths for local data, config, logs etc. */
type EnvPaths = Paths & {
/**
* provides the prefix into yargs.env, if `false`, no environment variables
* will be read
*/
env: string | false;
};
export declare class Env {
readonly envPaths: EnvPaths;
/**
* The `appName` parameter drives the default paths determination, according
* to the `env-paths` module; and also the default prefix for environment
* variables.
*
* @see https://github.com/sindresorhus/env-paths#api
* @see https://yargs.js.org/docs/#api-reference-envprefix
*/
constructor(appName: string, envPaths?: Partial<EnvPaths>);
/** @returns name uppercase snake-case */
static toEnvVar(name: string): string;
get envPrefix(): string;
/**
* @returns the config as an object containing environment variables, e.g. {
* TIMELD_GATEWAY_KEY1: 'key1',
* TIMELD_GATEWAY_NESTED__KEY2: 'key2',
* }
* @param config
* @param filter if non-empty, the keys to include
* @param env existing env to add to
* @param prefix prefix for new entries
*/
asEnv(config: Config, filter?: string[], env?: {
[env: string]: string;
}, prefix?: string): {
[env: string]: string;
};
baseYargs(args?: string[]): createYargs.Argv<{}>;
yargs(args?: string[]): Promise<createYargs.Argv<{
logLevel: string | undefined;
}>>;
/**
* Gets the path of a file or directory under an environment key.
* Ensures that the parent directory exists.
*/
readyPath(key: keyof Paths, ...path: string[]): Promise<string>;
readConfig(): Promise<Config>;
/** @returns config parameter, for chaining */
writeConfig(config: Config): Promise<Config>;
/** @returns final config written */
updateConfig(...configs: Config[]): Promise<Config>;
static isConfigKey(k: keyof Config): boolean;
/**
* @param {*} current
* @param {*} override
* @param {*} more
* @returns {*}
*/
static mergeConfig<T = Config>(current: any, override: any, ...more: any[]): T;
/**
* List the sub-paths, having no child directories, under the given key.
* @returns leaf sub-paths
*/
envDirs(key: keyof Paths): Promise<string[][]>;
/** Deletes the given env directory */
delEnvDir(key: keyof Paths, path: string[], { force }?: {
force?: boolean;
}): Promise<void>;
delEnvFile(key: keyof Paths, path: string[]): Promise<void>;
defaultIfNotExists<T>(err: any, defaultValue: T): T;
}
export {};