dojo
dojo copied to clipboard
feat: add ModelDefinition to Dojo Model
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
ModelDefinitionstructure to enhance model definitions, including fields forname,namespace,version, and more. - Added functions to retrieve model definitions and schemas across various interfaces, improving metadata management.
- Introduced a new
-
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
ModelDefinitionand related functions.
- Enhanced documentation to clarify the structure and purpose of the new
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.gzis excluded by!**/*.gztypes-test-db.tar.gzis 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere 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.
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.
Everything have been moved to https://github.com/dojoengine/dojo-core/pull/10 => close this PR.