UNPKG

@openally/config

Version:

Reactive configuration loader

33 lines (30 loc) 1.21 kB
import nodeFs from 'node:fs'; import { EventEmitter } from 'node:events'; import { JSONSchemaType } from 'ajv'; import Observable from 'zen-observable'; type ConfigAnySchema = Record<string | number | symbol, any>; interface ConfigOptions<T> { createOnNoEntry?: boolean; autoReload?: boolean; writeOnSet?: boolean; jsonSchema?: JSONSchemaType<T> | ConfigAnySchema; fs?: { promises: Pick<typeof nodeFs.promises, "readFile" | "writeFile">; watch: typeof nodeFs.watch; existsSync: typeof nodeFs.existsSync; }; } declare class AsynchronousConfig<T extends Record<string, any> = Record<string, any>> extends EventEmitter { #private; constructor(configFilePath: string, options?: ConfigOptions<T>); get payload(): T; set payload(newPayload: T); read(defaultPayload?: T): Promise<this>; setupAutoReload(): boolean; observableOf(fieldPath: string, depth?: number): Observable<unknown>; get<Y = any>(fieldPath: string, depth?: number): Y | null; set(fieldPath: string, fieldValue: any): this; writeOnDisk(): Promise<void>; close(): Promise<void>; } export { AsynchronousConfig, type ConfigAnySchema, type ConfigOptions };