diff --git a/examples/axum-app/app/Cargo.toml b/examples/axum-app/app/Cargo.toml index caac386..b046f31 100644 --- a/examples/axum-app/app/Cargo.toml +++ b/examples/axum-app/app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axum-app" -version = "0.3.1" +version = "0.4.0" rust-version = "1.68" edition = "2021" publish = false @@ -12,13 +12,9 @@ tracing = { version = "0.1.37" } [dependencies.zino] path = "../../../zino" -version = "0.3.1" -features = ["axum-server"] - -[dependencies.zino-core] -path = "../../../zino-core" -version = "0.3.1" +version = "0.4.0" +features = ["axum"] [dependencies.zino-model] path = "../../../zino-model" -version = "0.3.1" +version = "0.3.2" diff --git a/examples/axum-app/app/src/controller/stats.rs b/examples/axum-app/app/src/controller/stats.rs index 10ac619..9ee9423 100644 --- a/examples/axum-app/app/src/controller/stats.rs +++ b/examples/axum-app/app/src/controller/stats.rs @@ -1,6 +1,5 @@ use serde_json::json; -use zino::Request; -use zino_core::{RequestContext, Response}; +use zino::{Request, RequestContext, Response}; pub(crate) async fn index(req: Request) -> zino::Result { let mut res = Response::default(); diff --git a/examples/axum-app/app/src/controller/user.rs b/examples/axum-app/app/src/controller/user.rs index a80f321..8fa0dc7 100644 --- a/examples/axum-app/app/src/controller/user.rs +++ b/examples/axum-app/app/src/controller/user.rs @@ -1,6 +1,8 @@ use serde_json::json; -use zino::{AxumCluster, Request}; -use zino_core::{Application, Model, Query, Rejection, RequestContext, Response, Schema, Uuid}; +use zino::{ + Application, AxumCluster, Model, Query, Rejection, Request, RequestContext, Response, Schema, + Uuid, +}; use zino_model::User; pub(crate) async fn new(mut req: Request) -> zino::Result { diff --git a/examples/axum-app/app/src/main.rs b/examples/axum-app/app/src/main.rs index 9ea3bfb..c729411 100644 --- a/examples/axum-app/app/src/main.rs +++ b/examples/axum-app/app/src/main.rs @@ -2,7 +2,7 @@ mod controller; mod router; mod schedule; -use zino_core::Application; +use zino::Application; fn main() { zino::AxumCluster::new() diff --git a/examples/axum-app/app/src/schedule/job.rs b/examples/axum-app/app/src/schedule/job.rs index c064ac0..0f8d9fb 100644 --- a/examples/axum-app/app/src/schedule/job.rs +++ b/examples/axum-app/app/src/schedule/job.rs @@ -1,4 +1,4 @@ -use zino_core::{BoxFuture, DateTime, Map, Query, Schema, Uuid}; +use zino::{BoxFuture, DateTime, Map, Query, Schema, Uuid}; use zino_model::User; pub(super) fn every_15s(job_id: Uuid, job_data: &mut Map, _last_tick: DateTime) { diff --git a/examples/axum-app/app/src/schedule/mod.rs b/examples/axum-app/app/src/schedule/mod.rs index c2165c1..9d9ad9f 100644 --- a/examples/axum-app/app/src/schedule/mod.rs +++ b/examples/axum-app/app/src/schedule/mod.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use zino_core::{AsyncCronJob, CronJob}; +use zino::{AsyncCronJob, CronJob}; mod job; diff --git a/examples/axum-app/config/config.dev.toml b/examples/axum-app/config/config.dev.toml index 72d1601..bf1e5c8 100644 --- a/examples/axum-app/config/config.dev.toml +++ b/examples/axum-app/config/config.dev.toml @@ -1,6 +1,6 @@ name = "data-cube" -version = "0.3.1" +version = "0.4.0" [main] host = "127.0.0.1" diff --git a/examples/axum-app/config/config.prod.toml b/examples/axum-app/config/config.prod.toml index d766aaf..932e56e 100644 --- a/examples/axum-app/config/config.prod.toml +++ b/examples/axum-app/config/config.prod.toml @@ -1,6 +1,6 @@ name = "data-cube" -version = "0.3.1" +version = "0.4.0" [main] host = "127.0.0.1" @@ -27,7 +27,7 @@ username = "postgres" password = "G76hTg8T5Aa+SZQFc+0QnsRLo1UOjqpkp/jUQ+lySc8QCt4B" [tracing] -filter = "info,sqlx=warn" +filter = "info,sqlx=warn,tower_http=warn" [metrics] exporter = "prometheus" diff --git a/zino-core/Cargo.toml b/zino-core/Cargo.toml index aec58ca..7e76bc4 100644 --- a/zino-core/Cargo.toml +++ b/zino-core/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zino-core" description = "Core types and traits for zino." -version = "0.3.1" +version = "0.4.0" rust-version = "1.68" edition = "2021" license = "MIT" diff --git a/zino-core/src/application.rs b/zino-core/src/application.rs index 570472f..fe9f488 100644 --- a/zino-core/src/application.rs +++ b/zino-core/src/application.rs @@ -1,4 +1,10 @@ -use crate::{AsyncCronJob, CronJob, Job, JobScheduler, Map, State}; +//! Application trait. + +use crate::{ + schedule::{AsyncCronJob, CronJob, Job, JobScheduler}, + state::State, + Map, +}; use metrics_exporter_prometheus::{Matcher, PrometheusBuilder}; use metrics_exporter_tcp::TcpBuilder; use std::{ diff --git a/zino-core/src/authentication/mod.rs b/zino-core/src/authentication/mod.rs index 3ecc361..5c1c192 100644 --- a/zino-core/src/authentication/mod.rs +++ b/zino-core/src/authentication/mod.rs @@ -1,4 +1,6 @@ -use crate::{DateTime, Map, Validation}; +//! Access keys and security tokens. + +use crate::{datetime::DateTime, request::Validation, Map}; use hmac::{ digest::{FixedOutput, KeyInit, MacMarker, Update}, Mac, @@ -8,9 +10,8 @@ use std::time::Duration; mod access_key; mod security_token; -// Rexports. pub use access_key::{AccessKeyId, SecretAccessKey}; -pub(crate) use security_token::ParseTokenError; +pub(super) use security_token::ParseTokenError; pub use security_token::SecurityToken; /// HTTP signature using HMAC. diff --git a/zino-core/src/authentication/security_token.rs b/zino-core/src/authentication/security_token.rs index 0f4a063..ce31b71 100644 --- a/zino-core/src/authentication/security_token.rs +++ b/zino-core/src/authentication/security_token.rs @@ -1,4 +1,4 @@ -use crate::{crypto, AccessKeyId, DateTime}; +use crate::{authentication::AccessKeyId, crypto, datetime::DateTime}; use std::fmt; /// An error which can be returned when parsing a token. diff --git a/zino-core/src/cache.rs b/zino-core/src/cache.rs index 2722b6a..a9bf70c 100644 --- a/zino-core/src/cache.rs +++ b/zino-core/src/cache.rs @@ -1,10 +1,11 @@ +//! Global cache for the application. + use lru::LruCache; use parking_lot::RwLock; use serde_json::Value; use std::{num::NonZeroUsize, sync::LazyLock}; -/// Global cache for the application. -/// See the docs for [LruCache](https://docs.rs/lru/latest/lru/struct.LruCache.html). +/// Global cache based on [LruCache](https://docs.rs/lru/latest/lru/struct.LruCache.html). #[derive(Debug, Clone, Copy, Default)] pub struct GlobalCache; diff --git a/zino-core/src/channel/cloud_event.rs b/zino-core/src/channel/cloud_event.rs index 63280e9..df29679 100644 --- a/zino-core/src/channel/cloud_event.rs +++ b/zino-core/src/channel/cloud_event.rs @@ -1,4 +1,4 @@ -use crate::{DateTime, Map}; +use crate::{datetime::DateTime, Map}; use serde::{Deserialize, Serialize}; use serde_json::Value; diff --git a/zino-core/src/channel/mod.rs b/zino-core/src/channel/mod.rs index d94f6c0..800c9a6 100644 --- a/zino-core/src/channel/mod.rs +++ b/zino-core/src/channel/mod.rs @@ -1,6 +1,7 @@ +//! Cloud events and subscriptions. + mod cloud_event; mod subscription; -// Reexports. pub use cloud_event::CloudEvent; pub use subscription::Subscription; diff --git a/zino-core/src/database/mod.rs b/zino-core/src/database/mod.rs index 78aef9c..5cf0c9b 100644 --- a/zino-core/src/database/mod.rs +++ b/zino-core/src/database/mod.rs @@ -1,3 +1,5 @@ +//! Connection pool and ORM. + use crate::{crypto, state::SHARED_STATE}; use sqlx::{ postgres::{PgConnectOptions, PgPoolOptions}, @@ -12,7 +14,6 @@ mod mutation; mod query; mod schema; -// Reexports. pub use column::Column; pub use model::Model; pub use mutation::Mutation; diff --git a/zino-core/src/database/model.rs b/zino-core/src/database/model.rs index 9b64d7a..b8d9bfb 100644 --- a/zino-core/src/database/model.rs +++ b/zino-core/src/database/model.rs @@ -1,4 +1,4 @@ -use crate::{Map, Validation}; +use crate::{request::Validation, Map}; use serde::{de::DeserializeOwned, Serialize}; use serde_json::{Error, Value}; diff --git a/zino-core/src/database/mutation.rs b/zino-core/src/database/mutation.rs index 03e3aa2..cb1d15c 100644 --- a/zino-core/src/database/mutation.rs +++ b/zino-core/src/database/mutation.rs @@ -1,4 +1,4 @@ -use crate::{Map, Schema, Validation}; +use crate::{database::Schema, request::Validation, Map}; #[derive(Debug, Clone, Default)] /// SQL mutation builder. diff --git a/zino-core/src/database/query.rs b/zino-core/src/database/query.rs index 6e0950d..ad4cf9b 100644 --- a/zino-core/src/database/query.rs +++ b/zino-core/src/database/query.rs @@ -1,4 +1,8 @@ -use crate::{Column, Map, Schema, Validation}; +use crate::{ + database::{Column, Schema}, + request::Validation, + Map, +}; use serde_json::Value; #[derive(Debug, Clone, Default)] diff --git a/zino-core/src/database/schema.rs b/zino-core/src/database/schema.rs index 6ada567..ffe326b 100644 --- a/zino-core/src/database/schema.rs +++ b/zino-core/src/database/schema.rs @@ -1,4 +1,8 @@ -use crate::{Column, ConnectionPool, Map, Model, Mutation, Query, Validation}; +use crate::{ + database::{Column, ConnectionPool, Model, Mutation, Query}, + request::Validation, + Map, +}; use futures::TryStreamExt; use serde::de::DeserializeOwned; use serde_json::json; diff --git a/zino-core/src/datetime.rs b/zino-core/src/datetime.rs index 387e1ff..484e01d 100644 --- a/zino-core/src/datetime.rs +++ b/zino-core/src/datetime.rs @@ -1,3 +1,5 @@ +//! ISO 8601 combined date and time with local time zone. + use chrono::{ format::{ParseError, ParseResult}, Local, NaiveDateTime, SecondsFormat, TimeZone, Utc, @@ -11,7 +13,7 @@ use std::{ time::Duration, }; -/// ISO 8601 combined date and time with local time zone. +/// A wrapper type for `chrono::DateTime`. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] pub struct DateTime(chrono::DateTime); diff --git a/zino-core/src/lib.rs b/zino-core/src/lib.rs index 7b3c926..ac6e27d 100644 --- a/zino-core/src/lib.rs +++ b/zino-core/src/lib.rs @@ -11,29 +11,17 @@ #![feature(type_alias_impl_trait)] #![forbid(unsafe_code)] -mod application; -mod authentication; -mod cache; -mod channel; -mod crypto; -mod database; -mod datetime; -mod request; -mod response; -mod schedule; -mod state; - -// Reexports. -pub use application::Application; -pub use authentication::{AccessKeyId, Authentication, SecretAccessKey, SecurityToken}; -pub use cache::GlobalCache; -pub use channel::{CloudEvent, Subscription}; -pub use database::{Column, ConnectionPool, Model, Mutation, Query, Schema}; -pub use datetime::DateTime; -pub use request::{Context, RequestContext, Validation}; -pub use response::{Rejection, Response, ResponseCode}; -pub use schedule::{AsyncCronJob, CronJob, Job, JobScheduler}; -pub use state::State; +pub mod application; +pub mod authentication; +pub mod cache; +pub mod channel; +pub mod crypto; +pub mod database; +pub mod datetime; +pub mod request; +pub mod response; +pub mod schedule; +pub mod state; /// A JSON key/value type. pub type Map = serde_json::Map; diff --git a/zino-core/src/request/mod.rs b/zino-core/src/request/mod.rs index 1a971d5..ea53c1a 100644 --- a/zino-core/src/request/mod.rs +++ b/zino-core/src/request/mod.rs @@ -1,6 +1,12 @@ +//! Request context and validation. + use crate::{ - authentication::ParseTokenError, Authentication, CloudEvent, DateTime, Map, Model, Query, - Rejection, Response, ResponseCode, SecurityToken, Subscription, Uuid, + authentication::{Authentication, ParseTokenError, SecurityToken}, + channel::{CloudEvent, Subscription}, + database::{Model, Query}, + datetime::DateTime, + response::{Rejection, Response, ResponseCode}, + Map, Uuid, }; use http::uri::Uri; use http_types::{trace::TraceContext, Trailers}; @@ -13,7 +19,6 @@ use toml::value::Table; mod context; mod validation; -// Reexports. pub use context::Context; pub use validation::Validation; diff --git a/zino-core/src/request/validation.rs b/zino-core/src/request/validation.rs index 1f78bc9..69f2cf4 100644 --- a/zino-core/src/request/validation.rs +++ b/zino-core/src/request/validation.rs @@ -1,4 +1,4 @@ -use crate::{DateTime, Map, Response}; +use crate::{datetime::DateTime, response::Response, Map}; use bytes::Bytes; use http_body::Full; use serde_json::Value; diff --git a/zino-core/src/response/mod.rs b/zino-core/src/response/mod.rs index be1b0bf..3956c62 100644 --- a/zino-core/src/response/mod.rs +++ b/zino-core/src/response/mod.rs @@ -1,4 +1,9 @@ -use crate::{RequestContext, SharedString, Uuid, Validation}; +//! Constructing responses and rejections. + +use crate::{ + request::{RequestContext, Validation}, + SharedString, Uuid, +}; use bytes::Bytes; use http::header::{self, HeaderValue}; use http_body::Full; @@ -13,7 +18,6 @@ use std::{ mod rejection; -// Reexports. pub use rejection::Rejection; /// Response code. diff --git a/zino-core/src/response/rejection.rs b/zino-core/src/response/rejection.rs index 64ee803..1330561 100644 --- a/zino-core/src/response/rejection.rs +++ b/zino-core/src/response/rejection.rs @@ -1,4 +1,4 @@ -use crate::{BoxError, Response, Validation}; +use crate::{request::Validation, response::Response, BoxError}; use bytes::Bytes; use http_body::Full; use std::{error, fmt}; diff --git a/zino-core/src/schedule/mod.rs b/zino-core/src/schedule/mod.rs index 4c053da..efb85d2 100644 --- a/zino-core/src/schedule/mod.rs +++ b/zino-core/src/schedule/mod.rs @@ -1,4 +1,6 @@ -use crate::{BoxFuture, DateTime, Map, Uuid}; +//! Scheduler for sync and async cron jobs. + +use crate::{datetime::DateTime, BoxFuture, Map, Uuid}; use chrono::Local; use cron::Schedule; use std::{str::FromStr, time::Duration}; diff --git a/zino-core/src/state.rs b/zino-core/src/state.rs index f29b6f4..b12cfc2 100644 --- a/zino-core/src/state.rs +++ b/zino-core/src/state.rs @@ -1,3 +1,5 @@ +//! Application state. + use crate::Map; use std::{ env, fs, diff --git a/zino-derive/Cargo.toml b/zino-derive/Cargo.toml index e51d6ee..45811f2 100644 --- a/zino-derive/Cargo.toml +++ b/zino-derive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zino-derive" description = "Derived traits for zino." -version = "0.3.1" +version = "0.3.2" rust-version = "1.68" edition = "2021" license = "MIT" @@ -20,4 +20,4 @@ syn = { version = "1.0.107", features = ["full", "extra-traits"] } [dependencies.zino-core] path = "../zino-core" -version = "0.3.1" +version = "0.4.0" diff --git a/zino-derive/src/lib.rs b/zino-derive/src/lib.rs index 8469f98..e37ad28 100644 --- a/zino-derive/src/lib.rs +++ b/zino-derive/src/lib.rs @@ -99,7 +99,7 @@ pub fn schema_macro(item: TokenStream) -> TokenStream { None => quote! { None }, }; let column = quote! { - zino_core::Column::new(#name, #type_name, #quote_value, #not_null, #quote_index) + zino_core::database::Column::new(#name, #type_name, #quote_value, #not_null, #quote_index) }; columns.push(column); } @@ -114,14 +114,15 @@ pub fn schema_macro(item: TokenStream) -> TokenStream { let columns_len = columns.len(); let output = quote! { use std::sync::{LazyLock, OnceLock}; + use zino_core::database::{Column, ConnectionPool, Schema}; - static #schema_columns: LazyLock<[zino_core::Column; #columns_len]> = LazyLock::new(|| { + static #schema_columns: LazyLock<[Column; #columns_len]> = LazyLock::new(|| { [#(#columns),*] }); - static #schema_reader: OnceLock<&zino_core::ConnectionPool> = OnceLock::new(); - static #schema_writer: OnceLock<&zino_core::ConnectionPool> = OnceLock::new(); + static #schema_reader: OnceLock<&ConnectionPool> = OnceLock::new(); + static #schema_writer: OnceLock<&ConnectionPool> = OnceLock::new(); - impl zino_core::Schema for #name { + impl Schema for #name { /// Type name as a str. const TYPE_NAME: &'static str = #type_name_lowercase; /// Primary key name as a str. @@ -133,8 +134,8 @@ pub fn schema_macro(item: TokenStream) -> TokenStream { /// Returns a reference to the columns. #[inline] - fn columns() -> &'static [zino_core::Column<'static>] { - std::sync::LazyLock::force(&#schema_columns).as_slice() + fn columns() -> &'static [Column<'static>] { + LazyLock::force(&#schema_columns).as_slice() } /// Returns the primary key value as a `String`. @@ -144,7 +145,7 @@ pub fn schema_macro(item: TokenStream) -> TokenStream { } /// Gets the model reader. - async fn get_reader() -> Option<&'static zino_core::ConnectionPool> { + async fn get_reader() -> Option<&'static ConnectionPool> { match #schema_reader.get() { Some(connection_pool) => Some(*connection_pool), None => { @@ -158,7 +159,7 @@ pub fn schema_macro(item: TokenStream) -> TokenStream { } /// Gets the model writer. - async fn get_writer() -> Option<&'static zino_core::ConnectionPool> { + async fn get_writer() -> Option<&'static ConnectionPool> { match #schema_writer.get() { Some(connection_pool) => Some(*connection_pool), None => { @@ -172,14 +173,14 @@ pub fn schema_macro(item: TokenStream) -> TokenStream { } } - impl std::cmp::PartialEq for #name { + impl PartialEq for #name { #[inline] fn eq(&self, other: &Self) -> bool { self.#schema_primary_key == other.#schema_primary_key } } - impl std::cmp::Eq for #name {} + impl Eq for #name {} }; TokenStream::from(output) diff --git a/zino-model/Cargo.toml b/zino-model/Cargo.toml index aa5dca2..893e82f 100644 --- a/zino-model/Cargo.toml +++ b/zino-model/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zino-model" description = "Model types for zino." -version = "0.3.1" +version = "0.3.2" rust-version = "1.68" edition = "2021" license = "MIT" @@ -15,8 +15,8 @@ serde = { version = "1.0.152", features = ["derive"] } [dependencies.zino-core] path = "../zino-core" -version = "0.3.1" +version = "0.4.0" [dependencies.zino-derive] path = "../zino-derive" -version = "0.3.1" \ No newline at end of file +version = "0.3.2" \ No newline at end of file diff --git a/zino-model/src/collection.rs b/zino-model/src/collection.rs index 1e11a63..c1fca93 100644 --- a/zino-model/src/collection.rs +++ b/zino-model/src/collection.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The collection model. diff --git a/zino-model/src/dataset.rs b/zino-model/src/dataset.rs index 8715ff5..dda9838 100644 --- a/zino-model/src/dataset.rs +++ b/zino-model/src/dataset.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The dataset model. diff --git a/zino-model/src/group.rs b/zino-model/src/group.rs index a301dcc..6fd4bfd 100644 --- a/zino-model/src/group.rs +++ b/zino-model/src/group.rs @@ -1,6 +1,6 @@ use crate::User; use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The group model. diff --git a/zino-model/src/lib.rs b/zino-model/src/lib.rs index fcf6696..d7e8cdd 100644 --- a/zino-model/src/lib.rs +++ b/zino-model/src/lib.rs @@ -23,7 +23,6 @@ mod task; mod log; mod record; -// Reexports. pub use group::Group; pub use policy::Policy; pub use resource::Resource; diff --git a/zino-model/src/log.rs b/zino-model/src/log.rs index b9529bc..9584e9e 100644 --- a/zino-model/src/log.rs +++ b/zino-model/src/log.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The log model. diff --git a/zino-model/src/message.rs b/zino-model/src/message.rs index 84cc08c..13d849e 100644 --- a/zino-model/src/message.rs +++ b/zino-model/src/message.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The message model. diff --git a/zino-model/src/order.rs b/zino-model/src/order.rs index 5f480c8..87d7ef4 100644 --- a/zino-model/src/order.rs +++ b/zino-model/src/order.rs @@ -1,6 +1,6 @@ use crate::Resource; use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The order model. diff --git a/zino-model/src/policy.rs b/zino-model/src/policy.rs index 195921b..62dfde1 100644 --- a/zino-model/src/policy.rs +++ b/zino-model/src/policy.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The policy model. diff --git a/zino-model/src/record.rs b/zino-model/src/record.rs index f1b3fa2..3d6683d 100644 --- a/zino-model/src/record.rs +++ b/zino-model/src/record.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The record model. diff --git a/zino-model/src/resource.rs b/zino-model/src/resource.rs index eb794dc..b85fcc9 100644 --- a/zino-model/src/resource.rs +++ b/zino-model/src/resource.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The resource model. diff --git a/zino-model/src/source.rs b/zino-model/src/source.rs index e06396b..7a53adc 100644 --- a/zino-model/src/source.rs +++ b/zino-model/src/source.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The source model. diff --git a/zino-model/src/tag.rs b/zino-model/src/tag.rs index 7d66027..3a2465f 100644 --- a/zino-model/src/tag.rs +++ b/zino-model/src/tag.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The tag model. diff --git a/zino-model/src/task.rs b/zino-model/src/task.rs index fabd5ca..8493d8a 100644 --- a/zino-model/src/task.rs +++ b/zino-model/src/task.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use zino_core::{DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid}; use zino_derive::Schema; /// The task model. diff --git a/zino-model/src/user.rs b/zino-model/src/user.rs index cef1206..bc4a699 100644 --- a/zino-model/src/user.rs +++ b/zino-model/src/user.rs @@ -1,5 +1,8 @@ use serde::{Deserialize, Serialize}; -use zino_core::{AccessKeyId, DateTime, Map, Model, Schema, Uuid, Validation}; +use zino_core::{ + authentication::AccessKeyId, database::Model, datetime::DateTime, request::Validation, Map, + Uuid, +}; use zino_derive::Schema; /// The user model. diff --git a/zino/Cargo.toml b/zino/Cargo.toml index 230a748..218e68c 100644 --- a/zino/Cargo.toml +++ b/zino/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zino" description = "Full featured web application framework for Rust." -version = "0.3.1" +version = "0.4.0" rust-version = "1.68" edition = "2021" license = "MIT" @@ -13,13 +13,10 @@ documentation = "https://docs.rs/zino" readme = "README.md" [features] -default = ["axum-server"] -axum-server = ["dep:axum", "dep:tokio", "dep:tokio-stream", "dep:tower", "dep:tower-http"] +axum = ["dep:axum", "dep:tokio", "dep:tokio-stream", "dep:tower", "dep:tower-http"] [dependencies] async-trait = { version = "0.1.60" } -axum = { version = "0.6.1", features = ["ws"], optional = true } -cfg-if = { version = "1.0.0" } futures = { version = "0.3.25" } http-types = { version = "2.12.0" } hyper = { version = "0.14.23" } @@ -28,13 +25,16 @@ serde = { version = "1.0.152", features = ["derive"] } serde_json = { version = "1.0.91" } serde_qs = { version = "0.10.1" } serde_urlencoded = { version = "0.7.1" } +toml = { version = "0.5.10" } +tracing = { version = "0.1.37" } + +# optional dependencies +axum = { version = "0.6.1", features = ["ws"], optional = true } tokio = { version = "1.24.1", features = ["rt-multi-thread", "sync", "parking_lot"], optional = true } tokio-stream = { version = "0.1.11", features = ["sync"], optional = true } -toml = { version = "0.5.10" } tower = { version = "0.4.13", features = ["timeout"], optional = true } tower-http = { version = "0.3.5", features = ["full"], optional = true } -tracing = { version = "0.1.37" } [dependencies.zino-core] path = "../zino-core" -version = "0.3.1" \ No newline at end of file +version = "0.4.0" \ No newline at end of file diff --git a/zino/README.md b/zino/README.md index ceb6c07..ad0a1df 100644 --- a/zino/README.md +++ b/zino/README.md @@ -16,7 +16,12 @@ productivity and performance. You can start with the example [`axum-app`]. +## Feature flags + +Currently, we only provide the `axum` feature to enable an integration with [`axum`]. + [`sqlx`]: https://crates.io/crates/sqlx [`tracing`]: https://crates.io/crates/tracing [`metrics`]: https://crates.io/crates/metrics +[`axum`]: https://crates.io/crates/axum [`axum-app`]: https://github.com/photino/zino/tree/main/examples/axum-app \ No newline at end of file diff --git a/zino/src/channel/axum_channel.rs b/zino/src/channel/axum_channel.rs index 3871d31..5cde11a 100644 --- a/zino/src/channel/axum_channel.rs +++ b/zino/src/channel/axum_channel.rs @@ -3,7 +3,11 @@ use parking_lot::RwLock; use std::{collections::HashMap, sync::LazyLock}; use tokio::sync::mpsc::{self, error::TrySendError, Receiver, Sender}; use tokio_stream::wrappers::ReceiverStream; -use zino_core::{Application, CloudEvent, Subscription, Uuid}; +use zino_core::{ + application::Application, + channel::{CloudEvent, Subscription}, + Uuid, +}; /// A emitter is a sender of cloud events. type Emitter = Sender; diff --git a/zino/src/channel/mod.rs b/zino/src/channel/mod.rs index 5f0e74b..68eaa13 100644 --- a/zino/src/channel/mod.rs +++ b/zino/src/channel/mod.rs @@ -1,2 +1,2 @@ -#[cfg(feature = "axum-server")] +#[cfg(feature = "axum")] pub(crate) mod axum_channel; diff --git a/zino/src/cluster/axum_cluster.rs b/zino/src/cluster/axum_cluster.rs index b090fa8..70e2835 100644 --- a/zino/src/cluster/axum_cluster.rs +++ b/zino/src/cluster/axum_cluster.rs @@ -20,7 +20,14 @@ use tower_http::{ compression::CompressionLayer, services::{ServeDir, ServeFile}, }; -use zino_core::{Application, AsyncCronJob, DateTime, Job, JobScheduler, Map, Response, State}; +use zino_core::{ + application::Application, + datetime::DateTime, + response::Response, + schedule::{AsyncCronJob, Job, JobScheduler}, + state::State, + Map, +}; /// An HTTP server cluster for `axum`. pub struct AxumCluster { diff --git a/zino/src/cluster/mod.rs b/zino/src/cluster/mod.rs index f98e2bf..31039c2 100644 --- a/zino/src/cluster/mod.rs +++ b/zino/src/cluster/mod.rs @@ -1,2 +1,2 @@ -#[cfg(feature = "axum-server")] -pub mod axum_cluster; +#[cfg(feature = "axum")] +pub(crate) mod axum_cluster; diff --git a/zino/src/endpoint/axum_sse.rs b/zino/src/endpoint/axum_sse.rs index bb20e29..fc0ee66 100644 --- a/zino/src/endpoint/axum_sse.rs +++ b/zino/src/endpoint/axum_sse.rs @@ -5,7 +5,7 @@ use axum::{ use futures::stream::Stream; use std::convert::Infallible; use tokio_stream::StreamExt; -use zino_core::Subscription; +use zino_core::channel::Subscription; /// SSE endpoint handler. pub(crate) async fn sse_handler( diff --git a/zino/src/endpoint/axum_websocket.rs b/zino/src/endpoint/axum_websocket.rs index ad2e962..56f39d8 100644 --- a/zino/src/endpoint/axum_websocket.rs +++ b/zino/src/endpoint/axum_websocket.rs @@ -5,7 +5,7 @@ use axum::{ }, response::IntoResponse, }; -use zino_core::{CloudEvent, Subscription}; +use zino_core::channel::{CloudEvent, Subscription}; /// WebSocket endpoint handler. pub(crate) async fn websocket_handler( diff --git a/zino/src/endpoint/mod.rs b/zino/src/endpoint/mod.rs index aacb656..9c9061e 100644 --- a/zino/src/endpoint/mod.rs +++ b/zino/src/endpoint/mod.rs @@ -1,6 +1,5 @@ -cfg_if::cfg_if! { - if #[cfg(feature = "axum-server")] { - pub(crate) mod axum_sse; - pub(crate) mod axum_websocket; - } -} +#[cfg(feature = "axum")] +pub(crate) mod axum_sse; + +#[cfg(feature = "axum")] +pub(crate) mod axum_websocket; diff --git a/zino/src/lib.rs b/zino/src/lib.rs index bd8a1fa..ad9bc99 100644 --- a/zino/src/lib.rs +++ b/zino/src/lib.rs @@ -14,13 +14,19 @@ //! //! You can start with the example [`axum-app`]. //! +//! ## Feature flags +//! +//! Currently, we only provide the `axum` feature to enable an integration with [`axum`]. +//! //! [`zino`]: https://github.com/photino/zino //! [`sqlx`]: https://crates.io/crates/sqlx //! [`tracing`]: https://crates.io/crates/tracing //! [`metrics`]: https://crates.io/crates/metrics +//! [`axum`]: https://crates.io/crates/axum //! [`axum-app`]: https://github.com/photino/zino/tree/main/examples/axum-app #![feature(async_fn_in_trait)] +#![feature(doc_auto_cfg)] #![feature(once_cell)] #![feature(result_option_inspect)] #![feature(string_leak)] @@ -32,17 +38,32 @@ mod endpoint; mod middleware; mod request; -cfg_if::cfg_if! { - if #[cfg(feature = "axum-server")] { - // Reexports. - pub use cluster::axum_cluster::AxumCluster; - pub use request::axum_request::AxumExtractor; +#[cfg(feature = "axum")] +pub use cluster::axum_cluster::AxumCluster; - /// A specialized request extractor for `axum`. - pub type Request = AxumExtractor>; +#[cfg(feature = "axum")] +pub use request::axum_request::AxumExtractor; - /// A specialized `Result` type for `axum`. - pub type Result>> = - std::result::Result; - } -} +#[cfg(feature = "axum")] +/// A specialized request extractor for `axum`. +pub type Request = AxumExtractor>; + +#[cfg(feature = "axum")] +/// A specialized `Result` type for `axum`. +pub type Result>> = + std::result::Result; + +#[doc(no_inline)] +pub use zino_core::{ + application::Application, + authentication::{AccessKeyId, Authentication, SecretAccessKey, SecurityToken}, + cache::GlobalCache, + channel::{CloudEvent, Subscription}, + database::{Column, ConnectionPool, Model, Mutation, Query, Schema}, + datetime::DateTime, + request::{Context, RequestContext, Validation}, + response::{Rejection, Response, ResponseCode}, + schedule::{AsyncCronJob, CronJob, Job, JobScheduler}, + state::State, + BoxError, BoxFuture, Map, Uuid, +}; diff --git a/zino/src/middleware/axum_context.rs b/zino/src/middleware/axum_context.rs index 9b13e11..1d536ac 100644 --- a/zino/src/middleware/axum_context.rs +++ b/zino/src/middleware/axum_context.rs @@ -3,7 +3,7 @@ use axum::{ http::{Request, Response, StatusCode}, middleware::Next, }; -use zino_core::RequestContext; +use zino_core::request::RequestContext; pub(crate) async fn request_context( req: Request, diff --git a/zino/src/middleware/mod.rs b/zino/src/middleware/mod.rs index 0e272b4..2f0936c 100644 --- a/zino/src/middleware/mod.rs +++ b/zino/src/middleware/mod.rs @@ -1,7 +1,8 @@ -cfg_if::cfg_if! { - if #[cfg(feature = "axum-server")] { - pub(crate) mod axum_context; - pub(crate) mod tower_cors; - pub(crate) mod tower_tracing; - } -} +#[cfg(feature = "axum")] +pub(crate) mod axum_context; + +#[cfg(feature = "axum")] +pub(crate) mod tower_cors; + +#[cfg(feature = "axum")] +pub(crate) mod tower_tracing; diff --git a/zino/src/middleware/tower_cors.rs b/zino/src/middleware/tower_cors.rs index 0b6a390..6103c40 100644 --- a/zino/src/middleware/tower_cors.rs +++ b/zino/src/middleware/tower_cors.rs @@ -1,6 +1,6 @@ use std::{sync::LazyLock, time::Duration}; use tower_http::cors::{AllowHeaders, AllowMethods, AllowOrigin, CorsLayer, ExposeHeaders}; -use zino_core::Application; +use zino_core::application::Application; // CORS middleware. pub(crate) static CORS_MIDDLEWARE: LazyLock = LazyLock::new(|| { diff --git a/zino/src/request/axum_request.rs b/zino/src/request/axum_request.rs index 391a819..c2d55fd 100644 --- a/zino/src/request/axum_request.rs +++ b/zino/src/request/axum_request.rs @@ -11,7 +11,13 @@ use std::{ ops::{Deref, DerefMut}, }; use toml::value::Table; -use zino_core::{CloudEvent, Context, Map, Rejection, RequestContext, State, Validation}; +use zino_core::{ + channel::CloudEvent, + request::{Context, RequestContext, Validation}, + response::Rejection, + state::State, + Map, +}; /// An HTTP request extractor for `axum`. pub struct AxumExtractor(pub(crate) T); diff --git a/zino/src/request/mod.rs b/zino/src/request/mod.rs index 83c26f5..5d0b805 100644 --- a/zino/src/request/mod.rs +++ b/zino/src/request/mod.rs @@ -1,2 +1,2 @@ -#[cfg(feature = "axum-server")] -pub mod axum_request; +#[cfg(feature = "axum")] +pub(crate) mod axum_request;