znv
Version:
Parse your environment with Zod schemas
31 lines (30 loc) • 1.54 kB
TypeScript
import { ZodErrorMap } from "zod";
import type { Schemas } from "./parse-env.js";
export declare const errorMap: ZodErrorMap;
export interface ErrorWithContext {
/** The env var name. */
key: string;
/** The actual value present in `process.env[key]`, or undefined. */
receivedValue: unknown;
/** `ZodError` if Zod parsing failed, or `Error` if a preprocessor threw. */
error: unknown;
/** If a default was provided, whether the default value was used. */
defaultUsed: boolean;
/** If a default was provided, the given default value. */
defaultValue: unknown;
}
export interface TokenFormatters {
/** Formatter for the env var name. */
formatVarName?: (key: string) => string;
/** For parsed objects with errors, formatter for object keys. */
formatObjKey?: (key: string) => string;
/** Formatter for the actual value we received for the env var. */
formatReceivedValue?: (val: unknown) => string;
/** Formatter for the default value provided for the schema. */
formatDefaultValue?: (val: unknown) => string;
/** Formatter for the error summary header. */
formatHeader?: (header: string) => string;
}
export type Reporter = (errors: ErrorWithContext[], schemas: Schemas) => string;
export declare function makeDefaultReporter(formatters: TokenFormatters): Reporter;
export declare function reportErrors(errors: ErrorWithContext[], schemas: Schemas, { formatVarName, formatObjKey, formatReceivedValue, formatDefaultValue, formatHeader, }?: TokenFormatters): string;