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(zmodel): enum is resolved to wrong element after merging base models #1437

Merged
merged 2 commits into from
May 12, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented May 11, 2024

No description provided.

Copy link
Contributor

coderabbitai bot commented May 11, 2024

Important

Auto Review Skipped

Review was skipped due to path filters

Files ignored due to path filters (2)
  • tests/integration/tsconfig.json is excluded by !**/*.json
  • tests/regression/tsconfig.json is excluded by !**/*.json

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update primarily focuses on renaming and refactoring functions related to model merging and validation, enhancing compatibility across different modules by adjusting import paths, and introducing parameters to improve flexibility in model field retrieval. The changes streamline interactions between different components and modules, ensuring more robust and flexible schema handling.

Changes

Files Changes
cli-util.ts, ast-utils.ts, utils.ts Renamed mergeBaseModel to mergeBaseModels, added includeDelegate parameter to functions, and updated function logic.
datamodel-validator.ts, zmodel-code-action.ts Moved and added utility functions across modules, updated import paths.
issue-1435.test.ts Added new test case file with setup for regression testing.
model.ts, tests/utils.ts Minor renaming and formatting updates.

Possibly related issues


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 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 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 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.

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.
  • 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.

@ymc9
Copy link
Member Author

ymc9 commented May 11, 2024

Fixes #1435

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d2709f6 and 6122e9b.
Files ignored due to path filters (1)
  • tests/integration/tsconfig.json is excluded by !**/*.json
Files selected for processing (8)
  • packages/schema/src/cli/cli-util.ts (3 hunks)
  • packages/schema/src/language-server/validator/datamodel-validator.ts (1 hunks)
  • packages/schema/src/language-server/zmodel-code-action.ts (1 hunks)
  • packages/schema/src/utils/ast-utils.ts (4 hunks)
  • packages/schema/tests/utils.ts (3 hunks)
  • packages/sdk/src/utils.ts (1 hunks)
  • packages/testtools/src/model.ts (2 hunks)
  • tests/regression/tests/issue-1435.test.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/schema/tests/utils.ts
Additional comments not posted (12)
packages/testtools/src/model.ts (2)

Line range hint 8-56: The implementation of loadModel function appears robust and well-structured, handling various error scenarios effectively.


Line range hint 56-67: The loadModelWithError function correctly handles and categorizes errors from the loadModel function, which is a good practice for robust error management.

tests/regression/tests/issue-1435.test.ts (1)

1-119: The test suite for issue 1435 is comprehensive and well-structured, covering complex model relationships and database interactions effectively.

packages/schema/src/utils/ast-utils.ts (5)

Line range hint 50-85: The mergeBaseModels function is well-implemented, efficiently handling the merging of base models with attention to details like abstract model handling and container index fixing.


Line range hint 84-104: The filterBaseAttribute function correctly implements attribute filtering based on well-defined criteria, ensuring that only appropriate attributes are inherited.


Line range hint 104-123: The cloneAst function is effectively implemented, ensuring deep cloning of AST nodes with proper reference management and integration into the new context.


Line range hint 123-143: The getIdFields function is well-implemented, correctly handling the retrieval of both field-level and model-level ID attributes from data models.


Line range hint 143-148: The isAuthInvocation function correctly identifies invocations of the auth function in AST nodes, ensuring that the function is from the standard library.

packages/schema/src/cli/cli-util.ts (2)

Line range hint 15-104: The loadDocument function is well-implemented, effectively handling the loading and validation of ZModel documents, with comprehensive error management and support for plugins and imports.


Line range hint 116-134: The validationAfterImportMerge function correctly implements additional validation checks on the model, ensuring the presence of a datasource and the correct number of @@auth models.

packages/sdk/src/utils.ts (2)

507-512: The changes to getModelFieldsWithBases look good and align with the new functionality described.

Verification successful

The search results indicate that the function getModelFieldsWithBases is used extensively across various files in the packages/schema directory, as well as within its original file in packages/sdk/src/utils.ts. The usage of this function includes both the new signature with the includeDelegate parameter and calls where this parameter is not explicitly mentioned, which defaults to true due to the function definition.

Observations:

  • The function is imported and used in several files related to language server and validator functionalities within the schema package.
  • The function is called with and without the optional includeDelegate parameter, demonstrating flexibility and backward compatibility of the function's new signature.

Conclusion:

The integration of the getModelFieldsWithBases function with the new optional parameter appears to be successful and is being utilized appropriately across the system. The usage aligns with the intended enhancements described in the original review comment.

Actionable Directive:

  • Ensure that all developers are aware of the new optional parameter and its default behavior to avoid any confusion or misuse in future developments.

Locations in the codebase that need attention:

  • packages/schema/src/utils/ast-utils.ts
  • packages/schema/src/language-server/zmodel-code-action.ts
  • packages/schema/src/language-server/zmodel-scope.ts
  • packages/schema/src/language-server/zmodel-linker.ts
  • packages/schema/src/language-server/validator/datamodel-validator.ts
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of `getModelFieldsWithBases` with other parts of the system.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type typescript $'getModelFieldsWithBases'

Length of output: 81



Script:

#!/bin/bash
# Description: Verify integration of `getModelFieldsWithBases` with other parts of the system.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type ts $'getModelFieldsWithBases'

Length of output: 2219


515-524: The updates to getRecursiveBases function correctly implement the new includeDelegate parameter, enhancing flexibility.

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