Implement key validation in router and enhance schema serializa… - #438
Implement key validation in router and enhance schema serializa…#438freekh wants to merge 6 commits into
Conversation
🦋 Changeset detectedLatest commit: 04dcac9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
We need some UI updates to make sure description looks good for routes |
There was a problem hiding this comment.
Pull request overview
This PR extends the core schema router helper to support explicit key schemas (mirroring s.record(key, value)), enabling constraints like .maxLength(), .regexp(), .validate(), and .describe() to apply to router keys, and updates validation behavior so router pattern errors and key-schema errors can surface together.
Changes:
- Added overloads to
s.router(...)to accept an optional key schema argument and pass it through toRecordSchema. - Updated
RecordSchema.executeValidateto merge router validation errors instead of returning early, allowing additional validation errors to be reported. - Added comprehensive tests for key-schema serialization, key validation, combined error reporting, and serialize/deserialize round-tripping; updated Next example renders to include list selection fields.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/schema/router.ts | Adds s.router(router, keySchema, itemSchema) overload and implementation to forward key schema into RecordSchema. |
| packages/core/src/schema/router.test.ts | Adds coverage for key schema serialization, key validation behaviors, combined error surfacing, and serialize/deserialize round-trip. |
| packages/core/src/schema/record.ts | Changes router-validation handling to merge errors into existing ValidationErrors rather than returning early. |
| examples/next/content/authors.val.ts | Updates list render selection to include image. |
| examples/next/app/blogs/[blog]/page.val.ts | Adds .render({ as: "list", select: ... }) to the router-backed schema in the example. |
| .changeset/router-key-validation.md | Documents the new s.router key validation support in a patch changeset. |
Sub-errors were merged with object spread, which replaces the array of a colliding SourcePath rather than concatenating it. A record validates the key and the item on the same path, so a key with a router error, a key schema error and an item error only reported one of them. Adds a mergeValidationErrors helper next to appendValidationError on Schema and uses it for every merge in record, array and object. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The add and rename popovers only showed the key description when a caller passed it explicitly, so the sitemap's add-route button - which knows the path but not the schema - showed none. Both popovers already resolve the record schema, so fall back to its key description and keep the prop as an override. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Uses the new three-argument s.router form in examples/next so the key description is visible in the editor, and notes the UI change and the validation error merge in the changeset. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Merged Copilot review comment (resolved): validation errors are now merged path-wise via a new "We need some UI updates to make sure description looks good for routes": I deliberately left the Checks run from the repo root: |
…tion