-
-
Notifications
You must be signed in to change notification settings - Fork 127
feat(trpc): trpc router to orpc router #699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis change introduces a new Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant tRPCRouter
participant toORPCRouter
participant ORPCRouter
App->>tRPCRouter: Define router with procedures and metadata
App->>toORPCRouter: Call experimental_toORPCRouter(tRPCRouter)
toORPCRouter->>tRPCRouter: Traverse procedures and sub-routers
toORPCRouter->>ORPCRouter: Convert each procedure and metadata
toORPCRouter-->>App: Return ORPCRouter
App->>ORPCRouter: Use router (procedures, OpenAPI, etc.)
Possibly related PRs
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 new @orpc/trpc package that allows developers to convert existing tRPC routers into oRPC routers. This conversion enables the use of oRPC's features, such as OpenAPI specification generation and request handling, within tRPC applications. The pull request also includes documentation to guide users through the integration process.
Highlights
- tRPC to oRPC Conversion: Introduces a function to convert tRPC routers to oRPC routers, enabling the use of oRPC features like OpenAPI specification generation and request handling in tRPC applications.
- Documentation: Adds documentation on how to integrate oRPC with tRPC, including installation instructions, OpenAPI support, and error formatting.
- Package Creation: Creates a new
@orpc/trpcpackage to bridge tRPC and oRPC functionality.
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 is currently in preview and 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 to provide feedback.
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. ↩
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new @orpc/trpc package that bridges tRPC and oRPC, allowing the conversion of tRPC routers to oRPC routers. The changes include adding a new documentation page, updating package dependencies, and implementing the core conversion logic in to-orpc-router.ts. The review focuses on improving the clarity of route assignment and enhancing error handling by preserving stack traces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
packages/trpc/.gitignore (1)
1-5: Over-broad “dot-file” ignore may hide wanted config
.*ignores every hidden file except.gitignore/.*.example.
That will unintentionally hide useful project files such as:
.npmrc– registry auth / config.eslintrc,.prettierrc– linter & formatter rules.pnp.*– Yarn PnPConsider whitelisting the config files you do want committed instead of a blanket ignore:
.* # current – too broad +.* # keep default +!.npmrc +!.eslintrc* +!.prettierrc* +!.pnp.*packages/trpc/README.md (1)
1-6: Invalid HTML tag<image>— switch to standard<img>GitHub markdown does not recognise
<image>; the logo will not render.-<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" /> +<img align="center" src="https://orpc.unnoq.com/logo.webp" width="280" alt="oRPC logo" />You can also remove the empty
<h1></h1>which adds useless vertical space.apps/content/docs/openapi/integrations/trpc.md (1)
80-97: 404 fallback example slightly misleading
handler.handle()already returns{ matched: boolean; response?: Response }.
Whenmatchedis false,responseisundefined. The example ignoresmatched; you can simplify:-const { matched, response } = await handler.handle(request, { … }) - -return response ?? new Response('Not Found', { status: 404 }) +const { response } = await handler.handle(request, { … }) +return response ?? new Response('Not Found', { status: 404 })Or log
matchedfor debugging.packages/trpc/src/to-orpc-router.ts (1)
7-41: Consider documenting the experimental status of the API.All exported APIs are prefixed with
experimental_, indicating they may change in future versions. Consider adding JSDoc comments to warn users about the unstable nature of these APIs.+/** + * @experimental This API is experimental and may change in future versions. + */ export interface experimental_ORPCMeta extends ORPC.Route { } +/** + * @experimental This API is experimental and may change in future versions. + */ export type experimental_ToORPCRouterResult<TContext extends ORPC.Context, TMeta extends ORPC.Meta, TRecord extends Record<string, any>> +/** + * @experimental This API is experimental and may change in future versions. + * Converts a tRPC router to an ORPC-compatible router. + */ export function experimental_toORPCRouter<T extends AnyRouter>(
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
apps/content/.vitepress/config.ts(2 hunks)apps/content/docs/openapi/integrations/trpc.md(1 hunks)packages/trpc/.gitignore(1 hunks)packages/trpc/README.md(1 hunks)packages/trpc/package.json(1 hunks)packages/trpc/src/to-orpc-router.test-d.ts(1 hunks)packages/trpc/src/to-orpc-router.test.ts(1 hunks)packages/trpc/src/to-orpc-router.ts(1 hunks)packages/trpc/tests/shared.ts(1 hunks)packages/trpc/tsconfig.json(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/trpc/src/to-orpc-router.test-d.ts (3)
packages/trpc/tests/shared.ts (3)
trpcRouter(14-65)TRPCMeta(7-10)TRPCContext(6-6)packages/server/src/router.ts (2)
Router(12-17)InferRouterInitialContext(21-23)packages/server/src/procedure.ts (1)
Procedure(55-71)
packages/trpc/src/to-orpc-router.test.ts (6)
packages/trpc/tests/shared.ts (1)
trpcRouter(14-65)packages/server/src/procedure.ts (1)
isProcedure(75-87)packages/server/src/lazy.ts (1)
unlazy(42-44)packages/contract/tests/shared.ts (2)
inputSchema(6-6)outputSchema(8-8)packages/shared/src/iterator.ts (1)
isAsyncIteratorObject(4-10)packages/server/src/router-client.ts (1)
createRouterClient(27-69)
packages/trpc/tests/shared.ts (1)
packages/contract/tests/shared.ts (2)
inputSchema(6-6)outputSchema(8-8)
packages/trpc/src/to-orpc-router.ts (4)
packages/server/src/context.ts (1)
Context(1-1)packages/server/src/procedure.ts (2)
AnyProcedure(73-73)Procedure(55-71)packages/server/src/router.ts (1)
AnyRouter(19-19)packages/shared/src/object.ts (1)
isTypescriptObject(44-46)
🪛 LanguageTool
packages/trpc/README.md
[misspelling] ~33-~33: Possible spelling mistakes found.
Context: ...y (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more. - 🚀 Server Actions: Ful...
(EN_MULTITOKEN_SPELLING_TWO)
[style] ~51-~51: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... your API or implement API contract. - [@orpc/client](https://www.npmjs.com/package/@...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~52-~52: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... API on the client with type-safety. - [@orpc/openapi](https://www.npmjs.com/package/...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~53-~53: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...I specs and handle OpenAPI requests. - [@orpc/nest](https://www.npmjs.com/package/@or...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~54-~54: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... with NestJS. - [@orpc/react](https://www.npmjs.com/package/@o...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~55-~55: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...with React and React Server Actions. - [@orpc/tanstack-query](https://www.npmjs.com/p...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~56-~56: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...stack.com/query/latest) integration. - [@orpc/vue-colada](https://www.npmjs.com/packa...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[misspelling] ~56-~56: Possible spelling mistakes found.
Context: ...ge/@orpc/vue-colada): Integration with Pinia Colada. - [@or...
(EN_MULTITOKEN_SPELLING_TWO)
[style] ~57-~57: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ada](https://pinia-colada.esm.dev/). - [@orpc/hey-api](https://www.npmjs.com/package/...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~58-~58: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...I](https://heyapi.dev/) integration. - [@orpc/zod](https://www.npmjs.com/package/@orp...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~59-~59: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...tps://zod.dev/) doesn't support yet. - [@orpc/valibot](https://www.npmjs.com/package/...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~60-~60: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...rom Valibot. - [@orpc/arktype](https://www.npmjs.com/package/...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
🪛 markdownlint-cli2 (0.17.2)
packages/trpc/README.md
70-70: Images should have alternate text (alt text)
null
(MD045, no-alt-text)
🪛 GitHub Check: codecov/patch
packages/trpc/src/to-orpc-router.ts
[warning] 105-106: packages/trpc/src/to-orpc-router.ts#L105-L106
Added lines #L105 - L106 were not covered by tests
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: publish-commit
- GitHub Check: lint
🔇 Additional comments (10)
packages/trpc/tsconfig.json (1)
1-15: Type-checking options inherited — confirmcomposite& declaration outputs are enabledThe file only sets
extends,references,include, andexclude.
If the parent../../tsconfig.lib.jsondoes not enablecompilerOptions.composite: trueand output destinations (declaration,declarationMap,outDir), the build withtsc -bwill fail to emit or reference artefacts for the packages you list underreferences.Please double-check that the base config already contains:
{ "compilerOptions": { "composite": true, "declaration": true, "declarationMap": true } }and that it places the emitted files outside
src(otherwise they are picked up again by this project).If the base config does include them, you’re good to go.
Otherwise add an override block here.apps/content/.vitepress/config.ts (2)
158-163: Duplicated sidebar entry & cross-section link targetYou add the new item under the regular docs sidebar:
{ text: 'tRPC', link: '/docs/openapi/integrations/trpc' },The same link is also added in the OpenAPI sidebar (↓ line 225).
Showing the OpenAPI page inside the non-OpenAPI docs tree can be confusing and may create two active-match states.Confirm this is intentional; otherwise point
/docs/…to a dedicated intro page (or omit).
223-227: Side-by-side ordering looks goodThe OpenAPI subsection gets the tRPC entry in the expected alphabetical position – no issues.
packages/trpc/README.md (1)
30-41: Minor spelling & repetition flagged by linter – low priorityLanguageTool warns about “Succesive sentences begin with the same word” and potential multi-token spelling issues.
Content is understandable, so feel free to ignore or polish later.apps/content/docs/openapi/integrations/trpc.md (1)
41-49: Import alias may not match published APISample uses:
import { experimental_ORPCMeta as ORPCMeta, experimental_toORPCRouter as toORPCRouter } from '@orpc/trpc'Double-check that the package actually re-exports
experimental_ORPCMeta(singular) andexperimental_toORPCRouter.
If the public names areexperimental_ORPCMetaBuilder/toORPCRouter(or already stable), the snippet will break copy-paste.packages/trpc/package.json (1)
1-48: LGTM!The package.json is well-structured with appropriate dependencies, export configuration, and build scripts.
packages/trpc/src/to-orpc-router.test-d.ts (1)
1-44: LGTM!Comprehensive type-level tests that verify the correctness of the TRPC to ORPC router type transformation.
packages/trpc/src/to-orpc-router.test.ts (1)
1-76: LGTM!Comprehensive runtime tests covering shape validation, schema handling, metadata preservation, procedure invocation, error mapping, and lazy loading.
packages/trpc/tests/shared.ts (1)
1-65: LGTM!Well-designed test fixture that covers various TRPC router patterns including queries, subscriptions, nested routes, and lazy loading.
packages/trpc/src/to-orpc-router.ts (1)
96-106: ```shell
#!/bin/bash
set -eLocate any test files covering toORPCRouter
rg -l "toORPCRouter" -g "*.test.ts" || echo "No toORPCRouter tests found"
Search within those tests for custom Error throws to cover non-TRPCError path
rg -n "new Error" -g "*.test.ts" || echo "No tests throwing generic Error found"
</details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (2)
packages/trpc/src/to-orpc-router.ts (2)
86-86: Therouteproperty assignment needs clarification.As previously noted, assigning
metato therouteproperty may not be the intended behavior.
102-107: Consider preserving the original error stack trace.Including the original TRPCError as the cause would aid in debugging.
🧹 Nitpick comments (2)
packages/trpc/src/to-orpc-router.ts (2)
7-10: Document the purpose of the emptyexperimental_ORPCMetainterface.The interface extends
ORPC.Routebut has no additional properties. Consider adding a comment explaining its purpose as a placeholder for future extensions or remove it if not needed.+/** + * Metadata interface for ORPC routers converted from tRPC. + * Currently serves as a placeholder that extends ORPC.Route. + * Additional metadata properties can be added here in the future. + */ export interface experimental_ORPCMeta extends ORPC.Route { }
45-45: Consider removing theas anytype assertion for better type safety.The type assertion could hide potential type mismatches. Consider ensuring the return type matches through proper typing or add a comment explaining why the assertion is necessary.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/trpc/src/to-orpc-router.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/trpc/src/to-orpc-router.ts (4)
packages/server/src/context.ts (1)
Context(1-1)packages/server/src/procedure.ts (2)
AnyProcedure(73-73)Procedure(55-71)packages/server/src/router.ts (1)
AnyRouter(19-19)packages/shared/src/object.ts (1)
isTypescriptObject(44-46)
🪛 GitHub Check: codecov/patch
packages/trpc/src/to-orpc-router.ts
[warning] 110-111: packages/trpc/src/to-orpc-router.ts#L110-L111
Added lines #L110 - L111 were not covered by tests
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: publish-commit
- GitHub Check: lint
🔇 Additional comments (3)
packages/trpc/src/to-orpc-router.ts (3)
48-61: LGTM!The lazy router conversion correctly wraps tRPC lazy routers with ORPC's lazy loading mechanism.
116-142: LGTM!The function correctly disables validation with proper documentation explaining the rationale. The proxy implementation safely overrides the validate method while preserving other properties.
110-111: ```shell
#!/bin/bashRe-run with PCRE2 to search for generic throw statements excluding TRPCError
rg --pcre2 -A 10 'throw(?!.*TRPCError)' packages/trpc/src/to-orpc-router.test.ts packages/trpc/tests/
Fallback: look for any test referencing a generic Error
rg -n "new Error" -C3 packages/trpc/src/to-orpc-router.test.ts packages/trpc/tests/
</details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Summary by CodeRabbit
New Features
@orpc/trpc, enabling integration between oRPC and tRPC applications.Tests
Chores