export interface Spec { /** * An Array that lists the admissable parsed values for the env var. */ choices?: ReadonlyArray; /** * A string that describes the env var. */ desc?: string; /** * An example value for the env var. */ example?: string; /** * A url that leads to more detailed documentation about the env var. */ docs?: string; /** * A fallback value, which will be used if the env var wasn't specified. Providing a default effectively makes the env var optional. */ default?: NonNullable | undefined; /** * A fallback value to use only when NODE_ENV is not 'production'. * This is handy for env vars that are required for production environments, but optional for development and testing. */ devDefault?: NonNullable | undefined; } type OptionalAttrs = { default: undefined; } | { devDefault: undefined; } | { default: undefined; devDefault: undefined; } | { default: NonNullable; devDefault: undefined; } | { default: undefined; devDefault: NonNullable; }; type RequiredAttrs = { default: NonNullable; } | { devDefault: NonNullable; } | { devDefault: NonNullable; default: NonNullable; } | {}; type DefaultKeys = 'default' | 'devDefault'; type OptionalSpec = Spec & OptionalAttrs; type OptionalTypelessSpec = Omit, 'choices'>; type RequiredSpec = Spec & RequiredAttrs; type RequiredTypelessSpec = Omit, 'choices' | DefaultKeys>; type ChoicelessOptionalSpec = Omit, 'choices' | DefaultKeys> & OptionalAttrs; type ChoicelessRequiredSpec = Omit, 'choices' | DefaultKeys> & RequiredAttrs; type WithParser = { _parse: (input: string) => T; }; export type RequiredValidatorSpec = RequiredSpec & WithParser; export type OptionalValidatorSpec = OptionalSpec & WithParser; export type ValidatorSpec = RequiredValidatorSpec | OptionalValidatorSpec; export interface ExactValidator { (spec: OptionalSpec): OptionalValidatorSpec; (spec?: RequiredSpec): RequiredValidatorSpec; } export interface BaseValidator { (spec: OptionalSpec): OptionalValidatorSpec; (spec: ChoicelessRequiredSpec): RequiredValidatorSpec; (spec?: RequiredSpec): RequiredValidatorSpec; } export interface StructuredValidator { (): RequiredValidatorSpec; (): RequiredValidatorSpec; (spec: RequiredTypelessSpec): RequiredValidatorSpec; (spec: OptionalTypelessSpec): OptionalValidatorSpec; (spec: ChoicelessOptionalSpec): OptionalValidatorSpec; (spec: ChoicelessRequiredSpec): RequiredValidatorSpec; } export type SpecsOutput = { [K in keyof S]: unknown; }; export type CleanedEnv = S extends Record> ? Readonly<{ [K in keyof S]: S[K] extends OptionalValidatorSpec ? U | undefined : S[K] extends RequiredValidatorSpec ? U : never; } & CleanedEnvAccessors> : never; export interface CleanedEnvAccessors { /** true if NODE_ENV === 'development' */ readonly isDevelopment: boolean; readonly isDev: boolean; /** true if NODE_ENV === 'test' */ readonly isTest: boolean; /** true if NODE_ENV === 'production' */ readonly isProduction: boolean; readonly isProd: boolean; } export interface ReporterOptions { errors: Partial>; env: unknown; } export interface CleanOptions { /** * Pass in a function to override the default error handling and console output. * See ./reporter.ts for the default implementation. */ reporter?: ((opts: ReporterOptions) => void) | null; } export interface StrictProxyMiddlewareOptions { /** * A list of extra inspectable properties to add to the middleware. * * This is useful if you want to add support for framework-specific values. */ extraInspectables?: string[]; } export {};