-
Notifications
You must be signed in to change notification settings - Fork 1
Support fastify #88
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
Support fastify #88
Conversation
WalkthroughThe changes involve modifications to import paths across various files, reflecting a restructuring of the directory layout. New files for Fastify integration with Zod have been introduced, enhancing the application's capabilities. Additionally, adjustments in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant FastifyServer
participant Zod
participant Database
User->>FastifyServer: Sends request (GET /users)
FastifyServer->>Zod: Validates request
Zod-->>FastifyServer: Returns validation result
FastifyServer->>Database: Queries user data
Database-->>FastifyServer: Returns user data
FastifyServer-->>User: Sends response with user data
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (1)
examples/fastify/zod/fetch.ts (1)
33-36: Remove the redundant block statement.The block statement at lines 33-36 doesn't serve any purpose and can be safely removed to simplify the code.
Apply this diff to remove the block statement:
- { - // case-insensitive method example await fetchT(`${origin}/users?page=1`, { method: "GET" }); - }Tools
Biome
[error] 33-36: This block statement doesn't serve any purpose and can be safely removed.
Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.(lint/complexity/noUselessLoneBlockStatements)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
Files selected for processing (11)
- examples/express/valibot/express.ts (1 hunks)
- examples/express/valibot/fetch.ts (1 hunks)
- examples/express/zod/express.ts (1 hunks)
- examples/express/zod/fetch.ts (1 hunks)
- examples/fastify/zod/fastify.ts (1 hunks)
- examples/fastify/zod/fetch.ts (1 hunks)
- examples/spec/valibot.ts (1 hunks)
- examples/spec/zod.ts (1 hunks)
- package.json (5 hunks)
- src/fastify/zod.ts (1 hunks)
- src/zod/index.ts (1 hunks)
Files skipped from review due to trivial changes (4)
- examples/express/valibot/express.ts
- examples/express/zod/express.ts
- examples/express/zod/fetch.ts
- examples/spec/valibot.ts
Additional context used
Biome
examples/fastify/zod/fastify.ts
[error] 51-54: This block statement doesn't serve any purpose and can be safely removed.
Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.(lint/complexity/noUselessLoneBlockStatements)
examples/fastify/zod/fetch.ts
[error] 9-9: Shouldn't redeclare 'JSONT'. Consider to delete it or rename it.
'JSONT' is defined here:
(lint/suspicious/noRedeclare)
[error] 33-36: This block statement doesn't serve any purpose and can be safely removed.
Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.(lint/complexity/noUselessLoneBlockStatements)
Additional comments not posted (19)
examples/spec/zod.ts (2)
2-2: LGTM!The change in the import path reflects a restructuring of the directory layout. It does not impact the functionality of the code.
4-7: LGTM!The change to the
JsonHeaderconstant enhances the flexibility of the definition, accommodating variations in header casing that may occur in API requests. The union type is correctly implemented and does not introduce any issues.src/fastify/zod.ts (4)
1-2: LGTM!The code changes are approved.
4-21: LGTM!The code changes are approved.
23-46: LGTM!The code changes are approved.
47-84: LGTM!The code changes are approved.
examples/fastify/zod/fastify.ts (6)
1-15: LGTM!The code segment correctly sets up a Fastify server with Zod integration for validation and serialization.
16-27: LGTM!The error handler correctly distinguishes between Zod errors and other Fastify errors, returning appropriate status codes and error details.
31-40: LGTM!The
/usersGET route definition and handler are implemented correctly. The handler validates thepagequery parameter and returns appropriate responses.
61-69: LGTM!The
/usersPOST route definition and handler are implemented correctly. The handler extracts theuserNamefrom the request body and returns a mockuserIdwith appropriate headers.
71-77: LGTM!The
/users/:userIdGET route definition and handler are implemented correctly. The handler extracts theuserIdfrom the request params and returns a mockuserName.
79-86: LGTM!The server listening code segment is implemented correctly. It starts the server on port 3000 and handles any errors appropriately.
examples/express/valibot/fetch.ts (1)
1-1: LGTM!The import path change for the
PathMaptype is approved. It reflects the restructuring of the directory layout.package.json (5)
14-17: LGTM!The changes to the example scripts are approved:
- The renaming improves clarity.
- The addition of Fastify examples expands the framework support.
40-41: LGTM!The addition of the
fastifyandfastify-type-provider-zodpeer dependencies is approved. It reflects the expansion of framework support to include Fastify.
59-63: LGTM!The changes to the
peerDependenciesMetasection are approved. They clarify that the Fastify dependencies are optional.
91-95: LGTM!The addition of the
./express/valibotentry in theexportssection is approved. It makes thevalibotmodule available for theexpressentry point.
111-114: LGTM!The addition of the
./valibotentry in theexportssection is approved. It makes thevalibotmodule available as a top-level entry point.src/zod/index.ts (1)
42-42: LGTM!Exporting the
ZodApiEndpointtype is a good change that enhances the modularity and reusability of the type. It allows other modules or files to utilize this type by importing it from this module.
| { | ||
| // @ts-expect-error noexist is not defined in pathMap["/users"]["get"] | ||
| request.query.noexist; | ||
| } |
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.
Remove the redundant block statement.
The standalone block statement at line range 51-54 is redundant and can be safely removed to simplify the code.
Apply this diff to remove the redundant block statement:
- {
- // @ts-expect-error noexist is not defined in pathMap["/users"]["get"]
- request.query.noexist;
- }Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| { | |
| // @ts-expect-error noexist is not defined in pathMap["/users"]["get"] | |
| request.query.noexist; | |
| } |
Tools
Biome
[error] 51-54: This block statement doesn't serve any purpose and can be safely removed.
Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.(lint/complexity/noUselessLoneBlockStatements)
| const fetchT = fetch as FetchT<typeof origin, PathMap>; | ||
| const origin = "http://localhost:3000"; | ||
| const headers = { "Content-Type": "application/json" } as const; | ||
| const JSONT = JSON as JSONT; |
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.
Remove the unnecessary redeclaration of JSONT.
The JSONT constant is already imported at the beginning of the file. Redeclaring it here is redundant and can lead to confusion.
Apply this diff to remove the constant declaration:
-const JSONT = JSON as JSONT;Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const JSONT = JSON as JSONT; |
Tools
Biome
[error] 9-9: Shouldn't redeclare 'JSONT'. Consider to delete it or rename it.
'JSONT' is defined here:
(lint/suspicious/noRedeclare)
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores
package.jsonto include new peer dependencies and reorganized example script names.