Skip to content

feat(router): support Arktype schema validation#44

Merged
halvaradop merged 3 commits intomasterfrom
feat/add-arktype-support
May 7, 2026
Merged

feat(router): support Arktype schema validation#44
halvaradop merged 3 commits intomasterfrom
feat/add-arktype-support

Conversation

@halvaradop
Copy link
Copy Markdown
Member

@halvaradop halvaradop commented May 7, 2026

Description

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

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

  • request body
  • route parameters
  • search parameters

Changes

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

TypeScript Limitation

Note

During the implementation of this feature, some type definitions triggered the following TypeScript compiler error:

TS2589: Type instantiation is excessively deep and possibly infinite

A follow-up pull request will focus on reducing type complexity and improving inference stability for deeply nested generic types.


Usage

import { type } from "arktype"

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

const credentials = createEndpoint(
  "POST",
  "/auth/credentials",
  (ctx) => {
    return Response.json({
      body: ctx.body,
    })
  },
  {
    schemas: {
      body: type({
        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",
  },
})

@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

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

Project Deployment Actions Updated (UTC)
router Ready Ready Preview, Comment May 7, 2026 11:37pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack

Warning

Rate limit exceeded

@halvaradop has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 45 minutes and 15 seconds 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: d758b9e1-51f2-45ca-bf77-8f8003409862

📥 Commits

Reviewing files that changed from the base of the PR and between ad34dc4 and 974a4f8.

📒 Files selected for processing (4)
  • src/assert.ts
  • src/types.ts
  • src/validator/registry.ts
  • test/endpoint.test.ts
📝 Walkthrough

Walkthrough

This PR extends router schema support to ArkType by adding ArkType as an optional peer dependency, exporting a runtime type guard, updating conditional type inference to branch on ArkType Type instances, implementing ArkType validation in the registry, and adding corresponding test coverage.

Changes

ArkType Schema Support

Layer / File(s) Summary
Dependencies & Type Guards
package.json, src/assert.ts
ArkType added as optional peer dependency; isArkType type guard exported to detect ArkType schemas by checking for allows and assert properties.
Type System Extension
src/types.ts
EndpointSchemas accepts ArkType Type<{}> for body, searchParams, and params; ContextSearchParams, ContextBody, and ContextParams now branch on ArkType to infer contained types via ToInferArktype helper; MiddlewareFunction return type union and InferMethod signature updated.
Runtime Validation Integration
src/validator/registry.ts
createValidator imports and uses isArkType to detect ArkType schemas; validation branch calls the type as a function, returning error when result is an Error, otherwise returning the parsed value.
Test Coverage
test/client.test.ts, test/endpoint.test.ts
Client type inference test added for ArkType-based route schemas; Valibot body schema tests reorganized for structural clarity.
Compiler Configuration
tsconfig.json
noErrorTruncation compiler option enabled for full error message display.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • aura-stack-ts/router#43: Adds support for Valibot schema library with parallel changes to type system, validators, type guards, and test coverage.

Poem

🐰 A rabbit hops through schema lands,
With Zod and Valibot close at hand,
But ArkType arrived one day,
And now three paths the types can play!
Types infer, validators dance,
In harmony's delightful stance.

🚥 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 directly summarizes the main objective of the pull request: adding support for Arktype schema validation across the router codebase.
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/add-arktype-support

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.

Comment thread src/assert.ts Fixed
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
test/client.test.ts (1)

413-483: 🏗️ Heavy lift

Type-level tests added, but runtime validation coverage is missing for ArkType.

The new test block only exercises expectTypeOf assertions. There are no runtime tests verifying that ArkType schemas actually reject invalid payloads (e.g., missing required fields returning 422) — the class of test present in test/endpoint.test.ts for Zod and Valibot ("With valid body" / "With invalid body").

Given the critical validator bug flagged above (all ArkType validations currently succeed), runtime tests would have caught this immediately. Consider adding a parallel describe block in test/endpoint.test.ts covering ArkType body, searchParams, and params — both valid and invalid inputs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/client.test.ts` around lines 413 - 483, Add runtime tests for ArkType
like the existing Zod/Valibot tests: create a new describe block in
test/endpoint.test.ts that uses createEndpoint with schemas: type(...) (for
params, body, searchParams) and createRouter/createClient to exercise valid and
invalid payloads; for each endpoint assert valid inputs return success
(200/expected JSON) and invalid inputs return 422 (or the same error shape used
by other validators). Use the same patterns and helper functions as the existing
`"With valid body"` / `"With invalid body"` tests so ArkType validations for
createEndpoint, createRouter and createClient (and the type(...) schemas) are
exercised at runtime.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/types.ts`:
- Line 5: Change the import to a type-only import so bundlers don't emit a
runtime dependency: replace the value import of Type with a TypeScript type
import (e.g., use "import type { Type } from 'arktype'") in src/types.ts; this
preserves all uses of the Type symbol in interfaces/conditional/mapped types
(where it's only used in type positions) and prevents a MODULE_NOT_FOUND for
consumers who don't have arktype installed.

In `@src/validator/registry.ts`:
- Around line 32-37: The check `parsed instanceof Error` in the isArkType branch
is wrong because ArkErrors are arrays, not Error instances; change the failure
detection to detect ArkErrors (e.g., use duck-typing on the required `summary`
property) instead of instanceof Error so invalid parses return { success: false,
... }. Update the block around isArkType/schema(data)/parsed to treat parsed as
an error when parsed != null && typeof (parsed as any).summary === 'string' (or,
if you prefer, use parsed instanceof schema.errors when that constructor is
available) and return the appropriate { success: false, data: null, error:
parsed } vs { success: true, data: parsed as T, error: null } accordingly.

In `@test/endpoint.test.ts`:
- Around line 171-215: Remove the duplicated test block for describe("Valibot
body schema", ...) that re-defines the same endpoint and tests twice; locate the
duplicate block that constructs the endpoint via createEndpoint(...), wires it
into const { POST } = createRouter([endpoint]) and contains the two tests "With
valid body" and "With invalid body", and delete that entire repeated block so
only the original test (the first describe containing createEndpoint,
createRouter and the two POST tests) remains.

---

Nitpick comments:
In `@test/client.test.ts`:
- Around line 413-483: Add runtime tests for ArkType like the existing
Zod/Valibot tests: create a new describe block in test/endpoint.test.ts that
uses createEndpoint with schemas: type(...) (for params, body, searchParams) and
createRouter/createClient to exercise valid and invalid payloads; for each
endpoint assert valid inputs return success (200/expected JSON) and invalid
inputs return 422 (or the same error shape used by other validators). Use the
same patterns and helper functions as the existing `"With valid body"` / `"With
invalid body"` tests so ArkType validations for createEndpoint, createRouter and
createClient (and the type(...) schemas) are exercised at runtime.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe9357ed-839c-43d1-af3e-44ed5687ffa9

📥 Commits

Reviewing files that changed from the base of the PR and between 5407fa9 and ad34dc4.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • package.json
  • src/assert.ts
  • src/types.ts
  • src/validator/registry.ts
  • test/client.test.ts
  • test/endpoint.test.ts
  • tsconfig.json

Comment thread src/types.ts Outdated
Comment thread src/validator/registry.ts
Comment thread test/endpoint.test.ts Outdated
@halvaradop halvaradop merged commit 1654e27 into master May 7, 2026
6 checks passed
@halvaradop halvaradop deleted the feat/add-arktype-support branch May 7, 2026 23:55
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