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

fix: preserve prisma client extensions's typing #1148

Merged
merged 2 commits into from
Mar 17, 2024
Merged

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Mar 17, 2024

Fixes #1140

Summary by CodeRabbit

  • New Features
    • Enhanced flexibility in Prisma client enhancements, supporting both plain and extended types.
  • Tests
    • Improved integration tests for Prisma client enhancements, focusing on polymorphism and TypeScript compilation adjustments.

Copy link
Contributor

coderabbitai bot commented Mar 17, 2024

Walkthrough

Walkthrough

The recent changes involve enhancing the PrismaClient functionality by introducing overloads for both plain and extended PrismaClient instances. This enhancement aims to provide flexibility in handling different types of Prisma clients, accommodating additional arguments for context and options. Furthermore, the integration tests have been refactored to support these enhancements, focusing on polymorphism and TypeScript compilation adjustments for both plain and extended Prisma scenarios.

Changes

Files Change Summary
packages/schema/src/plugins/enhancer/enhance/index.ts Modified EnhancerGenerator class to include overloads for both plain and extended PrismaClient, adding support for additional context and options arguments.
tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts Refactored test script to support polymorphism in plain and extended Prisma scenarios, including TypeScript compilation adjustments.

Assessment against linked issues

Objective Addressed Explanation
Investigate and resolve polymorphism typing with Prisma client extensions (#1140)
Identify the root cause of the typing problem related to polymorphism (#1140) The summary does not explicitly mention identifying the root cause but implies a resolution.
Implement a solution for polymorphism typing with Prisma client extensions (#1140)
Test changes to verify resolution of the typing issue without introducing new bugs (#1140) The changes include test script refactoring, but it's unclear if all scenarios are covered.
Document the modifications made to address the typing problem (#1140) No documentation changes are mentioned in the summary.

This assessment indicates that while the main objectives related to coding have been addressed, there is a lack of explicit mention of documentation updates and a complete verification through testing, which leaves some ambiguity regarding the thoroughness of the resolution.

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

Tips

Chat

There are 3 ways to chat with CodeRabbit:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 01e372e and 61438cc.
Files selected for processing (2)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (1 hunks)
  • tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts (3 hunks)
Additional comments: 3
packages/schema/src/plugins/enhancer/enhance/index.ts (1)
  • 95-127: The implementation of function overloads for enhance effectively addresses the need for supporting both plain and extended PrismaClient instances. This flexibility is crucial for the polymorphism feature to work seamlessly with Prisma client extensions. However, there are a few points to consider for refinement:
  1. Type Safety and Documentation: Ensure that the types used in the function signatures (ExtArgs, TypeMap, TypeMapCb, etc.) are well-documented. This will help developers understand the expected structure and usage of these types, especially when extending the PrismaClient.

  2. Error Handling: Consider adding error handling within the enhance function to manage cases where the provided prisma instance does not match any of the expected types. This could involve throwing a descriptive error or logging a warning to assist in debugging.

  3. Performance Considerations: Given that the enhance function is likely to be called frequently, evaluate the performance implications of the type checks and operations performed within the function. If there are any potential bottlenecks, consider optimizing these areas.

  4. Testing: Ensure comprehensive testing of the enhance function, covering various scenarios with both plain and extended PrismaClient instances. This includes testing with different combinations of context and options arguments to verify that the function behaves as expected in all cases.

Overall, the changes to the enhance function are a positive step towards resolving the issue with polymorphism's typing and Prisma client extensions. Addressing the above points will further strengthen the implementation and ensure a robust solution.

tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts (2)
  • 1080-1161: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1040-1095]

The test case for TypeScript compilation with a plain Prisma client is well-structured and demonstrates the intended use case effectively. However, consider adding assertions to verify the expected behavior of the operations performed within the main function. This would ensure that the enhancements applied to the Prisma client are functioning as expected.

Consider adding assertions or checks after the database operations to verify the expected outcomes. This could involve checking the properties of the created entities or the results of queries to ensure they match expected values.

  • 1097-1159: Similar to the previous comment, the test case for TypeScript compilation with an extended Prisma client is well-structured. It effectively demonstrates extending the Prisma client with custom methods. As with the plain Prisma client test case, adding assertions to verify the expected behavior would enhance the test's effectiveness.

Adding assertions or checks after database operations in the main function would help verify that the enhancements and custom methods applied to the Prisma client are working as intended. This could involve checking the properties of the created entities or the results of queries.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 61438cc and 6671675.
Files selected for processing (1)
  • tests/integration/tests/cli/plugins.test.ts (2 hunks)
Additional comments: 2
tests/integration/tests/cli/plugins.test.ts (2)
  • 76-76: Please ensure that the project and its tests are fully compatible with @prisma/client version ^5.0.0. This may involve reviewing the release notes for breaking changes or new features that could impact the project.
  • 86-86: Please ensure that the development environment and build processes are fully compatible with prisma version ^5.0.0. Reviewing the release notes for potential breaking changes or new features that could affect the project is advisable.

@ymc9 ymc9 merged commit b3fa1ed into v2 Mar 17, 2024
12 checks passed
@ymc9 ymc9 deleted the fix/merge-extension-typing branch March 17, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant