//#region src/standard.d.ts /** The Standard Schema interface. */ interface StandardSchemaV1 { /** The Standard Schema properties. */ readonly "~standard": StandardSchemaV1.Props; } declare namespace StandardSchemaV1 { /** The Standard Schema properties interface. */ interface Props { /** The version number of the standard. */ readonly version: 1; /** The vendor name of the schema library. */ readonly vendor: string; /** Validates unknown input values. */ readonly validate: (value: unknown) => Result | Promise>; /** Inferred types associated with the schema. */ readonly types?: Types | undefined; } /** The result interface of the validate function. */ type Result = SuccessResult | FailureResult; /** The result interface if validation succeeds. */ interface SuccessResult { /** The typed output value. */ readonly value: Output; /** The non-existent issues. */ readonly issues?: undefined; } /** The result interface if validation fails. */ interface FailureResult { /** The issues of failed validation. */ readonly issues: ReadonlyArray; } /** The issue interface of the failure output. */ interface Issue { /** The error message of the issue. */ readonly message: string; /** The path of the issue, if any. */ readonly path?: ReadonlyArray | undefined; } /** The path segment interface of the issue. */ interface PathSegment { /** The key representing a path segment. */ readonly key: PropertyKey; } /** The Standard Schema types interface. */ interface Types { /** The input type of the schema. */ readonly input: Input; /** The output type of the schema. */ readonly output: Output; } /** Infers the input type of a Standard Schema. */ type InferInput = NonNullable["input"]; /** Infers the output type of a Standard Schema. */ type InferOutput = NonNullable["output"]; } /** A dictionary of Standard Schema objects mapping input keys to their corresponding schemas. */ type StandardSchemaDictionary, Output extends Record = Input> = { [K in keyof Input]-?: StandardSchemaV1 }; declare namespace StandardSchemaDictionary { /** Infers the input types from a Standard Schema Dictionary. */ type InferInput = { [K in keyof T]: StandardSchemaV1.InferInput }; /** Infers the output types from a Standard Schema Dictionary. */ type InferOutput = { [K in keyof T]: StandardSchemaV1.InferOutput }; } //#endregion //#region src/types.d.ts /** Type for error messages that must be strings */ type ErrorMessage = T; /** Creates a type where all properties are impossible to set */ type Impossible> = Partial>; /** Merges two types, with B taking precedence over A */ type Merge = Omit & B; /** Simplifies a type by removing intersections and making it more readable */ type Simplify = { [P in keyof T]: T[P] } & {}; /** Gets all keys from T that can be undefined */ type PossiblyUndefinedKeys = { [K in keyof T]: undefined extends T[K] ? K : never }[keyof T]; /** Makes properties that can be undefined optional */ type UndefinedOptional = Partial>> & Omit>; /** Converts a readonly type to a mutable type */ type Mutable = T extends Readonly ? U : T; /** Extracts the combined schema from validation options */ type ExtractExtendsArray = T extends { extends?: infer E; } ? E extends ExtendsFormat ? E : [] : []; type Depth = 0 | 1 | 2 | 3 | 4; type DefaultDepth = 2; type Prev = [0, 0, 1, 2, 3]; type Dec = Prev[N]; type AsDictionary = T extends object ? StandardSchemaDictionary & T : StandardSchemaDictionary; type ExtractCombinedSchema = T extends ValidationOptions ? CombinedSchema, StandardSchemaDictionary, D>>, AsDictionary>> : T extends Readonly> ? CombinedSchema, StandardSchemaDictionary, D>>, AsDictionary>> : CombinedSchema, StandardSchemaDictionary, D>>, AsDictionary : StandardSchemaDictionary, T extends { server: infer Sv; } ? Sv extends ServerFormat ? Sv : StandardSchemaDictionary : StandardSchemaDictionary, T extends { client: infer C; } ? C extends ClientFormat ? C : StandardSchemaDictionary : StandardSchemaDictionary>>>; /** Reduces an array of schemas to a single schema */ type Reduce = StandardSchemaDictionary, D extends Depth = DefaultDepth> = D extends 0 ? Acc : Arr extends readonly [] | [] ? Acc : Arr extends readonly [infer Head, ...infer Tail] | [infer Head, ...infer Tail] ? Tail extends readonly unknown[] | unknown[] ? Mutable, AsDictionary>>>, D>> : never : never; type InferPresetOutput = StandardSchemaDictionary.InferOutput>; type CombinedSchema = StandardSchemaDictionary & Merge>; type PrefixFormat = string | undefined; type SharedFormat = StandardSchemaDictionary; type ServerFormat = StandardSchemaDictionary; type ClientFormat = StandardSchemaDictionary; type ExtendsFormat = (Preset | Readonly)[] | ReadonlyArray; type Preset = ValidationOptions & { id?: string; extends?: Extends; }; type Schema = StandardSchemaV1; interface BaseOptions { /** * Array of preset configurations to extend from. */ extends?: Extends; /** * Whether to skip validation of environment variables. * @default false */ skip?: boolean; /** * Whether to treat environment as server-side. * @default typeof window === "undefined" || "Deno" in window */ isServer?: boolean; /** * Called when validation fails. By default the error is logged, * and an error is thrown telling what environment variables are invalid. */ onError?: (issues: StandardSchemaV1.FailureResult["issues"]) => never; /** * Called when a server-side environment variable is accessed on the client. * By default an error is thrown. */ onInvalidAccess?: (variable: string) => never; } interface LooseOptions extends BaseOptions { /** * Must be undefined when using loose options. Use `env` instead. */ envStrict?: never; /** * What object holds the environment variables at runtime. This is usually * `process.env` or `import.meta.env`. * This doesn't enforce that all environment variables are set. */ env?: Record; } interface StrictOptions extends BaseOptions { /** * Runtime Environment variables to use for validation - `process.env`, `import.meta.env` or similar. * Enforces all environment variables to be set. Required in for example Next.js Edge and Client runtimes. */ envStrict?: Record<{ [Key in keyof Client$1]: Prefix extends undefined ? never : Key extends `${Prefix}${string}` ? Key : never }[keyof Client$1] | { [Key in keyof Server$1]: Prefix extends undefined ? Key : Key extends `${Prefix}${string}` ? never : Key }[keyof Server$1] | { [Key in keyof Shared$1]: Key extends string ? Key : never }[keyof Shared$1] | keyof StandardSchemaDictionary.InferOutput>, string | boolean | number | undefined>; /** * Must be undefined when using strict options. Use `envStrict` instead. */ env?: never; } interface SharedOptions { /** * Specify your shared environment variables schema here. These variables are available on both client and server. */ shared?: Shared$1; } interface ClientOptions { /** * The prefix that client-side variables must have. This is enforced both at * a type-level and at runtime. */ clientPrefix?: Prefix; /** * Specify your client-side environment variables schema here. This way you can ensure the app isn't * built with invalid env vars. */ client?: Partial<{ [Key in keyof Client$1]: Key extends `${Prefix}${string}` ? Client$1[Key] : ErrorMessage<`${Key extends string ? Key : never} is not prefixed with ${Prefix}.`> }>; } interface ServerOptions { /** * Specify your server-side environment variables schema here. This way you can ensure the app isn't * built with invalid env vars. */ server: Partial<{ [Key in keyof Server$1]: Prefix extends undefined ? Server$1[Key] : Prefix extends "" ? Server$1[Key] : Key extends `${Prefix}${string}` ? ErrorMessage<`${Key extends `${Prefix}${string}` ? Key : never} should not prefixed with ${Prefix}.`> : Server$1[Key] }>; } type ValidationOptions = ((ClientOptions & ServerOptions) | (ServerOptions & Impossible>) | (ClientOptions & Impossible>)) & SharedOptions; interface TransformSchemaOptions { /** * A custom function to combine the schemas. * Can be used to add further refinement or transformation. */ transform?: (shape: Simplify>, isServer: boolean) => FinalSchema$1; } type EnvOptions = (LooseOptions | StrictOptions) & ValidationOptions & TransformSchemaOptions; type FullSchemaShape = CombinedSchema, D>>, CombinedSchema>; type FinalSchema = StandardSchemaV1>>>; type DefineEnv = Simplify & { _schema: FinalSchema$1; }>>; //#endregion export { ValidationOptions as C, TransformSchemaOptions as S, ServerOptions as _, DefineEnv as a, Simplify as b, ExtendsFormat as c, InferPresetOutput as d, LooseOptions as f, ServerFormat as g, Schema as h, CombinedSchema as i, FinalSchema as l, Preset as m, ClientFormat as n, EnvOptions as o, PrefixFormat as p, ClientOptions as r, ErrorMessage as s, BaseOptions as t, FullSchemaShape as u, SharedFormat as v, StrictOptions as x, SharedOptions as y };