Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughIntroduces a client-side RequestValidationPlugin for contract-driven requests, exports it publicly, adds tests for validation and error cases, and updates documentation and site navigation with a new “Request Validation” docs page. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant UI as Client Code
participant CL as Client Link (StandardLink)
participant RV as RequestValidationPlugin
participant NX as Next Interceptors
participant DS as Downstream (Transport/Server)
UI->>CL: call(path, input)
activate CL
CL->>RV: intercept(path, input)
activate RV
alt Contract path found
alt Procedure has inputSchema
RV->>RV: validate(input)
alt Validation passes
RV-->>NX: next(path, input)
activate NX
NX-->>DS: forward(path, input)
DS-->>NX: response
NX-->>UI: response
deactivate NX
else Validation fails
RV-->>UI: throw ORPCError(BAD_REQUEST, issues)
end
else No inputSchema
RV-->>NX: next(path, input)
activate NX
NX-->>DS: forward(path, input)
DS-->>NX: response
NX-->>UI: response
deactivate NX
end
else No matching contract procedure
RV-->>UI: throw RequestValidationPluginError
end
deactivate RV
deactivate CL
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
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.
Summary of Changes
Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a significant new feature: the RequestValidationPlugin for the oRPC contract library. This plugin empowers developers to perform client-side validation of request payloads against their defined contract schemas, thereby enhancing data integrity and reducing the load on server-side validation. The changes encompass the plugin's core implementation, thorough unit tests to ensure its reliability, and clear, concise documentation to guide users on its setup and usage.
Highlights
- New Request Validation Plugin: Introduced a new
RequestValidationPluginthat enables client-side validation of requests against the defined contract schemas. This plugin intercepts requests and ensures data integrity before reaching the server. - Comprehensive Documentation: Added a new documentation page for the
Request Validation Plugin, detailing its purpose, setup instructions, and practical examples, including how to leverage it for form validation. - Robust Test Coverage: Included extensive unit tests for the
RequestValidationPlugin, covering scenarios such as successful validation, handling of procedures without input schemas, and proper error reporting for invalid inputs or missing contract procedures. - Error Handling: The plugin throws an
ORPCErrorwith aBAD_REQUESTcode when input validation fails, providing detailed issues. It also throws aRequestValidationPluginErrorif a matching procedure is not found in the contract.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces a new RequestValidationPlugin for client-side request validation, which is a great feature for improving application robustness by catching invalid data before it hits the server. The implementation is solid, with good documentation and comprehensive tests covering various scenarios. I have one suggestion to improve the React form validation example in the documentation to follow standard React practices and avoid confusion.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (6)
apps/content/docs/plugins/request-validation.md (2)
10-12: Tighten wording on minified contractsSmall grammar tweak.
-This plugin is best suited for [Contract-First Development](/docs/contract-first/define-contract). [Minified Contract](/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client) is **not supported** because it removes the schema from the contract. +This plugin is best suited for [Contract-First Development](/docs/contract-first/define-contract). [Minified contracts](/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client) are **not supported** because they remove the schema from the contract.
42-47: Make the TSX example standaloneAdd the missing React import so readers can paste‑run.
-```tsx -import { getIssueMessage, parseFormData } from '@orpc/openapi-client/helpers' +```tsx +import { useState } from 'react' +import { getIssueMessage, parseFormData } from '@orpc/openapi-client/helpers'packages/contract/src/plugins/request-validation.ts (1)
53-57: Polish comment grammarMinor clarity edit.
- /** - * we should not use validated input here, - * because validated input maybe is transformed by schema - * leading input no longer matching expected schema - */ + /** + * Do not pass the validated input here, + * because the schema may transform it, + * which could make the original input diverge from expectations downstream. + */packages/contract/src/plugins/request-validation.test.ts (3)
61-61: Avoid async describedescribe callbacks should be synchronous in Vitest/Jest.
-describe('validate input', async () => { +describe('validate input', () => {
86-93: Assert issues is an array for stronger guaranteesThe validator returns a list; assert Array to tighten the contract.
- issues: expect.any(Object), + issues: expect.any(Array),
99-106: Test the intended execution order explicitlyIf the plugin runs first (recommended), the user interceptor shouldn’t be called when validation fails.
- await expect(link.call(['not', 'found'], {}, { context: {} })).rejects.toThrow( + await expect(link.call(['not', 'found'], {}, { context: {} })).rejects.toThrow( new RequestValidationPluginError('No valid procedure found at path "not.found", this may happen when the contract router is not properly configured.'), ) - await expect(interceptor.mock.results[0]?.value).rejects.toThrow( - new RequestValidationPluginError('No valid procedure found at path "not.found", this may happen when the contract router is not properly configured.'), - ) + expect(interceptor).not.toHaveBeenCalled()If your intercept() runs last‑in‑first‑out, keep push() and this test as-is; otherwise switch to unshift() per the plugin comment above and apply this assertion.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/content/.vitepress/config.ts(1 hunks)apps/content/docs/plugins/request-validation.md(1 hunks)packages/contract/src/plugins/index.ts(1 hunks)packages/contract/src/plugins/request-validation.test.ts(1 hunks)packages/contract/src/plugins/request-validation.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/contract/src/plugins/request-validation.ts (4)
packages/client/src/adapters/standard/plugin.ts (1)
StandardLinkPlugin(4-7)packages/contract/src/router.ts (1)
AnyContractRouter(17-17)packages/client/src/adapters/standard/link.ts (1)
StandardLinkOptions(18-22)packages/contract/src/procedure.ts (1)
isContractProcedure(51-66)
packages/contract/src/plugins/request-validation.test.ts (2)
packages/client/src/adapters/standard/link.ts (1)
StandardLink(24-109)packages/contract/src/plugins/request-validation.ts (2)
RequestValidationPlugin(18-61)RequestValidationPluginError(9-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: test
- GitHub Check: publish-commit
- GitHub Check: lint
🔇 Additional comments (3)
apps/content/.vitepress/config.ts (1)
142-142: Sidebar entry LGTMLink path and placement under Plugins look correct.
packages/contract/src/plugins/index.ts (1)
1-1: Export looks goodPublic re‑export enables the documented import path.
apps/content/docs/plugins/request-validation.md (1)
34-36: Confirm OpenAPILink forwards StandardLink plugins at call timeOpenAPILink extends StandardOpenAPILink and creates a LinkFetchClient(options); StandardLinkOptions includes plugins?: StandardLinkPlugin[]. Verify OpenAPILinkOptions accepts a plugins array and that LinkFetchClient / StandardOpenAPILink forward options.plugins into the underlying StandardLink when making calls (see packages/openapi-client/src/adapters/fetch/openapi-link.ts and packages/client/src/adapters/standard/link.ts).
Closes: https://github.com/unnoq/orpc/issues/999
Summary by CodeRabbit
New Features
Documentation
Tests