Schema Libraries

ArkType

ArkType is a type-first validation library where you write types that look like TypeScript syntax.

ArkType is a type-first validation library where you write types that look like TypeScript syntax.

Installation

npm install arktype

Basic Schema

nuxt.config.ts
import { type } from 'arktype'

export default defineNuxtConfig({
  modules: ['nuxt-safe-runtime-config'],
  runtimeConfig: {
    databaseUrl: '',
    secretKey: '',
    port: 3000,
    public: { apiBase: 'https://api.example.com', appName: 'My App' },
  },
  safeRuntimeConfig: {
    $schema: type({
      'public': { 'apiBase': 'string', 'appName?': 'string' },
      'databaseUrl': 'string',
      'secretKey': 'string',
      'port?': 'number',
    }),
  },
})

Common Patterns

Required vs Optional

type({
  'required': 'string', // must exist
  'optional?': 'string', // can be undefined (note the ? in key)
  'withDefault': 'number = 3000', // default value
})

String Validations

type({
  email: 'string.email',
  apiUrl: 'string.url',
  token: 'string >= 32', // min length
  uuid: 'string.uuid',
})

Number Validations

type({
  port: 'integer & 1 <= number <= 65535',
  timeout: 'number >= 0',
  positive: 'number > 0',
})

Enums / Unions

type({
  logLevel: '\'debug\' | \'info\' | \'warn\' | \'error\'',
  cacheStrategy: '\'memory\' | \'redis\' | \'none\'',
})

Nested Objects

type({
  public: {
    api: {
      baseUrl: 'string',
      version: 'string',
    },
  },
  redis: {
    host: 'string',
    port: 'number',
  },
})

Arrays

type({
  allowedOrigins: 'string[]',
  ports: 'number[]',
})

Full Example

nuxt.config.ts
import { type } from 'arktype'

export default defineNuxtConfig({
  modules: ['nuxt-safe-runtime-config'],
  safeRuntimeConfig: {
    $schema: type({
      'public': { apiBase: 'string.url', appName: 'string', logLevel: '\'debug\' | \'info\' | \'warn\' | \'error\'' },
      'database': { 'url': 'string', 'poolSize?': 'number' },
      'auth': { jwtSecret: 'string >= 32', sessionTtl: 'number > 0' },
      'smtp?': { host: 'string', port: 'integer > 0', from: 'string.email' },
    }),
  },
})

Note on Standard Schema

ArkType supports Standard Schema natively. The module automatically uses ArkType's ~standard interface for validation and JSON Schema generation.

Copyright © 2026