Kito Framework - v1.0.0-alpha.8
    Preparing search index...

    Variable tConst

    t: {
        str(): StringSchema;
        num(): NumberSchema;
        bool(): BooleanSchema;
        array<T extends SchemaType>(item: T): ArraySchema<T>;
        object<T extends Record<string, SchemaType>>(shape: T): ObjectSchema<T>;
        literal<T extends string | number | boolean>(value: T): LiteralSchema<T>;
        union<T extends SchemaType[]>(...schemas: T): UnionSchema<T>;
    } = ...

    Schema builder utilities for creating type-safe request validation schemas.

    Type Declaration

    • str: function
      • Creates a string schema builder.

        Returns StringSchema

        String schema with validation methods

        t.str() // basic string
        t.str().min(3).max(50) // length constraints
        t.str().email() // email validation
        t.str().uuid() // UUID validation
        t.str().optional() // optional field
        t.str().default('hello') // default value
    • num: function
      • Creates a number schema builder.

        Returns NumberSchema

        Number schema with validation methods

        t.num() // basic number
        t.num().min(0).max(100) // range constraints
        t.num().int() // integer only
        t.num().positive() // positive numbers
        t.num().optional() // optional field
        t.num().default(0) // default value
    • bool: function
      • Creates a boolean schema builder.

        Returns BooleanSchema

        Boolean schema with validation methods

        t.bool() // basic boolean
        t.bool().optional() // optional field
        t.bool().default(false) // default value
    • array: function
      • Creates an array schema builder.

        Type Parameters

        • T extends SchemaType

          Type of array items

        Parameters

        • item: T

          Schema for array items

        Returns ArraySchema<T>

        Array schema with validation methods

        t.array(t.str()) // string array
        t.array(t.num().positive()) // array of positive numbers
        t.array(t.object({ name: t.str() })) // array of objects
        t.array(t.str()).min(1).max(10) // length constraints
    • object: function
      • Creates an object schema builder.

        Type Parameters

        • T extends Record<string, SchemaType>

          Object shape definition

        Parameters

        • shape: T

          Object property schemas

        Returns ObjectSchema<T>

        Object schema with validation methods

        t.object({
        name: t.str(),
        age: t.num(),
        email: t.str().email().optional()
        })

        // Nested objects
        t.object({
        user: t.object({
        profile: t.object({
        bio: t.str()
        })
        })
        })
    • literal: function
      • Creates a literal schema for exact value matching.

        Type Parameters

        • T extends string | number | boolean

          Literal value type

        Parameters

        • value: T

          Exact value to match

        Returns LiteralSchema<T>

        Literal schema

        t.literal('admin') // matches only "admin"
        t.literal(42) // matches only 42
        t.literal(true) // matches only true
    • union: function
      • Creates a union schema for multiple possible types.

        Type Parameters

        • T extends SchemaType[]

          Array of possible schema types

        Parameters

        • ...schemas: T

          Schemas to union

        Returns UnionSchema<T>

        Union schema

        // String or number
        t.union(t.str(), t.num())

        // Enum-like literals
        t.union(
        t.literal('admin'),
        t.literal('user'),
        t.literal('guest')
        )

        // Complex types
        t.union(
        t.object({ type: t.literal('user'), name: t.str() }),
        t.object({ type: t.literal('guest') })
        )
    import { t, schema } from 'kitojs';

    const userSchema = schema({
    params: t.object({
    id: t.str().uuid()
    }),
    body: t.object({
    name: t.str().min(1).max(50),
    email: t.str().email(),
    age: t.num().min(0).optional()
    })
    });

    app.post('/users/:id', [userSchema], ctx => {
    // ctx.req.params.id is validated as UUID
    // ctx.req.body is type-safe and validated
    });