Base protocol refactor complete
parent: tbd commit: 079d544
1 | |
2 | |
3 | use ; |
4 | |
5 | use |
6 | , | OperationError
7 | , |
8 | , |
9 | ; |
10 | use Debug; |
11 | use Mutex; |
12 | |
13 | use crate; |
14 | |
15 | use |
16 | repository_get_setting, repository_get_value, repository_set_setting, user_get_setting, |
17 | user_get_value, user_set_setting, OperationHandlers, |
18 | ; |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | async |
26 | &self, |
27 | _object: O, |
28 | _operation: D, |
29 | |
30 | // We don't handle operations with this backend |
31 | Err |
32 | |
33 | |
34 | async |
35 | &self, |
36 | _object_str: &str, |
37 | |
38 | Err |
39 | |
40 | |
41 | |
42 | /// A backend implementation which attempts to resolve data from the instance's database. |
43 | |
44 | |
45 | pub(self) our_instance: Instance, |
46 | pub(self) user_backend: , |
47 | pub(self) repository_backend: , |
48 | |
49 | |
50 | |
51 | |
52 | f.debug_struct .finish |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | async |
59 | &self, |
60 | object: O, |
61 | operation: D, |
62 | |
63 | let serialized = |
64 | map_err?; | to_value .
65 | let object = object.to_string; |
66 | if let Ok = from_str |
67 | let mut handler = default; |
68 | |
69 | handler |
70 | .insert |
71 | .insert |
72 | .insert; |
73 | |
74 | match handler |
75 | .handle |
76 | &user, |
77 | , | operation_name
78 | unwrap, | from_value .
79 | self.clone, |
80 | |
81 | .await |
82 | |
83 | Ok => Ok |
84 | .map_err?, |
85 | Err => match err |
86 | => Err, | Internal
87 | => Err, | Unhandled
88 | => Err | Operation
89 | from_slice |
90 | .map_err?, |
91 | , |
92 | , |
93 | |
94 | else if let Ok = from_str |
95 | let mut handler = default; |
96 | |
97 | handler |
98 | .insert |
99 | .insert |
100 | .insert; |
101 | |
102 | match handler |
103 | .handle |
104 | &repository, |
105 | , | operation_name
106 | unwrap, | from_value .
107 | self.clone, |
108 | |
109 | .await |
110 | |
111 | Ok => Ok |
112 | .map_err?, |
113 | Err => match err |
114 | => Err, | Internal
115 | => Err, | Unhandled
116 | => Err | Operation
117 | from_slice |
118 | .map_err?, |
119 | , |
120 | , |
121 | |
122 | else if .is_ok |
123 | Err |
124 | else |
125 | Err |
126 | |
127 | |
128 | |
129 | async |
130 | &self, |
131 | object_str: &str, |
132 | |
133 | if let Ok = from_str |
134 | let mut user_backend = self.user_backend.lock .await; |
135 | |
136 | if user_backend |
137 | .exists |
138 | .await |
139 | .map_err? |
140 | |
141 | Ok |
142 | new_unchecked |
143 | from_object_str |
144 | .map_err?, |
145 | self.clone, |
146 | |
147 | |
148 | else |
149 | return Err; |
150 | |
151 | else if let Ok = from_str |
152 | let mut repository_backend = self.repository_backend.lock .await; |
153 | |
154 | if repository_backend |
155 | .exists |
156 | .await |
157 | .map_err? |
158 | |
159 | Ok |
160 | new_unchecked |
161 | from_object_str |
162 | .map_err?, |
163 | self.clone, |
164 | |
165 | |
166 | else |
167 | return Err; |
168 | |
169 | else if from_str .is_ok |
170 | return Err; |
171 | else |
172 | // Invalid object type |
173 | return Err; |
174 | |
175 | |
176 | |
177 | |
178 | // These tests verify that the essential handling of the database backend is |
179 | // functional and correct. |
180 | |
181 | |
182 | use ; |
183 | |
184 | use Error; |
185 | use UserDisplayName; |
186 | use ObjectBackend; |
187 | use Description; |
188 | use |
189 | |
190 | , | UserAuthenticationToken
191 | , | Instance
192 | , |
193 | , | AnySetting
194 | , | User
195 | , |
196 | |
197 | |
198 | AuthenticationTokenRequest, RegisterAccountRequest, RepositoryCreateRequest, |
199 | , |
200 | , | RepositoryFileInspectRequest
201 | GiteratedObjectValue, |
202 | , |
203 | , |
204 | ; |
205 | |
206 | use Value; |
207 | use Mutex; |
208 | |
209 | use crate; |
210 | |
211 | use DatabaseBackend; |
212 | ; |
213 | |
214 | |
215 | |
216 | async |
217 | assert_eq!; |
218 | |
219 | Ok |
220 | & to_vec .unwrap, |
221 | |
222 | .unwrap |
223 | |
224 | async |
225 | Ok |
226 | & to_vec .unwrap, |
227 | |
228 | .unwrap |
229 | |
230 | async |
231 | &mut self, |
232 | _user: &User, |
233 | _name: &str, |
234 | _setting: &Value, |
235 | |
236 | Ok |
237 | |
238 | async |
239 | Ok |
240 | |
241 | |
242 | |
243 | |
244 | |
245 | async |
246 | &mut self, |
247 | _request: RegisterAccountRequest, |
248 | |
249 | todo! |
250 | |
251 | |
252 | async |
253 | &mut self, |
254 | _source: &Instance, |
255 | _request: AuthenticationTokenRequest, |
256 | |
257 | todo! |
258 | |
259 | |
260 | |
261 | ; |
262 | |
263 | |
264 | |
265 | async |
266 | &mut self, |
267 | _user: &User, |
268 | _request: &RepositoryCreateRequest, |
269 | |
270 | todo! |
271 | |
272 | async |
273 | &mut self, |
274 | _requester: , |
275 | _request: &RepositoryFileInspectRequest, |
276 | |
277 | todo! |
278 | |
279 | async |
280 | &mut self, |
281 | _requester: , |
282 | _user: &User, |
283 | |
284 | todo! |
285 | |
286 | |
287 | async |
288 | &mut self, |
289 | _repository: &Repository, |
290 | _name: &str, |
291 | |
292 | Ok |
293 | & to_vec .unwrap, |
294 | |
295 | .unwrap |
296 | |
297 | async |
298 | &mut self, |
299 | _repository: &Repository, |
300 | _name: &str, |
301 | |
302 | Ok |
303 | & to_vec .unwrap, |
304 | |
305 | .unwrap |
306 | |
307 | async |
308 | &mut self, |
309 | _repository: &Repository, |
310 | _name: &str, |
311 | _setting: &Value, |
312 | |
313 | Ok |
314 | |
315 | |
316 | async |
317 | // Ok(true) |
318 | Ok |
319 | == & from_str |
320 | "test_user:test.giterated.dev/[email protected]", |
321 | |
322 | .unwrap |
323 | |
324 | |
325 | |
326 | |
327 | DatabaseBackend |
328 | our_instance: from_str .unwrap, |
329 | user_backend: new as _, |
330 | repository_backend: new as _, |
331 | |
332 | |
333 | |
334 | |
335 | async |
336 | let backend = test_backend; |
337 | |
338 | let mut user = backend |
339 | . |
340 | .await |
341 | .expect; |
342 | |
343 | user. |
344 | .await |
345 | .expect; |
346 | |
347 | |
348 | |
349 | async |
350 | let backend = test_backend; |
351 | |
352 | let mut user = backend |
353 | . |
354 | .await |
355 | .expect; |
356 | |
357 | user. |
358 | .await |
359 | .expect; |
360 | |
361 | |
362 | |
363 | async |
364 | let backend = test_backend; |
365 | |
366 | let mut user = backend |
367 | . |
368 | .await |
369 | .expect; |
370 | |
371 | user. |
372 | .await |
373 | .expect; |
374 | |
375 | |
376 | |
377 | async |
378 | let backend = test_backend; |
379 | |
380 | let mut repository = backend |
381 | . |
382 | .await |
383 | .expect; |
384 | |
385 | repository |
386 | . |
387 | .await |
388 | .expect; |
389 | |
390 | |
391 | |
392 | async |
393 | let backend = test_backend; |
394 | |
395 | let mut repository = backend |
396 | . |
397 | .await |
398 | .expect; |
399 | |
400 | repository |
401 | . |
402 | .await |
403 | .expect; |
404 | |
405 | |
406 | |
407 | async |
408 | let backend = test_backend; |
409 | |
410 | let mut repository = backend |
411 | . |
412 | .await |
413 | .expect; |
414 | |
415 | repository |
416 | . |
417 | .await |
418 | .expect; |
419 | |
420 | |
421 |