Skip to content

Commit

Permalink
Release 0.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
photino committed Oct 25, 2023
1 parent 74e4c05 commit cce64b1
Show file tree
Hide file tree
Showing 36 changed files with 264 additions and 132 deletions.
8 changes: 4 additions & 4 deletions examples/actix-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.13.3"
version = "0.13.4"
features = ["actix"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.14.3"
version = "0.14.4"
features = [
"connector",
"connector-arrow",
Expand All @@ -32,8 +32,8 @@ features = [

[dependencies.zino-derive]
path = "../../zino-derive"
version = "0.11.3"
version = "0.11.4"

[dependencies.zino-model]
path = "../../zino-model"
version = "0.11.3"
version = "0.11.4"
2 changes: 2 additions & 0 deletions examples/actix-app/src/controller/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub async fn new(mut req: Request) -> Result {
"path": req.request_path(),
"user_intro": user_intro,
});
let locale = req.new_cookie("locale".into(), "en-US".into(), None);
res.set_cookie(&locale);
res.set_code(StatusCode::CREATED);
res.set_json_data(data);
Ok(res.into())
Expand Down
8 changes: 4 additions & 4 deletions examples/axum-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.13.3"
version = "0.13.4"
features = ["axum"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.14.3"
version = "0.14.4"
features = [
"crypto-sm",
"orm-mysql",
Expand All @@ -31,8 +31,8 @@ features = [

[dependencies.zino-derive]
path = "../../zino-derive"
version = "0.11.3"
version = "0.11.4"

[dependencies.zino-model]
path = "../../zino-model"
version = "0.11.3"
version = "0.11.4"
2 changes: 2 additions & 0 deletions examples/axum-app/src/controller/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub async fn new(mut req: Request) -> Result {
"path": req.request_path(),
"user_intro": user_intro,
});
let locale = req.new_cookie("locale".into(), "en-US".into(), None);
res.set_cookie(&locale);
res.set_code(StatusCode::CREATED);
res.set_json_data(data);
Ok(res.into())
Expand Down
6 changes: 3 additions & 3 deletions examples/dioxus-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.13.3"
version = "0.13.4"
features = ["dioxus-desktop"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.14.3"
version = "0.14.4"
features = ["orm-sqlite"]

[dependencies.zino-model]
path = "../../zino-model"
version = "0.11.3"
version = "0.11.4"
4 changes: 3 additions & 1 deletion examples/dioxus-desktop/src/service/stargazer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub async fn list_stargazers(per_page: u8, page: usize) -> Result<Vec<Map>, Erro
});
let mut data: Vec<Map> = App::fetch_json(resource, options.as_object()).await?;
for d in data.iter_mut() {
if let Some(user) = d.remove("user") && let Some(mut user) = user.into_map_opt() {
if let Some(user) = d.remove("user")
&& let Some(mut user) = user.into_map_opt()
{
d.append(&mut user);
}
}
Expand Down
8 changes: 4 additions & 4 deletions zino-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino-core"
description = "Core types and traits for zino."
version = "0.14.3"
version = "0.14.4"
rust-version = "1.73"
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -140,7 +140,7 @@ view-minijinja = ["view", "dep:minijinja"]
aes-gcm-siv = "0.11.1"
apache-avro = "0.16.0"
async-trait = "0.1.74"
base64 = "0.21.4"
base64 = "0.21.5"
bytes = "1.5.0"
cfg-if = "1.0"
convert_case = "0.6.0"
Expand All @@ -166,7 +166,7 @@ multer = "2.1.0"
parking_lot = "0.12.1"
rand = "0.8.5"
regex = "1.10.2"
reqwest-middleware = "0.2.3"
reqwest-middleware = "0.2.4"
reqwest-retry = "0.3.0"
reqwest-tracing = "0.4.6"
rmp-serde = "1.1.2"
Expand All @@ -175,7 +175,7 @@ serde_qs = "0.12.0"
sha2 = "0.10.8"
sysinfo = "0.29.10"
task-local-extensions = "0.1.4"
toml = "0.8.2"
toml = "0.8.4"
tracing = "0.1.40"
tracing-appender = "0.2.2"
url = "2.4.1"
Expand Down
26 changes: 26 additions & 0 deletions zino-core/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# zino-core

Core types and traits for zino.

## Feature flags

The following optional features are available:

| Name | Description | Default? |
|---------------------|--------------------------------------------------------|----------|
| `accessor` | Enables the data access layer built with [`opendal`]. | No |
| `cache` | Enables the cache services. | No |
| `chatbot` | Enables the chatbot services. | No |
| `connector` | Enables the data source connectors. | No |
| `crypto-sm` | Enables China's Standards of Encryption Algorithms. | No |
| `format` | Enables the support for common file formats. | No |
| `orm` | Enables the ORM for MySQL, PostgreSQL or **SQLite**. | No |
| `runtime-async-std` | Enables the [`async-std`] runtime. | No |
| `runtime-tokio` | Enables the [`tokio`] runtime. | Yes |
| `tls-native` | Enables the [`native-tls`] TLS backend. | No |
| `tls-rustls` | Enables the [`rustls`] TLS backend. | Yes |
| `view` | Enables the HTML template rendering. | No |

[`zino`]: https://github.com/photino/zino
[`opendal`]: https://crates.io/crates/opendal
[`async-std`]: https://crates.io/crates/async-std
[`tokio`]: https://crates.io/crates/tokio
[`native-tls`]: https://crates.io/crates/native-tls
[`rustls`]: https://crates.io/crates/rustls
4 changes: 3 additions & 1 deletion zino-core/src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ pub trait Application {
} else {
project_dir.join(dir)
};
if !path.exists() && let Err(err) = fs::create_dir_all(&path) {
if !path.exists()
&& let Err(err) = fs::create_dir_all(&path)
{
let path = path.display();
tracing::error!("fail to create the directory {path}: {err}");
}
Expand Down
4 changes: 3 additions & 1 deletion zino-core/src/auth/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ impl Authentication {
let signature = self.signature();
if signature.is_empty() {
validation.record("signature", "should be nonempty");
} else if let Ok(token) = self.sign_with::<H>(secret_access_key) && token != signature {
} else if let Ok(token) = self.sign_with::<H>(secret_access_key)
&& token != signature
{
validation.record("signature", "invalid signature");
}
validation
Expand Down
4 changes: 3 additions & 1 deletion zino-core/src/auth/session_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ impl SessionId {
} else {
domain.strip_suffix(realm)
};
if let Some(s) = remainder && s.ends_with('.') {
if let Some(s) = remainder
&& s.ends_with('.')
{
true
} else {
false
Expand Down
4 changes: 3 additions & 1 deletion zino-core/src/auth/user_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ impl<U, T> UserSession<U, String, T> {
} else {
role.strip_prefix(r.as_str())
};
if let Some(s) = remainder && s.starts_with(':') {
if let Some(s) = remainder
&& s.starts_with(':')
{
return true;
}
}
Expand Down
4 changes: 3 additions & 1 deletion zino-core/src/connector/connector_arrow/arrow_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ impl ArrowSchemaExt for Schema {
TomlValue::String(value_type) => parse_arrow_data_type(value_type)?,
TomlValue::Array(array) => {
let length = array.len();
if length == 1 && let Some(TomlValue::String(value_type)) = array.first() {
if length == 1
&& let Some(TomlValue::String(value_type)) = array.first()
{
let item_data_type = parse_arrow_data_type(value_type)?;
let field = Field::new("item", item_data_type, true);
DataType::List(Arc::new(field))
Expand Down
8 changes: 6 additions & 2 deletions zino-core/src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ impl NamedFile {
pub fn encrypt_with(&mut self, key: impl AsRef<[u8]>) -> Result<(), Error> {
let suffix = ".encrypted";
let bytes = crypto::encrypt(self.as_ref(), key.as_ref())?;
if let Some(ref mut file_name) = self.file_name && !file_name.ends_with(suffix) {
if let Some(ref mut file_name) = self.file_name
&& !file_name.ends_with(suffix)
{
file_name.push_str(suffix);
}
self.bytes = bytes.into();
Expand All @@ -155,7 +157,9 @@ impl NamedFile {
pub fn decrypt_with(&mut self, key: impl AsRef<[u8]>) -> Result<(), Error> {
let suffix = ".encrypted";
let bytes = crypto::decrypt(self.as_ref(), key.as_ref())?;
if let Some(ref mut file_name) = self.file_name && file_name.ends_with(suffix) {
if let Some(ref mut file_name) = self.file_name
&& file_name.ends_with(suffix)
{
file_name.truncate(file_name.len() - suffix.len());
}
self.bytes = bytes.into();
Expand Down
4 changes: 3 additions & 1 deletion zino-core/src/helper/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::{borrow::Cow, sync::LazyLock};
/// The interpolation parameter is represented as `${param}`,
/// in which `param` can only contain restricted chracters `[a-zA-Z]+[\w\.]*`.
pub(crate) fn format_query<'a>(query: &'a str, params: Option<&'a Map>) -> Cow<'a, str> {
if let Some(params) = params && query.contains('$') {
if let Some(params) = params
&& query.contains('$')
{
INTERPOLATION_PATTERN.replace_all(query, |captures: &Captures| {
let key = &captures[1];
params
Expand Down
4 changes: 3 additions & 1 deletion zino-core/src/helper/sql_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ pub(crate) fn prepare_sql_query<'a>(
placeholder: char,
) -> (Cow<'a, str>, Vec<&'a JsonValue>) {
let sql = super::format_query(query, params);
if let Some(params) = params && sql.contains('#') {
if let Some(params) = params
&& sql.contains('#')
{
let mut values = Vec::new();
let sql = STATEMENT_PATTERN.replace_all(&sql, |captures: &Captures| {
let key = &captures[1];
Expand Down
12 changes: 7 additions & 5 deletions zino-core/src/model/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ impl Query {
}
"timestamp" | "nonce" | "signature" => (),
_ => {
if let Some(value) = value.as_str() && value != "all" {
if key.starts_with('$') &&
let Some(expr) = value.strip_prefix('(')
if let Some(value) = value.as_str()
&& value != "all"
{
if key.starts_with('$')
&& let Some(expr) = value.strip_prefix('(')
{
filters.upsert(key, Self::parse_logical_query(expr));
} else if value.starts_with('$') &&
let Some((operator, value)) = value.split_once('.')
} else if value.starts_with('$')
&& let Some((operator, value)) = value.split_once('.')
{
filters.upsert(key, Map::from_entry(operator, value));
} else {
Expand Down
8 changes: 6 additions & 2 deletions zino-core/src/openapi/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ pub(crate) fn translate_model_entry(model: &mut Map, model_name: &str) {
&& let Some(value) = model.get(field)
{
let translated_field = [field, "translated"].join("_");
let translated_value = translation.translate(value).unwrap_or_else(|| value.clone());
let translated_value = translation
.translate(value)
.unwrap_or_else(|| value.clone());
data.upsert(translated_field, translated_value);
}
}
Expand All @@ -25,7 +27,9 @@ static MODEL_TRANSLATIONS: LazyLock<HashMap<&str, Translation>> = LazyLock::new(
for (model_name, fields) in definitions.iter() {
for (field, value) in fields {
let translation = value.as_table().map(Translation::with_config);
if let Some(translation) = translation && translation.is_ready() {
if let Some(translation) = translation
&& translation.is_ready()
{
let model_name = model_name.to_case(Case::Snake);
let model_key = format!("{model_name}.{field}").leak() as &'static str;
model_translations.insert(model_key, translation);
Expand Down
4 changes: 3 additions & 1 deletion zino-core/src/openapi/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ fn parse_schema_format(format: &str) -> SchemaFormat {
fn parse_path_parameters(path: &str) -> Vec<Parameter> {
let mut parameters = Vec::new();
for segment in path.split('/') {
if let Some(part) = segment.strip_prefix('{') && let Some(name) = part.strip_suffix('}') {
if let Some(part) = segment.strip_prefix('{')
&& let Some(name) = part.strip_suffix('}')
{
let schema_name = name.to_case(Case::Camel);
let parameter = ParameterBuilder::new()
.name(name)
Expand Down
8 changes: 6 additions & 2 deletions zino-core/src/orm/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,12 @@ where
Self::before_extract().await?;

let mut model = Self::try_get_model(id).await?;
if let Some(version) = data.get_u64("version") && model.version() != version {
return Err(Error::new("409 Conflict: there is a version control conflict"));
if let Some(version) = data.get_u64("version")
&& model.version() != version
{
return Err(Error::new(
"409 Conflict: there is a version control conflict",
));
}
Self::before_validation(data, extension.as_ref()).await?;

Expand Down
8 changes: 6 additions & 2 deletions zino-core/src/orm/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ where
fn encrypt_password(passowrd: &str) -> Result<String, Error> {
let key = Self::secret_key();
let passowrd = passowrd.as_bytes();
if let Ok(bytes) = base64::decode(passowrd) && bytes.len() == 256 {
if let Ok(bytes) = base64::decode(passowrd)
&& bytes.len() == 256
{
crypto::encrypt_hashed_password(passowrd, key)
} else {
crypto::encrypt_raw_password(passowrd, key)
Expand All @@ -36,7 +38,9 @@ where
let key = Self::secret_key();
let passowrd = passowrd.as_bytes();
let encrypted_password = encrypted_password.as_bytes();
if let Ok(bytes) = base64::decode(passowrd) && bytes.len() == 256 {
if let Ok(bytes) = base64::decode(passowrd)
&& bytes.len() == 256
{
crypto::verify_hashed_password(passowrd, encrypted_password, key)
} else {
crypto::verify_raw_password(passowrd, encrypted_password, key)
Expand Down
2 changes: 1 addition & 1 deletion zino-core/src/orm/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl MutationExt<DatabaseDriver> for Mutation {
let mutation = format!(r#"{key} = GREATEST({key}, {value})"#);
mutations.push(mutation);
}
_ => ()
_ => (),
}
if operator.starts_with('$') {
set_json_object = false;
Expand Down
7 changes: 5 additions & 2 deletions zino-core/src/orm/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ impl<'c> EncodeColumn<DatabaseDriver> for Column<'c> {
if let Some(values) = value.as_array()
&& let [min_value, max_value, ..] = values.as_slice()
{
let condition = format!(r#"{field} BETWEEN {min_value} AND {max_value}"#);
let condition =
format!(r#"{field} BETWEEN {min_value} AND {max_value}"#);
conditions.push(condition);
}
} else if operator == "json_length" {
Expand All @@ -222,7 +223,9 @@ impl<'c> EncodeColumn<DatabaseDriver> for Column<'c> {
return conditions.join(" AND ");
}
}
} else if let Some(range) = value.as_array() && range.len() == 2 {
} else if let Some(range) = value.as_array()
&& range.len() == 2
{
let min_value = self.encode_value(range.first());
let max_value = self.encode_value(range.last());
return format!(r#"{field} >= {min_value} AND {field} < {max_value}"#);
Expand Down
Loading

0 comments on commit cce64b1

Please sign in to comment.