Skip to content

feat(router): support Typebox schema validation#48

Merged
halvaradop merged 2 commits into
masterfrom
feat/support-typebox
May 12, 2026
Merged

feat(router): support Typebox schema validation#48
halvaradop merged 2 commits into
masterfrom
feat/support-typebox

Conversation

@halvaradop
Copy link
Copy Markdown
Member

@halvaradop halvaradop commented May 12, 2026

Description

This pull request adds ArkType schema validation support alongside the existing Zod, Valibot and Arktype integrations.

Aura Router now supports three schema validation libraries for endpoint validation across:

  • request body
  • route parameters
  • search parameters

Changes

  • Add Typebox schema validation support
  • Extend endpoint schema compatibility to support:
    • Zod
    • Valibot
    • ArkType
    • Typebox
  • Preserve type inference across router and client APIs

Usage

import { Object, String } from "typebox"

import {
  createEndpoint,
  createRouter,
  createClient,
} from "@aura-stack/router"

const credentials = createEndpoint(
  "POST",
  "/auth/credentials",
  (ctx) => {
    return Response.json({
      body: ctx.body,
    })
  },
  {
    schemas: {
      body: Object({
        username: String(),
        password: String(),
      }),
    },
  }
)

const router = createRouter([credentials])

const client = createClient<typeof router>({
  baseURL: "http://api.example.com",
})

await client.post("/auth/credentials", {
  body: {
    username: "johndoe",
    password: "1234567890",
  },
})

Summary by CodeRabbit

  • New Features

    • Extended validation to support TypeBox schemas for request bodies, search parameters, and route parameters.
    • TypeBox is now available as an optional peer dependency.
  • Tests

    • Added comprehensive test coverage for TypeBox schema validation scenarios.

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
router Ready Ready Preview, Comment May 12, 2026 10:56pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Warning

Rate limit exceeded

@halvaradop has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 27 minutes before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8039eec9-13f7-4a87-b08c-24bb530c57ac

📥 Commits

Reviewing files that changed from the base of the PR and between 4549260 and 45d2afa.

📒 Files selected for processing (5)
  • src/@types/client.ts
  • src/validator/registry.ts
  • test/client.test.ts
  • test/endpoint.test.ts
  • test/type.test-d.ts
📝 Walkthrough

Walkthrough

TypeBox schema validation support is integrated into the endpoint router: peer dependency added, EndpointSchemas interface extended to accept TObject schemas, UnwrapSchema utility infers TypeBox types via Static<>, createValidator validates TypeBox schemas using Check(), and comprehensive test coverage validates both runtime behavior and TypeScript type inference.

Changes

TypeBox Schema Support Integration

Layer / File(s) Summary
Peer dependency and schema type contracts
package.json, src/@types/types.ts
TypeBox is declared as an optional peer dependency at version ^1.1.38. EndpointSchemas interface is updated to accept TObject<{}> schemas for body, searchParams, and params fields, extending the existing ZodObject, ObjectSchema, and Type options.
TypeBox type inference via UnwrapSchema
src/@types/types.ts
UnwrapSchema conditional type is extended to recognize TypeBox TObject inputs and infer their TypeScript output type via Static<S>, while preserving fallback behavior for unsupported schema shapes.
Runtime TypeBox validation in createValidator
src/validator/registry.ts
createValidator is extended to recognize TypeBox object schemas via IsObject() guard and validate request data at runtime using Check(), returning { success: true, data } for valid inputs or { success: false, error } for validation failures.
TypeBox type inference assertions
test/type.test-d.ts
Type assertion tests verify that ContextSearchParams, ContextBody, and ContextParams correctly infer TypeScript types when schemas are provided as TypeBox TObject, TString, and TEnum constructs.
TypeBox endpoint validation tests
test/endpoint.test.ts
Endpoint integration tests validate TypeBox schema validation for request body, searchParams, and route params, asserting both successful validation and 422 responses with validation_error for invalid requests.

Sequence Diagram

sequenceDiagram
  participant Client
  participant createEndpoint as createEndpoint()
  participant UnwrapSchema as UnwrapSchema
  participant createValidator as createValidator()
  participant Check as TypeBox Check()
  participant Handler as Request Handler

  Client->>createEndpoint: request + TObject schemas
  createEndpoint->>UnwrapSchema: infer types from TObject
  UnwrapSchema-->>createEndpoint: Static<TObject> types
  createEndpoint->>createValidator: register TObject schemas
  createValidator->>Check: IsObject(schema)?
  Check-->>createValidator: recognized TypeBox schema
  Client->>Handler: request body/params/searchParams
  Handler->>Check: Check(schema, data)
  Check-->>Handler: valid or validation_error
  Handler-->>Client: success or 422 Unprocessable Entity
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • aura-stack-ts/router#44: Adds schema library support with parallel modifications to EndpointSchemas, UnwrapSchema, createValidator, and comprehensive test coverage.
  • aura-stack-ts/router#43: Extends the validator registry to support an additional schema library (Valibot), modifying createValidator and type inference patterns similarly.

Poem

🐰 TypeBox now hops through our router with care,
With TObject schemas dancing in the air,
Type inference and runtime checks aligned,
Optional peer dependency, perfectly designed,
Tests prove every param and body shines bright! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(router): support Typebox schema validation' accurately and concisely describes the main change—adding Typebox schema validation support to the router, which is clearly reflected across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/support-typebox

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@halvaradop halvaradop merged commit 91bdf04 into master May 12, 2026
6 checks passed
@halvaradop halvaradop deleted the feat/support-typebox branch May 12, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant