dojo icon indicating copy to clipboard operation
dojo copied to clipboard

feat: add ModelDefinition to Dojo Model

Open remybar opened this issue 1 year ago • 2 comments
trafficstars

Description

This PR adds the definition() function to Dojo models to be able to retrieve the full ModelDefinition at once instead of calling several functions to get each element one by one.

depends on https://github.com/dojoengine/dojo-core/pull/10.

TODO: remove dojo-core part as it has been moved to dojo-core repo.

Tests

  • [X] Yes
  • [ ] No, because they aren't needed
  • [ ] No, because I need help

Added to documentation?

  • [ ] README.md
  • [ ] Dojo Book
  • [X] No documentation needed

Checklist

  • [X] I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • [X] I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • [X] I've commented my code
  • [X] I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Introduced a new ModelDefinition structure to enhance model definitions, including fields for name, namespace, version, and more.
    • Added functions to retrieve model definitions and schemas across various interfaces, improving metadata management.
  • Bug Fixes

    • Updated class and original class hashes for multiple models to reflect recent changes in their implementations.
  • Documentation

    • Enhanced documentation to clarify the structure and purpose of the new ModelDefinition and related functions.

remybar avatar Sep 12 '24 08:09 remybar

Walkthrough

Ohayo, sensei! The recent changes introduce a new ModelDefinition structure within the dojo::model::definition namespace, enhancing the framework's capabilities for defining and managing model metadata. Several methods related to schema and model definitions are added across various modules, along with updates to existing traits and functions. Additionally, new tests are introduced to validate model definitions, and modifications are made to manifest files to reflect these updates.

Changes

Files Change Summary
crates/dojo-core/src/lib.cairo, crates/dojo-core/src/model/definition.cairo, crates/dojo-core/src/model/introspect.cairo, crates/dojo-core/src/model/metadata.cairo, crates/dojo-core/src/model/model.cairo, crates/dojo-core/src/tests/model/model.cairo Introduced ModelDefinition struct, added methods for schema and definition retrieval, and enhanced traits with debugging and comparison capabilities. Added tests for model definitions.
crates/dojo-lang/src/model.rs Added methods for schema and definition retrieval in ModelImpl and ContractState.
crates/dojo-world/src/contracts/abi/model.rs Defined ModelDefinition struct and added a function to retrieve model definitions.
examples/spawn-and-move/manifests/dev/base/abis/models/*.json Introduced ModelDefinition structure and added a function for definition retrieval in multiple model files.
examples/spawn-and-move/manifests/dev/base/models/*.toml Updated class_hash and original_class_hash values across multiple models, reflecting changes in underlying implementations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Model
    participant Definition

    User->>Model: Request Model Definition
    Model->>Definition: Retrieve Definition
    Definition-->>Model: Return ModelDefinition
    Model-->>User: Provide Model Definition

[!TIP]

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Recent review details

Configuration used: .coderabbit.yaml Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1a54041e4e50f719dd4dd4b6da95f1535ce17a9d and 6e2fdde8c2fb63dd1f2725656da151194f6dbaa9.

Files ignored due to path filters (2)
  • spawn-and-move-db.tar.gz is excluded by !**/*.gz
  • types-test-db.tar.gz is excluded by !**/*.gz
Files selected for processing (62)
  • crates/dojo-core/src/lib.cairo (1 hunks)
  • crates/dojo-core/src/model/definition.cairo (1 hunks)
  • crates/dojo-core/src/model/introspect.cairo (2 hunks)
  • crates/dojo-core/src/model/metadata.cairo (4 hunks)
  • crates/dojo-core/src/model/model.cairo (3 hunks)
  • crates/dojo-core/src/tests/model/model.cairo (1 hunks)
  • crates/dojo-lang/src/model.rs (2 hunks)
  • crates/dojo-world/src/contracts/abi/model.rs (1 hunks)
  • crates/dojo-world/src/contracts/model_test.rs (1 hunks)
  • crates/sozo/ops/src/tests/model.rs (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-ContractInitialized-376b7bd6.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-Message-1bb1d226.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-MockToken-38903c7c.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-Moved-318ae40d.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-Moves-2e2accba.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-PlayerConfig-3adad785.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-Position-1e145e26.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-ServerProfile-4caad1e6.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples_foes-RiverSkale-39535c12.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples_weapons-Flatbow-22f5bd16.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-ContractInitialized-376b7bd6.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-Message-1bb1d226.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-MockToken-38903c7c.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-Moved-318ae40d.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-Moves-2e2accba.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-PlayerConfig-3adad785.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-Position-1e145e26.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-ServerProfile-4caad1e6.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples_foes-RiverSkale-39535c12.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples_weapons-Flatbow-22f5bd16.toml (1 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-ContractInitialized-376b7bd6.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-Message-1bb1d226.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-MockToken-38903c7c.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-Moved-318ae40d.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-Moves-2e2accba.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-PlayerConfig-3adad785.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-Position-1e145e26.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-ServerProfile-4caad1e6.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples_foes-RiverSkale-39535c12.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples_weapons-Flatbow-22f5bd16.json (2 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/manifest.json (31 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/manifest.toml (11 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-ContractInitialized-376b7bd6.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-Message-1bb1d226.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-MockToken-38903c7c.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-Moved-318ae40d.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-Moves-2e2accba.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-PlayerConfig-3adad785.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-Position-1e145e26.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-ServerProfile-4caad1e6.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples_foes-RiverSkale-39535c12.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples_weapons-Flatbow-22f5bd16.json (2 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-ContractInitialized-376b7bd6.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-Message-1bb1d226.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-MockToken-38903c7c.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-Moved-318ae40d.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-Moves-2e2accba.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-PlayerConfig-3adad785.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-Position-1e145e26.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-ServerProfile-4caad1e6.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples_foes-RiverSkale-39535c12.toml (1 hunks)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples_weapons-Flatbow-22f5bd16.toml (1 hunks)
Files skipped from review due to trivial changes (1)
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-Moved-318ae40d.toml
Files skipped from review as they are similar to previous changes (61)
  • crates/dojo-core/src/lib.cairo
  • crates/dojo-core/src/model/definition.cairo
  • crates/dojo-core/src/model/introspect.cairo
  • crates/dojo-core/src/model/metadata.cairo
  • crates/dojo-core/src/model/model.cairo
  • crates/dojo-core/src/tests/model/model.cairo
  • crates/dojo-lang/src/model.rs
  • crates/dojo-world/src/contracts/abi/model.rs
  • crates/dojo-world/src/contracts/model_test.rs
  • crates/sozo/ops/src/tests/model.rs
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-ContractInitialized-376b7bd6.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-Message-1bb1d226.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-MockToken-38903c7c.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-Moved-318ae40d.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-Moves-2e2accba.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-PlayerConfig-3adad785.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-Position-1e145e26.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples-ServerProfile-4caad1e6.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples_foes-RiverSkale-39535c12.json
  • examples/spawn-and-move/manifests/dev/base/abis/models/dojo_examples_weapons-Flatbow-22f5bd16.json
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-ContractInitialized-376b7bd6.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-Message-1bb1d226.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-MockToken-38903c7c.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-Moved-318ae40d.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-Moves-2e2accba.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-PlayerConfig-3adad785.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-Position-1e145e26.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples-ServerProfile-4caad1e6.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples_foes-RiverSkale-39535c12.toml
  • examples/spawn-and-move/manifests/dev/base/models/dojo_examples_weapons-Flatbow-22f5bd16.toml
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-ContractInitialized-376b7bd6.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-Message-1bb1d226.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-MockToken-38903c7c.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-Moved-318ae40d.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-Moves-2e2accba.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-PlayerConfig-3adad785.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-Position-1e145e26.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples-ServerProfile-4caad1e6.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples_foes-RiverSkale-39535c12.json
  • examples/spawn-and-move/manifests/dev/deployment/abis/models/dojo_examples_weapons-Flatbow-22f5bd16.json
  • examples/spawn-and-move/manifests/dev/deployment/manifest.json
  • examples/spawn-and-move/manifests/dev/deployment/manifest.toml
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-ContractInitialized-376b7bd6.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-Message-1bb1d226.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-MockToken-38903c7c.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-Moved-318ae40d.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-Moves-2e2accba.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-PlayerConfig-3adad785.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-Position-1e145e26.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples-ServerProfile-4caad1e6.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples_foes-RiverSkale-39535c12.json
  • examples/spawn-and-move/manifests/release/base/abis/models/dojo_examples_weapons-Flatbow-22f5bd16.json
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-ContractInitialized-376b7bd6.toml
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-Message-1bb1d226.toml
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-MockToken-38903c7c.toml
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-Moves-2e2accba.toml
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-PlayerConfig-3adad785.toml
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-Position-1e145e26.toml
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples-ServerProfile-4caad1e6.toml
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples_foes-RiverSkale-39535c12.toml
  • examples/spawn-and-move/manifests/release/base/models/dojo_examples_weapons-Flatbow-22f5bd16.toml

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

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.

coderabbitai[bot] avatar Sep 12 '24 08:09 coderabbitai[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 67.94%. Comparing base (bf4ea9b) to head (6e2fdde). Report is 50 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2417      +/-   ##
==========================================
+ Coverage   67.92%   67.94%   +0.01%     
==========================================
  Files         364      364              
  Lines       47759    47845      +86     
==========================================
+ Hits        32439    32506      +67     
- Misses      15320    15339      +19     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Sep 13 '24 09:09 codecov[bot]

Everything have been moved to https://github.com/dojoengine/dojo-core/pull/10 => close this PR.

remybar avatar Oct 07 '24 12:10 remybar