Skip to content
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

chore: revert url changes #1128

Merged
merged 8 commits into from
Jan 13, 2025
Merged

chore: revert url changes #1128

merged 8 commits into from
Jan 13, 2025

Conversation

juliusmarminge
Copy link
Member

@juliusmarminge juliusmarminge commented Jan 12, 2025

Summary by CodeRabbit

  • New Features

    • Added a new ufsUrl property for uploaded files.
    • Introduced deprecation warnings for url and appUrl properties.
  • Deprecation Notice

    • url and appUrl will be removed in uploadthing v9.
    • Recommended to use ufsUrl for file URLs going forward.
  • Improvements

    • Enhanced URL handling and generation for file uploads.
    • Updated tests to incorporate new URL patterns for better flexibility.

Copy link

changeset-bot bot commented Jan 12, 2025

🦋 Changeset detected

Latest commit: 096f1d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
uploadthing Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link

vercel bot commented Jan 12, 2025

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 Jan 12, 2025 11:45pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Visit Preview Jan 12, 2025 11:45pm

Copy link
Contributor

coderabbitai bot commented Jan 12, 2025

Warning

Rate limit exceeded

@juliusmarminge has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 39 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between cd6447c and 096f1d8.

📒 Files selected for processing (1)
  • .changeset/purple-shrimps-chew.md (1 hunks)

Walkthrough

This pull request introduces modifications to the UploadThing library's URL handling mechanism, primarily by adding a new ufsUrl property to the UploadPutResult type. The existing url and appUrl properties are marked as deprecated and now log warnings when accessed, indicating their planned removal in uploadthing v9. These changes standardize the URL handling for uploaded files while maintaining backward compatibility.

Changes

File Change Summary
packages/uploadthing/src/_internal/types.ts Added ufsUrl property, deprecated url and appUrl properties with updated comments.
packages/uploadthing/src/_internal/upload-browser.ts Added ufsUrl, introduced deprecation warnings for url and appUrl accessed via getters.
packages/uploadthing/src/sdk/utils.ts Updated uploadFile return type to include ufsUrl.
packages/uploadthing/src/_internal/shared-schemas.ts Added ufsUrl property, updated deprecation comments for appUrl and url.
packages/uploadthing/src/_internal/handler.ts Added getter methods with deprecation warnings for url and appUrl.
packages/uploadthing/src/_internal/upload-server.ts Added deprecation warnings for url and appUrl accessed via getters.
packages/uploadthing/src/_internal/deprecations.ts Added logDeprecationWarning utility function to log deprecation messages.
packages/uploadthing/test/__test-helpers.ts Added UTFS_URL constant, updated URL patterns in response structures.
packages/uploadthing/test/client.browser.test.ts Added appUrlPattern and ufsUrlPattern, updated assertions in tests.
packages/uploadthing/test/sdk.live.test.ts Updated test cases to use new URL patterns for assertions.
packages/uploadthing/test/sdk.test.ts Removed UFS_HOST, added new URL patterns for tests.
packages/uploadthing/test/request-handler.test.ts Introduced UTFS_URL for URL construction in tests.

Possibly related PRs

  • feat: return file hash from uploaded object #978: This PR introduces a new property fileHash in the UploadedFileData class, which is relevant to the changes in the main PR that also involve modifications to the UploadPutResult type, including the addition of a new property ufsUrl.
  • feat: add effect/Redacted #993: This PR adds a new property ufsUrl to the UploadPutResult type, which aligns with the main PR's changes to the UploadPutResult type, specifically the introduction of the ufsUrl property.
  • feat: forward request context to onUploadComplete and onUploadError #1045: This PR enhances the upload handling process by allowing access to the request context in the onUploadComplete and onUploadError functions, which may relate to the overall upload functionality being modified in the main PR.

Suggested Labels

examples, 📚 documentation

Suggested Reviewers

  • markflorkowski
  • t3dotgg

🪧 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.
    • 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions github-actions bot added the sdk label Jan 12, 2025
