-
Notifications
You must be signed in to change notification settings - Fork 194
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(dojo-core): add read schema support #2932
Changes from 10 commits
66c882e
dbe3895
30c7d3c
77ea57a
772f1a7
33b5026
790bc56
b95b94b
5dd114c
1ed7b99
5643b53
95bdb30
b3ea517
89883f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ use dojo::{ | |
utils::{entity_id_from_serialized_keys, find_model_field_layout, entity_id_from_keys}, | ||
}; | ||
|
||
use super::{ModelDefinition, ModelDef}; | ||
use super::{ModelDefinition, ModelDef, ModelIndex}; | ||
/// Trait `KeyParser` defines a trait for parsing keys from a given model. | ||
/// | ||
/// A pointer to a model, which can be expressed by an entity id. | ||
|
@@ -12,6 +12,20 @@ pub struct ModelPtr<M> { | |
pub id: felt252, | ||
} | ||
|
||
pub trait ModelPtrsTrait<M> { | ||
fn to_indexes(self: Span<ModelPtr<M>>) -> Span<ModelIndex>; | ||
} | ||
|
||
pub impl ModelPtrsImpl<M> of ModelPtrsTrait<M> { | ||
fn to_indexes(self: Span<ModelPtr<M>>) -> Span<ModelIndex> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you document this function and why it has been necessary adding it? |
||
let mut ids = ArrayTrait::<ModelIndex>::new(); | ||
for ptr in self { | ||
ids.append(ModelIndex::Id(*ptr.id)); | ||
}; | ||
ids.span() | ||
} | ||
} | ||
|
||
pub trait KeyParser<M, K> { | ||
/// Parses the key from the given model. | ||
fn parse_key(self: @M) -> K; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use dojo::{model::{ModelPtr, model_value::ModelValueKey}}; | ||
use dojo::{model::{ModelPtr, model_value::ModelValueKey}, meta::Introspect}; | ||
|
||
// TODO: define the right interface for member accesses. | ||
|
||
|
@@ -35,10 +35,18 @@ pub trait ModelStorage<S, M> { | |
/// The ptr is mostly used for type inferrence. | ||
fn erase_models_ptrs(ref self: S, ptrs: Span<ModelPtr<M>>); | ||
|
||
/// Retrieves a model of type `M` using the provided entity idref . | ||
/// Retrieves a model of type `M` using the provided entity id. | ||
fn read_member<T, +Serde<T>>(self: @S, ptr: ModelPtr<M>, field_selector: felt252) -> T; | ||
|
||
/// Retrieves a model of type `M` using the provided entity id. | ||
/// Retrieves part of a model, matching a schema. | ||
fn read_schema<T, +Serde<T>, +Introspect<T>>(self: @S, ptr: ModelPtr<M>) -> T; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a bit more comments here, to show what a schema is. |
||
|
||
/// Retrieves part of multiple models, matching a schema. | ||
fn read_schemas<T, +Drop<T>, +Serde<T>, +Introspect<T>>( | ||
self: @S, ptrs: Span<ModelPtr<M>>, | ||
) -> Array<T>; | ||
|
||
/// Updates a member of a model. | ||
fn write_member<T, +Serde<T>, +Drop<T>>( | ||
ref self: S, ptr: ModelPtr<M>, field_selector: felt252, value: T, | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "dojo" | ||
version = "1.0.12" | ||
dependencies = [ | ||
"dojo_plugin", | ||
] | ||
|
||
[[package]] | ||
name = "dojo_benchmark" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"dojo", | ||
"dojo_cairo_test", | ||
] | ||
|
||
[[package]] | ||
name = "dojo_cairo_test" | ||
version = "1.0.12" | ||
dependencies = [ | ||
"dojo", | ||
] | ||
|
||
[[package]] | ||
name = "dojo_plugin" | ||
version = "2.9.2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
cairo-version = "=2.9.2" | ||
name = "dojo_benchmark" | ||
version = "0.1.0" | ||
edition = "2024_07" | ||
|
||
[[target.starknet-contract]] | ||
sierra = true | ||
casm = true | ||
build-external-contracts = ["dojo::world::world_contract::world"] | ||
|
||
[dependencies] | ||
dojo = { path = "../../crates/dojo/core" } | ||
starknet = "2.9.2" | ||
|
||
[dev-dependencies] | ||
cairo_test = "2.9.2" | ||
dojo_cairo_test = { path = "../../crates/dojo/core-cairo-test" } | ||
|
||
[features] | ||
default = [] | ||
|
||
[profile.sepolia] |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep this file to the minimum, I think only the |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||||||||||||||||||||||||||||||
[world] | ||||||||||||||||||||||||||||||||||
description = "Simple world." | ||||||||||||||||||||||||||||||||||
name = "simple" | ||||||||||||||||||||||||||||||||||
seed = "simple" | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Ohayo sensei! Inconsistent world configuration in benchmark directory. The benchmark directory's configuration should use "bench" instead of "simple" to maintain consistency with other benchmark-related files:
🔗 Analysis chainOhayo sensei! Verify world configuration consistency. The world configuration appears minimal and clean. However, the values differ from those suggested in previous reviews ("simple" vs "bench"). Please ensure these values are consistent with other configuration files and documentation. Let's check for consistency across the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for "simple" and "bench" in configuration files and documentation
echo "Searching for world name/seed usage..."
rg -g '*.{toml,json,md}' -i 'name.*=.*"?(simple|bench)"?'
rg -g '*.{toml,json,md}' -i 'seed.*=.*"?(simple|bench)"?'
Length of output: 803 |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
[env] | ||||||||||||||||||||||||||||||||||
rpc_url = "http://localhost:5050/" | ||||||||||||||||||||||||||||||||||
# Default account for katana with seed = 0 | ||||||||||||||||||||||||||||||||||
account_address = "0x127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec" | ||||||||||||||||||||||||||||||||||
private_key = "0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912" | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security Alert: Exposed Private Key, sensei! The private key should not be hardcoded in the configuration file, even for development. Consider:
🧰 Tools🪛 Gitleaks (8.21.2)10-10: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) |
||||||||||||||||||||||||||||||||||
#world_address = "0x01fdfa7a4dc649d4203d5669fb8086474a686458ea86f95027c7b9a5f10d43bb" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
[namespace] | ||||||||||||||||||||||||||||||||||
default = "ns" | ||||||||||||||||||||||||||||||||||
mappings = { "ns" = ["c1", "M"], "ns2" = ["c1", "M"] } | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
[init_call_args] | ||||||||||||||||||||||||||||||||||
"ns-c1" = ["0xfffe"] | ||||||||||||||||||||||||||||||||||
"ns2-c1" = ["0xfffe"] | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
[writers] | ||||||||||||||||||||||||||||||||||
"ns" = ["ns-c1", "ns-c2"] | ||||||||||||||||||||||||||||||||||
"ns-M" = ["ns-c2", "ns-c1", "ns2-c1"] | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
[owners] | ||||||||||||||||||||||||||||||||||
"ns" = ["ns-c1"] | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
[migration] | ||||||||||||||||||||||||||||||||||
order_inits = ["ns-c2", "ns-c1"] | ||||||||||||||||||||||||||||||||||
skip_contracts = ["ns-c3"] | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use more descriptive names please.