Skip to content

Conversation

@unnoq
Copy link
Member

@unnoq unnoq commented Jul 1, 2025

Closes: https://github.com/unnoq/orpc/issues/709

Summary by CodeRabbit

  • New Features

    • Introduced a configurable ORPCModule for NestJS, enabling centralized setup of error interceptors and event stream keep-alive intervals.
    • Expanded main exports to include new configuration and lifecycle hooks for greater flexibility.
    • Added comprehensive documentation and usage examples for configuring oRPC contracts in NestJS.
  • Bug Fixes

    • None.
  • Tests

    • Added new test case to verify integration and configuration of ORPCModule within a NestJS application.
  • Chores

    • Updated build and TypeScript configurations to support experimental decorators and improved build processes in both the core package and playground.
    • Updated playground scripts and dependencies for streamlined preview and build.

@vercel
Copy link

vercel bot commented Jul 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2025 9:33am

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 1, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 1, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces a configurable NestJS module (ORPCModule) for oRPC contract integration, allowing global error interception and event stream configuration. The implementation includes new exports, documentation, build configurations, and a test verifying module-level configuration and error handling. The playground and build scripts are updated to use the new module and configuration.

Changes

File(s) Change Summary
packages/nest/src/module.ts, packages/nest/src/implement.ts, packages/nest/src/index.ts Introduced ORPCModule with configuration, updated ImplementInterceptor to use injected config, expanded exports.
packages/nest/src/implement.test.ts Added test for integration of ORPCModule.forRoot and error interceptor.
apps/content/docs/openapi/integrations/implement-contract-in-nest.md Added documentation for module-level configuration with usage examples and explanations.
packages/nest/build.config.ts, playgrounds/nest/build.config.ts Added/updated build configuration files to support experimental decorators and new build process.
packages/nest/tsconfig.json Enabled emitDecoratorMetadata for decorator support.
playgrounds/nest/package.json Modified preview script to use unbuild, removed tsx, added unbuild dependency.
playgrounds/nest/src/app.module.ts Updated to import and configure ORPCModule with error interceptor and keep-alive interval.

Sequence Diagram(s)

sequenceDiagram
    participant AppModule
    participant ORPCModule
    participant ImplementInterceptor
    participant onErrorInterceptor
    participant ClientRequest
    participant sendStandardResponse

    AppModule->>ORPCModule: import ORPCModule.forRoot({ onError, eventIteratorKeepAliveInterval })
    ORPCModule->>ImplementInterceptor: Inject config
    ClientRequest->>ImplementInterceptor: intercept(request)
    ImplementInterceptor->>onErrorInterceptor: handle error (if occurs)
    ImplementInterceptor->>sendStandardResponse: send response with config
Loading

Assessment against linked issues

