mirror of https://github.com/zino-rs/zino
Refactor module structures
This commit is contained in:
parent
975c641f4c
commit
21b323d5a1
|
@ -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"
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -2,7 +2,7 @@ mod controller;
|
|||
mod router;
|
||||
mod schedule;
|
||||
|
||||
use zino_core::Application;
|
||||
use zino::Application;
|
||||
|
||||
fn main() {
|
||||
zino::AxumCluster::new()
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
use zino_core::{AsyncCronJob, CronJob};
|
||||
use zino::{AsyncCronJob, CronJob};
|
||||
|
||||
mod job;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
name = "data-cube"
|
||||
version = "0.3.1"
|
||||
version = "0.4.0"
|
||||
|
||||
[main]
|
||||
host = "127.0.0.1"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{DateTime, Map};
|
||||
use crate::{datetime::DateTime, Map};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Cloud events and subscriptions.
|
||||
|
||||
mod cloud_event;
|
||||
mod subscription;
|
||||
|
||||
// Reexports.
|
||||
pub use cloud_event::CloudEvent;
|
||||
pub use subscription::Subscription;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Map, Validation};
|
||||
use crate::{request::Validation, Map};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde_json::{Error, Value};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Map, Schema, Validation};
|
||||
use crate::{database::Schema, request::Validation, Map};
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
/// SQL mutation builder.
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Local>`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
pub struct DateTime(chrono::DateTime<Local>);
|
||||
|
||||
|
|
|
@ -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<String, serde_json::Value>;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
//! Application state.
|
||||
|
||||
use crate::Map;
|
||||
use std::{
|
||||
env, fs,
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
version = "0.3.2"
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -23,7 +23,6 @@ mod task;
|
|||
mod log;
|
||||
mod record;
|
||||
|
||||
// Reexports.
|
||||
pub use group::Group;
|
||||
pub use policy::Policy;
|
||||
pub use resource::Resource;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
version = "0.4.0"
|
|
@ -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
|
|
@ -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<CloudEvent>;
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#[cfg(feature = "axum-server")]
|
||||
#[cfg(feature = "axum")]
|
||||
pub(crate) mod axum_channel;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#[cfg(feature = "axum-server")]
|
||||
pub mod axum_cluster;
|
||||
#[cfg(feature = "axum")]
|
||||
pub(crate) mod axum_cluster;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<axum::http::Request<axum::body::Body>>;
|
||||
#[cfg(feature = "axum")]
|
||||
pub use request::axum_request::AxumExtractor;
|
||||
|
||||
/// A specialized `Result` type for `axum`.
|
||||
pub type Result<T = axum::http::Response<axum::body::Full<axum::body::Bytes>>> =
|
||||
std::result::Result<T, T>;
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "axum")]
|
||||
/// A specialized request extractor for `axum`.
|
||||
pub type Request = AxumExtractor<axum::http::Request<axum::body::Body>>;
|
||||
|
||||
#[cfg(feature = "axum")]
|
||||
/// A specialized `Result` type for `axum`.
|
||||
pub type Result<T = axum::http::Response<axum::body::Full<axum::body::Bytes>>> =
|
||||
std::result::Result<T, T>;
|
||||
|
||||
#[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,
|
||||
};
|
||||
|
|
|
@ -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<Body>,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<CorsLayer> = LazyLock::new(|| {
|
||||
|
|
|
@ -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<T>(pub(crate) T);
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#[cfg(feature = "axum-server")]
|
||||
pub mod axum_request;
|
||||
#[cfg(feature = "axum")]
|
||||
pub(crate) mod axum_request;
|
||||
|
|
Loading…
Reference in New Issue