import type { EnvVarConfig } from "@sveltejs/kit"; import { Schema } from "effect"; /** * The Standard Schema validator shape SvelteKit accepts for an environment variable. * * @since 4.2.0 */ export type StandardSchema = NonNullable["schema"]>; /** * A validator accepted by {@link DefineEnvVars}: an Effect Schema that decodes * synchronously from the raw string value, or an existing Standard Schema. * * @since 4.2.0 */ export type EnvironmentSchema = (Schema.ConstraintDecoder & { readonly Encoded: string | undefined; }) | StandardSchema; /** * The decoded output type an environment schema produces. * * @since 4.2.0 */ export type EnvironmentSchemaOutput = S extends Schema.Constraint ? S["Type"] : S extends StandardSchema ? Output : never; /** * One environment variable declaration: SvelteKit's metadata plus an Effect * Schema or Standard Schema validator. * * @since 4.2.0 */ export interface EnvironmentVariable { readonly public?: boolean; readonly static?: boolean; readonly description?: string; readonly schema?: S; } /** * Environment variable declarations keyed by variable name. * * @since 4.2.0 */ export type EnvironmentDefinition = Record; /** * The normalized declarations {@link DefineEnvVars} returns, with every Effect * Schema converted to a Standard Schema of the same decoded output type. * * @since 4.2.0 */ export type EnvironmentVariables = { readonly [Name in keyof Definition]: Omit & NormalizedVariableSchema; }; /** Keeps the schema member sound when a declaration's schema type includes undefined. */ type NormalizedVariableSchema = [S] extends [EnvironmentSchema] ? { readonly schema: StandardSchema>; } : [S] extends [undefined] ? { readonly schema?: undefined; } : { readonly schema?: StandardSchema>>; }; /** * Declares SvelteKit environment variables with Effect Schema validators. * * A thin wrapper over SvelteKit's `defineEnvVars` that converts Effect Schemas * to the Standard Schema interface SvelteKit validates at startup. Standard * Schema validators and schema-less declarations pass through unchanged, and * SvelteKit remains responsible for loading, visibility, and validation. * Schemas must decode synchronously from the raw string value. * * @example * ```ts * // src/env.ts * import { DefineEnvVars } from "svelte-effect-runtime/environment"; * import { Schema } from "effect"; * * export const variables = DefineEnvVars({ * PORT: { schema: Schema.NumberFromString, description: "Server port." }, * PUBLIC_ORIGIN: { public: true, schema: Schema.URLFromString }, * }); * ``` * * @since 4.2.0 * @param definition - Environment variable declarations keyed by variable name, * each carrying SvelteKit's metadata plus an Effect Schema or Standard Schema. * @returns The same declarations with every Effect Schema converted to a * Standard Schema, ready to export as `variables` from `src/env.ts`. */ export declare function DefineEnvVars(definition: Definition): EnvironmentVariables; export {};