JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Beginning of `stack-next` refactor

-Refactoring the protocol stack into something similar to a runtime. -Handles merging handler builders which is placing the ground work for plugins in. - Increased metadata generation during compilation enables less ser/de during execution. - Goal is to have an O(1) time from incoming operation to calling handlers. - Decreased penalty for using the statically typed API from within your code, now avoids some allocation. # Changes - Added `GiteratedRuntime` which is to replace the current unified stack - Added `RuntimeBuilder` which does what the current `OperationHandlers` struct does, but much better. - Added `RuntimeMetadata` to store type metadata for new `Any` based internals - Refactored serde_json out of the internal operation handling

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨708dea4

⁨giterated-daemon/src/database_backend/updates.rs⁩ - ⁨2300⁩ bytes
Raw
1 use futures_util::{future::BoxFuture, FutureExt};
2 use giterated_models::{
3 repository::{DefaultBranch, Description, Repository},
4 settings::{AnySetting, Setting},
5 update::ValueUpdate,
6 user::User,
7 value::{AnyValue, GiteratedObjectValue},
8 };
9 use giterated_stack::{AuthorizedUser, StackOperationState};
10
11 use super::DatabaseBackend;
12
13 pub fn user_set_value(
14 object: User,
15 value_name: String,
16 value: AnyValue<User>,
17 operation_state: &StackOperationState,
18 ) -> BoxFuture<'static, Result<(), ()>> {
19 todo!()
20 }
21
22 pub fn user_set_setting(
23 object: User,
24 value_name: String,
25 value: AnySetting,
26 operation_state: &StackOperationState,
27 ) -> BoxFuture<'static, Result<(), ()>> {
28 todo!()
29 }
30
31 pub fn repository_set_value(
32 object: Repository,
33 value_name: String,
34 value: AnyValue<Repository>,
35 operation_state: &StackOperationState,
36 ) -> BoxFuture<'static, Result<(), ()>> {
37 todo!()
38 }
39
40 pub fn repository_set_setting(
41 object: Repository,
42 value_name: String,
43 value: AnySetting,
44 operation_state: &StackOperationState,
45 ) -> BoxFuture<'static, Result<(), ()>> {
46 todo!()
47 }
48
49 pub fn repository_set_description(
50 object: Repository,
51 description: Description,
52 user: AuthorizedUser,
53 ) -> BoxFuture<'static, Result<(), ()>> {
54 async { Ok(()) }.boxed()
55 }
56
57 pub fn repository_set_default_branch(
58 object: Repository,
59 default_branch: DefaultBranch,
60 // Ensure user is authorized for this request
61 _user: AuthorizedUser,
62 backend: DatabaseBackend,
63 ) -> BoxFuture<'static, Result<(), ()>> {
64 async move {
65 let mut repository_backend = backend.repository_backend.lock().await;
66
67 repository_backend
68 .write_setting(
69 &object,
70 DefaultBranch::name(),
71 &serde_json::to_value(default_branch.clone()).unwrap(),
72 )
73 .await
74 .unwrap();
75
76 let set_value = ValueUpdate {
77 object: object.to_string(),
78 value_name: DefaultBranch::value_name().to_owned(),
79 value: unsafe { AnyValue::from_raw(serde_json::to_value(default_branch).unwrap()) },
80 };
81
82 // Submit value update back to the daemon
83 // state.value_update(set_value);
84 Ok(())
85 }
86 .boxed()
87 }
88