Copy link
Contributor

github-actions bot commented Jan 12, 2025

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 30.42KB See Treemap 📊
PR (8a324de) 30.67KB See Treemap 📊
Diff ↑255.00B

Copy link

pkg-pr-new bot commented Jan 12, 2025

Copy link
Contributor

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

🧹 Nitpick comments (1)
packages/uploadthing/test/__test-helpers.ts (1)

47-49: Consider consolidating URL pattern functions.

The appUrlPattern and fileUrlPattern functions share similar logic. Consider consolidating them into a single function with a type parameter to reduce code duplication.

-export const appUrlPattern = (appId = testToken.decoded.appId) =>
-  new RegExp(`^${UTFS_URL}/a/${appId}/.+$`);
-export const fileUrlPattern = () => new RegExp(`^${UTFS_URL}/f/.+$`);
+export const createUrlPattern = (type: 'app' | 'file', appId = testToken.decoded.appId) =>
+  new RegExp(`^${UTFS_URL}/${type === 'app' ? `a/${appId}` : 'f'}/.+$`);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aab8ab6 and ba0ec89.

📒 Files selected for processing (7)
  • packages/uploadthing/src/_internal/types.ts (1 hunks)
  • packages/uploadthing/src/_internal/upload-browser.ts (1 hunks)
  • packages/uploadthing/src/sdk/utils.ts (1 hunks)
  • packages/uploadthing/test/__test-helpers.ts (4 hunks)
  • packages/uploadthing/test/client.browser.test.ts (4 hunks)
  • packages/uploadthing/test/sdk.live.test.ts (7 hunks)
  • packages/uploadthing/test/sdk.test.ts (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: analyze-bundle (current-pr)
  • GitHub Check: typecheck
  • GitHub Check: e2e-node (backend-adapters)
  • GitHub Check: lint
  • GitHub Check: e2e-node (minimal-pagedir)
  • GitHub Check: e2e-node (minimal-appdir)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (10)
packages/uploadthing/test/__test-helpers.ts (1)

34-37: Verify PR objective alignment.

The addition of UTFS_URL and subsequent URL changes appear to introduce new URL patterns rather than reverting them, which seems to contradict the PR title "chore: revert url changes".

Could you clarify if this is intentionally introducing new URL patterns or if this should be reverting previous URL changes?

packages/uploadthing/src/sdk/utils.ts (1)

150-150: LGTM!

The addition of ufsUrl to the return object is consistent with the existing pattern.

packages/uploadthing/src/_internal/upload-browser.ts (2)

143-143: LGTM!

The addition of ufsUrl is consistent with the changes in other files.


Line range hint 1-1: Review PR title and description alignment.

The PR title suggests this is reverting URL changes, but the code changes appear to be:

  1. Adding a new ufsUrl property
  2. Deprecating existing URL properties
  3. Introducing new URL patterns

This seems more like a feature enhancement than a revert. Consider:

  1. Updating the PR title to reflect the actual changes
  2. Adding a clear migration guide for the URL property deprecations
  3. Documenting the rationale for these changes in the PR description
packages/uploadthing/test/sdk.live.test.ts (2)

7-12: LGTM! Import changes look good.

The addition of appUrlPattern and ufsUrlPattern imports aligns with the URL pattern changes being tested.


72-74: Consistent implementation of URL pattern assertions.

The URL pattern assertions have been consistently updated across all test cases to verify three distinct URLs:

  • url: Using fileUrlPattern()
  • appUrl: Using appUrlPattern(appId)
  • ufsUrl: Using ufsUrlPattern(appId)

This change ensures comprehensive validation of the URL structure in the upload response.

Also applies to: 108-110, 139-141, 164-166, 207-209, 249-251

packages/uploadthing/test/client.browser.test.ts (2)

20-20: LGTM! Import changes are consistent.

The addition of URL pattern imports maintains consistency with other test files.

Also applies to: 28-28


146-147: URL pattern assertions properly implemented in browser tests.

The browser-specific upload tests have been correctly updated to verify all three URL patterns in the upload response.

Also applies to: 191-192, 227-228

packages/uploadthing/test/sdk.test.ts (2)

16-16: LGTM! Import changes maintain consistency.

The URL pattern imports are consistent with the changes in other test files.

Also applies to: 18-18, 23-23


55-57: Comprehensive URL pattern validation across SDK tests.

The URL pattern assertions have been systematically updated across all test cases, including:

  • Single file uploads
  • Batch uploads
  • Error scenarios
  • File uploads from URLs

This ensures consistent validation of the URL structure in all upload responses.

Also applies to: 171-173, 305-307, 343-345, 367-369

Copy link
Contributor

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba0ec89 and e9901f6.

📒 Files selected for processing (2)
  • packages/uploadthing/src/_internal/shared-schemas.ts (1 hunks)
  • packages/uploadthing/src/_internal/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/uploadthing/src/_internal/types.ts
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: typecheck
  • GitHub Check: lint
  • GitHub Check: e2e-node (backend-adapters)
  • GitHub Check: e2e-node (minimal-pagedir)
  • GitHub Check: analyze-bundle (current-pr)
  • GitHub Check: e2e-node (minimal-appdir)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (1)
packages/uploadthing/src/_internal/shared-schemas.ts (1)

84-84: Verify consumers of UploadedFileData schema.

Let's ensure that all consumers of this schema are prepared for the new ufsUrl property.

✅ Verification successful

Documentation-only change with proper deprecation notice

This is a safe change that only adds a deprecation notice for a future version (v9) while maintaining backward compatibility. The notice correctly guides users to use the ufsUrl field as an alternative.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of UploadedFileData to verify compatibility

# Find direct references to UploadedFileData
echo "=== Direct references to UploadedFileData ==="
rg "UploadedFileData" --type ts

# Find potential type usage through ClientUploadedFileData
echo -e "\n=== References to ClientUploadedFileData ==="
rg "ClientUploadedFileData" --type ts

# Find potential implementations or extensions
echo -e "\n=== Potential implementations or extensions ==="
ast-grep --pattern 'extends $_ implements UploadedFileData'

Length of output: 8163

Copy link
Contributor

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

🧹 Nitpick comments (3)
packages/uploadthing/test/request-handler.test.ts (1)

414-416: Consider adding URL format validation tests.

While the URL construction is consistent, consider adding test cases that specifically validate:

  1. The format of the generated URLs
  2. The deprecation warnings for url and appUrl
  3. The accessibility of the generated URLs

Example test case:

it("should warn when accessing deprecated url properties", () => {
  const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
  const data = new UploadedFileData({
    url: `${UTFS_URL}/f/test.png`,
    appUrl: `${UTFS_URL}/a/${testToken.decoded.appId}/f/test.png`,
    ufsUrl: `https://${testToken.decoded.appId}.${UFS_HOST}/f/test.png`,
    // ... other required properties
  });
  
  // Access deprecated properties
  expect(data.url).toBeDefined();
  expect(data.appUrl).toBeDefined();
  
  // Verify deprecation warnings
  expect(consoleSpy).toHaveBeenCalledWith(
    expect.stringContaining("'url' is deprecated")
  );
  expect(consoleSpy).toHaveBeenCalledWith(
    expect.stringContaining("'appUrl' is deprecated")
  );
  
  consoleSpy.mockRestore();
});
packages/uploadthing/src/_internal/upload-server.ts (1)

45-60: LGTM! Consider enhancing the deprecation notice with version information.

The implementation of deprecation warnings using getters is a clean approach. However, to help users better plan their migration, consider including the current version in the deprecation message.

-          "`file.url` is deprecated and will be removed in uploadthing v9. Use `file.ufsUrl` instead.",
+          "`file.url` is deprecated in uploadthing v${version} and will be removed in v9. Use `file.ufsUrl` instead.",
packages/uploadthing/src/_internal/handler.ts (1)

339-353: Consider extracting deprecation messages to constants.

The implementation is correct, but the deprecation messages are duplicated across files. Consider extracting these messages to a shared constants file to ensure consistency and easier maintenance.

Create a new constants file:

// src/_internal/constants.ts
export const DEPRECATION_MESSAGES = {
  FILE_URL: "`file.url` is deprecated and will be removed in uploadthing v9. Use `file.ufsUrl` instead.",
  FILE_APP_URL: "`file.appUrl` is deprecated and will be removed in uploadthing v9. Use `file.ufsUrl` instead.",
} as const;

Then update the usage:

-                  "`file.url` is deprecated and will be removed in uploadthing v9. Use `file.ufsUrl` instead.",
+                  DEPRECATION_MESSAGES.FILE_URL,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2cd63d2 and d6d63c0.

📒 Files selected for processing (5)
  • packages/uploadthing/src/_internal/handler.ts (2 hunks)
  • packages/uploadthing/src/_internal/logger.ts (1 hunks)
  • packages/uploadthing/src/_internal/upload-browser.ts (2 hunks)
  • packages/uploadthing/src/_internal/upload-server.ts (2 hunks)
  • packages/uploadthing/test/request-handler.test.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/uploadthing/src/_internal/upload-browser.ts
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: analyze-bundle (current-pr)
  • GitHub Check: typecheck
  • GitHub Check: e2e-node (backend-adapters)
  • GitHub Check: e2e-node (minimal-pagedir)
  • GitHub Check: lint
  • GitHub Check: e2e-node (minimal-appdir)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (2)
packages/uploadthing/test/request-handler.test.ts (1)

414-416: LGTM! URL construction pattern is consistently implemented.

The URL construction pattern is consistently applied across all test cases, properly handling the transition to the new URL structure with the addition of ufsUrl.

Also applies to: 452-454, 466-468, 500-502

packages/uploadthing/src/_internal/logger.ts (1)

90-93: LGTM! Clean implementation of the deprecation logger.

The implementation provides clear visual indicators and consistent formatting for deprecation warnings.

file: requestInput.file,
file: {
...requestInput.file,
get url() {
Copy link
Member Author

@juliusmarminge juliusmarminge Jan 12, 2025

Choose a reason for hiding this comment

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

bit more encouragement to get people migrating faster

CleanShot 2025-01-13 at 00 23 42@2x

Copy link
Contributor

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

🧹 Nitpick comments (1)
packages/uploadthing/src/_internal/deprecations.ts (1)

1-4: Add JSDoc documentation for better maintainability.

The implementation looks good and follows best practices. However, adding JSDoc documentation would improve maintainability and provide better IDE support.

Consider adding documentation:

+/**
+ * Logs a deprecation warning to the console.
+ * @param message - The deprecation message to display
+ * @example
+ * logDeprecationWarning('Property "url" is deprecated. Use "ufsUrl" instead.');
+ */
 export const logDeprecationWarning = (message: string) => {
   // eslint-disable-next-line no-console
   console.warn(`⚠️ [uploadthing] ${message}`);
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d6d63c0 and 25d32b6.

📒 Files selected for processing (4)
  • packages/uploadthing/src/_internal/deprecations.ts (1 hunks)
  • packages/uploadthing/src/_internal/handler.ts (2 hunks)
  • packages/uploadthing/src/_internal/upload-browser.ts (2 hunks)
  • packages/uploadthing/src/_internal/upload-server.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/uploadthing/src/_internal/upload-server.ts
  • packages/uploadthing/src/_internal/handler.ts
  • packages/uploadthing/src/_internal/upload-browser.ts
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: e2e-node (backend-adapters)
  • GitHub Check: e2e-node (minimal-pagedir)
  • GitHub Check: e2e-node (minimal-appdir)
  • GitHub Check: analyze-bundle (current-pr)
  • GitHub Check: typecheck
  • GitHub Check: lint
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants