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

ambee/giterated

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

Make old operations use new types

Emilia - ⁨1⁩ year ago

parent: tbd commit: ⁨b22dd12

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨8086⁩ bytes
Raw
1 pub mod discovery;
2 pub mod git;
3 pub mod github;
4 pub mod settings;
5 pub mod user;
6
7 use anyhow::Error;
8 use async_trait::async_trait;
9 use giterated_models::issue::{IssueInfoBasic, IssueTag};
10 use giterated_models::object::Object;
11 use giterated_stack::{AuthenticatedUser, GiteratedStack, OperationState, StackOperationState};
12 use serde_json::Value;
13
14 use crate::backend::git::GitBackendError;
15 use giterated_models::authenticated::UserAuthenticationToken;
16
17 use giterated_models::instance::{
18 AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest,
19 };
20
21 use giterated_models::repository::{
22 Commit, Repository, RepositoryBranch, RepositoryBranchRequest, RepositoryBranchesRequest,
23 RepositoryCommitBeforeRequest, RepositoryCommitFromIdRequest, RepositoryDiff,
24 RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest,
25 RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryIssueTagsRequest,
26 RepositoryIssuesCountRequest, RepositoryIssuesRequest, RepositoryLastCommitOfFileRequest,
27 RepositoryStatistics, RepositoryStatisticsRequest, RepositorySummary, RepositoryTag,
28 RepositoryTagRequest, RepositoryTagsRequest, RepositoryTreeEntry,
29 };
30
31 use giterated_models::user::User;
32
33 // TODO: Document all functions
34 #[async_trait(?Send)]
35 pub trait RepositoryBackend {
36 async fn create_repository(
37 &mut self,
38 user: &AuthenticatedUser,
39 request: &RepositoryCreateRequest,
40 ) -> Result<Repository, GitBackendError>;
41 async fn repository_file_inspect(
42 &mut self,
43 requester: &Option<AuthenticatedUser>,
44 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
45 OperationState(operation_state): OperationState<StackOperationState>,
46 request: &RepositoryFileInspectRequest,
47 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
48 async fn repository_file_from_id(
49 &mut self,
50 requester: &Option<AuthenticatedUser>,
51 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
52 OperationState(operation_state): OperationState<StackOperationState>,
53 request: &RepositoryFileFromIdRequest,
54 ) -> Result<RepositoryFile, Error>;
55 async fn repository_file_from_path(
56 &mut self,
57 requester: &Option<AuthenticatedUser>,
58 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
59 OperationState(operation_state): OperationState<StackOperationState>,
60 request: &RepositoryFileFromPathRequest,
61 ) -> Result<(RepositoryFile, String), Error>;
62 async fn repository_commit_from_id(
63 &mut self,
64 requester: &Option<AuthenticatedUser>,
65 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
66 OperationState(operation_state): OperationState<StackOperationState>,
67 request: &RepositoryCommitFromIdRequest,
68 ) -> Result<Commit, Error>;
69 async fn repository_last_commit_of_file(
70 &mut self,
71 requester: &Option<AuthenticatedUser>,
72 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
73 OperationState(operation_state): OperationState<StackOperationState>,
74 request: &RepositoryLastCommitOfFileRequest,
75 ) -> Result<Commit, Error>;
76 async fn repository_diff(
77 &mut self,
78 requester: &Option<AuthenticatedUser>,
79 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
80 OperationState(operation_state): OperationState<StackOperationState>,
81 request: &RepositoryDiffRequest,
82 ) -> Result<RepositoryDiff, Error>;
83 async fn repository_diff_patch(
84 &mut self,
85 requester: &Option<AuthenticatedUser>,
86 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
87 OperationState(operation_state): OperationState<StackOperationState>,
88 request: &RepositoryDiffPatchRequest,
89 ) -> Result<String, Error>;
90 async fn repository_commit_before(
91 &mut self,
92 requester: &Option<AuthenticatedUser>,
93 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
94 OperationState(operation_state): OperationState<StackOperationState>,
95 request: &RepositoryCommitBeforeRequest,
96 ) -> Result<Commit, Error>;
97 async fn repository_get_statistics(
98 &mut self,
99 requester: &Option<AuthenticatedUser>,
100 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
101 OperationState(operation_state): OperationState<StackOperationState>,
102 request: &RepositoryStatisticsRequest,
103 ) -> Result<RepositoryStatistics, Error>;
104 async fn repository_get_branches(
105 &mut self,
106 requester: &Option<AuthenticatedUser>,
107 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
108 OperationState(operation_state): OperationState<StackOperationState>,
109 request: &RepositoryBranchesRequest,
110 ) -> Result<(Vec<RepositoryBranch>, usize), Error>;
111 async fn repository_get_branch(
112 &mut self,
113 requester: &Option<AuthenticatedUser>,
114 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
115 OperationState(operation_state): OperationState<StackOperationState>,
116 request: &RepositoryBranchRequest,
117 ) -> Result<RepositoryBranch, Error>;
118 async fn repository_get_tags(
119 &mut self,
120 requester: &Option<AuthenticatedUser>,
121 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
122 OperationState(operation_state): OperationState<StackOperationState>,
123 request: &RepositoryTagsRequest,
124 ) -> Result<(Vec<RepositoryTag>, usize), Error>;
125 async fn repository_get_tag(
126 &mut self,
127 requester: &Option<AuthenticatedUser>,
128 repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
129 OperationState(operation_state): OperationState<StackOperationState>,
130 request: &RepositoryTagRequest,
131 ) -> Result<RepositoryTag, Error>;
132 async fn exists(
133 &mut self,
134 requester: &Option<AuthenticatedUser>,
135 repository: &Repository,
136 ) -> Result<bool, Error>;
137 }
138
139 pub trait IssuesBackend {
140 fn issues_count(
141 &mut self,
142 requester: &Option<AuthenticatedUser>,
143 request: &RepositoryIssuesCountRequest,
144 ) -> Result<u64, Error>;
145 fn issue_tags(
146 &mut self,
147 requester: &Option<AuthenticatedUser>,
148 request: &RepositoryIssueTagsRequest,
149 ) -> Result<Vec<IssueTag>, Error>;
150 fn issues(
151 &mut self,
152 requester: &Option<AuthenticatedUser>,
153 request: &RepositoryIssuesRequest,
154 ) -> Result<Vec<IssueInfoBasic>, Error>;
155 }
156
157 #[async_trait::async_trait]
158 pub trait AuthBackend {
159 async fn register(
160 &mut self,
161 request: RegisterAccountRequest,
162 ) -> Result<UserAuthenticationToken, Error>;
163
164 async fn login(
165 &mut self,
166 source: &Instance,
167 request: AuthenticationTokenRequest,
168 ) -> Result<UserAuthenticationToken, Error>;
169 }
170
171 #[async_trait::async_trait]
172 pub trait UserBackend: AuthBackend {
173 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
174 async fn repositories_for_user(
175 &mut self,
176 requester: &Option<AuthenticatedUser>,
177 user: &User,
178 ) -> Result<Vec<RepositorySummary>, Error>;
179 }
180
181 #[async_trait::async_trait]
182 pub trait MetadataBackend {
183 async fn user_get(&mut self, user: &User, name: &str) -> Result<Value, Error>;
184 async fn user_write(&mut self, user: &User, name: &str, setting: Value) -> Result<(), Error>;
185 async fn repository_get(&mut self, repository: &Repository, name: &str)
186 -> Result<Value, Error>;
187 async fn repository_write(
188 &mut self,
189 repository: &Repository,
190 name: &str,
191 setting: Value,
192 ) -> Result<(), Error>;
193 }
194