nestjs-config-validator
Version:
Advanced configuration validator for NestJS with type-safe schema validation and full TypeScript type inference
34 lines (33 loc) • 1.62 kB
TypeScript
import { ConfigService } from '@nestjs/config';
import { RootConfigSchema, ConfigSchema } from './types';
import { InferRootConfigType, ConfigPaths } from './type-utils';
/**
* Создает типизированные пути для доступа к конфигурации
*/
export declare const createConfigPaths: <T extends readonly ConfigSchema[]>(schemas: T) => ConfigPaths<T>;
/**
* Создает типизированную конфигурацию для NestJS
*/
export interface TypedConfigSetup<T extends readonly ConfigSchema[]> {
config: InferRootConfigType<T>;
paths: ConfigPaths<T>;
rootSchema: RootConfigSchema;
}
/**
* Создает полную типизированную конфигурацию
*/
export declare const createTypedConfig: <T extends readonly ConfigSchema[]>(rootSchema: RootConfigSchema) => TypedConfigSetup<T>;
/**
* Типизированный ConfigService wrapper
*/
export declare class TypedConfigService<T extends readonly ConfigSchema[]> {
private readonly configService;
private readonly paths;
constructor(configService: ConfigService, paths: ConfigPaths<T>);
get<K extends string>(path: K): K extends keyof InferRootConfigType<T> ? InferRootConfigType<T>[K] : never;
getOrThrow<K extends string>(path: K): K extends keyof InferRootConfigType<T> ? InferRootConfigType<T>[K] : never;
}
/**
* Создает типизированный ConfigService
*/
export declare const createTypedConfigService: <T extends readonly ConfigSchema[]>(configService: ConfigService, paths: ConfigPaths<T>) => TypedConfigService<T>;