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-models/src/operation.rs⁩ - ⁨1187⁩ bytes
Raw
1 use std::{any::type_name, fmt::Debug};
2
3 use serde::{de::DeserializeOwned, Deserialize, Serialize};
4 use serde_json::Value;
5
6 use crate::object::GiteratedObject;
7
8 pub trait GiteratedOperation<O: GiteratedObject>:
9 Send + Sync + Serialize + DeserializeOwned
10 {
11 type Success: Serialize + DeserializeOwned + Send;
12 type Failure: Serialize + DeserializeOwned + Send;
13
14 fn operation_name() -> &'static str {
15 type_name::<Self>()
16 }
17 }
18
19 #[derive(Clone, Debug, Serialize, Deserialize)]
20 #[serde(transparent)]
21 #[repr(transparent)]
22 pub struct AnyOperation(pub Value);
23
24 impl<O: GiteratedObject> GiteratedOperation<O> for AnyOperation {
25 type Success = Value;
26
27 type Failure = Value;
28 }
29
30 #[derive(Clone, Debug, Serialize, Deserialize)]
31 #[serde(transparent)]
32 #[repr(transparent)]
33 pub struct AnyOperationV2(pub Vec<u8>);
34
35 impl<O: GiteratedObject> GiteratedOperation<O> for AnyOperationV2 {
36 type Success = Vec<u8>;
37
38 type Failure = Vec<u8>;
39 }
40
41 /// The internal state of an operation, used to provide authentication information
42 /// and the ability to make giterated calls within handlers.
43 #[derive(Clone)]
44 pub struct GiteratedOperationState<S: Clone + Send + Sync>(pub S);
45