11use crate :: prelude:: * ;
2- use crate :: setup:: ResourceSetupStatus ;
2+ use crate :: setup:: ResourceSetupChange ;
33use std:: fmt:: Debug ;
44use std:: hash:: Hash ;
55
@@ -350,31 +350,31 @@ impl<T: SimpleFunctionFactoryBase> SimpleFunctionFactory for T {
350350 }
351351}
352352
353- pub struct TypedExportDataCollectionBuildOutput < F : StorageFactoryBase + ?Sized > {
353+ pub struct TypedExportDataCollectionBuildOutput < F : TargetFactoryBase + ?Sized > {
354354 pub export_context : BoxFuture < ' static , Result < Arc < F :: ExportContext > > > ,
355355 pub setup_key : F :: Key ,
356356 pub desired_setup_state : F :: SetupState ,
357357}
358- pub struct TypedExportDataCollectionSpec < F : StorageFactoryBase + ?Sized > {
358+ pub struct TypedExportDataCollectionSpec < F : TargetFactoryBase + ?Sized > {
359359 pub name : String ,
360360 pub spec : F :: Spec ,
361361 pub key_fields_schema : Vec < FieldSchema > ,
362362 pub value_fields_schema : Vec < FieldSchema > ,
363363 pub index_options : IndexOptions ,
364364}
365365
366- pub struct TypedResourceSetupChangeItem < ' a , F : StorageFactoryBase + ?Sized > {
366+ pub struct TypedResourceSetupChangeItem < ' a , F : TargetFactoryBase + ?Sized > {
367367 pub key : F :: Key ,
368- pub setup_status : & ' a F :: SetupStatus ,
368+ pub setup_change : & ' a F :: SetupChange ,
369369}
370370
371371#[ async_trait]
372- pub trait StorageFactoryBase : ExportTargetFactory + Send + Sync + ' static {
372+ pub trait TargetFactoryBase : TargetFactory + Send + Sync + ' static {
373373 type Spec : DeserializeOwned + Send + Sync ;
374374 type DeclarationSpec : DeserializeOwned + Send + Sync ;
375375 type Key : Debug + Clone + Serialize + DeserializeOwned + Eq + Hash + Send + Sync ;
376376 type SetupState : Debug + Clone + Serialize + DeserializeOwned + Send + Sync ;
377- type SetupStatus : ResourceSetupStatus ;
377+ type SetupChange : ResourceSetupChange ;
378378 type ExportContext : Send + Sync + ' static ;
379379
380380 fn name ( & self ) -> & str ;
@@ -397,13 +397,13 @@ pub trait StorageFactoryBase: ExportTargetFactory + Send + Sync + 'static {
397397
398398 /// Will not be called if it's setup by user.
399399 /// It returns an error if the target only supports setup by user.
400- async fn check_setup_status (
400+ async fn diff_setup_states (
401401 & self ,
402402 key : Self :: Key ,
403403 desired_state : Option < Self :: SetupState > ,
404404 existing_states : setup:: CombinedState < Self :: SetupState > ,
405405 flow_instance_ctx : Arc < FlowInstanceContext > ,
406- ) -> Result < Self :: SetupStatus > ;
406+ ) -> Result < Self :: SetupChange > ;
407407
408408 fn check_state_compatibility (
409409 & self ,
@@ -439,13 +439,13 @@ pub trait StorageFactoryBase: ExportTargetFactory + Send + Sync + 'static {
439439
440440 async fn apply_setup_changes (
441441 & self ,
442- setup_status : Vec < TypedResourceSetupChangeItem < ' async_trait , Self > > ,
442+ setup_change : Vec < TypedResourceSetupChangeItem < ' async_trait , Self > > ,
443443 context : Arc < FlowInstanceContext > ,
444444 ) -> Result < ( ) > ;
445445}
446446
447447#[ async_trait]
448- impl < T : StorageFactoryBase > ExportTargetFactory for T {
448+ impl < T : TargetFactoryBase > TargetFactory for T {
449449 async fn build (
450450 self : Arc < Self > ,
451451 data_collections : Vec < interface:: ExportDataCollectionSpec > ,
@@ -455,7 +455,7 @@ impl<T: StorageFactoryBase> ExportTargetFactory for T {
455455 Vec < interface:: ExportDataCollectionBuildOutput > ,
456456 Vec < ( serde_json:: Value , serde_json:: Value ) > ,
457457 ) > {
458- let ( data_coll_output, decl_output) = StorageFactoryBase :: build (
458+ let ( data_coll_output, decl_output) = TargetFactoryBase :: build (
459459 self ,
460460 data_collections
461461 . into_iter ( )
@@ -497,32 +497,32 @@ impl<T: StorageFactoryBase> ExportTargetFactory for T {
497497 Ok ( ( data_coll_output, decl_output) )
498498 }
499499
500- async fn check_setup_status (
500+ async fn diff_setup_states (
501501 & self ,
502502 key : & serde_json:: Value ,
503503 desired_state : Option < serde_json:: Value > ,
504504 existing_states : setup:: CombinedState < serde_json:: Value > ,
505505 flow_instance_ctx : Arc < FlowInstanceContext > ,
506- ) -> Result < Box < dyn setup:: ResourceSetupStatus > > {
506+ ) -> Result < Box < dyn setup:: ResourceSetupChange > > {
507507 let key: T :: Key = Self :: deserialize_setup_key ( key. clone ( ) ) ?;
508508 let desired_state: Option < T :: SetupState > = desired_state
509509 . map ( |v| serde_json:: from_value ( v. clone ( ) ) )
510510 . transpose ( ) ?;
511511 let existing_states = from_json_combined_state ( existing_states) ?;
512- let setup_status = StorageFactoryBase :: check_setup_status (
512+ let setup_change = TargetFactoryBase :: diff_setup_states (
513513 self ,
514514 key,
515515 desired_state,
516516 existing_states,
517517 flow_instance_ctx,
518518 )
519519 . await ?;
520- Ok ( Box :: new ( setup_status ) )
520+ Ok ( Box :: new ( setup_change ) )
521521 }
522522
523523 fn describe_resource ( & self , key : & serde_json:: Value ) -> Result < String > {
524524 let key: T :: Key = Self :: deserialize_setup_key ( key. clone ( ) ) ?;
525- StorageFactoryBase :: describe_resource ( self , & key)
525+ TargetFactoryBase :: describe_resource ( self , & key)
526526 }
527527
528528 fn normalize_setup_key ( & self , key : & serde_json:: Value ) -> Result < serde_json:: Value > {
@@ -535,21 +535,23 @@ impl<T: StorageFactoryBase> ExportTargetFactory for T {
535535 desired_state : & serde_json:: Value ,
536536 existing_state : & serde_json:: Value ,
537537 ) -> Result < SetupStateCompatibility > {
538- let result = StorageFactoryBase :: check_state_compatibility (
538+ let result = TargetFactoryBase :: check_state_compatibility (
539539 self ,
540540 & serde_json:: from_value ( desired_state. clone ( ) ) ?,
541541 & serde_json:: from_value ( existing_state. clone ( ) ) ?,
542542 ) ?;
543543 Ok ( result)
544544 }
545545
546+ /// Extract additional keys that are passed through as part of the mutation to `apply_mutation()`.
547+ /// This is useful for targets that need to use additional parts as key for the target (which is not considered as part of the key for cocoindex).
546548 fn extract_additional_key (
547549 & self ,
548550 key : & value:: KeyValue ,
549551 value : & value:: FieldValues ,
550552 export_context : & ( dyn Any + Send + Sync ) ,
551553 ) -> Result < serde_json:: Value > {
552- StorageFactoryBase :: extract_additional_key (
554+ TargetFactoryBase :: extract_additional_key (
553555 self ,
554556 key,
555557 value,
@@ -575,23 +577,23 @@ impl<T: StorageFactoryBase> ExportTargetFactory for T {
575577 } )
576578 } )
577579 . collect :: < Result < _ > > ( ) ?;
578- StorageFactoryBase :: apply_mutation ( self , mutations) . await
580+ TargetFactoryBase :: apply_mutation ( self , mutations) . await
579581 }
580582
581583 async fn apply_setup_changes (
582584 & self ,
583- setup_status : Vec < ResourceSetupChangeItem < ' async_trait > > ,
585+ setup_change : Vec < ResourceSetupChangeItem < ' async_trait > > ,
584586 context : Arc < FlowInstanceContext > ,
585587 ) -> Result < ( ) > {
586- StorageFactoryBase :: apply_setup_changes (
588+ TargetFactoryBase :: apply_setup_changes (
587589 self ,
588- setup_status
590+ setup_change
589591 . into_iter ( )
590592 . map ( |item| -> anyhow:: Result < _ > {
591593 Ok ( TypedResourceSetupChangeItem {
592594 key : serde_json:: from_value ( item. key . clone ( ) ) ?,
593- setup_status : ( item. setup_status as & dyn Any )
594- . downcast_ref :: < T :: SetupStatus > ( )
595+ setup_change : ( item. setup_change as & dyn Any )
596+ . downcast_ref :: < T :: SetupChange > ( )
595597 . ok_or_else ( invariance_violation) ?,
596598 } )
597599 } )
0 commit comments