@@ -316,9 +316,52 @@ pub trait TargetFactory: Send + Sync {
316316 ) -> Result < ( ) > ;
317317}
318318
319+ pub struct TargetAttachmentState {
320+ pub setup_key : serde_json:: Value ,
321+ pub setup_state : serde_json:: Value ,
322+ }
323+
324+ #[ async_trait]
325+ pub trait AttachmentSetupChangeAction {
326+ fn describe_change ( & self ) -> String ;
327+
328+ async fn apply_change ( & self ) -> Result < ( ) > ;
329+ }
330+
331+ pub trait TargetAttachmentFactory : Send + Sync {
332+ /// Normalize the key. e.g. the JSON format may change (after code change, e.g. new optional field or field ordering), even if the underlying value is not changed.
333+ /// This should always return the canonical serialized form.
334+ fn normalize_setup_key ( & self , key : & serde_json:: Value ) -> Result < serde_json:: Value > ;
335+
336+ fn get_state (
337+ & self ,
338+ target_name : & str ,
339+ target_spec : & serde_json:: Map < String , serde_json:: Value > ,
340+ attachment_spec : serde_json:: Value ,
341+ ) -> Result < TargetAttachmentState > ;
342+
343+ /// Should return Some if and only if any changes are needed.
344+ fn diff_setup_states (
345+ & self ,
346+ key : & serde_json:: Value ,
347+ new_state : Option < serde_json:: Value > ,
348+ existing_states : setup:: CombinedState < serde_json:: Value > ,
349+ ) -> Result < Option < Box < dyn AttachmentSetupChangeAction + Send + Sync > > > ;
350+ }
351+
319352#[ derive( Clone ) ]
320353pub enum ExecutorFactory {
321354 Source ( Arc < dyn SourceFactory + Send + Sync > ) ,
322355 SimpleFunction ( Arc < dyn SimpleFunctionFactory + Send + Sync > ) ,
323356 ExportTarget ( Arc < dyn TargetFactory + Send + Sync > ) ,
357+ TargetAttachment ( Arc < dyn TargetAttachmentFactory + Send + Sync > ) ,
358+ }
359+
360+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , Hash ) ]
361+ pub struct AttachmentSetupKey ( pub String , pub serde_json:: Value ) ;
362+
363+ impl std:: fmt:: Display for AttachmentSetupKey {
364+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
365+ write ! ( f, "{}:{}" , self . 0 , self . 1 )
366+ }
324367}
0 commit comments