Create `NetworkedSubstack`.
# giterated-protocol - Create `NetworkedSubstack` which will handle all networked operations giterated needs - Add support for `NetworkedSubstack` for both the daemon and client - Pipe everything through but leave APIs temp # `giterated-daemon` - Remove a bunch of random old code, dead code, and files that aren't needed. - Moved all connection handling to `client.rs`, simplified connection logic with new types
parent: tbd commit: 202bb12
1 | use ; |
2 | |
3 | use FutureExt; |
4 | use |
5 | , | OperationError
6 | , | Instance
7 | , |
8 | , | GiteratedOperation
9 | , | Setting
10 | , | GiteratedObjectValue
11 | ; |
12 | use ; |
13 | |
14 | use crate:: |
15 | , MetadataProvider, AnyFailure, AnyObject, AnyOperation, | HandlerWrapper
16 | AnySetting, AnySuccess, AnyValue, GiteratedStack, GiteratedStackState, IntoGiteratedHandler, |
17 | MaybeDynamicObject, MaybeDynamicValue, ObjectOperationPair, ObjectSettingPair, ObjectValuePair, |
18 | OperationHandler, RuntimeMetadata, SettingChange, SettingGetter, StackOperationState, |
19 | ValueChange, ValueGetter, |
20 | ; |
21 | |
22 | |
23 | pub(crate) operation_handlers: , |
24 | pub(crate) value_getters: , |
25 | pub(crate) setting_getters: , |
26 | pub(crate) metadata: RuntimeMetadata, |
27 | pub(crate) value_change: , |
28 | pub(crate) metadata_providers: , |
29 | pub(crate) setting_change: , |
30 | |
31 | pub(crate) state: S, |
32 | |
33 | |
34 | |
35 | |
36 | Self |
37 | operation_handlers: Default default, |
38 | value_getters: Default default, |
39 | setting_getters: Default default, |
40 | metadata: Default default, |
41 | value_change: Default default, |
42 | metadata_providers: Default default, |
43 | setting_change: Default default, |
44 | state, |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | /// Insert an operation handler into the runtime builder. |
51 | /// |
52 | /// # Type Registration |
53 | /// Inserting the handler will automatically, if required, register the operation type of the |
54 | /// handler. It will **not** register the object type automatically. |
55 | |
56 | |
57 | O: GiteratedObject + Clone, |
58 | D: + Clone, |
59 | H: |
60 | (O, D), |
61 | A, |
62 | S, |
63 | StackOperationState, |
64 | , |
65 | > + Send |
66 | + Sync |
67 | + 'static, |
68 | O: 'static, |
69 | D: 'static, |
70 | : Debug + 'static, | Failure
71 | : 'static, | Success
72 | |
73 | let wrapped = new; |
74 | |
75 | let wrapped = wrapped.map |
76 | |
77 | |
78 | Ok |
79 | any_object.unwrap .clone, | .
80 | any_operation.unwrap .clone, | .
81 | |
82 | , |
83 | ; |
84 | |
85 | let wrapped = wrapped.map_return |
86 | Ok => Ok, |
87 | Err => Err |
88 | => | Operation
89 | Operation |
90 | |
91 | => Internal, | Internal
92 | => Unhandled, | Unhandled
93 | , |
94 | ; |
95 | |
96 | let pair = ; |
97 | |
98 | self.operation_handlers.insert; |
99 | |
100 | self.metadata.; |
101 | |
102 | self |
103 | |
104 | |
105 | /// Register a [`GiteratedObject`] type with the runtime. |
106 | /// |
107 | /// # Type Registration |
108 | /// This will register the provided object type. |
109 | |
110 | self.metadata.; |
111 | |
112 | // Insert handler so ObjectRequest is handled properly |
113 | |
114 | self.operation |
115 | move |_object: Instance, |
116 | operation: ObjectRequest, |
117 | _state: S, |
118 | _operation_state: StackOperationState, |
119 | stack: | |
120 | let operation = operation.clone; |
121 | async move |
122 | for in stack.metadata.objects.iter |
123 | if .is_ok |
124 | return Ok; |
125 | |
126 | |
127 | |
128 | Err |
129 | |
130 | .boxed_local |
131 | , |
132 | ; |
133 | |
134 | self |
135 | |
136 | |
137 | /// Register a [`Setting`] type with the runtime. |
138 | /// |
139 | /// # Type Registration |
140 | /// This will register the provided setting type. |
141 | |
142 | &mut self, |
143 | |
144 | self.metadata.; |
145 | |
146 | self |
147 | |
148 | |
149 | /// Register a [`GiteratedObjectValue`] that is also a [`Setting`], which |
150 | /// allows for automatic value updates. |
151 | |
152 | O: GiteratedObject + 'static + Clone, |
153 | T: + Setting + 'static + Clone, |
154 | > |
155 | &mut self, |
156 | |
157 | self.metadata.; |
158 | self.metadata.; |
159 | |
160 | self.setting_change.insert |
161 | , |
162 | new |
163 | , |
164 | move |object: AnyObject, |
165 | setting: AnySetting, |
166 | _state: , |
167 | operation_state: StackOperationState, |
168 | stack: | |
169 | trace! |
170 | "value setting updated {}::{}", |
171 | , | object_name
172 | value_name |
173 | ; |
174 | let object = object.clone; |
175 | async move |
176 | let object = object. .unwrap; |
177 | let setting = setting. .unwrap; |
178 | stack |
179 | .value_update |
180 | object.clone, |
181 | , | new
182 | &operation_state, |
183 | |
184 | .await; |
185 | Ok |
186 | |
187 | .boxed_local |
188 | , |
189 | , |
190 | ; |
191 | |
192 | let wrapped = new |
193 | self.state.clone, |
194 | |
195 | |
196 | _state: _, |
197 | _operation_state: StackOperationState, |
198 | stack: | |
199 | info!; |
200 | let object = object.clone; |
201 | async move |
202 | match stack |
203 | . |
204 | .await |
205 | |
206 | Ok => Ok, |
207 | Err => |
208 | panic!; |
209 | |
210 | |
211 | |
212 | .boxed_local |
213 | , |
214 | ; |
215 | |
216 | self.value_getters |
217 | .insert; |
218 | |
219 | self |
220 | |
221 | |
222 | /// Register a [`GiteratedObjectValue<O>`] type with the runtime, providing |
223 | /// its associated handler for [`GetValue`]. |
224 | /// |
225 | /// # Type Registration |
226 | /// This will register the provided [`GiteratedObjectValue`] type for its matching / specified |
227 | /// object type. It will **not** register the object type automatically. |
228 | |
229 | |
230 | O: MaybeDynamicObject + 'static, |
231 | F: |
232 | (O, String), |
233 | A, |
234 | S, |
235 | StackOperationState, |
236 | , |
237 | > + Send |
238 | + Sync, |
239 | F: 'static, |
240 | |
241 | let wrapped = new; |
242 | |
243 | let wrapped = wrapped.map |
244 | |
245 | Ok |
246 | , |
247 | ; |
248 | |
249 | let wrapped = wrapped.map_return |
250 | Ok => Ok, |
251 | Err => Err |
252 | => Internal, | Operation
253 | => Internal, | Internal
254 | => Unhandled, | Unhandled
255 | , |
256 | ; |
257 | |
258 | assert! |
259 | .value_getters |
260 | .insert |
261 | ObjectValuePair |
262 | object_kind: object_name, |
263 | value_kind: "any" |
264 | , |
265 | wrapped |
266 | |
267 | .is_none; |
268 | |
269 | self |
270 | |
271 | |
272 | |
273 | |
274 | F: |
275 | (O, V), |
276 | A, |
277 | S, |
278 | StackOperationState, |
279 | , |
280 | > + Send |
281 | + Sync, |
282 | V: MaybeDynamicValue + Clone + 'static, |
283 | O: 'static + MaybeDynamicObject, |
284 | V: 'static, |
285 | F: 'static, |
286 | |
287 | let wrapped = new; |
288 | |
289 | let wrapped = wrapped.map |
290 | |
291 | Ok |
292 | , |
293 | ; |
294 | |
295 | assert! |
296 | .value_change |
297 | .insert |
298 | ObjectValuePair |
299 | object_kind: object_name, |
300 | value_kind: value_name |
301 | , |
302 | wrapped |
303 | |
304 | .is_none; |
305 | |
306 | self |
307 | |
308 | |
309 | |
310 | self.metadata_providers.push; |
311 | |
312 | self |
313 | |
314 | |
315 | |
316 | // Placeholder |
317 | |
318 | |
319 | todo! |
320 | |
321 | |
322 | |
323 | |
324 | ; |
325 |