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

ambee/giterated

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

`[feature/plugins]` Some plugin work?

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨10a447b

Showing ⁨⁨20⁩ changed files⁩ with ⁨⁨220⁩ insertions⁩ and ⁨⁨170⁩ deletions⁩

Cargo.lock

View file
@@ -788,6 +788,7 @@ dependencies = [
788 788 "dlopen2",
789 789 "giterated-models",
790 790 "semver",
791 "serde",
791 792 "serde_json",
792 793 "thiserror",
793 794 "tracing",

giterated-daemon/src/client.rs

View file
@@ -6,18 +6,18 @@ use giterated_models::{
6 6 instance::Instance,
7 7 object_backend::ObjectBackend,
8 8 };
9 use giterated_plugin::new_stack::{runtime_handler::RuntimeHandle, Runtime};
9 use giterated_plugin::new_stack::{handle::RuntimeHandle, OperationState, Runtime};
10 10 use giterated_protocol::{
11 11 handlers::{NetworkedObject, NetworkedOperation},
12 AuthenticatedPayload, StackOperationState,
12 AuthenticatedPayload,
13 13 };
14 14 use tokio::net::TcpStream;
15 15 use tokio_tungstenite::{tungstenite::Message, WebSocketStream};
16 16
17 17 pub async fn client_wrapper(
18 our_instance: Instance,
18 _our_instance: Instance,
19 19 mut socket: WebSocketStream<TcpStream>,
20 runtime: Arc<Runtime>,
20 _runtime: Arc<Runtime>,
21 21 ) {
22 22 loop {
23 23 let message = socket.next().await;
@@ -97,7 +97,7 @@ pub async fn client_wrapper(
97 97
98 98 pub async fn handle_client_message(
99 99 payload: AuthenticatedPayload,
100 operation_state: StackOperationState,
100 operation_state: OperationState,
101 101 runtime: RuntimeHandle,
102 102 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
103 103 let mut networked_object = runtime

giterated-daemon/src/main.rs

View file
@@ -49,7 +49,7 @@ async fn main() -> Result<(), Error> {
49 49
50 50 info!("Connected");
51 51
52 let mut runtime = Runtime::default();
52 let mut runtime = Runtime::new();
53 53
54 54 let runtime = Arc::new(runtime);
55 55

giterated-plugin/Cargo.toml

View file
@@ -14,3 +14,4 @@ giterated-models = { path = "../giterated-models" }
14 14 semver = "*"
15 15 serde_json = "1.0"
16 16 async-trait = "0.1"
17 serde = "*"
17 \ No newline at end of file

giterated-plugin/giterated-plugin-sys/src/lib.rs

View file
@@ -1,4 +1,6 @@
1 use std::sync::OnceLock;
1 mod local_runtime;
2
3 use std::marker::PhantomData;
2 4
3 5 use giterated_models::{
4 6 object::GiteratedObject, operation::GiteratedOperation, settings::Setting,
@@ -7,8 +9,7 @@ use giterated_models::{
7 9 use giterated_plugin::{
8 10 callback::{
9 11 CallbackPtr, IntoPluginOperationHandler, IntoPluginSettingGetter, IntoPluginSettingSetter,
10 IntoPluginValueGetter, OperationHandlerCallback, SettingGetterCallback,
11 ValueGetterCallback,
12 IntoPluginValueGetter, OperationHandlerCallback, ValueGetterCallback,
12 13 },
13 14 handle::PluginInitializationState,
14 15 new_stack::PluginState,
@@ -31,8 +32,8 @@ impl<'init, S> PluginStackBuilder<'init, S> {
31 32 plugin_state: S,
32 33 state: *mut PluginInitializationState,
33 34 vtable: &'init InitializationVTable,
34 ) -> Self {
35 Self {
35 ) -> PluginStackBuilder<'init, S> {
36 PluginStackBuilder {
36 37 init_state: state,
37 38 vtable,
38 39 state: plugin_state,
@@ -68,7 +69,7 @@ impl<'init, S> PluginStackBuilder<'init, S> {
68 69 self
69 70 }
70 71
71 pub fn object_setting<O, OS, HG, HS>(&mut self, get: HG, set: HS) -> &mut Self
72 pub fn object_setting<O, OS, HG, HS>(&mut self, _get: HG, _set: HS) -> &mut Self
72 73 where
73 74 O: GiteratedObject,
74 75 OS: IntoSettingVTable + Setting,
@@ -138,12 +139,10 @@ impl<'init, S> PluginStackBuilder<'init, S> {
138 139 }
139 140
140 141 pub fn operation<
141 DS,
142 DF,
143 142 A,
144 143 O: GiteratedObject + IntoObjectVTable,
145 144 D: IntoOperationVTable<O> + GiteratedOperation<O>,
146 T: IntoPluginOperationHandler<S, O, D, DS, DF, A>,
145 T: IntoPluginOperationHandler<S, O, D, A>,
147 146 >(
148 147 &mut self,
149 148 handler: T,
@@ -155,7 +154,7 @@ impl<'init, S> PluginStackBuilder<'init, S> {
155 154 self.init_state,
156 155 O::object_name(),
157 156 D::operation_name(),
158 OperationHandlerCallback::new::<S, O, D, DS, DF, A, T>(handler),
157 OperationHandlerCallback::new::<S, O, D, A, T>(handler),
159 158 )
160 159 }
161 160
@@ -225,7 +224,7 @@ pub trait ValueSettingExt<PS> {
225 224 }
226 225
227 226 impl<PS> ValueSettingExt<PS> for PluginStackBuilder<'_, PS> {
228 fn value_setting<O, VS, HG, HS>(&mut self, get: HG, set: HS) -> &mut Self
227 fn value_setting<O, VS, HG, HS>(&mut self, _get: HG, _set: HS) -> &mut Self
229 228 where
230 229 O: GiteratedObject + IntoObjectVTable + 'static,
231 230 VS: GiteratedObjectValue<Object = O> + IntoValueVTable<O> + Setting + IntoSettingVTable,

giterated-plugin/giterated-plugin-sys/src/local_runtime.rs

View file
@@ -0,0 +1 @@
1

giterated-plugin/src/callback/mod.rs

View file
@@ -7,7 +7,10 @@ pub use value::*;
7 7 mod setting;
8 8 pub use setting::*;
9 9
10 use crate::new_stack::{runtime_handler::RuntimeHandle, PluginState, Runtime};
10 use crate::{
11 new_stack::{PluginState, Runtime},
12 vtable::RuntimeVTable,
13 };
11 14
12 15 /// A container for a callback pointer, used to provide an internal callback function or
13 16 /// state to a plugin when performing a callback.
@@ -23,6 +26,6 @@ impl CallbackPtr {
23 26
24 27 #[repr(C)]
25 28 pub struct RuntimeState {
26 pub runtime: RuntimeHandle,
29 pub vtable: RuntimeVTable,
27 30 pub operation_state: PluginState,
28 31 }

giterated-plugin/src/callback/operation.rs

View file
@@ -1,7 +1,10 @@
1 use giterated_models::error::OperationError;
1 use giterated_models::{
2 error::OperationError, object::GiteratedObject, operation::GiteratedOperation,
3 value::GiteratedObjectValue,
4 };
2 5
3 6 use crate::{
4 new_stack::{runtime_handler::RuntimeHandle, PluginState, Runtime, State},
7 new_stack::{handle::RuntimeHandle, OperationState, PluginState, Runtime, State},
5 8 AnyObject, AnyOperation,
6 9 };
7 10
@@ -22,7 +25,13 @@ pub struct OperationHandlerCallback {
22 25 }
23 26
24 27 impl OperationHandlerCallback {
25 pub fn new<S, O, D, DS, DF, A, T: IntoPluginOperationHandler<S, O, D, DS, DF, A>>(
28 pub fn new<
29 S,
30 O: GiteratedObject,
31 D: GiteratedOperation<O>,
32 A,
33 T: IntoPluginOperationHandler<S, O, D, A>,
34 >(
26 35 handler: T,
27 36 ) -> Self {
28 37 OperationHandlerCallback {
@@ -32,7 +41,7 @@ impl OperationHandlerCallback {
32 41 }
33 42 }
34 43
35 pub trait IntoPluginOperationHandler<S, O, D, DS, DF, A> {
44 pub trait IntoPluginOperationHandler<S, O: GiteratedObject, D: GiteratedOperation<O>, A> {
36 45 unsafe extern "C" fn handle(
37 46 callback_ptr: CallbackPtr,
38 47 runtime_state: &RuntimeState,
@@ -43,13 +52,13 @@ pub trait IntoPluginOperationHandler<S, O, D, DS, DF, A> {
43 52 fn callback_ptr(&self) -> CallbackPtr;
44 53 }
45 54
46 impl<F, S, O, D, DS, DF, Fut> IntoPluginOperationHandler<S, O, D, DS, DF, ()> for F
55 impl<F, S, O, D, Fut> IntoPluginOperationHandler<S, O, D, ()> for F
47 56 where
48 Fut: Future<Output = Result<DS, OperationError<DF>>>,
57 Fut: Future<Output = Result<D::Success, OperationError<D::Failure>>>,
49 58 F: Fn(S, O, D) -> Fut,
50 59 S: Clone + Debug,
51 O: Debug,
52 D: Debug,
60 O: Debug + GiteratedObject,
61 D: Debug + GiteratedOperation<O>,
53 62 {
54 63 unsafe extern "C" fn handle(
55 64 callback: CallbackPtr,
@@ -84,13 +93,13 @@ where
84 93 }
85 94 }
86 95
87 impl<F, S, O, D, DS, DF, Fut, A1> IntoPluginOperationHandler<S, O, D, DS, DF, (A1,)> for F
96 impl<F, S, O, D, Fut, A1> IntoPluginOperationHandler<S, O, D, (A1,)> for F
88 97 where
89 Fut: Future<Output = Result<DS, OperationError<DF>>>,
98 Fut: Future<Output = Result<D::Success, OperationError<D::Failure>>>,
90 99 F: Fn(S, O, D, A1) -> Fut,
91 100 S: Clone + Debug,
92 O: Debug,
93 D: Debug,
101 O: Debug + GiteratedObject,
102 D: Debug + GiteratedOperation<O>,
94 103 {
95 104 unsafe extern "C" fn handle(
96 105 callback_ptr: CallbackPtr,
@@ -107,13 +116,13 @@ where
107 116 }
108 117 }
109 118
110 impl<F, S, O, D, DS, DF, Fut, A1, A2> IntoPluginOperationHandler<S, O, D, DS, DF, (A1, A2)> for F
119 impl<F, S, O, D, Fut, A1, A2> IntoPluginOperationHandler<S, O, D, (A1, A2)> for F
111 120 where
112 Fut: Future<Output = Result<DS, OperationError<DF>>>,
121 Fut: Future<Output = Result<D::Success, OperationError<D::Failure>>>,
113 122 F: Fn(S, O, D, A1, A2) -> Fut,
114 123 S: Clone + Debug,
115 O: Debug,
116 D: Debug,
124 O: Debug + GiteratedObject,
125 D: Debug + GiteratedOperation<O>,
117 126 {
118 127 unsafe extern "C" fn handle(
119 128 callback_ptr: CallbackPtr,
@@ -130,43 +139,43 @@ where
130 139 }
131 140 }
132 141
133 pub trait FromOperationState<S, O, D>: Sized {
142 pub trait FromOperationState<O, D>: Sized {
134 143 fn from_operation_state(
135 state: &S,
144 operation_state: &OperationState,
136 145 runtime_state: &RuntimeState,
137 146 object: &O,
138 147 operation: &D,
139 148 ) -> Result<Self, OperationError<anyhow::Error>>;
140 149 }
141 150
142 impl<S, O, D> FromOperationState<S, O, D> for RuntimeHandle {
151 impl<O, D> FromOperationState<O, D> for RuntimeHandle {
143 152 fn from_operation_state(
144 state: &S,
153 operation_state: &OperationState,
145 154 runtime_state: &RuntimeState,
146 155 object: &O,
147 156 operation: &D,
148 157 ) -> Result<Self, OperationError<anyhow::Error>> {
149 Ok(runtime_state.runtime.clone())
158 Ok(unsafe { RuntimeHandle::from_vtable(runtime_state.vtable) })
150 159 }
151 160 }
152 161
153 impl<S, O, D, T> FromOperationState<S, O, D> for Option<T>
162 impl<O, D, T> FromOperationState<O, D> for Option<T>
154 163 where
155 T: FromOperationState<S, O, D>,
164 T: FromOperationState<O, D>,
156 165 {
157 166 fn from_operation_state(
158 state: &S,
167 operation_state: &OperationState,
159 168 runtime_state: &RuntimeState,
160 169 object: &O,
161 170 operation: &D,
162 171 ) -> Result<Self, OperationError<anyhow::Error>> {
163 Ok(T::from_operation_state(state, runtime_state, object, operation).ok())
172 Ok(T::from_operation_state(operation_state, runtime_state, object, operation).ok())
164 173 }
165 174 }
166 175
167 impl<S, O, D, OS: Clone> FromOperationState<S, O, D> for State<OS> {
176 impl<O, D, OS: Clone> FromOperationState<O, D> for State<OS> {
168 177 fn from_operation_state(
169 state: &S,
178 operation_state: &OperationState,
170 179 runtime_state: &RuntimeState,
171 180 object: &O,
172 181 operation: &D,

giterated-plugin/src/new_stack/handle.rs

View file
@@ -0,0 +1,62 @@
1 use std::marker::PhantomData;
2
3 use giterated_models::{
4 error::OperationError,
5 object::{GiteratedObject, Object, ObjectRequestError},
6 object_backend::ObjectBackend,
7 operation::GiteratedOperation,
8 };
9 use std::fmt::Debug;
10
11 use crate::vtable::RuntimeVTable;
12
13 use super::OperationState;
14
15 #[derive(Clone)]
16 pub struct RuntimeHandle {
17 runtime_vtable: RuntimeVTable,
18 }
19
20 impl RuntimeHandle {
21 pub async fn handle_serialized(
22 &self,
23 object: &str,
24 operation_name: &str,
25 payload: &[u8],
26 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
27 todo!()
28 }
29 }
30
31 impl RuntimeHandle {
32 pub(crate) unsafe fn from_vtable(runtime_vtable: RuntimeVTable) -> Self {
33 Self { runtime_vtable }
34 }
35 }
36
37 #[async_trait::async_trait(?Send)]
38 impl ObjectBackend<OperationState> for RuntimeHandle {
39 async fn object_operation<O, D>(
40 &self,
41 object: O,
42 operation: &str,
43 payload: D,
44 operation_state: &OperationState,
45 ) -> Result<D::Success, OperationError<D::Failure>>
46 where
47 O: GiteratedObject + Debug + 'static,
48 D: GiteratedOperation<O> + Debug + 'static,
49 D::Success: Clone,
50 D::Failure: Clone,
51 {
52 todo!()
53 }
54
55 async fn get_object<O: GiteratedObject + Debug + 'static>(
56 &self,
57 object_str: &str,
58 operation_state: &OperationState,
59 ) -> Result<Object<OperationState, O, Self>, OperationError<ObjectRequestError>> {
60 todo!()
61 }
62 }

giterated-plugin/src/new_stack/mod.rs

View file
@@ -1,3 +1,4 @@
1 pub mod handle;
1 2 pub mod operation_walker;
2 3 pub mod runtime_handler;
3 4
@@ -11,6 +12,7 @@ use giterated_models::{
11 12 operation::GiteratedOperation,
12 13 };
13 14 use semver::Version;
15 use serde::Serialize;
14 16 use tracing::{debug, debug_span, field::DebugValue, span, trace, trace_span, warn, Level};
15 17
16 18 use crate::{
@@ -34,10 +36,6 @@ impl<S> std::ops::Deref for State<S> {
34 36 }
35 37 }
36 38
37 pub struct OperationState {
38 pub our_instance: Instance,
39 }
40
41 39 #[derive(Default)]
42 40 pub struct TypeMetadata {
43 41 pub objects: HashMap<&'static str, ObjectVtable>,
@@ -178,18 +176,16 @@ impl PluginState {
178 176 }
179 177 }
180 178
181 pub struct Runtime<S: Clone> {
179 pub struct Runtime {
182 180 plugins: Vec<(PluginMeta, PluginHandle)>,
183 181 handlers: RuntimeHandlers,
184 _marker: PhantomData<S>,
185 182 }
186 183
187 impl<S: Clone> Runtime<S> {
184 impl Runtime {
188 185 pub fn new() -> Self {
189 186 Self {
190 187 plugins: vec![],
191 188 handlers: RuntimeHandlers::default(),
192 _marker: PhantomData,
193 189 }
194 190 }
195 191
@@ -490,3 +486,31 @@ pub enum HandlerError {
490 486 Internal(()),
491 487 Unhandled,
492 488 }
489
490 pub trait StateId {
491 fn state_id(&self) -> &'static str;
492 }
493
494 pub unsafe trait FfiState: StateId {
495 fn into_ffi_state_bytes(self) -> Vec<u8>;
496
497 fn from_ffi_state_bytes(bytes: Vec<u8>) -> Self;
498 }
499
500 unsafe impl<T> FfiState for T
501 where
502 T: Serialize + StateId,
503 {
504 fn into_ffi_state_bytes(self) -> Vec<u8> {
505 todo!()
506 }
507
508 fn from_ffi_state_bytes(bytes: Vec<u8>) -> Self {
509 todo!()
510 }
511 }
512
513 #[derive(Clone, Debug)]
514 pub struct OperationState {
515 entries: HashMap<&'static str, Vec<u8>>,
516 }

giterated-plugin/src/new_stack/runtime_handler.rs

View file
@@ -10,23 +10,7 @@ use giterated_models::{
10 10
11 11 use crate::vtable::{AnyFailure, AnySuccess, OperationVTable};
12 12
13 use super::PluginState;
14
15 #[derive(Clone)]
16 pub struct RuntimeHandle {
17 inner: Arc<RuntimeHandleInner>,
18 }
19
20 impl RuntimeHandle {
21 pub async fn handle_serialized(
22 &self,
23 operation_name: &str,
24 object: &str,
25 operation: &[u8],
26 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
27 todo!()
28 }
29 }
13 use super::{handle::RuntimeHandle, PluginState};
30 14
31 15 #[repr(C)]
32 16 struct RuntimeHandleInner {
@@ -47,30 +31,3 @@ struct HandlerResult {
47 31 operation_vtable: OperationVTable,
48 32 result: Result<AnySuccess, OperationError<AnyFailure>>,
49 33 }
50
51 #[async_trait::async_trait(?Send)]
52 impl<S: Send + Sync + Clone> ObjectBackend<S> for RuntimeHandle {
53 async fn object_operation<O, D>(
54 &self,
55 object: O,
56 operation: &str,
57 payload: D,
58 operation_state: &S,
59 ) -> Result<D::Success, OperationError<D::Failure>>
60 where
61 O: GiteratedObject + Debug + 'static,
62 D: GiteratedOperation<O> + Debug + 'static,
63 D::Success: Clone,
64 D::Failure: Clone,
65 {
66 todo!()
67 }
68
69 async fn get_object<O: GiteratedObject + Debug + 'static>(
70 &self,
71 object_str: &str,
72 operation_state: &S,
73 ) -> Result<Object<S, O, Self>, OperationError<ObjectRequestError>> {
74 todo!()
75 }
76 }

giterated-plugin/src/vtable/mod.rs

View file
@@ -1,7 +1,9 @@
1 1 //! Giterated's VTable System
2 2 //!
3 3 //! Docs here? :)
4 mod runtime;
4 5 mod setting;
6 pub use runtime::*;
5 7 pub use setting::*;
6 8 mod operation;
7 9 pub use operation::*;

giterated-plugin/src/vtable/runtime.rs

View file
@@ -0,0 +1,2 @@
1 #[derive(Clone, Copy)]
2 pub struct RuntimeVTable {}

plugins/example-plugin/src/lib.rs

View file
@@ -3,7 +3,7 @@ use std::sync::OnceLock;
3 3 use giterated_models::{
4 4 error::OperationError,
5 5 instance::Instance,
6 object::ObjectRequest,
6 object::{ObjectRequest, ObjectRequestError, ObjectResponse},
7 7 user::{DisplayName, User},
8 8 };
9 9 use giterated_plugin::{
@@ -73,7 +73,7 @@ async fn handler(
73 73 state: (),
74 74 _object: Instance,
75 75 _operation: ObjectRequest,
76 ) -> Result<(), OperationError<()>> {
76 ) -> Result<ObjectResponse, OperationError<ObjectRequestError>> {
77 77 info!("handling operation!");
78 78
79 79 todo!()

plugins/example-plugin/src/main.rs

View file
@@ -18,7 +18,7 @@ fn main() {
18 18
19 19 let mut handle = PluginHandle::from_dylib("example_plugin_dylib.dll").unwrap();
20 20
21 let mut runtime = Runtime::<()>::new();
21 let mut runtime = Runtime::new();
22 22
23 23 runtime.insert_plugin(handle);
24 24

plugins/giterated-backend/src/handlers.rs

View file
@@ -5,7 +5,7 @@ use giterated_models::{
5 5 repository::{Repository, RepositoryInfoRequest, RepositorySummary, RepositoryView},
6 6 user::{User, UserRepositoriesRequest},
7 7 };
8 use giterated_plugin::new_stack::{runtime_handler::RuntimeHandle, OperationState, Runtime, State};
8 use giterated_plugin::new_stack::{handle::RuntimeHandle, OperationState, Runtime, State};
9 9
10 10 use crate::DatabaseBackend;
11 11

plugins/giterated-issues/src/handlers.rs

View file
@@ -1,4 +1,3 @@
1 use crate::db::IssueRow;
2 1 use crate::setting::Contents;
3 2 use crate::value::{Author, CommentCount, CreationDate, Name};
4 3 use crate::IssuesPluginState;
@@ -9,110 +8,110 @@ use crate::{
9 8 },
10 9 Issue,
11 10 };
12 use giterated_models::error::IntoInternalError;
13 use giterated_models::user::User;
11
14 12 use giterated_models::{error::OperationError, repository::Repository};
15 use sqlx::PgPool;
16 13
17 14 pub async fn create_issue_request(
18 state: IssuesPluginState,
15 _state: IssuesPluginState,
19 16 repository: Repository,
20 request: CreateIssueRequest,
17 _request: CreateIssueRequest,
21 18 ) -> Result<Issue, OperationError<IssueCreationError>> {
22 // TODO: AUTHN & AUTHZ
23 let issue = sqlx::query_as!(
24 IssueRow,
25 r#"INSERT INTO issues VALUES (null, $1, $2, $3, $4, $5) RETURNING *"#,
26 repository.to_string(),
27 request.author.to_string(),
28 0,
29 request.name,
30 request.contents,
31 )
32 .fetch_one(&state.pool)
33 .await
34 .as_internal_error_with_context("creating issue in db")?;
19 // // TODO: AUTHN & AUTHZ
20 // let issue = sqlx::query_as!(
21 // IssueRow,
22 // r#"INSERT INTO issues VALUES (null, $1, $2, $3, $4, $5) RETURNING *"#,
23 // repository.to_string(),
24 // request.author.to_string(),
25 // 0,
26 // request.name,
27 // request.contents,
28 // )
29 // .fetch_one(&state.pool)
30 // .await
31 // .as_internal_error_with_context("creating issue in db")?;
35 32
36 Ok(Issue {
37 repository,
38 id: issue.id as u32,
39 })
33 // Ok(Issue {
34 // repository,
35 // id: issue.id as u32,
36 // })
37
38 Ok(Issue { repository, id: 1 })
40 39 }
41 40
42 41 pub async fn query_issues_request(
43 state: IssuesPluginState,
44 repository: Repository,
45 request: QueryIssuesRequest,
42 _state: IssuesPluginState,
43 _repository: Repository,
44 _request: QueryIssuesRequest,
46 45 ) -> Result<Vec<Issue>, OperationError<IssueQueryError>> {
47 46 // TODO: AUTHN & AUTHZ
48 47 todo!()
49 48 }
50 49
51 50 pub async fn edit_issue_request(
52 state: IssuesPluginState,
53 issue: Issue,
54 request: IssueEditRequest,
51 _state: IssuesPluginState,
52 _issue: Issue,
53 _request: IssueEditRequest,
55 54 ) -> Result<(), OperationError<IssueEditError>> {
56 55 // TODO: AUTHN & AUTHZ
57 56 todo!()
58 57 }
59 58
60 59 pub async fn issue_post_comment_request(
61 state: IssuesPluginState,
62 issue: Issue,
63 request: IssuePostCommentRequest,
60 _state: IssuesPluginState,
61 _issue: Issue,
62 _request: IssuePostCommentRequest,
64 63 ) -> Result<u32, OperationError<IssuePostCommentError>> {
65 64 // TODO: AUTHN & AUTHZ
66 65 todo!()
67 66 }
68 67
69 68 pub async fn issue_value_author(
70 state: IssuesPluginState,
71 issue: Issue,
69 _state: IssuesPluginState,
70 _issue: Issue,
72 71 ) -> Result<Author, OperationError<anyhow::Error>> {
73 72 todo!()
74 73 }
75 74
76 75 pub async fn issue_value_creation_date(
77 state: IssuesPluginState,
78 issue: Issue,
76 _state: IssuesPluginState,
77 _issue: Issue,
79 78 ) -> Result<CreationDate, OperationError<anyhow::Error>> {
80 79 todo!()
81 80 }
82 81
83 82 pub async fn issue_value_comment_count(
84 state: IssuesPluginState,
85 issue: Issue,
83 _state: IssuesPluginState,
84 _issue: Issue,
86 85 ) -> Result<CommentCount, OperationError<anyhow::Error>> {
87 86 todo!()
88 87 }
89 88
90 89 pub async fn issue_set_setting_name(
91 state: IssuesPluginState,
92 issue: Issue,
93 name: Name,
90 _state: IssuesPluginState,
91 _issue: Issue,
92 _name: Name,
94 93 ) -> Result<(), OperationError<anyhow::Error>> {
95 94 todo!()
96 95 }
97 96
98 97 pub async fn issue_get_setting_name(
99 state: IssuesPluginState,
100 issue: Issue,
98 _state: IssuesPluginState,
99 _issue: Issue,
101 100 ) -> Result<Name, OperationError<anyhow::Error>> {
102 101 todo!()
103 102 }
104 103
105 104 pub async fn issue_set_setting_contents(
106 state: IssuesPluginState,
107 issue: Issue,
108 contents: Contents,
105 _state: IssuesPluginState,
106 _issue: Issue,
107 _contents: Contents,
109 108 ) -> Result<(), OperationError<anyhow::Error>> {
110 109 todo!()
111 110 }
112 111
113 112 pub async fn issue_get_setting_contents(
114 state: IssuesPluginState,
115 issue: Issue,
113 _state: IssuesPluginState,
114 _issue: Issue,
116 115 ) -> Result<Contents, OperationError<anyhow::Error>> {
117 116 todo!()
118 117 }

plugins/giterated-issues/src/lib.rs

View file
@@ -1,14 +1,10 @@
1 use std::{
2 fmt::Display,
3 str::FromStr,
4 sync::{Arc, OnceLock},
5 };
1 use std::{fmt::Display, str::FromStr, sync::OnceLock};
6 2
7 3 use anyhow::Error;
8 4 use giterated_models::{object::GiteratedObject, repository::Repository};
9 5 use giterated_plugin::{
10 6 handle::PluginInitializationState,
11 new_stack::{FFIPluginMeta, PluginState},
7 new_stack::{FFIPluginMeta, OperationState, PluginState},
12 8 vtable::{HostVTable, InitializationVTable},
13 9 };
14 10 use giterated_plugin_sys::PluginStackBuilder;
@@ -18,18 +14,11 @@ use handlers::{
18 14 issue_value_author, issue_value_comment_count, issue_value_creation_date, query_issues_request,
19 15 };
20 16 use serde::{Deserialize, Serialize};
21 use setting::{Contents, NotificationsOverride};
17 use setting::NotificationsOverride;
22 18 use sqlx::{postgres::PgConnectOptions, PgPool};
23 use tokio::{
24 fs::File,
25 io::AsyncReadExt,
26 runtime::Runtime,
27 spawn,
28 task::{block_in_place, spawn_blocking},
29 };
19 use tokio::{fs::File, io::AsyncReadExt, runtime::Runtime};
30 20 use toml::Table;
31 21 use tracing::{debug, info};
32 use value::{Author, CommentCount, CreationDate, Name};
33 22
34 23 pub mod db;
35 24 pub mod handlers;

plugins/giterated-issues/src/main.rs

View file
@@ -21,7 +21,7 @@ pub async fn main() {
21 21
22 22 let mut handle = PluginHandle::from_dylib("giterated_issues.dll").unwrap();
23 23
24 let mut runtime = Runtime::<()>::new();
24 let mut runtime = Runtime::new();
25 25
26 26 runtime.insert_plugin(handle);
27 27

plugins/giterated-protocol/src/handlers.rs

View file
@@ -1,4 +1,4 @@
1 use std::{fmt::Display, net::SocketAddr, str::FromStr, sync::Arc};
1 use std::{fmt::Display, net::SocketAddr, str::FromStr};
2 2
3 3 use anyhow::Error;
4 4 use futures_util::{SinkExt, StreamExt};
@@ -9,7 +9,7 @@ use giterated_models::{
9 9 operation::GiteratedOperation,
10 10 };
11 11 use giterated_plugin::{
12 new_stack::{runtime_handler::RuntimeHandle, Runtime},
12 new_stack::{handle::RuntimeHandle, OperationState},
13 13 AnyFailure, AnyObject, AnyOperation, AnySuccess,
14 14 };
15 15 use serde::{Deserialize, Serialize};
@@ -19,7 +19,7 @@ use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, Web
19 19 use crate::{Authenticated, GiteratedMessage, ProtocolState, RemoteError};
20 20
21 21 pub async fn handle_network_operation<OS: Send + Sync + Clone + 'static>(
22 state: ProtocolState,
22 _state: ProtocolState,
23 23 object: NetworkedObject,
24 24 operation: NetworkedOperation,
25 25 runtime: RuntimeHandle,
@@ -86,10 +86,11 @@ impl GiteratedOperation<NetworkedObject> for NetworkedOperation {
86 86
87 87 /// Handler which will attempt to resolve any operation that doesn't resolve locally
88 88 /// against a remote instance.
89 pub async fn try_handle_with_remote<OS>(
89 pub async fn try_handle_with_remote(
90 90 state: ProtocolState,
91 91 object: AnyObject,
92 92 operation: AnyOperation,
93 _runtime: RuntimeHandle,
93 94 ) -> Result<AnySuccess, OperationError<AnyFailure>> {
94 95 // if object.is::<NetworkedObject>() {
95 96 // return Err(OperationError::Unhandled);