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