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

    Function schema

    • Creates a typed schema definition for request validation. This is a type helper that preserves schema structure for type inference.

      Type Parameters

      • T extends SchemaDefinition

        Schema definition type

      Parameters

      • definition: T

        Schema definition object

      Returns T

      The same schema definition with preserved types

      import { schema, t } from 'kitojs';

      const userSchema = schema({
      params: t.object({
      id: t.str().uuid()
      }),
      query: t.object({
      limit: t.num().min(1).max(100).default(10)
      }),
      body: t.object({
      name: t.str().min(1),
      email: t.str().email()
      }),
      headers: t.object({
      authorization: t.str()
      })
      });

      app.post('/users/:id', ({ req, res }) => {
      // All request parts are type-safe and validated
      const id = req.params.id; // string (UUID validated)
      const limit = req.query.limit; // number
      const name = req.body.name; // string
      }, userSchema);
    Index

    Methods

    Methods

    • Converts a JSON Schema definition to internal schema format

      Type Parameters

      • T extends JSONSchemaDefinition

        JSON Schema definition type

      Parameters

      • definition: T

        JSON Schema definition object

      Returns SchemaDefinition & { __jsonSchemaInfer: InferJSONSchemaRequest<T> }

      Converted schema definition with preserved types

      import { schema } from 'kitojs';

      const userSchema = schema.json({
      params: {
      type: 'object',
      properties: {
      id: { type: 'string', format: 'uuid' }
      },
      required: ['id']
      },
      body: {
      type: 'object',
      properties: {
      name: { type: 'string', minLength: 1 },
      email: { type: 'string', format: 'email' }
      },
      required: ['name', 'email']
      }
      });

      app.post('/users/:id', ({ req, res }) => {
      // types are inferred from JSON Schema
      const id = req.params.id; // string
      const name = req.body.name; // string
      }, userSchema);