-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: detect api/ folder from tuono CLI * feat: prevent adding the API in the data endpoints list * feat: create basic API handler proc macro * feat: parse api/ and build .tuono/main.rs file * chore: remove unused cargo dependencies * refactor: tuono base health_check * fix: remove failing test * feat: update version to v0.14.0
- Loading branch information
1 parent
3a4e739
commit 087813f
Showing
16 changed files
with
246 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tuono" | ||
version = "0.13.3" | ||
version = "0.14.0" | ||
edition = "2021" | ||
authors = ["V. Ageno <[email protected]>"] | ||
description = "Superfast React fullstack framework" | ||
|
@@ -32,3 +32,4 @@ regex = "1.10.4" | |
reqwest = {version = "0.12.4", features =["blocking", "json"]} | ||
serde_json = "1.0" | ||
fs_extra = "1.3.0" | ||
http = "1.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tuono_lib" | ||
version = "0.13.3" | ||
version = "0.14.0" | ||
edition = "2021" | ||
authors = ["V. Ageno <[email protected]>"] | ||
description = "Superfast React fullstack framework" | ||
|
@@ -31,7 +31,7 @@ either = "1.13.0" | |
tower-http = {version = "0.6.0", features = ["fs"]} | ||
colored = "2.1.0" | ||
|
||
tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.13.3"} | ||
tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.14.0"} | ||
# Match the same version used by axum | ||
tokio-tungstenite = "0.24.0" | ||
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::utils::{ | ||
crate_application_state_extractor, create_struct_fn_arg, import_main_application_state, | ||
params_argument, request_argument, | ||
}; | ||
use proc_macro::{Span, TokenStream}; | ||
use quote::quote; | ||
use syn::punctuated::Punctuated; | ||
use syn::token::Comma; | ||
use syn::{parse_macro_input, FnArg, Ident, ItemFn, Pat}; | ||
|
||
pub fn api_core(attrs: TokenStream, item: TokenStream) -> TokenStream { | ||
let item = parse_macro_input!(item as ItemFn); | ||
let http_method = parse_macro_input!(attrs as Ident) | ||
.to_string() | ||
.to_lowercase(); | ||
|
||
let api_fn_name = Ident::new( | ||
&format!("{}__tuono_internal_api", http_method), | ||
Span::call_site().into(), | ||
); | ||
|
||
let fn_name = &item.sig.ident; | ||
let return_type = &item.sig.output; | ||
|
||
let mut argument_names: Punctuated<Pat, Comma> = Punctuated::new(); | ||
let mut axum_arguments: Punctuated<FnArg, Comma> = Punctuated::new(); | ||
|
||
// Fn Arguments minus the first which always is the request | ||
for (i, arg) in item.sig.inputs.iter().enumerate() { | ||
if i == 0 { | ||
axum_arguments.insert(i, params_argument()); | ||
continue; | ||
} | ||
|
||
if i == 1 { | ||
axum_arguments.insert(1, create_struct_fn_arg()) | ||
} | ||
|
||
if let FnArg::Typed(pat_type) = arg { | ||
let index = i - 1; | ||
let argument_name = *pat_type.pat.clone(); | ||
argument_names.insert(index, argument_name.clone()); | ||
} | ||
} | ||
|
||
axum_arguments.insert(axum_arguments.len(), request_argument()); | ||
|
||
let application_state_extractor = crate_application_state_extractor(argument_names.clone()); | ||
let application_state_import = import_main_application_state(argument_names.clone()); | ||
|
||
quote! { | ||
#application_state_import | ||
|
||
#item | ||
|
||
pub async fn #api_fn_name(#axum_arguments)#return_type { | ||
|
||
#application_state_extractor | ||
|
||
let pathname = request.uri(); | ||
let headers = request.headers(); | ||
|
||
let req = tuono_lib::Request::new(pathname.to_owned(), headers.to_owned(), params); | ||
|
||
#fn_name(req.clone(), #argument_names).await | ||
} | ||
} | ||
.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
|
||
mod api; | ||
mod handler; | ||
mod utils; | ||
|
||
#[proc_macro_attribute] | ||
pub fn handler(args: TokenStream, item: TokenStream) -> TokenStream { | ||
handler::handler_core(args, item) | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn api(args: TokenStream, item: TokenStream) -> TokenStream { | ||
api::api_core(args, item) | ||
} |
Oops, something went wrong.