diff --git a/Cargo.lock b/Cargo.lock index 25c2830..6df7e92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -108,7 +108,7 @@ dependencies = [ [[package]] name = "cloudwatch-provider" -version = "1.0.0-alpha.2" +version = "1.0.0-alpha.3" dependencies = [ "base64", "bytes", @@ -283,7 +283,7 @@ dependencies = [ [[package]] name = "fiberplane-pdk" -version = "1.0.0-alpha.2" +version = "1.0.0-alpha.3" dependencies = [ "fiberplane-models", "fiberplane-pdk-macros", @@ -299,7 +299,7 @@ dependencies = [ [[package]] name = "fiberplane-pdk-macros" -version = "1.0.0-alpha.2" +version = "1.0.0-alpha.3" dependencies = [ "Inflector", "fiberplane-models", @@ -976,7 +976,7 @@ checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "sample-provider" -version = "1.0.0-alpha.2" +version = "1.0.0-alpha.3" dependencies = [ "fiberplane-pdk", "serde", diff --git a/Cargo.toml b/Cargo.toml index e227781..5844c98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ exclude = ["providers/.cargo"] authors = ["Fiberplane "] edition = "2021" rust-version = "1.65" -version = "1.0.0-alpha.2" +version = "1.0.0-alpha.3" license = "MIT OR Apache-2.0" [workspace.dependencies] @@ -14,8 +14,8 @@ fp-bindgen = { version = "3.0.0-alpha.1" } fp-bindgen-support = { version = "3.0.0-alpha.1" } #fiberplane-models = { version = "1.0.0-alpha.2", registry = "artifactory" } fiberplane-models = { git = "ssh://git@github.com/fiberplane/fiberplane-rs.git", branch = "main" } -fiberplane-pdk = { version = "1.0.0-alpha.1", path = "fiberplane-pdk" } -fiberplane-pdk-macros = { version = "1.0.0-alpha.1", path = "fiberplane-pdk-macros" } +fiberplane-pdk = { version = "1.0.0-alpha.3", path = "fiberplane-pdk" } +fiberplane-pdk-macros = { version = "1.0.0-alpha.3", path = "fiberplane-pdk-macros" } #fiberplane-provider-bindings = { version = "1.0.0-alpha.2", registry = "artifactory" } fiberplane-provider-bindings = { git = "ssh://git@github.com/fiberplane/fiberplane-rs.git", branch = "main" } diff --git a/fiberplane-pdk-macros/src/lib.rs b/fiberplane-pdk-macros/src/lib.rs index 1bbf17a..19229b8 100644 --- a/fiberplane-pdk-macros/src/lib.rs +++ b/fiberplane-pdk-macros/src/lib.rs @@ -21,7 +21,8 @@ use quote::quote; /// requests of the given type. Handlers may have one or two arguments, the /// types of which are given between parentheses. The first argument is always /// the type of the query data, while the second optionally specifies a type -/// for the provider's config. Providing a handler is mandatory. +/// for the provider's config. Add a `.await` call to the handler +/// if the handler is asynchronous. Providing a handler is mandatory. /// * **label** - A label that is used when presenting the query type to the /// user. Some query types are not intended to be user-selected (such as the /// `status` query type) in which case they should not define a label. @@ -49,7 +50,7 @@ use quote::quote; /// }, /// "x-custom-query-type" => { /// label: "My custom query", -/// handler: query_custom(ExampleQueryData), +/// handler: query_custom(ExampleQueryData).await, /// supported_mime_types: ["application/vnd.fiberplane.provider.my-provider.custom-data"], /// } /// } @@ -58,7 +59,7 @@ use quote::quote; /// todo!("Implement timeseries query handling") /// } /// -/// fn query_custom(query_data: ExampleQueryData) -> Result { +/// async fn query_custom(query_data: ExampleQueryData) -> Result { /// todo!("Implement custom query handling") /// } /// ``` diff --git a/fiberplane-pdk-macros/src/query_types.rs b/fiberplane-pdk-macros/src/query_types.rs index f0f2ae9..d9d954c 100644 --- a/fiberplane-pdk-macros/src/query_types.rs +++ b/fiberplane-pdk-macros/src/query_types.rs @@ -64,7 +64,11 @@ pub fn define_query_types(input: TokenStream) -> TokenStream { }; quote! { #ty::parse(#parse_arg)? } }); - quote! { #fn_name(#(#args),*) } + if handler.is_async { + quote! { #fn_name(#(#args),*).await } + } else { + quote! { #fn_name(#(#args),*) } + } }); quote! { #identifier => #handler } @@ -172,6 +176,7 @@ impl Parse for QueryTypeField { } struct QueryHandler { + is_async: bool, ident: Ident, _parens: token::Paren, arg_types: Punctuated, @@ -180,10 +185,23 @@ struct QueryHandler { impl Parse for QueryHandler { fn parse(input: ParseStream) -> Result { let content; + + let ident = input.parse::()?; + let _parens = parenthesized!(content in input); + let arg_types = content.parse_terminated(Ident::parse)?; + let is_async = if input.peek(Token![.]) && input.peek2(Token![await]) { + input.parse::()?; + input.parse::()?; + true + } else { + false + }; + Ok(Self { - ident: input.parse()?, - _parens: parenthesized!(content in input), - arg_types: content.parse_terminated(Ident::parse)?, + is_async, + ident, + _parens, + arg_types, }) } }