pingdotgg / uploadthing

File uploads for modern web devs
https://uploadthing.com
MIT License
4.26k stars 315 forks source link

fix: correct args in middleware args when using object syntax #1017

Closed juliusmarminge closed 1 month ago

juliusmarminge commented 1 month ago

Fixes: https://discord.com/channels/966627436387266600/1295885646916878366/1295886403095236718

Summary by CodeRabbit

vercel[bot] commented 1 month ago

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

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 16, 2024 7:47am
1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **legacy-docs-uploadthing** | ⬜️ Ignored ([Inspect](https://vercel.com/pinglabs/legacy-docs-uploadthing/D8rX5GxNSBF9zjNGd1vNuHKLtaEe)) | | | Oct 16, 2024 7:47am |
changeset-bot[bot] commented 1 month ago

⚠️ No Changeset found

Latest commit: 3718df260f9cb19562546e7f21cd6f5d1507b230

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

coderabbitai[bot] commented 1 month ago

Walkthrough

The changes involve modifications to the createRouteHandler function in packages/uploadthing/src/server.ts, allowing it to accept an event object that may contain a request property. This enhances the function's ability to handle different input structures. Additionally, a new test case has been added to the test suite in packages/uploadthing/test/adapters.test.ts to verify that the handler can process requests encapsulated within an object, ensuring compatibility with various middleware functions.

Changes

File Path Change Summary
packages/uploadthing/src/server.ts Modified createRouteHandler to accept an event object ev, checking for ev.request.
packages/uploadthing/test/adapters.test.ts Added a new test case to verify the handler's ability to accept an object containing a request.

Poem

In the meadow where bunnies play,
A handler now works in a new way!
With events that bring requests near,
Our tests now cheer, "Let's give a cheer!"
For every hop and every bound,
Flexibility's joy is truly found! 🐇✨


📜 Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
📥 Commits Files that changed from the base of the PR and between 467a8e6fc97e5718266cda9ea379599c7418e82a and 3718df260f9cb19562546e7f21cd6f5d1507b230.
📒 Files selected for processing (2) * packages/uploadthing/src/server.ts (1 hunks) * packages/uploadthing/test/adapters.test.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
packages/uploadthing/src/server.ts (2)
`27-32`: **LGTM! This change improves flexibility in handling middleware arguments.** The modification to `createRouteHandler` now allows it to handle both direct `Request` objects and objects containing a `request` property. This change: 1. Addresses the PR objective of fixing args in middleware when using object syntax. 2. Improves flexibility without breaking existing functionality. 3. Ensures compatibility with various middleware functions that might wrap the request in an object. The implementation is correct and uses the `in` operator to safely check for the presence of the `request` property. --- `27-32`: **Verify usage of `createRouteHandler` across the codebase** While the changes to `createRouteHandler` improve its flexibility, it's important to ensure that this modification doesn't introduce any unintended side effects in other parts of the codebase that might be using this function. Let's run a script to check the usage of `createRouteHandler` across the codebase: This script will help us identify any potential areas that might need adjustment due to the changes in `createRouteHandler`.
✅ Verification successful **Usage of `createRouteHandler` verified across the codebase** All instances of `createRouteHandler` have been reviewed, and no unintended side effects were found from the recent changes. The modifications in `packages/uploadthing/src/server.ts` are isolated and maintain compatibility with existing implementations.
🏁 Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Check usage of createRouteHandler across the codebase # Search for createRouteHandler usage echo "Searching for createRouteHandler usage:" rg --type typescript -A 5 "createRouteHandler" # Search for potential direct Request usage with createRouteHandler echo "\nSearching for potential direct Request usage with createRouteHandler:" rg --type typescript -A 5 "createRouteHandler.*Request" ``` Length of output: 416 --- Script: ```shell #!/bin/bash # Description: Check usage of createRouteHandler across the codebase # Search for createRouteHandler usage in .ts and .tsx files echo "Searching for createRouteHandler usage in .ts and .tsx files:" rg "createRouteHandler" --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx -A 5 # Search for potential direct Request usage with createRouteHandler in .ts and .tsx files echo "\nSearching for potential direct Request usage with createRouteHandler in .ts and .tsx files:" rg "createRouteHandler.*Request" --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx -A 5 ``` Length of output: 632 --- Script: ```shell #!/bin/bash # Description: Check usage of createRouteHandler across the codebase # Search for createRouteHandler usage in .ts and .tsx files echo "Searching for createRouteHandler usage in .ts and .tsx files:" rg "createRouteHandler" -g "*.ts" -g "*.tsx" -A 5 # Search for potential direct Request usage with createRouteHandler in .ts and .tsx files echo "\nSearching for potential direct Request usage with createRouteHandler in .ts and .tsx files:" rg "createRouteHandler.*Request" -g "*.ts" -g "*.tsx" -A 5 ``` Length of output: 36480
packages/uploadthing/test/adapters.test.ts (2)
`238-294`: **LGTM! New test case effectively covers object syntax for request handling.** This new test case is a valuable addition as it verifies the correct handling of middleware args when using object syntax. It aligns well with the PR objectives and maintains consistency with existing test structures. The test comprehensively checks: 1. Correct handler creation and execution 2. Proper middleware invocation with expected arguments 3. Accurate response generation 4. Asynchronous metadata registration at UploadThing This test enhances the robustness of the adapter implementation and ensures compatibility with various request handling scenarios. --- Line range hint `1-1180`: **Overall, the changes enhance the test coverage without disrupting existing tests.** The addition of the new test case "accepts object with request in" to the "adapters:server" section is the only significant change in this file. This new test integrates seamlessly with the existing test suite, maintaining consistency in structure and naming conventions. It effectively addresses the PR objective of correcting args in middleware when using object syntax. The test suites for other adapters (h3, next, next-legacy, express, fastify, and effect-platform) remain unchanged, preserving the overall integrity of the test file.
--- 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?
❤️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `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 generate unit testing code for this file.` - `@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 generate unit testing code.` - `@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.` 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 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
github-actions[bot] commented 1 month ago

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 26.11KB See Treemap 📊
PR (0ae31070845c3943cb53e5d48ad3a33e390df9c3) 26.11KB See Treemap 📊
Diff No change
pkg-pr-new[bot] commented 1 month ago

Open in Stackblitz

More templates

- [@example/minimal-appdir](https://pkg.pr.new/template/a1cb0123-738c-4d57-b585-854255b212a4) - [@example/minimal-astro-react](https://pkg.pr.new/template/7703882e-cb8d-45b4-a9fb-5eca61326ece) - [@example/minimal-expo](https://pkg.pr.new/template/c267f2c4-9447-47ce-9488-fb870f53ecf7) - [@example/minimal-nuxt](https://pkg.pr.new/template/d4120a92-d875-4d6f-9f19-81279b7c9a3d) - [@example/minimal-pagedir](https://pkg.pr.new/template/d502cf7f-af03-4107-805e-1c1abc692ff9) - [@example/minimal-solidstart](https://pkg.pr.new/template/c2980165-fcbd-47cd-a05a-3404f59f8118) - [@example/minimal-sveltekit](https://pkg.pr.new/template/841c6ed4-0f20-49df-8bd2-acb3fa52f232) - [@example/minimal-tanstack-start](https://pkg.pr.new/template/5afff95d-1fef-43e8-9179-c3a244f96995)

pnpm add https://pkg.pr.new/pingdotgg/uploadthing@1017

commit: 3718df2