schema

Schema shapes accepted by arkenv() in core and standard modes.

Edit on GitHub

arkenv() accepts a schema that maps environment variable names to validators. Core uses the ArkType DSL (and compiled type() values). Standard mode accepts a map of Standard Schema validators.

Declarative map

Pass a map of ArkType strings (or nested objects). This is an EnvSchema: each value is validated against ArkEnv's ArkType scope before parsing.

./env.ts
import  from "@arkenv/core";

export const  = ({
  : "'development' | 'production' | 'test' = 'development'",
  : "string.host = 'localhost'",
  : "number.port = 3000",
  : "string",
});

Compiled type()

Build the schema once with type() when you reuse it across runtimes or packages.

./env-schema.ts
import , {  } from "@arkenv/core";

export const  = ({
  : "number.port = 3000",
  : "string",
});

export const  = ();

See Reusing schemas.

Standard Schema maps

With @arkenv/standard, every value must be a Standard Schema validator (Zod, Valibot, and others). ArkType DSL strings fail.

./env.ts
import  from "@arkenv/standard";
import * as  from "zod";

export const  = ({
  : .().(0).(65535),
  : .(),
});

Inferring types

Infer<T> works for declarative maps, compiled ArkType types, and Standard Schema values.

./env.ts
import , { type  } from "@arkenv/core";

const  = {
  : "string",
  : "number.port = 3000",
} as ;

export const  = ();
export type  = <typeof >;

Client and server schemas

Framework packages enforce public prefixes on a flat schema:

  • Flat: one schema; public prefixes decide client exposure
  • Optional recipe: two modules with extends when names must stay off the client type graph

Details: Client vs. server, @arkenv/nextjs, @arkenv/nuxt.

Next steps