nx-config2
Version:
Next-generation configuration management for Node.js - Zero dependencies, TypeScript-first, production-ready
163 lines • 5.12 kB
TypeScript
/**
* Type definitions for nx-config2
*/
import { RemoteJsonConfig } from 'nx-remote-json';
import { EventEmitter } from 'events';
export type ConfigSource = string | object | {
filePath: string;
};
export type MergeStrategy = 'deep' | 'shallow' | 'override' | 'append';
export interface ParseConfigOptions {
strict?: boolean;
verbose?: boolean;
filePath?: string;
encoding?: BufferEncoding;
dotenvPath?: string;
defaults?: Record<string, any>;
transform?: Record<string, (value: string) => any>;
prefix?: string;
suffix?: string;
descriptions?: Record<string, string>;
createDirectories?: boolean;
commandLineArgs?: boolean;
envSeparator?: string;
heuristicJsonParsing?: boolean;
lenientJson?: boolean;
enableSharedEnv?: boolean;
sharedEnvRequired?: boolean;
warnOnFallback?: boolean | 'error';
}
export interface MultiConfigOptions extends ParseConfigOptions {
sources: ConfigSource[];
mergeStrategy?: MergeStrategy;
keepSeparate?: boolean;
names?: string[];
extends?: string;
priority?: 'first' | 'last';
}
export interface ParseConfigResult<T = any> {
config: T;
resolvedVars: string[];
warnings: string[];
errors: string[];
documentation?: string;
}
export interface MultiConfigResult<T = any> {
config: T;
configs: Record<string, any>;
resolvedVars: string[];
warnings: string[];
errors: string[];
documentation?: string;
}
export interface VerificationResult {
validated: boolean;
missing: string[];
empty: string[];
present: string[];
}
export interface InitConfigOptions extends ParseConfigOptions {
requiredVars?: string[];
validateOnInit?: boolean;
throwOnMissing?: boolean;
schema?: Record<string, SchemaDefinition>;
generateDocs?: boolean;
docsPath?: string;
overrides?: Record<string, any>;
stores?: ConfigStore[];
onResolved?: (config: any) => any;
}
export interface InitConfigResult<T = any> {
config: T;
validation: VerificationResult;
resolvedVars: string[];
warnings: string[];
documentation?: string | undefined;
}
export interface RemoteConfigOptions extends Omit<InitConfigOptions, 'stores'> {
remoteJsonConfig: RemoteJsonConfig;
mode: string;
jsonRouter: string;
jsonKey: string;
}
export interface SchemaDefinition {
type: 'string' | 'number' | 'boolean' | 'json' | 'array' | 'url' | 'email' | 'port' | 'bigint' | 'regex' | 'duration' | 'timestamp' | 'ipaddress' | 'nat' | 'int' | 'bytes';
required?: boolean;
default?: any;
enum?: any[];
min?: number;
max?: number;
pattern?: RegExp;
transform?: (value: string) => any;
description?: string;
doc?: string;
isDirectory?: boolean;
isFile?: boolean;
sensitive?: boolean;
nullable?: boolean;
arg?: string;
env?: string;
format?: string | ((value: any) => boolean);
}
export interface ConfigStore {
name: string;
type: 'literal' | 'file' | 'memory' | 'env' | 'argv';
data?: any;
filePath?: string;
secure?: boolean;
secret?: string;
}
export interface WatchConfigOptions {
interval?: number;
onChange?: (newConfig: any) => void;
onError?: (error: Error) => void;
}
export interface ConfigHierarchy {
set(key: string, value: any): void;
get(key: string): any;
has(key: string): boolean;
reset(key: string): void;
load(data: any): void;
save(callback?: (err?: Error) => void): void;
merge(data: any): void;
}
export interface EnvVariableInfo {
varName: string;
length: number;
synthesizedValue: string;
}
export interface ConfigWatcher extends EventEmitter {
stop(): void;
on(event: 'change', listener: (newConfig: any) => void): this;
on(event: 'error', listener: (error: Error) => void): this;
once(event: 'change', listener: (newConfig: any) => void): this;
once(event: 'error', listener: (error: Error) => void): this;
emit(event: 'change', newConfig: any): boolean;
emit(event: 'error', error: Error): boolean;
}
export declare class ConfigParseError extends Error {
variableName?: string | undefined;
path?: string | undefined;
filePath?: string | undefined;
constructor(message: string, variableName?: string | undefined, path?: string | undefined, filePath?: string | undefined);
}
export declare class ConfigValidationError extends Error {
missingVars: string[];
emptyVars: string[];
constructor(message: string, missingVars: string[], emptyVars: string[]);
}
export declare class ConfigFileError extends Error {
filePath: string;
originalError?: Error | undefined;
constructor(message: string, filePath: string, originalError?: Error | undefined);
}
export declare class ConfigSchemaError extends Error {
field: string;
expectedType: string;
constructor(message: string, field: string, expectedType: string);
}
export declare class ConfigMergeError extends Error {
sources: string[];
constructor(message: string, sources: string[]);
}
//# sourceMappingURL=types.d.ts.map