From 0326ccebf2b21d141ee0c57c1cfbe153f9fbf386 Mon Sep 17 00:00:00 2001 From: Victor Teo Date: Thu, 21 Nov 2024 21:13:30 +0800 Subject: [PATCH] 0.3.2 --- Cargo.lock | 14 +++++++------- Cargo.toml | 4 ++-- index.d.ts | 5 +++-- src/request/handler_match.rs | 2 +- src/request/request.rs | 2 +- src/response/mod.rs | 7 +++++++ 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f626621..b9739ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3773,9 +3773,9 @@ dependencies = [ [[package]] name = "teo" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c3f6fe1c21558f51ee9e209f402483c6cda99054211a0e34bc658086b82e8fb" +checksum = "d27ae60a06710260eb8e26066dff8efed7e8387780697f38b52fba43c66dd2cb" dependencies = [ "array_tool", "async-recursion", @@ -3822,9 +3822,9 @@ dependencies = [ [[package]] name = "teo-generator" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c7e525ba494af82c5ba5cb8fa91780906a674c3118b407604f0391c7e6c3753" +checksum = "40f3fa8bcaa435f037f4f65d9c6aba717d315f653daa4cc2025b2f9adab4d085" dependencies = [ "askama", "async-recursion", @@ -3922,9 +3922,9 @@ dependencies = [ [[package]] name = "teo-runtime" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01a4cb37d67e78f961cb67bc238c6fed276914802cfa31be3be3dbaeca6f4e6a" +checksum = "536a18bd3da81e1277108cb62a36334fb6d42c549868b2d083eeb38cc3c844d0" dependencies = [ "array_tool", "async-recursion", @@ -3999,7 +3999,7 @@ dependencies = [ [[package]] name = "teodevgroup_teo" -version = "0.3.0" +version = "0.3.2" dependencies = [ "bigdecimal", "bson", diff --git a/Cargo.toml b/Cargo.toml index 6e8f3e1..7350f0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] edition = "2021" name = "teodevgroup_teo" -version = "0.3.1" +version = "0.3.2" [lib] crate-type = ["cdylib"] [dependencies] -teo = { version = "0.3.1" } +teo = { version = "0.3.2" } teo-result = { version = "0.3.0", features = ["napi"] } napi = { version = "2.16.13", default-features = false, features = ["napi5", "async", "chrono_date", "compat-mode"] } napi-derive = "2.16.12" diff --git a/index.d.ts b/index.d.ts index f46d5da..c0d70ff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -95,7 +95,7 @@ export declare class App { export declare class HandlerMatch { path(): Array handlerName(): string - captures(): {[key: string]: string} + captures(): {[key: string]: string} | any } export declare class Request { version(): string @@ -114,7 +114,7 @@ export declare class Request { cookie(name: string): Cookie | null cookies(): Array handlerMatch(): HandlerMatch - captures(): {[key: string]: string} + captures(): {[key: string]: string} | any bodyObject(): any setBodyObject(value: unknown): void teo(): any @@ -182,6 +182,7 @@ export declare class Response { static data(value: unknown): Response static dataMeta(data: unknown, meta: unknown): Response static file(path: string): Response + static sendFile(base: string, path: string): Response static redirect(path: string): Response setCode(code: number): void code(): number diff --git a/src/request/handler_match.rs b/src/request/handler_match.rs index 94c570c..4183c73 100644 --- a/src/request/handler_match.rs +++ b/src/request/handler_match.rs @@ -26,7 +26,7 @@ impl HandlerMatch { self.inner.handler_name() } - #[napi(ts_return_type = "{[key: string]: string}")] + #[napi(ts_return_type = "{[key: string]: string} | any")] pub fn captures(&self, env: Env) -> Result { let captures_map = self.inner.captures(); let mut js_object = env.create_object()?; diff --git a/src/request/request.rs b/src/request/request.rs index b0e11c6..1b9eece 100644 --- a/src/request/request.rs +++ b/src/request/request.rs @@ -122,7 +122,7 @@ impl Request { Ok(HandlerMatch::new(self.teo_request.handler_match()?.clone())) } - #[napi(ts_return_type = "{[key: string]: string}")] + #[napi(ts_return_type = "{[key: string]: string} | any")] pub fn captures(&self, env: Env) -> Result { self.handler_match()?.captures(env) } diff --git a/src/response/mod.rs b/src/response/mod.rs index 92e1e5e..8c4500a 100644 --- a/src/response/mod.rs +++ b/src/response/mod.rs @@ -72,6 +72,13 @@ impl Response { } } + #[napi(js_name = "sendFile")] + pub fn send_file(base: String, path: String) -> Result { + Ok(Self { + teo_response: TeoResponse::send_file(base, path)? + }) + } + #[napi(js_name = "redirect")] pub fn redirect(path: String) -> Self { Self {