feat(router): support Arktype schema validation#44
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis 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 ChangesArkType Schema Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
test/client.test.ts (1)
413-483: 🏗️ Heavy liftType-level tests added, but runtime validation coverage is missing for ArkType.
The new test block only exercises
expectTypeOfassertions. 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 intest/endpoint.test.tsfor 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
describeblock intest/endpoint.test.tscovering 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
package.jsonsrc/assert.tssrc/types.tssrc/validator/registry.tstest/client.test.tstest/endpoint.test.tstsconfig.json
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:
Changes
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 infiniteA follow-up pull request will focus on reducing type complexity and improving inference stability for deeply nested generic types.
Usage