1pub mod cli;
2pub mod loader;
3
4use heck::ToTitleCase;
5use std::future::Future;
6
7use clap::Args;
8use spin_core::Linker;
9use spin_factors::RuntimeFactors;
10use spin_factors_executor::{FactorsExecutorApp, FactorsInstanceBuilder};
11
12pub use spin_app::App;
13
14pub type TriggerApp<T, F> = FactorsExecutorApp<F, <T as Trigger<F>>::InstanceState>;
16
17pub type TriggerInstanceBuilder<'a, T, F> =
19 FactorsInstanceBuilder<'a, F, <T as Trigger<F>>::InstanceState>;
20
21pub type Store<T, F> = spin_core::Store<TriggerInstanceState<T, F>>;
23
24type TriggerInstanceState<T, F> = spin_factors_executor::InstanceState<
26 <F as RuntimeFactors>::InstanceState,
27 <T as Trigger<F>>::InstanceState,
28>;
29
30pub trait Trigger<F: RuntimeFactors>: Sized + Send {
32 const TYPE: &'static str;
34
35 type CliArgs: Args;
37
38 type InstanceState: Send + 'static;
40
41 fn new(cli_args: Self::CliArgs, app: &App) -> anyhow::Result<Self>;
43
44 #[doc(hidden)]
49 fn update_core_config(&mut self, config: &mut spin_core::Config) -> anyhow::Result<()> {
50 let _ = config;
51 Ok(())
52 }
53
54 fn add_to_linker(
56 &mut self,
57 linker: &mut Linker<TriggerInstanceState<Self, F>>,
58 ) -> anyhow::Result<()> {
59 let _ = linker;
60 Ok(())
61 }
62
63 fn run(
65 self,
66 trigger_app: TriggerApp<Self, F>,
67 ) -> impl Future<Output = anyhow::Result<()>> + Send;
68
69 fn supported_host_requirements() -> Vec<&'static str> {
73 Vec::new()
74 }
75
76 fn display_name() -> String {
78 Self::TYPE.to_title_case()
79 }
80}