ArkType is a type-first validation library where you write types that look like TypeScript syntax.
npm install arktype
import { type } from 'arktype'
const runtimeConfigSchema = type({
'public': {
'apiBase': 'string',
'appName?': 'string',
},
'databaseUrl': 'string',
'secretKey': 'string',
'port?': 'number',
})
export default defineNuxtConfig({
modules: ['nuxt-safe-runtime-config'],
runtimeConfig: {
databaseUrl: process.env.DATABASE_URL || '',
secretKey: process.env.SECRET_KEY || '',
port: Number.parseInt(process.env.PORT || '3000'),
public: {
apiBase: process.env.NUXT_PUBLIC_API_BASE || 'https://api.example.com',
appName: 'My App',
},
},
safeRuntimeConfig: {
$schema: runtimeConfigSchema,
},
})
type({
required: 'string', // must exist
'optional?': 'string', // can be undefined (note the ? in key)
withDefault: 'number = 3000', // default value
})
type({
email: 'string.email',
apiUrl: 'string.url',
token: 'string >= 32', // min length
uuid: 'string.uuid',
})
type({
port: 'integer & 1 <= number <= 65535',
timeout: 'number >= 0',
positive: 'number > 0',
})
type({
environment: "'development' | 'staging' | 'production'",
logLevel: "'debug' | 'info' | 'warn' | 'error'",
})
type({
public: {
api: {
baseUrl: 'string',
version: 'string',
},
},
redis: {
host: 'string',
port: 'number',
},
})
type({
allowedOrigins: 'string[]',
ports: 'number[]',
})
import { type } from 'arktype'
const runtimeConfigSchema = type({
'public': {
'apiBase': 'string.url',
'appName': 'string',
'environment': "'development' | 'staging' | 'production'",
},
'database': {
'url': 'string',
'poolSize?': 'number',
},
'auth': {
'jwtSecret': 'string >= 32',
'sessionTtl': 'number > 0',
},
'email?': {
'host': 'string',
'port': 'integer > 0',
'from': 'string.email',
},
})
export default defineNuxtConfig({
modules: ['nuxt-safe-runtime-config'],
safeRuntimeConfig: { $schema: runtimeConfigSchema },
})
ArkType supports Standard Schema natively. The module automatically uses ArkType's ~standard interface for validation and JSON Schema generation.