Skip to content

Commit

Permalink
Release version 0.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
photino committed Nov 22, 2023
1 parent 6309868 commit 33ce419
Show file tree
Hide file tree
Showing 24 changed files with 324 additions and 107 deletions.
12 changes: 6 additions & 6 deletions examples/actix-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "actix-app"
description = "An example for actix-web integration."
version = "0.4.0"
version = "0.4.1"
rust-version = "1.73"
edition = "2021"
publish = false
Expand All @@ -11,23 +11,23 @@ actix-web = "4.4.0"
tracing = "0.1.40"

[dependencies.serde]
version = "1.0.192"
version = "1.0.193"
features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.14.4"
version = "0.15.0"
features = ["actix"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.15.4"
version = "0.16.0"
features = ["orm-postgres", "view-minijinja"]

[dependencies.zino-derive]
path = "../../zino-derive"
version = "0.12.4"
version = "0.13.0"

[dependencies.zino-model]
path = "../../zino-model"
version = "0.12.4"
version = "0.13.0"
14 changes: 8 additions & 6 deletions examples/axum-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "axum-app"
description = "An example for axum integration."
version = "0.10.0"
version = "0.10.1"
rust-version = "1.73"
edition = "2021"
publish = false
Expand All @@ -11,27 +11,29 @@ axum = "0.6.20"
tracing = "0.1.40"

[dependencies.serde]
version = "1.0.192"
version = "1.0.193"
features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.14.4"
version = "0.15.0"
features = ["axum"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.15.4"
version = "0.16.0"
features = [
"crypto-sm",
"orm-mysql",
"validator-email",
"validator-phone-number",
"view-tera",
]

[dependencies.zino-derive]
path = "../../zino-derive"
version = "0.12.4"
version = "0.13.0"

[dependencies.zino-model]
path = "../../zino-model"
version = "0.12.4"
version = "0.13.0"
12 changes: 10 additions & 2 deletions examples/axum-app/src/model/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct User {
name: String,
#[schema(
auto_initialized,
enum_values = "Active | Inactive | Locked | Deleted",
enum_values = "Active | Inactive | Locked | Deleted | Archived",
default_value = "Inactive",
index_type = "hash",
comment = "User status"
Expand All @@ -42,12 +42,20 @@ pub struct User {
account: String,
#[schema(not_null, write_only, comment = "User password")]
password: String,
#[schema(format = "phone_number")]
mobile: String,
#[schema(format = "email")]
email: String,
#[schema(format = "uri")]
avatar: String,
#[schema(snapshot, nonempty, unique_items, comment = "User roles", example = "admin, worker")]
#[schema(
snapshot,
nonempty,
unique_items,
enum_values = "admin | worker | auditor",
comment = "User roles",
example = "admin, worker"
)]
roles: Vec<String>,
#[schema(unique_items, reference = "Tag", comment = "User tags")]
tags: Vec<i64>,
Expand Down
12 changes: 6 additions & 6 deletions examples/dioxus-desktop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dioxus-desktop"
description = "An example for Dioxus desktop integration."
version = "0.1.2"
version = "0.1.3"
rust-version = "1.73"
edition = "2021"
publish = false
Expand All @@ -21,23 +21,23 @@ features = [
]

[dependencies.serde]
version = "1.0.192"
version = "1.0.193"
features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.14.4"
version = "0.15.0"
features = ["dioxus-desktop"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.15.4"
version = "0.16.0"
features = ["orm-sqlite"]

[dependencies.zino-model]
path = "../../zino-model"
version = "0.12.4"
version = "0.13.0"

[dependencies.zino-dioxus]
path = "../../zino-dioxus"
version = "0.1.3"
version = "0.1.4"
4 changes: 2 additions & 2 deletions zino-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino-cli"
description = "CLI tools for zino."
version = "0.1.2"
version = "0.1.3"
rust-version = "1.73"
edition = "2021"
license = "MIT"
Expand All @@ -25,4 +25,4 @@ features = ["derive"]

[dependencies.zino-core]
path = "../zino-core"
version = "0.15.3"
version = "0.16.0"
32 changes: 25 additions & 7 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.15.4"
version = "0.16.0"
rust-version = "1.73"
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -95,6 +95,12 @@ all-connectors = [
"connector-postgres",
"connector-sqlite",
]
all-validators = [
"validator-credit-card",
"validator-email",
"validator-phone-number",
"validator-regex",
]
auth-oauth2 = ["dep:oauth2"]
auth-oidc = ["dep:openidconnect"]
auth-totp = ["dep:totp-rs"]
Expand All @@ -113,6 +119,7 @@ full = [
"all-auth",
"all-chatbots",
"all-connectors",
"all-validators",
"orm",
"view",
]
Expand All @@ -134,8 +141,12 @@ tls-rustls = [
"opendal?/rustls",
"reqwest/rustls-tls",
"sqlx?/tls-rustls",
"ureq/rustls",
]
validator = []
validator-credit-card = ["validator", "dep:card-validate"]
validator-email = ["validator"]
validator-phone-number = ["validator", "dep:phonenumber"]
validator-regex = ["validator"]
view = ["dep:minijinja"]
view-minijinja = ["view", "dep:minijinja"]
view-tera = ["view", "dep:tera"]
Expand Down Expand Up @@ -192,6 +203,10 @@ features = ["std"]
version = "0.16.3"
optional = true

[dependencies.card-validate]
version = "2.3.0"
optional = true

[dependencies.chrono]
version = "0.4.31"
features = ["serde"]
Expand Down Expand Up @@ -223,6 +238,10 @@ features = ["layers-all"]
version = "3.4.0"
optional = true

[dependencies.phonenumber]
version = "0.3.3"
optional = true

[dependencies.reqwest]
version = "0.11.22"
default-features = false
Expand All @@ -235,7 +254,7 @@ features = [
]

[dependencies.serde]
version = "1.0.192"
version = "1.0.193"
features = ["derive"]

[dependencies.serde_json]
Expand Down Expand Up @@ -286,9 +305,8 @@ version = "0.9.1"
features = ["macros"]

[dependencies.ureq]
version = "2.8.0"
default-features = false
features = ["gzip", "json"]
version = "2.9.0"
features = ["json"]

[dependencies.utoipa]
version = "4.1.0"
Expand All @@ -300,7 +318,7 @@ features = [
]

[dependencies.uuid]
version = "1.6.0"
version = "1.6.1"
features = [
"fast-rng",
"serde",
Expand Down
7 changes: 5 additions & 2 deletions zino-core/src/model/column.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::Reference;
use crate::{extension::{JsonObjectExt, JsonValueExt}, JsonValue, Map};
use crate::{
extension::{JsonObjectExt, JsonValueExt},
JsonValue, Map,
};
use apache_avro::schema::{Name, RecordField, RecordFieldOrder, Schema, UnionSchema};
use serde::Serialize;
use std::{borrow::Cow, collections::BTreeMap};
Expand Down Expand Up @@ -162,7 +165,7 @@ impl<'a> Column<'a> {
true
}

/// Returns `true` if the column is the primary key.
/// Returns `true` if the column is a primary key.
#[inline]
pub fn is_primary_key(&self) -> bool {
self.has_attribute("primary_key")
Expand Down
14 changes: 14 additions & 0 deletions zino-core/src/model/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ pub trait ModelHooks: Model {
Ok(())
}

/// A hook running before archiving a model in the table.
#[inline]
async fn before_archive(&mut self) -> Result<Self::Data, Error> {
self.before_save().await
}

/// A hook running after archiving a model in the table.
#[inline]
async fn after_archive(ctx: &QueryContext, data: Self::Data) -> Result<(), Error> {
Self::after_save(ctx, data).await?;
ctx.emit_metrics("archive");
Ok(())
}

/// A hook running before updating a model in the table.
#[inline]
async fn before_update(&mut self) -> Result<Self::Data, Error> {
Expand Down
43 changes: 36 additions & 7 deletions zino-core/src/orm/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ where
self.status().eq_ignore_ascii_case("Deleted")
}

/// Returns `true` if the `status` is `Archived`.
#[inline]
fn is_archived(&self) -> bool {
self.status().eq_ignore_ascii_case("Archived")
}

/// Returns `true` if the `description` is nonempty.
#[inline]
fn has_description(&self) -> bool {
Expand Down Expand Up @@ -315,7 +321,7 @@ where
mutation
}

/// Constructs the `Mutation` for a soft delete of the model.
/// Constructs a `Mutation` for logically deleting the model.
fn soft_delete_mutation(&self) -> Mutation {
let mut mutation = Self::default_mutation();
let mut updates = self.next_edition_updates();
Expand All @@ -324,7 +330,7 @@ where
mutation
}

/// Constructs the `Mutation` for a lock of the model.
/// Constructs a `Mutation` for locking the model.
fn lock_mutation(&self) -> Mutation {
let mut mutation = Self::default_mutation();
let mut updates = self.next_edition_updates();
Expand All @@ -333,6 +339,15 @@ where
mutation
}

/// Constructs a `Mutation` for archiving the model.
fn archive_mutation(&self) -> Mutation {
let mut mutation = Self::default_mutation();
let mut updates = self.next_edition_updates();
updates.upsert("status", "Archived");
mutation.append_updates(&mut updates);
mutation
}

/// Constructs a default snapshot `Query` for the model.
fn default_snapshot_query() -> Query {
let mut query = Self::default_query();
Expand Down Expand Up @@ -410,6 +425,18 @@ where
Ok(())
}

/// Archives a model of the primary key by setting the status as `Archived`.
async fn archive_by_id(id: &K) -> Result<(), Error> {
let mut model = Self::try_get_model(id).await?;
let model_data = model.before_archive().await?;

let query = model.current_version_query();
let mut mutation = model.archive_mutation();
let ctx = Self::update_one(&query, &mut mutation).await?;
Self::after_archive(&ctx, model_data).await?;
Ok(())
}

/// Updates a model of the primary key using the json object.
async fn update_by_id(
id: &K,
Expand All @@ -423,8 +450,8 @@ where
&& model.version() != version
{
bail!(
"409 Conflict: there is a version conflict for `{}`",
version
"409 Conflict: there is a version conflict for the model `{}`",
id
);
}
Self::before_validation(data, extension.as_ref()).await?;
Expand All @@ -441,10 +468,12 @@ where
if !validation.is_success() {
return Ok((validation, model));
}
if model.is_locked() {
data.retain(|key, _value| key == "visibility" || key == "status");
} else if model.is_deleted() {
if model.is_deleted() {
data.retain(|key, _value| key == "status");
} else if model.is_locked() {
data.retain(|key, _value| key == "visibility" || key == "status");
} else if model.is_archived() {
bail!("403 Forbidden: archived model `{}` can not be modified", id);
}
model.after_validation(data).await?;

Expand Down
Loading

0 comments on commit 33ce419

Please sign in to comment.