diff --git a/contracts/okp4-cognitarium/src/contract.rs b/contracts/okp4-cognitarium/src/contract.rs index 95a38a84..93adbdc7 100644 --- a/contracts/okp4-cognitarium/src/contract.rs +++ b/contracts/okp4-cognitarium/src/contract.rs @@ -80,7 +80,12 @@ pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> StdResult { QueryMsg::Describe { query, format } => to_binary(&query::describe( deps, query, - format.unwrap_or(DataFormat::Turtle), + format.unwrap_or(DataFormat::default()), + )?), + QueryMsg::Construct { query, format } => to_binary(&query::construct( + deps, + query, + format.unwrap_or(DataFormat::default()), )?), } } @@ -90,9 +95,9 @@ pub mod query { use super::*; use crate::msg::{ - DescribeQuery, DescribeResponse, Node, Prefix, SelectItem, SelectQuery, SelectResponse, - SimpleWhereCondition, StoreResponse, TriplePattern, Value, VarOrNamedNode, VarOrNode, - VarOrNodeOrLiteral, WhereCondition, + ConstructQuery, DescribeQuery, DescribeResponse, Node, Prefix, SelectItem, SelectQuery, + SelectResponse, SimpleWhereCondition, StoreResponse, TriplePattern, Value, VarOrNamedNode, + VarOrNode, VarOrNodeOrLiteral, WhereCondition, }; use crate::querier::{PlanBuilder, QueryEngine}; use crate::rdf::{self, Atom, TripleWriter}; @@ -224,6 +229,14 @@ pub mod query { data: Binary::from(out), }) } + + pub fn construct( + _deps: Deps<'_>, + _query: ConstructQuery, + _format: DataFormat, + ) -> StdResult { + todo!() + } } #[cfg(test)] diff --git a/contracts/okp4-cognitarium/src/msg.rs b/contracts/okp4-cognitarium/src/msg.rs index 4ce66e22..2635f7af 100644 --- a/contracts/okp4-cognitarium/src/msg.rs +++ b/contracts/okp4-cognitarium/src/msg.rs @@ -107,12 +107,26 @@ pub enum QueryMsg { /// If not provided, the default format is [Turtle](https://www.w3.org/TR/turtle/) format. format: Option, }, + + /// # Construct + /// + /// Returns the resources matching the criteria defined by the provided query as a set of RDF + /// triples serialized in the provided format. + #[returns(ConstructResponse)] + Construct { + /// The query to execute. + query: ConstructQuery, + /// The format in which the triples are serialized. + /// If not provided, the default format is [Turtle](https://www.w3.org/TR/turtle/) format. + format: Option, + }, } /// # DataFormat /// Represents the format in which the data are serialized, for example when returned by a query or /// when inserted in the store. #[cw_serde] +#[derive(Default)] pub enum DataFormat { /// # RDF XML /// Output in [RDF/XML](https://www.w3.org/TR/rdf-syntax-grammar/) format. @@ -121,6 +135,7 @@ pub enum DataFormat { /// # Turtle /// Output in [Turtle](https://www.w3.org/TR/turtle/) format. #[serde(rename = "turtle")] + #[default] Turtle, /// # N-Triples /// Output in [N-Triples](https://www.w3.org/TR/n-triples/) format. @@ -308,6 +323,16 @@ pub struct DescribeResponse { pub data: Binary, } +/// # ConstructResponse +/// Represents the response of a [QueryMsg::Construct] query. +#[cw_serde] +pub struct ConstructResponse { + /// The format of the data. + pub format: DataFormat, + /// The data serialized in the specified format. + pub data: Binary, +} + /// # Head /// Represents the head of a [SelectResponse]. #[cw_serde] @@ -389,6 +414,21 @@ pub struct DescribeQuery { pub r#where: WhereClause, } +/// # ConstructQuery +/// Represents a CONSTRUCT query over the triple store, allowing to retrieve a set of triples +/// serialized in a specific format. +#[cw_serde] +pub struct ConstructQuery { + /// The prefixes used in the query. + pub prefixes: Vec, + /// The triples to construct. + /// If nothing is provided, the patterns from the `where` clause are used for construction. + pub construct: Vec, + /// The WHERE clause. + /// This clause is used to specify the triples to construct using variable bindings. + pub r#where: WhereClause, +} + /// # Prefix /// Represents a prefix in a [SelectQuery]. A prefix is a shortcut for a namespace used in the query. #[cw_serde]