Objective Addressed Explanation
Allow module-level configuration for error handling and response customization in NestJS oRPC integration (#709)
Provide ability to attach zod errors or custom error data globally via interceptors (#709)
Update documentation to show how to configure error handling and keep-alive settings in NestJS (#709)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

  • unnoq/orpc#480: Introduced the foundational NestJS integration for oRPC contracts, which this PR extends with configuration and testing.
  • unnoq/orpc#243: Added exports of hook utilities (onError, etc.) in the client package, related to the expanded exports in this PR.

Suggested labels

size:L

Poem

A module hops in, with config so neat,
Error interceptors make debugging a treat.
Decorators enabled, responses refined,
Now Zod errors are easy to find.
With tests and docs, the path is clear—
oRPC in Nest, let’s give a cheer! 🐇✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 enhances the @orpc/nest module by adding configuration options through a new ORPCModule. This allows developers to configure interceptors and event iterator keep-alive intervals, providing more control over the behavior of oRPC services within NestJS applications. The changes include updates to documentation, build configurations, and testing to ensure the new module functions as expected.

Highlights

  • Module Configuration: Introduces ORPCModule for configuring the @orpc/nest module in NestJS applications, allowing the use of interceptors and setting the event iterator keep-alive interval.
  • Interceptor Implementation: Implements ImplementInterceptor to intercept requests and responses, using the configuration provided via ORPCModule.
  • Build Configuration: Updates build configurations to enable experimental decorators and adjust output settings.
  • Testing: Adds a test case to verify the functionality of ORPCModule.forRoot with interceptors.
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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 the ability to configure the @orpc/nest module using ORPCModule.forRoot(), enabling the setting of global interceptors and other options. The implementation adheres to NestJS patterns for dynamic modules, including documentation, tests, and a playground example. The review focuses on ensuring null safety when accessing the module configuration.

@codecov
Copy link

codecov bot commented Jul 1, 2025

Codecov Report

Attention: Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/nest/src/index.ts 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 1, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@710

@orpc/client

npm i https://pkg.pr.new/@orpc/client@710

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@710

@orpc/experimental-durable-event-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-event-iterator@710

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@710

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@710

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@710

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@710

@orpc/react

npm i https://pkg.pr.new/@orpc/react@710

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@710

@orpc/server

npm i https://pkg.pr.new/@orpc/server@710

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@710

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@710

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@710

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@710

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@710

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@710

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@710

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@710

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@710

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@710

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@710

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@710

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@710

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@710

commit: c944f38

Copy link

@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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d636350 and a1136f1.

📒 Files selected for processing (10)
  • apps/content/docs/openapi/integrations/implement-contract-in-nest.md (1 hunks)
  • packages/nest/build.config.ts (1 hunks)
  • packages/nest/src/implement.test.ts (2 hunks)
  • packages/nest/src/implement.ts (5 hunks)
  • packages/nest/src/index.ts (1 hunks)
  • packages/nest/src/module.ts (1 hunks)
  • packages/nest/tsconfig.json (1 hunks)
  • playgrounds/nest/build.config.ts (1 hunks)
  • playgrounds/nest/package.json (2 hunks)
  • playgrounds/nest/src/app.module.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
playgrounds/nest/src/app.module.ts (2)
packages/nest/src/module.ts (1)
  • Module (15-31)
packages/nest/src/index.ts (1)
  • onError (6-6)
🪛 GitHub Actions: CI
playgrounds/nest/package.json

[error] 1-1: pnpm install failed due to outdated lockfile. The pnpm-lock.yaml is not up to date with package.json. Dependencies added: unbuild@^3.5.0, removed: tsx@^4.20.3. Use 'pnpm install --no-frozen-lockfile' to bypass.

🪛 Biome (1.9.4)
packages/nest/src/module.ts

[error] 16-31: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)

🔇 Additional comments (15)
packages/nest/tsconfig.json (1)

4-4: LGTM! Essential TypeScript configuration for NestJS decorators.

The addition of emitDecoratorMetadata: true is necessary for NestJS's dependency injection system to work properly with decorators and metadata reflection.

packages/nest/build.config.ts (1)

1-13: Well-structured build configuration for decorator support.

The unbuild configuration correctly enables experimental decorators support, which aligns with the TypeScript configuration changes and is essential for building the NestJS integration.

playgrounds/nest/package.json (1)

6-6: Script update aligns with new build configuration.

The change from tsx to unbuild with the .mjs extension is consistent with the new build configuration using unbuild.

playgrounds/nest/src/app.module.ts (1)

8-8: Import statement looks good.

The imports correctly bring in the necessary exports from the nest package.

packages/nest/src/index.ts (2)

3-3: Essential export for module functionality.

Adding the module export makes the ORPCModule and related types available for external use, which is necessary for the NestJS integration.


6-6: Comprehensive lifecycle event handler exports.

The addition of onError, onFinish, onStart, and onSuccess exports provides users with all necessary lifecycle hooks for configuring interceptors, as demonstrated in the playground usage.

playgrounds/nest/build.config.ts (1)

1-18: LGTM! Clean build configuration for the playground.

The unbuild configuration is well-structured and correctly enables TypeScript experimental decorators support, which aligns with the NestJS decorators used in the module implementation.

apps/content/docs/openapi/integrations/implement-contract-in-nest.md (1)

223-250: Excellent documentation addition!

The new Configuration section provides clear guidance on module setup with practical examples. The explanatory notes about interceptors and event iterator keep-alive are particularly helpful for users.

packages/nest/src/implement.test.ts (2)

7-14: Good addition of test infrastructure.

The spy on sendStandardResponse and the import of StandardServerNode provide the necessary testing infrastructure for verifying module configuration integration.


384-414: Comprehensive test coverage for module integration.

The test effectively verifies that:

  • The module configuration is properly injected and used
  • HTTP behavior remains unchanged
  • Interceptors are called correctly
  • Configuration options are passed to sendStandardResponse

This ensures the module integration works as expected.

packages/nest/src/implement.ts (3)

11-12: Proper imports for module integration.

The addition of ORPCModuleConfig type and ORPC_MODULE_CONFIG_SYMBOL imports correctly supports the dependency injection pattern.

Also applies to: 22-22


102-107: Excellent dependency injection implementation.

The @Injectable() decorator and constructor properly implement NestJS dependency injection patterns. Using @Optional() for the config ensures the interceptor works both with and without module configuration.


135-135: Correct configuration integration.

The injected configuration is properly passed to both createProcedureClient and sendStandardResponse, enabling module-level configuration to affect procedure behavior and response handling.

Also applies to: 160-160

packages/nest/src/module.ts (2)

8-13: Well-designed configuration interface and symbol.

The ORPC_MODULE_CONFIG_SYMBOL provides proper type safety for dependency injection, and ORPCModuleConfig correctly extends the necessary option interfaces for comprehensive configuration support.


15-31: Proper NestJS dynamic module implementation.

The forRoot method follows NestJS conventions perfectly:

  • Returns a proper dynamic module configuration
  • Registers configuration and interceptor as providers
  • Exports necessary providers for dependency injection
  • global: true is appropriate for this type of infrastructure module

The static analysis hint about avoiding static-only classes is a false positive here - this is the standard and expected pattern for NestJS dynamic modules.

@unnoq unnoq requested a review from Copilot July 1, 2025 13:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a configurable ORPCModule for NestJS, allowing centralized setup of lifecycle interceptors and event-stream keep-alive intervals, and updates related build and playground configurations.

  • Add ORPCModule.forRoot(...) to playground to demonstrate module configuration.
  • Implement ORPCModuleConfig injection in the interceptor and wire it through createProcedureClient and sendStandardResponse.
  • Update build scripts (unbuild), TypeScript configs, exports, and add a test verifying the new module API.

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
playgrounds/nest/src/app.module.ts Import and configure ORPCModule.forRoot with error interceptor and keep-alive interval
playgrounds/nest/package.json Update preview script to use unbuild and node dist/main.mjs; remove tsx dependency
playgrounds/nest/build.config.ts Add Unbuild configuration for experimental decorators
packages/nest/tsconfig.json Enable emitDecoratorMetadata to support decorator metadata
packages/nest/src/module.ts Define ORPCModule, symbol, and config interface
packages/nest/src/index.ts Export the new module and re-export additional lifecycle hooks
packages/nest/src/implement.ts Inject ORPCModuleConfig into ImplementInterceptor and pass it to client and response functions
packages/nest/src/implement.test.ts Add test for ORPCModule.forRoot, spying on sendStandardResponse
packages/nest/build.config.ts Add Unbuild configuration for the Nest package
apps/content/docs/.../implement-contract-in-nest.md Document ORPCModule.forRoot usage and config options
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)

packages/nest/src/implement.ts:12

  • The interceptor class uses NestInterceptor, ExecutionContext, and CallHandler types but they aren't imported. Please add NestInterceptor, ExecutionContext, and CallHandler to the import from '@nestjs/common'.
import { applyDecorators, Delete, Get, Head, Inject, Injectable, Optional, Patch, Post, Put, UseInterceptors } from '@nestjs/common'

packages/nest/src/implement.test.ts:390

  • The test uses eventIteratorKeepAliveComment, but the module API expects eventIteratorKeepAliveInterval. Rename this property to match the actual config option.
          eventIteratorKeepAliveComment: '__TEST__',

@unnoq unnoq merged commit 3d8a81d into main Jul 2, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI Contract First Error Question

1 participant