Skip to content

Commit d25c7b8

Browse files
authored
Add array to model and make metadata queryable (#55)
1 parent 0e6ebab commit d25c7b8

File tree

4 files changed

+172
-1
lines changed

4 files changed

+172
-1
lines changed

resources/metadata_array.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"data": {
3+
"id": "det",
4+
"attributes": {
5+
"ancestors": [
6+
"4866611f-e6d9-4517-bedf-fc5526df57ad",
7+
"primary"
8+
],
9+
"structure_family": "array",
10+
"specs": [],
11+
"metadata": {},
12+
"structure": {
13+
"data_type": {
14+
"endianness": "not_applicable",
15+
"kind": "i",
16+
"itemsize": 1,
17+
"dt_units": null
18+
},
19+
"chunks": [
20+
[
21+
1,
22+
1,
23+
1,
24+
1,
25+
1
26+
],
27+
[
28+
1024
29+
],
30+
[
31+
1024
32+
]
33+
],
34+
"shape": [
35+
5,
36+
1024,
37+
1024
38+
],
39+
"dims": null,
40+
"resizable": false
41+
},
42+
"access_blob": {},
43+
"sorting": null,
44+
"data_sources": null
45+
},
46+
"links": {
47+
"self": "http://0.0.0.0:8000/api/v1/metadata/4866611f-e6d9-4517-bedf-fc5526df57ad/primary/det",
48+
"full": "http://0.0.0.0:8000/api/v1/array/full/4866611f-e6d9-4517-bedf-fc5526df57ad/primary/det",
49+
"block": "http://0.0.0.0:8000/api/v1/array/block/4866611f-e6d9-4517-bedf-fc5526df57ad/primary/det?block={0},{1},{2}"
50+
},
51+
"meta": null
52+
},
53+
"error": null,
54+
"links": null,
55+
"meta": {}
56+
}

src/clients.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::de::DeserializeOwned;
66
use tracing::{info, instrument};
77
use uuid::Uuid;
88

9-
use crate::model::{app, container, event_stream, run, table};
9+
use crate::model::{app, array, container, event_stream, run, table};
1010

1111
pub type ClientResult<T> = Result<T, ClientError>;
1212

@@ -46,6 +46,15 @@ impl TiledClient {
4646
self.request(&format!("/api/v1/metadata/{id}/{stream}"), None)
4747
.await
4848
}
49+
pub async fn array_metadata(
50+
&self,
51+
id: Uuid,
52+
stream: String,
53+
array: String,
54+
) -> ClientResult<array::ArrayMetadataRoot> {
55+
self.request(&format!("/api/v1/metadata/{id}/{stream}/{array}"), None)
56+
.await
57+
}
4958
pub async fn table_metadata(
5059
&self,
5160
id: Uuid,

src/model.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub(crate) mod app;
2+
pub(crate) mod array;
23
pub(crate) mod container;
34
pub(crate) mod event_stream;
45
pub(crate) mod node;
@@ -32,6 +33,15 @@ impl TiledQuery {
3233
self.0.event_stream_metadata(id, stream).await
3334
}
3435
#[instrument(skip(self))]
36+
async fn array_metadata(
37+
&self,
38+
id: Uuid,
39+
stream: String,
40+
array: String,
41+
) -> Result<array::ArrayMetadataRoot, ClientError> {
42+
self.0.array_metadata(id, stream, array).await
43+
}
44+
#[instrument(skip(self))]
3545
async fn table_metadata(
3646
&self,
3747
id: Uuid,
@@ -131,6 +141,31 @@ mod tests {
131141
mock.assert();
132142
}
133143
#[tokio::test]
144+
async fn array_metadata() {
145+
let id = Uuid::parse_str("4866611f-e6d9-4517-bedf-fc5526df57ad").unwrap();
146+
let stream = "primary";
147+
let array = "det";
148+
let server = MockServer::start();
149+
let mock = server
150+
.mock_async(|when, then| {
151+
when.method("GET")
152+
.path(format!("/api/v1/metadata/{id}/{stream}/{array}"));
153+
then.status(200)
154+
.body_from_file("resources/metadata_array.json");
155+
})
156+
.await;
157+
let schema = build_schema(&server.base_url());
158+
let query = r#"{ arrayMetadata(id:"4866611f-e6d9-4517-bedf-fc5526df57ad", stream:"primary", array:"det") {data {id}}}"#;
159+
let response = schema.execute(query).await;
160+
let exp = value! ({
161+
"arrayMetadata": { "data": {"id": "det"}}
162+
});
163+
164+
assert_eq!(response.data, exp);
165+
assert_eq!(response.errors, &[]);
166+
mock.assert();
167+
}
168+
#[tokio::test]
134169
async fn table_metadata() {
135170
let id = Uuid::parse_str("4866611f-e6d9-4517-bedf-fc5526df57ad").unwrap();
136171
let stream = "primary";

src/model/array.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use std::collections::HashMap;
2+
3+
use async_graphql::SimpleObject;
4+
use serde::{Deserialize, Serialize};
5+
use serde_json::Value;
6+
7+
use crate::model::node;
8+
9+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)]
10+
pub struct ArrayMetadataRoot {
11+
pub data: ArrayData,
12+
pub error: Value,
13+
pub links: Option<node::Links>,
14+
pub meta: Value,
15+
}
16+
17+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)]
18+
pub struct ArrayData {
19+
pub id: String,
20+
pub attributes: ArrayAttributes,
21+
pub links: ArrayLinks,
22+
pub meta: Value,
23+
}
24+
25+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)]
26+
pub struct ArrayAttributes {
27+
pub ancestors: Vec<Value>,
28+
pub structure_family: String,
29+
pub specs: Option<Vec<Value>>,
30+
pub metadata: HashMap<String, Value>,
31+
pub structure: ArrayStructure,
32+
pub access_blob: Value,
33+
pub sorting: Value,
34+
pub data_sources: Value,
35+
}
36+
37+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)]
38+
pub struct ArrayStructure {
39+
data_type: DataType,
40+
chunks: Value,
41+
shape: Value,
42+
dims: Value,
43+
resizable: bool,
44+
}
45+
46+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)]
47+
pub struct DataType {
48+
endianness: String,
49+
kind: String,
50+
itemsize: i64,
51+
dt_units: Value,
52+
}
53+
54+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)]
55+
pub struct ArrayLinks {
56+
#[serde(rename = "self")]
57+
#[graphql(name = "self")]
58+
pub full: Option<String>,
59+
pub block: Option<String>,
60+
}
61+
62+
#[cfg(test)]
63+
mod tests {
64+
use crate::model::array;
65+
use crate::test_utils::assert_readable_as;
66+
67+
#[test]
68+
fn array_metadata() {
69+
assert_readable_as::<array::ArrayMetadataRoot>("resources/metadata_array.json");
70+
}
71+
}

0 commit comments

Comments
 (0)