Unified stack `GetValue` implementation
parent: tbd commit: 325f5af
1 | |
2 | pub use ; |
3 | |
4 | |
5 | |
6 | |
7 | use ; |
8 | |
9 | use Debug; |
10 | use FutureExt; |
11 | use |
12 | , | OperationError
13 | |
14 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
15 | , |
16 | , | GiteratedObject
17 | , | ObjectBackend
18 | , | GiteratedOperation
19 | , |
20 | , |
21 | , | User
22 | , | GetValue
23 | ; |
24 | use ; |
25 | |
26 | |
27 | |
28 | pub object_name: String, |
29 | pub operation_name: String, |
30 | |
31 | |
32 | |
33 | pub name: String, |
34 | pub deserialize: , |
35 | |
36 | |
37 | |
38 | pub name: String, |
39 | pub deserialize: , |
40 | pub serialize: |
41 | , |
42 | pub typed_get: , |
43 | pub is_get_value_typed: , |
44 | |
45 | |
46 | |
47 | pub name: String, |
48 | pub from_str: , |
49 | pub any_is_same: , |
50 | |
51 | |
52 | |
53 | pub name: String, |
54 | pub object_kind: String, |
55 | pub deserialize: |
56 | , |
57 | pub any_is_same: , |
58 | pub serialize_success: |
59 | , |
60 | pub serialize_error: |
61 | , |
62 | |
63 | |
64 | |
65 | |
66 | pub object_kind: String, |
67 | pub value_kind: String, |
68 | |
69 | |
70 | |
71 | |
72 | L, |
73 | O: GiteratedObject, |
74 | D: GiteratedOperation<O>, |
75 | S: Send + Sync + Clone, |
76 | > |
77 | |
78 | ; |
79 | ; |
80 | |
81 | async |
82 | &self, |
83 | object: &O, |
84 | operation: D, |
85 | state: S, |
86 | operation_state: &StackOperationState, |
87 | ; |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | F: FnMut( |
94 | &O, |
95 | D, |
96 | S, |
97 | ) |
98 | -> |
99 | + Send |
100 | + Sync |
101 | + Clone, |
102 | O: GiteratedObject + Send + Sync, |
103 | D: + 'static, |
104 | : Send, | Failure
105 | S: Send + Sync + Clone + 'static, |
106 | |
107 | |
108 | operation_name |
109 | |
110 | |
111 | |
112 | object_name |
113 | |
114 | |
115 | async |
116 | &self, |
117 | object: &O, |
118 | operation: D, |
119 | state: S, |
120 | _operation_state: &StackOperationState, |
121 | |
122 | self.clone .await |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | F: FnMut( |
130 | &O, |
131 | D, |
132 | S, |
133 | O1, |
134 | ) |
135 | -> |
136 | + Send |
137 | + Sync |
138 | + Clone, |
139 | O: GiteratedObject + Send + Sync, |
140 | D: + 'static + Send + Sync, |
141 | : Send, | Failure
142 | S: Send + Sync + Clone + 'static, |
143 | O1: , |
144 | |
145 | |
146 | operation_name |
147 | |
148 | |
149 | |
150 | object_name |
151 | |
152 | |
153 | async |
154 | &self, |
155 | object: &O, |
156 | operation: D, |
157 | state: S, |
158 | operation_state: &StackOperationState, |
159 | |
160 | let o1 = O1 from_state |
161 | .await |
162 | .map_err?; |
163 | self.clone .await |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | F: FnMut( |
171 | &O, |
172 | D, |
173 | S, |
174 | O1, |
175 | O2, |
176 | ) |
177 | -> |
178 | + Send |
179 | + Sync |
180 | + Clone, |
181 | O: GiteratedObject + Send + Sync, |
182 | D: + 'static + Send + Sync, |
183 | : Send, | Failure
184 | S: Send + Sync + Clone + 'static, |
185 | O1: , |
186 | O2: , |
187 | |
188 | |
189 | operation_name |
190 | |
191 | |
192 | |
193 | object_name |
194 | |
195 | |
196 | async |
197 | &self, |
198 | object: &O, |
199 | operation: D, |
200 | state: S, |
201 | operation_state: &StackOperationState, |
202 | |
203 | let o1 = O1 from_state |
204 | .await |
205 | .map_err?; |
206 | let o2 = O2 from_state |
207 | .await |
208 | .map_err?; |
209 | self.clone .await |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | F: FnMut( |
217 | &O, |
218 | D, |
219 | S, |
220 | O1, |
221 | O2, |
222 | O3, |
223 | ) |
224 | -> |
225 | + Send |
226 | + Sync |
227 | + Clone, |
228 | O: GiteratedObject + Send + Sync, |
229 | D: + 'static + Send + Sync, |
230 | : Send, | Failure
231 | S: Send + Sync + Clone + 'static, |
232 | O1: , |
233 | O2: , |
234 | O3: , |
235 | |
236 | |
237 | operation_name |
238 | |
239 | |
240 | |
241 | object_name |
242 | |
243 | |
244 | async |
245 | &self, |
246 | object: &O, |
247 | operation: D, |
248 | state: S, |
249 | operation_state: &StackOperationState, |
250 | |
251 | let o1 = O1 from_state |
252 | .await |
253 | .map_err?; |
254 | let o2 = O2 from_state |
255 | .await |
256 | .map_err?; |
257 | let o3 = O3 from_state |
258 | .await |
259 | .map_err?; |
260 | self.clone .await |
261 | |
262 | |
263 | |
264 | |
265 | func: |
266 | dyn Fn( |
267 | &(dyn Any + Send + Sync), |
268 | &(dyn Any + Send + Sync), |
269 | &(dyn Any + Send + Sync), |
270 | StackOperationState, |
271 | ) -> |
272 | |
273 | dyn |
274 | Output = |
275 | , |
276 | , |
277 | >, |
278 | >, |
279 | >, |
280 | > + Send |
281 | + Sync, |
282 | >, |
283 | state: , |
284 | |
285 | |
286 | |
287 | |
288 | A, |
289 | O: GiteratedObject + Send + Sync + 'static, |
290 | D: + 'static + Clone, |
291 | F: + 'static + Send + Sync + Clone, |
292 | S: GiteratedStackState + 'static, |
293 | > |
294 | handler: F, |
295 | state: S, |
296 | |
297 | |
298 | : Send + Sync, | Failure
299 | : Send + Sync, | Success
300 | |
301 | Self |
302 | func: Box new |
303 | let handler = handler.clone; |
304 | let state = state. .unwrap .clone; |
305 | let object: &O = object.downcast_ref .unwrap; |
306 | let operation: &D = operation.downcast_ref .unwrap; |
307 | let object = object.clone; |
308 | let operation = operation.clone; |
309 | async move |
310 | let result = handler |
311 | .handle |
312 | .await; |
313 | result |
314 | .map |
315 | .map_err |
316 | => | Operation
317 | Operation |
318 | |
319 | => | Internal
320 | Internal |
321 | |
322 | => Unhandled, | Unhandled
323 | |
324 | |
325 | .boxed_local |
326 | , |
327 | state: Box new, |
328 | |
329 | |
330 | |
331 | async |
332 | &self, |
333 | object: & , |
334 | operation: & , |
335 | operation_state: &StackOperationState, |
336 | |
337 | |
338 | as_ref, | .
339 | as_ref, | .
340 | self.state.as_ref, |
341 | operation_state.clone, |
342 | |
343 | .await |
344 | |
345 | |
346 | |
347 | |
348 | |
349 | type Error: Serialize + DeserializeOwned; |
350 | |
351 | async |
352 | object: &O, |
353 | operation: &D, |
354 | state: &StackOperationState, |
355 | ; |
356 | |
357 | |
358 | |
359 | |
360 | for Arc |
361 | |
362 | type Error = ; |
363 | |
364 | async |
365 | _object: &O, |
366 | _operation: &D, |
367 | state: &StackOperationState, |
368 | |
369 | Ok |
370 | |
371 | |
372 | |
373 | |
374 | |
375 | for StackOperationState |
376 | |
377 | type Error = ; |
378 | |
379 | async |
380 | _object: &O, |
381 | _operation: &D, |
382 | state: &StackOperationState, |
383 | |
384 | Ok |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | for AuthenticatedUser |
391 | |
392 | type Error = ; |
393 | |
394 | async |
395 | _object: &O, |
396 | _operation: &D, |
397 | state: &StackOperationState, |
398 | |
399 | state |
400 | .user |
401 | .clone |
402 | .ok_or_else |
403 | |
404 | |
405 | |
406 | |
407 | |
408 | for AuthenticatedInstance |
409 | |
410 | type Error = ; |
411 | |
412 | async |
413 | _object: &O, |
414 | _operation: &D, |
415 | state: &StackOperationState, |
416 | |
417 | state |
418 | .instance |
419 | .clone |
420 | .ok_or_else |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | T: + Send + Sync, |
427 | O: GiteratedObject + Sync, |
428 | D: + Send + Sync, |
429 | > |
430 | |
431 | type Error = ; |
432 | |
433 | async |
434 | object: &O, |
435 | operation: &D, |
436 | state: &StackOperationState, |
437 | |
438 | Ok |
439 | |
440 | |
441 | |
442 | |
443 | ; |
444 | |
445 | |
446 | ; |
447 | |
448 | |
449 | |
450 | async |
451 | &self, |
452 | authorize_for: &O, |
453 | state: &StackOperationState, |
454 | ; |
455 | |
456 | |
457 | |
458 | |
459 | async |
460 | &self, |
461 | authorize_for: &O, |
462 | operation_state: &StackOperationState, |
463 | |
464 | Ok |
465 | .runtime |
466 | . |
467 | .await |
468 | .is_ok |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | async |
475 | &self, |
476 | authorize_for: &User, |
477 | operation_state: &StackOperationState, |
478 | |
479 | let authenticated_user = operation_state |
480 | .user |
481 | .as_ref |
482 | .ok_or_else?; |
483 | |
484 | Ok |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | async |
491 | &self, |
492 | authorize_for: &User, |
493 | operation_state: &StackOperationState, |
494 | |
495 | let authenticated_user = operation_state |
496 | .user |
497 | .as_ref |
498 | .ok_or_else?; |
499 | |
500 | Ok |
501 | |
502 | |
503 | |
504 | |
505 | |
506 | async |
507 | &self, |
508 | authorize_for: &Repository, |
509 | operation_state: &StackOperationState, |
510 | |
511 | let authenticated_user = operation_state |
512 | .user |
513 | .as_ref |
514 | .ok_or_else?; |
515 | |
516 | let mut object = operation_state |
517 | .runtime |
518 | . |
519 | .await |
520 | .map_err?; |
521 | |
522 | let access_list = object |
523 | . |
524 | .await |
525 | .map_err?; |
526 | |
527 | if access_list |
528 | .0 |
529 | .iter |
530 | .find |
531 | .is_some |
532 | |
533 | Ok |
534 | else |
535 | Ok |
536 | |
537 | |
538 | |
539 | |
540 | |
541 | |
542 | async |
543 | &self, |
544 | authorize_for: &Repository, |
545 | operation_state: &StackOperationState, |
546 | |
547 | let authenticated_user = operation_state |
548 | .user |
549 | .as_ref |
550 | .ok_or_else?; |
551 | |
552 | let mut object = operation_state |
553 | .runtime |
554 | . |
555 | .await |
556 | .map_err?; |
557 | |
558 | let access_list = object |
559 | . |
560 | .await |
561 | .map_err?; |
562 | |
563 | if access_list |
564 | .0 |
565 | .iter |
566 | .find |
567 | .is_some |
568 | |
569 | Ok |
570 | else |
571 | Ok |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | |
578 | async |
579 | &self, |
580 | authorize_for: &Instance, |
581 | state: &StackOperationState, |
582 | |
583 | if state.our_instance == *authorize_for |
584 | Ok |
585 | else |
586 | Ok |
587 | |
588 | |
589 | |
590 | |
591 | |
592 | |
593 | async |
594 | &self, |
595 | authorize_for: &Instance, |
596 | state: &StackOperationState, |
597 | |
598 | if state.our_instance == *authorize_for |
599 | Ok |
600 | else |
601 | Ok |
602 | |
603 | |
604 | |
605 | |
606 | |
607 | |
608 | async |
609 | &self, |
610 | authorize_for: &Instance, |
611 | state: &StackOperationState, |
612 | |
613 | if state.our_instance == *authorize_for |
614 | Ok |
615 | else |
616 | Ok |
617 | |
618 | |
619 | |
620 | |
621 | |
622 | |
623 | type Error = ; |
624 | |
625 | async |
626 | object: &User, |
627 | operation: &A, |
628 | state: &StackOperationState, |
629 | |
630 | let authenticated = from_state .await?; |
631 | |
632 | match operation.authorize .await |
633 | Ok => |
634 | assert!; |
635 | |
636 | Err => return Err, |
637 | ; |
638 | |
639 | Ok |
640 | |
641 | |
642 | |
643 | |
644 | |
645 | for AuthorizedInstance |
646 | |
647 | type Error = ; |
648 | |
649 | async |
650 | object: &Instance, |
651 | operation: &A, |
652 | state: &StackOperationState, |
653 | |
654 | let authenticated = from_state .await?; |
655 | |
656 | match operation.authorize .await |
657 | Ok => |
658 | assert!; |
659 | |
660 | Err => return Err, |
661 | ; |
662 | |
663 | Ok |
664 | |
665 | |
666 | |
667 | // #[async_trait::async_trait> FromOperationState for Option<T> { |
668 | // type Error = (); |
669 | |
670 | // async fn from_state(state: &StackOperationState) -> Result<Option<T>, OperationError<()>> { |
671 | // Ok(T::from_state(] |
672 | // impl<T: FromOperationStatestate).await.ok()) |
673 | // } |
674 | // } |
675 | |
676 | |
677 | |
678 | pub our_instance: Instance, |
679 | pub runtime: , |
680 | pub instance: , |
681 | pub user: , |
682 | |
683 | |
684 | |
685 | ; |
686 | |
687 | |
688 | |
689 | AuthenticatedInstance |
690 | |
691 | |
692 | |
693 | |
694 | type Target = Instance; |
695 | |
696 | |
697 | &self.0 |
698 | |
699 | |
700 | |
701 | |
702 | ; |
703 | |
704 | |
705 | |
706 | AuthenticatedUser |
707 | |
708 | |
709 | |
710 | |
711 | type Target = User; |
712 | |
713 | |
714 | &self.0 |
715 | |
716 | |
717 |