frost_guest_sdk/
lib.rs

1pub use wit_bindgen;
2
3#[macro_export]
4macro_rules! frost_component {
5    (
6        component: $component:tt,
7        world: $world:literal,
8        path: $wit_path:literal $(,)?
9    ) => {
10        pub mod bindings {
11            use super::*;
12            use $crate::wit_bindgen as wit_bindgen;
13
14            $crate::wit_bindgen::generate!({
15                world: $world,
16                path: $wit_path,
17                generate_all,
18                runtime_path: "frost_guest_sdk::wit_bindgen::rt",
19            });
20
21            export!($component);
22        }
23
24        pub mod sdk_guest {
25            pub use super::bindings;
26
27            pub mod outcome {
28                use super::bindings::exports::frost::batch::job::{
29                    FailureOutcome, MessageOutcome, Outcome, RetryOutcome,
30                };
31
32                pub fn ok(message: impl Into<String>) -> Outcome {
33                    Outcome::Success(MessageOutcome {
34                        message: message.into(),
35                        props: Vec::new(),
36                    })
37                }
38
39                pub fn ok_with_props(
40                    message: impl Into<String>,
41                    props: Vec<super::bindings::frost::core::types::Kv>,
42                ) -> Outcome {
43                    Outcome::Success(MessageOutcome {
44                        message: message.into(),
45                        props,
46                    })
47                }
48
49                pub fn retry(message: impl Into<String>, retry_after_ns: Option<u64>) -> Outcome {
50                    Outcome::Retry(RetryOutcome {
51                        message: message.into(),
52                        retry_after_ns,
53                        props: Vec::new(),
54                    })
55                }
56
57                pub fn retry_with_props(
58                    message: impl Into<String>,
59                    retry_after_ns: Option<u64>,
60                    props: Vec<super::bindings::frost::core::types::Kv>,
61                ) -> Outcome {
62                    Outcome::Retry(RetryOutcome {
63                        message: message.into(),
64                        retry_after_ns,
65                        props,
66                    })
67                }
68
69                pub fn fail(message: impl Into<String>, permanent: bool) -> Outcome {
70                    Outcome::Failure(FailureOutcome {
71                        message: message.into(),
72                        permanent,
73                        props: Vec::new(),
74                    })
75                }
76
77                pub fn fail_with_props(
78                    message: impl Into<String>,
79                    permanent: bool,
80                    props: Vec<super::bindings::frost::core::types::Kv>,
81                ) -> Outcome {
82                    Outcome::Failure(FailureOutcome {
83                        message: message.into(),
84                        permanent,
85                        props,
86                    })
87                }
88            }
89
90            pub mod prelude {
91                pub use super::bindings::exports::frost::batch::job::{
92                    FailureOutcome, Guest as Job, MessageOutcome, Outcome, RetryOutcome,
93                };
94                pub use super::bindings::frost::core::context::Ctx;
95                pub use super::bindings::frost::core::diagnostics::{log, Level};
96                pub use super::bindings::frost::core::types::{Error, Kv, Properties};
97                pub use super::outcome::{fail, fail_with_props, ok, ok_with_props, retry, retry_with_props};
98                pub use $crate::frost_component;
99            }
100        }
101    };
102}