1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
use activitystreams_vocabulary::{Collection, Iri, create_actor, create_item, field_access};
create_actor! {
/// Represents a project, a planned endeavor that involves usage of tools related to the software development lifecycle.
///
/// It may be a software project, but may also be totally unrelated to software development.
///
/// For example, it may be a book that is being written using Markdown files kept in a Git repository.
///
/// A [Project] object is a way to collect forge related components together under one title.
///
/// # Example
///
/// ```rust
/// use activityforge::{Project, context};
/// use activitystreams_vocabulary::{
/// Collection, Iri, MultibaseHeader, MultibasePublicKey, Multikey, MultikeyPublicKey, Name,
/// };
///
/// # fn main() {
/// let id = Iri::try_from("https://dev.example/projects/wanderer").unwrap();
/// let name = Name::try_from("Wanderer").unwrap();
/// let summary = "3D nature exploration game";
/// let inbox = Iri::try_from("https://dev.example/projects/wanderer/inbox").unwrap();
/// let outbox = Iri::try_from("https://dev.example/projects/wanderer/outbox").unwrap();
/// let followers = Iri::try_from("https://dev.example/projects/wanderer/followers").unwrap();
///
/// let key_id = Iri::try_from("https://dev.example/aviva/treesim#main-key").unwrap();
/// let controller = Iri::try_from("https://dev.example/aviva/treesim").unwrap();
/// let encoded_multibase = "u7QGwDY2Tjn93PVFWWq02piP1NE9_XRlg-c8-jhJiHqKBHw";
///
/// let item0 = Iri::try_from("https://dev.example/repos/opengl-vegetation").unwrap();
/// let item1 = Iri::try_from("https://dev.example/repos/opengl-vegetation/patch-tracker").unwrap();
/// let item2 = Iri::try_from("https://dev.example/repos/treesim").unwrap();
/// let item3 = Iri::try_from("https://dev.example/repos/treesim/patch-tracker").unwrap();
/// let item4 = Iri::try_from("https://dev.example/repos/wanderer").unwrap();
/// let item5 = Iri::try_from("https://dev.example/repos/wanderer/patch-tracker").unwrap();
/// let item6 = Iri::try_from("https://dev.example/issue-trackers/wanderer").unwrap();
///
/// let json_str = format!(
/// r#"{{
/// "@context": [
/// "https://www.w3.org/ns/activitystreams",
/// "https://forgefed.org/ns"
/// ],
/// "type": "Project",
/// "id": "{id}",
/// "name": "{name}",
/// "summary": "{summary}",
/// "inbox": "{inbox}",
/// "outbox": "{outbox}",
/// "followers": "{followers}",
/// "assertionMethod": [
/// {{
/// "type": "Multikey",
/// "id": "{key_id}",
/// "controller": "{controller}",
/// "publicKeyMultibase": "{encoded_multibase}"
/// }}
/// ],
/// "components": {{
/// "type": "Collection",
/// "totalItems": 7,
/// "items": [
/// "{item0}",
/// "{item1}",
/// "{item2}",
/// "{item3}",
/// "{item4}",
/// "{item5}",
/// "{item6}"
/// ]
/// }}
/// }}"#
/// );
///
/// let context = context::forgefed_context();
///
/// let multibase = MultibasePublicKey::new()
/// .with_header(MultibaseHeader::Base64UrlNoPad)
/// .with_key(MultikeyPublicKey::Ed25519([
/// 0xb0, 0x0d, 0x8d, 0x93, 0x8e, 0x7f, 0x77, 0x3d, 0x51, 0x56, 0x5a, 0xad, 0x36, 0xa6,
/// 0x23, 0xf5, 0x34, 0x4f, 0x7f, 0x5d, 0x19, 0x60, 0xf9, 0xcf, 0x3e, 0x8e, 0x12, 0x62,
/// 0x1e, 0xa2, 0x81, 0x1f,
/// ]));
///
/// let multikey = Multikey::new_inner()
/// .with_id(key_id)
/// .with_controller(controller.clone())
/// .with_public_key_multibase(multibase);
///
/// let items = [item0, item1, item2, item3, item4, item5, item6];
/// let components = Collection::new_inner()
/// .with_total_items(items.len() as u64)
/// .with_items(items);
///
/// let project = Project::new()
/// .with_context_property(context)
/// .with_id(id)
/// .with_name(name)
/// .with_summary(summary)
/// .with_inbox(inbox)
/// .with_outbox(outbox)
/// .with_followers(followers)
/// .with_assertion_method([multikey])
/// .with_components(components);
///
/// assert_eq!(serde_json::to_string_pretty(&project).unwrap(), json_str);
/// assert_eq!(
/// serde_json::from_str::<Project>(json_str.as_str()).unwrap(),
/// project
/// );
/// # }
/// ```
Project: crate::ActorType::Project {
components: Option<Collection>,
}
}
field_access! {
Project {
/// Identifies a [Collection](activitystreams_vocabulary::Collection) listing actors whose services and resources are considered to be components of this project.
///
/// The collection items are Relationship objects whose relationship is hasComponent and whose instrument is the maximal role allowed for delegation, specified when the component was added.
components: option_ref { Collection },
}
}
create_item! {
ProjectItem
boxed
default: Self::Project(Box::default()),
{
Project(Project),
Iri(Iri),
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::context;
use activitystreams_vocabulary::{
MultibaseHeader, MultibasePublicKey, Multikey, MultikeyPublicKey, Name,
};
#[test]
fn test_valid() {
let id = Iri::try_from("https://dev.example/projects/wanderer").unwrap();
let name = Name::try_from("Wanderer").unwrap();
let summary = "3D nature exploration game";
let inbox = Iri::try_from("https://dev.example/projects/wanderer/inbox").unwrap();
let outbox = Iri::try_from("https://dev.example/projects/wanderer/outbox").unwrap();
let followers = Iri::try_from("https://dev.example/projects/wanderer/followers").unwrap();
let key_id = Iri::try_from("https://dev.example/aviva/treesim#main-key").unwrap();
let controller = Iri::try_from("https://dev.example/aviva/treesim").unwrap();
let encoded_multibase = "u7QGwDY2Tjn93PVFWWq02piP1NE9_XRlg-c8-jhJiHqKBHw";
let item0 = Iri::try_from("https://dev.example/repos/opengl-vegetation").unwrap();
let item1 =
Iri::try_from("https://dev.example/repos/opengl-vegetation/patch-tracker").unwrap();
let item2 = Iri::try_from("https://dev.example/repos/treesim").unwrap();
let item3 = Iri::try_from("https://dev.example/repos/treesim/patch-tracker").unwrap();
let item4 = Iri::try_from("https://dev.example/repos/wanderer").unwrap();
let item5 = Iri::try_from("https://dev.example/repos/wanderer/patch-tracker").unwrap();
let item6 = Iri::try_from("https://dev.example/issue-trackers/wanderer").unwrap();
let json_str = format!(
r#"{{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://forgefed.org/ns"
],
"type": "Project",
"id": "{id}",
"name": "{name}",
"summary": "{summary}",
"inbox": "{inbox}",
"outbox": "{outbox}",
"followers": "{followers}",
"assertionMethod": [
{{
"type": "Multikey",
"id": "{key_id}",
"controller": "{controller}",
"publicKeyMultibase": "{encoded_multibase}"
}}
],
"components": {{
"type": "Collection",
"totalItems": 7,
"items": [
"{item0}",
"{item1}",
"{item2}",
"{item3}",
"{item4}",
"{item5}",
"{item6}"
]
}}
}}"#
);
let context = context::forgefed_context();
let multibase = MultibasePublicKey::new()
.with_header(MultibaseHeader::Base64UrlNoPad)
.with_key(MultikeyPublicKey::Ed25519([
0xb0, 0x0d, 0x8d, 0x93, 0x8e, 0x7f, 0x77, 0x3d, 0x51, 0x56, 0x5a, 0xad, 0x36, 0xa6,
0x23, 0xf5, 0x34, 0x4f, 0x7f, 0x5d, 0x19, 0x60, 0xf9, 0xcf, 0x3e, 0x8e, 0x12, 0x62,
0x1e, 0xa2, 0x81, 0x1f,
]));
let multikey = Multikey::new_inner()
.with_id(key_id)
.with_controller(controller.clone())
.with_public_key_multibase(multibase);
let items = [item0, item1, item2, item3, item4, item5, item6];
let components = Collection::new_inner()
.with_total_items(items.len() as u64)
.with_items(items);
let project = Project::new()
.with_context_property(context)
.with_id(id)
.with_name(name)
.with_summary(summary)
.with_inbox(inbox)
.with_outbox(outbox)
.with_followers(followers)
.with_assertion_method([multikey])
.with_components(components);
assert_eq!(serde_json::to_string_pretty(&project).unwrap(), json_str);
assert_eq!(
serde_json::from_str::<Project>(json_str.as_str()).unwrap(),
project
);
}
}