artemis_codegen_proc_macro/lib.rs
1use artemis_codegen::wasm::{wasm_client as generate, WasmClientInput};
2use proc_macro::TokenStream;
3
4/// Generate a WASM client wrapper that gets exported in your WASM binary
5/// This is required because WASM doesn't support generics and the regular
6/// Client uses a lot of them. It will hard-code your exchanges, as well
7/// as other options you may pass to the macro.
8///
9/// Additional options can be passed from JavaScript, only exchanges and the query enum are required.
10/// The query enum is generated by [artemis-build](../artemis-build/index.html) and is located in
11/// the root of your query module.
12///
13/// Make sure this is located in a WASM-only module or annotate
14/// it with `#[cfg(target_arch = "wasm32")]`
15///
16/// # Usage
17///
18/// ```ignore
19/// use artemis::wasm_client;
20/// use artemis::default_exchanges::{DedupExchange, CacheExchange, FetchExchange};
21/// use artemis_test::queries::wasm::Queries;
22///
23/// wasm_client! {
24/// exchanges: [
25/// DedupExchange,
26/// CacheExchange,
27/// FetchExchange
28/// ],
29/// url: "my_url",
30/// queries: Queries
31/// }
32/// ```
33#[proc_macro]
34pub fn wasm_client(tokens: TokenStream) -> TokenStream {
35 let input = syn::parse_macro_input!(tokens as WasmClientInput);
36 generate(input).into()
37}