@avanio/variable-util
Advanced tools
| {"version":3,"file":"index.d.cts","names":[],"sources":["../src/ConfigOptions.ts","../src/interfaces/IConfigLoader.ts","../src/interfaces/IConfigParser.ts","../src/interfaces/IRequestCache.ts","../src/interfaces/IValidate.ts","../src/lib/formatUtils.ts","../src/types/EnvMapSchema.ts","../src/types/TypeValue.ts","../src/ConfigMap.ts","../src/getConfigObject.ts","../src/getConfigObjectResult.ts","../src/getConfigVariable.ts","../src/getConfigVariableResult.ts","../src/lib/objectUtils.ts","../src/lib/seenUtils.ts","../src/lib/semicolonUtils.ts","../src/loaders/ConfigLoader.ts","../src/loaders/EnvConfigLoader.ts","../src/types/RequestNotReady.ts","../src/loaders/MapConfigLoader.ts","../src/loaders/FetchConfigLoader.ts","../src/loaders/MemoryConfigLoader.ts","../src/loaders/ReactEnvConfigLoader.ts","../src/loaders/RecordConfigLoader.ts","../src/loaders/SwitchLoader.ts","../src/logger.ts","../src/parsers/arrayParser.ts","../src/parsers/bigIntParser.ts","../src/parsers/booleanParser.ts","../src/parsers/floatParser.ts","../src/parsers/integerParser.ts","../src/parsers/JsonConfigParser.ts","../src/parsers/SemicolonConfigParser.ts","../src/parsers/stringParser.ts","../src/parsers/UrlParser.ts","../src/VariableError.ts","../src/VariableLookupError.ts"],"mappings":";;;;;;;;;;;KAQY,aAAA;EAAA,wEAEX,MAAA,GAAS,WAAA,SAAA;EAET,SAAA;AAAA;;;;AAQD;;KAAY,mBAAA;EAEH,+BAAR,MAAA,EAAQ,WAAA;EAER,SAAA;AAAA;;AAUD;;;;;;iBAAgB,YAAA,CAAA;EAAc,MAAA;EAAQ;AAAA,IAAY,OAAA,CAAQ,aAAA,IAAsB,mBAAA;;;;;;;;;AA1BhF;;KCAY,iBAAA;EDEF,wGCAT,KAAA;EAEA,IAAA;EAEA,IAAA;AAAA;;;;;;UAQgB,aAAA;;WAEP,UAAA,EAAY,SAAA;EDUtB;;;;;ECJC,eAAA,CAAgB,SAAA,uBAAgC,iBAAA,GAAoB,O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A;IAAU;EAAA,IAAoB,4BAAA,CAA6B,GAAA;EAOxG,KAAA,CAAA;IAAc;EAAA,GAAQ,WAAA,GAAc,OAAA,CAAQ,MAAA;EAI5C,YAAA,CAAA;IAA2B;EAAA,GAAQ,iBAAA,CAAkB,MAAA,oBAA0B,OAAA,CAAQ,GAAA;EAIvF,QAAA,CAAgB,MAAA,EAAQ,GAAA,EAAK,OAAA,GAAU,aAAA;EAIvC,WAAA,CAAmB,MAAA,EAAQ,GAAA;AAAA;;;;;;;;AhC1D5B;;;iBiCGgB,YAAA,gCAAA,CAA6C,QAAA,GAAW,iBAAA,CAAkB,MAAA,IAAU,aAAA,SAAsB,MAAA;;;;;;;UCJzG,cAAA;EAChB,WAAA;AAAA;;;;;;;;cAUY,SAAA,YAAqB,aAAA,CAAc,GAAA,EAAK,GAAA;EACpD,IAAA;;;;UAIQ,WAAA;;;;AlCWT;EkCLC,WAAA,CAAA;IAAoB;EAAA,IAAc,cAAA;EAIlC,KAAA,CAAA;IAAc;EAAA,GAAQ,WAAA,GAAc,GAAA;EAQpC,QAAA,CAAgB,KAAA,EAAO,GAAA;EAIvB,WAAA,CAAmB,KAAA,EAAO,GAAA;;;;;;UAYlB,iBAAA;AAAA;;;;;;;;;AlCjDT;;;;cmCEa,aAAA,SAAsB,KAAA;;;;;AnCUnC;EmCJC,WAAA,CAAmB,OAAA,UAAiB,OAAA,GAAU,YAAA;AAAA;;;;;;;;AnCR/C;;coCCa,mBAAA,SAA4B,aAAA;EAAA,SACxB,WAAA;;;;;;ApCUjB;EoCHC,WAAA,CAAmB,WAAA,UAAqB,OAAA,UAAiB,OAAA,GAAU,YAAA;AAAA"} |
| {"version":3,"file":"index.d.mts","names":[],"sources":["../src/ConfigOptions.ts","../src/interfaces/IConfigLoader.ts","../src/interfaces/IConfigParser.ts","../src/interfaces/IRequestCache.ts","../src/interfaces/IValidate.ts","../src/lib/formatUtils.ts","../src/types/EnvMapSchema.ts","../src/types/TypeValue.ts","../src/ConfigMap.ts","../src/getConfigObject.ts","../src/getConfigObjectResult.ts","../src/getConfigVariable.ts","../src/getConfigVariableResult.ts","../src/lib/objectUtils.ts","../src/lib/seenUtils.ts","../src/lib/semicolonUtils.ts","../src/loaders/ConfigLoader.ts","../src/loaders/EnvConfigLoader.ts","../src/types/RequestNotReady.ts","../src/loaders/MapConfigLoader.ts","../src/loaders/FetchConfigLoader.ts","../src/loaders/MemoryConfigLoader.ts","../src/loaders/ReactEnvConfigLoader.ts","../src/loaders/RecordConfigLoader.ts","../src/loaders/SwitchLoader.ts","../src/logger.ts","../src/parsers/arrayParser.ts","../src/parsers/bigIntParser.ts","../src/parsers/booleanParser.ts","../src/parsers/floatParser.ts","../src/parsers/integerParser.ts","../src/parsers/JsonConfigParser.ts","../src/parsers/SemicolonConfigParser.ts","../src/parsers/stringParser.ts","../src/parsers/UrlParser.ts","../src/VariableError.ts","../src/VariableLookupError.ts"],"mappings":";;;;;;;;;;;KAQY,aAAA;EAAA,wEAEX,MAAA,GAAS,WAAA,SAAA;EAET,SAAA;AAAA;;;;AAQD;;KAAY,mBAAA;EAEH,+BAAR,MAAA,EAAQ,WAAA;EAER,SAAA;AAAA;;AAUD;;;;;;iBAAgB,YAAA,CAAA;EAAc,MAAA;EAAQ;AAAA,IAAY,OAAA,CAAQ,aAAA,IAAsB,mBAAA;;;;;;;;;AA1BhF;;KCAY,iBAAA;EDEF,wGCAT,KAAA;EAEA,IAAA;EAEA,IAAA;AAAA;;;;;;UAQgB,aAAA;;WAEP,UAAA,EAAY,SAAA;EDUtB;;;;;ECJC,eAAA,CAAgB,SAAA,uBAAgC,iBAAA,GAAoB,OAAA,aAAoB,iBAAA;;;;;EAKxF,gBAAA,0BAA0C,OAAA;AAAA;;;;;;;;;;KAY/B,cAAA,GAAiB,MAAA;AAvC7B;;;;;;;;;AAcA;AAdA,KAmDY,mBAAA,MAAyB,MAAA,OAAa,CAAA;;;;;;;KCrDtC,WAAA;EACX,MAAA,EAAQ,aAAA;EACR,GAAA;E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A,EAAQ,GAAA,EAAK,OAAA,GAAU,aAAA;EAIvC,WAAA,CAAmB,MAAA,EAAQ,GAAA;AAAA;;;;;;;;AhC1D5B;;;iBiCGgB,YAAA,gCAAA,CAA6C,QAAA,GAAW,iBAAA,CAAkB,MAAA,IAAU,aAAA,SAAsB,MAAA;;;;;;;UCJzG,cAAA;EAChB,WAAA;AAAA;;;;;;;;cAUY,SAAA,YAAqB,aAAA,CAAc,GAAA,EAAK,GAAA;EACpD,IAAA;;;;UAIQ,WAAA;;;;AlCWT;EkCLC,WAAA,CAAA;IAAoB;EAAA,IAAc,cAAA;EAIlC,KAAA,CAAA;IAAc;EAAA,GAAQ,WAAA,GAAc,GAAA;EAQpC,QAAA,CAAgB,KAAA,EAAO,GAAA;EAIvB,WAAA,CAAmB,KAAA,EAAO,GAAA;;;;;;UAYlB,iBAAA;AAAA;;;;;;;;;AlCjDT;;;;cmCEa,aAAA,SAAsB,KAAA;;;;;AnCUnC;EmCJC,WAAA,CAAmB,OAAA,UAAiB,OAAA,GAAU,YAAA;AAAA;;;;;;;;AnCR/C;;coCCa,mBAAA,SAA4B,aAAA;EAAA,SACxB,WAAA;;;;;;ApCUjB;EoCHC,WAAA,CAAmB,WAAA,UAAqB,OAAA,UAAiB,OAAA,GAAU,YAAA;AAAA"} |
+630
-605
| Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
| let _luolapeikko_result_option = require("@luolapeikko/result-option"); | ||
| let _luolapeikko_ts_common = require("@luolapeikko/ts-common"); | ||
| let _luolapeikko_result_option = require("@luolapeikko/result-option"); | ||
| let events = require("events"); | ||
| //#region src/types/RequestNotReady.ts | ||
| /** | ||
| * Type guard for RequestNotReady | ||
| * @param {unknown} obj - object to check if it is a RequestNotReady payload | ||
| * @returns {boolean} boolean indicating if the object is a RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| function isRequestNotReadMessage(obj) { | ||
| return typeof obj === "object" && obj !== null && "_type" in obj && obj._type === "RequestNotReady" && "message" in obj && typeof obj.message === "string"; | ||
| } | ||
| /** | ||
| * function to create a RequestNotReady payload to indicate that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @param {string} message - reason why the request is not ready yet | ||
| * @returns {RequestNotReady} RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| function createRequestNotReady(message) { | ||
| return { | ||
| message, | ||
| _type: "RequestNotReady" | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/logger.ts | ||
@@ -296,2 +270,12 @@ let logger; | ||
| /** | ||
| * Get result from loader | ||
| * @param {IConfigLoader} loader - loader to use | ||
| * @param {string} rootKey - key of variable | ||
| * @returns {Promise<LoaderValueResult | undefined>} - result of loader | ||
| */ | ||
| async function getResult(loader, rootKey) { | ||
| if (await loader.isLoaderDisabled()) return; | ||
| return await loader.getLoaderResult(rootKey); | ||
| } | ||
| /** | ||
| * handle function for loader | ||
@@ -311,4 +295,3 @@ * @template Input - Type of input value | ||
| try { | ||
| if (await loader.isLoaderDisabled()) return; | ||
| const result = await loader.getLoaderResult(rootKey); | ||
| const result = await getResult(loader, rootKey); | ||
| if (!result) return; | ||
@@ -323,4 +306,4 @@ const { value, path, seen } = result; | ||
| key: rootKey, | ||
| value, | ||
| loader | ||
| loader, | ||
| value | ||
| }); | ||
@@ -337,4 +320,4 @@ } catch (err) { | ||
| key: rootKey, | ||
| value, | ||
| loader | ||
| loader, | ||
| value | ||
| }); | ||
@@ -351,4 +334,4 @@ } catch (err) { | ||
| key: rootKey, | ||
| value: rawOutput, | ||
| loader | ||
| loader, | ||
| value: rawOutput | ||
| }); | ||
@@ -435,2 +418,243 @@ if (validateData) output = validateData; | ||
| //#endregion | ||
| //#region src/VariableLookupError.ts | ||
| /** | ||
| * Custom error class for variable lookup errors. | ||
| * @class VariableLookupError | ||
| * @augments VariableError | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| */ | ||
| var VariableLookupError = class extends VariableError { | ||
| variableKey; | ||
| /** | ||
| * Create a new VariableLookupError | ||
| * @param {string} variableKey - The variable key. | ||
| * @param {string} message - The error message. | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| constructor(variableKey, message, options) { | ||
| super(message, options); | ||
| this.variableKey = variableKey; | ||
| this.name = "VariableLookupError"; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ConfigMap.ts | ||
| /** | ||
| * ConfigMap | ||
| * @example | ||
| * type ConfigEnv = { | ||
| * PORT: number; | ||
| * HOST: string; | ||
| * DEBUG: boolean; | ||
| * URL: URL; | ||
| * }; | ||
| * const env = new EnvConfigLoader(); | ||
| * const config = new ConfigMap<ConfigEnv>( | ||
| * { | ||
| * DEBUG: {defaultValue: false, parser: booleanParser()}, | ||
| * HOST: {defaultValue: 'localhost', parser: stringParser()}, | ||
| * PORT: {defaultValue: 3000, parser: integerParser()}, | ||
| * URL: {defaultValue: new URL('http://localhost:3000'), parser: new UrlParser({urlSanitize: true})}, | ||
| * }, | ||
| * [env], | ||
| * ); | ||
| * console.log('port', await config.get('PORT')); | ||
| * @template Data - type of config map | ||
| * @since v1.1.0 | ||
| */ | ||
| var ConfigMap = class { | ||
| schema; | ||
| options; | ||
| loaders; | ||
| /** | ||
| * ConfigMap constructor | ||
| * @param {EnvMapSchema<Data>} schema - schema of config map | ||
| * @param {Iterable<IConfigLoader>} loaders - iterable of config loaders | ||
| * @param {ConfigOptions} options - optional config options (logger, namespace) | ||
| */ | ||
| constructor(schema, loaders, options = { | ||
| logger: void 0, | ||
| namespace: void 0 | ||
| }) { | ||
| this.schema = schema; | ||
| this.options = options; | ||
| this.loaders = loaders; | ||
| } | ||
| /** | ||
| * Set logger value | ||
| * @param {ILoggerLike | undefined} logger - logger like object | ||
| */ | ||
| setLogger(logger) { | ||
| this.options.logger = logger; | ||
| } | ||
| /** | ||
| * get env object from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: LoaderTypeValue<number> = await config.getObject('PORT'); | ||
| * console.log(valueObject.type, valueObject.value); // 'env', 3000 | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getObject(key, encodeOptions) { | ||
| if (typeof key !== "string") throw new VariableError(`ConfigMap key ${String(key)} is not a string`); | ||
| const entry = this.schema[key]; | ||
| if (!entry) throw new VariableLookupError(key, `ConfigMap key ${String(key)} not found in config map`); | ||
| const { parser, defaultValue, params, undefinedThrowsError, undefinedErrorMessage } = entry; | ||
| const configObject = await getConfigObject(key, Array.from(await _luolapeikko_ts_common.LoadableCore.resolve(this.loaders)), parser, defaultValue, params, this.options, encodeOptions); | ||
| if (undefinedThrowsError && configObject.value === void 0) { | ||
| buildOptions(this.options).logger?.info(`ConfigMap key ${String(key)} is undefined (expect to throw error)`); | ||
| throw new VariableError(undefinedErrorMessage ?? `ConfigMap key ${String(key)} is undefined`); | ||
| } | ||
| return configObject; | ||
| } | ||
| /** | ||
| * get env object from config map as Result | ||
| * @returns {Promise<Result<TypeValueRecords<Data>>>} Result Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: Result<LoaderTypeValue<number>> = await config.getObjectResult('PORT'); | ||
| * if (valueObject.isOk()) { | ||
| * const {type, value} = valueObject.ok(); | ||
| * console.log(type, value); // 'env', 3000 | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getObjectResult(key, encodeOptions) { | ||
| try { | ||
| return (0, _luolapeikko_result_option.Ok)(await this.getObject(key, encodeOptions)); | ||
| } catch (err) { | ||
| return (0, _luolapeikko_result_option.Err)(err); | ||
| } | ||
| } | ||
| /** | ||
| * get env value from config map | ||
| * @returns {Promise<Data[Key]>} Promise of value or undefined | ||
| * @example | ||
| * const port: number = await config.get('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async get(key, encodeOptions) { | ||
| return (await this.getObject(key, encodeOptions)).value; | ||
| } | ||
| /** | ||
| * get env value as string from config map | ||
| * @returns {Promise<string | undefined>} Promise of string value or undefined | ||
| * @example | ||
| * const port: string = await config.getString('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getString(key, encodeOptions) { | ||
| return (await this.getObject(key, encodeOptions)).stringValue; | ||
| } | ||
| /** | ||
| * get env value from config map as Result | ||
| * @returns {Promise<Result<Data[Key]>>} Result Promise of value or undefined | ||
| * @example | ||
| * const port: Result<number> = await config.getResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getResult(key, encodeOptions) { | ||
| try { | ||
| return (0, _luolapeikko_result_option.Ok)(await this.get(key, encodeOptions)); | ||
| } catch (err) { | ||
| return (0, _luolapeikko_result_option.Err)(err); | ||
| } | ||
| } | ||
| /** | ||
| * get env value as string from config map as Result | ||
| * @returns {Promise<Result<string | undefined>>} Result Promise of string value or undefined | ||
| * @example | ||
| * const port: Result<string> = await config.getStringResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getStringResult(key, encodeOptions) { | ||
| try { | ||
| return (0, _luolapeikko_result_option.Ok)(await this.getString(key, encodeOptions)); | ||
| } catch (err) { | ||
| return (0, _luolapeikko_result_option.Err)(err); | ||
| } | ||
| } | ||
| /** | ||
| * get all env value objects from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of all values | ||
| * @example | ||
| * const values: TypeValueRecords<Data> = await config.getAll(); | ||
| * console.log(values.PORT.type, values.PORT.value); // 'env', 3000 | ||
| */ | ||
| async getAllObjects() { | ||
| return (await this.getAllPromises()).reduce((result, [key, value]) => { | ||
| result[key] = value; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * get all env values from config map | ||
| * @returns {Promise<Data>} Promise of all values | ||
| * @example | ||
| * const values: Data = await config.getAllValues(); | ||
| * console.log('PORT', values.PORT); // 3000 (number) | ||
| */ | ||
| async getAllValues() { | ||
| return (await this.getAllPromises()).reduce((result, [key, value]) => { | ||
| result[key] = value.value; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * get all env values from config map as string | ||
| * @returns {Promise<Record<keyof Data, string>>} Promise of all values as string | ||
| * @example | ||
| * const values: Record<keyof Data, string> = await config.getAllStringValues(); | ||
| * console.log('PORT', values.PORT); // '3000' (string) | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getAllStringValues(encodeOptions) { | ||
| return (await this.getAllPromises(encodeOptions)).reduce((result, [key, value]) => { | ||
| result[key] = value.stringValue; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * Validate all env values from config map, expect to throw error if error exists | ||
| * @param {(data: Data) => void} callback callback function | ||
| */ | ||
| async validateAll(callback) { | ||
| callback(await this.getAllValues()); | ||
| } | ||
| /** | ||
| * run lookup to all keys and return all promises | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<[keyof Data, LoaderTypeValueStrict<Data[keyof Data]>][]>} Promise of all values | ||
| */ | ||
| getAllPromises(encodeOptions) { | ||
| return Promise.all(Object.keys(this.schema).map(async (key) => { | ||
| return [key, await this.getObject(key, encodeOptions)]; | ||
| })); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/getConfigObjectResult.ts | ||
| async function getConfigObjectResult(rootKey, loaders, parser, defaultValueLoadable, params, options) { | ||
| try { | ||
| return (0, _luolapeikko_result_option.Ok)(await getConfigObject(rootKey, loaders, parser, defaultValueLoadable, params, options)); | ||
| } catch (err) { | ||
| return (0, _luolapeikko_result_option.Err)(err); | ||
| } | ||
| } | ||
| //#endregion | ||
| //#region src/getConfigVariable.ts | ||
@@ -452,10 +676,66 @@ async function getConfigVariable(rootKey, loaders, parser, defaultValueLoadable, params, options, encodeOptions) { | ||
| //#endregion | ||
| //#region src/getConfigObjectResult.ts | ||
| async function getConfigObjectResult(rootKey, loaders, parser, defaultValueLoadable, params, options) { | ||
| try { | ||
| return (0, _luolapeikko_result_option.Ok)(await getConfigObject(rootKey, loaders, parser, defaultValueLoadable, params, options)); | ||
| } catch (err) { | ||
| return (0, _luolapeikko_result_option.Err)(err); | ||
| } | ||
| //#region src/lib/objectUtils.ts | ||
| /** | ||
| * validate if a value is a valid object | ||
| * @param {unknown} value - value to validate | ||
| * @returns {value is Record<string, unknown>} - true if value is a valid object | ||
| * @since v0.2.5 | ||
| */ | ||
| function isValidObject(value) { | ||
| return typeof value === "object" && value !== null && !Array.isArray(value); | ||
| } | ||
| /** | ||
| * Check if a value has a toJSON method | ||
| * @param {unknown} value - value to check | ||
| * @returns {value is {toJSON: () => string}} - true if value has a toJSON method | ||
| */ | ||
| function haveToJSON(value) { | ||
| return typeof value === "object" && value !== null && "toJSON" in value; | ||
| } | ||
| /** | ||
| * Stringify a value to a string | ||
| * @param {unknown} value - value to stringify | ||
| * @returns {string} - stringified value | ||
| */ | ||
| function stringifyValue(value) { | ||
| if (isValidObject(value)) return haveToJSON(value) ? value.toJSON() : JSON.stringify(value); | ||
| return String(value); | ||
| } | ||
| /** | ||
| * Convert an object to a string value object | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Record<string, string | undefined>} - object with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| function buildStringObject(obj) { | ||
| return Object.entries(obj).reduce((last, [key, value]) => { | ||
| if (value) last[key] = stringifyValue(value); | ||
| return last; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * Convert an object to a Map<string, string> | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Map<string, string>} - Map with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| function buildStringMap(obj) { | ||
| return Object.entries(obj).reduce((acc, [key, value]) => { | ||
| if (value) acc.set(key, stringifyValue(value)); | ||
| return acc; | ||
| }, /* @__PURE__ */ new Map()); | ||
| } | ||
| /** | ||
| * Apply a Record<string, string> to a Map<string, string> | ||
| * @param {Record<string, string | undefined>} obj - object to apply | ||
| * @param {Map<string, string>} target - Map to apply to | ||
| * @returns {Map<string, string>} - target with updates | ||
| * @since v0.2.5 | ||
| */ | ||
| function applyStringMap(obj, target) { | ||
| return Object.entries(obj).reduce((acc, [key, value]) => { | ||
| if (value) acc.set(key, value); | ||
| return acc; | ||
| }, target); | ||
| } | ||
@@ -537,68 +817,2 @@ //#endregion | ||
| //#endregion | ||
| //#region src/lib/objectUtils.ts | ||
| /** | ||
| * validate if a value is a valid object | ||
| * @param {unknown} value - value to validate | ||
| * @returns {value is Record<string, unknown>} - true if value is a valid object | ||
| * @since v0.2.5 | ||
| */ | ||
| function isValidObject(value) { | ||
| return typeof value === "object" && value !== null && !Array.isArray(value); | ||
| } | ||
| /** | ||
| * Check if a value has a toJSON method | ||
| * @param {unknown} value - value to check | ||
| * @returns {value is {toJSON: () => string}} - true if value has a toJSON method | ||
| */ | ||
| function haveToJSON(value) { | ||
| return typeof value === "object" && value !== null && "toJSON" in value; | ||
| } | ||
| /** | ||
| * Stringify a value to a string | ||
| * @param {unknown} value - value to stringify | ||
| * @returns {string} - stringified value | ||
| */ | ||
| function stringifyValue(value) { | ||
| if (isValidObject(value)) return haveToJSON(value) ? value.toJSON() : JSON.stringify(value); | ||
| return String(value); | ||
| } | ||
| /** | ||
| * Convert an object to a string value object | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Record<string, string | undefined>} - object with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| function buildStringObject(obj) { | ||
| return Object.entries(obj).reduce((last, [key, value]) => { | ||
| if (value) last[key] = stringifyValue(value); | ||
| return last; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * Convert an object to a Map<string, string> | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Map<string, string>} - Map with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| function buildStringMap(obj) { | ||
| return Object.entries(obj).reduce((acc, [key, value]) => { | ||
| if (value) acc.set(key, stringifyValue(value)); | ||
| return acc; | ||
| }, /* @__PURE__ */ new Map()); | ||
| } | ||
| /** | ||
| * Apply a Record<string, string> to a Map<string, string> | ||
| * @param {Record<string, string | undefined>} obj - object to apply | ||
| * @param {Map<string, string>} target - Map to apply to | ||
| * @returns {Map<string, string>} - target with updates | ||
| * @since v0.2.5 | ||
| */ | ||
| function applyStringMap(obj, target) { | ||
| return Object.entries(obj).reduce((acc, [key, value]) => { | ||
| if (value) acc.set(key, value); | ||
| return acc; | ||
| }, target); | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/ConfigLoader.ts | ||
@@ -614,5 +828,7 @@ /** | ||
| var ConfigLoader = class extends events.EventEmitter { | ||
| options; | ||
| overrideKeys; | ||
| valueSeen = /* @__PURE__ */ new Map(); | ||
| constructor(props = {}, overrideKeys = {}) { | ||
| super(); | ||
| this.valueSeen = /* @__PURE__ */ new Map(); | ||
| this.options = props; | ||
@@ -625,13 +841,13 @@ this.overrideKeys = overrideKeys; | ||
| return { | ||
| value: loaderValue.value, | ||
| path: loaderValue.path, | ||
| seen: handleSeen(this.valueSeen, lookupKey, loaderValue.value) | ||
| seen: handleSeen(this.valueSeen, lookupKey, loaderValue.value), | ||
| value: loaderValue.value | ||
| }; | ||
| } | ||
| async isLoaderDisabled() { | ||
| const loadableDisabled = (await this.getOptions()).disabled; | ||
| const loadableDisabled = (await this.getOptions()).disabled ?? false; | ||
| return _luolapeikko_ts_common.LoadableCore.resolve(loadableDisabled); | ||
| } | ||
| setDisabled(disabled) { | ||
| return this.setOption("disabled", disabled); | ||
| this.setOption("disabled", disabled); | ||
| } | ||
@@ -660,41 +876,2 @@ /** | ||
| //#endregion | ||
| //#region src/loaders/RecordConfigLoader.ts | ||
| /** | ||
| * RecordConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| */ | ||
| var RecordConfigLoader = class extends ConfigLoader { | ||
| constructor(..._args) { | ||
| super(..._args); | ||
| this._isLoaded = false; | ||
| } | ||
| /** | ||
| * reloads the data | ||
| */ | ||
| async reload() { | ||
| this.valueSeen.clear(); | ||
| await this.loadData(); | ||
| } | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} - true if the data is loaded, false otherwise | ||
| */ | ||
| isLoaded() { | ||
| return this._isLoaded; | ||
| } | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async loadData() { | ||
| this.dataPromise = this.handleData(); | ||
| await this.dataPromise; | ||
| this.emit("updated"); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/loaders/EnvConfigLoader.ts | ||
@@ -710,11 +887,8 @@ /** | ||
| var EnvConfigLoader = class extends ConfigLoader { | ||
| constructor(..._args) { | ||
| super(..._args); | ||
| this.loaderType = "env"; | ||
| this.defaultOptions = { disabled: false }; | ||
| } | ||
| loaderType = "env"; | ||
| defaultOptions = { disabled: false }; | ||
| handleLoaderValue(lookupKey) { | ||
| return { | ||
| value: process.env[lookupKey], | ||
| path: `process.env.${lookupKey}` | ||
| path: `process.env.${lookupKey}`, | ||
| value: process.env[lookupKey] | ||
| }; | ||
@@ -725,25 +899,26 @@ } | ||
| //#endregion | ||
| //#region src/loaders/ReactEnvConfigLoader.ts | ||
| //#region src/types/RequestNotReady.ts | ||
| /** | ||
| * React env loader class is used to load env variables from process.env.REACT_APP_* | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {Partial<OverrideMap>} [override] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| * Type guard for RequestNotReady | ||
| * @param {unknown} obj - object to check if it is a RequestNotReady payload | ||
| * @returns {boolean} boolean indicating if the object is a RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| var ReactEnvConfigLoader = class extends ConfigLoader { | ||
| constructor(..._args) { | ||
| super(..._args); | ||
| this.loaderType = "react-env"; | ||
| this.defaultOptions = { disabled: false }; | ||
| } | ||
| handleLoaderValue(lookupKey) { | ||
| const targetKey = `REACT_APP_${lookupKey}`; | ||
| return { | ||
| value: process.env[targetKey], | ||
| path: `process.env.${targetKey}` | ||
| }; | ||
| } | ||
| }; | ||
| function isRequestNotReadMessage(obj) { | ||
| return typeof obj === "object" && obj !== null && "_type" in obj && obj._type === "RequestNotReady" && "message" in obj && typeof obj.message === "string"; | ||
| } | ||
| /** | ||
| * function to create a RequestNotReady payload to indicate that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @param {string} message - reason why the request is not ready yet | ||
| * @returns {RequestNotReady} RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| function createRequestNotReady(message) { | ||
| return { | ||
| _type: "RequestNotReady", | ||
| message | ||
| }; | ||
| } | ||
@@ -760,7 +935,4 @@ //#endregion | ||
| var MapConfigLoader = class extends ConfigLoader { | ||
| constructor(..._args) { | ||
| super(..._args); | ||
| this._isLoaded = false; | ||
| this.data = /* @__PURE__ */ new Map(); | ||
| } | ||
| _isLoaded = false; | ||
| data = /* @__PURE__ */ new Map(); | ||
| /** | ||
@@ -800,2 +972,15 @@ * clear maps and reloads the data | ||
| var FetchConfigLoader = class extends MapConfigLoader { | ||
| loaderType; | ||
| request; | ||
| path = "undefined"; | ||
| defaultOptions = { | ||
| cache: void 0, | ||
| cacheHitHttpCode: 304, | ||
| disabled: false, | ||
| fetchClient: typeof window === "object" ? fetch.bind(window) : fetch, | ||
| isSilent: false, | ||
| logger: void 0, | ||
| payload: "json", | ||
| validate: void 0 | ||
| }; | ||
| /** | ||
@@ -810,13 +995,2 @@ * Constructor for FetchConfigLoader | ||
| super(options, overrideKeys); | ||
| this.path = "undefined"; | ||
| this.defaultOptions = { | ||
| cache: void 0, | ||
| cacheHitHttpCode: 304, | ||
| disabled: false, | ||
| fetchClient: typeof window === "object" ? fetch.bind(window) : fetch, | ||
| isSilent: false, | ||
| logger: void 0, | ||
| payload: "json", | ||
| validate: void 0 | ||
| }; | ||
| this.request = request; | ||
@@ -831,4 +1005,4 @@ this.loaderType = type; | ||
| return { | ||
| value: this.data.get(lookupKey), | ||
| path: this.path | ||
| path: this.path, | ||
| value: this.data.get(lookupKey) | ||
| }; | ||
@@ -952,3 +1126,3 @@ } | ||
| async getRequest() { | ||
| return typeof this.request === "function" ? this.request() : this.request; | ||
| return await (typeof this.request === "function" ? this.request() : this.request); | ||
| } | ||
@@ -968,8 +1142,10 @@ }; | ||
| var MemoryConfigLoader = class extends ConfigLoader { | ||
| loaderType; | ||
| data; | ||
| defaultOptions = { | ||
| disabled: false, | ||
| logger: void 0 | ||
| }; | ||
| constructor(initialData, options = {}, overrideKeys = {}, type = "memory") { | ||
| super(options, overrideKeys); | ||
| this.defaultOptions = { | ||
| disabled: false, | ||
| logger: void 0 | ||
| }; | ||
| this.data = new Map(Object.entries(initialData)); | ||
@@ -990,4 +1166,4 @@ this.loaderType = type; | ||
| return { | ||
| value: this.data.get(lookupKey), | ||
| path: `key:${lookupKey}` | ||
| path: `key:${lookupKey}`, | ||
| value: this.data.get(lookupKey) | ||
| }; | ||
@@ -998,2 +1174,61 @@ } | ||
| //#endregion | ||
| //#region src/loaders/ReactEnvConfigLoader.ts | ||
| /** | ||
| * React env loader class is used to load env variables from process.env.REACT_APP_* | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {Partial<OverrideMap>} [override] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| var ReactEnvConfigLoader = class extends ConfigLoader { | ||
| loaderType = "react-env"; | ||
| defaultOptions = { disabled: false }; | ||
| handleLoaderValue(lookupKey) { | ||
| const targetKey = `REACT_APP_${lookupKey}`; | ||
| return { | ||
| path: `process.env.${targetKey}`, | ||
| value: process.env[targetKey] | ||
| }; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/loaders/RecordConfigLoader.ts | ||
| /** | ||
| * RecordConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| */ | ||
| var RecordConfigLoader = class extends ConfigLoader { | ||
| _isLoaded = false; | ||
| dataPromise; | ||
| /** | ||
| * reloads the data | ||
| */ | ||
| async reload() { | ||
| this.valueSeen.clear(); | ||
| await this.loadData(); | ||
| } | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} - true if the data is loaded, false otherwise | ||
| */ | ||
| isLoaded() { | ||
| return this._isLoaded; | ||
| } | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async loadData() { | ||
| this.dataPromise = this.handleData(); | ||
| await this.dataPromise; | ||
| this.emit("updated"); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/loaders/SwitchLoader.ts | ||
@@ -1016,9 +1251,11 @@ /** | ||
| var SwitchLoader = class extends ConfigLoader { | ||
| loaderType; | ||
| config; | ||
| keys = /* @__PURE__ */ new Set(); | ||
| defaultOptions = { | ||
| disabled: false, | ||
| logger: void 0 | ||
| }; | ||
| constructor(configs, props = {}, type = "switch") { | ||
| super(props); | ||
| this.keys = /* @__PURE__ */ new Set(); | ||
| this.defaultOptions = { | ||
| disabled: false, | ||
| logger: void 0 | ||
| }; | ||
| this.config = configs; | ||
@@ -1045,4 +1282,4 @@ this.loaderType = type; | ||
| if (currentValue) output = { | ||
| value: currentValue, | ||
| path: `switch:${String(key)}:${lookupKey}` | ||
| path: `switch:${String(key)}:${lookupKey}`, | ||
| value: currentValue | ||
| }; | ||
@@ -1058,103 +1295,35 @@ } | ||
| //#endregion | ||
| //#region src/parsers/JsonConfigParser.ts | ||
| //#region src/parsers/arrayParser.ts | ||
| /** | ||
| * Config parser to parse JSON string as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new JsonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, object>} | ||
| * Build parser for array of values | ||
| * @template Input - Type of input | ||
| * @template Output - Type of output | ||
| * @param {IConfigParser<Input, Output>} parse parser for the array values | ||
| * @param {string} separator separator for the array values, defaults to ';' | ||
| * @param {TypeGuardValidate<Output> | undefined} validate optional post validation | ||
| * @returns {IConfigParser<Output[], Input[]>} Parser for array of values | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| var JsonConfigParser = class { | ||
| constructor({ protectedKeys, validate, showProtectedKeys } = {}) { | ||
| this.name = "jsonConfigParser"; | ||
| this.protectedKeys = new Set(protectedKeys); | ||
| this.validate = validate; | ||
| this.showProtectedKeys = showProtectedKeys; | ||
| } | ||
| parse({ value }) { | ||
| return this.buildBaseRecord(JSON.parse(value)); | ||
| } | ||
| async postValidate({ value }) { | ||
| return await this.validate?.(value); | ||
| } | ||
| toString(config) { | ||
| return JSON.stringify(Object.entries(config).reduce((last, [key, value]) => { | ||
| if (value) last[key] = value; | ||
| return last; | ||
| }, {})); | ||
| } | ||
| toLogString(config) { | ||
| return JSON.stringify(Object.entries(config).reduce((last, [key, value]) => { | ||
| if (value) if (this.protectedKeys.has(key)) last[key] = buildHiddenValue(String(value), this.showProtectedKeys); | ||
| else last[key] = value; | ||
| return last; | ||
| }, {})); | ||
| } | ||
| /** | ||
| * Build a string record from the given data | ||
| * @param {unknown} data - to be validated as object | ||
| * @returns {object} A record with string values | ||
| */ | ||
| buildBaseRecord(data) { | ||
| if (typeof data !== "object" || data === null || Array.isArray(data)) return {}; | ||
| return data; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/parsers/UrlParser.ts | ||
| /** | ||
| * UrlParser class is used to parse and validate env variables of type URL. | ||
| * @class UrlParser | ||
| * @implements {IConfigParser<URL, URL>} | ||
| * @category Parsers | ||
| * @since v0.2.5 | ||
| */ | ||
| var UrlParser = class { | ||
| /** | ||
| * Create a new UrlParser | ||
| * @param {UrlParserProps} properties - Properties for the UrlParser | ||
| */ | ||
| constructor({ urlSanitize } = {}) { | ||
| this.name = "urlParser"; | ||
| this.urlSanitize = urlSanitize ?? false; | ||
| } | ||
| parse({ value }) { | ||
| try { | ||
| return new URL(value); | ||
| } catch (err) { | ||
| throw _luolapeikko_ts_common.ErrorCore.from(err); | ||
| function arrayParser(parse, separator = ";", validate) { | ||
| return { | ||
| name: "arraySeparatorParser", | ||
| parse: (props) => { | ||
| return Promise.all(props.value.split(separator).map((v) => parse.parse({ | ||
| ...props, | ||
| value: v | ||
| }))); | ||
| }, | ||
| postValidate: async (props) => { | ||
| if (!validate) return; | ||
| return (await Promise.all(props.value.map(async (v) => { | ||
| if (!(await validate)?.(v)) return; | ||
| return v; | ||
| }))).filter((v) => v !== void 0); | ||
| }, | ||
| toString: (value) => { | ||
| return value.map((v) => parse.toString(v)).join(separator); | ||
| } | ||
| } | ||
| toString(value) { | ||
| return value.href; | ||
| } | ||
| toLogString(value) { | ||
| if (this.urlSanitize) return this.handleUrlSanitize(value.href); | ||
| return value.toString(); | ||
| } | ||
| /** | ||
| * Build a URL object from a string and sanitize the username and password | ||
| * @param {string} value string to parse | ||
| * @returns {URL} URL object with sanitized username and password | ||
| */ | ||
| handleUrlSanitize(value) { | ||
| const url = new URL(value); | ||
| url.password = "*".repeat(url.password.length); | ||
| url.username = "*".repeat(url.username.length); | ||
| return url.href; | ||
| } | ||
| }; | ||
| }; | ||
| } | ||
@@ -1171,3 +1340,3 @@ //#endregion | ||
| const parsed = parseInt(value, 10); | ||
| if (isNaN(parsed)) return (0, _luolapeikko_result_option.Err)(/* @__PURE__ */ new TypeError(`${value} is not an integer string`)); | ||
| if (Number.isNaN(parsed)) return (0, _luolapeikko_result_option.Err)(/* @__PURE__ */ new TypeError(`${value} is not an integer string`)); | ||
| return (0, _luolapeikko_result_option.Ok)(parsed); | ||
@@ -1218,3 +1387,3 @@ } | ||
| const parsed = parseFloat(value); | ||
| if (isNaN(parsed)) return (0, _luolapeikko_result_option.Err)(/* @__PURE__ */ new TypeError(`${value} is not a float string`)); | ||
| if (Number.isNaN(parsed)) return (0, _luolapeikko_result_option.Err)(/* @__PURE__ */ new TypeError(`${value} is not a float string`)); | ||
| return (0, _luolapeikko_result_option.Ok)(parsed); | ||
@@ -1237,16 +1406,16 @@ } | ||
| //#endregion | ||
| //#region src/parsers/stringParser.ts | ||
| //#region src/parsers/bigIntParser.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to string | ||
| * @template Output - Type of output, defaults to bigint | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<string, Output>} - parser | ||
| * @returns {IConfigParser<bigint, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| function stringParser(validate) { | ||
| function bigIntParser(validate) { | ||
| return { | ||
| name: "stringParser", | ||
| parse: ({ value, key }) => { | ||
| return getString(value).mapErr((cause) => new TypeError(`value for key ${key} is not a string`, { cause })).unwrap(); | ||
| name: "bigIntParser", | ||
| parse: ({ key, value }) => { | ||
| return getBigInt(value).mapErr((cause) => new TypeError(`value for key ${key} is not an integer string`, { cause })).unwrap(); | ||
| }, | ||
@@ -1257,7 +1426,4 @@ postValidate: async (props) => { | ||
| }, | ||
| preValidate: ({ key, value }) => { | ||
| if (typeof value !== "string") throw new TypeError(`value for key ${key} is not a string`); | ||
| }, | ||
| toString: (value) => { | ||
| return value; | ||
| return value.toString(); | ||
| } | ||
@@ -1268,45 +1434,2 @@ }; | ||
| //#endregion | ||
| //#region src/parsers/SemicolonConfigParser.ts | ||
| /** | ||
| * Config parser to parse semicolon separated string key=value pairs as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses 'foo=bar;baz=qux;secret=secret' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new SemicolonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, Record<string, string>>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| var SemicolonConfigParser = class { | ||
| constructor({ keepCase, protectedKeys, validate, showProtectedKeys } = {}) { | ||
| this.name = "semicolonConfigParser"; | ||
| this.protectedKeys = new Set(protectedKeys); | ||
| this.validate = validate; | ||
| this.keepCase = keepCase ?? true; | ||
| this.showProtectedKeys = showProtectedKeys; | ||
| } | ||
| parse({ value }) { | ||
| return Promise.resolve(parseSemicolonConfig(value, this.keepCase)); | ||
| } | ||
| async postValidate({ value }) { | ||
| return await this.validate?.(value); | ||
| } | ||
| toString(config, options) { | ||
| return stringifySemicolonConfig(config, options?.uriEncode); | ||
| } | ||
| toLogString(config) { | ||
| return logStringifySemicolonConfig(config, this.showProtectedKeys, this.protectedKeys); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/parsers/booleanParser.ts | ||
@@ -1405,51 +1528,124 @@ /** | ||
| //#endregion | ||
| //#region src/parsers/arrayParser.ts | ||
| //#region src/parsers/JsonConfigParser.ts | ||
| /** | ||
| * Build parser for array of values | ||
| * @template Input - Type of input | ||
| * @template Output - Type of output | ||
| * @param {IConfigParser<Input, Output>} parse parser for the array values | ||
| * @param {string} separator separator for the array values, defaults to ';' | ||
| * @param {TypeGuardValidate<Output> | undefined} validate optional post validation | ||
| * @returns {IConfigParser<Output[], Input[]>} Parser for array of values | ||
| * Config parser to parse JSON string as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new JsonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, object>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| function arrayParser(parse, separator = ";", validate) { | ||
| return { | ||
| name: "arraySeparatorParser", | ||
| parse: (props) => { | ||
| return Promise.all(props.value.split(separator).map((v) => parse.parse({ | ||
| ...props, | ||
| value: v | ||
| }))); | ||
| }, | ||
| postValidate: async (props) => { | ||
| if (!validate) return; | ||
| return (await Promise.all(props.value.map(async (v) => { | ||
| if (!(await validate)?.(v)) return; | ||
| return v; | ||
| }))).filter((v) => v !== void 0); | ||
| }, | ||
| toString: (value) => { | ||
| return value.map((v) => parse.toString(v)).join(separator); | ||
| } | ||
| }; | ||
| } | ||
| var JsonConfigParser = class { | ||
| name = "jsonConfigParser"; | ||
| validate; | ||
| showProtectedKeys; | ||
| protectedKeys; | ||
| constructor({ protectedKeys, validate, showProtectedKeys } = {}) { | ||
| this.protectedKeys = new Set(protectedKeys); | ||
| this.validate = validate; | ||
| this.showProtectedKeys = showProtectedKeys; | ||
| } | ||
| parse({ value }) { | ||
| return this.buildBaseRecord(JSON.parse(value)); | ||
| } | ||
| async postValidate({ value }) { | ||
| return await this.validate?.(value); | ||
| } | ||
| toString(config) { | ||
| return JSON.stringify(Object.entries(config).reduce((last, [key, value]) => { | ||
| if (value) last[key] = value; | ||
| return last; | ||
| }, {})); | ||
| } | ||
| toLogString(config) { | ||
| return JSON.stringify(Object.entries(config).reduce((last, [key, value]) => { | ||
| if (value) if (this.protectedKeys.has(key)) last[key] = buildHiddenValue(String(value), this.showProtectedKeys); | ||
| else last[key] = value; | ||
| return last; | ||
| }, {})); | ||
| } | ||
| /** | ||
| * Build a string record from the given data | ||
| * @param {unknown} data - to be validated as object | ||
| * @returns {object} A record with string values | ||
| */ | ||
| buildBaseRecord(data) { | ||
| if (typeof data !== "object" || data === null || Array.isArray(data)) return {}; | ||
| return data; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/parsers/bigIntParser.ts | ||
| //#region src/parsers/SemicolonConfigParser.ts | ||
| /** | ||
| * Config parser to parse semicolon separated string key=value pairs as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses 'foo=bar;baz=qux;secret=secret' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new SemicolonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, Record<string, string>>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| var SemicolonConfigParser = class { | ||
| name = "semicolonConfigParser"; | ||
| validate; | ||
| keepCase; | ||
| showProtectedKeys; | ||
| protectedKeys; | ||
| constructor({ keepCase, protectedKeys, validate, showProtectedKeys } = {}) { | ||
| this.protectedKeys = new Set(protectedKeys); | ||
| this.validate = validate; | ||
| this.keepCase = keepCase ?? true; | ||
| this.showProtectedKeys = showProtectedKeys; | ||
| } | ||
| parse({ value }) { | ||
| return Promise.resolve(parseSemicolonConfig(value, this.keepCase)); | ||
| } | ||
| async postValidate({ value }) { | ||
| return await this.validate?.(value); | ||
| } | ||
| toString(config, options) { | ||
| return stringifySemicolonConfig(config, options?.uriEncode); | ||
| } | ||
| toLogString(config) { | ||
| return logStringifySemicolonConfig(config, this.showProtectedKeys, this.protectedKeys); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/parsers/stringParser.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to bigint | ||
| * @template Output - Type of output, defaults to string | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<bigint, Output>} - parser | ||
| * @returns {IConfigParser<string, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| function bigIntParser(validate) { | ||
| function stringParser(validate) { | ||
| return { | ||
| name: "bigIntParser", | ||
| parse: ({ key, value }) => { | ||
| return getBigInt(value).mapErr((cause) => new TypeError(`value for key ${key} is not an integer string`, { cause })).unwrap(); | ||
| name: "stringParser", | ||
| parse: ({ value, key }) => { | ||
| return getString(value).mapErr((cause) => new TypeError(`value for key ${key} is not a string`, { cause })).unwrap(); | ||
| }, | ||
@@ -1460,4 +1656,7 @@ postValidate: async (props) => { | ||
| }, | ||
| preValidate: ({ key, value }) => { | ||
| if (typeof value !== "string") throw new TypeError(`value for key ${key} is not a string`); | ||
| }, | ||
| toString: (value) => { | ||
| return value.toString(); | ||
| return value; | ||
| } | ||
@@ -1468,222 +1667,48 @@ }; | ||
| //#endregion | ||
| //#region src/VariableLookupError.ts | ||
| //#region src/parsers/UrlParser.ts | ||
| /** | ||
| * Custom error class for variable lookup errors. | ||
| * @class VariableLookupError | ||
| * @augments VariableError | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| * UrlParser class is used to parse and validate env variables of type URL. | ||
| * @class UrlParser | ||
| * @implements {IConfigParser<URL, URL>} | ||
| * @category Parsers | ||
| * @since v0.2.5 | ||
| */ | ||
| var VariableLookupError = class extends VariableError { | ||
| var UrlParser = class { | ||
| name = "urlParser"; | ||
| /** | ||
| * Create a new VariableLookupError | ||
| * @param {string} variableKey - The variable key. | ||
| * @param {string} message - The error message. | ||
| * @param {ErrorOptions} [options] - The error options | ||
| * Should the username and password be sanitized | ||
| */ | ||
| constructor(variableKey, message, options) { | ||
| super(message, options); | ||
| this.variableKey = variableKey; | ||
| this.name = "VariableLookupError"; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ConfigMap.ts | ||
| /** | ||
| * ConfigMap | ||
| * @example | ||
| * type ConfigEnv = { | ||
| * PORT: number; | ||
| * HOST: string; | ||
| * DEBUG: boolean; | ||
| * URL: URL; | ||
| * }; | ||
| * const config = new ConfigMap<ConfigEnv>({ | ||
| * DEBUG: {loaders: [env()], parser: booleanParser, defaultValue: false}, | ||
| * HOST: {loaders: [env()], parser: stringParser, defaultValue: 'localhost'}, | ||
| * PORT: {loaders: [env()], parser: integerParser, defaultValue: 3000}, | ||
| * URL: {loaders: [env()], parser: new UrlParser({urlSanitize: true}), defaultValue: new URL('http://localhost:3000')}, | ||
| * }); | ||
| * console.log('port', await config.get('PORT')); | ||
| * @template Data - type of config map | ||
| * @since v1.1.0 | ||
| */ | ||
| var ConfigMap = class { | ||
| urlSanitize; | ||
| /** | ||
| * ConfigMap constructor | ||
| * @param {EnvMapSchema<Data>} schema - schema of config map | ||
| * @param {Iterable<IConfigLoader>} loaders - iterable of config loaders | ||
| * @param {ConfigOptions} options - optional config options (logger, namespace) | ||
| * Create a new UrlParser | ||
| * @param {UrlParserProps} properties - Properties for the UrlParser | ||
| */ | ||
| constructor(schema, loaders, options = { | ||
| logger: void 0, | ||
| namespace: void 0 | ||
| }) { | ||
| this.schema = schema; | ||
| this.options = options; | ||
| this.loaders = loaders; | ||
| constructor({ urlSanitize } = {}) { | ||
| this.urlSanitize = urlSanitize ?? false; | ||
| } | ||
| /** | ||
| * Set logger value | ||
| * @param {ILoggerLike | undefined} logger - logger like object | ||
| */ | ||
| setLogger(logger) { | ||
| this.options.logger = logger; | ||
| } | ||
| /** | ||
| * get env object from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: LoaderTypeValue<number> = await config.getObject('PORT'); | ||
| * console.log(valueObject.type, valueObject.value); // 'env', 3000 | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getObject(key, encodeOptions) { | ||
| if (typeof key !== "string") throw new VariableError(`ConfigMap key ${String(key)} is not a string`); | ||
| const entry = this.schema[key]; | ||
| if (!entry) throw new VariableLookupError(key, `ConfigMap key ${String(key)} not found in config map`); | ||
| const { parser, defaultValue, params, undefinedThrowsError, undefinedErrorMessage } = entry; | ||
| const configObject = await getConfigObject(key, Array.from(await _luolapeikko_ts_common.LoadableCore.resolve(this.loaders)), parser, defaultValue, params, this.options, encodeOptions); | ||
| if (undefinedThrowsError && configObject.value === void 0) { | ||
| buildOptions(this.options).logger?.info(`ConfigMap key ${String(key)} is undefined (expect to throw error)`); | ||
| throw new VariableError(undefinedErrorMessage ?? `ConfigMap key ${String(key)} is undefined`); | ||
| } | ||
| return configObject; | ||
| } | ||
| /** | ||
| * get env object from config map as Result | ||
| * @returns {Promise<Result<TypeValueRecords<Data>>>} Result Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: Result<LoaderTypeValue<number>> = await config.getObjectResult('PORT'); | ||
| * if (valueObject.isOk()) { | ||
| * const {type, value} = valueObject.ok(); | ||
| * console.log(type, value); // 'env', 3000 | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getObjectResult(key, encodeOptions) { | ||
| parse({ value }) { | ||
| try { | ||
| return (0, _luolapeikko_result_option.Ok)(await this.getObject(key, encodeOptions)); | ||
| return new URL(value); | ||
| } catch (err) { | ||
| return (0, _luolapeikko_result_option.Err)(err); | ||
| throw _luolapeikko_ts_common.ErrorCore.from(err); | ||
| } | ||
| } | ||
| /** | ||
| * get env value from config map | ||
| * @returns {Promise<Data[Key]>} Promise of value or undefined | ||
| * @example | ||
| * const port: number = await config.get('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async get(key, encodeOptions) { | ||
| return (await this.getObject(key, encodeOptions)).value; | ||
| toString(value) { | ||
| return value.href; | ||
| } | ||
| /** | ||
| * get env value as string from config map | ||
| * @returns {Promise<string | undefined>} Promise of string value or undefined | ||
| * @example | ||
| * const port: string = await config.getString('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getString(key, encodeOptions) { | ||
| return (await this.getObject(key, encodeOptions)).stringValue; | ||
| toLogString(value) { | ||
| if (this.urlSanitize) return this.handleUrlSanitize(value.href); | ||
| return value.toString(); | ||
| } | ||
| /** | ||
| * get env value from config map as Result | ||
| * @returns {Promise<Result<Data[Key]>>} Result Promise of value or undefined | ||
| * @example | ||
| * const port: Result<number> = await config.getResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * Build a URL object from a string and sanitize the username and password | ||
| * @param {string} value string to parse | ||
| * @returns {URL} URL object with sanitized username and password | ||
| */ | ||
| async getResult(key, encodeOptions) { | ||
| try { | ||
| return (0, _luolapeikko_result_option.Ok)(await this.get(key, encodeOptions)); | ||
| } catch (err) { | ||
| return (0, _luolapeikko_result_option.Err)(err); | ||
| } | ||
| handleUrlSanitize(value) { | ||
| const url = new URL(value); | ||
| url.password = "*".repeat(url.password.length); | ||
| url.username = "*".repeat(url.username.length); | ||
| return url.href; | ||
| } | ||
| /** | ||
| * get env value as string from config map as Result | ||
| * @returns {Promise<Result<string | undefined>>} Result Promise of string value or undefined | ||
| * @example | ||
| * const port: Result<string> = await config.getStringResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getStringResult(key, encodeOptions) { | ||
| try { | ||
| return (0, _luolapeikko_result_option.Ok)(await this.getString(key, encodeOptions)); | ||
| } catch (err) { | ||
| return (0, _luolapeikko_result_option.Err)(err); | ||
| } | ||
| } | ||
| /** | ||
| * get all env value objects from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of all values | ||
| * @example | ||
| * const values: TypeValueRecords<Data> = await config.getAll(); | ||
| * console.log(values.PORT.type, values.PORT.value); // 'env', 3000 | ||
| */ | ||
| async getAllObjects() { | ||
| return (await this.getAllPromises()).reduce((result, [key, value]) => { | ||
| result[key] = value; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * get all env values from config map | ||
| * @returns {Promise<Data>} Promise of all values | ||
| * @example | ||
| * const values: Data = await config.getAllValues(); | ||
| * console.log('PORT', values.PORT); // 3000 (number) | ||
| */ | ||
| async getAllValues() { | ||
| return (await this.getAllPromises()).reduce((result, [key, value]) => { | ||
| result[key] = value.value; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * get all env values from config map as string | ||
| * @returns {Promise<Record<keyof Data, string>>} Promise of all values as string | ||
| * @example | ||
| * const values: Record<keyof Data, string> = await config.getAllStringValues(); | ||
| * console.log('PORT', values.PORT); // '3000' (string) | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getAllStringValues(encodeOptions) { | ||
| return (await this.getAllPromises(encodeOptions)).reduce((result, [key, value]) => { | ||
| result[key] = value.stringValue; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * Validate all env values from config map, expect to throw error if error exists | ||
| * @param {(data: Data) => void} callback callback function | ||
| */ | ||
| async validateAll(callback) { | ||
| callback(await this.getAllValues()); | ||
| } | ||
| /** | ||
| * run lookup to all keys and return all promises | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<[keyof Data, LoaderTypeValueStrict<Data[keyof Data]>][]>} Promise of all values | ||
| */ | ||
| getAllPromises(encodeOptions) { | ||
| return Promise.all(Object.keys(this.schema).map(async (key) => { | ||
| return [key, await this.getObject(key, encodeOptions)]; | ||
| })); | ||
| } | ||
| }; | ||
@@ -1690,0 +1715,0 @@ |
+985
-946
@@ -1,15 +0,46 @@ | ||
| import { Loadable } from "@luolapeikko/ts-common"; | ||
| import { ILoggerLike, ISetOptionalLogger } from "@avanio/logger-like"; | ||
| import { IResult } from "@luolapeikko/result-option"; | ||
| import { Loadable } from "@luolapeikko/ts-common"; | ||
| import { EventEmitter } from "events"; | ||
| //#region src/ConfigOptions.d.ts | ||
| /** | ||
| * ConfigOptions | ||
| * @category Config | ||
| * @since v0.6.0 | ||
| */ | ||
| type ConfigOptions = { | ||
| /** undefined = global logger, null = no logger else it's ILoggerLike */logger?: ILoggerLike | null; /** optional namespace added to logs */ | ||
| namespace?: string; | ||
| }; | ||
| /** | ||
| * SolvedConfigOptions | ||
| * @category Config | ||
| * @since v0.6.0 | ||
| */ | ||
| type SolvedConfigOptions = { | ||
| /** optional logger instance */logger: ILoggerLike | undefined; /** optional namespace added to logs */ | ||
| namespace: string | undefined; | ||
| }; | ||
| /** | ||
| * Build options from partial options | ||
| * @param {Partial<ConfigOptions>} options - partial config options | ||
| * @returns {SolvedConfigOptions} - solved config options | ||
| * @category Config | ||
| * @since v0.6.0 | ||
| */ | ||
| declare function buildOptions({ | ||
| logger, | ||
| namespace | ||
| }?: Partial<ConfigOptions>): SolvedConfigOptions; | ||
| //#endregion | ||
| //#region src/interfaces/IConfigLoader.d.ts | ||
| /** | ||
| * Represents the result of loading a configuration value. | ||
| * @property value - The value associated with the configuration key, or `undefined` if not found. | ||
| * @property path - The source path from which the value was loaded. | ||
| * @property seen - Indicates whether the key and value have already been encountered (used for logging purposes). | ||
| * @since v0.8.0 | ||
| * @category Loaders | ||
| */ | ||
| * Represents the result of loading a configuration value. | ||
| * @property value - The value associated with the configuration key, or `undefined` if not found. | ||
| * @property path - The source path from which the value was loaded. | ||
| * @property seen - Indicates whether the key and value have already been encountered (used for logging purposes). | ||
| * @since v0.8.0 | ||
| * @category Loaders | ||
| */ | ||
| type LoaderValueResult = { | ||
@@ -21,6 +52,6 @@ /** this is shown on logs `ConfigVariables[type]: KEY [___VALUE___] from {path}` if showValue is true */value: string | undefined; /** this is shown on logs `ConfigVariables[type]: KEY [VALUE] from {___path___}` */ | ||
| /** | ||
| * Interface for config loaders | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| * Interface for config loaders | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| interface IConfigLoader { | ||
@@ -30,33 +61,33 @@ /** this is shown on logs `ConfigVariables[___type___]: KEY [VALUE] from {path}` */ | ||
| /** | ||
| * get loader result for lookupKey | ||
| * @param {string} lookupKey - key to lookup | ||
| * @returns {undefined | LoaderValueResult | Promise<undefined | LoaderValueResult>} - Promise of LoaderValueResult or undefined | ||
| */ | ||
| * get loader result for lookupKey | ||
| * @param {string} lookupKey - key to lookup | ||
| * @returns {undefined | LoaderValueResult | Promise<undefined | LoaderValueResult>} - Promise of LoaderValueResult or undefined | ||
| */ | ||
| getLoaderResult(lookupKey: string): undefined | LoaderValueResult | Promise<undefined | LoaderValueResult>; | ||
| /** | ||
| * Check if loader is disabled | ||
| * @returns {boolean | undefined | Promise<boolean | undefined>} - Promise of boolean or undefined | ||
| */ | ||
| * Check if loader is disabled | ||
| * @returns {boolean | undefined | Promise<boolean | undefined>} - Promise of boolean or undefined | ||
| */ | ||
| isLoaderDisabled(): boolean | undefined | Promise<boolean | undefined>; | ||
| } | ||
| /** | ||
| * Helper type to write override keys to config loaders | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| * @example | ||
| * type OverrideKeyMap = InferOverrideKeyMap<MainEnv & TestEnv>; | ||
| * // Example usage of OverrideKeyMap, where the keys are the original config keys and the values are the override keys | ||
| * const env = new EnvConfigLoader<OverrideKeyMap>(undefined, {PORT: 'HTTP_PORT'}); // get PORT value from process.env.HTTP_PORT | ||
| */ | ||
| * Helper type to write override keys to config loaders | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| * @example | ||
| * type OverrideKeyMap = InferOverrideKeyMap<MainEnv & TestEnv>; | ||
| * // Example usage of OverrideKeyMap, where the keys are the original config keys and the values are the override keys | ||
| * const env = new EnvConfigLoader<OverrideKeyMap>(undefined, {PORT: 'HTTP_PORT'}); // get PORT value from process.env.HTTP_PORT | ||
| */ | ||
| type OverrideKeyMap = Record<string, string>; | ||
| /** | ||
| * Helper infer type to write override keys to config loaders | ||
| * @template T - The type of the config object. | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| * @example | ||
| * type OverrideKeyMap = InferOverrideKeyMap<MainEnv & TestEnv>; | ||
| * // Example usage of OverrideKeyMap, where the keys are the original config keys and the values are the override keys | ||
| * const env = new EnvConfigLoader<OverrideKeyMap>(undefined, {PORT: 'HTTP_PORT'}); // get PORT value from process.env.HTTP_PORT | ||
| */ | ||
| * Helper infer type to write override keys to config loaders | ||
| * @template T - The type of the config object. | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| * @example | ||
| * type OverrideKeyMap = InferOverrideKeyMap<MainEnv & TestEnv>; | ||
| * // Example usage of OverrideKeyMap, where the keys are the original config keys and the values are the override keys | ||
| * const env = new EnvConfigLoader<OverrideKeyMap>(undefined, {PORT: 'HTTP_PORT'}); // get PORT value from process.env.HTTP_PORT | ||
| */ | ||
| type InferOverrideKeyMap<T> = Record<keyof T, string>; | ||
@@ -66,5 +97,5 @@ //#endregion | ||
| /** | ||
| * Parser method props | ||
| * @since v0.11.0 | ||
| */ | ||
| * Parser method props | ||
| * @since v0.11.0 | ||
| */ | ||
| type ParserProps = { | ||
@@ -76,5 +107,5 @@ loader: IConfigLoader; | ||
| /** | ||
| * PreValidate method props | ||
| * @since v0.11.0 | ||
| */ | ||
| * PreValidate method props | ||
| * @since v0.11.0 | ||
| */ | ||
| type PreValidateProps = { | ||
@@ -86,6 +117,6 @@ loader: IConfigLoader; | ||
| /** | ||
| * PostValidate method props | ||
| * @template T - Type of value | ||
| * @since v0.11.0 | ||
| */ | ||
| * PostValidate method props | ||
| * @template T - Type of value | ||
| * @since v0.11.0 | ||
| */ | ||
| type PostValidateProps<T> = { | ||
@@ -97,198 +128,186 @@ loader: IConfigLoader; | ||
| /** | ||
| * PreValidate function | ||
| * @template Output - Type of output value | ||
| * @since v1.0.0 | ||
| */ | ||
| * PreValidate function | ||
| * @template Output - Type of output value | ||
| * @since v1.0.0 | ||
| */ | ||
| type TypeGuardValidate<Output> = ((value: unknown) => value is Output) | Promise<(value: unknown) => value is Output>; | ||
| /** | ||
| * String encoder options for parsers | ||
| * @since v0.11.0 | ||
| */ | ||
| * String encoder options for parsers | ||
| * @since v0.11.0 | ||
| */ | ||
| type EncodeOptions = { | ||
| /** | ||
| * use URI encoding for string outputs (used by semicolon parser) | ||
| */ | ||
| * use URI encoding for string outputs (used by semicolon parser) | ||
| */ | ||
| uriEncode?: boolean; | ||
| /** | ||
| * not logging the value | ||
| */ | ||
| * not logging the value | ||
| */ | ||
| silent?: boolean; | ||
| }; | ||
| /** | ||
| * Interface for config parsers | ||
| * @template Input - Type of raw input value | ||
| * @template Output - Type of output value | ||
| * @since v1.0.0 | ||
| */ | ||
| * Interface for config parsers | ||
| * @template Input - Type of raw input value | ||
| * @template Output - Type of output value | ||
| * @since v1.0.0 | ||
| */ | ||
| interface IConfigParser<Input, Output> { | ||
| /** | ||
| * name of the parser | ||
| */ | ||
| * name of the parser | ||
| */ | ||
| name: string; | ||
| /** | ||
| * Config parser function | ||
| * @throws Error if parsing fails | ||
| */ | ||
| * Config parser function | ||
| * @throws Error if parsing fails | ||
| */ | ||
| parse(parserProps: ParserProps): Input | Promise<Input>; | ||
| /** | ||
| * Optional raw string value validation before parsing. | ||
| * @throws Error if validation fails | ||
| */ | ||
| * Optional raw string value validation before parsing. | ||
| * @throws Error if validation fails | ||
| */ | ||
| preValidate?(preValidateProps: PreValidateProps): void | Promise<void>; | ||
| /** | ||
| * Optional value validation after parsing | ||
| * @throws Error if validation fails | ||
| */ | ||
| * Optional value validation after parsing | ||
| * @throws Error if validation fails | ||
| */ | ||
| postValidate?(postValidateProps: PostValidateProps<Input>): Output | undefined | Promise<Output | undefined>; | ||
| /** | ||
| * Build readable string from value | ||
| */ | ||
| * Build readable string from value | ||
| */ | ||
| toString(config: Output, options?: EncodeOptions): string; | ||
| /** | ||
| * Optional build readable string from value for log (can hide sensitive part from logs) else toString is used | ||
| * @param config - value to log | ||
| */ | ||
| * Optional build readable string from value for log (can hide sensitive part from logs) else toString is used | ||
| * @param config - value to log | ||
| */ | ||
| toLogString?(config: Output): string; | ||
| } | ||
| //#endregion | ||
| //#region src/interfaces/IValidate.d.ts | ||
| /** | ||
| * Interface for validation function | ||
| * @template Input - Type of raw input | ||
| * @template Output - Type of output | ||
| * @since v1.0.0 | ||
| */ | ||
| type ValidateCallback<Input, Output> = (data: Input) => Output | Promise<Output>; | ||
| //#endregion | ||
| //#region src/interfaces/IRequestCache.d.ts | ||
| /** | ||
| * interface for a request cache | ||
| * @category Utils | ||
| * @example | ||
| * const exampleCache: IRequestCache = { | ||
| * isOnline() { | ||
| * return (typeof window !== 'undefined' && window.navigator && window.navigator.onLine) || true; | ||
| * }, | ||
| * async fetchRequest(req: Request) { | ||
| * if (typeof window !== 'undefined' && window.caches) { | ||
| * const cache = await window.caches.open('fetch'); | ||
| * return cache.match(req); | ||
| * } | ||
| * return undefined; | ||
| * }, | ||
| * async storeRequest(req: Request, res: Response) { | ||
| * if (typeof window !== 'undefined' && window.caches && res.ok) { | ||
| * const cache = await window.caches.open('fetch'); | ||
| * req.headers.delete('Authorization'); | ||
| * await cache.put(req, res.clone()); | ||
| * } | ||
| * }, | ||
| * }; | ||
| * @since v0.2.8 | ||
| */ | ||
| * interface for a request cache | ||
| * @category Utils | ||
| * @example | ||
| * const exampleCache: IRequestCache = { | ||
| * isOnline() { | ||
| * return (typeof window !== 'undefined' && window.navigator && window.navigator.onLine) || true; | ||
| * }, | ||
| * async fetchRequest(req: Request) { | ||
| * if (typeof window !== 'undefined' && window.caches) { | ||
| * const cache = await window.caches.open('fetch'); | ||
| * return cache.match(req); | ||
| * } | ||
| * return undefined; | ||
| * }, | ||
| * async storeRequest(req: Request, res: Response) { | ||
| * if (typeof window !== 'undefined' && window.caches && res.ok) { | ||
| * const cache = await window.caches.open('fetch'); | ||
| * req.headers.delete('Authorization'); | ||
| * await cache.put(req, res.clone()); | ||
| * } | ||
| * }, | ||
| * }; | ||
| * @since v0.2.8 | ||
| */ | ||
| interface IRequestCache { | ||
| /** | ||
| * check if the client is connected to the internet | ||
| */ | ||
| * check if the client is connected to the internet | ||
| */ | ||
| isOnline(): boolean; | ||
| /** | ||
| * get the cached response for a request | ||
| */ | ||
| * get the cached response for a request | ||
| */ | ||
| fetchRequest(req: Request): Promise<Response | undefined>; | ||
| /** | ||
| * store the response for a request | ||
| */ | ||
| * store the response for a request | ||
| */ | ||
| storeRequest(req: Request, res: Response): Promise<void>; | ||
| } | ||
| //#endregion | ||
| //#region src/types/RequestNotReady.d.ts | ||
| //#region src/interfaces/IValidate.d.ts | ||
| /** | ||
| * RequestNotReady indicates that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| interface RequestNotReady { | ||
| _type: 'RequestNotReady'; | ||
| message: string; | ||
| } | ||
| * Interface for validation function | ||
| * @template Input - Type of raw input | ||
| * @template Output - Type of output | ||
| * @since v1.0.0 | ||
| */ | ||
| type ValidateCallback<Input, Output> = (data: Input) => Output | Promise<Output>; | ||
| //#endregion | ||
| //#region src/lib/formatUtils.d.ts | ||
| /** | ||
| * Type guard for RequestNotReady | ||
| * @param {unknown} obj - object to check if it is a RequestNotReady payload | ||
| * @returns {boolean} boolean indicating if the object is a RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| declare function isRequestNotReadMessage(obj: unknown): obj is RequestNotReady; | ||
| * PartialHiddenValueStringType is the type for partial hidden value string, it can be 'prefix', 'suffix' or 'prefix-suffix' | ||
| * - 'prefix': show only prefix of secret "j43****" | ||
| * - 'suffix': show only suffix of secret "****7hd" | ||
| * - 'prefix-suffix': show both prefix and suffix of secret "j43****7hd" | ||
| * @since v0.9.0 | ||
| * @category Utils | ||
| */ | ||
| type PartialHiddenValueStringType = "prefix" | "suffix" | "prefix-suffix"; | ||
| /** | ||
| * function to create a RequestNotReady payload to indicate that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @param {string} message - reason why the request is not ready yet | ||
| * @returns {RequestNotReady} RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| declare function createRequestNotReady(message: string): RequestNotReady; | ||
| //#endregion | ||
| //#region src/lib/formatUtils.d.ts | ||
| type PartialHiddenValueStringType = /** show only prefix of secret "j43****" */'prefix' /** show only suffix of secret "****7hd" */ | 'suffix' /** show both prefix and suffix of secret "j43****7hd" */ | 'prefix-suffix'; | ||
| * ShowValueType is the type for show value option, it can be boolean or PartialHiddenValueStringType | ||
| * - true: show the actual value | ||
| * - false: show the value with asterisks | ||
| * - PartialHiddenValueStringType: shows part of the value (prefix, suffix, or both) | ||
| * @since v0.9.0 | ||
| */ | ||
| type ShowValueType = boolean | PartialHiddenValueStringType; | ||
| /** | ||
| * Format parameters for the variables | ||
| * @since v0.2.5 | ||
| */ | ||
| * Format parameters for the variables | ||
| * @since v0.2.5 | ||
| */ | ||
| interface FormatParameters { | ||
| /** | ||
| * Whether to show the value in the output, defaults to undefined | ||
| * - undefined: hide the value | ||
| * - true: show the actual value | ||
| * - false: show the value with asterisks | ||
| * - 'prefix': show only prefix of value (1-3 characters based on length of the value) | ||
| * - 'suffix': show only suffix of value (1-3 characters based on length of the value) | ||
| * - 'both': show both prefix and suffix of value (1-2 characters on suffix and prefix based on length of the value) | ||
| * @default false | ||
| */ | ||
| * Whether to show the value in the output, defaults to undefined | ||
| * - undefined: hide the value | ||
| * - true: show the actual value | ||
| * - false: show the value with asterisks | ||
| * - 'prefix': show only prefix of value (1-3 characters based on length of the value) | ||
| * - 'suffix': show only suffix of value (1-3 characters based on length of the value) | ||
| * - 'both': show both prefix and suffix of value (1-2 characters on suffix and prefix based on length of the value) | ||
| * @default false | ||
| */ | ||
| showValue?: ShowValueType; | ||
| } | ||
| /** | ||
| * Sanitizes a URL by replacing the username and password with asterisks. | ||
| * @param {string} value - The URL to sanitize. | ||
| * @param {ILoggerLike} [logger] - An optional logger to use for logging warnings. | ||
| * @returns {string} The sanitized URL. | ||
| * @category Utils | ||
| * @since v0.2.5 | ||
| */ | ||
| * Sanitizes a URL by replacing the username and password with asterisks. | ||
| * @param {string} value - The URL to sanitize. | ||
| * @param {ILoggerLike} [logger] - An optional logger to use for logging warnings. | ||
| * @returns {string} The sanitized URL. | ||
| * @category Utils | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function urlSanitize$1(value: string, logger?: ILoggerLike): string; | ||
| /** | ||
| * Returns a formatted string representation of a value, enclosed in square brackets. | ||
| * @param {string | undefined} value - The value to format. | ||
| * @param {FormatParameters | undefined} config - An optional configuration object. | ||
| * @returns {string} The formatted string representation of the value. | ||
| * @category Utils | ||
| * @since v0.2.5 | ||
| */ | ||
| * Returns a formatted string representation of a value, enclosed in square brackets. | ||
| * @param {string | undefined} value - The value to format. | ||
| * @param {FormatParameters | undefined} config - An optional configuration object. | ||
| * @returns {string} The formatted string representation of the value. | ||
| * @category Utils | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function printValue(value: string | undefined, config: FormatParameters | undefined): string; | ||
| /** | ||
| * Constructs a hidden value string based on the specified visibility option. | ||
| * @param {string} value - The original string value to be hidden. | ||
| * @param {ShowValueType | undefined} show - Determines how the value should be displayed: | ||
| * - `true`: shows the full value | ||
| * - `undefined` or `false`: hides the value completely with asterisks | ||
| * - `PartialHiddenValueStringType`: shows part of the value (prefix, suffix, or both) | ||
| * @returns {string} The resulting string with the specified visibility. | ||
| * @since v0.2.5 | ||
| */ | ||
| * Constructs a hidden value string based on the specified visibility option. | ||
| * @param {string} value - The original string value to be hidden. | ||
| * @param {ShowValueType | undefined} show - Determines how the value should be displayed: | ||
| * - `true`: shows the full value | ||
| * - `undefined` or `false`: hides the value completely with asterisks | ||
| * - `PartialHiddenValueStringType`: shows part of the value (prefix, suffix, or both) | ||
| * @returns {string} The resulting string with the specified visibility. | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildHiddenValue(value: string, show: ShowValueType | undefined): string; | ||
| /** | ||
| * Builds a hidden value string, replacing each character with an asterisk. | ||
| * @param {string} value - The value to be hidden. | ||
| * @returns {string} The hidden value string with asterisks. | ||
| * @since v0.2.5 | ||
| */ | ||
| * Builds a hidden value string, replacing each character with an asterisk. | ||
| * @param {string} value - The value to be hidden. | ||
| * @returns {string} The hidden value string with asterisks. | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildHiddenAsterisksValueString(value: string): string; | ||
| /** | ||
| * Show only 1-3 characters of the secret value based on length of the value. | ||
| * @param {string} value - The value to partially hide. | ||
| * @param {PartialHiddenValueStringType} type - The type of partial hiding to apply ('prefix', 'suffix', or 'prefix-suffix'). | ||
| * @returns {string} The partially hidden value string. | ||
| * @since v0.2.5 | ||
| */ | ||
| * Show only 1-3 characters of the secret value based on length of the value. | ||
| * @param {string} value - The value to partially hide. | ||
| * @param {PartialHiddenValueStringType} type - The type of partial hiding to apply ('prefix', 'suffix', or 'prefix-suffix'). | ||
| * @returns {string} The partially hidden value string. | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildPartialHiddenValueString(value: string, type: PartialHiddenValueStringType): string; | ||
@@ -298,87 +317,87 @@ //#endregion | ||
| /** | ||
| * Optional environment entry | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| * Optional environment entry | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| type OptionalEnvEntry<Value> = { | ||
| /** | ||
| * The parser to use to parse the value | ||
| */ | ||
| * The parser to use to parse the value | ||
| */ | ||
| parser: IConfigParser<unknown, Value>; | ||
| /** | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| defaultValue?: Loadable<Value>; | ||
| /** | ||
| * The format parameters to use to format the value | ||
| */ | ||
| * The format parameters to use to format the value | ||
| */ | ||
| params?: FormatParameters; | ||
| /** | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| undefinedThrowsError?: boolean; | ||
| /** | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| undefinedErrorMessage?: string; | ||
| }; | ||
| /** | ||
| * Required environment entry | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| * Required environment entry | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| type RequiredEnvEntry<Value> = { | ||
| /** | ||
| * The parser to use to parse the value | ||
| */ | ||
| * The parser to use to parse the value | ||
| */ | ||
| parser: IConfigParser<unknown, Value>; | ||
| /** | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| defaultValue: Loadable<Value>; | ||
| /** | ||
| * The format parameters to use to format the value | ||
| */ | ||
| * The format parameters to use to format the value | ||
| */ | ||
| params?: FormatParameters; | ||
| /** | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| undefinedThrowsError?: boolean; | ||
| /** | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| undefinedErrorMessage?: string; | ||
| }; | ||
| /** | ||
| * Required environment entry with undefinedThrowsError | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| * Required environment entry with undefinedThrowsError | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| type RequiredUndefinedThrowEntry<Value> = { | ||
| /** | ||
| * The parser to use to parse the value | ||
| */ | ||
| * The parser to use to parse the value | ||
| */ | ||
| parser: IConfigParser<unknown, Value>; | ||
| /** | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| defaultValue?: Loadable<Value>; | ||
| /** | ||
| * The format parameters to use to format the value | ||
| */ | ||
| * The format parameters to use to format the value | ||
| */ | ||
| params?: FormatParameters; | ||
| /** | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| undefinedThrowsError: true; | ||
| /** | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| undefinedErrorMessage?: string; | ||
| }; | ||
| /** | ||
| * Environment map schema | ||
| * @template Output - type of output value | ||
| * @since v0.2.15 | ||
| */ | ||
| * Environment map schema | ||
| * @template Output - type of output value | ||
| * @since v0.2.15 | ||
| */ | ||
| type EnvMapSchema<Output extends Record<string, unknown>> = { [K in keyof Required<Output>]: undefined extends Output[K] ? OptionalEnvEntry<Output[K]> : RequiredEnvEntry<Output[K]> | RequiredUndefinedThrowEntry<Output[K]> }; | ||
@@ -388,6 +407,6 @@ //#endregion | ||
| /** | ||
| * Loader type value | ||
| * @template T - type of value | ||
| * @since 0.2.18 | ||
| */ | ||
| * Loader type value | ||
| * @template T - type of value | ||
| * @since 0.2.18 | ||
| */ | ||
| type LoaderTypeValue<T> = { | ||
@@ -400,6 +419,6 @@ /** type of loader output (default, env,...) */type: string | undefined; /** output value */ | ||
| /** | ||
| * Loader type strict value | ||
| * @template T - type of value | ||
| * @since 0.2.18 | ||
| */ | ||
| * Loader type strict value | ||
| * @template T - type of value | ||
| * @since 0.2.18 | ||
| */ | ||
| type LoaderTypeValueStrict<T> = { | ||
@@ -412,94 +431,176 @@ /** type of loader output (default, env,...) */type: string | undefined; /** output value */ | ||
| //#endregion | ||
| //#region src/ConfigOptions.d.ts | ||
| type ConfigOptions = { | ||
| /** undefined = global logger, null = no logger else it's ILoggerLike */logger?: ILoggerLike | null; /** optional namespace added to logs */ | ||
| namespace?: string; | ||
| }; | ||
| type SolvedConfigOptions = { | ||
| /** optional logger instance */logger: ILoggerLike | undefined; /** optional namespace added to logs */ | ||
| namespace: string | undefined; | ||
| }; | ||
| //#region src/ConfigMap.d.ts | ||
| /** | ||
| * Build options from partial options | ||
| * @param {Partial<ConfigOptions>} options - partial config options | ||
| * @returns {SolvedConfigOptions} - solved config options | ||
| * @category Config | ||
| * @since v0.6.0 | ||
| */ | ||
| declare function buildOptions({ | ||
| logger, | ||
| namespace | ||
| }?: Partial<ConfigOptions>): SolvedConfigOptions; | ||
| //#endregion | ||
| //#region src/getConfigVariable.d.ts | ||
| * TypeValueRecords | ||
| * @template T - type of config map | ||
| * @since v0.6.0 | ||
| */ | ||
| type TypeValueRecords<T> = Record<keyof T, LoaderTypeValueStrict<T[keyof T]>>; | ||
| /** | ||
| * get config variable from loaders | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * | ||
| * const port: Promise<string> = await getConfigVariable('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * // with override key | ||
| * const port: Promise<string> = await getConfigVariable('PORT', [env('HTTP_PORT', fileEnv())], stringParser, '8080', {showValue: true}); | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey - root key of config variable | ||
| * @param {IConfigLoader[]} loaders - loaders to use | ||
| * @param {IConfigParser<unknown, Output>} parser - parser to use | ||
| * @param {Loadable<Output>} [defaultValueLoadable] - default value to use | ||
| * @param {FormatParameters} [params] - optional format parameters | ||
| * @param {ConfigOptions} [options] - optional config options | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<Output>} - config variable | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function getConfigVariable<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<Output>; | ||
| declare function getConfigVariable<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<Output | undefined>; | ||
| * ConfigMap | ||
| * @example | ||
| * type ConfigEnv = { | ||
| * PORT: number; | ||
| * HOST: string; | ||
| * DEBUG: boolean; | ||
| * URL: URL; | ||
| * }; | ||
| * const env = new EnvConfigLoader(); | ||
| * const config = new ConfigMap<ConfigEnv>( | ||
| * { | ||
| * DEBUG: {defaultValue: false, parser: booleanParser()}, | ||
| * HOST: {defaultValue: 'localhost', parser: stringParser()}, | ||
| * PORT: {defaultValue: 3000, parser: integerParser()}, | ||
| * URL: {defaultValue: new URL('http://localhost:3000'), parser: new UrlParser({urlSanitize: true})}, | ||
| * }, | ||
| * [env], | ||
| * ); | ||
| * console.log('port', await config.get('PORT')); | ||
| * @template Data - type of config map | ||
| * @since v1.1.0 | ||
| */ | ||
| declare class ConfigMap<Data extends Record<string, unknown>> implements ISetOptionalLogger { | ||
| private schema; | ||
| private options; | ||
| private loaders; | ||
| /** | ||
| * ConfigMap constructor | ||
| * @param {EnvMapSchema<Data>} schema - schema of config map | ||
| * @param {Iterable<IConfigLoader>} loaders - iterable of config loaders | ||
| * @param {ConfigOptions} options - optional config options (logger, namespace) | ||
| */ | ||
| constructor(schema: EnvMapSchema<Data>, loaders: Loadable<Iterable<IConfigLoader>>, options?: ConfigOptions); | ||
| /** | ||
| * Set logger value | ||
| * @param {ILoggerLike | undefined} logger - logger like object | ||
| */ | ||
| setLogger(logger: ILoggerLike | undefined): void; | ||
| /** | ||
| * get env object from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: LoaderTypeValue<number> = await config.getObject('PORT'); | ||
| * console.log(valueObject.type, valueObject.value); // 'env', 3000 | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getObject<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<LoaderTypeValueStrict<Data[Key]>>; | ||
| /** | ||
| * get env object from config map as Result | ||
| * @returns {Promise<Result<TypeValueRecords<Data>>>} Result Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: Result<LoaderTypeValue<number>> = await config.getObjectResult('PORT'); | ||
| * if (valueObject.isOk()) { | ||
| * const {type, value} = valueObject.ok(); | ||
| * console.log(type, value); // 'env', 3000 | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getObjectResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<LoaderTypeValueStrict<Data[Key]>>>; | ||
| /** | ||
| * get env value from config map | ||
| * @returns {Promise<Data[Key]>} Promise of value or undefined | ||
| * @example | ||
| * const port: number = await config.get('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| get<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<Data[Key]>; | ||
| /** | ||
| * get env value as string from config map | ||
| * @returns {Promise<string | undefined>} Promise of string value or undefined | ||
| * @example | ||
| * const port: string = await config.getString('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getString<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<undefined extends Data[Key] ? string | undefined : string>; | ||
| /** | ||
| * get env value from config map as Result | ||
| * @returns {Promise<Result<Data[Key]>>} Result Promise of value or undefined | ||
| * @example | ||
| * const port: Result<number> = await config.getResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<Data[Key]>>; | ||
| /** | ||
| * get env value as string from config map as Result | ||
| * @returns {Promise<Result<string | undefined>>} Result Promise of string value or undefined | ||
| * @example | ||
| * const port: Result<string> = await config.getStringResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getStringResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<undefined extends Data[Key] ? string | undefined : string>>; | ||
| /** | ||
| * get all env value objects from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of all values | ||
| * @example | ||
| * const values: TypeValueRecords<Data> = await config.getAll(); | ||
| * console.log(values.PORT.type, values.PORT.value); // 'env', 3000 | ||
| */ | ||
| getAllObjects(): Promise<TypeValueRecords<Data>>; | ||
| /** | ||
| * get all env values from config map | ||
| * @returns {Promise<Data>} Promise of all values | ||
| * @example | ||
| * const values: Data = await config.getAllValues(); | ||
| * console.log('PORT', values.PORT); // 3000 (number) | ||
| */ | ||
| getAllValues(): Promise<Data>; | ||
| /** | ||
| * get all env values from config map as string | ||
| * @returns {Promise<Record<keyof Data, string>>} Promise of all values as string | ||
| * @example | ||
| * const values: Record<keyof Data, string> = await config.getAllStringValues(); | ||
| * console.log('PORT', values.PORT); // '3000' (string) | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getAllStringValues(encodeOptions?: EncodeOptions): Promise<Record<keyof Data, string>>; | ||
| /** | ||
| * Validate all env values from config map, expect to throw error if error exists | ||
| * @param {(data: Data) => void} callback callback function | ||
| */ | ||
| validateAll(callback: (data: Data) => void): Promise<void>; | ||
| /** | ||
| * run lookup to all keys and return all promises | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<[keyof Data, LoaderTypeValueStrict<Data[keyof Data]>][]>} Promise of all values | ||
| */ | ||
| private getAllPromises; | ||
| } | ||
| //#endregion | ||
| //#region src/getConfigVariableResult.d.ts | ||
| /** | ||
| * get config variable from loaders | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const portResult: Result<string> = await getConfigVariableResult('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * | ||
| * const value: string = portResult.unwrap(); // get value or throw error | ||
| * const value: string | undefined = portResult.ok(); // get value or undefined | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey - root key of config variable | ||
| * @param {IConfigLoader[]} loaders - loaders to use | ||
| * @param {IConfigParser<unknown, Output>} parser - parser to use | ||
| * @param {Loadable<Output>} [defaultValueLoadable] - default value to use | ||
| * @param {FormatParameters} [params] - optional format parameters | ||
| * @param {ConfigOptions} [options] - optional config options | ||
| * @returns {Promise<IResult<Output | undefined>>} - result with value or error | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function getConfigVariableResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<Output>>; | ||
| declare function getConfigVariableResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<Output | undefined>>; | ||
| //#endregion | ||
| //#region src/getConfigObject.d.ts | ||
| /** | ||
| * Clear the seen map for default values (for unit testing purposes) | ||
| * @since v0.2.5 | ||
| */ | ||
| * Clear the seen map for default values (for unit testing purposes) | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function clearDefaultValueSeenMap(): void; | ||
| /** | ||
| * get config object which contains value and type of loader | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * const portConfig: {type: string | undefined; value: string} = await getConfigObject('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * const value: string = portConfig.value; | ||
| * const type: string | undefined = portConfig.type; // loader type name | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey root key of config object | ||
| * @param {IConfigLoader[]} loaders array of loaders | ||
| * @param {IConfigParser<unknown, Output>} parser parser for value | ||
| * @param {Loadable<Output>} defaultValueLoadable optional default value | ||
| * @param {FormatParameters} params optional format parameters | ||
| * @param {ConfigOptions} options optional config options | ||
| * @param {EncodeOptions} [encodeOptions] optional encode options | ||
| * @returns {Promise<LoaderTypeValue<Output>>} config object | ||
| * @since v0.2.5 | ||
| */ | ||
| * get config object which contains value and type of loader | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * const portConfig: {type: string | undefined; value: string} = await getConfigObject('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * const value: string = portConfig.value; | ||
| * const type: string | undefined = portConfig.type; // loader type name | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey root key of config object | ||
| * @param {IConfigLoader[]} loaders array of loaders | ||
| * @param {IConfigParser<unknown, Output>} parser parser for value | ||
| * @param {Loadable<Output>} defaultValueLoadable optional default value | ||
| * @param {FormatParameters} params optional format parameters | ||
| * @param {ConfigOptions} options optional config options | ||
| * @param {EncodeOptions} [encodeOptions] optional encode options | ||
| * @returns {Promise<LoaderTypeValue<Output>>} config object | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function getConfigObject<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<LoaderTypeValueStrict<Output>>; | ||
@@ -510,22 +611,22 @@ declare function getConfigObject<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<LoaderTypeValue<Output>>; | ||
| /** | ||
| * Wrapper around getConfigObject that returns a Result | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * const portConfig: Result<{type: string | undefined; value: string}> = await getConfigObject('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * if ( portConfig.isOk() ) { | ||
| * const {value, type} = portConfig.unwrap(); | ||
| * } else { | ||
| * // handle error | ||
| * } | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey root key of config object | ||
| * @param {IConfigLoader[]} loaders array of loaders | ||
| * @param {IConfigParser<unknown, Output>} parser parser for value | ||
| * @param {Loadable<Output>} defaultValueLoadable optional default value | ||
| * @param {FormatParameters} params optional format parameters | ||
| * @param {ConfigOptions} options optional config options | ||
| * @returns {Promise<IResult<{type: string | undefined; value: Output}>>} result | ||
| * @since v0.2.5 | ||
| */ | ||
| * Wrapper around getConfigObject that returns a Result | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * const portConfig: Result<{type: string | undefined; value: string}> = await getConfigObject('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * if ( portConfig.isOk() ) { | ||
| * const {value, type} = portConfig.unwrap(); | ||
| * } else { | ||
| * // handle error | ||
| * } | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey root key of config object | ||
| * @param {IConfigLoader[]} loaders array of loaders | ||
| * @param {IConfigParser<unknown, Output>} parser parser for value | ||
| * @param {Loadable<Output>} defaultValueLoadable optional default value | ||
| * @param {FormatParameters} params optional format parameters | ||
| * @param {ConfigOptions} options optional config options | ||
| * @returns {Promise<IResult<{type: string | undefined; value: Output}>>} result | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function getConfigObjectResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<{ | ||
@@ -540,8 +641,133 @@ type: string | undefined; | ||
| //#endregion | ||
| //#region src/getConfigVariable.d.ts | ||
| /** | ||
| * get config variable from loaders | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * | ||
| * const port: Promise<string> = await getConfigVariable('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * // with override key | ||
| * const port: Promise<string> = await getConfigVariable('PORT', [env('HTTP_PORT', fileEnv())], stringParser, '8080', {showValue: true}); | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey - root key of config variable | ||
| * @param {IConfigLoader[]} loaders - loaders to use | ||
| * @param {IConfigParser<unknown, Output>} parser - parser to use | ||
| * @param {Loadable<Output>} [defaultValueLoadable] - default value to use | ||
| * @param {FormatParameters} [params] - optional format parameters | ||
| * @param {ConfigOptions} [options] - optional config options | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<Output>} - config variable | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function getConfigVariable<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<Output>; | ||
| declare function getConfigVariable<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<Output | undefined>; | ||
| //#endregion | ||
| //#region src/getConfigVariableResult.d.ts | ||
| /** | ||
| * get config variable from loaders | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const portResult: Result<string> = await getConfigVariableResult('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * | ||
| * const value: string = portResult.unwrap(); // get value or throw error | ||
| * const value: string | undefined = portResult.ok(); // get value or undefined | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey - root key of config variable | ||
| * @param {IConfigLoader[]} loaders - loaders to use | ||
| * @param {IConfigParser<unknown, Output>} parser - parser to use | ||
| * @param {Loadable<Output>} [defaultValueLoadable] - default value to use | ||
| * @param {FormatParameters} [params] - optional format parameters | ||
| * @param {ConfigOptions} [options] - optional config options | ||
| * @returns {Promise<IResult<Output | undefined>>} - result with value or error | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function getConfigVariableResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<Output>>; | ||
| declare function getConfigVariableResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<Output | undefined>>; | ||
| //#endregion | ||
| //#region src/lib/objectUtils.d.ts | ||
| /** | ||
| * validate if a value is a valid object | ||
| * @param {unknown} value - value to validate | ||
| * @returns {value is Record<string, unknown>} - true if value is a valid object | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function isValidObject(value: unknown): value is Record<string, unknown>; | ||
| /** | ||
| * Convert an object to a string value object | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Record<string, string | undefined>} - object with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildStringObject(obj: Record<string, unknown>): Record<string, string>; | ||
| /** | ||
| * Convert an object to a Map<string, string> | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Map<string, string>} - Map with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildStringMap(obj: Record<string, unknown>): Map<string, string>; | ||
| /** | ||
| * Apply a Record<string, string> to a Map<string, string> | ||
| * @param {Record<string, string | undefined>} obj - object to apply | ||
| * @param {Map<string, string>} target - Map to apply to | ||
| * @returns {Map<string, string>} - target with updates | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function applyStringMap(obj: Record<string, string | undefined>, target: Map<string, string>): Map<string, string>; | ||
| //#endregion | ||
| //#region src/lib/seenUtils.d.ts | ||
| /** | ||
| * Function to check if we have seen a value before and update the seenMap | ||
| * @param {Map<string, string>} seenMap - Map of seen values | ||
| * @param {string} key - key to check | ||
| * @param {string | undefined} value - value to check | ||
| * @returns {boolean} - true if already seen value, false if not | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function handleSeen(seenMap: Map<string, string>, key: string, value: string | undefined): boolean; | ||
| //#endregion | ||
| //#region src/lib/semicolonUtils.d.ts | ||
| /** | ||
| * Parse a semicolon separated string into a config object | ||
| * @param {string} config Semicolon separated string | ||
| * @param {boolean} [keepCase] Keep the case of the keys, default true | ||
| * @returns {Record<string, string>} Config object | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * parseSemicolonConfig('a=b;c=d') // {a: 'b', c: 'd'} | ||
| */ | ||
| declare function parseSemicolonConfig(config: string, keepCase?: boolean): Record<string, string>; | ||
| /** | ||
| * Stringify a config object to a semicolon separated string | ||
| * @param {Record<string, string>} config Object to stringify | ||
| * @param {boolean} [uriEncode] Use URI encoding for string outputs | ||
| * @returns {string} Stringified config | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * stringifySemicolonConfig({a: 'b', c: 'd'}) // 'a=b;c=d' | ||
| */ | ||
| declare function stringifySemicolonConfig(config: Record<string, unknown>, uriEncode?: boolean): string; | ||
| /** | ||
| * Stringify a config object to a semicolon separated string for logging | ||
| * @template Out - Type of output | ||
| * @param {Record<string, string>} config Object to stringify | ||
| * @param {ShowValueType} showProtectedKeys How to show protected keys | ||
| * @param {string[]} protectedKeys list of protected keys | ||
| * @returns {string} Stringified config | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * logStringifySemicolonConfig({a: 'b', c: 'd'}) // 'a=b;c=d' | ||
| */ | ||
| declare function logStringifySemicolonConfig<Out extends Record<string, unknown>>(config: Out, showProtectedKeys: ShowValueType | undefined, protectedKeys: Set<keyof Out>): string; | ||
| //#endregion | ||
| //#region src/loaders/ConfigLoader.d.ts | ||
| /** | ||
| * ConfigLoaderEventMap is the event map for the ConfigLoader | ||
| * @category Loaders | ||
| * @since v0.11.1 | ||
| */ | ||
| * ConfigLoaderEventMap is the event map for the ConfigLoader | ||
| * @category Loaders | ||
| * @since v0.11.1 | ||
| */ | ||
| type ConfigLoaderEventMap = { | ||
@@ -551,9 +777,14 @@ /** notify when loader data is updated */updated: []; | ||
| /** | ||
| * IConfigLoaderProps is the interface for ConfigLoader props | ||
| * @category Loaders | ||
| * @since v0.8.0 | ||
| */ | ||
| * IConfigLoaderProps is the interface for ConfigLoader props | ||
| * @category Loaders | ||
| * @since v0.8.0 | ||
| */ | ||
| interface IConfigLoaderProps { | ||
| disabled?: Loadable<boolean>; | ||
| } | ||
| /** | ||
| * LoaderValueResult is the result of a loader value lookup | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| type LoaderValue = { | ||
@@ -564,9 +795,9 @@ value: string | undefined; | ||
| /** | ||
| * Abstract base class for config loaders | ||
| * @template Props - the type of the props | ||
| * @template OverrideMap - the type of the override key map | ||
| * @category Loaders | ||
| * @abstract | ||
| * @since v1.0.0 | ||
| */ | ||
| * Abstract base class for config loaders | ||
| * @template Props - the type of the props | ||
| * @template OverrideMap - the type of the override key map | ||
| * @category Loaders | ||
| * @abstract | ||
| * @since v1.0.0 | ||
| */ | ||
| declare abstract class ConfigLoader<Props extends IConfigLoaderProps, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends EventEmitter<ConfigLoaderEventMap> implements IConfigLoader { | ||
@@ -579,103 +810,75 @@ abstract loaderType: Lowercase<string>; | ||
| constructor(props?: Loadable<Partial<Props>>, overrideKeys?: Partial<OverrideMap>); | ||
| getLoaderResult(lookupKey: string): Promise<{ | ||
| value: string | undefined; | ||
| path: string; | ||
| seen: boolean; | ||
| } | undefined>; | ||
| isLoaderDisabled(): Promise<boolean | undefined>; | ||
| setDisabled(disabled: Loadable<boolean>): Promise<void>; | ||
| getLoaderResult(lookupKey: string): Promise<undefined | LoaderValueResult>; | ||
| isLoaderDisabled(): Promise<boolean>; | ||
| setDisabled(disabled: Loadable<boolean>): void; | ||
| /** | ||
| * Get options from loader and merge with default options | ||
| * @returns {Promise<DefaultProps>} - Promise of DefaultProps & Props | ||
| */ | ||
| * Get options from loader and merge with default options | ||
| * @returns {Promise<DefaultProps>} - Promise of DefaultProps & Props | ||
| */ | ||
| protected getOptions(): Promise<Props>; | ||
| protected setOption<Key extends keyof Props>(key: Key, value: Props[Key]): Promise<void>; | ||
| /** | ||
| * Build error string `ConfigVariables[<type>]: <message>` | ||
| * @param {string} message - error message | ||
| * @returns {string} - error string | ||
| */ | ||
| * Build error string `ConfigVariables[<type>]: <message>` | ||
| * @param {string} message - error message | ||
| * @returns {string} - error string | ||
| */ | ||
| protected buildErrorStr(message: string): string; | ||
| /** | ||
| * implementation of config loader function | ||
| * @param lookupKey - key to lookup in config | ||
| * @param params - optional passing params for handleLoader (i.e. lookup key override, settings etc.) | ||
| * @returns {LoaderValue | Promise<LoaderValue>} - Promise of LoaderValue | ||
| */ | ||
| * implementation of config loader function | ||
| * @param lookupKey - key to lookup in config | ||
| * @returns {LoaderValue | Promise<LoaderValue>} - Promise of LoaderValue | ||
| */ | ||
| protected abstract handleLoaderValue(lookupKey: string): undefined | LoaderValue | Promise<undefined | LoaderValue>; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/RecordConfigLoader.d.ts | ||
| /** | ||
| * RecordConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| */ | ||
| declare abstract class RecordConfigLoader<Props extends IConfigLoaderProps, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<Props, OverrideMap> { | ||
| protected abstract defaultOptions: Props; | ||
| protected _isLoaded: boolean; | ||
| protected dataPromise: Promise<Record<string, string>> | undefined; | ||
| /** | ||
| * reloads the data | ||
| */ | ||
| reload(): Promise<void>; | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} - true if the data is loaded, false otherwise | ||
| */ | ||
| isLoaded(): boolean; | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| protected loadData(): Promise<void>; | ||
| protected abstract handleData(): Promise<Record<string, string>>; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/EnvConfigLoader.d.ts | ||
| /** | ||
| * env loader class is used to load env variables from process.env | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {string} [overrideKey] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| * env loader class is used to load env variables from process.env | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {string} [overrideKey] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class EnvConfigLoader<OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<IConfigLoaderProps, OverrideMap> { | ||
| readonly loaderType = "env"; | ||
| defaultOptions: IConfigLoaderProps; | ||
| protected handleLoaderValue(lookupKey: string): { | ||
| value: string | undefined; | ||
| path: string; | ||
| }; | ||
| protected handleLoaderValue(lookupKey: string): LoaderValue; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/ReactEnvConfigLoader.d.ts | ||
| //#region src/types/RequestNotReady.d.ts | ||
| /** | ||
| * React env loader class is used to load env variables from process.env.REACT_APP_* | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {Partial<OverrideMap>} [override] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class ReactEnvConfigLoader<OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<IConfigLoaderProps, OverrideMap> { | ||
| readonly loaderType = "react-env"; | ||
| defaultOptions: IConfigLoaderProps; | ||
| protected handleLoaderValue(lookupKey: string): { | ||
| value: string | undefined; | ||
| path: string; | ||
| }; | ||
| * RequestNotReady indicates that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| interface RequestNotReady { | ||
| _type: "RequestNotReady"; | ||
| message: string; | ||
| } | ||
| /** | ||
| * Type guard for RequestNotReady | ||
| * @param {unknown} obj - object to check if it is a RequestNotReady payload | ||
| * @returns {boolean} boolean indicating if the object is a RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| declare function isRequestNotReadMessage(obj: unknown): obj is RequestNotReady; | ||
| /** | ||
| * function to create a RequestNotReady payload to indicate that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @param {string} message - reason why the request is not ready yet | ||
| * @returns {RequestNotReady} RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| declare function createRequestNotReady(message: string): RequestNotReady; | ||
| //#endregion | ||
| //#region src/loaders/MapConfigLoader.d.ts | ||
| /** | ||
| * MapConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| * MapConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| declare abstract class MapConfigLoader<Props extends IConfigLoaderProps, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<Props, OverrideMap> { | ||
@@ -686,15 +889,15 @@ protected abstract defaultOptions: Props; | ||
| /** | ||
| * clear maps and reloads the data | ||
| */ | ||
| * clear maps and reloads the data | ||
| */ | ||
| reload(): Promise<void>; | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} Whether the data is loaded | ||
| */ | ||
| * is the data loaded | ||
| * @returns {boolean} Whether the data is loaded | ||
| */ | ||
| isLoaded(): boolean; | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| protected loadData(): Promise<void>; | ||
@@ -706,5 +909,5 @@ protected abstract handleLoadData(): Promise<boolean>; | ||
| /** | ||
| * Options for the FetchConfigLoader | ||
| * @since v1.0.0 | ||
| */ | ||
| * Options for the FetchConfigLoader | ||
| * @since v1.0.0 | ||
| */ | ||
| interface FetchConfigLoaderOptions extends IConfigLoaderProps { | ||
@@ -714,3 +917,3 @@ fetchClient: typeof fetch; | ||
| isSilent: boolean; | ||
| payload: 'json'; | ||
| payload: "json"; | ||
| validate: ValidateCallback<Record<string, string | undefined>, Record<string, string | undefined>> | undefined; | ||
@@ -724,7 +927,7 @@ logger: ILoggerLike | undefined; | ||
| /** | ||
| * FetchConfigLoader is used to load config from a fetch request | ||
| * @template OverrideMap - the type of the override key map | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| * FetchConfigLoader is used to load config from a fetch request | ||
| * @template OverrideMap - the type of the override key map | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class FetchConfigLoader<OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends MapConfigLoader<FetchConfigLoaderOptions, OverrideMap> { | ||
@@ -736,33 +939,30 @@ readonly loaderType: Lowercase<string>; | ||
| /** | ||
| * Constructor for FetchConfigLoader | ||
| * @param {Loadable<ConfigRequest>} request - callback that returns a fetch request or a message object that the request is not ready | ||
| * @param {Loadable<Partial<FetchConfigLoaderOptions>>} options - optional options for FetchConfigLoader | ||
| * @param {Partial<OverrideMap>} overrideKeys - optional override keys for FetchConfigLoader | ||
| * @param {Lowercase<string>} type - optional name type for FetchConfigLoader (default: 'fetch') | ||
| */ | ||
| * Constructor for FetchConfigLoader | ||
| * @param {Loadable<ConfigRequest>} request - callback that returns a fetch request or a message object that the request is not ready | ||
| * @param {Loadable<Partial<FetchConfigLoaderOptions>>} options - optional options for FetchConfigLoader | ||
| * @param {Partial<OverrideMap>} overrideKeys - optional override keys for FetchConfigLoader | ||
| * @param {Lowercase<string>} type - optional name type for FetchConfigLoader (default: 'fetch') | ||
| */ | ||
| constructor(request: Loadable<ConfigRequest>, options?: Loadable<Partial<FetchConfigLoaderOptions>>, overrideKeys?: Partial<OverrideMap>, type?: Lowercase<string>); | ||
| protected handleLoaderValue(lookupKey: string): Promise<{ | ||
| value: string | undefined; | ||
| path: string; | ||
| }>; | ||
| protected handleLoaderValue(lookupKey: string): Promise<undefined | LoaderValue>; | ||
| protected handleLoadData(): Promise<boolean>; | ||
| /** | ||
| * if client is offline, we will try return the cached response else add cache validation (ETag) and try get the response from the fetch request | ||
| * @param {Request} req - request to fetch | ||
| * @returns {Promise<Response | undefined>} - response or undefined | ||
| */ | ||
| * if client is offline, we will try return the cached response else add cache validation (ETag) and try get the response from the fetch request | ||
| * @param {Request} req - request to fetch | ||
| * @returns {Promise<Response | undefined>} - response or undefined | ||
| */ | ||
| private fetchRequestOrCacheResponse; | ||
| /** | ||
| * on error, check if we have a valid cached response | ||
| * @param {Request} req - request to fetch | ||
| * @param {Response} res - response from fetch | ||
| * @returns {Promise<Response>} - response | ||
| */ | ||
| * on error, check if we have a valid cached response | ||
| * @param {Request} req - request to fetch | ||
| * @param {Response} res - response from fetch | ||
| * @returns {Promise<Response>} - response | ||
| */ | ||
| private checkIfValidCacheResponse; | ||
| /** | ||
| * if we get a 304, get the cached response | ||
| * @param {Request} req - request to fetch | ||
| * @param {Response} res - response from fetch | ||
| * @returns {Promise<Response>} - response | ||
| */ | ||
| * if we get a 304, get the cached response | ||
| * @param {Request} req - request to fetch | ||
| * @param {Response} res - response from fetch | ||
| * @returns {Promise<Response>} - response | ||
| */ | ||
| private handleNotModifiedCache; | ||
@@ -774,2 +974,7 @@ private handleJson; | ||
| //#region src/loaders/MemoryConfigLoader.d.ts | ||
| /** | ||
| * IMemoryConfigLoaderProps is the interface for MemoryConfigLoader props | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| interface IMemoryConfigLoaderProps extends IConfigLoaderProps { | ||
@@ -779,9 +984,9 @@ logger: ILoggerLike | undefined; | ||
| /** | ||
| * Config loader with in-memory data which can be set and retrieved variables on the fly. | ||
| * - Useful for temporary controlled overrides or testing | ||
| * @template MemoryMap - the type of the memory map | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| * Config loader with in-memory data which can be set and retrieved variables on the fly. | ||
| * - Useful for temporary controlled overrides or testing | ||
| * @template MemoryMap - the type of the memory map | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| declare class MemoryConfigLoader<MemoryMap extends Record<string, string | undefined>, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<IMemoryConfigLoaderProps, OverrideMap> { | ||
@@ -794,9 +999,55 @@ readonly loaderType: Lowercase<string>; | ||
| get(key: keyof MemoryMap): Promise<string | undefined>; | ||
| protected handleLoaderValue(lookupKey: string): { | ||
| value: string | undefined; | ||
| path: string; | ||
| }; | ||
| protected handleLoaderValue(lookupKey: string): LoaderValue; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/ReactEnvConfigLoader.d.ts | ||
| /** | ||
| * React env loader class is used to load env variables from process.env.REACT_APP_* | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {Partial<OverrideMap>} [override] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class ReactEnvConfigLoader<OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<IConfigLoaderProps, OverrideMap> { | ||
| readonly loaderType = "react-env"; | ||
| defaultOptions: IConfigLoaderProps; | ||
| protected handleLoaderValue(lookupKey: string): LoaderValue; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/RecordConfigLoader.d.ts | ||
| /** | ||
| * RecordConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| */ | ||
| declare abstract class RecordConfigLoader<Props extends IConfigLoaderProps, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<Props, OverrideMap> { | ||
| protected abstract defaultOptions: Props; | ||
| protected _isLoaded: boolean; | ||
| protected dataPromise: Promise<Record<string, string>> | undefined; | ||
| /** | ||
| * reloads the data | ||
| */ | ||
| reload(): Promise<void>; | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} - true if the data is loaded, false otherwise | ||
| */ | ||
| isLoaded(): boolean; | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| protected loadData(): Promise<void>; | ||
| protected abstract handleData(): Promise<Record<string, string>>; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/SwitchLoader.d.ts | ||
| /** | ||
| * ISwitchLoaderProps is the interface for SwitchLoader props | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| interface ISwitchLoaderProps extends IConfigLoaderProps { | ||
@@ -806,29 +1057,29 @@ logger?: ILoggerLike; | ||
| /** | ||
| * ConfigMap, this is a helper type to define the configuration map for the switch loader. | ||
| * @template Key - The key to switch between | ||
| * @template Map - The configuration map | ||
| * @since v0.10.1 | ||
| * @example | ||
| * type TestConfigMapEnv = { DEMO: string; ANOTHER: string; }; | ||
| * const switchConfigMap: SwitchConfigMap<TestConfigMapEnv, 'switch1' | 'switch2'> = { | ||
| * switch1: { DEMO: 'value' }, | ||
| * switch2: { DEMO: 'value2' }, | ||
| * }; | ||
| */ | ||
| * ConfigMap, this is a helper type to define the configuration map for the switch loader. | ||
| * @template Key - The key to switch between | ||
| * @template Map - The configuration map | ||
| * @since v0.10.1 | ||
| * @example | ||
| * type TestConfigMapEnv = { DEMO: string; ANOTHER: string; }; | ||
| * const switchConfigMap: SwitchConfigMap<TestConfigMapEnv, 'switch1' | 'switch2'> = { | ||
| * switch1: { DEMO: 'value' }, | ||
| * switch2: { DEMO: 'value2' }, | ||
| * }; | ||
| */ | ||
| type SwitchConfigMap<Map extends Record<string, unknown>, Key extends string> = Record<Key, Partial<Record<keyof Map, string>>>; | ||
| /** | ||
| * SwitchLoader, this loader will switch between different configurations based on the active key. | ||
| * @example | ||
| * type TestConfigMapEnv = { DEMO: string; ANOTHER: string; }; | ||
| * const switchLoader = new SwitchLoader<TestEnv, 'switch1' | 'switch2'>({ | ||
| * switch1: { DEMO: 'value' }, | ||
| * switch2: { DEMO: 'value2' }, | ||
| * }); | ||
| * const switcher = switchLoader.getLoader; // use this on the config map loaders: [switcher(), dotenv(), env(), ...] | ||
| * await switchLoader.activateSwitch('switch1'); // when you want enable switch1 values | ||
| * @template Config - The configuration map | ||
| * @template Key - The key to switch between | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| * SwitchLoader, this loader will switch between different configurations based on the active key. | ||
| * @example | ||
| * type TestConfigMapEnv = { DEMO: string; ANOTHER: string; }; | ||
| * const switchLoader = new SwitchLoader<TestEnv, 'switch1' | 'switch2'>({ | ||
| * switch1: { DEMO: 'value' }, | ||
| * switch2: { DEMO: 'value2' }, | ||
| * }); | ||
| * const switcher = switchLoader.getLoader; // use this on the config map loaders: [switcher(), dotenv(), env(), ...] | ||
| * await switchLoader.activateSwitch('switch1'); // when you want enable switch1 values | ||
| * @template Config - The configuration map | ||
| * @template Key - The key to switch between | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| declare class SwitchLoader<Config extends Record<string, unknown>, Key extends string> extends ConfigLoader<ISwitchLoaderProps> { | ||
@@ -847,3 +1098,99 @@ readonly loaderType: Lowercase<string>; | ||
| //#endregion | ||
| //#region src/logger.d.ts | ||
| /** | ||
| * Set the logger to be used by the module | ||
| * @category Utils | ||
| * @param {ILoggerLike} newLogger - logger to be used | ||
| * @since v0.2.18 | ||
| */ | ||
| declare function setLogger(newLogger: ILoggerLike): void; | ||
| /** | ||
| * Get current logger instance | ||
| * @category Utils | ||
| * @returns {ILoggerLike | undefined} - current logger | ||
| * @since v0.5.9 | ||
| */ | ||
| declare function getLogger(): ILoggerLike | undefined; | ||
| /** | ||
| * resolve logger: undefined = global logger, null = no logger else it's ILoggerLike | ||
| * @param {ILoggerLike | undefined | null} logger - logger to resolve | ||
| * @category Utils | ||
| * @returns {ILoggerLike | undefined} - resolved logger | ||
| * @since v0.5.9 | ||
| */ | ||
| declare function resolveLogger(logger: undefined | null | ILoggerLike): ILoggerLike | undefined; | ||
| //#endregion | ||
| //#region src/parsers/arrayParser.d.ts | ||
| /** | ||
| * Build parser for array of values | ||
| * @template Input - Type of input | ||
| * @template Output - Type of output | ||
| * @param {IConfigParser<Input, Output>} parse parser for the array values | ||
| * @param {string} separator separator for the array values, defaults to ';' | ||
| * @param {TypeGuardValidate<Output> | undefined} validate optional post validation | ||
| * @returns {IConfigParser<Output[], Input[]>} Parser for array of values | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function arrayParser<Input, Output>(parse: IConfigParser<Input, Output>, separator?: string, validate?: TypeGuardValidate<Output>): IConfigParser<Input[], Output[]>; | ||
| //#endregion | ||
| //#region src/parsers/bigIntParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to bigint | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<bigint, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function bigIntParser<Output extends bigint = bigint>(validate?: TypeGuardValidate<Output>): IConfigParser<bigint, Output>; | ||
| //#endregion | ||
| //#region src/parsers/booleanParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * | ||
| * supports the following string ___true___ values: | ||
| * | ||
| * ```['true', '1', 'yes', 'y', 'on']``` | ||
| * | ||
| * supports the following string ___false___ values: | ||
| * | ||
| * ```['false', '0', 'no', 'n', 'off']``` | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<boolean, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function booleanParser<Output extends boolean = boolean>(validate?: TypeGuardValidate<Output>): IConfigParser<boolean, Output>; | ||
| //#endregion | ||
| //#region src/parsers/floatParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<number, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function floatParser<Output extends number = number>(validate?: TypeGuardValidate<Output>): IConfigParser<number, Output>; | ||
| //#endregion | ||
| //#region src/parsers/integerParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<number, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function integerParser<Output extends number = number>(validate?: TypeGuardValidate<Output>): IConfigParser<number, Output>; | ||
| //#endregion | ||
| //#region src/parsers/JsonConfigParser.d.ts | ||
| /** | ||
| * JsonConfigParserOptions is the interface for JsonConfigParser options | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| * @template Out - the type of the output object | ||
| */ | ||
| type JsonConfigParserOptions<Out extends Record<string, unknown>> = { | ||
@@ -855,20 +1202,20 @@ validate?: ValidateCallback<object, Out>; /** keys to hide or partially hide */ | ||
| /** | ||
| * Config parser to parse JSON string as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new JsonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, object>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| * Config parser to parse JSON string as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new JsonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, object>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class JsonConfigParser<Out extends Record<string, unknown>> implements IConfigParser<object, Out> { | ||
@@ -893,141 +1240,16 @@ name: string; | ||
| /** | ||
| * Build a string record from the given data | ||
| * @param {unknown} data - to be validated as object | ||
| * @returns {object} A record with string values | ||
| */ | ||
| * Build a string record from the given data | ||
| * @param {unknown} data - to be validated as object | ||
| * @returns {object} A record with string values | ||
| */ | ||
| private buildBaseRecord; | ||
| } | ||
| //#endregion | ||
| //#region src/parsers/UrlParser.d.ts | ||
| //#region src/parsers/SemicolonConfigParser.d.ts | ||
| /** | ||
| * Properties for the UrlParser | ||
| * @since v0.2.5 | ||
| */ | ||
| interface UrlParserProps { | ||
| urlSanitize?: boolean; | ||
| } | ||
| /** | ||
| * UrlParser class is used to parse and validate env variables of type URL. | ||
| * @class UrlParser | ||
| * @implements {IConfigParser<URL, URL>} | ||
| * @category Parsers | ||
| * @since v0.2.5 | ||
| */ | ||
| declare class UrlParser implements IConfigParser<URL, URL> { | ||
| name: string; | ||
| /** | ||
| * Should the username and password be sanitized | ||
| */ | ||
| private urlSanitize; | ||
| /** | ||
| * Create a new UrlParser | ||
| * @param {UrlParserProps} properties - Properties for the UrlParser | ||
| */ | ||
| constructor({ | ||
| urlSanitize | ||
| }?: UrlParserProps); | ||
| parse({ | ||
| value | ||
| }: ParserProps): URL; | ||
| toString(value: URL): string; | ||
| toLogString(value: URL): string; | ||
| /** | ||
| * Build a URL object from a string and sanitize the username and password | ||
| * @param {string} value string to parse | ||
| * @returns {URL} URL object with sanitized username and password | ||
| */ | ||
| private handleUrlSanitize; | ||
| } | ||
| //#endregion | ||
| //#region src/parsers/stringParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to string | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<string, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function stringParser<Output extends string = string>(validate?: TypeGuardValidate<Output>): IConfigParser<string, Output>; | ||
| //#endregion | ||
| //#region src/lib/semicolonUtils.d.ts | ||
| /** | ||
| * Parse a semicolon separated string into a config object | ||
| * @param {string} config Semicolon separated string | ||
| * @param {boolean} [keepCase] Keep the case of the keys, default true | ||
| * @returns {Record<string, string>} Config object | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * parseSemicolonConfig('a=b;c=d') // {a: 'b', c: 'd'} | ||
| */ | ||
| declare function parseSemicolonConfig(config: string, keepCase?: boolean): Record<string, string>; | ||
| /** | ||
| * Stringify a config object to a semicolon separated string | ||
| * @param {Record<string, string>} config Object to stringify | ||
| * @param {boolean} [uriEncode] Use URI encoding for string outputs | ||
| * @returns {string} Stringified config | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * stringifySemicolonConfig({a: 'b', c: 'd'}) // 'a=b;c=d' | ||
| */ | ||
| declare function stringifySemicolonConfig(config: Record<string, unknown>, uriEncode?: boolean): string; | ||
| /** | ||
| * Stringify a config object to a semicolon separated string for logging | ||
| * @template Out - Type of output | ||
| * @param {Record<string, string>} config Object to stringify | ||
| * @param {ShowValueType} showProtectedKeys How to show protected keys | ||
| * @param {string[]} protectedKeys list of protected keys | ||
| * @returns {string} Stringified config | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * logStringifySemicolonConfig({a: 'b', c: 'd'}) // 'a=b;c=d' | ||
| */ | ||
| declare function logStringifySemicolonConfig<Out extends Record<string, unknown>>(config: Out, showProtectedKeys: ShowValueType | undefined, protectedKeys: Set<keyof Out>): string; | ||
| //#endregion | ||
| //#region src/lib/objectUtils.d.ts | ||
| /** | ||
| * validate if a value is a valid object | ||
| * @param {unknown} value - value to validate | ||
| * @returns {value is Record<string, unknown>} - true if value is a valid object | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function isValidObject(value: unknown): value is Record<string, unknown>; | ||
| /** | ||
| * Convert an object to a string value object | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Record<string, string | undefined>} - object with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildStringObject(obj: Record<string, unknown>): Record<string, string>; | ||
| /** | ||
| * Convert an object to a Map<string, string> | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Map<string, string>} - Map with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildStringMap(obj: Record<string, unknown>): Map<string, string>; | ||
| /** | ||
| * Apply a Record<string, string> to a Map<string, string> | ||
| * @param {Record<string, string | undefined>} obj - object to apply | ||
| * @param {Map<string, string>} target - Map to apply to | ||
| * @returns {Map<string, string>} - target with updates | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function applyStringMap(obj: Record<string, string | undefined>, target: Map<string, string>): Map<string, string>; | ||
| //#endregion | ||
| //#region src/lib/seenUtils.d.ts | ||
| /** | ||
| * Function to check if we have seen a value before and update the seenMap | ||
| * @param {Map<string, string>} seenMap - Map of seen values | ||
| * @param {string} key - key to check | ||
| * @param {string | undefined} value - value to check | ||
| * @returns {boolean} - true if already seen value, false if not | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function handleSeen(seenMap: Map<string, string>, key: string, value: string | undefined): boolean; | ||
| //#endregion | ||
| //#region src/parsers/SemicolonConfigParser.d.ts | ||
| * SemicolonConfigParserOptions is the interface for SemicolonConfigParser options | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| * @template OutType - the type of the output object | ||
| */ | ||
| interface SemicolonConfigParserOptions<OutType extends Record<string, unknown> = Record<string, unknown>> { | ||
@@ -1043,20 +1265,20 @@ validate?: ValidateCallback<Record<string, string>, OutType>; | ||
| /** | ||
| * Config parser to parse semicolon separated string key=value pairs as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses 'foo=bar;baz=qux;secret=secret' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new SemicolonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, Record<string, string>>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| * Config parser to parse semicolon separated string key=value pairs as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses 'foo=bar;baz=qux;secret=secret' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new SemicolonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, Record<string, string>>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class SemicolonConfigParser<Out extends Record<string, unknown> = Record<string, unknown>> implements IConfigParser<Record<string, string>, Out> { | ||
@@ -1084,85 +1306,71 @@ name: string; | ||
| //#endregion | ||
| //#region src/parsers/booleanParser.d.ts | ||
| //#region src/parsers/stringParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * | ||
| * supports the following string ___true___ values: | ||
| * | ||
| * ```['true', '1', 'yes', 'y', 'on']``` | ||
| * | ||
| * supports the following string ___false___ values: | ||
| * | ||
| * ```['false', '0', 'no', 'n', 'off']``` | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<boolean, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function booleanParser<Output extends boolean = boolean>(validate?: TypeGuardValidate<Output>): IConfigParser<boolean, Output>; | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to string | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<string, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function stringParser<Output extends string = string>(validate?: TypeGuardValidate<Output>): IConfigParser<string, Output>; | ||
| //#endregion | ||
| //#region src/parsers/floatParser.d.ts | ||
| //#region src/parsers/UrlParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<number, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function floatParser<Output extends number = number>(validate?: TypeGuardValidate<Output>): IConfigParser<number, Output>; | ||
| //#endregion | ||
| //#region src/parsers/integerParser.d.ts | ||
| * Properties for the UrlParser | ||
| * @since v0.2.5 | ||
| */ | ||
| interface UrlParserProps { | ||
| urlSanitize?: boolean; | ||
| } | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<number, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function integerParser<Output extends number = number>(validate?: TypeGuardValidate<Output>): IConfigParser<number, Output>; | ||
| * UrlParser class is used to parse and validate env variables of type URL. | ||
| * @class UrlParser | ||
| * @implements {IConfigParser<URL, URL>} | ||
| * @category Parsers | ||
| * @since v0.2.5 | ||
| */ | ||
| declare class UrlParser implements IConfigParser<URL, URL> { | ||
| name: string; | ||
| /** | ||
| * Should the username and password be sanitized | ||
| */ | ||
| private urlSanitize; | ||
| /** | ||
| * Create a new UrlParser | ||
| * @param {UrlParserProps} properties - Properties for the UrlParser | ||
| */ | ||
| constructor({ | ||
| urlSanitize | ||
| }?: UrlParserProps); | ||
| parse({ | ||
| value | ||
| }: ParserProps): URL; | ||
| toString(value: URL): string; | ||
| toLogString(value: URL): string; | ||
| /** | ||
| * Build a URL object from a string and sanitize the username and password | ||
| * @param {string} value string to parse | ||
| * @returns {URL} URL object with sanitized username and password | ||
| */ | ||
| private handleUrlSanitize; | ||
| } | ||
| //#endregion | ||
| //#region src/parsers/arrayParser.d.ts | ||
| /** | ||
| * Build parser for array of values | ||
| * @template Input - Type of input | ||
| * @template Output - Type of output | ||
| * @param {IConfigParser<Input, Output>} parse parser for the array values | ||
| * @param {string} separator separator for the array values, defaults to ';' | ||
| * @param {TypeGuardValidate<Output> | undefined} validate optional post validation | ||
| * @returns {IConfigParser<Output[], Input[]>} Parser for array of values | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function arrayParser<Input, Output>(parse: IConfigParser<Input, Output>, separator?: string, validate?: TypeGuardValidate<Output>): IConfigParser<Input[], Output[]>; | ||
| //#endregion | ||
| //#region src/parsers/bigIntParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to bigint | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<bigint, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function bigIntParser<Output extends bigint = bigint>(validate?: TypeGuardValidate<Output>): IConfigParser<bigint, Output>; | ||
| //#endregion | ||
| //#region src/VariableError.d.ts | ||
| /** | ||
| * Custom error class for variable errors. | ||
| * @class VariableError | ||
| * @augments Error | ||
| * @param {string} message - The error message. | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| * @example | ||
| * throw new VariableError('Variable not found'); | ||
| */ | ||
| * Custom error class for variable errors. | ||
| * @class VariableError | ||
| * @augments Error | ||
| * @param {string} message - The error message. | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| * @example | ||
| * throw new VariableError('Variable not found'); | ||
| */ | ||
| declare class VariableError extends Error { | ||
| /** | ||
| * Create a new VariableError | ||
| * @param {string} message - The error message | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| * Create a new VariableError | ||
| * @param {string} message - The error message | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| constructor(message: string, options?: ErrorOptions); | ||
@@ -1173,189 +1381,20 @@ } | ||
| /** | ||
| * Custom error class for variable lookup errors. | ||
| * @class VariableLookupError | ||
| * @augments VariableError | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| */ | ||
| * Custom error class for variable lookup errors. | ||
| * @class VariableLookupError | ||
| * @augments VariableError | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| */ | ||
| declare class VariableLookupError extends VariableError { | ||
| readonly variableKey: string; | ||
| /** | ||
| * Create a new VariableLookupError | ||
| * @param {string} variableKey - The variable key. | ||
| * @param {string} message - The error message. | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| * Create a new VariableLookupError | ||
| * @param {string} variableKey - The variable key. | ||
| * @param {string} message - The error message. | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| constructor(variableKey: string, message: string, options?: ErrorOptions); | ||
| } | ||
| //#endregion | ||
| //#region src/ConfigMap.d.ts | ||
| /** | ||
| * TypeValueRecords | ||
| * @template T - type of config map | ||
| * @since v0.6.0 | ||
| */ | ||
| type TypeValueRecords<T> = Record<keyof T, LoaderTypeValueStrict<T[keyof T]>>; | ||
| /** | ||
| * ConfigMap | ||
| * @example | ||
| * type ConfigEnv = { | ||
| * PORT: number; | ||
| * HOST: string; | ||
| * DEBUG: boolean; | ||
| * URL: URL; | ||
| * }; | ||
| * const config = new ConfigMap<ConfigEnv>({ | ||
| * DEBUG: {loaders: [env()], parser: booleanParser, defaultValue: false}, | ||
| * HOST: {loaders: [env()], parser: stringParser, defaultValue: 'localhost'}, | ||
| * PORT: {loaders: [env()], parser: integerParser, defaultValue: 3000}, | ||
| * URL: {loaders: [env()], parser: new UrlParser({urlSanitize: true}), defaultValue: new URL('http://localhost:3000')}, | ||
| * }); | ||
| * console.log('port', await config.get('PORT')); | ||
| * @template Data - type of config map | ||
| * @since v1.1.0 | ||
| */ | ||
| declare class ConfigMap<Data extends Record<string, unknown>> implements ISetOptionalLogger { | ||
| private schema; | ||
| private options; | ||
| private loaders; | ||
| /** | ||
| * ConfigMap constructor | ||
| * @param {EnvMapSchema<Data>} schema - schema of config map | ||
| * @param {Iterable<IConfigLoader>} loaders - iterable of config loaders | ||
| * @param {ConfigOptions} options - optional config options (logger, namespace) | ||
| */ | ||
| constructor(schema: EnvMapSchema<Data>, loaders: Loadable<Iterable<IConfigLoader>>, options?: ConfigOptions); | ||
| /** | ||
| * Set logger value | ||
| * @param {ILoggerLike | undefined} logger - logger like object | ||
| */ | ||
| setLogger(logger: ILoggerLike | undefined): void; | ||
| /** | ||
| * get env object from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: LoaderTypeValue<number> = await config.getObject('PORT'); | ||
| * console.log(valueObject.type, valueObject.value); // 'env', 3000 | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getObject<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<LoaderTypeValueStrict<Data[Key]>>; | ||
| /** | ||
| * get env object from config map as Result | ||
| * @returns {Promise<Result<TypeValueRecords<Data>>>} Result Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: Result<LoaderTypeValue<number>> = await config.getObjectResult('PORT'); | ||
| * if (valueObject.isOk()) { | ||
| * const {type, value} = valueObject.ok(); | ||
| * console.log(type, value); // 'env', 3000 | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getObjectResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<LoaderTypeValueStrict<Data[Key]>>>; | ||
| /** | ||
| * get env value from config map | ||
| * @returns {Promise<Data[Key]>} Promise of value or undefined | ||
| * @example | ||
| * const port: number = await config.get('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| get<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<Data[Key]>; | ||
| /** | ||
| * get env value as string from config map | ||
| * @returns {Promise<string | undefined>} Promise of string value or undefined | ||
| * @example | ||
| * const port: string = await config.getString('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getString<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<undefined extends Data[Key] ? string | undefined : string>; | ||
| /** | ||
| * get env value from config map as Result | ||
| * @returns {Promise<Result<Data[Key]>>} Result Promise of value or undefined | ||
| * @example | ||
| * const port: Result<number> = await config.getResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<Data[Key]>>; | ||
| /** | ||
| * get env value as string from config map as Result | ||
| * @returns {Promise<Result<string | undefined>>} Result Promise of string value or undefined | ||
| * @example | ||
| * const port: Result<string> = await config.getStringResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getStringResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<undefined extends Data[Key] ? string | undefined : string>>; | ||
| /** | ||
| * get all env value objects from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of all values | ||
| * @example | ||
| * const values: TypeValueRecords<Data> = await config.getAll(); | ||
| * console.log(values.PORT.type, values.PORT.value); // 'env', 3000 | ||
| */ | ||
| getAllObjects(): Promise<TypeValueRecords<Data>>; | ||
| /** | ||
| * get all env values from config map | ||
| * @returns {Promise<Data>} Promise of all values | ||
| * @example | ||
| * const values: Data = await config.getAllValues(); | ||
| * console.log('PORT', values.PORT); // 3000 (number) | ||
| */ | ||
| getAllValues(): Promise<Data>; | ||
| /** | ||
| * get all env values from config map as string | ||
| * @returns {Promise<Record<keyof Data, string>>} Promise of all values as string | ||
| * @example | ||
| * const values: Record<keyof Data, string> = await config.getAllStringValues(); | ||
| * console.log('PORT', values.PORT); // '3000' (string) | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getAllStringValues(encodeOptions?: EncodeOptions): Promise<Record<keyof Data, string>>; | ||
| /** | ||
| * Validate all env values from config map, expect to throw error if error exists | ||
| * @param {(data: Data) => void} callback callback function | ||
| */ | ||
| validateAll(callback: (data: Data) => void): Promise<void>; | ||
| /** | ||
| * run lookup to all keys and return all promises | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<[keyof Data, LoaderTypeValueStrict<Data[keyof Data]>][]>} Promise of all values | ||
| */ | ||
| private getAllPromises; | ||
| } | ||
| //#endregion | ||
| //#region src/logger.d.ts | ||
| /** | ||
| * Set the logger to be used by the module | ||
| * @category Utils | ||
| * @param {ILoggerLike} newLogger - logger to be used | ||
| * @since v0.2.18 | ||
| */ | ||
| declare function setLogger(newLogger: ILoggerLike): void; | ||
| /** | ||
| * Get current logger instance | ||
| * @category Utils | ||
| * @returns {ILoggerLike | undefined} - current logger | ||
| * @since v0.5.9 | ||
| */ | ||
| declare function getLogger(): ILoggerLike | undefined; | ||
| /** | ||
| * resolve logger: undefined = global logger, null = no logger else it's ILoggerLike | ||
| * @param {ILoggerLike | undefined | null} logger - logger to resolve | ||
| * @category Utils | ||
| * @returns {ILoggerLike | undefined} - resolved logger | ||
| * @since v0.5.9 | ||
| */ | ||
| declare function resolveLogger(logger: undefined | null | ILoggerLike): ILoggerLike | undefined; | ||
| //#endregion | ||
| export { ConfigLoader, ConfigLoaderEventMap, ConfigMap, ConfigOptions, ConfigRequest, EncodeOptions, EnvConfigLoader, EnvMapSchema, FetchConfigLoader, FetchConfigLoaderOptions, FormatParameters, IConfigLoader, IConfigLoaderProps, IConfigParser, IMemoryConfigLoaderProps, IRequestCache, ISwitchLoaderProps, InferOverrideKeyMap, JsonConfigParser, JsonConfigParserOptions, LoaderTypeValue, LoaderTypeValueStrict, LoaderValue, LoaderValueResult, MapConfigLoader, MemoryConfigLoader, OptionalEnvEntry, OverrideKeyMap, ParserProps, PartialHiddenValueStringType, PostValidateProps, PreValidateProps, ReactEnvConfigLoader, RecordConfigLoader, RequestNotReady, RequiredEnvEntry, RequiredUndefinedThrowEntry, SemicolonConfigParser, SemicolonConfigParserOptions, ShowValueType, SolvedConfigOptions, SwitchConfigMap, SwitchLoader, TypeGuardValidate, TypeValueRecords, UrlParser, UrlParserProps, ValidateCallback, VariableError, VariableLookupError, applyStringMap, arrayParser, bigIntParser, booleanParser, buildHiddenAsterisksValueString, buildHiddenValue, buildOptions, buildPartialHiddenValueString, buildStringMap, buildStringObject, clearDefaultValueSeenMap, createRequestNotReady, floatParser, getConfigObject, getConfigObjectResult, getConfigVariable, getConfigVariableResult, getLogger, handleSeen, integerParser, isRequestNotReadMessage, isValidObject, logStringifySemicolonConfig, parseSemicolonConfig, printValue, resolveLogger, setLogger, stringParser, stringifySemicolonConfig, urlSanitize$1 as urlSanitize }; | ||
| //# sourceMappingURL=index.d.cts.map |
+985
-946
@@ -0,15 +1,46 @@ | ||
| import { IResult } from "@luolapeikko/result-option"; | ||
| import { Loadable } from "@luolapeikko/ts-common"; | ||
| import { IResult } from "@luolapeikko/result-option"; | ||
| import { EventEmitter } from "events"; | ||
| import { ILoggerLike, ISetOptionalLogger } from "@avanio/logger-like"; | ||
| //#region src/ConfigOptions.d.ts | ||
| /** | ||
| * ConfigOptions | ||
| * @category Config | ||
| * @since v0.6.0 | ||
| */ | ||
| type ConfigOptions = { | ||
| /** undefined = global logger, null = no logger else it's ILoggerLike */logger?: ILoggerLike | null; /** optional namespace added to logs */ | ||
| namespace?: string; | ||
| }; | ||
| /** | ||
| * SolvedConfigOptions | ||
| * @category Config | ||
| * @since v0.6.0 | ||
| */ | ||
| type SolvedConfigOptions = { | ||
| /** optional logger instance */logger: ILoggerLike | undefined; /** optional namespace added to logs */ | ||
| namespace: string | undefined; | ||
| }; | ||
| /** | ||
| * Build options from partial options | ||
| * @param {Partial<ConfigOptions>} options - partial config options | ||
| * @returns {SolvedConfigOptions} - solved config options | ||
| * @category Config | ||
| * @since v0.6.0 | ||
| */ | ||
| declare function buildOptions({ | ||
| logger, | ||
| namespace | ||
| }?: Partial<ConfigOptions>): SolvedConfigOptions; | ||
| //#endregion | ||
| //#region src/interfaces/IConfigLoader.d.ts | ||
| /** | ||
| * Represents the result of loading a configuration value. | ||
| * @property value - The value associated with the configuration key, or `undefined` if not found. | ||
| * @property path - The source path from which the value was loaded. | ||
| * @property seen - Indicates whether the key and value have already been encountered (used for logging purposes). | ||
| * @since v0.8.0 | ||
| * @category Loaders | ||
| */ | ||
| * Represents the result of loading a configuration value. | ||
| * @property value - The value associated with the configuration key, or `undefined` if not found. | ||
| * @property path - The source path from which the value was loaded. | ||
| * @property seen - Indicates whether the key and value have already been encountered (used for logging purposes). | ||
| * @since v0.8.0 | ||
| * @category Loaders | ||
| */ | ||
| type LoaderValueResult = { | ||
@@ -21,6 +52,6 @@ /** this is shown on logs `ConfigVariables[type]: KEY [___VALUE___] from {path}` if showValue is true */value: string | undefined; /** this is shown on logs `ConfigVariables[type]: KEY [VALUE] from {___path___}` */ | ||
| /** | ||
| * Interface for config loaders | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| * Interface for config loaders | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| interface IConfigLoader { | ||
@@ -30,33 +61,33 @@ /** this is shown on logs `ConfigVariables[___type___]: KEY [VALUE] from {path}` */ | ||
| /** | ||
| * get loader result for lookupKey | ||
| * @param {string} lookupKey - key to lookup | ||
| * @returns {undefined | LoaderValueResult | Promise<undefined | LoaderValueResult>} - Promise of LoaderValueResult or undefined | ||
| */ | ||
| * get loader result for lookupKey | ||
| * @param {string} lookupKey - key to lookup | ||
| * @returns {undefined | LoaderValueResult | Promise<undefined | LoaderValueResult>} - Promise of LoaderValueResult or undefined | ||
| */ | ||
| getLoaderResult(lookupKey: string): undefined | LoaderValueResult | Promise<undefined | LoaderValueResult>; | ||
| /** | ||
| * Check if loader is disabled | ||
| * @returns {boolean | undefined | Promise<boolean | undefined>} - Promise of boolean or undefined | ||
| */ | ||
| * Check if loader is disabled | ||
| * @returns {boolean | undefined | Promise<boolean | undefined>} - Promise of boolean or undefined | ||
| */ | ||
| isLoaderDisabled(): boolean | undefined | Promise<boolean | undefined>; | ||
| } | ||
| /** | ||
| * Helper type to write override keys to config loaders | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| * @example | ||
| * type OverrideKeyMap = InferOverrideKeyMap<MainEnv & TestEnv>; | ||
| * // Example usage of OverrideKeyMap, where the keys are the original config keys and the values are the override keys | ||
| * const env = new EnvConfigLoader<OverrideKeyMap>(undefined, {PORT: 'HTTP_PORT'}); // get PORT value from process.env.HTTP_PORT | ||
| */ | ||
| * Helper type to write override keys to config loaders | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| * @example | ||
| * type OverrideKeyMap = InferOverrideKeyMap<MainEnv & TestEnv>; | ||
| * // Example usage of OverrideKeyMap, where the keys are the original config keys and the values are the override keys | ||
| * const env = new EnvConfigLoader<OverrideKeyMap>(undefined, {PORT: 'HTTP_PORT'}); // get PORT value from process.env.HTTP_PORT | ||
| */ | ||
| type OverrideKeyMap = Record<string, string>; | ||
| /** | ||
| * Helper infer type to write override keys to config loaders | ||
| * @template T - The type of the config object. | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| * @example | ||
| * type OverrideKeyMap = InferOverrideKeyMap<MainEnv & TestEnv>; | ||
| * // Example usage of OverrideKeyMap, where the keys are the original config keys and the values are the override keys | ||
| * const env = new EnvConfigLoader<OverrideKeyMap>(undefined, {PORT: 'HTTP_PORT'}); // get PORT value from process.env.HTTP_PORT | ||
| */ | ||
| * Helper infer type to write override keys to config loaders | ||
| * @template T - The type of the config object. | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| * @example | ||
| * type OverrideKeyMap = InferOverrideKeyMap<MainEnv & TestEnv>; | ||
| * // Example usage of OverrideKeyMap, where the keys are the original config keys and the values are the override keys | ||
| * const env = new EnvConfigLoader<OverrideKeyMap>(undefined, {PORT: 'HTTP_PORT'}); // get PORT value from process.env.HTTP_PORT | ||
| */ | ||
| type InferOverrideKeyMap<T> = Record<keyof T, string>; | ||
@@ -66,5 +97,5 @@ //#endregion | ||
| /** | ||
| * Parser method props | ||
| * @since v0.11.0 | ||
| */ | ||
| * Parser method props | ||
| * @since v0.11.0 | ||
| */ | ||
| type ParserProps = { | ||
@@ -76,5 +107,5 @@ loader: IConfigLoader; | ||
| /** | ||
| * PreValidate method props | ||
| * @since v0.11.0 | ||
| */ | ||
| * PreValidate method props | ||
| * @since v0.11.0 | ||
| */ | ||
| type PreValidateProps = { | ||
@@ -86,6 +117,6 @@ loader: IConfigLoader; | ||
| /** | ||
| * PostValidate method props | ||
| * @template T - Type of value | ||
| * @since v0.11.0 | ||
| */ | ||
| * PostValidate method props | ||
| * @template T - Type of value | ||
| * @since v0.11.0 | ||
| */ | ||
| type PostValidateProps<T> = { | ||
@@ -97,198 +128,186 @@ loader: IConfigLoader; | ||
| /** | ||
| * PreValidate function | ||
| * @template Output - Type of output value | ||
| * @since v1.0.0 | ||
| */ | ||
| * PreValidate function | ||
| * @template Output - Type of output value | ||
| * @since v1.0.0 | ||
| */ | ||
| type TypeGuardValidate<Output> = ((value: unknown) => value is Output) | Promise<(value: unknown) => value is Output>; | ||
| /** | ||
| * String encoder options for parsers | ||
| * @since v0.11.0 | ||
| */ | ||
| * String encoder options for parsers | ||
| * @since v0.11.0 | ||
| */ | ||
| type EncodeOptions = { | ||
| /** | ||
| * use URI encoding for string outputs (used by semicolon parser) | ||
| */ | ||
| * use URI encoding for string outputs (used by semicolon parser) | ||
| */ | ||
| uriEncode?: boolean; | ||
| /** | ||
| * not logging the value | ||
| */ | ||
| * not logging the value | ||
| */ | ||
| silent?: boolean; | ||
| }; | ||
| /** | ||
| * Interface for config parsers | ||
| * @template Input - Type of raw input value | ||
| * @template Output - Type of output value | ||
| * @since v1.0.0 | ||
| */ | ||
| * Interface for config parsers | ||
| * @template Input - Type of raw input value | ||
| * @template Output - Type of output value | ||
| * @since v1.0.0 | ||
| */ | ||
| interface IConfigParser<Input, Output> { | ||
| /** | ||
| * name of the parser | ||
| */ | ||
| * name of the parser | ||
| */ | ||
| name: string; | ||
| /** | ||
| * Config parser function | ||
| * @throws Error if parsing fails | ||
| */ | ||
| * Config parser function | ||
| * @throws Error if parsing fails | ||
| */ | ||
| parse(parserProps: ParserProps): Input | Promise<Input>; | ||
| /** | ||
| * Optional raw string value validation before parsing. | ||
| * @throws Error if validation fails | ||
| */ | ||
| * Optional raw string value validation before parsing. | ||
| * @throws Error if validation fails | ||
| */ | ||
| preValidate?(preValidateProps: PreValidateProps): void | Promise<void>; | ||
| /** | ||
| * Optional value validation after parsing | ||
| * @throws Error if validation fails | ||
| */ | ||
| * Optional value validation after parsing | ||
| * @throws Error if validation fails | ||
| */ | ||
| postValidate?(postValidateProps: PostValidateProps<Input>): Output | undefined | Promise<Output | undefined>; | ||
| /** | ||
| * Build readable string from value | ||
| */ | ||
| * Build readable string from value | ||
| */ | ||
| toString(config: Output, options?: EncodeOptions): string; | ||
| /** | ||
| * Optional build readable string from value for log (can hide sensitive part from logs) else toString is used | ||
| * @param config - value to log | ||
| */ | ||
| * Optional build readable string from value for log (can hide sensitive part from logs) else toString is used | ||
| * @param config - value to log | ||
| */ | ||
| toLogString?(config: Output): string; | ||
| } | ||
| //#endregion | ||
| //#region src/interfaces/IValidate.d.ts | ||
| /** | ||
| * Interface for validation function | ||
| * @template Input - Type of raw input | ||
| * @template Output - Type of output | ||
| * @since v1.0.0 | ||
| */ | ||
| type ValidateCallback<Input, Output> = (data: Input) => Output | Promise<Output>; | ||
| //#endregion | ||
| //#region src/interfaces/IRequestCache.d.ts | ||
| /** | ||
| * interface for a request cache | ||
| * @category Utils | ||
| * @example | ||
| * const exampleCache: IRequestCache = { | ||
| * isOnline() { | ||
| * return (typeof window !== 'undefined' && window.navigator && window.navigator.onLine) || true; | ||
| * }, | ||
| * async fetchRequest(req: Request) { | ||
| * if (typeof window !== 'undefined' && window.caches) { | ||
| * const cache = await window.caches.open('fetch'); | ||
| * return cache.match(req); | ||
| * } | ||
| * return undefined; | ||
| * }, | ||
| * async storeRequest(req: Request, res: Response) { | ||
| * if (typeof window !== 'undefined' && window.caches && res.ok) { | ||
| * const cache = await window.caches.open('fetch'); | ||
| * req.headers.delete('Authorization'); | ||
| * await cache.put(req, res.clone()); | ||
| * } | ||
| * }, | ||
| * }; | ||
| * @since v0.2.8 | ||
| */ | ||
| * interface for a request cache | ||
| * @category Utils | ||
| * @example | ||
| * const exampleCache: IRequestCache = { | ||
| * isOnline() { | ||
| * return (typeof window !== 'undefined' && window.navigator && window.navigator.onLine) || true; | ||
| * }, | ||
| * async fetchRequest(req: Request) { | ||
| * if (typeof window !== 'undefined' && window.caches) { | ||
| * const cache = await window.caches.open('fetch'); | ||
| * return cache.match(req); | ||
| * } | ||
| * return undefined; | ||
| * }, | ||
| * async storeRequest(req: Request, res: Response) { | ||
| * if (typeof window !== 'undefined' && window.caches && res.ok) { | ||
| * const cache = await window.caches.open('fetch'); | ||
| * req.headers.delete('Authorization'); | ||
| * await cache.put(req, res.clone()); | ||
| * } | ||
| * }, | ||
| * }; | ||
| * @since v0.2.8 | ||
| */ | ||
| interface IRequestCache { | ||
| /** | ||
| * check if the client is connected to the internet | ||
| */ | ||
| * check if the client is connected to the internet | ||
| */ | ||
| isOnline(): boolean; | ||
| /** | ||
| * get the cached response for a request | ||
| */ | ||
| * get the cached response for a request | ||
| */ | ||
| fetchRequest(req: Request): Promise<Response | undefined>; | ||
| /** | ||
| * store the response for a request | ||
| */ | ||
| * store the response for a request | ||
| */ | ||
| storeRequest(req: Request, res: Response): Promise<void>; | ||
| } | ||
| //#endregion | ||
| //#region src/types/RequestNotReady.d.ts | ||
| //#region src/interfaces/IValidate.d.ts | ||
| /** | ||
| * RequestNotReady indicates that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| interface RequestNotReady { | ||
| _type: 'RequestNotReady'; | ||
| message: string; | ||
| } | ||
| * Interface for validation function | ||
| * @template Input - Type of raw input | ||
| * @template Output - Type of output | ||
| * @since v1.0.0 | ||
| */ | ||
| type ValidateCallback<Input, Output> = (data: Input) => Output | Promise<Output>; | ||
| //#endregion | ||
| //#region src/lib/formatUtils.d.ts | ||
| /** | ||
| * Type guard for RequestNotReady | ||
| * @param {unknown} obj - object to check if it is a RequestNotReady payload | ||
| * @returns {boolean} boolean indicating if the object is a RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| declare function isRequestNotReadMessage(obj: unknown): obj is RequestNotReady; | ||
| * PartialHiddenValueStringType is the type for partial hidden value string, it can be 'prefix', 'suffix' or 'prefix-suffix' | ||
| * - 'prefix': show only prefix of secret "j43****" | ||
| * - 'suffix': show only suffix of secret "****7hd" | ||
| * - 'prefix-suffix': show both prefix and suffix of secret "j43****7hd" | ||
| * @since v0.9.0 | ||
| * @category Utils | ||
| */ | ||
| type PartialHiddenValueStringType = "prefix" | "suffix" | "prefix-suffix"; | ||
| /** | ||
| * function to create a RequestNotReady payload to indicate that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @param {string} message - reason why the request is not ready yet | ||
| * @returns {RequestNotReady} RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| declare function createRequestNotReady(message: string): RequestNotReady; | ||
| //#endregion | ||
| //#region src/lib/formatUtils.d.ts | ||
| type PartialHiddenValueStringType = /** show only prefix of secret "j43****" */'prefix' /** show only suffix of secret "****7hd" */ | 'suffix' /** show both prefix and suffix of secret "j43****7hd" */ | 'prefix-suffix'; | ||
| * ShowValueType is the type for show value option, it can be boolean or PartialHiddenValueStringType | ||
| * - true: show the actual value | ||
| * - false: show the value with asterisks | ||
| * - PartialHiddenValueStringType: shows part of the value (prefix, suffix, or both) | ||
| * @since v0.9.0 | ||
| */ | ||
| type ShowValueType = boolean | PartialHiddenValueStringType; | ||
| /** | ||
| * Format parameters for the variables | ||
| * @since v0.2.5 | ||
| */ | ||
| * Format parameters for the variables | ||
| * @since v0.2.5 | ||
| */ | ||
| interface FormatParameters { | ||
| /** | ||
| * Whether to show the value in the output, defaults to undefined | ||
| * - undefined: hide the value | ||
| * - true: show the actual value | ||
| * - false: show the value with asterisks | ||
| * - 'prefix': show only prefix of value (1-3 characters based on length of the value) | ||
| * - 'suffix': show only suffix of value (1-3 characters based on length of the value) | ||
| * - 'both': show both prefix and suffix of value (1-2 characters on suffix and prefix based on length of the value) | ||
| * @default false | ||
| */ | ||
| * Whether to show the value in the output, defaults to undefined | ||
| * - undefined: hide the value | ||
| * - true: show the actual value | ||
| * - false: show the value with asterisks | ||
| * - 'prefix': show only prefix of value (1-3 characters based on length of the value) | ||
| * - 'suffix': show only suffix of value (1-3 characters based on length of the value) | ||
| * - 'both': show both prefix and suffix of value (1-2 characters on suffix and prefix based on length of the value) | ||
| * @default false | ||
| */ | ||
| showValue?: ShowValueType; | ||
| } | ||
| /** | ||
| * Sanitizes a URL by replacing the username and password with asterisks. | ||
| * @param {string} value - The URL to sanitize. | ||
| * @param {ILoggerLike} [logger] - An optional logger to use for logging warnings. | ||
| * @returns {string} The sanitized URL. | ||
| * @category Utils | ||
| * @since v0.2.5 | ||
| */ | ||
| * Sanitizes a URL by replacing the username and password with asterisks. | ||
| * @param {string} value - The URL to sanitize. | ||
| * @param {ILoggerLike} [logger] - An optional logger to use for logging warnings. | ||
| * @returns {string} The sanitized URL. | ||
| * @category Utils | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function urlSanitize$1(value: string, logger?: ILoggerLike): string; | ||
| /** | ||
| * Returns a formatted string representation of a value, enclosed in square brackets. | ||
| * @param {string | undefined} value - The value to format. | ||
| * @param {FormatParameters | undefined} config - An optional configuration object. | ||
| * @returns {string} The formatted string representation of the value. | ||
| * @category Utils | ||
| * @since v0.2.5 | ||
| */ | ||
| * Returns a formatted string representation of a value, enclosed in square brackets. | ||
| * @param {string | undefined} value - The value to format. | ||
| * @param {FormatParameters | undefined} config - An optional configuration object. | ||
| * @returns {string} The formatted string representation of the value. | ||
| * @category Utils | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function printValue(value: string | undefined, config: FormatParameters | undefined): string; | ||
| /** | ||
| * Constructs a hidden value string based on the specified visibility option. | ||
| * @param {string} value - The original string value to be hidden. | ||
| * @param {ShowValueType | undefined} show - Determines how the value should be displayed: | ||
| * - `true`: shows the full value | ||
| * - `undefined` or `false`: hides the value completely with asterisks | ||
| * - `PartialHiddenValueStringType`: shows part of the value (prefix, suffix, or both) | ||
| * @returns {string} The resulting string with the specified visibility. | ||
| * @since v0.2.5 | ||
| */ | ||
| * Constructs a hidden value string based on the specified visibility option. | ||
| * @param {string} value - The original string value to be hidden. | ||
| * @param {ShowValueType | undefined} show - Determines how the value should be displayed: | ||
| * - `true`: shows the full value | ||
| * - `undefined` or `false`: hides the value completely with asterisks | ||
| * - `PartialHiddenValueStringType`: shows part of the value (prefix, suffix, or both) | ||
| * @returns {string} The resulting string with the specified visibility. | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildHiddenValue(value: string, show: ShowValueType | undefined): string; | ||
| /** | ||
| * Builds a hidden value string, replacing each character with an asterisk. | ||
| * @param {string} value - The value to be hidden. | ||
| * @returns {string} The hidden value string with asterisks. | ||
| * @since v0.2.5 | ||
| */ | ||
| * Builds a hidden value string, replacing each character with an asterisk. | ||
| * @param {string} value - The value to be hidden. | ||
| * @returns {string} The hidden value string with asterisks. | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildHiddenAsterisksValueString(value: string): string; | ||
| /** | ||
| * Show only 1-3 characters of the secret value based on length of the value. | ||
| * @param {string} value - The value to partially hide. | ||
| * @param {PartialHiddenValueStringType} type - The type of partial hiding to apply ('prefix', 'suffix', or 'prefix-suffix'). | ||
| * @returns {string} The partially hidden value string. | ||
| * @since v0.2.5 | ||
| */ | ||
| * Show only 1-3 characters of the secret value based on length of the value. | ||
| * @param {string} value - The value to partially hide. | ||
| * @param {PartialHiddenValueStringType} type - The type of partial hiding to apply ('prefix', 'suffix', or 'prefix-suffix'). | ||
| * @returns {string} The partially hidden value string. | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildPartialHiddenValueString(value: string, type: PartialHiddenValueStringType): string; | ||
@@ -298,87 +317,87 @@ //#endregion | ||
| /** | ||
| * Optional environment entry | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| * Optional environment entry | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| type OptionalEnvEntry<Value> = { | ||
| /** | ||
| * The parser to use to parse the value | ||
| */ | ||
| * The parser to use to parse the value | ||
| */ | ||
| parser: IConfigParser<unknown, Value>; | ||
| /** | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| defaultValue?: Loadable<Value>; | ||
| /** | ||
| * The format parameters to use to format the value | ||
| */ | ||
| * The format parameters to use to format the value | ||
| */ | ||
| params?: FormatParameters; | ||
| /** | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| undefinedThrowsError?: boolean; | ||
| /** | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| undefinedErrorMessage?: string; | ||
| }; | ||
| /** | ||
| * Required environment entry | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| * Required environment entry | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| type RequiredEnvEntry<Value> = { | ||
| /** | ||
| * The parser to use to parse the value | ||
| */ | ||
| * The parser to use to parse the value | ||
| */ | ||
| parser: IConfigParser<unknown, Value>; | ||
| /** | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| defaultValue: Loadable<Value>; | ||
| /** | ||
| * The format parameters to use to format the value | ||
| */ | ||
| * The format parameters to use to format the value | ||
| */ | ||
| params?: FormatParameters; | ||
| /** | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| undefinedThrowsError?: boolean; | ||
| /** | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| undefinedErrorMessage?: string; | ||
| }; | ||
| /** | ||
| * Required environment entry with undefinedThrowsError | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| * Required environment entry with undefinedThrowsError | ||
| * @template Value - type of value | ||
| * @since v1.1.0 | ||
| */ | ||
| type RequiredUndefinedThrowEntry<Value> = { | ||
| /** | ||
| * The parser to use to parse the value | ||
| */ | ||
| * The parser to use to parse the value | ||
| */ | ||
| parser: IConfigParser<unknown, Value>; | ||
| /** | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| * The default value to use if the variable is not defined | ||
| */ | ||
| defaultValue?: Loadable<Value>; | ||
| /** | ||
| * The format parameters to use to format the value | ||
| */ | ||
| * The format parameters to use to format the value | ||
| */ | ||
| params?: FormatParameters; | ||
| /** | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| * Whether to throw an error if the variable is undefined | ||
| */ | ||
| undefinedThrowsError: true; | ||
| /** | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| * Replaces the default throw error message with this message | ||
| */ | ||
| undefinedErrorMessage?: string; | ||
| }; | ||
| /** | ||
| * Environment map schema | ||
| * @template Output - type of output value | ||
| * @since v0.2.15 | ||
| */ | ||
| * Environment map schema | ||
| * @template Output - type of output value | ||
| * @since v0.2.15 | ||
| */ | ||
| type EnvMapSchema<Output extends Record<string, unknown>> = { [K in keyof Required<Output>]: undefined extends Output[K] ? OptionalEnvEntry<Output[K]> : RequiredEnvEntry<Output[K]> | RequiredUndefinedThrowEntry<Output[K]> }; | ||
@@ -388,6 +407,6 @@ //#endregion | ||
| /** | ||
| * Loader type value | ||
| * @template T - type of value | ||
| * @since 0.2.18 | ||
| */ | ||
| * Loader type value | ||
| * @template T - type of value | ||
| * @since 0.2.18 | ||
| */ | ||
| type LoaderTypeValue<T> = { | ||
@@ -400,6 +419,6 @@ /** type of loader output (default, env,...) */type: string | undefined; /** output value */ | ||
| /** | ||
| * Loader type strict value | ||
| * @template T - type of value | ||
| * @since 0.2.18 | ||
| */ | ||
| * Loader type strict value | ||
| * @template T - type of value | ||
| * @since 0.2.18 | ||
| */ | ||
| type LoaderTypeValueStrict<T> = { | ||
@@ -412,94 +431,176 @@ /** type of loader output (default, env,...) */type: string | undefined; /** output value */ | ||
| //#endregion | ||
| //#region src/ConfigOptions.d.ts | ||
| type ConfigOptions = { | ||
| /** undefined = global logger, null = no logger else it's ILoggerLike */logger?: ILoggerLike | null; /** optional namespace added to logs */ | ||
| namespace?: string; | ||
| }; | ||
| type SolvedConfigOptions = { | ||
| /** optional logger instance */logger: ILoggerLike | undefined; /** optional namespace added to logs */ | ||
| namespace: string | undefined; | ||
| }; | ||
| //#region src/ConfigMap.d.ts | ||
| /** | ||
| * Build options from partial options | ||
| * @param {Partial<ConfigOptions>} options - partial config options | ||
| * @returns {SolvedConfigOptions} - solved config options | ||
| * @category Config | ||
| * @since v0.6.0 | ||
| */ | ||
| declare function buildOptions({ | ||
| logger, | ||
| namespace | ||
| }?: Partial<ConfigOptions>): SolvedConfigOptions; | ||
| //#endregion | ||
| //#region src/getConfigVariable.d.ts | ||
| * TypeValueRecords | ||
| * @template T - type of config map | ||
| * @since v0.6.0 | ||
| */ | ||
| type TypeValueRecords<T> = Record<keyof T, LoaderTypeValueStrict<T[keyof T]>>; | ||
| /** | ||
| * get config variable from loaders | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * | ||
| * const port: Promise<string> = await getConfigVariable('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * // with override key | ||
| * const port: Promise<string> = await getConfigVariable('PORT', [env('HTTP_PORT', fileEnv())], stringParser, '8080', {showValue: true}); | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey - root key of config variable | ||
| * @param {IConfigLoader[]} loaders - loaders to use | ||
| * @param {IConfigParser<unknown, Output>} parser - parser to use | ||
| * @param {Loadable<Output>} [defaultValueLoadable] - default value to use | ||
| * @param {FormatParameters} [params] - optional format parameters | ||
| * @param {ConfigOptions} [options] - optional config options | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<Output>} - config variable | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function getConfigVariable<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<Output>; | ||
| declare function getConfigVariable<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<Output | undefined>; | ||
| * ConfigMap | ||
| * @example | ||
| * type ConfigEnv = { | ||
| * PORT: number; | ||
| * HOST: string; | ||
| * DEBUG: boolean; | ||
| * URL: URL; | ||
| * }; | ||
| * const env = new EnvConfigLoader(); | ||
| * const config = new ConfigMap<ConfigEnv>( | ||
| * { | ||
| * DEBUG: {defaultValue: false, parser: booleanParser()}, | ||
| * HOST: {defaultValue: 'localhost', parser: stringParser()}, | ||
| * PORT: {defaultValue: 3000, parser: integerParser()}, | ||
| * URL: {defaultValue: new URL('http://localhost:3000'), parser: new UrlParser({urlSanitize: true})}, | ||
| * }, | ||
| * [env], | ||
| * ); | ||
| * console.log('port', await config.get('PORT')); | ||
| * @template Data - type of config map | ||
| * @since v1.1.0 | ||
| */ | ||
| declare class ConfigMap<Data extends Record<string, unknown>> implements ISetOptionalLogger { | ||
| private schema; | ||
| private options; | ||
| private loaders; | ||
| /** | ||
| * ConfigMap constructor | ||
| * @param {EnvMapSchema<Data>} schema - schema of config map | ||
| * @param {Iterable<IConfigLoader>} loaders - iterable of config loaders | ||
| * @param {ConfigOptions} options - optional config options (logger, namespace) | ||
| */ | ||
| constructor(schema: EnvMapSchema<Data>, loaders: Loadable<Iterable<IConfigLoader>>, options?: ConfigOptions); | ||
| /** | ||
| * Set logger value | ||
| * @param {ILoggerLike | undefined} logger - logger like object | ||
| */ | ||
| setLogger(logger: ILoggerLike | undefined): void; | ||
| /** | ||
| * get env object from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: LoaderTypeValue<number> = await config.getObject('PORT'); | ||
| * console.log(valueObject.type, valueObject.value); // 'env', 3000 | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getObject<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<LoaderTypeValueStrict<Data[Key]>>; | ||
| /** | ||
| * get env object from config map as Result | ||
| * @returns {Promise<Result<TypeValueRecords<Data>>>} Result Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: Result<LoaderTypeValue<number>> = await config.getObjectResult('PORT'); | ||
| * if (valueObject.isOk()) { | ||
| * const {type, value} = valueObject.ok(); | ||
| * console.log(type, value); // 'env', 3000 | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getObjectResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<LoaderTypeValueStrict<Data[Key]>>>; | ||
| /** | ||
| * get env value from config map | ||
| * @returns {Promise<Data[Key]>} Promise of value or undefined | ||
| * @example | ||
| * const port: number = await config.get('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| get<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<Data[Key]>; | ||
| /** | ||
| * get env value as string from config map | ||
| * @returns {Promise<string | undefined>} Promise of string value or undefined | ||
| * @example | ||
| * const port: string = await config.getString('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getString<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<undefined extends Data[Key] ? string | undefined : string>; | ||
| /** | ||
| * get env value from config map as Result | ||
| * @returns {Promise<Result<Data[Key]>>} Result Promise of value or undefined | ||
| * @example | ||
| * const port: Result<number> = await config.getResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<Data[Key]>>; | ||
| /** | ||
| * get env value as string from config map as Result | ||
| * @returns {Promise<Result<string | undefined>>} Result Promise of string value or undefined | ||
| * @example | ||
| * const port: Result<string> = await config.getStringResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getStringResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<undefined extends Data[Key] ? string | undefined : string>>; | ||
| /** | ||
| * get all env value objects from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of all values | ||
| * @example | ||
| * const values: TypeValueRecords<Data> = await config.getAll(); | ||
| * console.log(values.PORT.type, values.PORT.value); // 'env', 3000 | ||
| */ | ||
| getAllObjects(): Promise<TypeValueRecords<Data>>; | ||
| /** | ||
| * get all env values from config map | ||
| * @returns {Promise<Data>} Promise of all values | ||
| * @example | ||
| * const values: Data = await config.getAllValues(); | ||
| * console.log('PORT', values.PORT); // 3000 (number) | ||
| */ | ||
| getAllValues(): Promise<Data>; | ||
| /** | ||
| * get all env values from config map as string | ||
| * @returns {Promise<Record<keyof Data, string>>} Promise of all values as string | ||
| * @example | ||
| * const values: Record<keyof Data, string> = await config.getAllStringValues(); | ||
| * console.log('PORT', values.PORT); // '3000' (string) | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getAllStringValues(encodeOptions?: EncodeOptions): Promise<Record<keyof Data, string>>; | ||
| /** | ||
| * Validate all env values from config map, expect to throw error if error exists | ||
| * @param {(data: Data) => void} callback callback function | ||
| */ | ||
| validateAll(callback: (data: Data) => void): Promise<void>; | ||
| /** | ||
| * run lookup to all keys and return all promises | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<[keyof Data, LoaderTypeValueStrict<Data[keyof Data]>][]>} Promise of all values | ||
| */ | ||
| private getAllPromises; | ||
| } | ||
| //#endregion | ||
| //#region src/getConfigVariableResult.d.ts | ||
| /** | ||
| * get config variable from loaders | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const portResult: Result<string> = await getConfigVariableResult('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * | ||
| * const value: string = portResult.unwrap(); // get value or throw error | ||
| * const value: string | undefined = portResult.ok(); // get value or undefined | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey - root key of config variable | ||
| * @param {IConfigLoader[]} loaders - loaders to use | ||
| * @param {IConfigParser<unknown, Output>} parser - parser to use | ||
| * @param {Loadable<Output>} [defaultValueLoadable] - default value to use | ||
| * @param {FormatParameters} [params] - optional format parameters | ||
| * @param {ConfigOptions} [options] - optional config options | ||
| * @returns {Promise<IResult<Output | undefined>>} - result with value or error | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function getConfigVariableResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<Output>>; | ||
| declare function getConfigVariableResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<Output | undefined>>; | ||
| //#endregion | ||
| //#region src/getConfigObject.d.ts | ||
| /** | ||
| * Clear the seen map for default values (for unit testing purposes) | ||
| * @since v0.2.5 | ||
| */ | ||
| * Clear the seen map for default values (for unit testing purposes) | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function clearDefaultValueSeenMap(): void; | ||
| /** | ||
| * get config object which contains value and type of loader | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * const portConfig: {type: string | undefined; value: string} = await getConfigObject('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * const value: string = portConfig.value; | ||
| * const type: string | undefined = portConfig.type; // loader type name | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey root key of config object | ||
| * @param {IConfigLoader[]} loaders array of loaders | ||
| * @param {IConfigParser<unknown, Output>} parser parser for value | ||
| * @param {Loadable<Output>} defaultValueLoadable optional default value | ||
| * @param {FormatParameters} params optional format parameters | ||
| * @param {ConfigOptions} options optional config options | ||
| * @param {EncodeOptions} [encodeOptions] optional encode options | ||
| * @returns {Promise<LoaderTypeValue<Output>>} config object | ||
| * @since v0.2.5 | ||
| */ | ||
| * get config object which contains value and type of loader | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * const portConfig: {type: string | undefined; value: string} = await getConfigObject('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * const value: string = portConfig.value; | ||
| * const type: string | undefined = portConfig.type; // loader type name | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey root key of config object | ||
| * @param {IConfigLoader[]} loaders array of loaders | ||
| * @param {IConfigParser<unknown, Output>} parser parser for value | ||
| * @param {Loadable<Output>} defaultValueLoadable optional default value | ||
| * @param {FormatParameters} params optional format parameters | ||
| * @param {ConfigOptions} options optional config options | ||
| * @param {EncodeOptions} [encodeOptions] optional encode options | ||
| * @returns {Promise<LoaderTypeValue<Output>>} config object | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function getConfigObject<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<LoaderTypeValueStrict<Output>>; | ||
@@ -510,22 +611,22 @@ declare function getConfigObject<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<LoaderTypeValue<Output>>; | ||
| /** | ||
| * Wrapper around getConfigObject that returns a Result | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * const portConfig: Result<{type: string | undefined; value: string}> = await getConfigObject('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * if ( portConfig.isOk() ) { | ||
| * const {value, type} = portConfig.unwrap(); | ||
| * } else { | ||
| * // handle error | ||
| * } | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey root key of config object | ||
| * @param {IConfigLoader[]} loaders array of loaders | ||
| * @param {IConfigParser<unknown, Output>} parser parser for value | ||
| * @param {Loadable<Output>} defaultValueLoadable optional default value | ||
| * @param {FormatParameters} params optional format parameters | ||
| * @param {ConfigOptions} options optional config options | ||
| * @returns {Promise<IResult<{type: string | undefined; value: Output}>>} result | ||
| * @since v0.2.5 | ||
| */ | ||
| * Wrapper around getConfigObject that returns a Result | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * const portConfig: Result<{type: string | undefined; value: string}> = await getConfigObject('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * if ( portConfig.isOk() ) { | ||
| * const {value, type} = portConfig.unwrap(); | ||
| * } else { | ||
| * // handle error | ||
| * } | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey root key of config object | ||
| * @param {IConfigLoader[]} loaders array of loaders | ||
| * @param {IConfigParser<unknown, Output>} parser parser for value | ||
| * @param {Loadable<Output>} defaultValueLoadable optional default value | ||
| * @param {FormatParameters} params optional format parameters | ||
| * @param {ConfigOptions} options optional config options | ||
| * @returns {Promise<IResult<{type: string | undefined; value: Output}>>} result | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function getConfigObjectResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<{ | ||
@@ -540,8 +641,133 @@ type: string | undefined; | ||
| //#endregion | ||
| //#region src/getConfigVariable.d.ts | ||
| /** | ||
| * get config variable from loaders | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const fileEnv = new FileConfigLoader({fileName: './settings.json', type: 'json'}).getLoader; | ||
| * | ||
| * const port: Promise<string> = await getConfigVariable('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * // with override key | ||
| * const port: Promise<string> = await getConfigVariable('PORT', [env('HTTP_PORT', fileEnv())], stringParser, '8080', {showValue: true}); | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey - root key of config variable | ||
| * @param {IConfigLoader[]} loaders - loaders to use | ||
| * @param {IConfigParser<unknown, Output>} parser - parser to use | ||
| * @param {Loadable<Output>} [defaultValueLoadable] - default value to use | ||
| * @param {FormatParameters} [params] - optional format parameters | ||
| * @param {ConfigOptions} [options] - optional config options | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<Output>} - config variable | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function getConfigVariable<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<Output>; | ||
| declare function getConfigVariable<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions, encodeOptions?: EncodeOptions): Promise<Output | undefined>; | ||
| //#endregion | ||
| //#region src/getConfigVariableResult.d.ts | ||
| /** | ||
| * get config variable from loaders | ||
| * @example | ||
| * // from "@avanio/variable-util-node" | ||
| * const portResult: Result<string> = await getConfigVariableResult('PORT', [env(), fileEnv()], stringParser, '8080', {showValue: true}); | ||
| * | ||
| * const value: string = portResult.unwrap(); // get value or throw error | ||
| * const value: string | undefined = portResult.ok(); // get value or undefined | ||
| * @template Output - Type of output | ||
| * @param {string} rootKey - root key of config variable | ||
| * @param {IConfigLoader[]} loaders - loaders to use | ||
| * @param {IConfigParser<unknown, Output>} parser - parser to use | ||
| * @param {Loadable<Output>} [defaultValueLoadable] - default value to use | ||
| * @param {FormatParameters} [params] - optional format parameters | ||
| * @param {ConfigOptions} [options] - optional config options | ||
| * @returns {Promise<IResult<Output | undefined>>} - result with value or error | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function getConfigVariableResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<Output>>; | ||
| declare function getConfigVariableResult<Output>(rootKey: string, loaders: IConfigLoader[], parser: IConfigParser<unknown, Output>, defaultValueLoadable?: Loadable<Output>, params?: FormatParameters, options?: ConfigOptions): Promise<IResult<Output | undefined>>; | ||
| //#endregion | ||
| //#region src/lib/objectUtils.d.ts | ||
| /** | ||
| * validate if a value is a valid object | ||
| * @param {unknown} value - value to validate | ||
| * @returns {value is Record<string, unknown>} - true if value is a valid object | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function isValidObject(value: unknown): value is Record<string, unknown>; | ||
| /** | ||
| * Convert an object to a string value object | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Record<string, string | undefined>} - object with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildStringObject(obj: Record<string, unknown>): Record<string, string>; | ||
| /** | ||
| * Convert an object to a Map<string, string> | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Map<string, string>} - Map with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildStringMap(obj: Record<string, unknown>): Map<string, string>; | ||
| /** | ||
| * Apply a Record<string, string> to a Map<string, string> | ||
| * @param {Record<string, string | undefined>} obj - object to apply | ||
| * @param {Map<string, string>} target - Map to apply to | ||
| * @returns {Map<string, string>} - target with updates | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function applyStringMap(obj: Record<string, string | undefined>, target: Map<string, string>): Map<string, string>; | ||
| //#endregion | ||
| //#region src/lib/seenUtils.d.ts | ||
| /** | ||
| * Function to check if we have seen a value before and update the seenMap | ||
| * @param {Map<string, string>} seenMap - Map of seen values | ||
| * @param {string} key - key to check | ||
| * @param {string | undefined} value - value to check | ||
| * @returns {boolean} - true if already seen value, false if not | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function handleSeen(seenMap: Map<string, string>, key: string, value: string | undefined): boolean; | ||
| //#endregion | ||
| //#region src/lib/semicolonUtils.d.ts | ||
| /** | ||
| * Parse a semicolon separated string into a config object | ||
| * @param {string} config Semicolon separated string | ||
| * @param {boolean} [keepCase] Keep the case of the keys, default true | ||
| * @returns {Record<string, string>} Config object | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * parseSemicolonConfig('a=b;c=d') // {a: 'b', c: 'd'} | ||
| */ | ||
| declare function parseSemicolonConfig(config: string, keepCase?: boolean): Record<string, string>; | ||
| /** | ||
| * Stringify a config object to a semicolon separated string | ||
| * @param {Record<string, string>} config Object to stringify | ||
| * @param {boolean} [uriEncode] Use URI encoding for string outputs | ||
| * @returns {string} Stringified config | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * stringifySemicolonConfig({a: 'b', c: 'd'}) // 'a=b;c=d' | ||
| */ | ||
| declare function stringifySemicolonConfig(config: Record<string, unknown>, uriEncode?: boolean): string; | ||
| /** | ||
| * Stringify a config object to a semicolon separated string for logging | ||
| * @template Out - Type of output | ||
| * @param {Record<string, string>} config Object to stringify | ||
| * @param {ShowValueType} showProtectedKeys How to show protected keys | ||
| * @param {string[]} protectedKeys list of protected keys | ||
| * @returns {string} Stringified config | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * logStringifySemicolonConfig({a: 'b', c: 'd'}) // 'a=b;c=d' | ||
| */ | ||
| declare function logStringifySemicolonConfig<Out extends Record<string, unknown>>(config: Out, showProtectedKeys: ShowValueType | undefined, protectedKeys: Set<keyof Out>): string; | ||
| //#endregion | ||
| //#region src/loaders/ConfigLoader.d.ts | ||
| /** | ||
| * ConfigLoaderEventMap is the event map for the ConfigLoader | ||
| * @category Loaders | ||
| * @since v0.11.1 | ||
| */ | ||
| * ConfigLoaderEventMap is the event map for the ConfigLoader | ||
| * @category Loaders | ||
| * @since v0.11.1 | ||
| */ | ||
| type ConfigLoaderEventMap = { | ||
@@ -551,9 +777,14 @@ /** notify when loader data is updated */updated: []; | ||
| /** | ||
| * IConfigLoaderProps is the interface for ConfigLoader props | ||
| * @category Loaders | ||
| * @since v0.8.0 | ||
| */ | ||
| * IConfigLoaderProps is the interface for ConfigLoader props | ||
| * @category Loaders | ||
| * @since v0.8.0 | ||
| */ | ||
| interface IConfigLoaderProps { | ||
| disabled?: Loadable<boolean>; | ||
| } | ||
| /** | ||
| * LoaderValueResult is the result of a loader value lookup | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| type LoaderValue = { | ||
@@ -564,9 +795,9 @@ value: string | undefined; | ||
| /** | ||
| * Abstract base class for config loaders | ||
| * @template Props - the type of the props | ||
| * @template OverrideMap - the type of the override key map | ||
| * @category Loaders | ||
| * @abstract | ||
| * @since v1.0.0 | ||
| */ | ||
| * Abstract base class for config loaders | ||
| * @template Props - the type of the props | ||
| * @template OverrideMap - the type of the override key map | ||
| * @category Loaders | ||
| * @abstract | ||
| * @since v1.0.0 | ||
| */ | ||
| declare abstract class ConfigLoader<Props extends IConfigLoaderProps, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends EventEmitter<ConfigLoaderEventMap> implements IConfigLoader { | ||
@@ -579,103 +810,75 @@ abstract loaderType: Lowercase<string>; | ||
| constructor(props?: Loadable<Partial<Props>>, overrideKeys?: Partial<OverrideMap>); | ||
| getLoaderResult(lookupKey: string): Promise<{ | ||
| value: string | undefined; | ||
| path: string; | ||
| seen: boolean; | ||
| } | undefined>; | ||
| isLoaderDisabled(): Promise<boolean | undefined>; | ||
| setDisabled(disabled: Loadable<boolean>): Promise<void>; | ||
| getLoaderResult(lookupKey: string): Promise<undefined | LoaderValueResult>; | ||
| isLoaderDisabled(): Promise<boolean>; | ||
| setDisabled(disabled: Loadable<boolean>): void; | ||
| /** | ||
| * Get options from loader and merge with default options | ||
| * @returns {Promise<DefaultProps>} - Promise of DefaultProps & Props | ||
| */ | ||
| * Get options from loader and merge with default options | ||
| * @returns {Promise<DefaultProps>} - Promise of DefaultProps & Props | ||
| */ | ||
| protected getOptions(): Promise<Props>; | ||
| protected setOption<Key extends keyof Props>(key: Key, value: Props[Key]): Promise<void>; | ||
| /** | ||
| * Build error string `ConfigVariables[<type>]: <message>` | ||
| * @param {string} message - error message | ||
| * @returns {string} - error string | ||
| */ | ||
| * Build error string `ConfigVariables[<type>]: <message>` | ||
| * @param {string} message - error message | ||
| * @returns {string} - error string | ||
| */ | ||
| protected buildErrorStr(message: string): string; | ||
| /** | ||
| * implementation of config loader function | ||
| * @param lookupKey - key to lookup in config | ||
| * @param params - optional passing params for handleLoader (i.e. lookup key override, settings etc.) | ||
| * @returns {LoaderValue | Promise<LoaderValue>} - Promise of LoaderValue | ||
| */ | ||
| * implementation of config loader function | ||
| * @param lookupKey - key to lookup in config | ||
| * @returns {LoaderValue | Promise<LoaderValue>} - Promise of LoaderValue | ||
| */ | ||
| protected abstract handleLoaderValue(lookupKey: string): undefined | LoaderValue | Promise<undefined | LoaderValue>; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/RecordConfigLoader.d.ts | ||
| /** | ||
| * RecordConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| */ | ||
| declare abstract class RecordConfigLoader<Props extends IConfigLoaderProps, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<Props, OverrideMap> { | ||
| protected abstract defaultOptions: Props; | ||
| protected _isLoaded: boolean; | ||
| protected dataPromise: Promise<Record<string, string>> | undefined; | ||
| /** | ||
| * reloads the data | ||
| */ | ||
| reload(): Promise<void>; | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} - true if the data is loaded, false otherwise | ||
| */ | ||
| isLoaded(): boolean; | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| protected loadData(): Promise<void>; | ||
| protected abstract handleData(): Promise<Record<string, string>>; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/EnvConfigLoader.d.ts | ||
| /** | ||
| * env loader class is used to load env variables from process.env | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {string} [overrideKey] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| * env loader class is used to load env variables from process.env | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {string} [overrideKey] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class EnvConfigLoader<OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<IConfigLoaderProps, OverrideMap> { | ||
| readonly loaderType = "env"; | ||
| defaultOptions: IConfigLoaderProps; | ||
| protected handleLoaderValue(lookupKey: string): { | ||
| value: string | undefined; | ||
| path: string; | ||
| }; | ||
| protected handleLoaderValue(lookupKey: string): LoaderValue; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/ReactEnvConfigLoader.d.ts | ||
| //#region src/types/RequestNotReady.d.ts | ||
| /** | ||
| * React env loader class is used to load env variables from process.env.REACT_APP_* | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {Partial<OverrideMap>} [override] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class ReactEnvConfigLoader<OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<IConfigLoaderProps, OverrideMap> { | ||
| readonly loaderType = "react-env"; | ||
| defaultOptions: IConfigLoaderProps; | ||
| protected handleLoaderValue(lookupKey: string): { | ||
| value: string | undefined; | ||
| path: string; | ||
| }; | ||
| * RequestNotReady indicates that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| interface RequestNotReady { | ||
| _type: "RequestNotReady"; | ||
| message: string; | ||
| } | ||
| /** | ||
| * Type guard for RequestNotReady | ||
| * @param {unknown} obj - object to check if it is a RequestNotReady payload | ||
| * @returns {boolean} boolean indicating if the object is a RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| declare function isRequestNotReadMessage(obj: unknown): obj is RequestNotReady; | ||
| /** | ||
| * function to create a RequestNotReady payload to indicate that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @param {string} message - reason why the request is not ready yet | ||
| * @returns {RequestNotReady} RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| declare function createRequestNotReady(message: string): RequestNotReady; | ||
| //#endregion | ||
| //#region src/loaders/MapConfigLoader.d.ts | ||
| /** | ||
| * MapConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| * MapConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| declare abstract class MapConfigLoader<Props extends IConfigLoaderProps, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<Props, OverrideMap> { | ||
@@ -686,15 +889,15 @@ protected abstract defaultOptions: Props; | ||
| /** | ||
| * clear maps and reloads the data | ||
| */ | ||
| * clear maps and reloads the data | ||
| */ | ||
| reload(): Promise<void>; | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} Whether the data is loaded | ||
| */ | ||
| * is the data loaded | ||
| * @returns {boolean} Whether the data is loaded | ||
| */ | ||
| isLoaded(): boolean; | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| protected loadData(): Promise<void>; | ||
@@ -706,5 +909,5 @@ protected abstract handleLoadData(): Promise<boolean>; | ||
| /** | ||
| * Options for the FetchConfigLoader | ||
| * @since v1.0.0 | ||
| */ | ||
| * Options for the FetchConfigLoader | ||
| * @since v1.0.0 | ||
| */ | ||
| interface FetchConfigLoaderOptions extends IConfigLoaderProps { | ||
@@ -714,3 +917,3 @@ fetchClient: typeof fetch; | ||
| isSilent: boolean; | ||
| payload: 'json'; | ||
| payload: "json"; | ||
| validate: ValidateCallback<Record<string, string | undefined>, Record<string, string | undefined>> | undefined; | ||
@@ -724,7 +927,7 @@ logger: ILoggerLike | undefined; | ||
| /** | ||
| * FetchConfigLoader is used to load config from a fetch request | ||
| * @template OverrideMap - the type of the override key map | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| * FetchConfigLoader is used to load config from a fetch request | ||
| * @template OverrideMap - the type of the override key map | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class FetchConfigLoader<OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends MapConfigLoader<FetchConfigLoaderOptions, OverrideMap> { | ||
@@ -736,33 +939,30 @@ readonly loaderType: Lowercase<string>; | ||
| /** | ||
| * Constructor for FetchConfigLoader | ||
| * @param {Loadable<ConfigRequest>} request - callback that returns a fetch request or a message object that the request is not ready | ||
| * @param {Loadable<Partial<FetchConfigLoaderOptions>>} options - optional options for FetchConfigLoader | ||
| * @param {Partial<OverrideMap>} overrideKeys - optional override keys for FetchConfigLoader | ||
| * @param {Lowercase<string>} type - optional name type for FetchConfigLoader (default: 'fetch') | ||
| */ | ||
| * Constructor for FetchConfigLoader | ||
| * @param {Loadable<ConfigRequest>} request - callback that returns a fetch request or a message object that the request is not ready | ||
| * @param {Loadable<Partial<FetchConfigLoaderOptions>>} options - optional options for FetchConfigLoader | ||
| * @param {Partial<OverrideMap>} overrideKeys - optional override keys for FetchConfigLoader | ||
| * @param {Lowercase<string>} type - optional name type for FetchConfigLoader (default: 'fetch') | ||
| */ | ||
| constructor(request: Loadable<ConfigRequest>, options?: Loadable<Partial<FetchConfigLoaderOptions>>, overrideKeys?: Partial<OverrideMap>, type?: Lowercase<string>); | ||
| protected handleLoaderValue(lookupKey: string): Promise<{ | ||
| value: string | undefined; | ||
| path: string; | ||
| }>; | ||
| protected handleLoaderValue(lookupKey: string): Promise<undefined | LoaderValue>; | ||
| protected handleLoadData(): Promise<boolean>; | ||
| /** | ||
| * if client is offline, we will try return the cached response else add cache validation (ETag) and try get the response from the fetch request | ||
| * @param {Request} req - request to fetch | ||
| * @returns {Promise<Response | undefined>} - response or undefined | ||
| */ | ||
| * if client is offline, we will try return the cached response else add cache validation (ETag) and try get the response from the fetch request | ||
| * @param {Request} req - request to fetch | ||
| * @returns {Promise<Response | undefined>} - response or undefined | ||
| */ | ||
| private fetchRequestOrCacheResponse; | ||
| /** | ||
| * on error, check if we have a valid cached response | ||
| * @param {Request} req - request to fetch | ||
| * @param {Response} res - response from fetch | ||
| * @returns {Promise<Response>} - response | ||
| */ | ||
| * on error, check if we have a valid cached response | ||
| * @param {Request} req - request to fetch | ||
| * @param {Response} res - response from fetch | ||
| * @returns {Promise<Response>} - response | ||
| */ | ||
| private checkIfValidCacheResponse; | ||
| /** | ||
| * if we get a 304, get the cached response | ||
| * @param {Request} req - request to fetch | ||
| * @param {Response} res - response from fetch | ||
| * @returns {Promise<Response>} - response | ||
| */ | ||
| * if we get a 304, get the cached response | ||
| * @param {Request} req - request to fetch | ||
| * @param {Response} res - response from fetch | ||
| * @returns {Promise<Response>} - response | ||
| */ | ||
| private handleNotModifiedCache; | ||
@@ -774,2 +974,7 @@ private handleJson; | ||
| //#region src/loaders/MemoryConfigLoader.d.ts | ||
| /** | ||
| * IMemoryConfigLoaderProps is the interface for MemoryConfigLoader props | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| interface IMemoryConfigLoaderProps extends IConfigLoaderProps { | ||
@@ -779,9 +984,9 @@ logger: ILoggerLike | undefined; | ||
| /** | ||
| * Config loader with in-memory data which can be set and retrieved variables on the fly. | ||
| * - Useful for temporary controlled overrides or testing | ||
| * @template MemoryMap - the type of the memory map | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| * Config loader with in-memory data which can be set and retrieved variables on the fly. | ||
| * - Useful for temporary controlled overrides or testing | ||
| * @template MemoryMap - the type of the memory map | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| declare class MemoryConfigLoader<MemoryMap extends Record<string, string | undefined>, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<IMemoryConfigLoaderProps, OverrideMap> { | ||
@@ -794,9 +999,55 @@ readonly loaderType: Lowercase<string>; | ||
| get(key: keyof MemoryMap): Promise<string | undefined>; | ||
| protected handleLoaderValue(lookupKey: string): { | ||
| value: string | undefined; | ||
| path: string; | ||
| }; | ||
| protected handleLoaderValue(lookupKey: string): LoaderValue; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/ReactEnvConfigLoader.d.ts | ||
| /** | ||
| * React env loader class is used to load env variables from process.env.REACT_APP_* | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {Partial<OverrideMap>} [override] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class ReactEnvConfigLoader<OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<IConfigLoaderProps, OverrideMap> { | ||
| readonly loaderType = "react-env"; | ||
| defaultOptions: IConfigLoaderProps; | ||
| protected handleLoaderValue(lookupKey: string): LoaderValue; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/RecordConfigLoader.d.ts | ||
| /** | ||
| * RecordConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| */ | ||
| declare abstract class RecordConfigLoader<Props extends IConfigLoaderProps, OverrideMap extends OverrideKeyMap = OverrideKeyMap> extends ConfigLoader<Props, OverrideMap> { | ||
| protected abstract defaultOptions: Props; | ||
| protected _isLoaded: boolean; | ||
| protected dataPromise: Promise<Record<string, string>> | undefined; | ||
| /** | ||
| * reloads the data | ||
| */ | ||
| reload(): Promise<void>; | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} - true if the data is loaded, false otherwise | ||
| */ | ||
| isLoaded(): boolean; | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| protected loadData(): Promise<void>; | ||
| protected abstract handleData(): Promise<Record<string, string>>; | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/SwitchLoader.d.ts | ||
| /** | ||
| * ISwitchLoaderProps is the interface for SwitchLoader props | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| interface ISwitchLoaderProps extends IConfigLoaderProps { | ||
@@ -806,29 +1057,29 @@ logger?: ILoggerLike; | ||
| /** | ||
| * ConfigMap, this is a helper type to define the configuration map for the switch loader. | ||
| * @template Key - The key to switch between | ||
| * @template Map - The configuration map | ||
| * @since v0.10.1 | ||
| * @example | ||
| * type TestConfigMapEnv = { DEMO: string; ANOTHER: string; }; | ||
| * const switchConfigMap: SwitchConfigMap<TestConfigMapEnv, 'switch1' | 'switch2'> = { | ||
| * switch1: { DEMO: 'value' }, | ||
| * switch2: { DEMO: 'value2' }, | ||
| * }; | ||
| */ | ||
| * ConfigMap, this is a helper type to define the configuration map for the switch loader. | ||
| * @template Key - The key to switch between | ||
| * @template Map - The configuration map | ||
| * @since v0.10.1 | ||
| * @example | ||
| * type TestConfigMapEnv = { DEMO: string; ANOTHER: string; }; | ||
| * const switchConfigMap: SwitchConfigMap<TestConfigMapEnv, 'switch1' | 'switch2'> = { | ||
| * switch1: { DEMO: 'value' }, | ||
| * switch2: { DEMO: 'value2' }, | ||
| * }; | ||
| */ | ||
| type SwitchConfigMap<Map extends Record<string, unknown>, Key extends string> = Record<Key, Partial<Record<keyof Map, string>>>; | ||
| /** | ||
| * SwitchLoader, this loader will switch between different configurations based on the active key. | ||
| * @example | ||
| * type TestConfigMapEnv = { DEMO: string; ANOTHER: string; }; | ||
| * const switchLoader = new SwitchLoader<TestEnv, 'switch1' | 'switch2'>({ | ||
| * switch1: { DEMO: 'value' }, | ||
| * switch2: { DEMO: 'value2' }, | ||
| * }); | ||
| * const switcher = switchLoader.getLoader; // use this on the config map loaders: [switcher(), dotenv(), env(), ...] | ||
| * await switchLoader.activateSwitch('switch1'); // when you want enable switch1 values | ||
| * @template Config - The configuration map | ||
| * @template Key - The key to switch between | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| * SwitchLoader, this loader will switch between different configurations based on the active key. | ||
| * @example | ||
| * type TestConfigMapEnv = { DEMO: string; ANOTHER: string; }; | ||
| * const switchLoader = new SwitchLoader<TestEnv, 'switch1' | 'switch2'>({ | ||
| * switch1: { DEMO: 'value' }, | ||
| * switch2: { DEMO: 'value2' }, | ||
| * }); | ||
| * const switcher = switchLoader.getLoader; // use this on the config map loaders: [switcher(), dotenv(), env(), ...] | ||
| * await switchLoader.activateSwitch('switch1'); // when you want enable switch1 values | ||
| * @template Config - The configuration map | ||
| * @template Key - The key to switch between | ||
| * @since v1.0.0 | ||
| * @category Loaders | ||
| */ | ||
| declare class SwitchLoader<Config extends Record<string, unknown>, Key extends string> extends ConfigLoader<ISwitchLoaderProps> { | ||
@@ -847,3 +1098,99 @@ readonly loaderType: Lowercase<string>; | ||
| //#endregion | ||
| //#region src/logger.d.ts | ||
| /** | ||
| * Set the logger to be used by the module | ||
| * @category Utils | ||
| * @param {ILoggerLike} newLogger - logger to be used | ||
| * @since v0.2.18 | ||
| */ | ||
| declare function setLogger(newLogger: ILoggerLike): void; | ||
| /** | ||
| * Get current logger instance | ||
| * @category Utils | ||
| * @returns {ILoggerLike | undefined} - current logger | ||
| * @since v0.5.9 | ||
| */ | ||
| declare function getLogger(): ILoggerLike | undefined; | ||
| /** | ||
| * resolve logger: undefined = global logger, null = no logger else it's ILoggerLike | ||
| * @param {ILoggerLike | undefined | null} logger - logger to resolve | ||
| * @category Utils | ||
| * @returns {ILoggerLike | undefined} - resolved logger | ||
| * @since v0.5.9 | ||
| */ | ||
| declare function resolveLogger(logger: undefined | null | ILoggerLike): ILoggerLike | undefined; | ||
| //#endregion | ||
| //#region src/parsers/arrayParser.d.ts | ||
| /** | ||
| * Build parser for array of values | ||
| * @template Input - Type of input | ||
| * @template Output - Type of output | ||
| * @param {IConfigParser<Input, Output>} parse parser for the array values | ||
| * @param {string} separator separator for the array values, defaults to ';' | ||
| * @param {TypeGuardValidate<Output> | undefined} validate optional post validation | ||
| * @returns {IConfigParser<Output[], Input[]>} Parser for array of values | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function arrayParser<Input, Output>(parse: IConfigParser<Input, Output>, separator?: string, validate?: TypeGuardValidate<Output>): IConfigParser<Input[], Output[]>; | ||
| //#endregion | ||
| //#region src/parsers/bigIntParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to bigint | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<bigint, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function bigIntParser<Output extends bigint = bigint>(validate?: TypeGuardValidate<Output>): IConfigParser<bigint, Output>; | ||
| //#endregion | ||
| //#region src/parsers/booleanParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * | ||
| * supports the following string ___true___ values: | ||
| * | ||
| * ```['true', '1', 'yes', 'y', 'on']``` | ||
| * | ||
| * supports the following string ___false___ values: | ||
| * | ||
| * ```['false', '0', 'no', 'n', 'off']``` | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<boolean, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function booleanParser<Output extends boolean = boolean>(validate?: TypeGuardValidate<Output>): IConfigParser<boolean, Output>; | ||
| //#endregion | ||
| //#region src/parsers/floatParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<number, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function floatParser<Output extends number = number>(validate?: TypeGuardValidate<Output>): IConfigParser<number, Output>; | ||
| //#endregion | ||
| //#region src/parsers/integerParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<number, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function integerParser<Output extends number = number>(validate?: TypeGuardValidate<Output>): IConfigParser<number, Output>; | ||
| //#endregion | ||
| //#region src/parsers/JsonConfigParser.d.ts | ||
| /** | ||
| * JsonConfigParserOptions is the interface for JsonConfigParser options | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| * @template Out - the type of the output object | ||
| */ | ||
| type JsonConfigParserOptions<Out extends Record<string, unknown>> = { | ||
@@ -855,20 +1202,20 @@ validate?: ValidateCallback<object, Out>; /** keys to hide or partially hide */ | ||
| /** | ||
| * Config parser to parse JSON string as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new JsonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, object>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| * Config parser to parse JSON string as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new JsonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, object>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class JsonConfigParser<Out extends Record<string, unknown>> implements IConfigParser<object, Out> { | ||
@@ -893,141 +1240,16 @@ name: string; | ||
| /** | ||
| * Build a string record from the given data | ||
| * @param {unknown} data - to be validated as object | ||
| * @returns {object} A record with string values | ||
| */ | ||
| * Build a string record from the given data | ||
| * @param {unknown} data - to be validated as object | ||
| * @returns {object} A record with string values | ||
| */ | ||
| private buildBaseRecord; | ||
| } | ||
| //#endregion | ||
| //#region src/parsers/UrlParser.d.ts | ||
| //#region src/parsers/SemicolonConfigParser.d.ts | ||
| /** | ||
| * Properties for the UrlParser | ||
| * @since v0.2.5 | ||
| */ | ||
| interface UrlParserProps { | ||
| urlSanitize?: boolean; | ||
| } | ||
| /** | ||
| * UrlParser class is used to parse and validate env variables of type URL. | ||
| * @class UrlParser | ||
| * @implements {IConfigParser<URL, URL>} | ||
| * @category Parsers | ||
| * @since v0.2.5 | ||
| */ | ||
| declare class UrlParser implements IConfigParser<URL, URL> { | ||
| name: string; | ||
| /** | ||
| * Should the username and password be sanitized | ||
| */ | ||
| private urlSanitize; | ||
| /** | ||
| * Create a new UrlParser | ||
| * @param {UrlParserProps} properties - Properties for the UrlParser | ||
| */ | ||
| constructor({ | ||
| urlSanitize | ||
| }?: UrlParserProps); | ||
| parse({ | ||
| value | ||
| }: ParserProps): URL; | ||
| toString(value: URL): string; | ||
| toLogString(value: URL): string; | ||
| /** | ||
| * Build a URL object from a string and sanitize the username and password | ||
| * @param {string} value string to parse | ||
| * @returns {URL} URL object with sanitized username and password | ||
| */ | ||
| private handleUrlSanitize; | ||
| } | ||
| //#endregion | ||
| //#region src/parsers/stringParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to string | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<string, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function stringParser<Output extends string = string>(validate?: TypeGuardValidate<Output>): IConfigParser<string, Output>; | ||
| //#endregion | ||
| //#region src/lib/semicolonUtils.d.ts | ||
| /** | ||
| * Parse a semicolon separated string into a config object | ||
| * @param {string} config Semicolon separated string | ||
| * @param {boolean} [keepCase] Keep the case of the keys, default true | ||
| * @returns {Record<string, string>} Config object | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * parseSemicolonConfig('a=b;c=d') // {a: 'b', c: 'd'} | ||
| */ | ||
| declare function parseSemicolonConfig(config: string, keepCase?: boolean): Record<string, string>; | ||
| /** | ||
| * Stringify a config object to a semicolon separated string | ||
| * @param {Record<string, string>} config Object to stringify | ||
| * @param {boolean} [uriEncode] Use URI encoding for string outputs | ||
| * @returns {string} Stringified config | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * stringifySemicolonConfig({a: 'b', c: 'd'}) // 'a=b;c=d' | ||
| */ | ||
| declare function stringifySemicolonConfig(config: Record<string, unknown>, uriEncode?: boolean): string; | ||
| /** | ||
| * Stringify a config object to a semicolon separated string for logging | ||
| * @template Out - Type of output | ||
| * @param {Record<string, string>} config Object to stringify | ||
| * @param {ShowValueType} showProtectedKeys How to show protected keys | ||
| * @param {string[]} protectedKeys list of protected keys | ||
| * @returns {string} Stringified config | ||
| * @category Utils | ||
| * @since v1.0.0 | ||
| * @example | ||
| * logStringifySemicolonConfig({a: 'b', c: 'd'}) // 'a=b;c=d' | ||
| */ | ||
| declare function logStringifySemicolonConfig<Out extends Record<string, unknown>>(config: Out, showProtectedKeys: ShowValueType | undefined, protectedKeys: Set<keyof Out>): string; | ||
| //#endregion | ||
| //#region src/lib/objectUtils.d.ts | ||
| /** | ||
| * validate if a value is a valid object | ||
| * @param {unknown} value - value to validate | ||
| * @returns {value is Record<string, unknown>} - true if value is a valid object | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function isValidObject(value: unknown): value is Record<string, unknown>; | ||
| /** | ||
| * Convert an object to a string value object | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Record<string, string | undefined>} - object with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildStringObject(obj: Record<string, unknown>): Record<string, string>; | ||
| /** | ||
| * Convert an object to a Map<string, string> | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Map<string, string>} - Map with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function buildStringMap(obj: Record<string, unknown>): Map<string, string>; | ||
| /** | ||
| * Apply a Record<string, string> to a Map<string, string> | ||
| * @param {Record<string, string | undefined>} obj - object to apply | ||
| * @param {Map<string, string>} target - Map to apply to | ||
| * @returns {Map<string, string>} - target with updates | ||
| * @since v0.2.5 | ||
| */ | ||
| declare function applyStringMap(obj: Record<string, string | undefined>, target: Map<string, string>): Map<string, string>; | ||
| //#endregion | ||
| //#region src/lib/seenUtils.d.ts | ||
| /** | ||
| * Function to check if we have seen a value before and update the seenMap | ||
| * @param {Map<string, string>} seenMap - Map of seen values | ||
| * @param {string} key - key to check | ||
| * @param {string | undefined} value - value to check | ||
| * @returns {boolean} - true if already seen value, false if not | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function handleSeen(seenMap: Map<string, string>, key: string, value: string | undefined): boolean; | ||
| //#endregion | ||
| //#region src/parsers/SemicolonConfigParser.d.ts | ||
| * SemicolonConfigParserOptions is the interface for SemicolonConfigParser options | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| * @template OutType - the type of the output object | ||
| */ | ||
| interface SemicolonConfigParserOptions<OutType extends Record<string, unknown> = Record<string, unknown>> { | ||
@@ -1043,20 +1265,20 @@ validate?: ValidateCallback<Record<string, string>, OutType>; | ||
| /** | ||
| * Config parser to parse semicolon separated string key=value pairs as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses 'foo=bar;baz=qux;secret=secret' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new SemicolonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, Record<string, string>>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| * Config parser to parse semicolon separated string key=value pairs as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses 'foo=bar;baz=qux;secret=secret' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new SemicolonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, Record<string, string>>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare class SemicolonConfigParser<Out extends Record<string, unknown> = Record<string, unknown>> implements IConfigParser<Record<string, string>, Out> { | ||
@@ -1084,85 +1306,71 @@ name: string; | ||
| //#endregion | ||
| //#region src/parsers/booleanParser.d.ts | ||
| //#region src/parsers/stringParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * | ||
| * supports the following string ___true___ values: | ||
| * | ||
| * ```['true', '1', 'yes', 'y', 'on']``` | ||
| * | ||
| * supports the following string ___false___ values: | ||
| * | ||
| * ```['false', '0', 'no', 'n', 'off']``` | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<boolean, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function booleanParser<Output extends boolean = boolean>(validate?: TypeGuardValidate<Output>): IConfigParser<boolean, Output>; | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to string | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<string, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function stringParser<Output extends string = string>(validate?: TypeGuardValidate<Output>): IConfigParser<string, Output>; | ||
| //#endregion | ||
| //#region src/parsers/floatParser.d.ts | ||
| //#region src/parsers/UrlParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<number, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function floatParser<Output extends number = number>(validate?: TypeGuardValidate<Output>): IConfigParser<number, Output>; | ||
| //#endregion | ||
| //#region src/parsers/integerParser.d.ts | ||
| * Properties for the UrlParser | ||
| * @since v0.2.5 | ||
| */ | ||
| interface UrlParserProps { | ||
| urlSanitize?: boolean; | ||
| } | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to number | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<number, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function integerParser<Output extends number = number>(validate?: TypeGuardValidate<Output>): IConfigParser<number, Output>; | ||
| * UrlParser class is used to parse and validate env variables of type URL. | ||
| * @class UrlParser | ||
| * @implements {IConfigParser<URL, URL>} | ||
| * @category Parsers | ||
| * @since v0.2.5 | ||
| */ | ||
| declare class UrlParser implements IConfigParser<URL, URL> { | ||
| name: string; | ||
| /** | ||
| * Should the username and password be sanitized | ||
| */ | ||
| private urlSanitize; | ||
| /** | ||
| * Create a new UrlParser | ||
| * @param {UrlParserProps} properties - Properties for the UrlParser | ||
| */ | ||
| constructor({ | ||
| urlSanitize | ||
| }?: UrlParserProps); | ||
| parse({ | ||
| value | ||
| }: ParserProps): URL; | ||
| toString(value: URL): string; | ||
| toLogString(value: URL): string; | ||
| /** | ||
| * Build a URL object from a string and sanitize the username and password | ||
| * @param {string} value string to parse | ||
| * @returns {URL} URL object with sanitized username and password | ||
| */ | ||
| private handleUrlSanitize; | ||
| } | ||
| //#endregion | ||
| //#region src/parsers/arrayParser.d.ts | ||
| /** | ||
| * Build parser for array of values | ||
| * @template Input - Type of input | ||
| * @template Output - Type of output | ||
| * @param {IConfigParser<Input, Output>} parse parser for the array values | ||
| * @param {string} separator separator for the array values, defaults to ';' | ||
| * @param {TypeGuardValidate<Output> | undefined} validate optional post validation | ||
| * @returns {IConfigParser<Output[], Input[]>} Parser for array of values | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function arrayParser<Input, Output>(parse: IConfigParser<Input, Output>, separator?: string, validate?: TypeGuardValidate<Output>): IConfigParser<Input[], Output[]>; | ||
| //#endregion | ||
| //#region src/parsers/bigIntParser.d.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to bigint | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<bigint, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| declare function bigIntParser<Output extends bigint = bigint>(validate?: TypeGuardValidate<Output>): IConfigParser<bigint, Output>; | ||
| //#endregion | ||
| //#region src/VariableError.d.ts | ||
| /** | ||
| * Custom error class for variable errors. | ||
| * @class VariableError | ||
| * @augments Error | ||
| * @param {string} message - The error message. | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| * @example | ||
| * throw new VariableError('Variable not found'); | ||
| */ | ||
| * Custom error class for variable errors. | ||
| * @class VariableError | ||
| * @augments Error | ||
| * @param {string} message - The error message. | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| * @example | ||
| * throw new VariableError('Variable not found'); | ||
| */ | ||
| declare class VariableError extends Error { | ||
| /** | ||
| * Create a new VariableError | ||
| * @param {string} message - The error message | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| * Create a new VariableError | ||
| * @param {string} message - The error message | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| constructor(message: string, options?: ErrorOptions); | ||
@@ -1173,189 +1381,20 @@ } | ||
| /** | ||
| * Custom error class for variable lookup errors. | ||
| * @class VariableLookupError | ||
| * @augments VariableError | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| */ | ||
| * Custom error class for variable lookup errors. | ||
| * @class VariableLookupError | ||
| * @augments VariableError | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| */ | ||
| declare class VariableLookupError extends VariableError { | ||
| readonly variableKey: string; | ||
| /** | ||
| * Create a new VariableLookupError | ||
| * @param {string} variableKey - The variable key. | ||
| * @param {string} message - The error message. | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| * Create a new VariableLookupError | ||
| * @param {string} variableKey - The variable key. | ||
| * @param {string} message - The error message. | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| constructor(variableKey: string, message: string, options?: ErrorOptions); | ||
| } | ||
| //#endregion | ||
| //#region src/ConfigMap.d.ts | ||
| /** | ||
| * TypeValueRecords | ||
| * @template T - type of config map | ||
| * @since v0.6.0 | ||
| */ | ||
| type TypeValueRecords<T> = Record<keyof T, LoaderTypeValueStrict<T[keyof T]>>; | ||
| /** | ||
| * ConfigMap | ||
| * @example | ||
| * type ConfigEnv = { | ||
| * PORT: number; | ||
| * HOST: string; | ||
| * DEBUG: boolean; | ||
| * URL: URL; | ||
| * }; | ||
| * const config = new ConfigMap<ConfigEnv>({ | ||
| * DEBUG: {loaders: [env()], parser: booleanParser, defaultValue: false}, | ||
| * HOST: {loaders: [env()], parser: stringParser, defaultValue: 'localhost'}, | ||
| * PORT: {loaders: [env()], parser: integerParser, defaultValue: 3000}, | ||
| * URL: {loaders: [env()], parser: new UrlParser({urlSanitize: true}), defaultValue: new URL('http://localhost:3000')}, | ||
| * }); | ||
| * console.log('port', await config.get('PORT')); | ||
| * @template Data - type of config map | ||
| * @since v1.1.0 | ||
| */ | ||
| declare class ConfigMap<Data extends Record<string, unknown>> implements ISetOptionalLogger { | ||
| private schema; | ||
| private options; | ||
| private loaders; | ||
| /** | ||
| * ConfigMap constructor | ||
| * @param {EnvMapSchema<Data>} schema - schema of config map | ||
| * @param {Iterable<IConfigLoader>} loaders - iterable of config loaders | ||
| * @param {ConfigOptions} options - optional config options (logger, namespace) | ||
| */ | ||
| constructor(schema: EnvMapSchema<Data>, loaders: Loadable<Iterable<IConfigLoader>>, options?: ConfigOptions); | ||
| /** | ||
| * Set logger value | ||
| * @param {ILoggerLike | undefined} logger - logger like object | ||
| */ | ||
| setLogger(logger: ILoggerLike | undefined): void; | ||
| /** | ||
| * get env object from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: LoaderTypeValue<number> = await config.getObject('PORT'); | ||
| * console.log(valueObject.type, valueObject.value); // 'env', 3000 | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getObject<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<LoaderTypeValueStrict<Data[Key]>>; | ||
| /** | ||
| * get env object from config map as Result | ||
| * @returns {Promise<Result<TypeValueRecords<Data>>>} Result Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: Result<LoaderTypeValue<number>> = await config.getObjectResult('PORT'); | ||
| * if (valueObject.isOk()) { | ||
| * const {type, value} = valueObject.ok(); | ||
| * console.log(type, value); // 'env', 3000 | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getObjectResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<LoaderTypeValueStrict<Data[Key]>>>; | ||
| /** | ||
| * get env value from config map | ||
| * @returns {Promise<Data[Key]>} Promise of value or undefined | ||
| * @example | ||
| * const port: number = await config.get('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| get<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<Data[Key]>; | ||
| /** | ||
| * get env value as string from config map | ||
| * @returns {Promise<string | undefined>} Promise of string value or undefined | ||
| * @example | ||
| * const port: string = await config.getString('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getString<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<undefined extends Data[Key] ? string | undefined : string>; | ||
| /** | ||
| * get env value from config map as Result | ||
| * @returns {Promise<Result<Data[Key]>>} Result Promise of value or undefined | ||
| * @example | ||
| * const port: Result<number> = await config.getResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<Data[Key]>>; | ||
| /** | ||
| * get env value as string from config map as Result | ||
| * @returns {Promise<Result<string | undefined>>} Result Promise of string value or undefined | ||
| * @example | ||
| * const port: Result<string> = await config.getStringResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getStringResult<Key extends keyof Data = keyof Data>(key: Key, encodeOptions?: EncodeOptions): Promise<IResult<undefined extends Data[Key] ? string | undefined : string>>; | ||
| /** | ||
| * get all env value objects from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of all values | ||
| * @example | ||
| * const values: TypeValueRecords<Data> = await config.getAll(); | ||
| * console.log(values.PORT.type, values.PORT.value); // 'env', 3000 | ||
| */ | ||
| getAllObjects(): Promise<TypeValueRecords<Data>>; | ||
| /** | ||
| * get all env values from config map | ||
| * @returns {Promise<Data>} Promise of all values | ||
| * @example | ||
| * const values: Data = await config.getAllValues(); | ||
| * console.log('PORT', values.PORT); // 3000 (number) | ||
| */ | ||
| getAllValues(): Promise<Data>; | ||
| /** | ||
| * get all env values from config map as string | ||
| * @returns {Promise<Record<keyof Data, string>>} Promise of all values as string | ||
| * @example | ||
| * const values: Record<keyof Data, string> = await config.getAllStringValues(); | ||
| * console.log('PORT', values.PORT); // '3000' (string) | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| getAllStringValues(encodeOptions?: EncodeOptions): Promise<Record<keyof Data, string>>; | ||
| /** | ||
| * Validate all env values from config map, expect to throw error if error exists | ||
| * @param {(data: Data) => void} callback callback function | ||
| */ | ||
| validateAll(callback: (data: Data) => void): Promise<void>; | ||
| /** | ||
| * run lookup to all keys and return all promises | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<[keyof Data, LoaderTypeValueStrict<Data[keyof Data]>][]>} Promise of all values | ||
| */ | ||
| private getAllPromises; | ||
| } | ||
| //#endregion | ||
| //#region src/logger.d.ts | ||
| /** | ||
| * Set the logger to be used by the module | ||
| * @category Utils | ||
| * @param {ILoggerLike} newLogger - logger to be used | ||
| * @since v0.2.18 | ||
| */ | ||
| declare function setLogger(newLogger: ILoggerLike): void; | ||
| /** | ||
| * Get current logger instance | ||
| * @category Utils | ||
| * @returns {ILoggerLike | undefined} - current logger | ||
| * @since v0.5.9 | ||
| */ | ||
| declare function getLogger(): ILoggerLike | undefined; | ||
| /** | ||
| * resolve logger: undefined = global logger, null = no logger else it's ILoggerLike | ||
| * @param {ILoggerLike | undefined | null} logger - logger to resolve | ||
| * @category Utils | ||
| * @returns {ILoggerLike | undefined} - resolved logger | ||
| * @since v0.5.9 | ||
| */ | ||
| declare function resolveLogger(logger: undefined | null | ILoggerLike): ILoggerLike | undefined; | ||
| //#endregion | ||
| export { ConfigLoader, ConfigLoaderEventMap, ConfigMap, ConfigOptions, ConfigRequest, EncodeOptions, EnvConfigLoader, EnvMapSchema, FetchConfigLoader, FetchConfigLoaderOptions, FormatParameters, IConfigLoader, IConfigLoaderProps, IConfigParser, IMemoryConfigLoaderProps, IRequestCache, ISwitchLoaderProps, InferOverrideKeyMap, JsonConfigParser, JsonConfigParserOptions, LoaderTypeValue, LoaderTypeValueStrict, LoaderValue, LoaderValueResult, MapConfigLoader, MemoryConfigLoader, OptionalEnvEntry, OverrideKeyMap, ParserProps, PartialHiddenValueStringType, PostValidateProps, PreValidateProps, ReactEnvConfigLoader, RecordConfigLoader, RequestNotReady, RequiredEnvEntry, RequiredUndefinedThrowEntry, SemicolonConfigParser, SemicolonConfigParserOptions, ShowValueType, SolvedConfigOptions, SwitchConfigMap, SwitchLoader, TypeGuardValidate, TypeValueRecords, UrlParser, UrlParserProps, ValidateCallback, VariableError, VariableLookupError, applyStringMap, arrayParser, bigIntParser, booleanParser, buildHiddenAsterisksValueString, buildHiddenValue, buildOptions, buildPartialHiddenValueString, buildStringMap, buildStringObject, clearDefaultValueSeenMap, createRequestNotReady, floatParser, getConfigObject, getConfigObjectResult, getConfigVariable, getConfigVariableResult, getLogger, handleSeen, integerParser, isRequestNotReadMessage, isValidObject, logStringifySemicolonConfig, parseSemicolonConfig, printValue, resolveLogger, setLogger, stringParser, stringifySemicolonConfig, urlSanitize$1 as urlSanitize }; | ||
| //# sourceMappingURL=index.d.mts.map |
+630
-605
@@ -0,31 +1,5 @@ | ||
| import { Err, Ok } from "@luolapeikko/result-option"; | ||
| import { ErrorCore, LoadableCore } from "@luolapeikko/ts-common"; | ||
| import { Err, Ok } from "@luolapeikko/result-option"; | ||
| import { EventEmitter } from "events"; | ||
| //#region src/types/RequestNotReady.ts | ||
| /** | ||
| * Type guard for RequestNotReady | ||
| * @param {unknown} obj - object to check if it is a RequestNotReady payload | ||
| * @returns {boolean} boolean indicating if the object is a RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| function isRequestNotReadMessage(obj) { | ||
| return typeof obj === "object" && obj !== null && "_type" in obj && obj._type === "RequestNotReady" && "message" in obj && typeof obj.message === "string"; | ||
| } | ||
| /** | ||
| * function to create a RequestNotReady payload to indicate that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @param {string} message - reason why the request is not ready yet | ||
| * @returns {RequestNotReady} RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| function createRequestNotReady(message) { | ||
| return { | ||
| message, | ||
| _type: "RequestNotReady" | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/logger.ts | ||
@@ -295,2 +269,12 @@ let logger; | ||
| /** | ||
| * Get result from loader | ||
| * @param {IConfigLoader} loader - loader to use | ||
| * @param {string} rootKey - key of variable | ||
| * @returns {Promise<LoaderValueResult | undefined>} - result of loader | ||
| */ | ||
| async function getResult(loader, rootKey) { | ||
| if (await loader.isLoaderDisabled()) return; | ||
| return await loader.getLoaderResult(rootKey); | ||
| } | ||
| /** | ||
| * handle function for loader | ||
@@ -310,4 +294,3 @@ * @template Input - Type of input value | ||
| try { | ||
| if (await loader.isLoaderDisabled()) return; | ||
| const result = await loader.getLoaderResult(rootKey); | ||
| const result = await getResult(loader, rootKey); | ||
| if (!result) return; | ||
@@ -322,4 +305,4 @@ const { value, path, seen } = result; | ||
| key: rootKey, | ||
| value, | ||
| loader | ||
| loader, | ||
| value | ||
| }); | ||
@@ -336,4 +319,4 @@ } catch (err) { | ||
| key: rootKey, | ||
| value, | ||
| loader | ||
| loader, | ||
| value | ||
| }); | ||
@@ -350,4 +333,4 @@ } catch (err) { | ||
| key: rootKey, | ||
| value: rawOutput, | ||
| loader | ||
| loader, | ||
| value: rawOutput | ||
| }); | ||
@@ -434,2 +417,243 @@ if (validateData) output = validateData; | ||
| //#endregion | ||
| //#region src/VariableLookupError.ts | ||
| /** | ||
| * Custom error class for variable lookup errors. | ||
| * @class VariableLookupError | ||
| * @augments VariableError | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| */ | ||
| var VariableLookupError = class extends VariableError { | ||
| variableKey; | ||
| /** | ||
| * Create a new VariableLookupError | ||
| * @param {string} variableKey - The variable key. | ||
| * @param {string} message - The error message. | ||
| * @param {ErrorOptions} [options] - The error options | ||
| */ | ||
| constructor(variableKey, message, options) { | ||
| super(message, options); | ||
| this.variableKey = variableKey; | ||
| this.name = "VariableLookupError"; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ConfigMap.ts | ||
| /** | ||
| * ConfigMap | ||
| * @example | ||
| * type ConfigEnv = { | ||
| * PORT: number; | ||
| * HOST: string; | ||
| * DEBUG: boolean; | ||
| * URL: URL; | ||
| * }; | ||
| * const env = new EnvConfigLoader(); | ||
| * const config = new ConfigMap<ConfigEnv>( | ||
| * { | ||
| * DEBUG: {defaultValue: false, parser: booleanParser()}, | ||
| * HOST: {defaultValue: 'localhost', parser: stringParser()}, | ||
| * PORT: {defaultValue: 3000, parser: integerParser()}, | ||
| * URL: {defaultValue: new URL('http://localhost:3000'), parser: new UrlParser({urlSanitize: true})}, | ||
| * }, | ||
| * [env], | ||
| * ); | ||
| * console.log('port', await config.get('PORT')); | ||
| * @template Data - type of config map | ||
| * @since v1.1.0 | ||
| */ | ||
| var ConfigMap = class { | ||
| schema; | ||
| options; | ||
| loaders; | ||
| /** | ||
| * ConfigMap constructor | ||
| * @param {EnvMapSchema<Data>} schema - schema of config map | ||
| * @param {Iterable<IConfigLoader>} loaders - iterable of config loaders | ||
| * @param {ConfigOptions} options - optional config options (logger, namespace) | ||
| */ | ||
| constructor(schema, loaders, options = { | ||
| logger: void 0, | ||
| namespace: void 0 | ||
| }) { | ||
| this.schema = schema; | ||
| this.options = options; | ||
| this.loaders = loaders; | ||
| } | ||
| /** | ||
| * Set logger value | ||
| * @param {ILoggerLike | undefined} logger - logger like object | ||
| */ | ||
| setLogger(logger) { | ||
| this.options.logger = logger; | ||
| } | ||
| /** | ||
| * get env object from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: LoaderTypeValue<number> = await config.getObject('PORT'); | ||
| * console.log(valueObject.type, valueObject.value); // 'env', 3000 | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getObject(key, encodeOptions) { | ||
| if (typeof key !== "string") throw new VariableError(`ConfigMap key ${String(key)} is not a string`); | ||
| const entry = this.schema[key]; | ||
| if (!entry) throw new VariableLookupError(key, `ConfigMap key ${String(key)} not found in config map`); | ||
| const { parser, defaultValue, params, undefinedThrowsError, undefinedErrorMessage } = entry; | ||
| const configObject = await getConfigObject(key, Array.from(await LoadableCore.resolve(this.loaders)), parser, defaultValue, params, this.options, encodeOptions); | ||
| if (undefinedThrowsError && configObject.value === void 0) { | ||
| buildOptions(this.options).logger?.info(`ConfigMap key ${String(key)} is undefined (expect to throw error)`); | ||
| throw new VariableError(undefinedErrorMessage ?? `ConfigMap key ${String(key)} is undefined`); | ||
| } | ||
| return configObject; | ||
| } | ||
| /** | ||
| * get env object from config map as Result | ||
| * @returns {Promise<Result<TypeValueRecords<Data>>>} Result Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: Result<LoaderTypeValue<number>> = await config.getObjectResult('PORT'); | ||
| * if (valueObject.isOk()) { | ||
| * const {type, value} = valueObject.ok(); | ||
| * console.log(type, value); // 'env', 3000 | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getObjectResult(key, encodeOptions) { | ||
| try { | ||
| return Ok(await this.getObject(key, encodeOptions)); | ||
| } catch (err) { | ||
| return Err(err); | ||
| } | ||
| } | ||
| /** | ||
| * get env value from config map | ||
| * @returns {Promise<Data[Key]>} Promise of value or undefined | ||
| * @example | ||
| * const port: number = await config.get('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async get(key, encodeOptions) { | ||
| return (await this.getObject(key, encodeOptions)).value; | ||
| } | ||
| /** | ||
| * get env value as string from config map | ||
| * @returns {Promise<string | undefined>} Promise of string value or undefined | ||
| * @example | ||
| * const port: string = await config.getString('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getString(key, encodeOptions) { | ||
| return (await this.getObject(key, encodeOptions)).stringValue; | ||
| } | ||
| /** | ||
| * get env value from config map as Result | ||
| * @returns {Promise<Result<Data[Key]>>} Result Promise of value or undefined | ||
| * @example | ||
| * const port: Result<number> = await config.getResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getResult(key, encodeOptions) { | ||
| try { | ||
| return Ok(await this.get(key, encodeOptions)); | ||
| } catch (err) { | ||
| return Err(err); | ||
| } | ||
| } | ||
| /** | ||
| * get env value as string from config map as Result | ||
| * @returns {Promise<Result<string | undefined>>} Result Promise of string value or undefined | ||
| * @example | ||
| * const port: Result<string> = await config.getStringResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getStringResult(key, encodeOptions) { | ||
| try { | ||
| return Ok(await this.getString(key, encodeOptions)); | ||
| } catch (err) { | ||
| return Err(err); | ||
| } | ||
| } | ||
| /** | ||
| * get all env value objects from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of all values | ||
| * @example | ||
| * const values: TypeValueRecords<Data> = await config.getAll(); | ||
| * console.log(values.PORT.type, values.PORT.value); // 'env', 3000 | ||
| */ | ||
| async getAllObjects() { | ||
| return (await this.getAllPromises()).reduce((result, [key, value]) => { | ||
| result[key] = value; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * get all env values from config map | ||
| * @returns {Promise<Data>} Promise of all values | ||
| * @example | ||
| * const values: Data = await config.getAllValues(); | ||
| * console.log('PORT', values.PORT); // 3000 (number) | ||
| */ | ||
| async getAllValues() { | ||
| return (await this.getAllPromises()).reduce((result, [key, value]) => { | ||
| result[key] = value.value; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * get all env values from config map as string | ||
| * @returns {Promise<Record<keyof Data, string>>} Promise of all values as string | ||
| * @example | ||
| * const values: Record<keyof Data, string> = await config.getAllStringValues(); | ||
| * console.log('PORT', values.PORT); // '3000' (string) | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getAllStringValues(encodeOptions) { | ||
| return (await this.getAllPromises(encodeOptions)).reduce((result, [key, value]) => { | ||
| result[key] = value.stringValue; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * Validate all env values from config map, expect to throw error if error exists | ||
| * @param {(data: Data) => void} callback callback function | ||
| */ | ||
| async validateAll(callback) { | ||
| callback(await this.getAllValues()); | ||
| } | ||
| /** | ||
| * run lookup to all keys and return all promises | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<[keyof Data, LoaderTypeValueStrict<Data[keyof Data]>][]>} Promise of all values | ||
| */ | ||
| getAllPromises(encodeOptions) { | ||
| return Promise.all(Object.keys(this.schema).map(async (key) => { | ||
| return [key, await this.getObject(key, encodeOptions)]; | ||
| })); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/getConfigObjectResult.ts | ||
| async function getConfigObjectResult(rootKey, loaders, parser, defaultValueLoadable, params, options) { | ||
| try { | ||
| return Ok(await getConfigObject(rootKey, loaders, parser, defaultValueLoadable, params, options)); | ||
| } catch (err) { | ||
| return Err(err); | ||
| } | ||
| } | ||
| //#endregion | ||
| //#region src/getConfigVariable.ts | ||
@@ -451,10 +675,66 @@ async function getConfigVariable(rootKey, loaders, parser, defaultValueLoadable, params, options, encodeOptions) { | ||
| //#endregion | ||
| //#region src/getConfigObjectResult.ts | ||
| async function getConfigObjectResult(rootKey, loaders, parser, defaultValueLoadable, params, options) { | ||
| try { | ||
| return Ok(await getConfigObject(rootKey, loaders, parser, defaultValueLoadable, params, options)); | ||
| } catch (err) { | ||
| return Err(err); | ||
| } | ||
| //#region src/lib/objectUtils.ts | ||
| /** | ||
| * validate if a value is a valid object | ||
| * @param {unknown} value - value to validate | ||
| * @returns {value is Record<string, unknown>} - true if value is a valid object | ||
| * @since v0.2.5 | ||
| */ | ||
| function isValidObject(value) { | ||
| return typeof value === "object" && value !== null && !Array.isArray(value); | ||
| } | ||
| /** | ||
| * Check if a value has a toJSON method | ||
| * @param {unknown} value - value to check | ||
| * @returns {value is {toJSON: () => string}} - true if value has a toJSON method | ||
| */ | ||
| function haveToJSON(value) { | ||
| return typeof value === "object" && value !== null && "toJSON" in value; | ||
| } | ||
| /** | ||
| * Stringify a value to a string | ||
| * @param {unknown} value - value to stringify | ||
| * @returns {string} - stringified value | ||
| */ | ||
| function stringifyValue(value) { | ||
| if (isValidObject(value)) return haveToJSON(value) ? value.toJSON() : JSON.stringify(value); | ||
| return String(value); | ||
| } | ||
| /** | ||
| * Convert an object to a string value object | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Record<string, string | undefined>} - object with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| function buildStringObject(obj) { | ||
| return Object.entries(obj).reduce((last, [key, value]) => { | ||
| if (value) last[key] = stringifyValue(value); | ||
| return last; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * Convert an object to a Map<string, string> | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Map<string, string>} - Map with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| function buildStringMap(obj) { | ||
| return Object.entries(obj).reduce((acc, [key, value]) => { | ||
| if (value) acc.set(key, stringifyValue(value)); | ||
| return acc; | ||
| }, /* @__PURE__ */ new Map()); | ||
| } | ||
| /** | ||
| * Apply a Record<string, string> to a Map<string, string> | ||
| * @param {Record<string, string | undefined>} obj - object to apply | ||
| * @param {Map<string, string>} target - Map to apply to | ||
| * @returns {Map<string, string>} - target with updates | ||
| * @since v0.2.5 | ||
| */ | ||
| function applyStringMap(obj, target) { | ||
| return Object.entries(obj).reduce((acc, [key, value]) => { | ||
| if (value) acc.set(key, value); | ||
| return acc; | ||
| }, target); | ||
| } | ||
@@ -536,68 +816,2 @@ //#endregion | ||
| //#endregion | ||
| //#region src/lib/objectUtils.ts | ||
| /** | ||
| * validate if a value is a valid object | ||
| * @param {unknown} value - value to validate | ||
| * @returns {value is Record<string, unknown>} - true if value is a valid object | ||
| * @since v0.2.5 | ||
| */ | ||
| function isValidObject(value) { | ||
| return typeof value === "object" && value !== null && !Array.isArray(value); | ||
| } | ||
| /** | ||
| * Check if a value has a toJSON method | ||
| * @param {unknown} value - value to check | ||
| * @returns {value is {toJSON: () => string}} - true if value has a toJSON method | ||
| */ | ||
| function haveToJSON(value) { | ||
| return typeof value === "object" && value !== null && "toJSON" in value; | ||
| } | ||
| /** | ||
| * Stringify a value to a string | ||
| * @param {unknown} value - value to stringify | ||
| * @returns {string} - stringified value | ||
| */ | ||
| function stringifyValue(value) { | ||
| if (isValidObject(value)) return haveToJSON(value) ? value.toJSON() : JSON.stringify(value); | ||
| return String(value); | ||
| } | ||
| /** | ||
| * Convert an object to a string value object | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Record<string, string | undefined>} - object with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| function buildStringObject(obj) { | ||
| return Object.entries(obj).reduce((last, [key, value]) => { | ||
| if (value) last[key] = stringifyValue(value); | ||
| return last; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * Convert an object to a Map<string, string> | ||
| * @param {Record<string, unknown>} obj - object to convert | ||
| * @returns {Map<string, string>} - Map with string values | ||
| * @since v0.2.5 | ||
| */ | ||
| function buildStringMap(obj) { | ||
| return Object.entries(obj).reduce((acc, [key, value]) => { | ||
| if (value) acc.set(key, stringifyValue(value)); | ||
| return acc; | ||
| }, /* @__PURE__ */ new Map()); | ||
| } | ||
| /** | ||
| * Apply a Record<string, string> to a Map<string, string> | ||
| * @param {Record<string, string | undefined>} obj - object to apply | ||
| * @param {Map<string, string>} target - Map to apply to | ||
| * @returns {Map<string, string>} - target with updates | ||
| * @since v0.2.5 | ||
| */ | ||
| function applyStringMap(obj, target) { | ||
| return Object.entries(obj).reduce((acc, [key, value]) => { | ||
| if (value) acc.set(key, value); | ||
| return acc; | ||
| }, target); | ||
| } | ||
| //#endregion | ||
| //#region src/loaders/ConfigLoader.ts | ||
@@ -613,5 +827,7 @@ /** | ||
| var ConfigLoader = class extends EventEmitter { | ||
| options; | ||
| overrideKeys; | ||
| valueSeen = /* @__PURE__ */ new Map(); | ||
| constructor(props = {}, overrideKeys = {}) { | ||
| super(); | ||
| this.valueSeen = /* @__PURE__ */ new Map(); | ||
| this.options = props; | ||
@@ -624,13 +840,13 @@ this.overrideKeys = overrideKeys; | ||
| return { | ||
| value: loaderValue.value, | ||
| path: loaderValue.path, | ||
| seen: handleSeen(this.valueSeen, lookupKey, loaderValue.value) | ||
| seen: handleSeen(this.valueSeen, lookupKey, loaderValue.value), | ||
| value: loaderValue.value | ||
| }; | ||
| } | ||
| async isLoaderDisabled() { | ||
| const loadableDisabled = (await this.getOptions()).disabled; | ||
| const loadableDisabled = (await this.getOptions()).disabled ?? false; | ||
| return LoadableCore.resolve(loadableDisabled); | ||
| } | ||
| setDisabled(disabled) { | ||
| return this.setOption("disabled", disabled); | ||
| this.setOption("disabled", disabled); | ||
| } | ||
@@ -659,41 +875,2 @@ /** | ||
| //#endregion | ||
| //#region src/loaders/RecordConfigLoader.ts | ||
| /** | ||
| * RecordConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| */ | ||
| var RecordConfigLoader = class extends ConfigLoader { | ||
| constructor(..._args) { | ||
| super(..._args); | ||
| this._isLoaded = false; | ||
| } | ||
| /** | ||
| * reloads the data | ||
| */ | ||
| async reload() { | ||
| this.valueSeen.clear(); | ||
| await this.loadData(); | ||
| } | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} - true if the data is loaded, false otherwise | ||
| */ | ||
| isLoaded() { | ||
| return this._isLoaded; | ||
| } | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async loadData() { | ||
| this.dataPromise = this.handleData(); | ||
| await this.dataPromise; | ||
| this.emit("updated"); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/loaders/EnvConfigLoader.ts | ||
@@ -709,11 +886,8 @@ /** | ||
| var EnvConfigLoader = class extends ConfigLoader { | ||
| constructor(..._args) { | ||
| super(..._args); | ||
| this.loaderType = "env"; | ||
| this.defaultOptions = { disabled: false }; | ||
| } | ||
| loaderType = "env"; | ||
| defaultOptions = { disabled: false }; | ||
| handleLoaderValue(lookupKey) { | ||
| return { | ||
| value: process.env[lookupKey], | ||
| path: `process.env.${lookupKey}` | ||
| path: `process.env.${lookupKey}`, | ||
| value: process.env[lookupKey] | ||
| }; | ||
@@ -724,25 +898,26 @@ } | ||
| //#endregion | ||
| //#region src/loaders/ReactEnvConfigLoader.ts | ||
| //#region src/types/RequestNotReady.ts | ||
| /** | ||
| * React env loader class is used to load env variables from process.env.REACT_APP_* | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {Partial<OverrideMap>} [override] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| * Type guard for RequestNotReady | ||
| * @param {unknown} obj - object to check if it is a RequestNotReady payload | ||
| * @returns {boolean} boolean indicating if the object is a RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| var ReactEnvConfigLoader = class extends ConfigLoader { | ||
| constructor(..._args) { | ||
| super(..._args); | ||
| this.loaderType = "react-env"; | ||
| this.defaultOptions = { disabled: false }; | ||
| } | ||
| handleLoaderValue(lookupKey) { | ||
| const targetKey = `REACT_APP_${lookupKey}`; | ||
| return { | ||
| value: process.env[targetKey], | ||
| path: `process.env.${targetKey}` | ||
| }; | ||
| } | ||
| }; | ||
| function isRequestNotReadMessage(obj) { | ||
| return typeof obj === "object" && obj !== null && "_type" in obj && obj._type === "RequestNotReady" && "message" in obj && typeof obj.message === "string"; | ||
| } | ||
| /** | ||
| * function to create a RequestNotReady payload to indicate that the request is not ready to be loaded yet. (e.g. the user is not logged in) | ||
| * @param {string} message - reason why the request is not ready yet | ||
| * @returns {RequestNotReady} RequestNotReady payload | ||
| * @category Utils | ||
| * @since v0.2.8 | ||
| */ | ||
| function createRequestNotReady(message) { | ||
| return { | ||
| _type: "RequestNotReady", | ||
| message | ||
| }; | ||
| } | ||
@@ -759,7 +934,4 @@ //#endregion | ||
| var MapConfigLoader = class extends ConfigLoader { | ||
| constructor(..._args) { | ||
| super(..._args); | ||
| this._isLoaded = false; | ||
| this.data = /* @__PURE__ */ new Map(); | ||
| } | ||
| _isLoaded = false; | ||
| data = /* @__PURE__ */ new Map(); | ||
| /** | ||
@@ -799,2 +971,15 @@ * clear maps and reloads the data | ||
| var FetchConfigLoader = class extends MapConfigLoader { | ||
| loaderType; | ||
| request; | ||
| path = "undefined"; | ||
| defaultOptions = { | ||
| cache: void 0, | ||
| cacheHitHttpCode: 304, | ||
| disabled: false, | ||
| fetchClient: typeof window === "object" ? fetch.bind(window) : fetch, | ||
| isSilent: false, | ||
| logger: void 0, | ||
| payload: "json", | ||
| validate: void 0 | ||
| }; | ||
| /** | ||
@@ -809,13 +994,2 @@ * Constructor for FetchConfigLoader | ||
| super(options, overrideKeys); | ||
| this.path = "undefined"; | ||
| this.defaultOptions = { | ||
| cache: void 0, | ||
| cacheHitHttpCode: 304, | ||
| disabled: false, | ||
| fetchClient: typeof window === "object" ? fetch.bind(window) : fetch, | ||
| isSilent: false, | ||
| logger: void 0, | ||
| payload: "json", | ||
| validate: void 0 | ||
| }; | ||
| this.request = request; | ||
@@ -830,4 +1004,4 @@ this.loaderType = type; | ||
| return { | ||
| value: this.data.get(lookupKey), | ||
| path: this.path | ||
| path: this.path, | ||
| value: this.data.get(lookupKey) | ||
| }; | ||
@@ -951,3 +1125,3 @@ } | ||
| async getRequest() { | ||
| return typeof this.request === "function" ? this.request() : this.request; | ||
| return await (typeof this.request === "function" ? this.request() : this.request); | ||
| } | ||
@@ -967,8 +1141,10 @@ }; | ||
| var MemoryConfigLoader = class extends ConfigLoader { | ||
| loaderType; | ||
| data; | ||
| defaultOptions = { | ||
| disabled: false, | ||
| logger: void 0 | ||
| }; | ||
| constructor(initialData, options = {}, overrideKeys = {}, type = "memory") { | ||
| super(options, overrideKeys); | ||
| this.defaultOptions = { | ||
| disabled: false, | ||
| logger: void 0 | ||
| }; | ||
| this.data = new Map(Object.entries(initialData)); | ||
@@ -989,4 +1165,4 @@ this.loaderType = type; | ||
| return { | ||
| value: this.data.get(lookupKey), | ||
| path: `key:${lookupKey}` | ||
| path: `key:${lookupKey}`, | ||
| value: this.data.get(lookupKey) | ||
| }; | ||
@@ -997,2 +1173,61 @@ } | ||
| //#endregion | ||
| //#region src/loaders/ReactEnvConfigLoader.ts | ||
| /** | ||
| * React env loader class is used to load env variables from process.env.REACT_APP_* | ||
| * @template OverrideMap - the type of the override key map | ||
| * @param {Partial<OverrideMap>} [override] - optional override key for lookup | ||
| * @returns {IConfigLoader} - IConfigLoader object | ||
| * @category Loaders | ||
| * @since v1.0.0 | ||
| */ | ||
| var ReactEnvConfigLoader = class extends ConfigLoader { | ||
| loaderType = "react-env"; | ||
| defaultOptions = { disabled: false }; | ||
| handleLoaderValue(lookupKey) { | ||
| const targetKey = `REACT_APP_${lookupKey}`; | ||
| return { | ||
| path: `process.env.${targetKey}`, | ||
| value: process.env[targetKey] | ||
| }; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/loaders/RecordConfigLoader.ts | ||
| /** | ||
| * RecordConfigLoader is a class that extends ConfigLoader and adds the ability to reload the data. | ||
| * @template Props - the type of the options for the loader | ||
| * @template OverrideMap - the type of the override key map | ||
| * @since v1.0.0 | ||
| */ | ||
| var RecordConfigLoader = class extends ConfigLoader { | ||
| _isLoaded = false; | ||
| dataPromise; | ||
| /** | ||
| * reloads the data | ||
| */ | ||
| async reload() { | ||
| this.valueSeen.clear(); | ||
| await this.loadData(); | ||
| } | ||
| /** | ||
| * is the data loaded | ||
| * @returns {boolean} - true if the data is loaded, false otherwise | ||
| */ | ||
| isLoaded() { | ||
| return this._isLoaded; | ||
| } | ||
| /** | ||
| * load data from the loader. If the data is loaded successfully | ||
| * an "updated" event will be emitted. | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async loadData() { | ||
| this.dataPromise = this.handleData(); | ||
| await this.dataPromise; | ||
| this.emit("updated"); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/loaders/SwitchLoader.ts | ||
@@ -1015,9 +1250,11 @@ /** | ||
| var SwitchLoader = class extends ConfigLoader { | ||
| loaderType; | ||
| config; | ||
| keys = /* @__PURE__ */ new Set(); | ||
| defaultOptions = { | ||
| disabled: false, | ||
| logger: void 0 | ||
| }; | ||
| constructor(configs, props = {}, type = "switch") { | ||
| super(props); | ||
| this.keys = /* @__PURE__ */ new Set(); | ||
| this.defaultOptions = { | ||
| disabled: false, | ||
| logger: void 0 | ||
| }; | ||
| this.config = configs; | ||
@@ -1044,4 +1281,4 @@ this.loaderType = type; | ||
| if (currentValue) output = { | ||
| value: currentValue, | ||
| path: `switch:${String(key)}:${lookupKey}` | ||
| path: `switch:${String(key)}:${lookupKey}`, | ||
| value: currentValue | ||
| }; | ||
@@ -1057,103 +1294,35 @@ } | ||
| //#endregion | ||
| //#region src/parsers/JsonConfigParser.ts | ||
| //#region src/parsers/arrayParser.ts | ||
| /** | ||
| * Config parser to parse JSON string as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new JsonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, object>} | ||
| * Build parser for array of values | ||
| * @template Input - Type of input | ||
| * @template Output - Type of output | ||
| * @param {IConfigParser<Input, Output>} parse parser for the array values | ||
| * @param {string} separator separator for the array values, defaults to ';' | ||
| * @param {TypeGuardValidate<Output> | undefined} validate optional post validation | ||
| * @returns {IConfigParser<Output[], Input[]>} Parser for array of values | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| var JsonConfigParser = class { | ||
| constructor({ protectedKeys, validate, showProtectedKeys } = {}) { | ||
| this.name = "jsonConfigParser"; | ||
| this.protectedKeys = new Set(protectedKeys); | ||
| this.validate = validate; | ||
| this.showProtectedKeys = showProtectedKeys; | ||
| } | ||
| parse({ value }) { | ||
| return this.buildBaseRecord(JSON.parse(value)); | ||
| } | ||
| async postValidate({ value }) { | ||
| return await this.validate?.(value); | ||
| } | ||
| toString(config) { | ||
| return JSON.stringify(Object.entries(config).reduce((last, [key, value]) => { | ||
| if (value) last[key] = value; | ||
| return last; | ||
| }, {})); | ||
| } | ||
| toLogString(config) { | ||
| return JSON.stringify(Object.entries(config).reduce((last, [key, value]) => { | ||
| if (value) if (this.protectedKeys.has(key)) last[key] = buildHiddenValue(String(value), this.showProtectedKeys); | ||
| else last[key] = value; | ||
| return last; | ||
| }, {})); | ||
| } | ||
| /** | ||
| * Build a string record from the given data | ||
| * @param {unknown} data - to be validated as object | ||
| * @returns {object} A record with string values | ||
| */ | ||
| buildBaseRecord(data) { | ||
| if (typeof data !== "object" || data === null || Array.isArray(data)) return {}; | ||
| return data; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/parsers/UrlParser.ts | ||
| /** | ||
| * UrlParser class is used to parse and validate env variables of type URL. | ||
| * @class UrlParser | ||
| * @implements {IConfigParser<URL, URL>} | ||
| * @category Parsers | ||
| * @since v0.2.5 | ||
| */ | ||
| var UrlParser = class { | ||
| /** | ||
| * Create a new UrlParser | ||
| * @param {UrlParserProps} properties - Properties for the UrlParser | ||
| */ | ||
| constructor({ urlSanitize } = {}) { | ||
| this.name = "urlParser"; | ||
| this.urlSanitize = urlSanitize ?? false; | ||
| } | ||
| parse({ value }) { | ||
| try { | ||
| return new URL(value); | ||
| } catch (err) { | ||
| throw ErrorCore.from(err); | ||
| function arrayParser(parse, separator = ";", validate) { | ||
| return { | ||
| name: "arraySeparatorParser", | ||
| parse: (props) => { | ||
| return Promise.all(props.value.split(separator).map((v) => parse.parse({ | ||
| ...props, | ||
| value: v | ||
| }))); | ||
| }, | ||
| postValidate: async (props) => { | ||
| if (!validate) return; | ||
| return (await Promise.all(props.value.map(async (v) => { | ||
| if (!(await validate)?.(v)) return; | ||
| return v; | ||
| }))).filter((v) => v !== void 0); | ||
| }, | ||
| toString: (value) => { | ||
| return value.map((v) => parse.toString(v)).join(separator); | ||
| } | ||
| } | ||
| toString(value) { | ||
| return value.href; | ||
| } | ||
| toLogString(value) { | ||
| if (this.urlSanitize) return this.handleUrlSanitize(value.href); | ||
| return value.toString(); | ||
| } | ||
| /** | ||
| * Build a URL object from a string and sanitize the username and password | ||
| * @param {string} value string to parse | ||
| * @returns {URL} URL object with sanitized username and password | ||
| */ | ||
| handleUrlSanitize(value) { | ||
| const url = new URL(value); | ||
| url.password = "*".repeat(url.password.length); | ||
| url.username = "*".repeat(url.username.length); | ||
| return url.href; | ||
| } | ||
| }; | ||
| }; | ||
| } | ||
@@ -1170,3 +1339,3 @@ //#endregion | ||
| const parsed = parseInt(value, 10); | ||
| if (isNaN(parsed)) return Err(/* @__PURE__ */ new TypeError(`${value} is not an integer string`)); | ||
| if (Number.isNaN(parsed)) return Err(/* @__PURE__ */ new TypeError(`${value} is not an integer string`)); | ||
| return Ok(parsed); | ||
@@ -1217,3 +1386,3 @@ } | ||
| const parsed = parseFloat(value); | ||
| if (isNaN(parsed)) return Err(/* @__PURE__ */ new TypeError(`${value} is not a float string`)); | ||
| if (Number.isNaN(parsed)) return Err(/* @__PURE__ */ new TypeError(`${value} is not a float string`)); | ||
| return Ok(parsed); | ||
@@ -1236,16 +1405,16 @@ } | ||
| //#endregion | ||
| //#region src/parsers/stringParser.ts | ||
| //#region src/parsers/bigIntParser.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to string | ||
| * @template Output - Type of output, defaults to bigint | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<string, Output>} - parser | ||
| * @returns {IConfigParser<bigint, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| function stringParser(validate) { | ||
| function bigIntParser(validate) { | ||
| return { | ||
| name: "stringParser", | ||
| parse: ({ value, key }) => { | ||
| return getString(value).mapErr((cause) => new TypeError(`value for key ${key} is not a string`, { cause })).unwrap(); | ||
| name: "bigIntParser", | ||
| parse: ({ key, value }) => { | ||
| return getBigInt(value).mapErr((cause) => new TypeError(`value for key ${key} is not an integer string`, { cause })).unwrap(); | ||
| }, | ||
@@ -1256,7 +1425,4 @@ postValidate: async (props) => { | ||
| }, | ||
| preValidate: ({ key, value }) => { | ||
| if (typeof value !== "string") throw new TypeError(`value for key ${key} is not a string`); | ||
| }, | ||
| toString: (value) => { | ||
| return value; | ||
| return value.toString(); | ||
| } | ||
@@ -1267,45 +1433,2 @@ }; | ||
| //#endregion | ||
| //#region src/parsers/SemicolonConfigParser.ts | ||
| /** | ||
| * Config parser to parse semicolon separated string key=value pairs as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses 'foo=bar;baz=qux;secret=secret' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new SemicolonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, Record<string, string>>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| var SemicolonConfigParser = class { | ||
| constructor({ keepCase, protectedKeys, validate, showProtectedKeys } = {}) { | ||
| this.name = "semicolonConfigParser"; | ||
| this.protectedKeys = new Set(protectedKeys); | ||
| this.validate = validate; | ||
| this.keepCase = keepCase ?? true; | ||
| this.showProtectedKeys = showProtectedKeys; | ||
| } | ||
| parse({ value }) { | ||
| return Promise.resolve(parseSemicolonConfig(value, this.keepCase)); | ||
| } | ||
| async postValidate({ value }) { | ||
| return await this.validate?.(value); | ||
| } | ||
| toString(config, options) { | ||
| return stringifySemicolonConfig(config, options?.uriEncode); | ||
| } | ||
| toLogString(config) { | ||
| return logStringifySemicolonConfig(config, this.showProtectedKeys, this.protectedKeys); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/parsers/booleanParser.ts | ||
@@ -1404,51 +1527,124 @@ /** | ||
| //#endregion | ||
| //#region src/parsers/arrayParser.ts | ||
| //#region src/parsers/JsonConfigParser.ts | ||
| /** | ||
| * Build parser for array of values | ||
| * @template Input - Type of input | ||
| * @template Output - Type of output | ||
| * @param {IConfigParser<Input, Output>} parse parser for the array values | ||
| * @param {string} separator separator for the array values, defaults to ';' | ||
| * @param {TypeGuardValidate<Output> | undefined} validate optional post validation | ||
| * @returns {IConfigParser<Output[], Input[]>} Parser for array of values | ||
| * Config parser to parse JSON string as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new JsonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, object>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| function arrayParser(parse, separator = ";", validate) { | ||
| return { | ||
| name: "arraySeparatorParser", | ||
| parse: (props) => { | ||
| return Promise.all(props.value.split(separator).map((v) => parse.parse({ | ||
| ...props, | ||
| value: v | ||
| }))); | ||
| }, | ||
| postValidate: async (props) => { | ||
| if (!validate) return; | ||
| return (await Promise.all(props.value.map(async (v) => { | ||
| if (!(await validate)?.(v)) return; | ||
| return v; | ||
| }))).filter((v) => v !== void 0); | ||
| }, | ||
| toString: (value) => { | ||
| return value.map((v) => parse.toString(v)).join(separator); | ||
| } | ||
| }; | ||
| } | ||
| var JsonConfigParser = class { | ||
| name = "jsonConfigParser"; | ||
| validate; | ||
| showProtectedKeys; | ||
| protectedKeys; | ||
| constructor({ protectedKeys, validate, showProtectedKeys } = {}) { | ||
| this.protectedKeys = new Set(protectedKeys); | ||
| this.validate = validate; | ||
| this.showProtectedKeys = showProtectedKeys; | ||
| } | ||
| parse({ value }) { | ||
| return this.buildBaseRecord(JSON.parse(value)); | ||
| } | ||
| async postValidate({ value }) { | ||
| return await this.validate?.(value); | ||
| } | ||
| toString(config) { | ||
| return JSON.stringify(Object.entries(config).reduce((last, [key, value]) => { | ||
| if (value) last[key] = value; | ||
| return last; | ||
| }, {})); | ||
| } | ||
| toLogString(config) { | ||
| return JSON.stringify(Object.entries(config).reduce((last, [key, value]) => { | ||
| if (value) if (this.protectedKeys.has(key)) last[key] = buildHiddenValue(String(value), this.showProtectedKeys); | ||
| else last[key] = value; | ||
| return last; | ||
| }, {})); | ||
| } | ||
| /** | ||
| * Build a string record from the given data | ||
| * @param {unknown} data - to be validated as object | ||
| * @returns {object} A record with string values | ||
| */ | ||
| buildBaseRecord(data) { | ||
| if (typeof data !== "object" || data === null || Array.isArray(data)) return {}; | ||
| return data; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/parsers/bigIntParser.ts | ||
| //#region src/parsers/SemicolonConfigParser.ts | ||
| /** | ||
| * Config parser to parse semicolon separated string key=value pairs as object | ||
| * @example | ||
| * const objectSchema = z.object({ | ||
| * foo: z.string(), | ||
| * baz: z.string(), | ||
| * secret: z.string(), | ||
| * }); | ||
| * // parses 'foo=bar;baz=qux;secret=secret' string to {foo: "bar", baz: "qux", secret: "secret"} | ||
| * const fooBarJsonParser = new SemicolonConfigParser({ | ||
| * validate: (value) => objectSchema.parse(value), | ||
| * protectedKeys: ['secret'], | ||
| * showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging | ||
| * }); | ||
| * @template Out - the type of the output object | ||
| * @implements {IConfigParser<Out, Record<string, string>>} | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| var SemicolonConfigParser = class { | ||
| name = "semicolonConfigParser"; | ||
| validate; | ||
| keepCase; | ||
| showProtectedKeys; | ||
| protectedKeys; | ||
| constructor({ keepCase, protectedKeys, validate, showProtectedKeys } = {}) { | ||
| this.protectedKeys = new Set(protectedKeys); | ||
| this.validate = validate; | ||
| this.keepCase = keepCase ?? true; | ||
| this.showProtectedKeys = showProtectedKeys; | ||
| } | ||
| parse({ value }) { | ||
| return Promise.resolve(parseSemicolonConfig(value, this.keepCase)); | ||
| } | ||
| async postValidate({ value }) { | ||
| return await this.validate?.(value); | ||
| } | ||
| toString(config, options) { | ||
| return stringifySemicolonConfig(config, options?.uriEncode); | ||
| } | ||
| toLogString(config) { | ||
| return logStringifySemicolonConfig(config, this.showProtectedKeys, this.protectedKeys); | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/parsers/stringParser.ts | ||
| /** | ||
| * Build parser and have optional post validation (as example for literal values) | ||
| * @template Output - Type of output, defaults to bigint | ||
| * @template Output - Type of output, defaults to string | ||
| * @param {TypeGuardValidate<Output>} [validate] - optional post validation | ||
| * @returns {IConfigParser<bigint, Output>} - parser | ||
| * @returns {IConfigParser<string, Output>} - parser | ||
| * @category Parsers | ||
| * @since v1.0.0 | ||
| */ | ||
| function bigIntParser(validate) { | ||
| function stringParser(validate) { | ||
| return { | ||
| name: "bigIntParser", | ||
| parse: ({ key, value }) => { | ||
| return getBigInt(value).mapErr((cause) => new TypeError(`value for key ${key} is not an integer string`, { cause })).unwrap(); | ||
| name: "stringParser", | ||
| parse: ({ value, key }) => { | ||
| return getString(value).mapErr((cause) => new TypeError(`value for key ${key} is not a string`, { cause })).unwrap(); | ||
| }, | ||
@@ -1459,4 +1655,7 @@ postValidate: async (props) => { | ||
| }, | ||
| preValidate: ({ key, value }) => { | ||
| if (typeof value !== "string") throw new TypeError(`value for key ${key} is not a string`); | ||
| }, | ||
| toString: (value) => { | ||
| return value.toString(); | ||
| return value; | ||
| } | ||
@@ -1467,222 +1666,48 @@ }; | ||
| //#endregion | ||
| //#region src/VariableLookupError.ts | ||
| //#region src/parsers/UrlParser.ts | ||
| /** | ||
| * Custom error class for variable lookup errors. | ||
| * @class VariableLookupError | ||
| * @augments VariableError | ||
| * @category Errors | ||
| * @since v0.2.2 | ||
| * UrlParser class is used to parse and validate env variables of type URL. | ||
| * @class UrlParser | ||
| * @implements {IConfigParser<URL, URL>} | ||
| * @category Parsers | ||
| * @since v0.2.5 | ||
| */ | ||
| var VariableLookupError = class extends VariableError { | ||
| var UrlParser = class { | ||
| name = "urlParser"; | ||
| /** | ||
| * Create a new VariableLookupError | ||
| * @param {string} variableKey - The variable key. | ||
| * @param {string} message - The error message. | ||
| * @param {ErrorOptions} [options] - The error options | ||
| * Should the username and password be sanitized | ||
| */ | ||
| constructor(variableKey, message, options) { | ||
| super(message, options); | ||
| this.variableKey = variableKey; | ||
| this.name = "VariableLookupError"; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/ConfigMap.ts | ||
| /** | ||
| * ConfigMap | ||
| * @example | ||
| * type ConfigEnv = { | ||
| * PORT: number; | ||
| * HOST: string; | ||
| * DEBUG: boolean; | ||
| * URL: URL; | ||
| * }; | ||
| * const config = new ConfigMap<ConfigEnv>({ | ||
| * DEBUG: {loaders: [env()], parser: booleanParser, defaultValue: false}, | ||
| * HOST: {loaders: [env()], parser: stringParser, defaultValue: 'localhost'}, | ||
| * PORT: {loaders: [env()], parser: integerParser, defaultValue: 3000}, | ||
| * URL: {loaders: [env()], parser: new UrlParser({urlSanitize: true}), defaultValue: new URL('http://localhost:3000')}, | ||
| * }); | ||
| * console.log('port', await config.get('PORT')); | ||
| * @template Data - type of config map | ||
| * @since v1.1.0 | ||
| */ | ||
| var ConfigMap = class { | ||
| urlSanitize; | ||
| /** | ||
| * ConfigMap constructor | ||
| * @param {EnvMapSchema<Data>} schema - schema of config map | ||
| * @param {Iterable<IConfigLoader>} loaders - iterable of config loaders | ||
| * @param {ConfigOptions} options - optional config options (logger, namespace) | ||
| * Create a new UrlParser | ||
| * @param {UrlParserProps} properties - Properties for the UrlParser | ||
| */ | ||
| constructor(schema, loaders, options = { | ||
| logger: void 0, | ||
| namespace: void 0 | ||
| }) { | ||
| this.schema = schema; | ||
| this.options = options; | ||
| this.loaders = loaders; | ||
| constructor({ urlSanitize } = {}) { | ||
| this.urlSanitize = urlSanitize ?? false; | ||
| } | ||
| /** | ||
| * Set logger value | ||
| * @param {ILoggerLike | undefined} logger - logger like object | ||
| */ | ||
| setLogger(logger) { | ||
| this.options.logger = logger; | ||
| } | ||
| /** | ||
| * get env object from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: LoaderTypeValue<number> = await config.getObject('PORT'); | ||
| * console.log(valueObject.type, valueObject.value); // 'env', 3000 | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getObject(key, encodeOptions) { | ||
| if (typeof key !== "string") throw new VariableError(`ConfigMap key ${String(key)} is not a string`); | ||
| const entry = this.schema[key]; | ||
| if (!entry) throw new VariableLookupError(key, `ConfigMap key ${String(key)} not found in config map`); | ||
| const { parser, defaultValue, params, undefinedThrowsError, undefinedErrorMessage } = entry; | ||
| const configObject = await getConfigObject(key, Array.from(await LoadableCore.resolve(this.loaders)), parser, defaultValue, params, this.options, encodeOptions); | ||
| if (undefinedThrowsError && configObject.value === void 0) { | ||
| buildOptions(this.options).logger?.info(`ConfigMap key ${String(key)} is undefined (expect to throw error)`); | ||
| throw new VariableError(undefinedErrorMessage ?? `ConfigMap key ${String(key)} is undefined`); | ||
| } | ||
| return configObject; | ||
| } | ||
| /** | ||
| * get env object from config map as Result | ||
| * @returns {Promise<Result<TypeValueRecords<Data>>>} Result Promise of env object or undefined | ||
| * @example | ||
| * const valueObject: Result<LoaderTypeValue<number>> = await config.getObjectResult('PORT'); | ||
| * if (valueObject.isOk()) { | ||
| * const {type, value} = valueObject.ok(); | ||
| * console.log(type, value); // 'env', 3000 | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getObjectResult(key, encodeOptions) { | ||
| parse({ value }) { | ||
| try { | ||
| return Ok(await this.getObject(key, encodeOptions)); | ||
| return new URL(value); | ||
| } catch (err) { | ||
| return Err(err); | ||
| throw ErrorCore.from(err); | ||
| } | ||
| } | ||
| /** | ||
| * get env value from config map | ||
| * @returns {Promise<Data[Key]>} Promise of value or undefined | ||
| * @example | ||
| * const port: number = await config.get('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async get(key, encodeOptions) { | ||
| return (await this.getObject(key, encodeOptions)).value; | ||
| toString(value) { | ||
| return value.href; | ||
| } | ||
| /** | ||
| * get env value as string from config map | ||
| * @returns {Promise<string | undefined>} Promise of string value or undefined | ||
| * @example | ||
| * const port: string = await config.getString('PORT'); | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getString(key, encodeOptions) { | ||
| return (await this.getObject(key, encodeOptions)).stringValue; | ||
| toLogString(value) { | ||
| if (this.urlSanitize) return this.handleUrlSanitize(value.href); | ||
| return value.toString(); | ||
| } | ||
| /** | ||
| * get env value from config map as Result | ||
| * @returns {Promise<Result<Data[Key]>>} Result Promise of value or undefined | ||
| * @example | ||
| * const port: Result<number> = await config.getResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * Build a URL object from a string and sanitize the username and password | ||
| * @param {string} value string to parse | ||
| * @returns {URL} URL object with sanitized username and password | ||
| */ | ||
| async getResult(key, encodeOptions) { | ||
| try { | ||
| return Ok(await this.get(key, encodeOptions)); | ||
| } catch (err) { | ||
| return Err(err); | ||
| } | ||
| handleUrlSanitize(value) { | ||
| const url = new URL(value); | ||
| url.password = "*".repeat(url.password.length); | ||
| url.username = "*".repeat(url.username.length); | ||
| return url.href; | ||
| } | ||
| /** | ||
| * get env value as string from config map as Result | ||
| * @returns {Promise<Result<string | undefined>>} Result Promise of string value or undefined | ||
| * @example | ||
| * const port: Result<string> = await config.getStringResult('PORT'); | ||
| * if (port.isOk()) { | ||
| * console.log('port', port.ok()); | ||
| * } | ||
| * @param {string} key - key of config map | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getStringResult(key, encodeOptions) { | ||
| try { | ||
| return Ok(await this.getString(key, encodeOptions)); | ||
| } catch (err) { | ||
| return Err(err); | ||
| } | ||
| } | ||
| /** | ||
| * get all env value objects from config map | ||
| * @returns {Promise<TypeValueRecords<Data>>} Promise of all values | ||
| * @example | ||
| * const values: TypeValueRecords<Data> = await config.getAll(); | ||
| * console.log(values.PORT.type, values.PORT.value); // 'env', 3000 | ||
| */ | ||
| async getAllObjects() { | ||
| return (await this.getAllPromises()).reduce((result, [key, value]) => { | ||
| result[key] = value; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * get all env values from config map | ||
| * @returns {Promise<Data>} Promise of all values | ||
| * @example | ||
| * const values: Data = await config.getAllValues(); | ||
| * console.log('PORT', values.PORT); // 3000 (number) | ||
| */ | ||
| async getAllValues() { | ||
| return (await this.getAllPromises()).reduce((result, [key, value]) => { | ||
| result[key] = value.value; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * get all env values from config map as string | ||
| * @returns {Promise<Record<keyof Data, string>>} Promise of all values as string | ||
| * @example | ||
| * const values: Record<keyof Data, string> = await config.getAllStringValues(); | ||
| * console.log('PORT', values.PORT); // '3000' (string) | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| */ | ||
| async getAllStringValues(encodeOptions) { | ||
| return (await this.getAllPromises(encodeOptions)).reduce((result, [key, value]) => { | ||
| result[key] = value.stringValue; | ||
| return result; | ||
| }, {}); | ||
| } | ||
| /** | ||
| * Validate all env values from config map, expect to throw error if error exists | ||
| * @param {(data: Data) => void} callback callback function | ||
| */ | ||
| async validateAll(callback) { | ||
| callback(await this.getAllValues()); | ||
| } | ||
| /** | ||
| * run lookup to all keys and return all promises | ||
| * @param {EncodeOptions} [encodeOptions] - optional encode options | ||
| * @returns {Promise<[keyof Data, LoaderTypeValueStrict<Data[keyof Data]>][]>} Promise of all values | ||
| */ | ||
| getAllPromises(encodeOptions) { | ||
| return Promise.all(Object.keys(this.schema).map(async (key) => { | ||
| return [key, await this.getObject(key, encodeOptions)]; | ||
| })); | ||
| } | ||
| }; | ||
@@ -1689,0 +1714,0 @@ |
+12
-52
| { | ||
| "name": "@avanio/variable-util", | ||
| "version": "1.2.2", | ||
| "version": "1.3.0", | ||
| "description": "Utility to get variables from multiple resources", | ||
@@ -9,8 +9,10 @@ "main": "./dist/index.cjs", | ||
| "exports": { | ||
| "types": { | ||
| "import": "./dist/index.d.mts", | ||
| "require": "./dist/index.d.cts" | ||
| "import": { | ||
| "types": "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| "import": "./dist/index.mjs", | ||
| "require": "./dist/index.cjs", | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| }, | ||
| "default": "./dist/index.mjs" | ||
@@ -20,9 +22,4 @@ }, | ||
| "scripts": { | ||
| "doc": "typedoc", | ||
| "build": "tsdown src/index.ts --sourcemap --format cjs,esm --dts --clean", | ||
| "prepublishOnly": "npm run build", | ||
| "test": "vitest test --run --no-isolate --coverage", | ||
| "coverage": "vitest test --run --no-isolate --reporter=dot --coverage --coverage.reporter=lcov", | ||
| "lint": "eslint . --ext .ts", | ||
| "validate": "tsc --noEmit --project tsconfig.test.json" | ||
| "build": "tsdown src/index.ts --sourcemap --format cjs,esm --dts --clean -c tsconfig.build.json", | ||
| "validate": "tsc --noEmit" | ||
| }, | ||
@@ -32,6 +29,3 @@ "files": [ | ||
| ], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "github:mharj/variable-util" | ||
| }, | ||
| "repository": "github:mharj/variable-util", | ||
| "keywords": [ | ||
@@ -47,35 +41,2 @@ "env", | ||
| "homepage": "https://github.com/mharj/variable-util#readme", | ||
| "devDependencies": { | ||
| "@avanio/logger-like": "^0.2.12", | ||
| "@cspell/eslint-plugin": "^9.2.1", | ||
| "@eslint/js": "^9.35.0", | ||
| "@luolapeikko/result-option": "^2.0.1", | ||
| "@luolapeikko/ts-common": "^1.1.1", | ||
| "@stylistic/eslint-plugin": "^5.3.1", | ||
| "@types/etag": "^1.8.4", | ||
| "@types/node": "^22.18.3", | ||
| "@types/sinon": "^17.0.4", | ||
| "@typescript-eslint/eslint-plugin": "^8.43.0", | ||
| "@typescript-eslint/parser": "^8.43.0", | ||
| "@vitest/coverage-v8": "^3.2.4", | ||
| "c8": "^10.1.3", | ||
| "dotenv": "^17.2.2", | ||
| "eslint": "^9.35.0", | ||
| "eslint-config-prettier": "^10.1.8", | ||
| "eslint-import-resolver-typescript": "^4.4.4", | ||
| "eslint-plugin-import": "^2.32.0", | ||
| "eslint-plugin-jsdoc": "^56.1.2", | ||
| "eslint-plugin-prettier": "^5.5.4", | ||
| "eslint-plugin-sonarjs": "^3.0.5", | ||
| "etag": "^1.8.1", | ||
| "prettier": "^3.6.2", | ||
| "sinon": "^21.0.0", | ||
| "tsdown": "^0.20.3", | ||
| "typedoc": "^0.28.12", | ||
| "typescript": "^5.9.2", | ||
| "typescript-eslint": "^8.43.0", | ||
| "vite": "^7.1.5", | ||
| "vitest": "^3.2.4", | ||
| "zod": "^3.25.76" | ||
| }, | ||
| "peerDependencies": { | ||
@@ -85,4 +46,3 @@ "@avanio/logger-like": ">= 0.1.0", | ||
| "@luolapeikko/ts-common": ">= 1.0.0" | ||
| }, | ||
| "packageManager": "pnpm@10.15.1+sha512.34e538c329b5553014ca8e8f4535997f96180a1d0f614339357449935350d924e22f8614682191264ec33d1462ac21561aff97f6bb18065351c162c7e8f6de67" | ||
| } | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
466563
7.51%0
-100%10
25%3346
1.52%63
-4.55%48
-2.04%