diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 38b9c58..dd52880 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -108,7 +108,7 @@ jobs: token: ${{secrets.CODECOV_TOKEN}} - name: Archive code coverage results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: code-coverage-report path: cobertura.xml diff --git a/Cargo.toml b/Cargo.toml index f63b97a..76fed45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ codegen-units = 1 opt-level = "z" [workspace.package] -version = "0.1.0-rc.16" +version = "0.1.0-rc.17" authors = ["gudaoxuri "] description = "Elegant, clean Rust development framework" keywords = ["http", "database", "web", "redis", "mq"] diff --git a/examples/macros_examples/src/example_for_derive_create_entity.rs b/examples/macros_examples/src/example_for_derive_create_entity.rs index 011079e..3800806 100644 --- a/examples/macros_examples/src/example_for_derive_create_entity.rs +++ b/examples/macros_examples/src/example_for_derive_create_entity.rs @@ -21,7 +21,7 @@ pub struct Model { pub number64: i64, pub number_f32: f32, pub number_f64: f64, - pub number_u8: Vec, + pub be_var_binary: Vec, pub can_bool: bool, #[index(full_text, index_id = "index_id_3")] pub can_be_null: Option, diff --git a/examples/macros_examples/src/example_for_derive_create_table.rs b/examples/macros_examples/src/example_for_derive_create_table.rs index 1262e6b..c884f94 100644 --- a/examples/macros_examples/src/example_for_derive_create_table.rs +++ b/examples/macros_examples/src/example_for_derive_create_table.rs @@ -20,7 +20,7 @@ pub struct Model { pub number64: i64, pub number_f32: f32, pub number_f64: f64, - pub number_u8: Vec, + pub be_var_binary: Vec, pub can_bool: bool, pub can_be_null: Option, #[tardis_entity(custom_type = "char", custom_len = "50")] diff --git a/tardis-macros/src/tardis_create_table.rs b/tardis-macros/src/tardis_create_table.rs index 7400333..cd98509 100644 --- a/tardis-macros/src/tardis_create_table.rs +++ b/tardis-macros/src/tardis_create_table.rs @@ -222,9 +222,9 @@ fn create_single_col_token_statement(field: CreateTableMeta) -> Result) -> Result "tiny_integer", "u8" => { if let Some("Vec") = segments_type { - "binary" + "var_binary" } else if cfg!(feature = "reldb-postgres") { return Err(Error::new( span, @@ -309,7 +309,7 @@ fn map_rust_ty_custom_ty(ident: &Ident, segments_type: Option<&str>) -> Result "Json", }; let result = if let Some("Vec") = segments_type { - if custom_ty != "binary" { + if custom_ty != "var_binary" && custom_ty != "binary" { format!("array.{custom_ty}") } else { custom_ty.to_string() @@ -337,9 +337,9 @@ fn map_custom_type_to_sea_type(custom_column_type: &str, custom_len: Vec, s } "String" | "string" => { if let Some(len) = custom_len.first() { - quote!(::tardis::db::sea_orm::sea_query::ColumnType::String(Some(#len))) + quote!(::tardis::db::sea_orm::sea_query::ColumnType::String(::tardis::db::sea_orm::sea_query::StringLen::N(#len))) } else { - quote!(::tardis::db::sea_orm::sea_query::ColumnType::String(None)) + quote!(::tardis::db::sea_orm::sea_query::ColumnType::String(::tardis::db::sea_orm::sea_query::StringLen::None)) } } "Text" | "text" => { @@ -399,18 +399,16 @@ fn map_custom_type_to_sea_type(custom_column_type: &str, custom_len: Vec, s } "Binary" | "binary" => { if let Some(len) = custom_len.first() { - quote!(::tardis::db::sea_orm::sea_query::ColumnType::Binary(::tardis::db::sea_orm::sea_query::BlobSize::Blob( - Some(#len) - ))) + quote!(::tardis::db::sea_orm::sea_query::ColumnType::Binary(#len)) } else { - quote!(::tardis::db::sea_orm::sea_query::ColumnType::Binary(::tardis::db::sea_orm::sea_query::BlobSize::Blob(None))) + return Err(Error::new(span, "column_type:binary must have custom_len!".to_string())); } } "VarBinary" | "var_binary" => { if let Some(len) = custom_len.first() { - quote!(::tardis::db::sea_orm::sea_query::ColumnType::VarBinary(#len)) + quote!(::tardis::db::sea_orm::sea_query::ColumnType::VarBinary(::tardis::db::sea_orm::sea_query::StringLen::N(#len))) } else { - return Err(Error::new(span, "column_type:var_binary must have custom_len!".to_string())); + quote!(::tardis::db::sea_orm::sea_query::ColumnType::VarBinary(::tardis::db::sea_orm::sea_query::StringLen::None)) } } "Bit" | "bit" => { diff --git a/tardis/Cargo.toml b/tardis/Cargo.toml index b1f9d35..85e0bdb 100644 --- a/tardis/Cargo.toml +++ b/tardis/Cargo.toml @@ -51,7 +51,6 @@ cache = ["futures-util", "redis", "deadpool-redis"] mq = ["futures-util", "lapin", "amq-protocol-types", "async-global-executor"] mail = ["lettre"] os = ["async-trait", "anyhow", "rust-s3", "urlencoding"] -k8s = ["future", "kube", "k8s-openapi"] fs = ["tokio/fs", "tokio/io-util"] process = ["tokio/process"] test = ["testcontainers", "testcontainers-modules"] @@ -61,7 +60,7 @@ tracing = [ "opentelemetry-otlp", "opentelemetry_sdk", "opentelemetry-http", - "poem?/opentelemetry" + "poem?/opentelemetry", ] tokio-console = ["console-subscriber"] tracing-appender = ["dep:tracing-appender"] @@ -74,9 +73,9 @@ opentelemetry-http = ["dep:opentelemetry-http"] # Basic serde = { version = "1", features = ["derive"] } serde_json = { version = "1" } -derive_more = { version = "0.99" } +derive_more = { version = "1", features = ["full"] } nanoid = { version = "0.4" } -base64 = { version = "0.21" } +base64 = { version = "0.22" } hex = { version = "0.4" } lazy_static = { version = "1.4" } rand = { version = "0.8" } @@ -86,9 +85,9 @@ config = { version = "0.13" } regex = { version = "1.5" } url = { version = "2.2", features = ["serde"] } lru = { version = "0.12.0" } -typed-builder = { version = "0.18" } +typed-builder = { version = "0.20" } paste = { version = "1.0" } -urlencoding = { version = "2" , optional = true } +urlencoding = { version = "2", optional = true } # Tokio tokio = { version = "1", features = [ "macros", @@ -97,14 +96,14 @@ tokio = { version = "1", features = [ "time", "sync", ] } -tokio-util = { version = "0.7.10" } +tokio-util = { version = "0.7.12" } # Tardis Macros -tardis-macros = { version = "0.1.0-rc.14", optional = true } +tardis-macros = { workspace = true, optional = true } # Log tracing = { version = "0.1" } tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-appender = { version = "0.2", optional = true } -console-subscriber = { version = "0.2", optional = true } +console-subscriber = { version = "0.4", optional = true } # Tracing tracing-opentelemetry = { version = "0.25", optional = true } opentelemetry = { version = "0.24", default-features = false, features = [ @@ -120,6 +119,8 @@ opentelemetry-otlp = { version = "0.17", features = [ "http-proto", "tls", ], optional = true } +opentelemetry-http = { version = "0.13", optional = true } + # TLS native-tls = { version = "0.2", optional = true } @@ -161,7 +162,7 @@ futures-util = { version = "0.3", optional = true } async-trait = { version = "0.1", optional = true } # RelDB -sea-orm = { version = "0.12", features = [ +sea-orm = { version = "1", features = [ "macros", "runtime-tokio-native-tls", "with-chrono", @@ -187,26 +188,26 @@ poem = { version = "3", features = [ "tempfile", "session", ], optional = true } -poem-grpc = { version = "0.4", optional = true } +poem-grpc = { version = "0.5", optional = true } # Web Client reqwest = { version = "0.12", features = [ "json", "multipart", - "stream" + "stream", ], optional = true } # Websocket Client -tokio-tungstenite = { version = "0.21", features = [ +tokio-tungstenite = { version = "0.24", features = [ "native-tls", ], optional = true } # Redis -redis = { version = "0.24", features = [ +redis = { version = "0.27", features = [ "tokio-comp", "tokio-native-tls-comp", ], optional = true } -deadpool-redis = { version = "0.14", optional = true } +deadpool-redis = { version = "0.18", optional = true } # Rabbit lapin = { version = "2", optional = true } @@ -223,16 +224,12 @@ lettre = { version = "0.11", features = [ # Object Storage # rust-s3 = { version = "0.33", optional = true } -rust-s3 = { version = "0.35.0-alpha.3", optional = true, features = ["no-verify-ssl"] } +rust-s3 = { version = "0.35.1", optional = true, features = [ + "no-verify-ssl", +] } # rust-s3 = { path = "../../rust-s3/s3", optional = true } anyhow = { version = "1.0", optional = true } -# K8s -kube = { version = "^0.87", features = ["runtime"], optional = true } -# temporarily fix https://github.com/kube-rs/kube/issues/1486 -json-patch = "=1.2.0" -k8s-openapi = { version = "^0.20", features = ["earliest"], optional = true } - # Test # update this may cause break changes testcontainers = { version = "0.15", optional = true } @@ -243,7 +240,6 @@ testcontainers-modules = { version = "0.3", features = [ # Debug git-version = { version = "0.3.9", optional = true } -opentelemetry-http = { version = "0.12.0", features = ["tokio"], optional = true } http = "1.1.0" crossbeam = "0.8.4" @@ -257,8 +253,8 @@ tokio = { version = "1", features = [ "process", ] } criterion = { version = "0.5" } -poem-grpc-build = "0.4" -prost = "0.13.1" +poem-grpc-build = "0.5" +prost = "0.13.3" strip-ansi-escapes = "0.2.0" portpicker = "0.1.1" # macros diff --git a/tardis/README.md b/tardis/README.md index 9c01f56..ff4437e 100644 --- a/tardis/README.md +++ b/tardis/README.md @@ -51,8 +51,6 @@ * ``tracing`` open telemetry support * ``tokio-console`` console subscriber layer supported by [tokio-console](https://github.com/tokio-rs/console) * ``tracing-appender`` write log into file periodically. -* ``cluster`` work with tardis cluster -* ``k8s`` k8s support for cluster * ``build-info`` get build info like package version or git version ## 🚀 Quick start @@ -117,14 +115,6 @@ async fn main() -> TardisResult<()> { Ok(()) } ``` -### Run with cluster mode -You can enable cluster mode when it has multi nodes, especially when it comes to k8s. -```toml -[fw.cluster] -watch_kind = "k8s" -k8s_svc = "my-service" -k8s_ns = "my-namespace" -``` ### Dependencies diff --git a/tardis/src/basic/error.rs b/tardis/src/basic/error.rs index b981b62..da902f9 100644 --- a/tardis/src/basic/error.rs +++ b/tardis/src/basic/error.rs @@ -249,10 +249,3 @@ impl From for TardisError { TardisError::internal_error(&format!("[Tardis.Basic] {error}"), "") } } - -#[cfg(feature = "k8s")] -impl From for TardisError { - fn from(error: kube::Error) -> Self { - TardisError::internal_error(&format!("[Tardis.Basic] {error}"), "") - } -} diff --git a/tardis/src/config/config_nacos/nacos_client.rs b/tardis/src/config/config_nacos/nacos_client.rs index 7b7658a..f66c0c9 100644 --- a/tardis/src/config/config_nacos/nacos_client.rs +++ b/tardis/src/config/config_nacos/nacos_client.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, fmt::Display, io::Read, sync::Arc}; +use std::{collections::HashMap, io::Read, sync::Arc}; use derive_more::Display; // use futures::TryFutureExt; @@ -188,7 +188,7 @@ impl NacosClient { async fn listen_config_inner(&self, params: &T) -> Result { let resp = self .reqwest_client - .post(&format!("{}/v1/cs/configs/listener", self.base_url)) + .post(format!("{}/v1/cs/configs/listener", self.base_url)) // refer: https://nacos.io/zh-cn/docs/open-api.html // doc says it's `pulling` instead of `polling` .header("Long-Pulling-Timeout", self.poll_period.as_millis().to_string()) diff --git a/tardis/src/db/reldb_client.rs b/tardis/src/db/reldb_client.rs index 04c83fe..ba6e1a5 100644 --- a/tardis/src/db/reldb_client.rs +++ b/tardis/src/db/reldb_client.rs @@ -179,7 +179,7 @@ impl TardisRelDBClient { raw_opt = raw_opt.log_statements(opt.get_sqlx_logging_level()); } let result = opt - .pool_options::() + .sqlx_pool_options::() .after_connect(move |conn, _| { let timezone = timezone.clone(); Box::pin(async move { @@ -207,7 +207,7 @@ impl TardisRelDBClient { raw_opt = raw_opt.disable_statement_logging(); } let result = opt - .pool_options::() + .sqlx_pool_options::() .after_connect(move |conn, _| { let timezone = timezone.clone(); Box::pin(async move { diff --git a/tardis/src/os/os_client.rs b/tardis/src/os/os_client.rs index 6e1c4d8..3e3cbfe 100644 --- a/tardis/src/os/os_client.rs +++ b/tardis/src/os/os_client.rs @@ -19,7 +19,7 @@ pub struct TardisOSClient { struct TardisOSS3Client { region: Region, credentials: Credentials, - default_bucket: Option, + default_bucket: Option>, } #[async_trait::async_trait] @@ -372,7 +372,7 @@ impl TardisOSOperations for TardisOSS3Client { } impl TardisOSS3Client { - fn get_bucket(&self, bucket_name: Option<&str>) -> TardisResult { + fn get_bucket(&self, bucket_name: Option<&str>) -> TardisResult> { if let Some(bucket_name) = bucket_name { Ok(*Bucket::new(bucket_name, self.region.clone(), self.credentials.clone())?.with_path_style()) } else { diff --git a/tardis/src/utils/tardis_component.rs b/tardis/src/utils/tardis_component.rs index 3616426..d68731d 100644 --- a/tardis/src/utils/tardis_component.rs +++ b/tardis/src/utils/tardis_component.rs @@ -33,7 +33,7 @@ pub struct TardisComponentInner { inner: RwLock>, } -impl Deref for TardisComponent { +impl Deref for TardisComponent { type Target = TardisComponentInner; fn deref(&self) -> &Self::Target { self.0.get_or_init(Default::default) diff --git a/tardis/src/web/ws_client.rs b/tardis/src/web/ws_client.rs index d77f3f0..2687ace 100644 --- a/tardis/src/web/ws_client.rs +++ b/tardis/src/web/ws_client.rs @@ -71,10 +71,10 @@ impl TardisWSClient { url.port().unwrap_or(0) ); let connect = if url.scheme() != "wss" { - tokio_tungstenite::connect_async(url.clone()).await + tokio_tungstenite::connect_async(url.to_string()).await } else { tokio_tungstenite::connect_async_tls_with_config( - url.clone(), + url.to_string(), None, false, Some(Connector::NativeTls(TlsConnector::builder().danger_accept_invalid_certs(true).build().map_err(|e| { diff --git a/tardis/tests/macros_test_all.rs b/tardis/tests/macros_test_all.rs index 9e3cd98..7c88377 100644 --- a/tardis/tests/macros_test_all.rs +++ b/tardis/tests/macros_test_all.rs @@ -1,6 +1,6 @@ -// #[test] -// fn test_all() { -// let t = trybuild::TestCases::new(); -// t.pass("tests/macros_tests/pass_cases/*.rs"); -// t.compile_fail("tests/macros_tests/fail_cases/*.rs"); -// } +#[test] +fn test_all() { + let t = trybuild::TestCases::new(); + t.pass("tests/macros_tests/pass_cases/*.rs"); + // t.compile_fail("tests/macros_tests/fail_cases/*.rs"); +} diff --git a/tardis/tests/macros_tests/pass_cases/auto_fill_ctx_test.rs b/tardis/tests/macros_tests/pass_cases/auto_fill_ctx_test.rs index 4d98e3c..a0e819b 100644 --- a/tardis/tests/macros_tests/pass_cases/auto_fill_ctx_test.rs +++ b/tardis/tests/macros_tests/pass_cases/auto_fill_ctx_test.rs @@ -9,7 +9,7 @@ use tardis::{TardisCreateEntity, TardisEmptyBehavior, TardisEmptyRelation}; pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, - #[fill_ctx(own_paths)] + #[fill_ctx(fill = "own_paths")] pub auto_fill_ctx: String, } diff --git a/tardis/tests/macros_tests/pass_cases/common_type_test.rs b/tardis/tests/macros_tests/pass_cases/common_type_test.rs index 0661fc8..d6529c3 100644 --- a/tardis/tests/macros_tests/pass_cases/common_type_test.rs +++ b/tardis/tests/macros_tests/pass_cases/common_type_test.rs @@ -3,6 +3,7 @@ use tardis::chrono::Utc; use tardis::db::reldb_client::TardisActiveModel; use tardis::db::sea_orm; use tardis::db::sea_orm::sea_query::IndexCreateStatement; +use tardis::db::sea_orm::sea_query::StringLen; use tardis::db::sea_orm::*; use tardis::serde_json::{self, Value}; use tardis::{chrono, TardisCreateEntity, TardisEmptyBehavior, TardisEmptyRelation}; @@ -23,9 +24,9 @@ pub struct Model { pub number64: i64, pub number_f32: f32, pub number_f64: f64, - pub be_binary: Vec, + pub be_var_binary: Vec, #[tardis_entity(custom_len = "50")] - pub be_option_50_binary: Option>, + pub be_option_50_var_binary: Option>, #[index] pub be_bool: bool, #[index(full_text, index_id = "index_id_3")] @@ -53,7 +54,7 @@ pub struct Model { // pub be_vec_custom: Vec, // pub be_option_vec_custom: Option>, #[index(index_id = "index_id_2", index_type = "Custom(GiST)", full_text)] - #[fill_ctx(own_paths)] + #[fill_ctx(fill = "own_paths")] pub aaa: String, } @@ -82,31 +83,31 @@ fn main() { let table_cols: &Vec<_> = create_table_statement.get_columns(); assert_eq!(table_cols.len(), 24); - let find_id: Vec<_> = table_cols.iter().filter(|col| col.get_column_name() == "id" && col.get_column_type() == Some(&ColumnType::String(None))).collect(); + let find_id: Vec<_> = table_cols.iter().filter(|col| col.get_column_name() == "id" && col.get_column_type() == Some(&ColumnType::String(StringLen::None))).collect(); assert_eq!(find_id.len(), 1); let find_id: Vec<_> = table_cols.iter().filter(|col| col.get_column_name() == "number8" && col.get_column_type() == Some(&ColumnType::TinyInteger)).collect(); assert_eq!(find_id.len(), 1); let find_id: Vec<_> = - table_cols.iter().filter(|col| col.get_column_name() == "be_binary" && col.get_column_type() == Some(&ColumnType::Binary(sea_query::BlobSize::Blob(None)))).collect(); + table_cols.iter().filter(|col| col.get_column_name() == "be_var_binary" && col.get_column_type() == Some(&ColumnType::VarBinary(StringLen::None))).collect(); assert_eq!(find_id.len(), 1); - let find_id: Vec<_> = table_cols - .iter() - .filter(|col| col.get_column_name() == "be_option_50_binary" && col.get_column_type() == Some(&ColumnType::Binary(sea_query::BlobSize::Blob(Some(50))))) - .collect(); + let find_id: Vec<_> = + table_cols.iter().filter(|col| col.get_column_name() == "be_option_50_var_binary" && col.get_column_type() == Some(&ColumnType::VarBinary(StringLen::N(50)))).collect(); assert_eq!(find_id.len(), 1); let find_id: Vec<_> = table_cols .iter() - .filter(|col| col.get_column_name() == "be_custom_array_string" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(Some(50)))))) + .filter(|col| { + col.get_column_name() == "be_custom_array_string" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(StringLen::N(50))))) + }) .collect(); assert_eq!(find_id.len(), 1); let find_id: Vec<_> = table_cols .iter() - .filter(|col| col.get_column_name() == "be_vec_text" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(None))))) + .filter(|col| col.get_column_name() == "be_vec_text" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(StringLen::None))))) .collect(); assert_eq!(find_id.len(), 1); let find_id: Vec<_> = table_cols .iter() - .filter(|col| col.get_column_name() == "be_option_vec_text" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(Some(50)))))) + .filter(|col| col.get_column_name() == "be_option_vec_text" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(StringLen::N(50)))))) .collect(); assert_eq!(find_id.len(), 1);