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

feat(torii-grpc): add list to member value enum for usage in sdk #2828

Merged
merged 2 commits into from
Dec 23, 2024

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Dec 20, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new List variant to enhance the MemberValue type, allowing for a collection of MemberValue items.
  • Bug Fixes

    • Updated conversion methods to accommodate the new List variant, ensuring proper functionality.

Copy link

coderabbitai bot commented Dec 20, 2024

Walkthrough

Ohayo, sensei! The changes introduce a new list-based variant to the MemberValue enum in the Torii gRPC module. This enhancement allows representing lists of member values, expanding the type's flexibility. The modification involves adding a List(Vec<MemberValue>) variant and updating the conversion implementation to properly handle list-type values when transforming between internal and protobuf representations.

Changes

File Change Summary
crates/torii/grpc/src/types/mod.rs - Added List(Vec<MemberValue>) enum variant to MemberValue
- Updated From<MemberValue> implementation to support list conversion

Sequence Diagram

sequenceDiagram
    participant Enum as MemberValue
    participant Converter as From Implementation
    participant Proto as Proto Types

    Enum ->> Converter: Convert List variant
    Converter ->> Proto: Create MemberValueList
    Converter ->> Proto: Convert each list item
    Proto -->> Converter: Return converted list representation
Loading

The sequence diagram illustrates how the new list variant is converted from the internal MemberValue to its protobuf representation, showing the process of transforming a list of values through the conversion implementation.

Possibly related PRs

  • feat(torii-grpc): IN operator for comparison #2812: This PR introduces a new field MemberValueList in the MemberValue message, which allows for a list of MemberValue instances, directly relating to the new List(Vec<MemberValue>) variant added in the main PR.

Suggested reviewers

  • glihm

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd193ff and e4d9d86.

📒 Files selected for processing (1)
  • crates/torii/grpc/src/types/mod.rs (2 hunks)
🔇 Additional comments (2)
crates/torii/grpc/src/types/mod.rs (2)

154-154: Ohayo sensei! The List variant looks good!

The recursive nature of List(Vec<MemberValue>) allows for nested lists, which is a powerful feature for representing complex data structures.


422-429: Ohayo! The forward conversion looks clean, sensei!

The implementation efficiently converts the list using iterators and handles nested values correctly through recursion.


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

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.

Copy link

@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.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0b8033 and dd193ff.

📒 Files selected for processing (1)
  • crates/torii/grpc/src/types/mod.rs (2 hunks)
🔇 Additional comments (1)
crates/torii/grpc/src/types/mod.rs (1)

154-154: Ohayo! The List variant addition looks good, sensei!

The recursive definition allowing Vec<MemberValue> is well-structured and follows Rust's idiomatic patterns for representing nested data structures.

Let's verify the usage patterns to ensure we handle nested lists appropriately:

✅ Verification successful

Let me analyze the protobuf definition and any existing validation patterns to ensure we have proper handling of nested lists.


Ohayo! The List variant implementation is properly aligned with protobuf definition, sensei!

The implementation correctly maps to the protobuf MemberValueList message type, which is defined with repeated MemberValue values. The conversion logic handles the transformation appropriately, and the protobuf definition supports the nested structure.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for patterns where List variant is used
rg -A 5 "MemberValue::List" 

Length of output: 490


Script:

#!/bin/bash
# Let's check the protobuf definition for MemberValueList
rg -A 10 "message MemberValueList"

# Also check if there are any validation implementations
rg -A 5 "validate.*List"

# Check for any test cases involving List variant
rg -A 10 "test.*List"

Length of output: 684

Comment on lines 422 to 424
MemberValue::List(list) => member_value::ValueType::List(proto::types::MemberValueList {
values: list.into_iter().map(|v| proto::types::MemberValue { value_type: Some(v.into()) }).collect(),
}),
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Ohayo! We need to implement the reverse conversion, sensei!

After reviewing the entire file, I can confirm that while we have the conversion from MemberValue to protobuf type, we're missing the reverse conversion (from protobuf to MemberValue). This could lead to issues when deserializing data from the protobuf format.

  • Missing implementation for From<proto::types::MemberValue> for MemberValue or TryFrom<proto::types::MemberValue> for MemberValue
  • The reverse conversion for the List variant needs to be handled recursively, similar to the forward conversion
🔗 Analysis chain

Implementation looks clean, but let's verify the reverse conversion, sensei!

The conversion to protobuf type is well-implemented using iterators and handles nested values correctly. However, we should ensure the reverse conversion (from proto to MemberValue) is also implemented.

Let's check for the reverse conversion implementation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the reverse conversion implementation
ast-grep --pattern 'impl $_ for MemberValue {
  $$$
  fn from($_: proto::types::MemberValue) -> Self {
    $$$
  }
}'

# Also check for TryFrom implementation
ast-grep --pattern 'impl TryFrom<proto::types::MemberValue> for MemberValue {
  $$$
  fn try_from($_: proto::types::MemberValue) -> Result<Self, Self::Error> {
    $$$
  }
}'

Length of output: 296


Script:

#!/bin/bash
# Let's try a broader search for MemberValue implementations
rg -A 10 "impl.*MemberValue" 

# Also search for From trait implementations in the file
rg -A 10 "impl.*From.*MemberValue" crates/torii/grpc/src/types/mod.rs

# And search specifically for the List variant conversion
rg -A 5 "MemberValue::List" crates/torii/grpc/src/types/mod.rs

Length of output: 1963


Script:

#!/bin/bash
# Let's search for From implementations in the reverse direction
rg -A 10 "impl From<proto::types::MemberValue.*> for MemberValue"

# Also search for any conversion from proto::types::MemberValueList
rg -A 10 "MemberValueList.*MemberValue"

# And let's check the entire file content to ensure we don't miss any conversion
cat crates/torii/grpc/src/types/mod.rs

Length of output: 16672

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 55.92%. Comparing base (c0b8033) to head (e4d9d86).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/grpc/src/types/mod.rs 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2828      +/-   ##
==========================================
- Coverage   55.92%   55.92%   -0.01%     
==========================================
  Files         439      439              
  Lines       56156    56163       +7     
==========================================
- Hits        31408    31407       -1     
- Misses      24748    24756       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glihm glihm changed the title feat(torii-grpc): add list to member value enum for usasge in sdk feat(torii-grpc): add list to member value enum for usage in sdk Dec 21, 2024
@glihm glihm merged commit 845c5b1 into dojoengine:main Dec 23, 2024
12 of 14 checks passed
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.

2 participants