1
1
use cosmwasm_schema:: { cw_serde, QueryResponses } ;
2
2
use cosmwasm_std:: { Binary , Uint128 } ;
3
- use std:: collections:: HashMap ;
4
3
5
4
/// Instantiate message
6
5
#[ cw_serde]
@@ -21,38 +20,33 @@ pub enum ExecuteMsg {
21
20
Insert { input : GraphInput } ,
22
21
23
22
/// # Remove
24
- /// Remove the resources matching the constraints expressed in [resource_sets].
23
+ /// Remove all the Tuples linked to the resources matching the criteria defined in the provided
24
+ /// queries.
25
+ ///
26
+ /// Only the smart contract owner (i.e. the address who instantiated it) is authorized to perform
27
+ /// this action.
25
28
Remove {
26
- /// resource_sets represents multiple sets of resources matching the provided constraints
27
- /// and identified by a key, the key can be used in other constraints to expressed links
28
- /// between resources.
29
- resource_sets : HashMap < String , ResourceConstraints > ,
29
+ /// The queries act as the logical disjunction of each single query, a resource shall match
30
+ /// at least one query.
31
+ queries : Vec < ResourceQuery > ,
30
32
} ,
31
33
}
32
34
33
35
/// Query messages
34
36
#[ cw_serde]
35
37
#[ derive( QueryResponses ) ]
36
38
pub enum QueryMsg {
37
- /// # SelectResources
39
+ /// # Resources
38
40
///
39
- /// Returns the resources matching the constraints expressed in [resource_sets] formatted according
40
- /// to the provided [format].
41
- ///
42
- /// A resource being considered as a set of triples (i.e. subject - predicate - object) having the
43
- /// same subject.
44
- ///
45
- /// The provided [resource_sets] being able to depend on each other, circular dependencies are
46
- /// considered as an error.
47
- #[ returns( SelectResourcesResponse ) ]
48
- SelectResources {
49
- /// resource_sets represents multiple sets of resources matching the provided constraints
50
- /// and identified by a key, the key can be used in other constraints to expressed links
51
- /// between resources.
52
- resource_sets : HashMap < String , ResourceConstraints > ,
53
-
54
- /// format denotes the expected output format. Its value shape the way the response shall be
55
- /// interpreted.
41
+ /// Returns the resources matching the criteria defined in the provided queries formatted according
42
+ /// to the provided format.
43
+ #[ returns( ResourcesResponse ) ]
44
+ Resources {
45
+ /// The queries act as the logical disjunction of each single query, a resource shall match
46
+ /// at least one query.
47
+ queries : Vec < ResourceQuery > ,
48
+
49
+ /// The expected output format. Its value shape the way the response shall be interpreted.
56
50
format : ResourcesOutputFormat ,
57
51
} ,
58
52
}
@@ -80,64 +74,106 @@ pub enum GraphInput {
80
74
NTriples { data : Binary } ,
81
75
}
82
76
77
+ /// # ResourcesOutputFormat
78
+ /// Supported output formats for [QueryMsg::Resources] query.
83
79
#[ cw_serde]
84
80
pub enum ResourcesOutputFormat {
85
- Json {
86
- project : HashMap < String , Vec < String > > ,
87
- } ,
88
- Noop ,
81
+ /// TODO: remove me once there are proper output formats..
82
+ Dummy ,
89
83
}
90
84
85
+ /// # ResourcesResponse
86
+ /// Response to the [QueryMsg::Resources] query, its content depends on the specified [ResourcesOutputFormat].
91
87
#[ cw_serde]
92
- pub enum SelectResourcesResponse { }
88
+ pub enum ResourcesResponse {
89
+ /// TODO: remove me once there are proper output formats..
90
+ Dummy ,
91
+ }
93
92
94
- /// # ResourceConstraints
95
- /// ResourceConstraints contains a set of resource constraints behaving as a logical conjunction, it
96
- /// means that a resource must match all the constraints.
97
- pub type ResourceConstraints = Vec < ResourceConstraint > ;
93
+ /// # ResourceQuery
94
+ /// A named query targeting resources.
95
+ #[ cw_serde]
96
+ pub struct ResourceQuery {
97
+ /// The query name, can be used to reference another query to allow join.
98
+ /// Must be unique.
99
+ pub name : String ,
100
+
101
+ /// The set of criteria a resource must meet to validate the query, it act as the logical
102
+ /// conjunction of all the criteria.
103
+ pub criteria : Vec < ResourceCriteria > ,
104
+ }
98
105
99
- /// # ResourceConstraint
100
- /// ResourceConstraint represents a constraint a resource shall match, it can depends on another
101
- /// resource set to express links between different resources.
106
+ /// # ResourceCriteria
107
+ /// Represents a single query criteria on a resource.
108
+ ///
109
+ /// It can rely on another query referencing it by its name to express conditions on links between
110
+ /// resources (e.g. the `subject` of a resource shall be referenced in a resource of another query).
111
+ /// It behaves as a right join, the resources of the referenced query aren't filtered.
102
112
#[ cw_serde]
103
- pub enum ResourceConstraint {
104
- /// Subject match a resource containing the provided value as subject.
105
- Subject ( String ) ,
113
+ pub enum ResourceCriteria {
114
+ /// Subject match a resource containing the provided node as subject.
115
+ Subject ( Node ) ,
106
116
107
- /// Property match a resource containing the provided pair of ([ predicate], [ object] ).
117
+ /// Property match a resource matching the pair of (` predicate`, ` object` ).
108
118
Property {
109
- /// predicate denotes the predicate to match.
110
- predicate : String ,
119
+ /// The predicate to match.
120
+ predicate : Node ,
111
121
112
- /// object denotes the object value associated with the predicate.
113
- /// It can reference either a literal value or a reference to another resource set.
114
- object : ValueOrRef ,
122
+ /// The object to match, which may be joined on another query.
123
+ object : ValueOrJoin < ObjectValue > ,
115
124
} ,
116
125
117
- /// Referenced match a resource if referenced by another resource. For instance, if the resource's
118
- /// subject under constraint is referenced as the object in another resource's triple, the triple
119
- /// containing the provided pair of ([subject], [predicate]).
126
+ /// Referenced match a resource whose `subject` is referenced in another resource.
120
127
Referenced {
121
- /// subject denotes the resource referencing the resource under constraint.
122
- /// It can reference either a literal value or a reference to another resource set.
123
- subject : ValueOrRef ,
128
+ /// The `subject` the referencing resource shall have, which may be joined on another query.
129
+ referer : ValueOrJoin < Node > ,
124
130
125
- /// The predicate on the referencing resource that shall express the reference.
126
- predicate : String ,
131
+ /// The predicate through which the referencing resource shall express the reference.
132
+ property : Node ,
127
133
} ,
128
134
}
129
135
130
- /// # ValueOrRef
131
- /// ValueOrRef represents an expected value in a resource constraint being either literal or a reference
132
- /// to another resource set.
136
+ /// # Node
137
+ /// Node denotes, among RDF elements, either a named or blank node, for instance:
138
+ ///
139
+ /// A named node can be represented given its IRI: `http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral`.
133
140
///
134
- /// When referencing a resource set the value will be considered as logical disjunction of every
135
- /// resource's subject it contains.
141
+ /// A blank node given its id: `9af906ad-d3b1-4a05-ae4b-9288df593d5b`.
142
+ pub type Node = String ;
143
+
144
+ /// # Literal
145
+ /// Literal represents the possible form an object literal value can have.
136
146
#[ cw_serde]
137
- pub enum ValueOrRef {
138
- /// The literal value.
147
+ pub enum Literal {
148
+ /// A simple string literal value.
139
149
Value ( String ) ,
140
150
141
- /// The reference to another resource set, identified by its key.
142
- ResourceSet ( String ) ,
151
+ /// An internationalized string value.
152
+ I18NValue { value : String , language : String } ,
153
+
154
+ /// A typed value.
155
+ Typed { value : String , datatype : Node } ,
156
+ }
157
+
158
+ /// # ObjectValue
159
+ /// Represents the different value an object can take.
160
+ #[ cw_serde]
161
+ pub enum ObjectValue {
162
+ /// A literal value.
163
+ Literal ( Literal ) ,
164
+
165
+ /// A node to another resource.
166
+ Node ( Node ) ,
167
+ }
168
+
169
+ /// # ValueOrJoin
170
+ /// Represents an expected value in a [ResourceCriteria], which can be either provided static value
171
+ /// or a join on another [ResourceQuery].
172
+ #[ cw_serde]
173
+ pub enum ValueOrJoin < T > {
174
+ /// A static value.
175
+ Value ( T ) ,
176
+
177
+ /// A reference to another [ResourceQuery], identified by its name.
178
+ JoinQuery ( String ) ,
143
179
}
0 commit comments