Add write schema 1.5
Description
Added the write schema method to dojo to write part of a model efficiently
Related issue
Tests
- [x] Yes
- [ ] No, because they aren't needed
- [ ] No, because I need help
Added to documentation?
- [ ] README.md
- [ ] Dojo Book
- [ ] No documentation needed
Checklist
- [x] I've formatted my code (
scripts/rust_fmt.sh,scripts/cairo_fmt.sh) - [ ] I've linted my code (
scripts/clippy.sh,scripts/docs.sh) - [x] I've commented my code
- [ ] I've requested a review after addressing the comments
Summary by CodeRabbit
-
New Features
- Added support for schema-based partial model updates and batch member updates, including new methods for writing and reading schemas.
- Introduced a new event type for tracking batch member updates.
- Added new schema and model structures for more flexible data handling.
- Added a new method to update player configuration items in the example project.
- Added new configuration file for example project setup.
-
Bug Fixes
- Improved event handling and serialization for new schema events.
-
Tests
- Added comprehensive tests for schema-based reading and writing, including equality checks and partial updates.
-
Documentation
- Updated manifests and configuration files to reflect new features and changes.
-
Style
- Enhanced code style with additional trait derivations for equality comparisons.
- Reformatted serialization and deserialization code for improved readability.
Walkthrough
Ohayo sensei! This update introduces schema-based batch operations for models, new event handling for StoreUpdateMembers, and adds support for partial model writes and reads using schemas. It also extends public traits and enums, updates contract logic, and enhances test coverage for schema operations and equality checks.
Changes
| Files/Group | Change Summary |
|---|---|
bin/sozo/src/commands/events.rs |
Added handling and formatting for WorldEvent::StoreUpdateMembers in match_event. |
crates/dojo/core/src/lib.cairo, crates/dojo/core/src/meta/layout.cairo |
Changed public exports; added/renamed traits and methods for field layouts and schema support. |
crates/dojo/core/src/model/definition.cairo |
Added Schema variant to ModelIndex enum. |
crates/dojo/core/src/model/model.cairo |
Added to_schemas method to ModelPtrsTrait and its implementation. |
crates/dojo/core/src/model/storage.cairo, crates/dojo/core/src/world/storage.cairo |
Added write_schema/write_schemas methods; updated schema-based read/write logic. |
crates/dojo/core/src/world/errors.cairo |
Added DELETE_ENTITY_SCHEMA error constant. |
crates/dojo/core/src/world/world_contract.cairo |
Added StoreUpdateMembers event struct/variant; extended contract logic for schema batch updates and events. |
crates/dojo/world/src/contracts/abigen/world.rs |
Added StoreUpdateMembers struct/variant; updated serialization, deserialization, and event matching logic. |
examples/benchmark/src/model.cairo, crates/dojo/core-tests/src/tests/model/model.cairo |
Added PartialEq derives, new schema structs, constants, and comprehensive tests for schema operations. |
examples/spawn-and-move/manifest_dev.json |
Updated manifest: new addresses, Schema variant, StoreUpdateMembers event, new contract function. |
examples/spawn-and-move/src/actions.cairo |
Added update_player_config_items method to actions interface and implementation. |
examples/spawn-and-move/src/models.cairo |
Added PlayerConfigItems struct. |
examples/spawn-and-move/torii_dev.toml |
Added new configuration file for Torii indexer. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant Contract
participant Storage
User->>Contract: set_entity_internal(ModelIndex::Schema, schema_data)
Contract->>Storage: write_struct_layout(schema_data)
Contract->>Contract: emit StoreUpdateMembers event (selector, entity_id, member_selectors, values)
sequenceDiagram
participant User
participant Contract
User->>Contract: delete_entity_internal(ModelIndex::Schema)
Contract->>Contract: panic(DELETE_ENTITY_SCHEMA)
Possibly related PRs
- dojoengine/dojo#2287: Adds handling and event support for the
StoreUpdateMembersevent inmatch_event, closely related to this PR’s event struct and serialization changes. - dojoengine/dojo#2649: Modifies the same
match_eventfunction inbin/sozo/src/commands/events.rs, focusing on event processing and output formatting, complementing this PR’s event variant addition. - dojoengine/dojo#2633: Introduces batch entity operations and the
StoreUpdateMembersevent struct in the world contract and abigen bindings, sharing core event handling code with this PR.
Suggested labels
contributor
Suggested reviewers
- glihm
- kariy
[!NOTE]
⚡️ Unit Test Generation is now available in beta!
Learn more here, or try it out under "Finishing Touches" below.
📜 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 ca45360d1fd13c4af779ec1a8fac302d1d379844 and 2eb84d12ef48b044b9dd40f434ca418a5ad78337.
📒 Files selected for processing (3)
-
crates/dojo/world/src/contracts/abigen/model.rs(16 hunks) -
crates/dojo/world/src/contracts/abigen/world.rs(106 hunks) -
examples/spawn-and-move/src/actions.cairo(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- examples/spawn-and-move/src/actions.cairo
- crates/dojo/world/src/contracts/abigen/world.rs
🔇 Additional comments (7)
crates/dojo/world/src/contracts/abigen/model.rs (7)
82-87: Ohayo sensei! LGTM - Clean formatting improvementThe multi-line formatting with trailing commas improves readability in the auto-generated
cairo_serializemethod.
102-106: Consistent struct construction formatting looks goodThe multi-line struct construction with trailing commas maintains consistency with the serialization formatting above.
126-128: Excellent consistent formatting across all serialize methodsAll the
cairo_serializemethod calls have been consistently formatted to use multi-line style with trailing commas. This greatly improves readability and maintainability of the auto-generated code.Also applies to: 164-166, 207-209, 259-267, 305-310, 348-350
231-237: Well-formatted struct construction in deserialize methodsThe struct construction formatting is now consistent with the serialize methods, using multi-line style with trailing commas for better readability.
Also applies to: 281-285, 322-325, 365-369
411-414: Improved error message formatting in TryFrom implementationsThe multi-line formatting of the error messages makes them more readable while maintaining the same functionality.
Also applies to: 424-427
505-529: Clean multi-line formatting in Layout enum deserialize methodThe consistent multi-line formatting for the
cairo_deserializecalls improves code readability while maintaining the same deserialization logic.
614-633: Consistent formatting applied to Ty enum deserialize methodThe multi-line formatting matches the pattern used throughout the file, providing better readability for the auto-generated deserialization code.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 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. -
Explain this complex logic. -
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 explain this code block. -
@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 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 explain its main purpose. -
@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.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
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 generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai generate unit teststo generate unit tests for this 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.
proc macros have been merged, could you rebase please? Don't hesitate to reach out if you have any questions about the proc macros.