Skip to content

Commit 0d365a8

Browse files
authored
Merge pull request #73 from dojoengine/feat/model-filtering
feat: add model filtering
2 parents 2afd5e6 + e8efc27 commit 0d365a8

File tree

8 files changed

+58
-19
lines changed

8 files changed

+58
-19
lines changed

Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ crate-type = ["cdylib", "rlib", "staticlib"]
88

99

1010
[dependencies]
11-
dojo-world = { git = "https://github.com/dojoengine/dojo", rev = "bcd581e" }
12-
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "bcd581e" }
13-
torii-client = { git = "https://github.com/dojoengine/dojo", rev = "bcd581e" }
11+
dojo-world = { git = "https://github.com/dojoengine/dojo", rev = "180c6d2" }
12+
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "180c6d2" }
13+
torii-client = { git = "https://github.com/dojoengine/dojo", rev = "180c6d2" }
1414
torii-grpc = { git = "https://github.com/dojoengine/dojo", features = [
1515
"client",
16-
], rev = "bcd581e" }
17-
torii-relay = { git = "https://github.com/dojoengine/dojo", rev = "bcd581e" }
16+
], rev = "180c6d2" }
17+
torii-relay = { git = "https://github.com/dojoengine/dojo", rev = "180c6d2" }
1818

1919
starknet = "0.12.0"
2020
starknet-crypto = "0.7.2"

dojo.h

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ typedef struct Query {
386386
struct COptionClause clause;
387387
bool dont_include_hashed_keys;
388388
struct CArrayOrderBy order_by;
389+
struct CArrayc_char entity_models;
389390
} Query;
390391

391392
typedef struct CArrayFieldElement {

dojo.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ struct Query {
724724
COption<Clause> clause;
725725
bool dont_include_hashed_keys;
726726
CArray<OrderBy> order_by;
727+
CArray<const char*> entity_models;
727728
};
728729

729730
struct ModelMetadata {

dojo.pyx

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ cdef extern from *:
255255
COptionClause clause;
256256
bool dont_include_hashed_keys;
257257
CArrayOrderBy order_by;
258+
CArrayc_char entity_models;
258259

259260
cdef struct CArrayFieldElement:
260261
FieldElement *data;

src/c/types.rs

+33
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,31 @@ impl<T> From<&CArray<T>> for Vec<T> {
251251
}
252252
}
253253

254+
impl From<&CArray<*const c_char>> for Vec<String> {
255+
fn from(val: &CArray<*const c_char>) -> Self {
256+
let mut strings = Vec::with_capacity(val.data_len);
257+
for i in 0..val.data_len {
258+
let c_str = unsafe { CStr::from_ptr(val.data.wrapping_add(i).read()) };
259+
strings.push(c_str.to_string_lossy().into_owned());
260+
}
261+
strings
262+
}
263+
}
264+
265+
impl From<Vec<String>> for CArray<*const c_char> {
266+
fn from(val: Vec<String>) -> Self {
267+
let c_strings: Vec<*const c_char> =
268+
val.into_iter().map(|s| CString::new(s).unwrap().into_raw() as *const c_char).collect();
269+
270+
let data = c_strings.as_ptr() as *mut *const c_char;
271+
let data_len = c_strings.len();
272+
273+
std::mem::forget(c_strings);
274+
275+
CArray { data, data_len }
276+
}
277+
}
278+
254279
#[derive(Clone, Debug)]
255280
#[repr(C)]
256281
pub struct CHashItem<K, V> {
@@ -300,6 +325,7 @@ pub struct Query {
300325
pub clause: COption<Clause>,
301326
pub dont_include_hashed_keys: bool,
302327
pub order_by: CArray<OrderBy>,
328+
pub entity_models: CArray<*const c_char>,
303329
}
304330

305331
#[derive(Clone, Debug)]
@@ -857,6 +883,8 @@ impl From<&Query> for torii_grpc::types::Query {
857883
let order_by: Vec<OrderBy> = (&val.order_by).into();
858884
let order_by = order_by.iter().map(|o| o.into()).collect();
859885

886+
let entity_models: Vec<String> = (&val.entity_models).into();
887+
860888
match &val.clause {
861889
COption::Some(clause) => {
862890
let clause = (&clause.clone()).into();
@@ -866,6 +894,7 @@ impl From<&Query> for torii_grpc::types::Query {
866894
clause: Option::Some(clause),
867895
dont_include_hashed_keys: val.dont_include_hashed_keys,
868896
order_by,
897+
entity_models,
869898
}
870899
}
871900
COption::None => torii_grpc::types::Query {
@@ -874,6 +903,7 @@ impl From<&Query> for torii_grpc::types::Query {
874903
clause: Option::None,
875904
dont_include_hashed_keys: val.dont_include_hashed_keys,
876905
order_by,
906+
entity_models,
877907
},
878908
}
879909
}
@@ -882,6 +912,7 @@ impl From<&Query> for torii_grpc::types::Query {
882912
impl From<&torii_grpc::types::Query> for Query {
883913
fn from(val: &torii_grpc::types::Query) -> Self {
884914
let order_by = val.order_by.iter().map(|o| o.into()).collect::<Vec<OrderBy>>();
915+
let entity_models = val.clone().entity_models.into();
885916

886917
match &val.clause {
887918
Option::Some(clause) => {
@@ -892,6 +923,7 @@ impl From<&torii_grpc::types::Query> for Query {
892923
clause: COption::Some(clause),
893924
dont_include_hashed_keys: val.dont_include_hashed_keys,
894925
order_by: order_by.into(),
926+
entity_models,
895927
}
896928
}
897929
Option::None => Query {
@@ -900,6 +932,7 @@ impl From<&torii_grpc::types::Query> for Query {
900932
clause: COption::None,
901933
dont_include_hashed_keys: val.dont_include_hashed_keys,
902934
order_by: order_by.into(),
935+
entity_models,
903936
},
904937
}
905938
}

src/wasm/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ impl ToriiClient {
688688
clause: None,
689689
dont_include_hashed_keys: false,
690690
order_by: vec![],
691+
entity_models: vec![],
691692
})
692693
.await;
693694

src/wasm/types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ pub struct Query {
288288
pub clause: Option<Clause>,
289289
pub dont_include_hashed_keys: bool,
290290
pub order_by: Vec<OrderBy>,
291+
pub entity_models: Vec<String>,
291292
}
292293

293294
#[derive(Tsify, Serialize, Deserialize, Debug)]
@@ -332,6 +333,7 @@ impl From<&Query> for torii_grpc::types::Query {
332333
clause: value.clause.as_ref().map(|c| c.into()),
333334
dont_include_hashed_keys: value.dont_include_hashed_keys,
334335
order_by: value.order_by.iter().map(|o| o.into()).collect(),
336+
entity_models: value.entity_models.iter().map(|m| m.to_string()).collect(),
335337
}
336338
}
337339
}

0 commit comments

Comments
 (0)