-
-
Notifications
You must be signed in to change notification settings - Fork 103
feat(nest): Change the nest integration to support Nest features that were competing with Orpc #1149
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
Open
Mathiasduc
wants to merge
4
commits into
unnoq:main
Choose a base branch
from
Mathiasduc:feat/server/nest/add-support-for-nestjs-features
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(nest): Change the nest integration to support Nest features that were competing with Orpc #1149
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f74cf3
feat(server): Change the nest integration to support Nest features th…
Mathiasduc 047a5b7
fixup! feat(server): Change the nest integration to support Nest feat…
Mathiasduc f56f7a0
fixup! feat(server): Change the nest integration to support Nest feat…
Mathiasduc c82d19b
refactor(nest): move test files to tests directory
unnoq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common' | ||
| import type { Response } from 'express' | ||
| import type { FastifyReply } from 'fastify' | ||
| import { Catch, Injectable } from '@nestjs/common' | ||
| import { StandardBracketNotationSerializer, StandardOpenAPIJsonSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard' | ||
| import { StandardOpenAPICodec } from '@orpc/openapi/standard' | ||
| import { ORPCError } from '@orpc/server' | ||
| import * as StandardServerFastify from '@orpc/standard-server-fastify' | ||
| import * as StandardServerNode from '@orpc/standard-server-node' | ||
|
|
||
| const codec = new StandardOpenAPICodec( | ||
| new StandardOpenAPISerializer( | ||
| new StandardOpenAPIJsonSerializer(), | ||
| new StandardBracketNotationSerializer(), | ||
| ), | ||
| ) | ||
|
|
||
| /** | ||
| * Global exception filter that catches ORPCError instances and converts them | ||
| * to standardized oRPC error responses. | ||
| * | ||
| * This filter is optional - you can choose to: | ||
| * 1. Use this filter to get standard oRPC error responses | ||
| * 2. Handle ORPCError in your own custom exception filters | ||
| * 3. Let NestJS default error handling take over | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // Register globally in your app | ||
| * app.useGlobalFilters(new ORPCExceptionFilter()) | ||
| * | ||
| * // Or register as a provider | ||
| * @Module({ | ||
| * providers: [ | ||
| * { | ||
| * provide: APP_FILTER, | ||
| * useClass: ORPCExceptionFilter, | ||
| * }, | ||
| * ], | ||
| * }) | ||
| * export class AppModule {} | ||
| * ``` | ||
| */ | ||
| @Catch(ORPCError) | ||
| @Injectable() | ||
| export class ORPCExceptionFilter implements ExceptionFilter { | ||
| constructor( | ||
| private config?: StandardServerNode.SendStandardResponseOptions | undefined, | ||
| ) {} | ||
|
|
||
| async catch(exception: ORPCError<any, any>, host: ArgumentsHost) { | ||
| const ctx = host.switchToHttp() | ||
| const res = ctx.getResponse<Response | FastifyReply>() | ||
| const standardResponse = codec.encodeError(exception) | ||
| // Send the response directly with proper status and headers | ||
| const isFastify = 'raw' in res | ||
| if (isFastify) { | ||
| await StandardServerFastify.sendStandardResponse(res as FastifyReply, standardResponse, this.config) | ||
| } | ||
| else { | ||
| await StandardServerNode.sendStandardResponse(res as Response, standardResponse, this.config) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm looking for a way to make all codecs extendable. Specifically, I'd like to know if it's possible to add a custom serializer by passing it into the main configuration, similar to the method described for extending native data types.